Skip to content

Commit

Permalink
Cleanup unit tests that export files by making sure those files are d…
Browse files Browse the repository at this point in the history
…eleted once the unit test is complete. Moved logging from a .txt to a .log file so that git ignores the files (assimp#5852)

Signed-off-by: AMZN-Gene <[email protected]>
Co-authored-by: Kim Kulling <[email protected]>
  • Loading branch information
AMZN-Gene and kimkulling authored Oct 30, 2024
1 parent 287d7ec commit ec56382
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
15 changes: 13 additions & 2 deletions test/unit/ImportExport/utAssjsonImportExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,29 @@ class utAssjsonImportExport : public AbstractImportExportBase {
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/OBJ/spider.obj", aiProcess_ValidateDataStructure);

Exporter exporter;
aiReturn res = exporter.Export(scene, "assjson", "./spider_test.json");
const char *testFileName = "./spider_test.json";
aiReturn res = exporter.Export(scene, "assjson", testFileName);
if (aiReturn_SUCCESS != res) {
return false;
}

Assimp::ExportProperties exportProperties;
exportProperties.SetPropertyBool("JSON_SKIP_WHITESPACES", true);
aiReturn resNoWhitespace = exporter.Export(scene, "assjson", "./spider_test_nowhitespace.json", 0u, &exportProperties);
const char *testNoWhitespaceFileName = "./spider_test_nowhitespace.json";
aiReturn resNoWhitespace = exporter.Export(scene, "assjson", testNoWhitespaceFileName, 0u, &exportProperties);
if (aiReturn_SUCCESS != resNoWhitespace) {
return false;
}

// Cleanup, remove generated json
if (0 != std::remove(testFileName)) {
return false;
}

if (0 != std::remove(testNoWhitespaceFileName)) {
return false;
}

return true;
}
};
Expand Down
4 changes: 2 additions & 2 deletions test/unit/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ int main(int argc, char *argv[]) {
// ............................................................................

// create a logger from both CPP
Assimp::DefaultLogger::create("AssimpLog_Cpp.txt", Assimp::Logger::VERBOSE,
Assimp::DefaultLogger::create("AssimpLog_Cpp.log", Assimp::Logger::VERBOSE,
aiDefaultLogStream_STDOUT | aiDefaultLogStream_DEBUGGER | aiDefaultLogStream_FILE);

// .. and C. They should smoothly work together
aiEnableVerboseLogging(AI_TRUE);
aiLogStream logstream = aiGetPredefinedLogStream(aiDefaultLogStream_FILE, "AssimpLog_C.txt");
aiLogStream logstream = aiGetPredefinedLogStream(aiDefaultLogStream_FILE, "AssimpLog_C.log");
aiAttachLogStream(&logstream);

int result = RUN_ALL_TESTS();
Expand Down
6 changes: 6 additions & 0 deletions test/unit/utColladaExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ TEST_F(utColladaExport, testExportCamera) {
EXPECT_FLOAT_EQ(pos[i].y, read->mPosition.y);
EXPECT_FLOAT_EQ(pos[i].z, read->mPosition.z);
}

// Cleanup, delete the exported file
EXPECT_EQ(0, std::remove(file));
}

// ------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -220,6 +223,9 @@ TEST_F(utColladaExport, testExportLight) {
EXPECT_NEAR(orig->mAngleInnerCone, read->mAngleInnerCone, 0.001);
EXPECT_NEAR(orig->mAngleOuterCone, read->mAngleOuterCone, 0.001);
}

// Cleanup, delete the exported file
EXPECT_EQ(0, std::remove(file));
}

#endif // ASSIMP_BUILD_NO_EXPORT
3 changes: 3 additions & 0 deletions test/unit/utIssues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ TEST_F( utIssues, OpacityBugWhenExporting_727 ) {
EXPECT_FLOAT_EQ( opacity, newOpacity );
}
delete scene;

// Cleanup. Delete exported dae.dae file
EXPECT_EQ(0, std::remove(path.c_str()));
}

#endif // ASSIMP_BUILD_NO_EXPORT
14 changes: 11 additions & 3 deletions test/unit/utSTLImportExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,14 @@ TEST_F(utSTLImporterExporter, exporterTest) {
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/STL/Spider_ascii.stl", aiProcess_ValidateDataStructure);

Assimp::Exporter mAiExporter;
mAiExporter.Export(scene, "stl", "spiderExport.stl");
const char *stlFileName = "spiderExport.stl";
mAiExporter.Export(scene, "stl", stlFileName);

const aiScene *scene2 = importer.ReadFile("spiderExport.stl", aiProcess_ValidateDataStructure);
const aiScene *scene2 = importer.ReadFile(stlFileName, aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene2);

// Cleanup, delete the exported file
std::remove(stlFileName);
}

TEST_F(utSTLImporterExporter, test_export_pointclouds) {
Expand Down Expand Up @@ -162,8 +166,12 @@ TEST_F(utSTLImporterExporter, test_export_pointclouds) {
Assimp::Exporter mAiExporter;
ExportProperties *properties = new ExportProperties;
properties->SetPropertyBool(AI_CONFIG_EXPORT_POINT_CLOUDS, true);
mAiExporter.Export(&scene, "stl", "testExport.stl", 0, properties);

const char *stlFileName = "testExport.stl";
mAiExporter.Export(&scene, "stl", stlFileName, 0, properties);

// Cleanup, delete the exported file
::remove(stlFileName);
delete properties;
}

Expand Down

0 comments on commit ec56382

Please sign in to comment.