102 std::cout <<
"***************************************************************"
103 "******************************************************"
105 std::cout <<
"==> testXmlGeneration" << std::endl;
108 boost::filesystem::remove(
"TestAppInstance.xml");
111 TestApp app(
"TestAppInstance");
115 xmlpp::XsdValidator validator(
"application.xsd");
116 validator.validate(
"TestAppInstance.xml");
119 xmlpp::DomParser parser;
121 parser.parse_file(
"TestAppInstance.xml");
123 catch(xmlpp::exception& e) {
124 throw std::runtime_error(std::string(
"ConfigReader: Error opening the config file "
125 "'TestAppInstance.xml': ") +
130 auto*
const root = parser.get_document()->get_root_node();
131 BOOST_CHECK_EQUAL(root->get_name(),
"application");
134 bool found_pipeIn{
false};
135 bool found_multiplierDIn{
false};
136 bool found_multiplierDOut{
false};
137 bool found_multiplierU16In{
false};
138 bool found_multiplierU16Out{
false};
139 bool found_pipeOut{
false};
140 bool foundTrigger{
false};
142 bool foundDeviceStatus{
false};
143 bool foundDeviceMessage{
false};
144 bool foundBecameFunctional{
false};
146 for(
const auto& child : root->get_children()) {
148 const auto* element =
dynamic_cast<const xmlpp::Element*
>(child);
153 if(element->get_name() ==
"variable") {
155 auto* xname = element->get_attribute(
"name");
156 BOOST_REQUIRE(xname !=
nullptr);
157 std::string name(xname->get_value());
164 std::string numberOfElements =
getValueFromNode(element,
"numberOfElements");
167 if(name ==
"pipeOut") {
169 BOOST_TEST(value_type ==
"string");
170 BOOST_TEST(direction ==
"application_to_control_system");
171 BOOST_TEST(unit ==
"unit");
172 BOOST_TEST(description ==
"Some pipe module");
173 BOOST_TEST(numberOfElements ==
"1");
175 else if(name ==
"pipeIn") {
176 found_pipeOut =
true;
177 BOOST_TEST(value_type ==
"string");
178 BOOST_CHECK_EQUAL(direction,
"control_system_to_application");
179 BOOST_TEST(unit ==
"unit");
180 BOOST_TEST(description ==
"Some pipe module");
181 BOOST_TEST(numberOfElements ==
"1");
183 else if(name ==
"trigger") {
185 BOOST_TEST(value_type ==
"Void");
186 BOOST_CHECK_EQUAL(direction,
"control_system_to_application");
187 BOOST_TEST(unit ==
"n./a.");
188 BOOST_TEST(description ==
"");
189 BOOST_TEST(numberOfElements ==
"0");
192 BOOST_ERROR(
"Wrong variable name found.");
195 else if(element->get_name() ==
"directory") {
196 auto* xname = element->get_attribute(
"name");
197 BOOST_REQUIRE(xname !=
nullptr);
198 std::string name(xname->get_value());
200 for(
const auto& subchild : child->get_children()) {
201 const auto* element2 =
dynamic_cast<const xmlpp::Element*
>(subchild);
206 if(element2->get_name() ==
"directory") {
207 auto* xname2 = element2->get_attribute(
"name");
208 BOOST_REQUIRE(xname2 !=
nullptr);
209 std::string name2(xname2->get_value());
212 for(
const auto& devicechild : element2->get_children()) {
213 const auto* deviceChildElement =
dynamic_cast<const xmlpp::Element*
>(devicechild);
214 if(!deviceChildElement) {
217 if(deviceChildElement->get_name() ==
"variable") {
219 auto* xname3 = deviceChildElement->get_attribute(
"name");
220 BOOST_REQUIRE(xname3 !=
nullptr);
221 std::string name3(xname3->get_value());
224 std::string value_type =
getValueFromNode(deviceChildElement,
"value_type");
227 std::string description =
getValueFromNode(deviceChildElement,
"description");
228 std::string numberOfElements =
getValueFromNode(deviceChildElement,
"numberOfElements");
229 if(name3 ==
"status") {
230 foundDeviceStatus =
true;
231 BOOST_CHECK_EQUAL(value_type,
"int32");
232 BOOST_CHECK_EQUAL(description,
"Error status of the device - Error status of the device");
233 BOOST_CHECK_EQUAL(numberOfElements,
"1");
234 BOOST_CHECK_EQUAL(direction,
"application_to_control_system");
235 BOOST_CHECK_EQUAL(unit,
"");
237 else if(name3 ==
"status_message") {
238 foundDeviceMessage =
true;
239 BOOST_CHECK_EQUAL(value_type,
"string");
240 BOOST_CHECK_EQUAL(description,
"Error status of the device - status message");
241 BOOST_CHECK_EQUAL(numberOfElements,
"1");
242 BOOST_CHECK_EQUAL(direction,
"application_to_control_system");
243 BOOST_CHECK_EQUAL(unit,
"");
245 else if(name3 ==
"deviceBecameFunctional") {
246 foundBecameFunctional =
true;
247 BOOST_CHECK_EQUAL(value_type,
"Void");
248 BOOST_CHECK_EQUAL(description,
"");
249 BOOST_CHECK_EQUAL(numberOfElements,
"1");
250 BOOST_CHECK_EQUAL(direction,
"application_to_control_system");
251 BOOST_CHECK_EQUAL(unit,
"");
254 BOOST_ERROR(
"Unexpected variable " + name2);
258 BOOST_ERROR(
"Wrong tag " + element2->get_name() +
" found");
262 else if(element2->get_name() ==
"variable") {
264 auto* xname2 = element2->get_attribute(
"name");
265 BOOST_REQUIRE(xname2 !=
nullptr);
266 std::string name2(xname2->get_value());
273 std::string numberOfElements =
getValueFromNode(element2,
"numberOfElements");
275 if(name2 ==
"input") {
276 if(name ==
"multiplierD") {
277 found_multiplierDIn =
true;
278 BOOST_CHECK_EQUAL(value_type,
"double");
279 BOOST_CHECK_EQUAL(description,
"Some module");
280 BOOST_CHECK_EQUAL(numberOfElements,
"1");
282 else if(name ==
"multiplierU16") {
283 found_multiplierU16In =
true;
284 BOOST_CHECK_EQUAL(value_type,
"uint16");
285 BOOST_CHECK_EQUAL(description,
"Some other module");
286 BOOST_CHECK_EQUAL(numberOfElements,
"120");
289 BOOST_ERROR(
"Wrong Directory name found");
291 BOOST_CHECK_EQUAL(direction,
"control_system_to_application");
292 BOOST_CHECK_EQUAL(unit,
"");
294 else if(name2 ==
"output") {
295 if(name ==
"multiplierD") {
296 found_multiplierDOut =
true;
297 BOOST_CHECK_EQUAL(value_type,
"double");
298 BOOST_CHECK_EQUAL(description,
"Some module");
299 BOOST_CHECK_EQUAL(numberOfElements,
"1");
301 else if(name ==
"multiplierU16") {
302 found_multiplierU16Out =
true;
303 BOOST_CHECK_EQUAL(value_type,
"uint16");
304 BOOST_CHECK_EQUAL(description,
"Some other module");
305 BOOST_CHECK_EQUAL(numberOfElements,
"120");
308 BOOST_ERROR(
"Wrong Directory name found");
310 BOOST_CHECK_EQUAL(direction,
"application_to_control_system");
311 BOOST_CHECK_EQUAL(unit,
"");
314 BOOST_ERROR(
"Wrong variable name found.");
320 BOOST_ERROR(
"Wrong tag found.");
324 BOOST_CHECK(found_pipeIn);
325 BOOST_CHECK(found_pipeOut);
326 BOOST_CHECK(found_multiplierDIn);
327 BOOST_CHECK(found_multiplierDOut);
328 BOOST_CHECK(found_multiplierU16In);
329 BOOST_CHECK(found_multiplierU16Out);
330 BOOST_CHECK(foundTrigger);
331 BOOST_CHECK(foundDeviceMessage);
332 BOOST_CHECK(foundDeviceStatus);
333 BOOST_CHECK(foundBecameFunctional);