From 7e8a3ec4cbdedf85d21c6dc994c3fed7bd1c4e6e Mon Sep 17 00:00:00 2001 From: RichardTea <31507749+RichardTea@users.noreply.github.com> Date: Thu, 25 Jul 2019 13:38:49 +0100 Subject: [PATCH] Add unit test of valid and unique Exporter IDs, rename assjson id "json" is a very vague exporter ID, change to "assjson" Add a unit test to ensure all exporter have unique IDs and that they all have an ID, description and extension --- code/Assjson/json_exporter.cpp | 9 ------ code/Common/Exporter.cpp | 6 ++-- .../ImportExport/utAssjsonImportExport.cpp | 2 +- test/unit/ImportExport/utExporter.cpp | 29 +++++++++++++++++++ 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/code/Assjson/json_exporter.cpp b/code/Assjson/json_exporter.cpp index cd542b29e..e9fa72496 100644 --- a/code/Assjson/json_exporter.cpp +++ b/code/Assjson/json_exporter.cpp @@ -34,15 +34,6 @@ namespace Assimp { void ExportAssimp2Json(const char*, Assimp::IOSystem*, const aiScene*, const Assimp::ExportProperties*); -Exporter::ExportFormatEntry Assimp2Json_desc = Assimp::Exporter::ExportFormatEntry( - "json", - "Plain JSON representation of the Assimp scene data structure", - "json", - &ExportAssimp2Json, - 0u -); - - // small utility class to simplify serializing the aiScene to Json class JSONWriter { public: diff --git a/code/Common/Exporter.cpp b/code/Common/Exporter.cpp index 87745bca9..acff29399 100644 --- a/code/Common/Exporter.cpp +++ b/code/Common/Exporter.cpp @@ -167,7 +167,7 @@ Exporter::ExportFormatEntry gExporters[] = #endif #ifndef ASSIMP_BUILD_NO_ASSXML_EXPORTER - Exporter::ExportFormatEntry( "assxml", "Assxml Document", "assxml" , &ExportSceneAssxml, 0 ), + Exporter::ExportFormatEntry( "assxml", "Assimp XML Document", "assxml" , &ExportSceneAssxml, 0 ), #endif #ifndef ASSIMP_BUILD_NO_X3D_EXPORTER @@ -183,8 +183,8 @@ Exporter::ExportFormatEntry gExporters[] = Exporter::ExportFormatEntry( "3mf", "The 3MF-File-Format", "3mf", &ExportScene3MF, 0 ), #endif -#ifndef ASSIMP_BUILD_NO_Assjson_EXPORTER - Exporter::ExportFormatEntry("json", "Plain JSON representation of the Assimp scene data structure", "json", &ExportAssimp2Json, 0) +#ifndef ASSIMP_BUILD_NO_ASSJSON_EXPORTER + Exporter::ExportFormatEntry( "assjson", "Assimp JSON Document", "json", &ExportAssimp2Json, 0) #endif }; diff --git a/test/unit/ImportExport/utAssjsonImportExport.cpp b/test/unit/ImportExport/utAssjsonImportExport.cpp index 20a2a9e24..82dbf8b57 100644 --- a/test/unit/ImportExport/utAssjsonImportExport.cpp +++ b/test/unit/ImportExport/utAssjsonImportExport.cpp @@ -57,7 +57,7 @@ public: const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/OBJ/spider.obj", aiProcess_ValidateDataStructure); Exporter exporter; - aiReturn res = exporter.Export(scene, "json", "./spider_test.json"); + aiReturn res = exporter.Export(scene, "assjson", "./spider_test.json"); return aiReturn_SUCCESS == res; } }; diff --git a/test/unit/ImportExport/utExporter.cpp b/test/unit/ImportExport/utExporter.cpp index c46a55b00..4635be2a4 100644 --- a/test/unit/ImportExport/utExporter.cpp +++ b/test/unit/ImportExport/utExporter.cpp @@ -71,3 +71,32 @@ TEST_F(ExporterTest, ProgressHandlerTest) { TestProgressHandler *ph(new TestProgressHandler); exporter.SetProgressHandler(ph); } + +// Make sure all the registered exporters have useful descriptions +TEST_F(ExporterTest, ExporterIdTest) { + Exporter exporter; + size_t exportFormatCount = exporter.GetExportFormatCount(); + EXPECT_NE(0, exportFormatCount) << "No registered exporters"; + typedef std::map ExportIdMap; + ExportIdMap exporterMap; + for (size_t i = 0; i < exportFormatCount; ++i) + { + // Check that the exporter description exists and makes sense + const aiExportFormatDesc* desc = exporter.GetExportFormatDescription(i); + ASSERT_NE(nullptr, desc) << "Missing aiExportFormatDesc at index " << i; + EXPECT_NE(nullptr, desc->id) << "Null exporter ID at index " << i; + EXPECT_STRNE("", desc->id) << "Empty exporter ID at index " << i; + EXPECT_NE(nullptr, desc->description) << "Null exporter description at index " << i; + EXPECT_STRNE("", desc->description) << "Empty exporter description at index " << i; + EXPECT_NE(nullptr, desc->fileExtension) << "Null exporter file extension at index " << i; + EXPECT_STRNE("", desc->fileExtension) << "Empty exporter file extension at index " << i; + + // Check the ID is unique + std::string key(desc->id); + std::pair result = exporterMap.emplace(key, desc); + EXPECT_TRUE(result.second) << "Duplicate exported id: '" << key << "' " << desc->description << " *." << desc->fileExtension << " at index " << i; + } + + const aiExportFormatDesc* desc = exporter.GetExportFormatDescription(exportFormatCount); + EXPECT_EQ(nullptr, desc) << "More exporters than claimed"; +}