1#ifndef CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H 2#define CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H 3 4#include <cppunit/Portability.h> 5#include <cppunit/Outputter.h> 6#include <vector> 7#include <iostream> 8 9namespace CppUnit 10{ 11 12class Exception; 13class SourceLine; 14class Test; 15class TestFailure; 16class TestResultCollector; 17 18/*! 19 * \brief Outputs a TestResultCollector in a compiler compatible format. 20 * \ingroup WritingTestResult 21 * 22 * Printing the test results in a compiler compatible format (assertion 23 * location has the same format as compiler error), allow you to use your 24 * IDE to jump to the assertion failure. 25 * 26 * For example, when running the test in a post-build with VC++, if an assertion 27 * fails, you can jump to the assertion by pressing F4 (jump to next error). 28 * 29 * You should use defaultOutputter() to create an instance. 30 * 31 * Heres is an example of usage (from examples/cppunittest/CppUnitTestMain.cpp): 32 * \code 33 * int main( int argc, char* argv[] ) { 34 * // if command line contains "-selftest" then this is the post build check 35 * // => the output must be in the compiler error format. 36 * bool selfTest = (argc > 1) && 37 * (string("-selftest") == argv[1]); 38 * 39 * CppUnit::TextUi::TestRunner runner; 40 * runner.addTest( CppUnitTest::suite() ); // Add the top suite to the test runner 41 * 42 * if ( selfTest ) 43 * { // Change the default outputter to a compiler error format outputter 44 * // The test runner owns the new outputter. 45 * runner.setOutputter( CppUnit::CompilerOutputter::defaultOutputter( 46 * &runner.result(), 47 * cerr ) ); 48 * } 49 * 50 * // Run the test and don't wait a key if post build check. 51 * bool wasSucessful = runner.run( "", !selfTest ); 52 * 53 * // Return error code 1 if the one of test failed. 54 * return wasSucessful ? 0 : 1; 55 * } 56 * \endcode 57 */ 58class CPPUNIT_API CompilerOutputter : public Outputter 59{ 60public: 61 /*! Constructs a CompilerOutputter object. 62 */ 63 CompilerOutputter( TestResultCollector *result, 64 std::ostream &stream ); 65 66 /// Destructor. 67 virtual ~CompilerOutputter(); 68 69 /*! Creates an instance of an outputter that matches your current compiler. 70 */ 71 static CompilerOutputter *defaultOutputter( TestResultCollector *result, 72 std::ostream &stream ); 73 74 void write(); 75 76 virtual void printSucess(); 77 virtual void printFailureReport(); 78 virtual void printFailuresList(); 79 virtual void printStatistics(); 80 virtual void printFailureDetail( TestFailure *failure ); 81 virtual void printFailureLocation( SourceLine sourceLine ); 82 virtual void printFailureType( TestFailure *failure ); 83 virtual void printFailedTestName( TestFailure *failure ); 84 virtual void printFailureMessage( TestFailure *failure ); 85 virtual void printNotEqualMessage( Exception *thrownException ); 86 virtual void printDefaultMessage( Exception *thrownException ); 87 virtual std::string wrap( std::string message ); 88 89private: 90 /// Prevents the use of the copy constructor. 91 CompilerOutputter( const CompilerOutputter © ); 92 93 /// Prevents the use of the copy operator. 94 void operator =( const CompilerOutputter © ); 95 96 typedef std::vector<std::string> Lines; 97 static Lines splitMessageIntoLines( std::string message ); 98 99private: 100 TestResultCollector *m_result; 101 std::ostream &m_stream; 102}; 103 104 105} // namespace CppUnit 106 107 108 109#endif // CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H 110