TestToolBox::XmlCheck Class Reference

Check an XML tree/subtree or compare two trees/subtrees. For more info about usage see Using XmlCheck. More...

#include <XmlCheck.h>

Collaboration diagram for TestToolBox::XmlCheck:
Collaboration graph
[legend]

List of all members.

Protected Attributes

IEventReceiverm_pEventReceiver
 Interface for receiving all kinds of test events.

Private Member Functions

void WriteNode (TiXmlNode *in_pNode, unsigned int in_indent, int in_maxChildNodes=0, char const *in_file=0, long in_lineNum=0, FormattedContents *in_pContents=0)
 Write given XML node to EventReceiver or given optional container.
void WriteAttributes (TiXmlElement *in_pElement, unsigned int in_indent, char const *in_file=0, long in_lineNum=0, FormattedContents *in_pContents=0)
 Writes attributes of given XML node to EventReceiver.
std::string IfDetailed (std::string const &in_str)
 Helper function to produce more detailed output.

Private Attributes

EventContext m_outputMode
 Output mode for writing XML contents.
bool m_detailedOutput
 Flag indicating whether the output contains more details.
std::set< std::string > m_attributesToIgnore
 Set of attribute names to ignore when checking an XML tree.
std::set< std::string > m_nodesToIgnore
 Set of node names to ignore when checking an XML tree.
std::map< std::string, int > m_doubleAttributes
 Set of attribute names to be treated as doubles with specific precision.
std::map< std::string, int > m_doubleNodes
 Set of node names to be treated as doubles with specific precision.
std::string m_compareResult
 Result of last call to Compare().

Static Private Attributes

static const unsigned int NUM_INDENTS_PER_SPACE = 2
 Indenting to be used when writing an XML tree to test output.

Configuration



IEventReceiverSetEventReceiver (IEventReceiver *in_pEventReceiver)
 Define to which destination test events (e.g. failures) are reported.
void SetDefaults (void)
 Set default values for the following settings.
void SetOutputModeForWritingXmlContents (EventContext in_outputMode)
 Set output mode for writing XML contents.
void SetDetailedOutput (bool in_detailedOutput)
 Set amount of data written to test output.
void IgnoreAttribute (std::string const &in_attribute, bool in_ignore=true)
 Define whether the given attribute shall be ignored when checking XML data.
bool IsAttributeToIgnore (std::string const &in_attribute) const
 Return whether the given attribute shall be ignored when checking XML data.
void IgnoreNode (std::string const &in_nodeName, bool in_ignore=true)
 Define whether the given node shall be ignored when checking XML data.
bool IsNodeToIgnore (std::string const &in_nodeName) const
 Return whether the given node shall be ignored when checking XML data.
void UseAsDoubleAttribute (std::string const &in_attribute, bool in_useAsDouble=true, int in_precision=4)
 Define whether the given attribute is of type double and in case of type double specify the precision to be used for checking the value.
bool IsDoubleAttribute (std::string const &in_attribute) const
 Return whether the given attribute is of type double.
int GetPrecisionOfDoubleAttribute (std::string const &in_attribute) const
 Return the precision used for checking of the given double attribute.
void UseAsDoubleNode (std::string const &in_nodeName, bool in_useAsDouble=true, int in_precision=4)
 Define whether the given node is of type double and in case of type double specify the precision to be used for checking the value.
bool IsDoubleNode (std::string const &in_nodeName) const
 Return whether the given node is of type double.
int GetPrecisionOfDoubleNode (std::string const &in_nodeName) const
 Return the precision used for checking of the given double node.

Check XML contents



void CheckNode (TiXmlNode *in_pNode, char const *in_file=0, long in_lineNum=0)
 Writes contents of given XML node to EventReceiver. Each attribute and text is reported with a separate call to EventReceiver.
void CheckSubNode (TiXmlNode *in_pNode, std::string const &in_xPathExpression_1, std::string const &in_xPathExpression_2="", std::string const &in_xPathExpression_3="", std::string const &in_xPathExpression_4="", std::string const &in_xPathExpression_5="", char const *in_file=0, long in_lineNum=0)
 Writes contents of given XML node to EventReceiver. Each attribute and text is reported with a separate call to EventReceiver.
void CheckSubNodeWithMaxChilds (int in_maxChilds, TiXmlNode *in_pNode, std::string const &in_xPathExpression_1, std::string const &in_xPathExpression_2="", std::string const &in_xPathExpression_3="", std::string const &in_xPathExpression_4="", std::string const &in_xPathExpression_5="", char const *in_file=0, long in_lineNum=0)
 Same as CheckSubNode() but writes contents only for the first in_maxChilds direct child elements of the node identified by the XPath expression(s).
bool Compare (TiXmlNode *in_pNodeA, TiXmlNode *in_pNodeB, char const *in_file=0, long in_lineNum=0)
 Compares two XML (sub) trees. The result depends on the settings for attributes/nodes to ignore and for the used precision of double values.
std::string GetCompareResult (void) const
 Get textual description of the last call to Compare.

Helper functions



static std::string GetFullPath (TiXmlNode *in_pNode, std::string const &in_rPathToConcat="")
 Get the path for the given node.
static TiXmlNode * SubNodeFromXPath (TiXmlNode *in_pParentNode, std::string const &in_xPathExpression_1, std::string const &in_xPathExpression_2="", std::string const &in_xPathExpression_3="", std::string const &in_xPathExpression_4="", std::string const &in_xPathExpression_5="")
 Get the node from the given parent node and the given path description.

Detailed Description

Check an XML tree/subtree or compare two trees/subtrees. For more info about usage see Using XmlCheck.

See also:
XmlCheck.h (File documentation)
TestXmlCheckBasic (basic tests)
TestXmlCheckWithBoost (tests with Boost)
TestXmlCheckWithBoostExtensions (tests with Boost and TestToolBox::TestEvents)

Member Function Documentation

IEventReceiver* TestToolBox::XmlCheck::SetEventReceiver ( IEventReceiver in_pEventReceiver  ) 

Define to which destination test events (e.g. failures) are reported.

Returns:
previous EventReceiver
void TestToolBox::XmlCheck::SetOutputModeForWritingXmlContents ( EventContext  in_outputMode  ) 

Set output mode for writing XML contents.

Allowed values: CTX_PROT, CTX_INFO, CTX_TEST_EVENT

void TestToolBox::XmlCheck::CheckNode ( TiXmlNode *  in_pNode,
char const *  in_file = 0,
long  in_lineNum = 0 
)

Writes contents of given XML node to EventReceiver. Each attribute and text is reported with a separate call to EventReceiver.

Parameters:
in_pNode XML (sub)tree to check
in_file optional file name used in case of error
in_lineNum optional line number used in case of error
void TestToolBox::XmlCheck::CheckSubNode ( TiXmlNode *  in_pNode,
std::string const &  in_xPathExpression_1,
std::string const &  in_xPathExpression_2 = "",
std::string const &  in_xPathExpression_3 = "",
std::string const &  in_xPathExpression_4 = "",
std::string const &  in_xPathExpression_5 = "",
char const *  in_file = 0,
long  in_lineNum = 0 
)

Writes contents of given XML node to EventReceiver. Each attribute and text is reported with a separate call to EventReceiver.

Parameters:
in_pNode XML (sub)tree to check
in_xPathExpression_1 XPath expression defining a subnode
in_xPathExpression_2 XPath expression defining a subnode of level 2
in_xPathExpression_3 XPath expression defining a subnode of level 3
in_xPathExpression_4 XPath expression defining a subnode of level 4
in_xPathExpression_5 XPath expression defining a subnode of level 5
in_file optional file name used in case of error
in_lineNum optional line number used in case of error
void TestToolBox::XmlCheck::CheckSubNodeWithMaxChilds ( int  in_maxChilds,
TiXmlNode *  in_pNode,
std::string const &  in_xPathExpression_1,
std::string const &  in_xPathExpression_2 = "",
std::string const &  in_xPathExpression_3 = "",
std::string const &  in_xPathExpression_4 = "",
std::string const &  in_xPathExpression_5 = "",
char const *  in_file = 0,
long  in_lineNum = 0 
)

Same as CheckSubNode() but writes contents only for the first in_maxChilds direct child elements of the node identified by the XPath expression(s).

Parameters:
in_maxChilds max number of childs to check
in_pNode XML (sub)tree to check
in_xPathExpression_1 XPath expression defining a subnode
in_xPathExpression_2 XPath expression defining a subnode of level 2
in_xPathExpression_3 XPath expression defining a subnode of level 3
in_xPathExpression_4 XPath expression defining a subnode of level 4
in_xPathExpression_5 XPath expression defining a subnode of level 5
in_file optional file name used in case of error
in_lineNum optional line number used in case of error
bool TestToolBox::XmlCheck::Compare ( TiXmlNode *  in_pNodeA,
TiXmlNode *  in_pNodeB,
char const *  in_file = 0,
long  in_lineNum = 0 
)

Compares two XML (sub) trees. The result depends on the settings for attributes/nodes to ignore and for the used precision of double values.

Returns:
true if the XML trees are identical
Parameters:
in_pNodeA XML (sub)tree A to check
in_pNodeB XML (sub)tree B to check
in_file optional file name used in case of error
in_lineNum optional line number used in case of error
void TestToolBox::XmlCheck::WriteNode ( TiXmlNode *  in_pNode,
unsigned int  in_indent,
int  in_maxChildNodes = 0,
char const *  in_file = 0,
long  in_lineNum = 0,
FormattedContents *  in_pContents = 0 
) [private]

Write given XML node to EventReceiver or given optional container.

Parameters:
in_pNode XML (sub)tree to check
in_indent indentation for pretty format
in_maxChildNodes maximum number of direct childs to check, 0 : all childs
in_file optional file name used in case of error
in_lineNum optional line number used in case of error
in_pContents optional container to write output to instead of using configured EventReceiver
void TestToolBox::XmlCheck::WriteAttributes ( TiXmlElement *  in_pElement,
unsigned int  in_indent,
char const *  in_file = 0,
long  in_lineNum = 0,
FormattedContents *  in_pContents = 0 
) [private]

Writes attributes of given XML node to EventReceiver.

Each attribute and text is reported with a separate call to EventReceiver.

Parameters:
in_pElement XML (sub)tree to check
in_indent indentation for pretty format
in_file optional file name used in case of error
in_lineNum optional line number used in case of error
in_pContents optional container to write output to

The documentation for this class was generated from the following file:
Generated on Fri May 27 22:58:04 2011 for TestToolBox by  doxygen 1.6.3