Commit 9c447ed1 authored by Cédric Traizet's avatar Cédric Traizet

ENH: added the possibility of providing a list of keys that should not be...

ENH: added the possibility of providing a list of keys that should not be tested in CompareMetadataDict and don't test TileHints and datatype in RegressionTestMetaData()
parent fd3bf036
Pipeline #5958 passed with stages
in 93 minutes and 32 seconds
......@@ -1420,13 +1420,27 @@ int TestHelper::RegressionTestImage(int cpt, const char* testImageFilename, cons
namespace
{
template <class InputIt1, class InputIt2, class BinaryPredicate >
int CompareMetadataDict( InputIt1 first1, InputIt1 last1,
InputIt2 first2, InputIt2 last2,
/** \fn CompareMetadataDict
\brief Compare two metadata dictionaries key by key. Dictionaries are assumed to be associative containers (e.g. std::map)
\param[in] baselineMap : reference metadata dictionary
\param[in] testMap : metadata dictionary to be compared
\param[in] reportErrors : print difference between dictionaries into srd::cerr
\param[in] untestedKeys : list of keys that should be ignored during comparison
\param[in] p bianry predicate used to compare elements (mapped type) of the two input maps
\return number of different elements.
*/
template <class MapType, class BinaryPredicate >
int CompareMetadataDict( const MapType & baselineMap,
const MapType & testMap,
bool reportErrors,
std::vector< typename MapType::key_type> untestedKeys,
const BinaryPredicate & p)
{
auto first1 = testMap.begin();
auto last1 = testMap.end();
auto first2 = baselineMap.begin();
auto last2 = baselineMap.end();
if (std::distance(first1, last1) != std::distance(first2, last2))
{
if (reportErrors)
......@@ -1441,34 +1455,38 @@ int CompareMetadataDict( InputIt1 first1, InputIt1 last1,
while (first1 != last1)
{
if (first1->first != first2->first)
if (std::find(untestedKeys.begin(), untestedKeys.end(), first1->first) == untestedKeys.end())
//if (first1->first != untestedKeys)
{
errorCount++;
if (reportErrors)
if (first1->first != first2->first)
{
std::cerr << "Metadata key " << otb::MetaData::EnumToString(first1->first)
<< " does not match between test and baseline images: "
<< std::endl;
errorCount++;
if (reportErrors)
{
std::cerr << "Metadata key " << otb::MetaData::EnumToString(first1->first)
<< " does not match between test and baseline images: "
<< std::endl;
}
return errorCount;
}
return errorCount;
}
if (!p(first1->second, first2->second))
{
errorCount++;
if (reportErrors)
std::cerr << "Metadata " << otb::MetaData::EnumToString(first1->first)
<< " does not match between test and baseline images: "
<< std::endl
<< "Baseline image: "
<< first1->second
<< std::endl
<< "Test image: "
<< first2->second
<< std::endl;
if (!p(first1->second, first2->second))
{
errorCount++;
if (reportErrors)
std::cerr << "Metadata " << otb::MetaData::EnumToString(first1->first)
<< " does not match between test and baseline images: "
<< std::endl
<< "Baseline image: "
<< first1->second
<< std::endl
<< "Test image: "
<< first2->second
<< std::endl;
}
}
++first1;
++first2;
}
......@@ -1477,16 +1495,19 @@ int CompareMetadataDict( InputIt1 first1, InputIt1 last1,
}
template <class InputIt1, class InputIt2 >
int CompareMetadataDict( InputIt1 first1, InputIt1 last1,
InputIt2 first2, InputIt2 last2,
bool reportErrors)
template <class MapType>
int CompareMetadataDict( const MapType & baselineMap,
const MapType & testMap,
bool reportErrors,
std::vector< typename MapType::key_type> untestedKeys)
{
auto p = []( const decltype(first1->second) & rhs,
const decltype(first2->second) & lhs)
auto p = []( const typename MapType::mapped_type & rhs,
const typename MapType::mapped_type & lhs)
{return rhs == lhs;};
return CompareMetadataDict(first1, last1, first2, last2, reportErrors, p);
return CompareMetadataDict(baselineMap, testMap, reportErrors, untestedKeys, p);
}
}
int TestHelper::RegressionTestMetaData(const char* testImageFilename, const char* baselineImageFilename, const double tolerance) const
......@@ -1660,52 +1681,48 @@ int TestHelper::RegressionTestMetaData(const char* testImageFilename, const char
const auto & testImageMetadata = testImPtr->GetImageMetadata();
// Compare string keys (strict equality)
errcount += CompareMetadataDict(baselineImageMetadata.StringKeys.begin(),
baselineImageMetadata.StringKeys.end(),
testImageMetadata.StringKeys.begin(),
testImageMetadata.StringKeys.end(),
m_ReportErrors);
errcount += CompareMetadataDict(baselineImageMetadata.StringKeys,
testImageMetadata.StringKeys,
m_ReportErrors,
{});
// Compare numeric keys
auto compareDouble = [tolerance](double lhs, double rhs)
{return fabs(lhs - rhs)
<= ( (fabs(lhs) < fabs(rhs) ? fabs(rhs) : fabs(lhs)) * tolerance);};
errcount += CompareMetadataDict(baselineImageMetadata.NumericKeys.begin(),
baselineImageMetadata.NumericKeys.end(),
testImageMetadata.NumericKeys.begin(),
testImageMetadata.NumericKeys.end(),
// Don't test TileHints and datatype, as these metadata are written by gdal drivers, not otb.
std::vector<MDNum> untestedMDNum = {MDNum::TileHintX, MDNum::TileHintY, MDNum::DataType};
errcount += CompareMetadataDict(baselineImageMetadata.NumericKeys,
testImageMetadata.NumericKeys,
m_ReportErrors,
untestedMDNum,
compareDouble);
// Compare time keys (strict equality)
errcount += CompareMetadataDict(baselineImageMetadata.TimeKeys.begin(),
baselineImageMetadata.TimeKeys.end(),
testImageMetadata.TimeKeys.begin(),
testImageMetadata.TimeKeys.end(),
m_ReportErrors);
errcount += CompareMetadataDict(baselineImageMetadata.TimeKeys,
testImageMetadata.TimeKeys,
m_ReportErrors,
{});
// Compare LUTs (strict equality)
errcount += CompareMetadataDict(baselineImageMetadata.LUT1DKeys.begin(),
baselineImageMetadata.LUT1DKeys.end(),
testImageMetadata.LUT1DKeys.begin(),
testImageMetadata.LUT1DKeys.end(),
m_ReportErrors);
errcount += CompareMetadataDict(baselineImageMetadata.LUT1DKeys,
testImageMetadata.LUT1DKeys,
m_ReportErrors,
{});
errcount += CompareMetadataDict(baselineImageMetadata.LUT2DKeys.begin(),
baselineImageMetadata.LUT2DKeys.end(),
testImageMetadata.LUT2DKeys.begin(),
testImageMetadata.LUT2DKeys.end(),
m_ReportErrors);
errcount += CompareMetadataDict(baselineImageMetadata.LUT2DKeys,
testImageMetadata.LUT2DKeys,
m_ReportErrors,
{});
// Compare extra keys (strict equality)
errcount += CompareMetadataDict(baselineImageMetadata.ExtraKeys.begin(),
baselineImageMetadata.ExtraKeys.end(),
testImageMetadata.ExtraKeys.begin(),
testImageMetadata.ExtraKeys.end(),
m_ReportErrors);
errcount += CompareMetadataDict(baselineImageMetadata.ExtraKeys,
testImageMetadata.ExtraKeys,
m_ReportErrors,
{});
if (baselineImageMetadata.Has(MDGeom::RPC))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment