Skip to content

Commit df141c2

Browse files
committed
TEST: fix failing unit tests
1 parent ac4a6ba commit df141c2

2 files changed

Lines changed: 41 additions & 17 deletions

File tree

Source/Test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ if(EBSDLIB_DOWNLOAD_TEST_FILES)
7979
endif()
8080

8181
ebsdlib_download_test_data(EBSDLIB_DATA_DIR ${EBSDLIB_DATA_DIR} ARCHIVE_NAME Laue_Orientation_Clusters_v6.tar.gz SHA512 f327d3d2a86d539b3c1f3fc755d8f5741d8eb68aab45fc1ab54d9e5db48643903f9a37898366203e6eb2e7585ce57c6e186cca2107acb1a53318b813345cb10a)
82-
ebsdlib_download_test_data(EBSDLIB_DATA_DIR ${EBSDLIB_DATA_DIR} ARCHIVE_NAME Pole_Figure_Images.tar.gz SHA512 c3111bd3dcb89ec3ddcfcee4792bb7a9a1815475ac3f9a70bd93915c2a6dbbdcc9091dfe5ddb064a655758d77f9718c1661dd2005bcc60502ba336e40eb205a1)
82+
ebsdlib_download_test_data(EBSDLIB_DATA_DIR ${EBSDLIB_DATA_DIR} ARCHIVE_NAME Pole_Figure_Images.tar.gz SHA512 fe395dbc05c5408e806b6271873a21a9cef343c940126fed682233b21a793d6e62b3d33a4ac2a77bf5789c514187a595798e823f1f1fd7f71360fdea6e6500e8)
8383

8484
endif()
8585

Source/Test/PoleFigureCompositorTest.cpp

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ void GeneratePoleFigures(const std::string& phaseName, size_t opsIndex, hid_t ex
107107
{
108108
std::string layoutStr = (layoutType == PoleFigureLayoutType::Horizontal) ? "Horz" : (layoutType == PoleFigureLayoutType::Vertical) ? "Vert" : "Sqr";
109109
hid_t layoutGroupId = H5Support::H5Utilities::createGroup(exemplarFileId, layoutStr);
110+
REQUIRE(layoutGroupId > 0);
110111
H5Support::H5ScopedGroupSentinel layoutGroupSentinel(layoutGroupId, true);
111112

112113
for(size_t sampleId = 0; sampleId < k_NumSamplingGroups; ++sampleId)
@@ -157,22 +158,32 @@ void GeneratePoleFigures(const std::string& phaseName, size_t opsIndex, hid_t ex
157158
REQUIRE(result.height == metrics.pageHeight);
158159

159160
UInt8ArrayType::Pointer image = result.image;
160-
// std::string outputPath = fmt::format("{}/Pole_Figure_Images/Pole_Figure_{}_{}_{}.tif", ebsdlib::unit_test::k_TestFilesDir, layoutStr,op->getRotationPointGroup() , sampleId);
161-
// auto writerResult = TiffWriter::WriteColorImage(outputPath, result.width, result.height, 4, result.image->data());
162-
// REQUIRE(writerResult.first == 0);
163-
//
164161
std::string datasetName = fmt::format("{}", sampleId);
165-
// std::vector<hsize_t> dims = {static_cast<hsize_t>(result.height), static_cast<hsize_t>(result.width), 4ULL};
166-
// herr_t err = H5Support::H5Lite::writePointerDataset(layoutGroupId, datasetName, dims.size(), dims.data(), result.image->data());
167-
// REQUIRE(err == 0);
162+
#if WRITE_EXEMPLAR_IMAGES
163+
std::string outputPath = fmt::format("{}/Pole_Figure_Images/Pole_Figure_{}_{}_{}.tif", ebsdlib::unit_test::k_TestFilesDir, layoutStr,op->getRotationPointGroup() , sampleId);
164+
auto writerResult = TiffWriter::WriteColorImage(outputPath, result.width, result.height, 4, result.image->data());
165+
REQUIRE(writerResult.first == 0);
166+
//
167+
168+
std::vector<hsize_t> dims = {static_cast<hsize_t>(result.height), static_cast<hsize_t>(result.width), 4ULL};
169+
herr_t err = H5Support::H5Lite::writePointerDataset(layoutGroupId, datasetName, dims.size(), dims.data(), result.image->data());
170+
REQUIRE(err == 0);
171+
#else
172+
168173
std::vector<uint8_t> exemplarData;
169174
err = H5Support::H5Lite::readVectorDataset(layoutGroupId, datasetName, exemplarData);
170175
REQUIRE(err == 0);
171176
REQUIRE(exemplarData.size() == static_cast<size_t>(result.width * result.height * 4));
177+
size_t misMatchCount = 0;
172178
for(size_t i = 0; i < exemplarData.size(); i++)
173179
{
174-
REQUIRE(exemplarData[i] == (*image)[i]);
180+
if(exemplarData[i] != (*image)[i])
181+
{
182+
misMatchCount++;
183+
}
175184
}
185+
REQUIRE(misMatchCount == 0);
186+
#endif
176187
}
177188
}
178189
}
@@ -181,19 +192,29 @@ void GeneratePoleFigures(const std::string& phaseName, size_t opsIndex, hid_t ex
181192
TEST_CASE("ebsdlib::PoleFigureCompositorTest::All_Laue_Classes", "[EbsdLib][PoleFigureCompositorTest]")
182193
{
183194
const ebsdlib::unit_test::TestFileSentinel testDataSentinel(ebsdlib::unit_test::k_TestFilesDir, "Laue_Orientation_Clusters_v6.tar.gz", "Laue_Orientation_Clusters_v6", true, true);
184-
const ebsdlib::unit_test::TestFileSentinel testDataSentinel1(ebsdlib::unit_test::k_TestFilesDir, "Pole_Figure_Images.tar.gz", "Pole_Figure_Images", true, true);
195+
const ebsdlib::unit_test::TestFileSentinel testDataSentinel1(ebsdlib::unit_test::k_TestFilesDir, "Pole_Figure_Images.tar.gz", "Pole_Figure_Images"
196+
#if WRITE_EXEMPLAR_IMAGES
197+
, false, false
198+
#endif
199+
);
185200

186201
const std::string hdfInputFile = fmt::format("{}/Pole_Figure_Images/Exemplar_Data.h5", ebsdlib::unit_test::k_TestFilesDir);
187202
hid_t fileId = -1;
188-
// if(!std::filesystem::exists(hdfInputFile))
189-
// {
190-
// fileId = H5Support::H5Utilities::createFile(hdfInputFile);
191-
// }
192-
// else
203+
#if WRITE_EXEMPLAR_IMAGES
204+
if(!std::filesystem::exists(hdfInputFile))
205+
{
206+
std::cout << "Creating " << hdfInputFile << std::endl;
207+
fileId = H5Support::H5Utilities::createFile(hdfInputFile);
208+
}
209+
else
210+
#else
193211
{
212+
std::cout << "Opening " << hdfInputFile << std::endl;
194213
fileId = H5Support::H5Utilities::openFile(hdfInputFile, true);
195214
}
196-
H5Support::H5ScopedFileSentinel fileSentinel(fileId, true);
215+
#endif
216+
REQUIRE(fileId > 0);
217+
H5Support::H5ScopedFileSentinel fileSentinel(fileId, false);
197218

198219
std::vector<LaueOps::Pointer> ops = LaueOps::GetAllOrientationOps();
199220

@@ -210,10 +231,13 @@ TEST_CASE("ebsdlib::PoleFigureCompositorTest::All_Laue_Classes", "[EbsdLib][Pole
210231
tested.insert(rpg);
211232

212233
hid_t layoutGroupId = H5Support::H5Utilities::createGroup(fileId, rpg);
213-
H5Support::H5ScopedGroupSentinel layoutGroupSentinel(layoutGroupId, true);
234+
REQUIRE(layoutGroupId > 0);
235+
H5Support::H5ScopedGroupSentinel layoutGroupSentinel(layoutGroupId, false);
214236

215237
const std::string phaseName = fmt::format("Laue_{}", rpg);
238+
#if !WRITE_EXEMPLAR_IMAGES
216239
SECTION(phaseName + " VMF")
240+
#endif
217241
{
218242
GeneratePoleFigures(phaseName, opsIdx, layoutGroupId);
219243
}

0 commit comments

Comments
 (0)