preCICE
v3.1.2
Loading...
Searching...
No Matches
src
xml
tests
XMLTest.cpp
Go to the documentation of this file.
1
#include <Eigen/Core>
2
#include <
string
>
3
#include <
tuple
>
4
#include "
math/constants.hpp
"
5
#include "
testing/TestContext.hpp
"
6
#include "
testing/Testing.hpp
"
7
#include "
xml/ValueParser.hpp
"
8
#include "
xml/XMLAttribute.hpp
"
9
#include "
xml/XMLTag.hpp
"
10
11
using namespace
precice
;
12
using namespace
precice::xml
;
13
using
precice::testing::getPathToSources
;
14
15
BOOST_AUTO_TEST_SUITE
(XML)
16
17
struct
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"
, 3);
24
}
25
}
26
27
void
xmlEndTagCallback
(
const
ConfigurationContext
&
context
,
XMLTag
&
callingTag
)
override
28
{
29
std::ignore =
callingTag
;
30
}
31
};
32
33
BOOST_AUTO_TEST_CASE
(
AttributeConcatenation
)
34
{
35
PRECICE_TEST
(1_rank);
36
std::string
filename(getPathToSources() +
"/xml/tests/config_xmltest_concatenation.xml"
);
37
38
CallbackHost
cb
;
39
XMLTag
rootTag
(
cb
,
"configuration"
,
XMLTag::OCCUR_ONCE
);
40
XMLTag
testcaseTag
(
cb
,
"test-attribute-concatenation"
,
XMLTag::OCCUR_ONCE
);
41
XMLTag
testTag
(
cb
,
"test"
,
XMLTag::OCCUR_ONCE_OR_MORE
);
42
43
auto
attr
=
makeXMLAttribute
(
"attribute"
,
""
).
setOptions
({
"value-one"
,
"value-two"
,
"value-three"
});
44
testTag
.addAttribute(
attr
);
45
46
testcaseTag
.addSubtag(
testTag
);
47
rootTag
.addSubtag(
testcaseTag
);
48
49
configure
(
rootTag
,
ConfigurationContext
{}, filename);
50
}
51
52
BOOST_AUTO_TEST_CASE
(
VectorAttributes
)
53
{
54
PRECICE_TEST
(1_rank);
55
std::string
filename(getPathToSources() +
"/xml/tests/config_xmltest_vectorattributes.xml"
);
56
57
CallbackHost
cb
;
58
XMLTag
rootTag
(
cb
,
"configuration"
,
XMLTag::OCCUR_ONCE
);
59
XMLTag
testTagEigenXd
(
cb
,
"test-eigen-vectorxd-attributes"
,
XMLTag::OCCUR_ONCE
);
60
61
XMLAttribute<Eigen::VectorXd>
attrEigenXd
(
"value"
);
62
testTagEigenXd
.addAttribute(
attrEigenXd
);
63
rootTag
.addSubtag(
testTagEigenXd
);
64
65
configure
(
rootTag
,
ConfigurationContext
{}, filename);
66
BOOST_TEST
(
cb
.eigenVectorXd(0) == 3.0);
67
BOOST_TEST
(
cb
.eigenVectorXd(1) == 2.0);
68
BOOST_TEST
(
cb
.eigenVectorXd(2) == 1.0);
69
}
70
71
BOOST_AUTO_TEST_SUITE_END
()
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
TestContext.hpp
Testing.hpp
PRECICE_TEST
#define PRECICE_TEST(...)
Definition
Testing.hpp:27
ValueParser.hpp
XMLAttribute.hpp
XMLTag.hpp
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(AttributeConcatenation)
Definition
XMLTest.cpp:33
std::string
precice::xml::XMLAttribute
Definition
XMLAttribute.hpp:20
precice::xml::XMLAttribute::setOptions
XMLAttribute & setOptions(std::vector< ATTRIBUTE_T > options)
Definition
XMLAttribute.hpp:137
precice::xml::XMLAttribute::getName
const std::string & getName() const
Definition
XMLAttribute.hpp:77
precice::xml::XMLTag
Represents an XML tag to be configured automatically.
Definition
XMLTag.hpp:31
precice::xml::XMLTag::OCCUR_ONCE_OR_MORE
@ OCCUR_ONCE_OR_MORE
Definition
XMLTag.hpp:70
precice::xml::XMLTag::OCCUR_ONCE
@ OCCUR_ONCE
Definition
XMLTag.hpp:69
constants.hpp
precice::testing::getPathToSources
std::string getPathToSources()
Returns the base path to the sources.
Definition
Testing.cpp:31
precice::xml
contains the XML configuration parser.
Definition
CommunicationConfiguration.hpp:9
precice::xml::makeXMLAttribute
XMLAttribute< std::string > makeXMLAttribute(std::string name, const char *defaultValue)
Definition
XMLAttribute.hpp:219
precice::xml::configure
void configure(XMLTag &tag, const precice::xml::ConfigurationContext &context, std::string_view configurationFilename)
Configures the given configuration from file configurationFilename.
Definition
XMLTag.cpp:395
precice
Main namespace of the precice library.
Definition
Acceleration.cpp:5
string
CallbackHost
Definition
XMLTest.cpp:17
CallbackHost::eigenVectorXd
Eigen::VectorXd eigenVectorXd
Definition
XMLTest.cpp:18
CallbackHost::xmlEndTagCallback
void xmlEndTagCallback(const ConfigurationContext &context, XMLTag &callingTag) override
Callback at end of XML tag and at end of subtag.
Definition
XMLTest.cpp:27
CallbackHost::xmlTagCallback
void xmlTagCallback(const ConfigurationContext &context, XMLTag &callingTag) override
Callback at begin of XML tag.
Definition
XMLTest.cpp:20
precice::xml::ConfigurationContext
Tightly coupled to the parameters of Participant()
Definition
XMLTag.hpp:24
tuple