preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XMLTest.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"
7#include "xml/ValueParser.hpp"
9#include "xml/XMLTag.hpp"
10
11using namespace precice;
12using namespace precice::xml;
14
16
17struct CallbackHost : public XMLTag::Listener {
18 Eigen::VectorXd eigenVectorXd;
19
20 void xmlTagCallback(const ConfigurationContext &context, XMLTag &callingTag) override
21 {
22 if (callingTag.getName() == "test-eigen-vectorxd-attributes") {
23 eigenVectorXd = callingTag.getEigenVectorXdAttributeValue("value");
24 }
25 }
26
27 void xmlEndTagCallback(const ConfigurationContext &context, XMLTag &callingTag) override
28 {
29 std::ignore = callingTag;
30 }
31};
32
34BOOST_AUTO_TEST_CASE(AttributeConcatenation)
35{
37 std::string filename(getPathToSources() + "/xml/tests/config_xmltest_concatenation.xml");
38
39 CallbackHost cb;
40 XMLTag rootTag(cb, "configuration", XMLTag::OCCUR_ONCE);
41 XMLTag testcaseTag(cb, "test-attribute-concatenation", XMLTag::OCCUR_ONCE);
42 XMLTag testTag(cb, "test", XMLTag::OCCUR_ONCE_OR_MORE);
43
44 auto attr = makeXMLAttribute("attribute", "").setOptions({"value-one", "value-two", "value-three"});
45 testTag.addAttribute(attr);
46
47 testcaseTag.addSubtag(testTag);
48 rootTag.addSubtag(testcaseTag);
49
50 configure(rootTag, ConfigurationContext{}, filename);
51}
52
54BOOST_AUTO_TEST_CASE(VectorAttributes)
55{
57 std::string filename(getPathToSources() + "/xml/tests/config_xmltest_vectorattributes.xml");
58
59 CallbackHost cb;
60 XMLTag rootTag(cb, "configuration", XMLTag::OCCUR_ONCE);
61 XMLTag testTagEigenXd(cb, "test-eigen-vectorxd-attributes", XMLTag::OCCUR_ONCE);
62
63 XMLAttribute<Eigen::VectorXd> attrEigenXd("value");
64 testTagEigenXd.addAttribute(attrEigenXd);
65 rootTag.addSubtag(testTagEigenXd);
66
67 configure(rootTag, ConfigurationContext{}, filename);
68 BOOST_TEST(cb.eigenVectorXd.size() == 3);
69 BOOST_TEST(cb.eigenVectorXd(0) == 3.0);
70 BOOST_TEST(cb.eigenVectorXd(1) == 2.0);
71 BOOST_TEST(cb.eigenVectorXd(2) == 1.0);
72}
73
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST()
Definition Testing.hpp:39
#define PRECICE_TEST_SETUP(...)
Creates and attaches a TestSetup to a Boost test case.
Definition Testing.hpp:29
BOOST_AUTO_TEST_CASE(AttributeConcatenation)
Definition XMLTest.cpp:34
Represents an XML tag to be configured automatically.
Definition XMLTag.hpp:28
Eigen::VectorXd getEigenVectorXdAttributeValue(const std::string &name) const
Definition XMLTag.cpp:173
const std::string & getName() const
Returns name (without namespace).
Definition XMLTag.hpp:153
XMLTag & addAttribute(const XMLAttribute< double > &attribute)
Adds a XML attribute by making a copy of the given attribute.
Definition XMLTag.cpp:53
XMLTag & addSubtag(const XMLTag &tag)
Adds an XML tag as subtag by making a copy of the given tag.
Definition XMLTag.cpp:41
std::string getPathToSources()
Returns the base path to the sources.
Definition Testing.cpp:33
contains the XML configuration parser.
XMLAttribute< std::string > makeXMLAttribute(std::string name, const char *defaultValue)
std::string configure(XMLTag &tag, const precice::xml::ConfigurationContext &context, std::string_view configurationFilename)
Configures the given configuration from file configurationFilename.
Definition XMLTag.cpp:284
Main namespace of the precice library.
Eigen::VectorXd eigenVectorXd
Definition XMLTest.cpp:18
void xmlEndTagCallback(const ConfigurationContext &context, XMLTag &callingTag) override
Callback at end of XML tag and at end of subtag.
Definition XMLTest.cpp:27
void xmlTagCallback(const ConfigurationContext &context, XMLTag &callingTag) override
Callback at begin of XML tag.
Definition XMLTest.cpp:20
Tightly coupled to the parameters of Participant()
Definition XMLTag.hpp:21