From 8c88526da8a03fb841a9785da8c6bce27b1e7f0f Mon Sep 17 00:00:00 2001 From: kimkulling Date: Mon, 21 Sep 2020 16:39:24 +0200 Subject: [PATCH 1/2] fix collada unittests. --- code/AssetLib/Collada/ColladaParser.cpp | 6 ++++++ include/assimp/StringUtils.h | 21 +++++++++++++++++++++ test/unit/utColladaExport.cpp | 3 +++ 3 files changed, 30 insertions(+) diff --git a/code/AssetLib/Collada/ColladaParser.cpp b/code/AssetLib/Collada/ColladaParser.cpp index 12cc24797..a5dcab19b 100644 --- a/code/AssetLib/Collada/ColladaParser.cpp +++ b/code/AssetLib/Collada/ColladaParser.cpp @@ -404,6 +404,10 @@ void ColladaParser::PostProcessControllers() { std::string meshId; for (ControllerLibrary::iterator it = mControllerLibrary.begin(); it != mControllerLibrary.end(); ++it) { meshId = it->second.mMeshId; + if (meshId.empty()) { + break; + } + ControllerLibrary::iterator findItr = mControllerLibrary.find(meshId); while (findItr != mControllerLibrary.end()) { meshId = findItr->second.mMeshId; @@ -1404,6 +1408,7 @@ void ColladaParser::ReadDataArray(XmlNode &node) { XmlParser::getUIntAttribute(node, "count", count); std::string v; XmlParser::getValueAsString(node, v); + trim(v); const char *content = v.c_str(); // read values and store inside an array in the data library @@ -1437,6 +1442,7 @@ void ColladaParser::ReadDataArray(XmlNode &node) { ai_real value; // read a number + //SkipSpacesAndLineEnd(&content); content = fast_atoreal_move(content, value); data.mValues.push_back(value); // skip whitespace after it diff --git a/include/assimp/StringUtils.h b/include/assimp/StringUtils.h index 7e1cb4ce0..545a9ff30 100644 --- a/include/assimp/StringUtils.h +++ b/include/assimp/StringUtils.h @@ -52,6 +52,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include +#include +#include /// @fn ai_snprintf /// @brief The portable version of the function snprintf ( C99 standard ), which works on visual studio compilers 2013 and earlier. @@ -162,4 +165,22 @@ AI_FORCE_INLINE std::string Rgba2Hex(int r, int g, int b, int a, bool with_head) return ss.str(); } +inline void ltrim(std::string &s) { + s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { + return !std::isspace(ch); + })); +} + +// trim from end (in place) +inline void rtrim(std::string &s) { + s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { + return !std::isspace(ch); + }).base(), s.end()); +} + +// trim from both ends (in place) +inline void trim(std::string &s) { + ltrim(s); + rtrim(s); +} #endif // INCLUDED_AI_STRINGUTILS_H diff --git a/test/unit/utColladaExport.cpp b/test/unit/utColladaExport.cpp index efb2d7f17..56b24798e 100644 --- a/test/unit/utColladaExport.cpp +++ b/test/unit/utColladaExport.cpp @@ -47,6 +47,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include + #ifndef ASSIMP_BUILD_NO_EXPORT class utColladaExport : public ::testing::Test { @@ -77,6 +79,7 @@ TEST_F(utColladaExport, testExportCamera) { EXPECT_EQ(AI_SUCCESS, ex->Export(pTest, "collada", file)); const unsigned int origNumCams(pTest->mNumCameras); + //std::vector origFOV; std::unique_ptr origFOV(new float[origNumCams]); std::unique_ptr orifClipPlaneNear(new float[origNumCams]); std::unique_ptr orifClipPlaneFar(new float[origNumCams]); From 71f20eaa8a4773696e467612346a13e2c184a848 Mon Sep 17 00:00:00 2001 From: kimkulling Date: Tue, 22 Sep 2020 15:51:21 +0200 Subject: [PATCH 2/2] next fixes --- code/AssetLib/Collada/ColladaParser.cpp | 2 ++ test/unit/utIssues.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/code/AssetLib/Collada/ColladaParser.cpp b/code/AssetLib/Collada/ColladaParser.cpp index 595b8daf2..01103ddf8 100644 --- a/code/AssetLib/Collada/ColladaParser.cpp +++ b/code/AssetLib/Collada/ColladaParser.cpp @@ -316,6 +316,8 @@ void ColladaParser::ReadAssetInfo(XmlNode &node) { } } else if (name == "contributor") { ReadMetaDataItem(currentNode, mAssetMetaData); + } else { + ReadMetaDataItem(currentNode, mAssetMetaData); } } } diff --git a/test/unit/utIssues.cpp b/test/unit/utIssues.cpp index 2083c15b1..d0ea284b9 100644 --- a/test/unit/utIssues.cpp +++ b/test/unit/utIssues.cpp @@ -52,7 +52,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; class utIssues : public ::testing::Test { - + // empty }; #ifndef ASSIMP_BUILD_NO_EXPORT