Skip to content
Snippets Groups Projects
Unverified Commit 5f857a1f authored by Adam Paquette's avatar Adam Paquette Committed by GitHub
Browse files

Update Cube Tests (#5689)

* Moved CubeIoHandler getters into public space

* Made getDataFile protected

* Made realDataFileName public on cube

* Added new cube tests as gtests

* Added CubeBsqHandlerTests

* Removed old Cube unittests

* Removed cube truth
parent ac1a5095
No related branches found
No related tags found
No related merge requests found
......@@ -325,7 +325,7 @@ namespace Isis {
void putGroup(const PvlGroup &group);
void latLonRange(double &minLatitude, double &maxLatitude, double &minLongitude,
double &maxLongitude);
FileName realDataFileName() const;
private:
void applyVirtualBandsToLabel();
......@@ -333,7 +333,6 @@ namespace Isis {
void construct();
QFile *dataFile() const;
FileName realDataFileName() const;
void initialize();
void initCoreFromLabel(const Pvl &label);
......
......@@ -127,8 +127,6 @@ namespace Isis {
virtual void updateLabels(Pvl &labels) = 0;
QMutex *dataFileMutex();
protected:
int bandCount() const;
int getBandCountInChunk() const;
BigInt getBytesPerChunk() const;
......@@ -137,13 +135,15 @@ namespace Isis {
int getChunkCountInSampleDimension() const;
int getChunkIndex(const RawCubeChunk &) const;
BigInt getDataStartByte() const;
QFile * getDataFile();
int lineCount() const;
int getLineCountInChunk() const;
PixelType pixelType() const;
int sampleCount() const;
int getSampleCountInChunk() const;
protected:
QFile * getDataFile();
void setChunkSizes(int numSamples, int numLines, int numBands);
/**
......
Unit test for Cube
Constructing cube ...
File =
Samps = 0
Lines = 0
Bands = 0
Base = 0
Mult = 1
Type = 7
Atchd = 1
Format = 1
Open = 0
R/O = N/A
R/W = N/A
Lbytes = 65536
Creating 32-bit cube ...
File = IsisCube_00.cub
Samps = 150
Lines = 200
Bands = 2
Base = 0
Mult = 1
Type = 7
Atchd = 1
Format = 1
Open = 1
R/O = 0
R/W = 1
Lbytes = 65536
Write cube ...
Opening cube ...
File = IsisCube_01.cub
Samps = 150
Lines = 200
Bands = 2
Base = 0
Mult = 1
Type = 7
Atchd = 1
Format = 1
Open = 1
R/O = 1
R/W = 0
Lbytes = 6563
Comparing cube ...
Creating 8-bit cube ...
Comparing cube ...
File = IsisCube_02.lbl
Samps = 150
Lines = 200
Bands = 1
Base = 200
Mult = -1
Type = 1
Atchd = 0
Format = 0
Open = 1
R/O = 1
R/W = 0
Lbytes = 419
Creating 16-bit cube ...
Comparing cube ...
File = IsisCube_03.cub
Samps = 150
Lines = 200
Bands = 2
Base = 30000
Mult = -1
Type = 4
Atchd = 1
Format = 1
Open = 1
R/O = 1
R/W = 0
Lbytes = 65536
Testing histogram method, band 1 ...
Average: 14900
Standard Dev: 8602.66
Mode: 149.148
Total Pixels: 30000
Null Pixels: 0
Testing histogram method, all bands ...
Average: 29800
Standard Dev: 17205.2
Mode: 149.148
Total Pixels: 60000
Null Pixels: 0
**PROGRAMMER ERROR** Invalid band in [CubeInfo::Histogram].
**PROGRAMMER ERROR** Cannot create histogram object for an unopened cube.
Testing statistics method, band 1 ...
Average: 14900
Standard Dev: 8602.66
Total Pixels: 30000
Null Pixels: 0
Testing statistics method, all bands ...
Average: 29800
Standard Dev: 17205.2
Total Pixels: 60000
Null Pixels: 0
**PROGRAMMER ERROR** Invalid band in [CubeInfo::Statistics].
**PROGRAMMER ERROR** Cannot create statistics object for an unopened cube.
Virtual band tests
Nbands = 2
Band 1 = 1
Band 2 = 2
Nbands = 1
Band 1 = 2
ReOpen tests
File = IsisCube_01.cub
Samps = 150
Lines = 200
Bands = 1
Base = 0
Mult = 1
Type = 7
Atchd = 1
Format = 1
Open = 1
R/O = 1
R/W = 0
Lbytes = 6563
File = IsisCube_01.cub
Samps = 150
Lines = 200
Bands = 1
Base = 0
Mult = 1
Type = 7
Atchd = 1
Format = 1
Open = 1
R/O = 0
R/W = 1
Lbytes = 6563
File = IsisCube_01.cub
Samps = 150
Lines = 200
Bands = 1
Base = 0
Mult = 1
Type = 7
Atchd = 1
Format = 1
Open = 1
R/O = 1
R/W = 0
Lbytes = 6563
Testing reading past cube boundaries ...
Constructing cube ...
File = IsisCube_boundary.cub
Samps = 10
Lines = 10
Bands = 4
Base = 0
Mult = 1
Type = 7
Atchd = 1
Format = 1
Open = 1
R/O = 0
R/W = 1
Lbytes = 65536
Reading completely within cube boundaries ...
Comparing results ...
Reading completely outside band boundaries ...
Comparing results ...
Reading partially within band boundaries ...
Reading bands 0 (should be null) and 1 (should be 1.0)...
Comparing results ...
Reading bands 4 (should be 1.0) and 5 (should be null)...
Comparing results ...
Testing reading past cube boundaries with virtual bands (2, 1, 3, 4, 2)...
Reading completely outside virtual band boundaries ...
Comparing results starting at band 6...
Comparing results starting at band 1000...
Comparing results starting at band -1...
Reading partially within virtual band boundaries ...
Comparing results ...
Testing one line BSQ cube (where chunk dimensions == buffer shape) ...
Constructing cube ...
File = IsisCube_bsqOneLine.cub
Samps = 3
Lines = 1
Bands = 3
Base = 0
Mult = 1
Type = 7
Atchd = 1
Format = 0
Open = 1
R/O = 0
R/W = 1
Lbytes = 65536
Testing reading ascending repeating virtual bands (1, 2, 2, 3)...
Testing reading skipped ascending virtual bands (1, 3, 3)...
Testing reading outside of cube boundaries with virtual bands (1, 5)...
Testing reading descending virtual bands (3, 1, 3)...
Testing creating large BSQ where samples exceed 1GB chunk size limit ...
Constructing cube ...
File = IsisCube_largebsq.cub
Samps = 268435457
Lines = 2
Bands = 1
Base = 0
Mult = 1
Type = 7
Atchd = 1
Format = 0
Open = 1
R/O = 0
R/W = 1
Lbytes = 65536
Testing creating BSQ cube where size of sample pixels exceeds cube's lineCount ...
Constructing cube ...
File = IsisCube_bsq.cub
Samps = 15000
Lines = 18000
Bands = 1
Base = 0
Mult = 1
Type = 7
Atchd = 1
Format = 0
Open = 1
R/O = 0
R/W = 1
Lbytes = 65536
Testing errors ...
**PROGRAMMER ERROR** You already have a cube opened.
**PROGRAMMER ERROR** You already have a cube opened.
**PROGRAMMER ERROR** Cannot write to the cube [IsisCube_01.cub] because it is opened read-only.
**I/O ERROR** Unable to open [blah].
**PROGRAMMER ERROR** Out of array bounds [2].
**PROGRAMMER ERROR** Out of array bounds [0].
**PROGRAMMER ERROR** Try opening a file before you read it.
**PROGRAMMER ERROR** Tried to write to a cube before opening/creating it.
**PROGRAMMER ERROR** Number of samples [0], lines [0], or bands [0] cannot be less than 1.
**I/O ERROR** Label space is full in [IsisCube_04.cub] unable to write labels.
**USER ERROR** The cube you are attempting to create [IsisCube_05] is [33527GB]. This is larger than the current allowed size of [12GB]. The cube dimensions were (S,L,B) [1000000, 1000000, 9] with [4] bytes per pixel. If you still wish to create this cube, the maximum value can be changed in your personal preference file located in [~/.Isis/IsisPreferences] within the group CubeCustomization, keyword MaximumSize. If you do not have an ISISPreference file, please refer to the documentation 'Environment and Preference Setup'. Error.
**PROGRAMMER ERROR** Unknown value for access [a]. Expected 'r' or 'rw'.
**PROGRAMMER ERROR** SetDimensions: Invalid number of sample, lines or bands.
**PROGRAMMER ERROR** SetDimensions: Invalid number of sample, lines or bands.
**PROGRAMMER ERROR** SetDimensions: Invalid number of sample, lines or bands.
**I/O ERROR** Failed to open [...] with read/write access.
**ERROR** Cannot create the cube [shouldntExist.cub] with a pixel type set to None.
**PROGRAMMER ERROR** Cannot add a group to the label of cube [IsisCube_06.cub] because it is opened read-only.
Test creating an ecub
Object = IsisCube
Object = Core
^DnFile = $ISISTESTDATA/isis/src/base/unitTestData/isisTruth.cub
End_Object
Group = TestGroup
End_Group
End_Object
Object = Label
Bytes = 65536
End_Object
End
0 0 0 20 20 20 39 39 39 0 20 39 0 20 39 0 20 39
**ERROR** The cube [isisTruth_external.ecub] does not support storing DN data because it is using an external file for DNs.
Test creating an ecub from an ecub
Object = IsisCube
Object = Core
^DnFile = isisTruth_external.ecub
End_Object
End_Object
Object = Label
Bytes = 65536
End_Object
End
0 0 0 20 20 20 39 39 39 0 20 39 0 20 39 0 20 39
**ERROR** The cube [isisTruth_external2.ecub] does not support storing DN data because it is using an external file for DNs.
Test reading an ecub
Object = IsisCube
Object = Core
^DnFile = $ISISTESTDATA/isis/src/base/unitTestData/isisTruth.cub
End_Object
Group = TestGroup
End_Group
Group = TestGroup2
End_Group
End_Object
Object = Label
Bytes = 65536
End_Object
End
0 0 0 20 20 20 39 39 39 0 20 39 0 20 39 0 20 39
**PROGRAMMER ERROR** Cannot write to the cube [isisTruth_external.ecub] because it is opened read-only.
Test reading an ecub that points to another ecub
Object = IsisCube
Object = Core
^DnFile = isisTruth_external.ecub
End_Object
End_Object
Object = Label
Bytes = 65536
End_Object
End
0 0 0 20 20 20 39 39 39 0 20 39 0 20 39 0 20 39
**PROGRAMMER ERROR** Cannot write to the cube [isisTruth_external2.ecub] because it is opened read-only.
This diff is collapsed.
This diff is collapsed.
......@@ -6,8 +6,13 @@
using json = nlohmann::json;
#include "Blob.h"
#include "Cube.h"
#include "Brick.h"
#include "Camera.h"
#include "Cube.h"
#include "CubeAttribute.h"
#include "Histogram.h"
#include "LineManager.h"
#include "Statistics.h"
#include "CubeFixtures.h"
#include "TestUtilities.h"
......@@ -16,6 +21,38 @@ using json = nlohmann::json;
using namespace Isis;
void check_cube(Cube &cube,
QString &file,
int sampleCount,
int lineCount,
int bandCount,
double base,
double multiplier,
int pixelType,
bool attached,
int format,
int isOpen,
int isReadOnly,
int isReadWrite,
int labelSize) {
EXPECT_EQ(cube.fileName().toStdString(), file.toStdString());
EXPECT_EQ(cube.sampleCount(), sampleCount);
EXPECT_EQ(cube.lineCount(), lineCount);
EXPECT_EQ(cube.bandCount(), bandCount);
EXPECT_EQ(cube.base(), base);
EXPECT_EQ(cube.multiplier(), multiplier);
EXPECT_EQ(cube.pixelType(), pixelType);
EXPECT_EQ(cube.labelsAttached(), attached);
EXPECT_EQ(cube.format(), format);
EXPECT_EQ(cube.isOpen(), isOpen);
if (cube.isOpen()) {
EXPECT_EQ(cube.isReadOnly(), isReadOnly);
EXPECT_EQ(cube.isReadWrite(), isReadWrite);
}
EXPECT_EQ(cube.labelSize(), labelSize);
}
TEST(CubeTest, TestCubeAttachSpiceFromIsd) {
std::istringstream labelStrm(R"(
Object = IsisCube
......@@ -239,3 +276,587 @@ TEST_F(SmallCube, TestCubeHasBlob) {
EXPECT_TRUE(testCube->hasBlob("TestBlob", "SomeBlob"));
EXPECT_FALSE(testCube->hasBlob("SomeOtherTestBlob", "SomeBlob"));
}
TEST_F(TempTestingFiles, TestCubeCreateWriteCopy) {
Cube out;
QString file = "";
check_cube(out, file, 0, 0, 0, 0, 1, 7, 1, 1, 0, 0, 0, 65536);
out.setDimensions(150, 200, 2);
file = QString(tempDir.path() + "/IsisCube_00.cub");
out.create(file);
check_cube(out, file, 150, 200, 2, 0, 1, 7, 1, 1, 1, 0, 1, 65536);
LineManager line(out);
long j = 0;
for(line.begin(); !line.end(); line++) {
for(int i = 0; i < line.size(); i++) {
line[i] = (double) j;
j++;
}
j--;
out.write(line);
}
// Copy returns the resulting Cube, we don't care about it (but we need it to flush) so delete
QString file2 = tempDir.path() + "/IsisCube_01.cub";
delete out.copy(file2, CubeAttributeOutput());
out.close();
// Test the open and read methods
Cube in(file2);
check_cube(in, file2, 150, 200, 2, 0, 1, 7, 1, 1, 1, 1, 0, 6563);
LineManager inLine(in);
j = 0;
for(inLine.begin(); !inLine.end(); inLine++) {
in.read(inLine);
for(int i = 0; i < inLine.size(); i++) {
EXPECT_NEAR(inLine[i], (double) j, 1e-15);
j++;
}
j--;
}
in.close();
}
TEST_F(TempTestingFiles, TestCubeCreateWrite8bit) {
Cube out;
QString file = "";
check_cube(out, file, 0, 0, 0, 0, 1, 7, 1, 1, 0, 0, 0, 65536);
out.setDimensions(150, 200, 1);
out.setLabelsAttached(0);
out.setBaseMultiplier(200.0, -1.0);
out.setByteOrder(ISIS_LITTLE_ENDIAN ? Msb : Lsb);
out.setFormat(Cube::Bsq);
out.setLabelSize(1000);
out.setPixelType(UnsignedByte);
check_cube(out, file, 150, 200, 1, 200, -1, 1, 0, 0, 0, 0, 0, 1000);
file = QString(tempDir.path() + "/IsisCube_00.cub");
out.create(file);
long j = 0;
LineManager oline(out);
for(oline.begin(); !oline.end(); oline++) {
for(int i = 0; i < oline.size(); i++) {
oline[i] = (double) j;
}
out.clearIoCache();
out.write(oline);
j++;
}
out.close();
Cube in;
file = QString(tempDir.path() + "/IsisCube_00.lbl");
try {
in.open(file);
}
catch (IException &e) {
e.print();
}
check_cube(in, file, 150, 200, 1, 200, -1, 1, 0, 0, 1, 1, 0, 419);
j = 0;
LineManager inLine(in);
for(inLine.begin(); !inLine.end(); inLine++) {
in.read(inLine );
for(int i = 0; i < inLine.size(); i++) {
EXPECT_NEAR(inLine[i], (double) j, 1e-15);
}
in.clearIoCache();
j++;
}
in.close();
}
TEST_F(TempTestingFiles, TestCubeCreateWrite16bit) {
Cube out;
QString file = "";
check_cube(out, file, 0, 0, 0, 0, 1, 7, 1, 1, 0, 0, 0, 65536);
out.setDimensions(150, 200, 2);
out.setBaseMultiplier(30000.0, -1.0);
out.setByteOrder(ISIS_LITTLE_ENDIAN ? Msb : Lsb);
out.setPixelType(SignedWord);
check_cube(out, file, 150, 200, 2, 30000, -1, 4, 1, 1, 0, 0, 0, 65536);
file = QString(tempDir.path() + "/IsisCube.cub");
out.create(file);
long j = 0;
LineManager oline(out);
for(oline.begin(); !oline.end(); oline++) {
for(int i = 0; i < oline.size(); i++) {
oline[i] = (double) j;
}
out.clearIoCache();
out.write(oline);
j++;
}
out.close();
Cube in;
try {
in.open(file);
}
catch (IException &e) {
e.print();
}
check_cube(in, file, 150, 200, 2, 30000, -1, 4, 1, 1, 1, 1, 0, 65536);
j = 0;
LineManager inLine(in);
for(inLine.begin(); !inLine.end(); inLine++) {
in.read(inLine );
for(int i = 0; i < inLine.size(); i++) {
EXPECT_NEAR(inLine[i], (double) j, 1e-15);
}
in.clearIoCache();
j++;
}
in.close();
}
TEST_F(SmallCube, TestCubeHistorgramBand1) {
Histogram *bandHist = testCube->histogram(1);
EXPECT_DOUBLE_EQ(bandHist->Average(), 49.5);
EXPECT_DOUBLE_EQ(bandHist->StandardDeviation(), 29.011491975882016);
EXPECT_DOUBLE_EQ(bandHist->Mode(), 0);
EXPECT_DOUBLE_EQ(bandHist->TotalPixels(), 100);
EXPECT_DOUBLE_EQ(bandHist->NullPixels(), 0);
delete bandHist;
}
TEST_F(SmallCube, TestCubeHistorgramAll) {
Histogram *bandHist = testCube->histogram(0);
EXPECT_DOUBLE_EQ(bandHist->Average(), 499.5);
EXPECT_DOUBLE_EQ(bandHist->StandardDeviation(), 288.81943609574938);
EXPECT_DOUBLE_EQ(bandHist->Mode(), 0);
EXPECT_DOUBLE_EQ(bandHist->TotalPixels(), 1000);
EXPECT_DOUBLE_EQ(bandHist->NullPixels(), 0);
delete bandHist;
}
TEST_F(SmallCube, TestCubeStatisticsBand1) {
Statistics *bandHist = testCube->statistics(1);
EXPECT_DOUBLE_EQ(bandHist->Average(), 49.5);
EXPECT_DOUBLE_EQ(bandHist->StandardDeviation(), 29.011491975882016);
EXPECT_DOUBLE_EQ(bandHist->TotalPixels(), 100);
EXPECT_DOUBLE_EQ(bandHist->NullPixels(), 0);
delete bandHist;
}
TEST_F(SmallCube, TestCubeStatisticsAll) {
Statistics *bandHist = testCube->statistics(0);
EXPECT_DOUBLE_EQ(bandHist->Average(), 499.5);
EXPECT_DOUBLE_EQ(bandHist->StandardDeviation(), 288.81943609574938);
EXPECT_DOUBLE_EQ(bandHist->TotalPixels(), 1000);
EXPECT_DOUBLE_EQ(bandHist->NullPixels(), 0);
delete bandHist;
}
TEST_F(SmallCube, TestCubeNegativeHistStatsBand) {
try {
testCube->histogram(-1);
FAIL() << "Expected an exception to be thrown";
}
catch (IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("Invalid band in [CubeInfo::Histogram]"))
<< e.toString().toStdString();
}
try {
testCube->statistics(-1);
FAIL() << "Expected an exception to be thrown";
}
catch (IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("Invalid band in [CubeInfo::Statistics]"))
<< e.toString().toStdString();
}
}
TEST(CubeTest, TestCubeNoHistStats) {
Cube cube;
try {
cube.histogram();
FAIL() << "Expected an exception to be thrown";
}
catch (IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("Cannot create histogram object for an unopened cube"))
<< e.toString().toStdString();
}
try {
cube.statistics();
FAIL() << "Expected an exception to be thrown";
}
catch (IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("Cannot create statistics object for an unopened cube"))
<< e.toString().toStdString();
}
}
TEST_F(SmallCube, TestCubePhyscialBands) {
EXPECT_EQ(testCube->bandCount(), 10);
for (int i = 0; i < testCube->bandCount(); i++) {
EXPECT_EQ(testCube->physicalBand(i), i);
}
}
TEST_F(SmallCube, TestCubeVirutalBands) {
QString path = testCube->fileName();
testCube->close();
QList<QString> vbands = {"2", "3", "4", "5", "6", "7", "8", "9", "10"};
testCube->setVirtualBands(vbands);
testCube->open(path);
EXPECT_EQ(testCube->bandCount(), 9);
for (int i = 1; i < vbands.size() + 1; i++) {
EXPECT_EQ(testCube->physicalBand(i), i + 1);
}
}
TEST_F(SmallCube, TestCubeReopenRW) {
QString path = testCube->fileName();
check_cube(*testCube, path, 10, 10, 10, 0, 1, 7, 1, 1, 1, 0, 1, 65536);
testCube->reopen("rw");
check_cube(*testCube, path, 10, 10, 10, 0, 1, 7, 1, 1, 1, 0, 1, 65536);
}
TEST_F(SmallCube, TestCubeReopenR) {
QString path = testCube->fileName();
check_cube(*testCube, path, 10, 10, 10, 0, 1, 7, 1, 1, 1, 0, 1, 65536);
testCube->reopen("r");
check_cube(*testCube, path, 10, 10, 10, 0, 1, 7, 1, 1, 1, 1, 0, 65536);
}
TEST_F(SmallCube, TestCubeAlreadyOpenOpen) {
try {
testCube->open("blah");
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("You already have a cube opened."))
<< e.toString().toStdString();
}
}
TEST_F(SmallCube, TestCubeAlreadyOpenCreate) {
try {
testCube->create("blah");
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("You already have a cube opened."))
<< e.toString().toStdString();
}
}
TEST_F(TempTestingFiles, TestCubeWriteToReadOnly) {
Cube testCube;
QString file = QString(tempDir.path() + "/IsisCube_00.cub");
testCube.setDimensions(10, 10, 1);
testCube.create(file);
testCube.close();
testCube.open(file, "r");
LineManager line(testCube);
double pixelValue = 0.0;
for(int i = 0; i < line.size(); i++) {
line[i] = (double) pixelValue++;
}
try {
testCube.write(line);
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("Cannot write to the cube [IsisCube_00.cub] because it is opened read-only."))
<< e.toString().toStdString();
}
}
TEST(CubeTest, TestCubeOpenNonexistentCube) {
try {
Cube testCube;
testCube.open("blah");
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("Unable to open [blah]."))
<< e.toString().toStdString();
}
}
TEST_F(SmallCube, TestCubePhyscialBandOutOfBounds) {
QString path = testCube->fileName();
testCube->close();
QList<QString> vbands = {"1", "2", "3", "4", "5"};
testCube->setVirtualBands(vbands);
testCube->open(path);
try {
std::cout << testCube->bandCount() << std::endl;
int band = testCube->physicalBand(6);
std::cout << band << std::endl;
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("Out of array bounds [6]."))
<< e.toString().toStdString();
}
try {
testCube->physicalBand(0);
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("Out of array bounds [0]."))
<< e.toString().toStdString();
}
}
TEST(CubeTest, TestCubeReadBlankCube) {
Cube testCube;
testCube.setDimensions(10, 10, 1);
LineManager line(testCube);
try {
testCube.read(line);
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("Try opening a file before you read it."))
<< e.toString().toStdString();
}
}
TEST(CubeTest, TestCubeWriteBlankCube) {
Cube testCube;
testCube.setDimensions(10, 10, 1);
LineManager line(testCube);
double pixelValue = 0.0;
for(int i = 0; i < line.size(); i++) {
line[i] = (double) pixelValue++;
}
try {
testCube.write(line);
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("Tried to write to a cube before opening/creating it."))
<< e.toString().toStdString();
}
}
TEST_F(TempTestingFiles, TestCubeCreateZeroDimCube) {
Cube testCube;
try {
testCube.create(tempDir.path() + "/IsisCube_00.cub");
testCube.close();
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("Number of samples [0], lines [0], or bands [0] cannot be less than 1."))
<< e.toString().toStdString();
}
}
TEST_F(TempTestingFiles, TestCubeCreateSmallLabel) {
Cube testCube;
try {
testCube.setLabelSize(15);
testCube.setDimensions(1, 1, 1);
testCube.create(tempDir.path() + "/IsisCube_00.cub");
testCube.close();
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("Label space is full in [IsisCube_00.cub] unable to write labels."))
<< e.toString().toStdString();
}
}
TEST_F(TempTestingFiles, TestCubeCreateTooBig) {
Cube testCube;
try {
testCube.setDimensions(1000000, 1000000, 9);
testCube.create("IsisCube_00.cub");
testCube.close();
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("The cube you are attempting to create [IsisCube_00.cub] is [33527GB]. "
"This is larger than the current allowed size of [12GB]. The cube "
"dimensions were (S,L,B) [1000000, 1000000, 9] with [4] bytes per pixel. "
"If you still wish to create this cube, the maximum value can be changed "
"in your personal preference file located in [~/.Isis/IsisPreferences] "
"within the group CubeCustomization, keyword MaximumSize. If you do not have "
"an ISISPreference file, please refer to the documentation 'Environment and Preference Setup'. Error."))
<< e.toString().toStdString();
}
}
TEST_F(SmallCube, TestCubeOpenBadAccessor) {
try {
Cube localTestCube;
localTestCube.open(testCube->fileName(), "a");
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("Unknown value for access [a]. Expected 'r' or 'rw'."))
<< e.toString().toStdString();
}
}
TEST(CubeTest, TestCubeInvalidDimSamples) {
try {
Cube testCube;
testCube.setDimensions(0, 1, 1);
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("SetDimensions: Invalid number of sample, lines or bands."))
<< e.toString().toStdString();
}
}
TEST(CubeTest, TestCubeInvalidDimLines) {
try {
Cube testCube;
testCube.setDimensions(1, 0, 1);
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("SetDimensions: Invalid number of sample, lines or bands."))
<< e.toString().toStdString();
}
}
TEST(CubeTest, TestCubeInvalidDimBands) {
try {
Cube testCube;
testCube.setDimensions(1, 1, 0);
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("SetDimensions: Invalid number of sample, lines or bands."))
<< e.toString().toStdString();
}
}
TEST(CubeTest, TestCubeNonePixelType) {
try {
Cube testCube;
testCube.setPixelType(None);
testCube.setDimensions(1, 1, 1);
testCube.create("IsisCube_00.cub");
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("Cannot create the cube [IsisCube_00.cub] with a pixel type set to None."))
<< e.toString().toStdString();
}
}
TEST_F(TempTestingFiles, TestCubeAddGroupReadOnly) {
try {
Cube testCube;
testCube.setDimensions(1024, 1024, 1);
testCube.create(tempDir.path() + "/IsisCube_00.cub");
testCube.reopen("r");
testCube.putGroup(PvlGroup("TestGroup2"));
FAIL() << "Expected an exception to be thrown";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("Cannot add a group to the label of cube [IsisCube_00.cub] because it is opened read-only."))
<< e.toString().toStdString();
}
}
TEST_F(SmallCube, TestCubeCreateECube) {
Cube localTestCube;
QString path = testCube->fileName();
localTestCube.setExternalDnData(path);
localTestCube.create(tempDir.path() + "/isisTruth_external.ecub");
localTestCube.putGroup(PvlGroup("TestGroup"));
EXPECT_EQ(localTestCube.realDataFileName().expanded(), path);
EXPECT_TRUE(localTestCube.hasGroup("TestGroup"));
path = localTestCube.fileName();
check_cube(localTestCube, path, 10, 10, 10, 0, 1, 7, 2, 1, 1, 0, 1, 65536);
}
class ECube : public SmallCube {
protected:
Cube * testECube;
void SetUp() override {
SmallCube::SetUp();
testECube = new Cube();
testECube->setExternalDnData(testCube->fileName());
QString path = tempDir.path() + "/external.ecub";
testECube->create(path);
testECube->close();
testECube->open(path, "rw");
}
void TearDown() override {
if (testECube->isOpen()) {
testECube->close();
}
if (testECube) {
delete testECube;
}
SmallCube::TearDown();
}
};
TEST_F(ECube, TestCubeCreateECubeFromECube) {
QString path1 = testECube->fileName();
Cube localTestCube;
localTestCube.setExternalDnData(path1);
QString path2 = tempDir.path() + "/isisTruth_external2.ecub";
localTestCube.create(path2);
EXPECT_EQ(localTestCube.realDataFileName().expanded(), testCube->fileName());
check_cube(localTestCube, path2, 10, 10, 10, 0, 1, 7, 2, 1, 1, 0, 1, 65536);
}
TEST_F(ECube, TestCubeECubeRead) {
Brick readBrick(3, 3, 2, testECube->pixelType());
readBrick.SetBasePosition(1, 1, 1);
testECube->read(readBrick);
std::vector<int> truth = {0, 1, 2, 10, 11, 12, 20, 21, 22, 100, 101, 102, 110, 111, 112, 120, 121, 122};
for (int index = 0; index < readBrick.size(); index++) {
EXPECT_EQ(readBrick[index], truth[index]);
}
}
TEST_F(ECube, TestCubeECubeWrite) {
Brick writeBrick(3, 3, 2, testECube->pixelType());
writeBrick.SetBasePosition(1, 1, 1);
for (int index = 0; index < writeBrick.size(); index++) {
writeBrick[index] = 1.0;
}
try {
testECube->write(writeBrick);
FAIL();
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("The cube [external.ecub] does not support storing DN data because it is using an external file for DNs."))
<< e.toString().toStdString();
}
}
TEST_F(ECube, TestCubeECubeFromECubeRead) {
QString path1 = testECube->fileName();
Cube localTestCube;
localTestCube.setExternalDnData(path1);
QString path2 = tempDir.path() + "/isisTruth_external2.ecub";
localTestCube.create(path2);
Brick readBrick(3, 3, 2, localTestCube.pixelType());
readBrick.SetBasePosition(1, 1, 1);
localTestCube.read(readBrick);
std::vector<int> truth = {0, 1, 2, 10, 11, 12, 20, 21, 22, 100, 101, 102, 110, 111, 112, 120, 121, 122};
for (int index = 0; index < readBrick.size(); index++) {
EXPECT_EQ(readBrick[index], truth[index]);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment