1 #include <tst/Verify.h>
2 #include <tst/Validatrix.h>
3 #include <utl/AugerException.h>
4 #include <utl/ErrorLogger.h>
5 #include <boost/format.hpp>
6 #include <boost/lexical_cast.hpp>
25 return "\n" + string(
"t ") + t +
"\n";
46 { fType = -1; fCompareType = -1; fN = 0; fTolerance = -1; fItems.clear(); }
48 bool Tag(
const string& tag);
55 size_t GetN()
const {
return fN; }
58 { fItems.push_back(s); }
61 {
return fType ==
't'; }
64 {
return IsLabel() ? fItems.front() : fgNotALabel; }
67 bool Compare(
const string& s1,
const string& s2)
const;
70 bool CompareAs(
const string& s1,
const string& s2)
const;
73 bool TypeCompare(
const T& t1,
const T&
t2)
const;
84 const string Unpack::fgNotALabel =
"not a label";
88 Unpack::Tag(
const string& tag)
93 istringstream
is(tag);
95 !(fType ==
'i' || fType ==
'u' || fType ==
'd' || fType ==
't'))
109 if (!(is >> fN) || fN < 1)
111 if (!(is >> c) || c !=
']')
118 if (fCompareType == -1)
125 if (!(is >> fTolerance) || fTolerance < 0)
135 if (fType != u.
fType)
143 err <<
"tolerance mismatch: " << fTolerance <<
" != " << u.
fTolerance;
146 for (
size_t i = 0; i < fN; ++i)
158 case 'i':
return CompareAs<long>(s1, s2);
159 case 'u':
return CompareAs<unsigned long>(s1, s2);
160 case 'd':
return CompareAs<double>(s1, s2);
161 case 't':
return tst::Verify<utl::Equal>(s1, s2);
169 Unpack::CompareAs(
const string& s1,
const string& s2)
172 const auto c1 = lexical_cast<T>(s1);
173 const auto c2 = lexical_cast<T>(s2);
174 return TypeCompare(c1, c2);
180 Unpack::TypeCompare(
const T& t1,
const T&
t2)
183 switch (fCompareType) {
185 return tst::Verify<utl::Equal>(t1, t2);
187 return tst::Verify<utl::CloseAbs>(t1, t2, fTolerance);
189 return tst::Verify<utl::CloseRel>(t1, t2, fTolerance);
204 const size_t n = u.
GetN();
205 for (
size_t i = 0; i < n; ++i)
215 Compare(
const string& oldFilename,
const string& newFilename,
const bool failOnFirst)
218 info <<
"Comparing the reference file '" << oldFilename <<
"' with '" << newFilename <<
"'";
221 ifstream oldFile(oldFilename);
222 if (!oldFile.is_open()) {
224 err <<
"File \"" << oldFilename <<
"\" not found!";
228 ifstream newFile(newFilename);
229 if (!newFile.is_open()) {
231 err <<
"File \"" << newFilename <<
"\" not found!";
235 if (!
Compare(oldFile, newFile, failOnFirst)) {
237 err <<
"Comparison failed!";
242 INFO(
"Both files are within tolerances.");
249 Compare(istream& is1, istream& is2,
const bool failOnFirst)
255 if (!(is1 >> u1) || !(is2 >> u2))
262 err <<
"Validation failure encountered after label \""
272 }
while (is1 && is2);
273 return ok && is1.eof() && is2.eof();
void operator>>(const Event &theEvent, IoSdEvent &rawSEvent)
bool is(const double a, const double b)
#define INFO(message)
Macro for logging informational messages.
Predicate used in STL for searching for whitespace.
bool Compare(const string &oldFilename, const string &newFilename, const bool failOnFirst)
bool operator!=(const Unpack &u) const
bool operator==(const TimeStamp &ts, const TimeRange &tr)
std::string BeLabel(const string &tag)
#define WARNING(message)
Macro for logging warning messages.
bool Tag(const string &tag)
const double kDefaultTolerance
Base class for inconsistency/illogicality exceptions.
void PushBack(const string &s)
const string & GetLabel() const
#define ERROR(message)
Macro for logging error messages.
static const string fgNotALabel