diff --git a/Modules/IO/TestKernel/include/otbTestHelper.h b/Modules/IO/TestKernel/include/otbTestHelper.h index fe7c39636c5c9e526375809afc8890ac477e6e0a..7cb7b0c308fa5c62324931f2f444a65b4f91a18f 100644 --- a/Modules/IO/TestKernel/include/otbTestHelper.h +++ b/Modules/IO/TestKernel/include/otbTestHelper.h @@ -161,7 +161,7 @@ private: void ogrReportOnLayer(OGRLayer * ref_poLayer, const char *ref_pszWHERE, OGRGeometry *ref_poSpatialFilter, OGRLayer * test_poLayer, const char *test_pszWHERE, OGRGeometry *test_poSpatialFilter, - int& nbdiff) const; + int& nbdiff, double epsilon) const; static void DumpOGRFeature(FILE* fileid, OGRFeature* feature, char** papszOptions = nullptr); static void DumpOGRGeometry(FILE* fileid, OGRGeometry* geometry, const char * pszPrefix, char** papszOptions = nullptr); @@ -175,6 +175,8 @@ private: void AddWhiteSpace(const std::string& strIn, std::string &strOut) const; + void CheckValueTolerance(const char *Comment, double ref, double test, int &count, bool report, double epsilon) 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 5f47f2f3c7f9fa7c694c1e9c15c4eeb073b754a0..e44e24d1d0395af8c988c3d946aa1e188dcb2b60 100644 --- a/Modules/IO/TestKernel/src/otbTestHelper.cxx +++ b/Modules/IO/TestKernel/src/otbTestHelper.cxx @@ -92,6 +92,19 @@ namespace otb { +void TestHelper::CheckValueTolerance(const char *comment, double ref, double test, int &count, bool report, double epsilon) const +{ + double norm = (std::abs(ref) + std::abs(test))/2; + if (norm > m_EpsilonBoundaryChecking && (std::abs(ref-test) > epsilon * norm)) + { + count++; + if (report) + { + otbPrintDiff(comment, ref, test); + } + } +} + int TestHelper::RegressionTestAllImages(const StringList& baselineFilenamesImage, const StringList& testFilenamesImage) { @@ -1847,7 +1860,7 @@ int TestHelper::RegressionTestOgrFile(const char *testOgrFilename, const char *b } //Check Layer inforamtion - ogrReportOnLayer(ref_poLayer, nullptr, nullptr, test_poLayer, nullptr, nullptr, nbdiff); + ogrReportOnLayer(ref_poLayer, nullptr, nullptr, test_poLayer, nullptr, nullptr, nbdiff, toleranceDiffValue); //If no difference, check the feature if (nbdiff == 0) @@ -2534,7 +2547,8 @@ void TestHelper::ogrReportOnLayer(OGRLayer * ref_poLayer, OGRLayer * test_poLayer, const char *test_pszWHERE, OGRGeometry *test_poSpatialFilter, - int& nbdiff) const + int& nbdiff, + double epsilon) const { OGRFeatureDefn *ref_poDefn = ref_poLayer->GetLayerDefn(); @@ -2573,10 +2587,10 @@ void TestHelper::ogrReportOnLayer(OGRLayer * ref_poLayer, if (ref_poLayer->GetExtent(&ref_oExt, TRUE) == OGRERR_NONE) { - otbCheckValue("Extent: MinX", ref_oExt.MinX, test_oExt.MinX, nbdiff, m_ReportErrors); - otbCheckValue("Extent: MinY", ref_oExt.MinY, test_oExt.MinY, nbdiff, m_ReportErrors); - otbCheckValue("Extent: MaxX", ref_oExt.MaxX, test_oExt.MaxX, nbdiff, m_ReportErrors); - otbCheckValue("Extent: MaxY", ref_oExt.MaxY, test_oExt.MaxY, nbdiff, m_ReportErrors); + CheckValueTolerance("Extent: MinX", ref_oExt.MinX, test_oExt.MinX, nbdiff, m_ReportErrors, epsilon); + CheckValueTolerance("Extent: MinY", ref_oExt.MinY, test_oExt.MinY, nbdiff, m_ReportErrors, epsilon); + CheckValueTolerance("Extent: MaxX", ref_oExt.MaxX, test_oExt.MaxX, nbdiff, m_ReportErrors, epsilon); + CheckValueTolerance("Extent: MaxY", ref_oExt.MaxY, test_oExt.MaxY, nbdiff, m_ReportErrors, epsilon); } char *ref_pszWKT;