The class XmlOutputter (see Figure C-36) is a subclass of Outputter . It gets test results from a TestResultCollector and outputs them in XML format to an output stream. The write( ) method is called to produce the output, rather than calling the other output methods directly.

XmlOutputter defines a nested class named Node representing an XML node.

XmlOutputter belongs to the namespace CppUnit . It is declared in XmlOutputter.h and implemented in XmlOutputter.cpp .

Figure C-36. The class XmlOutputter


 class XmlOutputter : public Outputter 


XmlOutputter(TestResultCollector *result, ostream &stream, string encoding = "ISO-8859-1")

Constructs an XmlOutputter to get test results from result and output them to stream . The default encoding is ASCII, also known as Latin-1 or ISO 8859-1.

virtual ~XmlOutputter( )

A destructor.

Public Methods

virtual void addFailedTest(Test *test, TestFailure *failure, int testNumber, Node *testsNode)

Creates an XML node representing the test failure and adds it to testsNode . Also calls addFailureLocation() if the test failure has a valid SourceLine .

virtual void addFailedTests(FailedTests &failedTests, Node *rootNode)

Adds the test failures from failedTests to rootNode using addFailedTest( ) .

virtual void addFailureLocation(TestFailure *failure, Node *testNode)

Creates an XML node representing the test failure location and adds it to testNode .

virtual void addStatistics(Node *rootNode)

Creates an XML node containing the number of tests, number of failures, and number of errors, and adds it to rootNode .

virtual void addSucessfulTest(Test *test, int testNumber, Node *testsNode)

Creates an XML node representing a test success and adds it to testsNode .

virtual void addSucessfulTests(FailedTests &failedTests, Node *rootNode)

Adds the successful tests from the TestResultCollector to rootNode using addSucessfulTest( ) .

virtual Node *makeRootNode( )

Creates a Node and adds the test results to it using addFailedTests( ) , addSucessfulTests( ) , and addStatistics() .

virtual void writeProlog( )

A method that writes the XML prolog (header), which includes the XML version (1.0) and the encoding type.

virtual void writeTestsResult( )

A method that writes the body of the XML document. Calls makeRootNode( ) and writes the resulting Node to the output stream as a string .

void write( )

Method called to write the test results to the output stream as an XML document. Calls writeProlog( ) and writeTestsResult( ) .

Protected/Private Methods

virtual void fillFailedTestsMap(FailedTests &failedTests)

A protected method to get the test failures from the TestResultCollector and add them to failedTests .

XmlOutputter(const XmlOutputter& copy)

A copy constructor, scoped private to prevent its use.

void operator=(const XmlOutputter& copy)

A copy operator, scoped private to prevent its use.


typedef map<Test *,TestFailure*> FailedTests

Defines the type FailedTests as a map of Test objects to TestFailure objects.

string m_encoding

The encoding type to be written in the XML prolog ( private ).

TestResultCollector *m_result

The TestResultCollector passed in the constructor ( private ).

ostream& m_stream

The output stream passed in the constructor ( private ).

Unit Test Frameworks
Unit Test Frameworks
ISBN: 0596006896
EAN: 2147483647
Year: 2006
Pages: 146
Authors: Paul Hamill

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net