11 #include <cppunit/extensions/HelperMacros.h>
18 #include <boost/lexical_cast.hpp>
19 #include <utl/Reader.h>
20 #include <utl/ReaderErrorReporter.h>
21 #include <utl/AugerUnits.h>
22 #include <utl/TimeStamp.h>
23 #include <utl/TabulatedFunction.h>
24 #include <utl/Function.h>
25 #include <utl/UTCDateTime.h>
26 #include <utl/ErrorLogger.h>
27 #include <utl/AugerException.h>
28 #include <tst/Verify.h>
33 using namespace xercesc;
36 #define ASSERT_EQUAL(x, y) CPPUNIT_ASSERT(Verify<Equal>(x, y))
37 #define ASSERT_NOTEQUAL(x, y) CPPUNIT_ASSERT(Verify<Not<Equal> >(x, y))
38 #define ASSERT_CLOSE(x, y) CPPUNIT_ASSERT(Verify<CloseTo>(x, y))
39 #define ASSERT_CLOSEEPS(x, y, eps) CPPUNIT_ASSERT(Verify<CloseTo>(x, y, eps))
48 CPPUNIT_TEST(testHierarchy);
49 CPPUNIT_TEST(testAttributes);
50 CPPUNIT_TEST(testCastings);
51 CPPUNIT_TEST(testStringParse);
52 CPPUNIT_TEST(testXMLTime);
53 CPPUNIT_TEST(testEmpties);
54 CPPUNIT_TEST(testOperators);
55 CPPUNIT_TEST(testEmptyReader);
56 CPPUNIT_TEST(testWarning);
57 CPPUNIT_TEST(testEvaluatorUnits);
59 CPPUNIT_TEST(testTabulatedFunction);
60 CPPUNIT_TEST(testFunction);
61 CPPUNIT_TEST_SUITE_END();
72 fReader =
new Reader(XMLFILE, Reader::eDTD);
73 fSchemaReader =
new Reader(XMLSCHEMAFILE, Reader::eSCHEMA);
91 attMap[
"firstName"] =
"Jim";
92 attMap[
"lastName"] =
"Cronin";
93 string responsibility;
95 ASSERT_EQUAL(responsibility,
string(
"Spokesperson Emeritus"));
98 "firstName=Jim lastName=Cronin").
GetChild(
"responsibility").
GetData(responsibility);
99 ASSERT_EQUAL(responsibility,
string(
"Spokesperson Emeritus"));
105 ASSERT_EQUAL(theAttributes[
"firstName"],
string(
"Alan"));
106 ASSERT_EQUAL(theAttributes[
"lastName"],
string(
"Watson"));
116 apertureAttributes[
"site"] =
"Malargue";
146 CPPUNIT_ASSERT(caught);
157 CPPUNIT_ASSERT(caught);
169 CPPUNIT_ASSERT(caught);
182 ostringstream trimStream;
183 trimStream <<
"first line \t \n"
185 ostringstream inpStream;
186 inpStream <<
"<AtmosphereFuncList>\n"
187 " <!-- some stupid comment --> \n"
188 " <attenuationFunc> <!-- comment --> myAttenFunc </attenuationFunc> \n"
189 " <scatteringFunc> DefaultScattering </scatteringFunc> "
191 " \t " << trimStream.str() <<
" \t \n \r "
193 " <qualityFunc> DefaultQuality </qualityFunc> "
194 "</AtmosphereFuncList>";
197 Reader theReaderFromMem(readerInput);
223 CPPUNIT_ASSERT(fReader->GetTopBranch());
224 CPPUNIT_ASSERT(!fReader->GetTopBranch().GetParent());
225 CPPUNIT_ASSERT(fReader->GetTopBranch().GetFirstChild().GetParent() == fReader->GetTopBranch());
226 ASSERT_EQUAL(fReader->GetTopBranch().GetName(), string(
"document"));
235 ASSERT_EQUAL(boost::lexical_cast<int>(child.GetAttributes()[
"id"]), i);
246 ASSERT_EQUAL(boost::lexical_cast<int>(sib.GetAttributes()[
"id"]), i);
251 for (
Branch sib = last ; sib ; --sib) {
253 ASSERT_EQUAL(boost::lexical_cast<int>(sib.GetAttributes()[
"id"]), i);
259 hierarchyB.GetChild(
"parent1").GetChild(
"child",
"id=3").
260 GetFirstChild().GetName(), string(
"grandChild")
263 CPPUNIT_ASSERT(!hierarchyB.GetChild(
"parent2").GetFirstChild());
270 fReader->GetTopBranch().GetChild(
"castingTest").GetChild(
"list").GetData(dataString);
271 ASSERT_EQUAL(dataString,
string(
"2.14 2.16 2.19 2.23 2.27 2.32"));
274 myList.push_back(2.14*
mm);
275 myList.push_back(2.16*
mm);
276 myList.push_back(2.19*
mm);
277 myList.push_back(2.23*
mm);
278 myList.push_back(2.27*
mm);
279 myList.push_back(2.32*
mm);
281 list<double> dataList;
282 fReader->GetTopBranch().GetChild(
"castingTest").GetChild(
"list").GetData(dataList);
284 CPPUNIT_ASSERT(dataList == myList);
290 string time =
"1982-05-12T01:23:43.56789Z";
300 vector<TimeStamp> tv;
301 fReader->GetTopBranch().GetChild(
"timeTest").GetData(tv);
305 const double ns[] = { 0, 1, 1500, 94, 1370000 };
306 for (
int i = 0; i < 5; ++i) {
308 cout << tv[i] <<
" " << utc << endl;
341 CPPUNIT_ASSERT(b1 == b2);
342 CPPUNIT_ASSERT(b2 != b3);
355 Branch b = fReader->GetTopBranch();
364 CPPUNIT_ASSERT(s.find(
"noone") == std::string::npos);
365 CPPUNIT_ASSERT(s.find(
"nobody") != std::string::npos);
368 CPPUNIT_ASSERT(caught);
408 Branch b = fReader->GetTopBranch().GetChild(
"tabulatedFunctionTest");
410 for (
unsigned int i = 0, n = tf.
GetNPoints(); i < n; ++i) {
411 const Pair p = tf[i];
419 std::cout <<
"testFunction" << std::endl;
427 std::cout << func2.GetFunction() << std::endl;
429 for (
const auto& v : st) {
430 std::cout << v.first <<
" " << v.second << std::endl;
444 CPPUNIT_ASSERT(caught);
Branch GetTopBranch() const
#define ASSERT_EQUAL(x, y)
unsigned int GetNPoints() const
double GetNanosecond() const
constexpr double kilogram
void testTabulatedFunction()
Class to hold collection (x,y) points and provide interpolation between them.
std::map< std::string, std::string > AttributeMap
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
double pow(const double x, const unsigned int i)
Exception for errors encountered when parsing XML.
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
Branch GetTopBranch() const
Get the top Branch (represents same entity as document node)
AttributeMap GetAttributes() const
Get a map<string, string> containing all the attributes of this Branch.
Branch GetNextSibling() const
Get next sibling of this branch.
Utility for parsing XML files.
Class representing a document branch.
void GetData(bool &b) const
Overloads of the GetData member template function.
std::string GetName() const
function to get the Branch name
std::map< std::string, double > SymbolTable
Evaluate functions given in a string. The real work is done by the ExpressionParser class...
#define ASSERT_CLOSE(x, y)
void testEvaluatorUnits()
utl::Reader * fSchemaReader
Branch GetFirstChild() const
Get first child of this Branch.
a pair of graph points (x,y)
const std::string & GetMessage() const
Retrieve the message from the exception.
#define ASSERT_CLOSEEPS(x, y, eps)