19#include <boost/lexical_cast.hpp>
20#include <boost/test/unit_test.hpp>
22#include <oret/toplevelfixture.hpp>
23#include <ql/errors.hpp>
24#include <ql/types.hpp>
27using namespace boost::unit_test_framework;
31using ore::test::TopLevelFixture;
36class F :
public TopLevelFixture {
42 string testXML =
"<root>"
45 "<data1a attr = \"0.7736\">17.5</data1a>"
49 "<vector1bval>12.3</vector1bval><vector1bval>45.6</vector1bval><vector1bval>78.9</vector1bval>"
54 "<level2aDuplicates></level2aDuplicates>"
55 "<level2aDuplicates></level2aDuplicates>"
56 "<level2aDuplicates></level2aDuplicates>"
57 "<level2aDuplicates></level2aDuplicates>"
70BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, TopLevelFixture)
72BOOST_AUTO_TEST_SUITE(XmlManipulationTests)
76 BOOST_TEST_MESSAGE(
"Testing XML (scalar) data getters");
79 XMLNode* root = testDoc.getFirstNode(
"root");
88 string expectedStr =
"17.5";
90 BOOST_CHECK_EQUAL(data1a_str, expectedStr);
92 Real expectedReal = 17.5;
94 BOOST_CHECK_EQUAL(data1a_real, expectedReal);
107 string expAttribVal =
"0.7736";
109 BOOST_CHECK_EQUAL(attribVal, expAttribVal);
115 BOOST_TEST_MESSAGE(
"Testing XML vector data getters");
118 XMLNode* root = testDoc.getFirstNode(
"root");
128 vector<string> expVecStr = {
"12.3",
"45.6",
"78.9"};
129 vector<Real> expVecReal;
130 for (
auto s : expVecStr)
131 expVecReal.push_back(boost::lexical_cast<Real>(s));
133 BOOST_CHECK_EQUAL_COLLECTIONS(vec1b_str.begin(), vec1b_str.end(), expVecStr.begin(), expVecStr.end());
135 BOOST_CHECK_EQUAL_COLLECTIONS(vec1bReal.begin(), vec1bReal.end(), expVecReal.begin(), expVecReal.end());
138 vector<string> manualVectorString;
139 for (
auto c : vecNodes)
141 BOOST_CHECK_EQUAL_COLLECTIONS(manualVectorString.begin(), manualVectorString.end(), expVecStr.begin(),
147 BOOST_TEST_MESSAGE(
"Testing XML data setters");
150 XMLNode* root = testDoc.getFirstNode(
"root");
153 string newNodeVal =
"value17.3";
157 BOOST_CHECK_EQUAL(newNodeValCheck, newNodeVal);
159 vector<Real> nodesVec = {11.1, 22.2, 33.4, 55.6};
162 vector<Real> nodesVecCheck =
164 BOOST_CHECK_EQUAL_COLLECTIONS(nodesVecCheck.begin(), nodesVecCheck.end(), nodesVec.begin(), nodesVec.end());
169 BOOST_TEST_MESSAGE(
"Testing XML attributes");
172 XMLNode* root = testDoc.getFirstNode(
"root");
181 string attrExpVal =
"0.7736";
183 BOOST_CHECK_EQUAL(attrVal, attrExpVal);
186 string level1aAttrName =
"level1aAttrName";
187 string level1aAttrVal =
"14.2";
190 BOOST_CHECK_EQUAL(level1aAttrValExract, level1aAttrVal);
193BOOST_AUTO_TEST_SUITE_END()
195BOOST_AUTO_TEST_SUITE_END()
Small XML Document wrapper class.
void fromXMLString(const string &xmlString)
load a document from a hard-coded string
static void addAttribute(XMLDocument &doc, XMLNode *node, const string &attrName, const string &attrValue)
static vector< Real > getChildrenValuesAsDoubles(XMLNode *node, const string &names, const string &name, bool mandatory=false)
static void addChildren(XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values)
static string getAttribute(XMLNode *node, const string &attrName)
static void checkNode(XMLNode *n, const string &expectedName)
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
static XMLNode * getChildNode(XMLNode *n, const string &name="")
static string getNodeValue(XMLNode *node)
Get a node's value.
static int getChildValueAsInt(XMLNode *node, const string &name, bool mandatory=false, int defaultValue=0)
static vector< string > getChildrenValues(XMLNode *node, const string &names, const string &name, bool mandatory=false)
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
BOOST_FIXTURE_TEST_CASE(testXMLDataGetters, F)