preCICE v3.1.2
Loading...
Searching...
No Matches
ParserTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include <string>
3#include <tuple>
4#include "math/constants.hpp"
6#include "testing/Testing.hpp"
8#include "xml/ValueParser.hpp"
10#include "xml/XMLTag.hpp"
11
12using namespace precice;
13using namespace precice::xml;
15
17
19 Eigen::VectorXd eigenValue;
24
26 {
27 if (callingTag.getName() == "test-double") {
28 doubleValue = callingTag.getDoubleAttributeValue("attribute");
29 }
30
31 if (callingTag.getName() == "test-eigen") {
32 eigenValue = callingTag.getEigenVectorXdAttributeValue("attribute", 3);
33 }
34
35 if (callingTag.getName() == "test-int") {
36 intValue = callingTag.getIntAttributeValue("attribute");
37 }
38
39 if (callingTag.getName() == "test-bool") {
40 boolValue = callingTag.getBooleanAttributeValue("attribute");
41 }
42
43 if (callingTag.getName() == "test-string") {
44 stringValue = callingTag.getStringAttributeValue("text");
45 }
46 }
47
49 {
50 std::ignore = callingTag;
51 }
52};
53
55{
56 PRECICE_TEST(1_rank);
57 std::string filename(getPathToSources() + "/xml/tests/xmlparser_test.xml");
58
60 XMLTag rootTag(cb, "configuration", XMLTag::OCCUR_ONCE);
61 XMLTag testcaseTag(cb, "test-config", XMLTag::OCCUR_ONCE);
62
68
71 XMLAttribute<int> intAttr("attribute");
72 XMLAttribute<bool> boolAttr("attribute");
74
75 doubleTag.addAttribute(doubleAttr);
76 eigenTag.addAttribute(eigenAttr);
77 intTag.addAttribute(intAttr);
78 boolTag.addAttribute(boolAttr);
79 stringTag.addAttribute(stringAttr);
80
81 testcaseTag.addSubtag(doubleTag);
82 testcaseTag.addSubtag(eigenTag);
83 testcaseTag.addSubtag(intTag);
84 testcaseTag.addSubtag(boolTag);
85 testcaseTag.addSubtag(stringTag);
86
87 rootTag.addSubtag(testcaseTag);
88
90
91 BOOST_TEST(cb.boolValue == true);
92 BOOST_TEST(cb.doubleValue == 3.1);
93 BOOST_TEST(cb.intValue == 4);
94 BOOST_TEST(cb.stringValue == "Hello World");
95
96 BOOST_TEST(cb.eigenValue(0) == 3.0);
97 BOOST_TEST(cb.eigenValue(1) == 2.0);
98 BOOST_TEST(cb.eigenValue(2) == 1.0);
99}
100
102{
103 PRECICE_TEST(1_rank);
104 std::string filename(getPathToSources() + "/xml/tests/xmlparser_occtest.xml");
105
107 XMLTag rootTag(cb, "configuration", XMLTag::OCCUR_ONCE);
108 XMLTag testcaseTag(cb, "test-config", XMLTag::OCCUR_ONCE);
109
110 XMLTag occ2(cb, "test-occ_once_or_more-once", XMLTag::OCCUR_ONCE_OR_MORE);
111 XMLTag occ3(cb, "test-occ_arbitrary", XMLTag::OCCUR_ARBITRARY);
112 XMLTag occ4(cb, "test-occ_not_or_once", XMLTag::OCCUR_NOT_OR_ONCE);
113
114 XMLTag occ5(cb, "test-occ_once_or_more-more", XMLTag::OCCUR_ONCE_OR_MORE);
115 XMLTag occ6(cb, "test-occ_arbitrary-opt", XMLTag::OCCUR_ARBITRARY);
116 XMLTag occ7(cb, "test-occ_not_or_once-opt", XMLTag::OCCUR_NOT_OR_ONCE);
117
118 testcaseTag.addSubtag(occ2);
119 testcaseTag.addSubtag(occ3);
120 testcaseTag.addSubtag(occ4);
121
122 testcaseTag.addSubtag(occ5);
123 testcaseTag.addSubtag(occ6);
124 testcaseTag.addSubtag(occ7);
125
126 rootTag.addSubtag(testcaseTag);
127
129}
130
132{
133 PRECICE_TEST(1_rank);
134 std::string filename(getPathToSources() + "/xml/tests/xmlparser_nstest.xml");
135
137 XMLTag rootTag(cb, "configuration", XMLTag::OCCUR_ONCE);
138 XMLTag testcaseTag(cb, "test-config", XMLTag::OCCUR_ONCE);
139
142
143 testcaseTag.addNamespace("ns");
144
145 testcaseTag.addSubtag(intTag);
146 testcaseTag.addSubtag(stringTag);
147
148 rootTag.addSubtag(testcaseTag);
149
151}
152
167
169{
170 PRECICE_TEST(1_rank);
171 std::string filename(getPathToSources() + "/xml/tests/config_xmltest_context.xml");
172
174 XMLTag rootTag(cl, "configuration", XMLTag::OCCUR_ONCE);
175 ConfigurationContext ccontext{"test", 12, 32};
176 configure(rootTag, ccontext, filename);
177 BOOST_TEST(cl.startContext.name == "test");
178 BOOST_TEST(cl.startContext.rank == 12);
179 BOOST_TEST(cl.startContext.size == 32);
180 BOOST_TEST(cl.endContext.name == "test");
181 BOOST_TEST(cl.endContext.rank == 12);
182 BOOST_TEST(cl.endContext.size == 32);
183}
184
186{
187 PRECICE_TEST(1_rank);
188
189 BOOST_TEST(decodeXML("Less than &lt; test") == "Less than < test");
190 BOOST_TEST(decodeXML("Greater than &gt; test") == "Greater than > test");
191 BOOST_TEST(decodeXML("Ampersand &amp; test") == "Ampersand & test");
192 BOOST_TEST(decodeXML("Quotation &quot; test") == "Quotation \" test");
193 BOOST_TEST(decodeXML("Apostrophe &apos; test") == "Apostrophe ' test");
194
195 BOOST_TEST(decodeXML("&quot; &lt; &gt; &gt; &lt; &amp; &quot; &amp; &apos;") == "\" < > > < & \" & '");
196}
197
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(AttributeTypeTest)
#define PRECICE_TEST(...)
Definition Testing.hpp:27
const std::string & getName() const
Represents an XML tag to be configured automatically.
Definition XMLTag.hpp:31
std::string getPathToSources()
Returns the base path to the sources.
Definition Testing.cpp:31
contains the XML configuration parser.
std::string decodeXML(std::string xml)
Decodes escape sequences of a given xml.
void configure(XMLTag &tag, const precice::xml::ConfigurationContext &context, std::string_view configurationFilename)
Configures the given configuration from file configurationFilename.
Definition XMLTag.cpp:395
Main namespace of the precice library.
std::string stringValue
void xmlTagCallback(const ConfigurationContext &context, XMLTag &callingTag) override
Callback at begin of XML tag.
void xmlEndTagCallback(const ConfigurationContext &context, XMLTag &callingTag) override
Callback at end of XML tag and at end of subtag.
Eigen::VectorXd eigenValue
void xmlTagCallback(const ConfigurationContext &context, XMLTag &callingTag)
Callback at begin of XML tag.
ConfigurationContext endContext
ConfigurationContext startContext
void xmlEndTagCallback(const ConfigurationContext &context, XMLTag &callingTag)
Callback at end of XML tag and at end of subtag.
Tightly coupled to the parameters of Participant()
Definition XMLTag.hpp:24
Callback interface for configuration classes using XMLTag.
Definition XMLTag.hpp:43