How To Use
 All Modules Pages

Overview

Simple: Use singleton with one time intialization

In the simplest case you are always working with the singleton instance of XmlCheck.

A proper initialization can be done within global fixture of your test. There you decide which attributes and nodes shall be skipped throughout your test cases:

struct MyGlobalFixture : public TTB::DefaultSettingsForBoostAndTTB
{
    MyGlobalFixture(void)
    {
        TTB::TheXmlCheck()->IgnoreAttribute("date");
        TTB::TheXmlCheck()->IgnoreAttribute("time");
        ...
    }
}

BOOST_GLOBAL_FIXTURE(MyGlobalFixture);

In every test case you are using the same singleton instance of XmlCheck and you have not to care about proper initialization:

TheXmlCheck()->CheckNode(someXmlNode);

Temporarily using other settings

It may be necessary for some test cases to perform XML checks with changed filter settings. Then it is possible to

To make it even more simple you can use the automatic object AutoRestoreXmlCheck for storing and restoring settings:

//...
{
// Store current settings
TTB::AutoRestoreXmlCheck autoRestoreXmlCheck;
// Clear all settings
TTB::TheXmlCheck()->SetDefaults();
// Define new settings
TTB::TheXmlCheck()->IgnoreNode("Group_A");
TTB::TheXmlCheck()->IgnoreNode("Group_B");
// Do something with the new settings
TTB::TheXmlCheck()->CheckNode(doc);
TTB_EXP("MyContainer");
TTB_EXP(" Group_C");
TTB_EXP(" Interior");
TTB_EXP(" Something");
TTB_EXP(" Some text");
TTB_EXP(" date");
TTB_EXP(" 28.09.09");
} // previous settings for XmlCheck are restored when leaving scope
//...

An other simple alternative for ensuring proper settings for XmlCheeck would be to initialize XmlCheck with desired settings within constructor or destructor of your test suite fixture.

Using a local instance of XmlCheck

Instead of relying on a global singleton instance of XmlCheck you can also instantiate local instances of XmlCheck for some or all of your test cases:

{
// Create local instance of XmlCheck and connect it to TestEvents
TTB::XmlCheckSp spMyXmlCheck = TTB::XmlCheck::CreateLocalInstance(
TTB::TheTestEvents());
// Define desired settings
spMyXmlCheck->IgnoreNode("Group_A");
spMyXmlCheck->IgnoreNode("Group_B");
// Remark: settings of singleton instance of XmlCheck are not affected
// Perform check
spMyXmlCheck->CheckNode(doc);
TTB_EXP("MyContainer");
TTB_EXP(" Group_C");
TTB_EXP(" Interior");
TTB_EXP(" Something");
TTB_EXP(" Some text");
TTB_EXP(" date");
TTB_EXP(" 28.09.09");
} // when leaving scope local instance of XmlCheck is automatically destroyed

All instances are independent from each other. A small disadvantage may be that you have to create and initialize all instances.