OTB  9.0.0
Orfeo Toolbox
otbTestHelper.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbTestHelper_h
23 #define otbTestHelper_h
24 
25 #include <map>
26 #include <string>
27 #include <vector>
28 #include "itkObject.h"
29 #include "itkObjectFactory.h"
30 #include "otbStringUtils.h"
31 
32 #include "otbMetaDataKey.h"
33 #include "OTBTestKernelExport.h"
34 
35 class OGRFeature;
36 class OGRGeometry;
37 class OGRLayer;
38 
39 namespace otb
40 {
47 class OTBTestKernel_EXPORT TestHelper : public itk::Object
48 {
49 public:
50 
52  typedef TestHelper Self;
53  typedef itk::SmartPointer<Self> Pointer;
54  typedef itk::SmartPointer<const Self> ConstPointer;
55  typedef itk::Object Superclass;
56 
57  itkTypeMacro(TestHelper, itk::Object);
58  itkNewMacro(Self);
59 
60  typedef std::vector<std::string> StringList;
61  typedef StringList::const_iterator StringListIt;
62 
63  typedef std::vector<double> EpsilonList;
64  typedef EpsilonList::const_iterator EpsilonListIt;
65 
66  TestHelper();
67 
68  ~TestHelper() override;
69 
70  int RegressionTestAllImages(const StringList& baselineFilenamesImage, const StringList& testFilenamesImage, const EpsilonList& epsilons);
71 
72  int RegressionTestAllMetaData(const StringList& baselineFilenamesMetaData, const StringList& testFilenamesMetaData, const EpsilonList& epsilons);
73 
74  int RegressionTestAllAscii(const StringList& baselineFilenamesAscii, const StringList& testFilenamesAscii, const EpsilonList& epsilons,
75  const StringList& ignoredLines);
76 
77  int RegressionTestAllDiff(const StringList& baselineFilenamesAscii, const StringList& testFilenamesAscii, const EpsilonList& epsilons,
78  const StringList& ignoredLines);
79 
80  int RegressionTestAllBinary(const StringList& baselineFilenamesBinary, const StringList& testFilenamesBinary);
81 
82  int RegressionTestAllOgr(const StringList& baselineFilenamesOgr, const StringList& testFilenamesOgr, const EpsilonList& epsilons);
83 
84  itkSetMacro(ReportErrors, bool);
85  itkBooleanMacro(ReportErrors);
86  itkSetMacro(IgnoreLineOrder, bool);
87  itkBooleanMacro(IgnoreLineOrder);
88 
89  itkSetMacro(EpsilonBoundaryChecking, double);
90  itkSetMacro(ToleranceRatio, double);
91 
92 private:
93  std::map<std::string, int> RegressionTestBaselines(char* baselineFilename) const;
94 
95  int RegressionTestImage(int cpt, const char* testImageFilename, const char* baselineImageFilename, const double toleranceDiffPixelImage) const;
96 
97  int RegressionTestOgrFile(const char* testOgrFilename, const char* baselineOgrFilename, const double toleranceDiffValue) const;
98 
99  int RegressionTestBinaryFile(const char* testBinaryFileName, const char* baselineBinaryFileName) const;
100 
101  int RegressionTestAsciiFile(const char* testAsciiFileName, const char* baselineAsciiFileName, const double epsilon,
102  std::vector<std::string> ignoredLines) const;
103 
104  int RegressionTestDiffFile(const char* testAsciiFileName, const char* baselineAsciiFileName, const double epsilon,
105  std::vector<std::string> ignoredLines) const;
106 
107  int RegressionTestMetaData(const char* testImageFilename, const char* baselineImageFilename, const double toleranceDiffPixelImage) const;
108 
109  bool isNumber(int i) const;
110  bool isHexaNumber(int i) const;
111  bool isPoint(int i) const;
112  bool isMinusSign(int i) const;
113  bool isAlphaNum(int i) const;
114  bool isNumeric(const std::string& str) const;
115  bool isScientificNumeric(const std::string& str) const;
116  bool isHexaPointerAddress(const std::string& str) const;
117  bool isHexaPointerAddress(const std::string& str, size_t pos, size_t size) const;
118  bool isToBeIgnoredForAnyComparison(const std::string& str) const;
119  std::string VectorToString(const otb::MetaDataKey::VectorType& vector) const;
120  int TokenizeLine(const std::string& line, StringList& tokens) const;
121 
122  static bool IsTokenEmpty(boost::iterator_range<std::string::const_iterator>& token);
123 
124  // TODO : maybe merge this function with isToBeIgnoredForAnyComparison
125  bool IsLineValid(const std::string& str, const StringList& ignoredLines) const;
126  // FIXME parameters have to be cleaned up later (this is the first step of refactoring)
127  bool CompareLines(const std::string& strfileref, const std::string& strfiletest, int& nbdiff, std::ofstream& fluxfilediff, int& numLine,
128  std::vector<std::string>& listStrDiffLineFileRef, std::vector<std::string>& listStrDiffLineFileTest, double epsilon) const;
129 
130  void ogrReportOnLayer(OGRLayer* ref_poLayer, const char* ref_pszWHERE, OGRGeometry* ref_poSpatialFilter, OGRLayer* test_poLayer, const char* test_pszWHERE,
131  OGRGeometry* test_poSpatialFilter, int& nbdiff, double epsilon) const;
132 
133  static void DumpOGRFeature(FILE* fileid, OGRFeature* feature, char** papszOptions = nullptr);
134  static void DumpOGRGeometry(FILE* fileid, OGRGeometry* geometry, const char* pszPrefix, char** papszOptions = nullptr);
135 
140  const unsigned int m_MaxArea;
141 
142  void AddWhiteSpace(const std::string& strIn, std::string& strOut) const;
143 
144  void CheckValueTolerance(const char* Comment, double ref, double test, int& count, bool report, double epsilon) const;
145 
146  std::vector<std::pair<std::string, std::string>> m_SpecialTokens;
147 };
148 }
149 
150 #endif
otb::TestHelper::m_ReportErrors
bool m_ReportErrors
Definition: otbTestHelper.h:138
otb::TestHelper
Helper class to perform the baseline comparisons during the tests.
Definition: otbTestHelper.h:47
otb::TestHelper::m_MaxArea
const unsigned int m_MaxArea
Definition: otbTestHelper.h:140
otb::TestHelper::m_SpecialTokens
std::vector< std::pair< std::string, std::string > > m_SpecialTokens
Definition: otbTestHelper.h:146
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::TestHelper::Self
TestHelper Self
Definition: otbTestHelper.h:52
otb::MetaDataKey::VectorType
std::vector< double > VectorType
Definition: otbMetaDataKey.h:119
otb::TestHelper::m_ToleranceRatio
double m_ToleranceRatio
Definition: otbTestHelper.h:136
otb::TestHelper::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbTestHelper.h:53
otb::TestHelper::StringListIt
StringList::const_iterator StringListIt
Definition: otbTestHelper.h:61
otb::TestHelper::EpsilonList
std::vector< double > EpsilonList
Definition: otbTestHelper.h:63
otbMetaDataKey.h
otbStringUtils.h
otb::TestHelper::StringList
std::vector< std::string > StringList
Definition: otbTestHelper.h:58
otb::TestHelper::Superclass
itk::Object Superclass
Definition: otbTestHelper.h:55
otb::TestHelper::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbTestHelper.h:54
otb::TestHelper::EpsilonListIt
EpsilonList::const_iterator EpsilonListIt
Definition: otbTestHelper.h:64
otb::TestHelper::m_IgnoreLineOrder
bool m_IgnoreLineOrder
Definition: otbTestHelper.h:139
otb::TestHelper::m_EpsilonBoundaryChecking
double m_EpsilonBoundaryChecking
Definition: otbTestHelper.h:137