How To Use
 All Modules Pages

The XML data format is widely used within all kinds of applications. XML data may both be used as a format of exchanging data between sw modules at runtime and as a final format to store some complex results. In all these cases it may be of interest to automatically verify the xml contents within unit testing.

Basic principle

To be able to check some xml contents you need a pugi::xml_document or a pugi::xml_node which represents either the root node of your xml document or which corresponds to a subtree of this document. The class TestToolBox::XmlCheck accepts either of these param types (see methods CheckNode, CheckSubNode, Compare) and verifies the belonging xml contents by converting each attribute and node entry to a textual "TestEvent" which can be checked by calling macro TTB_EXP from your test script.

Getting pugi::xml_document/xml_node from xml string or file

In the simplest case you can request the needed params directly from your test object. For other cases XmlCheck supports you to get easy access to xml contents which are available in string format or within a file:

Read from string

static const std::string SIMPLE_DEMO =
R"(<MyRootNode created="15.02.2015">
<SubNode id="17">contents of subnode</SubNode>
pugi::xml_document doc;
TTB::TheXmlCheck()->ReadFromString(doc, SIMPLE_DEMO);

Save to xml file

static const std::string MY_XML_FILE_PATH_SIMPLE_DEMO = MY_TEST_DIR + "/SimpleDemo.xml";
TTB::TheXmlCheck()->SaveToFile(doc, MY_XML_FILE_PATH_SIMPLE_DEMO);

Read from xml file

TTB::TheXmlCheck()->ReadFromFile(doc, MY_XML_FILE_PATH_SIMPLE_DEMO);

Checking contents

When you finally have succeeded in getting a valid pugi::xml_document/xml_node you can check the xml contents:

// Iterate over xml tree and generate a textual "TestEvent"
// for each logical entity:
// Verify each entity with a separate call to "TTB_EXP"
TTB_EXP(" created: 15.02.2015");
TTB_EXP(" SubNode");
TTB_EXP(" id: 17");
TTB_EXP(" contents of subnode");