[Cppunit-cvs] cppunit2/src/cpput lighttestrunner.cpp,NONE,1.1 assertstring.cpp,1.3,1.4 cpput.vcproj,
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-07-02 20:27:49
|
Update of /cvsroot/cppunit/cppunit2/src/cpput In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14915/src/cpput Modified Files: assertstring.cpp cpput.vcproj testinfo.cpp testrunner.cpp Added Files: lighttestrunner.cpp Log Message: * Added a simple test runner that does not rely on the open test framework to run cppunit2 tests. * added CppTL::ConstCharView to wrapper const char *strings. * added CppTL::quoteMultiLineString() * string assertion output actual and expected using quoteMultiLineString(). * added serialize unit test for basic Properties * opentest tests now use the LightTestRunner. Index: assertstring.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/assertstring.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** assertstring.cpp 27 Feb 2005 10:13:37 -0000 1.3 --- assertstring.cpp 2 Jul 2005 20:27:36 -0000 1.4 *************** *** 14,19 **** Message newMessage( message ); newMessage.add( translate( "String does not start with the expected pattern." ) ); ! newMessage.add( translate( "Expected start: " ) + CppTL::quoteString( pattern ) ); ! newMessage.add( translate( "Actual string: " ) + CppTL::quoteString( string ) ); fail( newMessage ); } --- 14,19 ---- Message newMessage( message ); newMessage.add( translate( "String does not start with the expected pattern." ) ); ! newMessage.add( translate( "Expected start: " ) + CppTL::quoteMultiLineString( pattern ) ); ! newMessage.add( translate( "Actual string: " ) + CppTL::quoteMultiLineString( string ) ); fail( newMessage ); } *************** *** 31,36 **** Message newMessage( message ); newMessage.add( translate( "String does not end with the expected pattern." ) ); ! newMessage.add( translate( "Expected end: " ) + CppTL::quoteString( pattern ) ); ! newMessage.add( translate( "Actual string: " ) + CppTL::quoteString( string ) ); fail( newMessage ); } --- 31,36 ---- Message newMessage( message ); newMessage.add( translate( "String does not end with the expected pattern." ) ); ! newMessage.add( translate( "Expected end: " ) + CppTL::quoteMultiLineString( pattern ) ); ! newMessage.add( translate( "Actual string: " ) + CppTL::quoteMultiLineString( string ) ); fail( newMessage ); } *************** *** 47,52 **** Message newMessage( message ); newMessage.add( translate( "String does not contain the expected pattern." ) ); ! newMessage.add( translate( "Expected pattern: " ) + CppTL::quoteString( pattern ) ); ! newMessage.add( translate( "Actual string: " ) + CppTL::quoteString( string ) ); fail( newMessage ); } --- 47,52 ---- Message newMessage( message ); newMessage.add( translate( "String does not contain the expected pattern." ) ); ! newMessage.add( translate( "Expected pattern: " ) + CppTL::quoteMultiLineString( pattern ) ); ! newMessage.add( translate( "Actual string: " ) + CppTL::quoteMultiLineString( string ) ); fail( newMessage ); } *************** *** 76,83 **** newMessage.add( translate( "Strings are not equal." ) ); if ( !common.empty() ) ! newMessage.add( translate( "Common: " ) + CppTL::quoteString( common ) ); newMessage.add( translate( "Divergence position (0 based): " ) + stringize( differenceIndex ) ); ! newMessage.add( translate( "Expected (at divergence): " ) + CppTL::quoteString( expectedTail ) ); ! newMessage.add( translate( "Actual (at divergence): " ) + CppTL::quoteString( actualTail ) ); fail( newMessage ); } --- 76,83 ---- newMessage.add( translate( "Strings are not equal." ) ); if ( !common.empty() ) ! newMessage.add( translate( "Common: " ) + CppTL::quoteMultiLineString( common ) ); newMessage.add( translate( "Divergence position (0 based): " ) + stringize( differenceIndex ) ); ! newMessage.add( translate( "Expected (at divergence): " ) + CppTL::quoteMultiLineString( expectedTail ) ); ! newMessage.add( translate( "Actual (at divergence): " ) + CppTL::quoteMultiLineString( actualTail ) ); fail( newMessage ); } --- NEW FILE: lighttestrunner.cpp --- #include <cpput/lighttestrunner.h> #include <cpput/testcase.h> #include <cpput/testsuite.h> #include <cpptl/sharedptr.h> #include <cpptl/stringtools.h> #include <stdio.h> namespace CppUT { LightTestRunner::LightTestRunner() : testRun_( 0 ) , testFailed_( 0 ) { } LightTestRunner::~LightTestRunner() { } void LightTestRunner::addTest( const TestPtr &test ) { tests_.push_back( test ); } bool LightTestRunner::runAllTests() { TestInfo::setTestResultUpdater( *this ); for ( Tests::iterator it = tests_.begin(); it != tests_.end(); ++it ) runTest( *it ); printf( "Failure report:\n", report_ ); return testFailed_ == 0; } void LightTestRunner::runTest( const TestPtr &test ) { testPath_.push_back( test->name() ); if ( test->isTestCase() ) runTestCase( CppTL::staticPointerCast<AbstractTestCase>( test ) ); else runTestSuite( CppTL::staticPointerCast<TestSuite>( test ) ); testPath_.pop_back(); } void LightTestRunner::runTestSuite( const TestSuitePtr &suite ) { for ( int index =0; index < suite->testCount(); ++index ) runTest( suite->testAt( index ) ); } void LightTestRunner::runTestCase( const AbstractTestCasePtr &testCase ) { result_.clear(); printf( "Testing %s : ", getTestPath().c_str() ); TestInfo::startNewTest(); testCase->run(); ++testRun_; OpenTest::PropertiesAccessor status = result_.accessor()["result"]["status"]; bool succeeded = status.getValue( "success", false ).asBool(); CppTL::ConstString statusInfo; printf( "%s\n", succeeded ? "OK" : "FAIL" ); if ( !succeeded ) { ++testFailed_; CppTL::ConstString resultType = status.getValue( "type", "" ).asString(); if ( !resultType.empty() ) statusInfo += " (" + resultType + ")"; report_ += "-> " + getTestPath() + statusInfo + "\n"; OpenTest::PropertiesAccessor info = result_.accessor(); OpenTest::Properties::ValueEnum enumFaults = info["result/faults"].listValues(); while ( enumFaults.hasNext() ) { OpenTest::Value fault = enumFaults.next(); reportFailure( fault.asProperties(), false ); } OpenTest::Properties::ValueEnum enumAssertions = info["result/assertions"].listValues(); while ( enumAssertions.hasNext() ) { OpenTest::Value assertion = enumAssertions.next(); reportFailure( assertion.asProperties(), true ); } report_ += "\n"; } } void LightTestRunner::mergeInResult( const OpenTest::Properties &result ) { result_.mergeReplacingExisting( result ); } void LightTestRunner::mergeInResult( const OpenTest::PropertyPath &path, const OpenTest::Value &value ) { result_[path] = value; } void LightTestRunner::appendToResult( const OpenTest::PropertyPath &path, const OpenTest::Value &value ) { result_[path].append( value ); } CppTL::ConstString LightTestRunner::getTestPath() const { CppTL::StringBuffer buffer; for ( TestPath::const_iterator it = testPath_.begin(); it != testPath_.end(); ++it ) buffer += "/" + *it; return buffer; } void LightTestRunner::reportFailure( const OpenTest::Properties &failure, bool isAssertion ) { if ( failure.has( "location") && failure.has("location/file") ) { report_ += failure["location/file"].asString() + "(" + CppTL::toString( failure["location/line"].asInt() ) + ") : "; } else report_ += "unknwon failure location : "; CppTL::ConstString failureType = failure.getValue( "failure_type", isAssertion ? "assertion" : "fault" ).asString(); report_ += "[failure type: " + failureType + "]\n"; OpenTest::Properties::ValueEnum enumMessages = failure.accessor()["messages"].listValues(); if ( enumMessages.hasNext() ) report_ += "Messages:\n"; while ( enumMessages.hasNext() ) report_ += enumMessages.next().asString() + "\n"; OpenTest::Properties::ValueEnum enumLogs = failure.accessor()["logs"].listValues(); if ( enumLogs.hasNext() ) report_ += "Log:\n"; while ( enumLogs.hasNext() ) report_ += enumLogs.next().asString() + "\n"; report_ += "Specifics:\n" + failure.toString() + "\n"; } } // namespace CppUT Index: testrunner.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/testrunner.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** testrunner.cpp 28 Feb 2005 22:31:37 -0000 1.9 --- testrunner.cpp 2 Jul 2005 20:27:36 -0000 1.10 *************** *** 126,131 **** tracker.startTestRun(); TestResultUpdaterImplPtr resultUpdater( new TestResultUpdaterImpl( tracker ) ); ! TestInfo::setTestResultUpdater( CppTL::staticPointerCast<TestResultUpdater>( ! resultUpdater ) ); OpenTest::TestPlanEntryPtrEnum enumEntries = testPlan.entries(); --- 126,130 ---- tracker.startTestRun(); TestResultUpdaterImplPtr resultUpdater( new TestResultUpdaterImpl( tracker ) ); ! TestInfo::setTestResultUpdater( *resultUpdater ); OpenTest::TestPlanEntryPtrEnum enumEntries = testPlan.entries(); Index: cpput.vcproj =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/cpput.vcproj,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** cpput.vcproj 1 Jul 2005 08:19:36 -0000 1.33 --- cpput.vcproj 2 Jul 2005 20:27:36 -0000 1.34 *************** *** 439,442 **** --- 439,448 ---- </File> <File + RelativePath=".\lighttestrunner.cpp"> + </File> + <File + RelativePath="..\..\include\cpput\lighttestrunner.h"> + </File> + <File RelativePath="..\..\include\cpput\message.h"> </File> Index: testinfo.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/testinfo.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** testinfo.cpp 6 Mar 2005 18:49:59 -0000 1.10 --- testinfo.cpp 2 Jul 2005 20:27:36 -0000 1.11 *************** *** 43,46 **** --- 43,47 ---- , assertionCount_( 0 ) , failedAssertionCount_( 0 ) + , updater_( 0 ) { } *************** *** 93,97 **** } ! TestResultUpdaterPtr updater_; OpenTest::Properties result_; OpenTest::Properties assertion_; --- 94,98 ---- } ! TestResultUpdater *updater_; OpenTest::Properties result_; OpenTest::Properties assertion_; *************** *** 121,127 **** } ! void setTestResultUpdater( const TestResultUpdaterPtr &updater ) { ! data().updater_ = updater; } --- 122,128 ---- } ! void setTestResultUpdater( TestResultUpdater &updater ) { ! data().updater_ = &updater; } |