assertion_traits

   
assertion_traits

Description

The template assertion_traits (see Figure C-1) is used by the CPPUNIT_ASSERT_EQUAL() macro. The template is specialized for different data types that are passed to the macro. For example, the template specialization assertion_traits<int> is used when CPPUNIT_ASSERT_EQUAL( ) takes arguments of type int .

The declaration of assertion_traits is found in TestAssert.h . It belongs to the namespace CppUnit .

Figure C-1. The template assertion_traits
figs/utf_ac01.gif

Declaration

 template<class T> struct assertion_traits<T> 

Constructors/Destructors

None.

Public Methods


static bool equal(const T& x, const T& y)

A function template to compare two arguments of type T . The default implementation compares them using == .


static string toString(const T& x)

A function template to output a string representing the input argument of type T . The default implementation creates the output string by creating a std::OStringStream and using its << operator.

Protected/Private Methods

None.

Attributes

None.

   
AutoRegisterSuite

Description

The template AutoRegisterSuite (Figure C-2) is not intended for direct usage. It is statically instantiated by the macros CPPUNIT_TEST_SUITE_REGISTRATION() and CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ) . It registers a test of the type TestCaseType . For more details on test registration, see the description of TestFactoryRegistry , later in this appendix.

AutoRegisterSuite belongs to the namespace CppUnit . It is declared and implemented in extensions/AutoRegisterSuite.h .

Figure C-2. The template AutoRegisterSuite
figs/utf_ac02.gif

Declaration

 template<typename TestCaseType>

   class AutoRegisterSuite<TestCaseType> 

Constructors/Destructors


AutoRegisterSuite( )

Registers the test suite in the global registry.


AutoRegisterSuite(const string& name )

Registers the test suite in the registry specified by name .

Public Methods

None.

Protected/Private Methods

None.

Attributes

None.

   
CompilerOutputter

Description

The class CompilerOutputter (see Figure C-3) is a subclass of Outputter . It outputs test results in the format that the Microsoft Visual C++ (VC++) IDE uses for compiler errors, enabling the IDE to locate test assertions in the code.

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

Figure C-3. The class CompilerOutputter
figs/utf_ac03.gif

Declaration

 class CompilerOutputter : public Outputter 

Constructors/Destructors


CompilerOutputter(TestResultCollector *result, ostream & stream)

Creates a CompilerOutputter to get test results from result and outputs them to stream .


virtual ~CompilerOutputter( )

A destructor.

Public Methods


static CompilerOutputter *defaultOutputter( TestResultCollector *result, ostream& stream)

A static method that returns a new CompilerOutputter .


virtual void printDefaultMessage(Exception *thrownException)

virtual void printFailedTestName(TestFailure *failure)

virtual void printFailureDetail(TestFailure *failure)

virtual void printFailureLocation(SourceLine sourceLine)

virtual void printFailureMessage(TestFailure *failure)

virtual void printFailureReport( )

virtual void printFailuresList( )

virtual void printFailureType(TestFailure *failure)

virtual void printNotEqualMessage(Exception *thrownException)

virtual void printStatistics( )

virtual void printSucess( )

Methods that write test results from m_result to m_stream . Called by write( ) .


virtual string wrap(string message)

Returns message with carriage returns inserted to fit 80-column output width.


void write( )

A method called to output results. Depending on test success or failure, calls printSucess( ) or printFailureReport( ) , which in turn call the other print methods just described.

Protected/Private Methods


static Lines splitMessageIntoLines(string message)

Breaks message into Lines ( private ).


CompilerOutputter(const CompilerOutputter& copy)

A copy constructor, which is scoped private to prevent its use.


void operator=(const CompilerOutputter& copy)

A copy operator, which is scoped private to prevent its use.

Attributes


typedef vector<string> Lines

Defines the type Lines as a vector of string ( private ).


TestResultCollector *m_result

The TestResultCollector passed in the constructor ( private )


ostream& m_stream

The output stream passed in the constructor ( private ).