diff --git a/Modules/IO/TestKernel/include/otbTestHelper.h b/Modules/IO/TestKernel/include/otbTestHelper.h index 89abc453f7f59b537d383da9cfa9b1e6a3959019..898d5e1bf771b226452af5b2c538190e3a6e0237 100644 --- a/Modules/IO/TestKernel/include/otbTestHelper.h +++ b/Modules/IO/TestKernel/include/otbTestHelper.h @@ -65,7 +65,10 @@ public: m_ReportErrors(false), m_IgnoreLineOrder(false), m_MaxArea(1024*1024) - {} + { + m_SpecialTokens.push_back(std::pair<std::string,std::string>( + std::string("Integer"),std::string("Integer64"))); + } ~TestHelper() ITK_OVERRIDE{} @@ -170,6 +173,8 @@ private: const unsigned int m_MaxArea; void AddWhiteSpace(const std::string& strIn, std::string &strOut) const; + + std::vector<std::pair<std::string, std::string> > m_SpecialTokens; }; } diff --git a/Modules/IO/TestKernel/src/otbTestHelper.cxx b/Modules/IO/TestKernel/src/otbTestHelper.cxx index cc26c683f2c4bd2c765e1e8e80b7ac94687ed7d3..8f5c675a40b30880eb38f2e49429259f7010b0a4 100644 --- a/Modules/IO/TestKernel/src/otbTestHelper.cxx +++ b/Modules/IO/TestKernel/src/otbTestHelper.cxx @@ -796,92 +796,108 @@ int TestHelper::RegressionTestDiffFile(const char * testAsciiFileName, const cha break; } // ----------- comparing current token -------------------- - double vTest; - double vRef; - double vNorm; - // test if hexadecimal adress - bool isRefTokenHexa = isHexaPointerAddress( - curLineRef, - tokenRef[i].begin()-curLineRef.begin(), - tokenRef[i].size()); - bool isTestTokenHexa = isHexaPointerAddress( - curLineTest, - tokenTest[i].begin()-curLineTest.begin(), - tokenTest[i].size()); - // cast ref token - bool isRefTokenNum = true; - try - { - vRef = boost::lexical_cast<double>(tokenRef[i]); - // record the first numeric token position - if (firstNumericToken<0) - { - firstNumericToken = static_cast<int>(i); - } - } - catch (boost::bad_lexical_cast &) + bool areTokensEquivalent = false; + // first : try direct string comparison + if (curLineRef.compare( + tokenRef[i].begin() - curLineRef.begin(), + tokenRef[i].size(), + curLineTest, + tokenTest[i].begin() - curLineTest.begin(), + tokenTest[i].size()) == 0) { - isRefTokenNum = false; + areTokensEquivalent = true; } - // cast test token - bool isTestTokenNum = true; - try - { - vTest = boost::lexical_cast<double>(tokenTest[i]); - } - catch (boost::bad_lexical_cast &) - { - isTestTokenNum = false; - } - - if (isRefTokenHexa && isTestTokenHexa) - { - // these tokens are equivalent (we don't compare pointer adress) - if (differencesPos.empty()) - { - firstCommonTokens++; - } - commonTokens++; - } - else if (isRefTokenNum && isTestTokenNum) + else { - // test difference against epsilon - vNorm = (vcl_abs(vRef) + vcl_abs(vTest)) * 0.5; - if ((vNorm > m_EpsilonBoundaryChecking) //make sure that either the test of the ref are non 0 - && (vcl_abs(vRef-vTest) > epsilon * vNorm)) //epsilon as relative error + // examine other cases : + // test if hexadecimal adress + bool isRefTokenHexa = isHexaPointerAddress( + curLineRef, + tokenRef[i].begin()-curLineRef.begin(), + tokenRef[i].size()); + bool isTestTokenHexa = isHexaPointerAddress( + curLineTest, + tokenTest[i].begin()-curLineTest.begin(), + tokenTest[i].size()); + if (isRefTokenHexa && isTestTokenHexa) { - // record different numeric token - differencesPos.push_back(i); + // these tokens are equivalent (we don't compare pointer adress) + areTokensEquivalent = true; } else { - // these tokens are equivalent - commonTokens++; - if (differencesPos.empty()) + double vTest; + double vRef; + double vNorm; + // cast ref token + bool isRefTokenNum = true; + try + { + vRef = boost::lexical_cast<double>(tokenRef[i]); + // record the first numeric token position + if (firstNumericToken<0) + { + firstNumericToken = static_cast<int>(i); + } + } + catch (boost::bad_lexical_cast &) { - firstCommonTokens++; + isRefTokenNum = false; } - } - } - else - { - if (curLineRef.compare(tokenRef[i].begin() - curLineRef.begin(), - tokenRef[i].size(), - curLineTest, - tokenTest[i].begin() - curLineTest.begin(), - tokenTest[i].size()) == 0) - { - commonTokens++; - if (differencesPos.empty()) + // cast test token + bool isTestTokenNum = true; + try { - firstCommonTokens++; + vTest = boost::lexical_cast<double>(tokenTest[i]); + } + catch (boost::bad_lexical_cast &) + { + isTestTokenNum = false; + } + if (isRefTokenNum && isTestTokenNum) + { + // test difference against epsilon + vNorm = (vcl_abs(vRef) + vcl_abs(vTest)) * 0.5; + if ((vNorm <= m_EpsilonBoundaryChecking) //make sure that either the test of the ref are non 0 + || (vcl_abs(vRef-vTest) <= epsilon * vNorm)) //epsilon as relative error + { + // these tokens are equivalent + areTokensEquivalent = true; + } + } + else + { + // test for special tokens + for (unsigned int j=0 ; j<m_SpecialTokens.size() ; j++) + { + if (curLineRef.compare( + tokenRef[i].begin() - curLineRef.begin(), + tokenRef[i].size(), + m_SpecialTokens[j].first) == 0 && + curLineTest.compare( + tokenTest[i].begin() - curLineTest.begin(), + tokenTest[i].size(), + m_SpecialTokens[j].second) == 0) + { + areTokensEquivalent = true; + break; + } + } } } - else + } + if (areTokensEquivalent) + { + commonTokens++; + if (differencesPos.empty()) { - differencesPos.push_back(i); + firstCommonTokens++; } } + else + { + differencesPos.push_back(i); + } } // finish iteration of all tokens from reference line to detect first numeric token for (unsigned int i = std::min(nbTokenRef,nbTokenTest) ; i < nbTokenRef ; i++)