Update of /cvsroot/cpptool/CppParser/src/cpputtest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20897/src/cpputtest Modified Files: assertstringtest.cpp cpputtest.dsp cpputtest.vcproj main.cpp mocktestlistener.h testbasicassertion.cpp testfixturetest.cpp testfixturetest.h testfunctor.cpp testtestcase.cpp testtestcontext.cpp testtestsuite.cpp Added Files: commandlineoptionstest.cpp commandlineoptionstest.h testtestrunresult.cpp Removed Files: testresult.cpp Log Message: * upgraded to current cppunit 2 cvs Index: main.cpp =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cpputtest/main.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** main.cpp 8 Jun 2004 20:23:24 -0000 1.1.1.1 --- main.cpp 5 Aug 2004 20:52:46 -0000 1.2 *************** *** 1,9 **** ! #include <iostream> ! #include <cpput/result.h> #include <cpput/test.h> #include <cpput/testcontext.h> #include <cpput/testsuite.h> #include "assertenumtest.h" #include "assertstringtest.h" #include "registrytest.h" #include "enumeratortest.h" --- 1,11 ---- ! #include <cpput/progresslistener.h> ! #include <cpput/testrunresult.h> #include <cpput/test.h> #include <cpput/testcontext.h> #include <cpput/testsuite.h> + #include <iostream> #include "assertenumtest.h" #include "assertstringtest.h" + #include "commandlineoptionstest.h" #include "registrytest.h" #include "enumeratortest.h" *************** *** 13,17 **** bool testBasicAssertions(); bool testTestContext(); ! bool testResult(); bool testTestSuite(); bool testTestCase(); --- 15,19 ---- bool testBasicAssertions(); bool testTestContext(); ! bool testTestRunResult(); bool testTestSuite(); bool testTestCase(); *************** *** 23,27 **** return testBasicAssertions() && testFunctors() && ! testResult() && testTestContext() && testTestSuite() && --- 25,29 ---- return testBasicAssertions() && testFunctors() && ! testTestRunResult() && testTestContext() && testTestSuite() && *************** *** 30,42 **** - static std::string makeTestPath( const CppUT::Test &test ) - { - if ( test.parentTest() ) - return makeTestPath( *test.parentTest() ) + "/" + test.name(); - return test.name(); - } - static void dumpFailures( const CppUT::TestSuite &allSuite, ! const CppUT::Result &result ) { if ( result.successful() ) --- 32,37 ---- static void dumpFailures( const CppUT::TestSuite &allSuite, ! const CppUT::TestRunResult &result ) { if ( result.successful() ) *************** *** 48,52 **** for ( int index =0; index < result.failureCount(); ++index ) { ! const CppUT::TestFailure &failure = result.failureAt( index ); if ( failure.location().isValid() ) --- 43,47 ---- for ( int index =0; index < result.failureCount(); ++index ) { ! const CppUT::TestResult &failure = result.failureAt( index ); if ( failure.location().isValid() ) *************** *** 54,58 **** else std::cout << "Unknown failure location: "; ! std::cout << makeTestPath( failure.failedTest() ) << std::endl; std::cout << failure.message().toString() << std::endl; } --- 49,53 ---- else std::cout << "Unknown failure location: "; ! std::cout << CppUT::path( failure.test() ) << std::endl; std::cout << failure.message().toString() << std::endl; } *************** *** 63,90 **** - - class ShowProgress : public CppUT::TestListener - { - public: - void testFailed( const CppUT::TestFailure &failure, - CppUT::TestContext &context ) - { - testFailed_ = true; - } - - void enterTest( CppUT::Test &test, CppUT::TestContext &context ) - { - testFailed_ = false; - std::cout << "Testing '" << makeTestPath( test ) << "' : "; - } - - void exitTest( CppUT::Test &test, CppUT::TestContext &context ) - { - std::cout << (testFailed_ ? "FAILURE" : "OK") << std::endl; - } - - bool testFailed_; - }; - int main( int argc, const char *argv[] ) { --- 58,61 ---- *************** *** 105,114 **** allSuite->add( EnumeratorTest::suite() ); allSuite->add( AssertEnumTest::suite() ); CppUT::TestContext context; ! CppUT::Result result; context.add( result ); ! ShowProgress progress; context.add( progress ); allSuite->run( context ); --- 76,86 ---- allSuite->add( EnumeratorTest::suite() ); allSuite->add( AssertEnumTest::suite() ); + allSuite->add( CommandLineOptionsTest::suite() ); CppUT::TestContext context; ! CppUT::TestRunResult result; context.add( result ); ! CppUT::BriefProgressListener progress; context.add( progress ); allSuite->run( context ); Index: assertstringtest.cpp =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cpputtest/assertstringtest.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** assertstringtest.cpp 8 Jun 2004 20:23:24 -0000 1.1.1.1 --- assertstringtest.cpp 5 Aug 2004 20:52:46 -0000 1.2 *************** *** 1,5 **** #include "assertstringtest.h" #include <cpput/assertstring.h> ! #include <cpput/assertexception.h> #include <string.h> // use string.h for easier portability --- 1,5 ---- #include "assertstringtest.h" #include <cpput/assertstring.h> ! #include <cpput/resultexception.h> #include <string.h> // use string.h for easier portability --- NEW FILE: commandlineoptionstest.cpp --- #include "commandlineoptionstest.h" #include <cpput/assertstring.h> //#include <cpputtools/value.h> using namespace CppUTTools; #define LOCAL_CHECK_PARSE \ CPPUT_BEGIN_ASSERTION_MACRO() \ checkParse #define LOCAL_CHECK_PARSE_BAD_OPTION \ CPPUT_BEGIN_ASSERTION_MACRO() \ checkParseBadOption void CommandLineOptionsTest::setUp() { values_ = 0; } void CommandLineOptionsTest::tearDown() { delete values_; } void CommandLineOptionsTest::checkParse( CommandLineOptions::OptionsDescription &description, const char *argv[] ) { delete values_; values_ = new CommandLineOptions::OptionsValues(); std::vector<const char *> commandLine; commandLine.push_back( "test_app.exe" ); while ( *argv ) commandLine.push_back( *argv++ ); CommandLineOptions::parseCommandLine( commandLine.size(), &commandLine[0], description, *values_ ); values_->validate( description ); values_->store( description ); } void CommandLineOptionsTest::checkParseBadOption( CommandLineOptions::OptionsDescription &description, const char *argv[], const std::string &badOptionName ) { try { checkParse( description, argv ); CppUT::fail( "Bad option '" + badOptionName + "' not detected" ); } catch ( const CommandLineOptions::CommandLineParseError &e ) { CppUT::checkEquals( CommandLineOptions::CommandLineParseError::invalidOptionName, e.cause() ); CppUT::checkEquals( badOptionName, e.optionName() ); } } void CommandLineOptionsTest::testParseShortOption() { CommandLineOptions::OptionsDescription options( "test" ); options.add( ",f", "" ); options.add( ",x", "" ); const char *args[] = { "-f", "-x", 0 }; LOCAL_CHECK_PARSE( options, args ); CPPUT_ASSERT_EXPR( values_->hasOption("-f") ); CPPUT_ASSERT_EXPR( values_->hasOption("-x") ); } void CommandLineOptionsTest::testLongOption() { CommandLineOptions::OptionsDescription options( "test" ); options.add( "flag", "" ); options.add( "exclude", "" ); const char *args[] = { "--flag", "--exclude", 0 }; LOCAL_CHECK_PARSE( options, args ); CPPUT_ASSERT_EXPR( values_->hasOption("flag") ); CPPUT_ASSERT_EXPR( values_->hasOption("exclude") ); } void CommandLineOptionsTest::testErrorOnBadOptionName() { CommandLineOptions::OptionsDescription options( "test" ); options.add( "time", "" ); options.add( "exclude,x", "" ); options.add( ",I", "" ); options.add( "duration,d", "" ); options.add( "fast,f", "" ); const char *args1[] = { "--time", "--exclude", "-I", "--duration", "--fast", 0 }; LOCAL_CHECK_PARSE( options, args1 ); const char *args1b[] = { "-x", "-I", "-d", "-f", 0 }; LOCAL_CHECK_PARSE( options, args1b ); const char *args2[] = { "-t", "--exclude", 0 }; LOCAL_CHECK_PARSE_BAD_OPTION( options, args2, "-t" ); const char *args3[] = { "--exclude", "--super", 0 }; LOCAL_CHECK_PARSE_BAD_OPTION( options, args3, "--super" ); const char *args4[] = { "--x", "--super", 0 }; LOCAL_CHECK_PARSE_BAD_OPTION( options, args4, "--x" ); // Notes: we might want to allow this const char *args5[] = { "-exclude", "--super", 0 }; LOCAL_CHECK_PARSE_BAD_OPTION( options, args5, "-exclude" ); } /* void CommandLineOptionsTest::testParseOptionParameter() { CommandLineOptions::OptionsDescription options( "test" ); int time; std::string excluded; double duration; options.add( "time,t", time, "" ); options.add( "exclude,x", excluded, "" ); options.add( "include,i", "" ); options.add( "duration,d", duration, "" ); options.add( "fast,f", "" ); const char *args[] = { "--time", "1234", "--fast", "--exclude", "arg", "--include", "arg2", "--duration", "12.34", 0 }; LOCAL_CHECK_PARSE( options, args ); CPPUT_ASSERT_EXPR( values_->hasOption("fast") ); CPPUT_ASSERT_EXPR( values_->hasOption("time") ); CPPUT_ASSERT_EXPR( values_->hasOption("exclude") ); CPPUT_ASSERT_EXPR( values_->hasOption("include") ); CPPUT_ASSERT_EXPR( values_->hasOption("duration") ); } */ void CommandLineOptionsTest::testParseShortOptionAdjascentParameter() { CommandLineOptions::OptionsDescription options( "test" ); options.add( CommandLineOptions::option<std::string>( ",c:", "" ) ); options.add( CommandLineOptions::optionDefault<std::string>( ",f", ".config", "" ) ); const char *args[] = { "-cabcdef", 0 }; LOCAL_CHECK_PARSE( options, args ); CPPUT_ASSERT_EXPR( values_->hasOption("-c") ); CPPUT_ASSERTSTR_EQUAL( "abcdef", get<std::string>( values_->optionValue("-c") ) ); const char *args2[] = { "-f.ini", 0 }; LOCAL_CHECK_PARSE( options, args2 ); CPPUT_ASSERT_EXPR( values_->hasOption("-f") ); CPPUT_ASSERTSTR_EQUAL( ".ini", get<std::string>( values_->optionValue("-f") ) ); const char *args3[] = { "-f", 0 }; LOCAL_CHECK_PARSE( options, args3 ); CPPUT_ASSERT_EXPR( values_->hasOption("-f") ); CPPUT_ASSERTSTR_EQUAL( ".config", get<std::string>( values_->optionValue("-f") ) ); } void CommandLineOptionsTest::testParseShortOptionNextParameter() { CommandLineOptions::OptionsDescription options( "test" ); options.add( CommandLineOptions::option<std::string>( ",c:", "" ) ); options.add( CommandLineOptions::optionDefault<std::string>(",f", ".config", "" ) ); options.add( ",t", "" ); const char *args[] = { "-c", "abcdef", 0 }; LOCAL_CHECK_PARSE( options, args ); CPPUT_ASSERT_EXPR( values_->hasOption("-c") ); CPPUT_ASSERTSTR_EQUAL( "abcdef", get<std::string>( values_->optionValue("-c") ) ); const char *args2[] = { "-f", ".ini", 0 }; LOCAL_CHECK_PARSE( options, args2 ); CPPUT_ASSERT_EXPR( values_->hasOption("-f") ); CPPUT_ASSERTSTR_EQUAL( ".ini", get<std::string>( values_->optionValue("-f") ) ); const char *args3[] = { "-f", 0 }; LOCAL_CHECK_PARSE( options, args3 ); CPPUT_ASSERT_EXPR( values_->hasOption("-f") ); CPPUT_ASSERTSTR_EQUAL( ".config", get<std::string>( values_->optionValue("-f") ) ); const char *args4[] = { "-c", "abcdef", "-t", 0 }; LOCAL_CHECK_PARSE( options, args4 ); CPPUT_ASSERT_EXPR( values_->hasOption("-c") ); CPPUT_ASSERTSTR_EQUAL( "abcdef", get<std::string>( values_->optionValue("-c") ) ); const char *args5[] = { "-f", ".ini", "-t", 0 }; LOCAL_CHECK_PARSE( options, args5 ); CPPUT_ASSERT_EXPR( values_->hasOption("-f") ); CPPUT_ASSERTSTR_EQUAL( ".ini", get<std::string>( values_->optionValue("-f") ) ); const char *args6[] = { "-f", "-t", 0 }; LOCAL_CHECK_PARSE( options, args6 ); CPPUT_ASSERT_EXPR( values_->hasOption("-f") ); CPPUT_ASSERTSTR_EQUAL( ".config", get<std::string>( values_->optionValue("-f") ) ); } void CommandLineOptionsTest::testParserLongOptionAdjascentParameter() { CommandLineOptions::OptionsDescription options( "test" ); options.add( "column:", "" ); options.add( CommandLineOptions::optionDefault<std::string>( "file", ".config", "" ) ); const char *args[] = { "--column=abcdef", 0 }; LOCAL_CHECK_PARSE( options, args ); CPPUT_ASSERT_EXPR( values_->hasOption("column") ); CPPUT_ASSERTSTR_EQUAL( "abcdef", get<std::string>( values_->optionValue("column") ) ); const char *args2[] = { "--file=.ini", 0 }; LOCAL_CHECK_PARSE( options, args2 ); CPPUT_ASSERT_EXPR( values_->hasOption("file") ); CPPUT_ASSERTSTR_EQUAL( ".ini", get<std::string>( values_->optionValue("file") ) ); const char *args3[] = { "--file", 0 }; LOCAL_CHECK_PARSE( options, args3 ); CPPUT_ASSERT_EXPR( values_->hasOption("file") ); CPPUT_ASSERTSTR_EQUAL( ".config", get<std::string>( values_->optionValue("file") ) ); } void CommandLineOptionsTest::testParserLongOptionNextParameter() { CommandLineOptions::OptionsDescription options( "test" ); options.add( "column:", "" ); options.add( CommandLineOptions::optionDefault<std::string>( "file", ".config", "" ) ); options.add( ",t", "" ); const char *args[] = { "--column", "abcdef", 0 }; LOCAL_CHECK_PARSE( options, args ); CPPUT_ASSERT_EXPR( values_->hasOption("column") ); CPPUT_ASSERTSTR_EQUAL( "abcdef", get<std::string>( values_->optionValue("column") ) ); const char *args2[] = { "--file", ".ini", 0 }; LOCAL_CHECK_PARSE( options, args2 ); CPPUT_ASSERT_EXPR( values_->hasOption("file") ); CPPUT_ASSERTSTR_EQUAL( ".ini", get<std::string>( values_->optionValue("file") ) ); const char *args3[] = { "--file", 0 }; LOCAL_CHECK_PARSE( options, args3 ); CPPUT_ASSERT_EXPR( values_->hasOption("file") ); CPPUT_ASSERTSTR_EQUAL( ".config", get<std::string>( values_->optionValue("file") ) ); const char *args4[] = { "--column", "abcdef", "-t", 0 }; LOCAL_CHECK_PARSE( options, args4 ); CPPUT_ASSERT_EXPR( values_->hasOption("column") ); CPPUT_ASSERTSTR_EQUAL( "abcdef", get<std::string>( values_->optionValue("column") ) ); const char *args5[] = { "--file", ".ini", "-t", 0 }; LOCAL_CHECK_PARSE( options, args5 ); CPPUT_ASSERT_EXPR( values_->hasOption("file") ); CPPUT_ASSERTSTR_EQUAL( ".ini", get<std::string>( values_->optionValue("file") ) ); const char *args6[] = { "--file", "-t", 0 }; LOCAL_CHECK_PARSE( options, args6 ); CPPUT_ASSERT_EXPR( values_->hasOption("file") ); CPPUT_ASSERTSTR_EQUAL( ".config", get<std::string>( values_->optionValue("file") ) ); } void CommandLineOptionsTest::testValuesLookUpAsShortOrLong() { CommandLineOptions::OptionsDescription options( "test" ); options.add( "column,c:", "" ); const char *args[] = { "-c8", 0 }; LOCAL_CHECK_PARSE( options, args ); CPPUT_ASSERT_EXPR( values_->hasOption("-c") ); CPPUT_ASSERT_EXPR( values_->hasOption("column") ); const char *args2[] = { "--column", "8", 0 }; LOCAL_CHECK_PARSE( options, args2 ); CPPUT_ASSERT_EXPR( values_->hasOption("-c") ); CPPUT_ASSERT_EXPR( values_->hasOption("column") ); } void CommandLineOptionsTest::testStoreParameterValues() { CommandLineOptions::OptionsDescription options( "test" ); int column = -1; std::string file; options.add( CommandLineOptions::option( "column,c:", column, "" ) ); options.add( CommandLineOptions::option( "file", file, ".config", "" ) ); const char *args[] = { "-c8", "--file", "test", 0 }; LOCAL_CHECK_PARSE( options, args ); CPPUT_ASSERT_EXPR( values_->hasOption("column") ); CPPUT_ASSERT_EXPR( values_->hasOption("file") ); CPPUT_ASSERTSTR_EQUAL( "test", file ); CPPUT_ASSERT_EQUAL( 8, column ); const char *args2[] = { "--file", "-c", "8", 0 }; LOCAL_CHECK_PARSE( options, args2 ); CPPUT_ASSERT_EXPR( values_->hasOption("column") ); CPPUT_ASSERT_EXPR( values_->hasOption("file") ); CPPUT_ASSERTSTR_EQUAL( ".config", file ); CPPUT_ASSERT_EQUAL( 8, column ); } void CommandLineOptionsTest::testParseRequiredParameter() { CommandLineOptions::OptionsDescription options( "test" ); options.add( "column,c:", "" ); options.add( "file:", "" ); const char *args[] = { "--file", "--column", "abcdef", 0 }; try { checkParse( options, args ); CPPUT_FAIL( "Command line parsing should have failed because of missing parameter of --file." ); } catch ( const CommandLineOptions::ValidatorError &e ) { CPPUT_ASSERT_EXPR( e.cause() == CommandLineOptions::ValidatorError::missingParameter ); } } static Value validateTraceOrTime( const CommandLineOptions::Parameters ¶meters ) { std::string text = parameters.at(0); if ( text != "trace" && text != "time" ) throw CommandLineOptions::ValidatorError( CommandLineOptions::ValidatorError::badParameterValue, "trace or time expected." ); return value( text ); } void CommandLineOptionsTest::testCustomValidator() { CommandLineOptions::OptionsDescription options( "test" ); std::string file; options.add( CommandLineOptions::option( "debug,d:", file, "" ).setValidator( CommandLineOptions::validator( &validateTraceOrTime ) ) ); const char *args[] = { "-d", "trace", 0 }; LOCAL_CHECK_PARSE( options, args ); CPPUT_ASSERT_EXPR( values_->hasOption("debug") ); CPPUT_ASSERTSTR_EQUAL( "trace", file ); const char *args2[] = { "-d", "time", 0 }; LOCAL_CHECK_PARSE( options, args2 ); CPPUT_ASSERT_EXPR( values_->hasOption("debug") ); CPPUT_ASSERTSTR_EQUAL( "time", file ); const char *args3[] = { "-d", "bad", 0 }; try { checkParse( options, args3 ); CPPUT_FAIL( "Validation should have failed because of bad parameter for -d." ); } catch ( const CommandLineOptions::ValidatorError &e ) { CPPUT_ASSERTSTR_EQUAL( "debug", e.optionName() ); CPPUT_ASSERT_EXPR( e.cause() == CommandLineOptions::ValidatorError::badParameterValue ); } } void CommandLineOptionsTest::testEnumerationValidator() { CommandLineOptions::OptionsDescription options( "test" ); LogLevel level; CommandLineOptions::EnumerationValidator<LogLevel> logLevelValidator; logLevelValidator.add( "fatal", fatal, "Log only fatal events." ); logLevelValidator.add( "warning", warning, "Log only fatal and warning events." ); logLevelValidator.add( "info", info, "Log all events." ); options.add( CommandLineOptions::validatedOption( "level,l", level, fatal, "Set log level", logLevelValidator.clone() ) ); const char *args[] = { "-l", "info", 0 }; LOCAL_CHECK_PARSE( options, args ); CPPUT_ASSERT_EXPR( values_->hasOption("level") ); CPPUT_ASSERT_EQUAL( info, level ); const char *args2[] = { "-l", 0 }; LOCAL_CHECK_PARSE( options, args2 ); CPPUT_ASSERT_EXPR( values_->hasOption("level") ); CPPUT_ASSERT_EQUAL( fatal, level ); } Index: testfixturetest.h =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cpputtest/testfixturetest.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** testfixturetest.h 8 Jun 2004 20:23:25 -0000 1.1.1.1 --- testfixturetest.h 5 Aug 2004 20:52:46 -0000 1.2 *************** *** 7,11 **** # include <cpput/testcontext.h> # include <cpput/testfixture.h> ! # include <cpput/result.h> --- 7,11 ---- # include <cpput/testcontext.h> # include <cpput/testfixture.h> ! # include <cpput/testrunresult.h> Index: testtestcase.cpp =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cpputtest/testtestcase.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** testtestcase.cpp 8 Jun 2004 20:23:25 -0000 1.1.1.1 --- testtestcase.cpp 5 Aug 2004 20:52:46 -0000 1.2 *************** *** 1,5 **** #include <cpput/assert.h> ! #include <cpput/assertexception.h> ! #include <cpput/result.h> #include <cpput/testcase.h> #include <cpput/testcontext.h> --- 1,5 ---- #include <cpput/assert.h> ! #include <cpput/resultexception.h> ! #include <cpput/testrunresult.h> #include <cpput/testcase.h> #include <cpput/testcontext.h> *************** *** 94,98 **** CppUT::TestContext context; ! CppUT::Result result; context.add( result ); test->run( context ); --- 94,98 ---- CppUT::TestContext context; ! CppUT::TestRunResult result; context.add( result ); test->run( context ); *************** *** 129,133 **** CppUT::TestContext context; ! CppUT::Result result; context.add( result ); test->run( context ); --- 129,133 ---- CppUT::TestContext context; ! CppUT::TestRunResult result; context.add( result ); test->run( context ); *************** *** 150,154 **** CppUT::TestContext context; ! CppUT::Result result; context.add( result ); test->run( context ); --- 150,154 ---- CppUT::TestContext context; ! CppUT::TestRunResult result; context.add( result ); test->run( context ); *************** *** 171,175 **** CppUT::TestContext context; ! CppUT::Result result; context.add( result ); test->run( context ); --- 171,175 ---- CppUT::TestContext context; ! CppUT::TestRunResult result; context.add( result ); test->run( context ); *************** *** 192,196 **** CppUT::TestContext context; ! CppUT::Result result; context.add( result ); test->run( context ); --- 192,196 ---- CppUT::TestContext context; ! CppUT::TestRunResult result; context.add( result ); test->run( context ); *************** *** 213,217 **** CPPUT_ASSERT_EQUAL( "Test1", test->name() ); CppUT::TestContext context; ! CppUT::Result result; context.add( result ); test->run( context ); --- 213,217 ---- CPPUT_ASSERT_EQUAL( "Test1", test->name() ); CppUT::TestContext context; ! CppUT::TestRunResult result; context.add( result ); test->run( context ); *************** *** 233,237 **** CPPUT_ASSERT_EQUAL( "Test1", test->name() ); CppUT::TestContext context; ! CppUT::Result result; context.add( result ); test->run( context ); --- 233,237 ---- CPPUT_ASSERT_EQUAL( "Test1", test->name() ); CppUT::TestContext context; ! CppUT::TestRunResult result; context.add( result ); test->run( context ); --- NEW FILE: testtestrunresult.cpp --- #include <cpput/testrunresult.h> #include <cpput/assert.h> #include <cpput/resultexception.h> #include <cpput/test.h> #include <cpput/testcontext.h> #include <iostream> namespace { class DummyTest : public CppUT::AbstractTest { public: void run( CppUT::TestContext &context ) { } void accept( CppUT::TestVisitor &visitor ) { } int totalTestCount() const { return 1; } }; } bool testTestRunResult() { try { CppUT::TestRunResult result; CppUT::TestContext context; CPPUT_ASSERT( result.successful() ); CPPUT_ASSERT_EQUAL( 0, result.failureCount() ); DummyTest dummyTest1; CppUT::Message message1( "message1" ); message1.setStatus( false ); message1.setResultType( "fault" ); CppUT::TestResult failure1( dummyTest1, message1 ); result.processTestResult( failure1, context ); CPPUT_ASSERT_FALSE( result.successful() ); CPPUT_ASSERT_EQUAL( 1, result.failureCount() ); const CppUT::TestResult &failure1b = result.failureAt(0); CPPUT_ASSERT_FALSE( failure1b.isAssertionFailure() ); CPPUT_ASSERT_EQUAL( 1, failure1b.message().count() ); CPPUT_ASSERT_EQUAL( "message1", failure1b.message().at(0) ); DummyTest dummyTest2; CppUT::Message message2( "message2" ); message2.setStatus( false ); message2.setResultType( "assertion" ); CppUT::TestResult failure2( dummyTest2, message2, CppUT::Location( "somefile.cpp", 123 ) ); result.processTestResult( failure2, context ); CPPUT_ASSERT_FALSE( result.successful() ); CPPUT_ASSERT_EQUAL( 2, result.failureCount() ); const CppUT::TestResult &failure2b = result.failureAt(1); CPPUT_ASSERT( failure2b.isAssertionFailure() ); CPPUT_ASSERT_EQUAL( 1, failure2b.message().count() ); CPPUT_ASSERT_EQUAL( "message2", failure2b.message().at(0) ); CPPUT_ASSERT_EQUAL( "somefile.cpp", failure2b.location().fileName() ); CPPUT_ASSERT_EQUAL( 123, failure2b.location().lineNumber() ); DummyTest dummyTest3; CppUT::Message message3( "message3" ); message3.setStatus( false ); message3.setResultType( "assertion" ); CppUT::TestResult failure3( dummyTest3, message3, CppUT::Location( "somefile3.cpp", 23 ) ); result.processTestResult( failure3, context ); CPPUT_ASSERT_EQUAL( 3, result.failureCount() ); CPPUT_ASSERT( result.failureAt(2).isAssertionFailure() ); DummyTest dummyTest4; CppUT::Message message4( "message4" ); message3.setStatus( false ); message3.setResultType( "assertion" ); CppUT::TestResult failure4( dummyTest4, message4 ); result.processTestResult( failure4, context ); CPPUT_ASSERT_EQUAL( 4, result.failureCount() ); CPPUT_ASSERT_FALSE( result.failureAt(3).isAssertionFailure() ); } catch ( CppUT::AssertException &e ) { std::cout << "testResult() failed: " << e.what() << std::endl; return false; } return true; } Index: testtestsuite.cpp =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cpputtest/testtestsuite.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** testtestsuite.cpp 8 Jun 2004 20:23:25 -0000 1.1.1.1 --- testtestsuite.cpp 5 Aug 2004 20:52:46 -0000 1.2 *************** *** 1,4 **** #include <cpput/assert.h> ! #include <cpput/assertexception.h> #include <cpput/testsuite.h> #include <cpput/testcontext.h> --- 1,4 ---- #include <cpput/assert.h> ! #include <cpput/resultexception.h> #include <cpput/testsuite.h> #include <cpput/testcontext.h> Index: testtestcontext.cpp =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cpputtest/testtestcontext.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** testtestcontext.cpp 8 Jun 2004 20:23:25 -0000 1.1.1.1 --- testtestcontext.cpp 5 Aug 2004 20:52:46 -0000 1.2 *************** *** 1,6 **** #include <cpput/assert.h> ! #include <cpput/assertexception.h> #include <cpput/test.h> ! #include <cpput/testfailure.h> #include <cpput/testsuite.h> #include <cpput/testcontext.h> --- 1,6 ---- #include <cpput/assert.h> ! #include <cpput/resultexception.h> #include <cpput/test.h> ! #include <cpput/testresult.h> #include <cpput/testsuite.h> #include <cpput/testcontext.h> *************** *** 66,72 **** }; ! class CustomException1TestFailureGuard : public CppUT::TestFailureGuard { ! public: // overridden from TestFailureGuard bool protect( Context &context ) { --- 66,72 ---- }; ! class CustomException1TestExceptionGuard : public CppUT::TestExceptionGuard { ! public: // overridden from TestExceptionGuard bool protect( Context &context ) { *************** *** 78,82 **** { CppUT::FaultException fault( "CustomException1" ); ! context.failureHandler_.handleFault( context.protectedTest_, fault ); } --- 78,82 ---- { CppUT::FaultException fault( "CustomException1" ); ! context.exceptionHandler_.handleResultException( context.protectedTest_, fault ); } *************** *** 85,91 **** }; ! class CustomException2TestFailureGuard : public CppUT::TestFailureGuard { ! public: // overridden from TestFailureGuard bool protect( Context &context ) { --- 85,91 ---- }; ! class CustomException2TestExceptionGuard : public CppUT::TestExceptionGuard { ! public: // overridden from TestExceptionGuard bool protect( Context &context ) { *************** *** 97,101 **** { CppUT::FaultException fault( "CustomException2" ); ! context.failureHandler_.handleFault( context.protectedTest_, fault ); } --- 97,101 ---- { CppUT::FaultException fault( "CustomException2" ); ! context.exceptionHandler_.handleResultException( context.protectedTest_, fault ); } *************** *** 107,112 **** { public: // overridden from CppUT::TestListener ! void testFailed( const CppUT::TestFailure &failure, ! CppUT::TestContext &context ) { message_ = failure.message().toString(); --- 107,112 ---- { public: // overridden from CppUT::TestListener ! void processTestResult( CppUT::TestResult &failure, ! CppUT::TestContext &context ) { message_ = failure.message().toString(); *************** *** 260,263 **** --- 260,265 ---- CPPUT_ASSERT_EQUAL( 1, listener1.exitTestCount_ ); CPPUT_ASSERT_EQUAL( 0, listener1.testFailedCount_ ); + CPPUT_ASSERT_EQUAL( 1, listener1.testResultCount_ ); + CPPUT_ASSERT_EQUAL( 1, listener1.testSucceededCount_ ); CPPUT_ASSERT_EQUAL( 0, listener1.enterSuiteCount_ ); CPPUT_ASSERT_EQUAL( 0, listener1.exitSuiteCount_ ); *************** *** 270,276 **** --- 272,282 ---- CPPUT_ASSERT_EQUAL( 2, listener1.exitTestCount_ ); CPPUT_ASSERT_EQUAL( 1, listener1.testFailedCount_ ); + CPPUT_ASSERT_EQUAL( 2, listener1.testResultCount_ ); + CPPUT_ASSERT_EQUAL( 1, listener1.testSucceededCount_ ); CPPUT_ASSERT_EQUAL( 1, listener2.enterTestCount_ ); CPPUT_ASSERT_EQUAL( 1, listener2.exitTestCount_ ); CPPUT_ASSERT_EQUAL( 1, listener2.testFailedCount_ ); + CPPUT_ASSERT_EQUAL( 1, listener2.testResultCount_ ); + CPPUT_ASSERT_EQUAL( 0, listener2.testSucceededCount_ ); MockTestListener listener3; *************** *** 281,290 **** --- 287,302 ---- CPPUT_ASSERT_EQUAL( 3, listener1.exitTestCount_ ); CPPUT_ASSERT_EQUAL( 2, listener1.testFailedCount_ ); + CPPUT_ASSERT_EQUAL( 3, listener1.testResultCount_ ); + CPPUT_ASSERT_EQUAL( 1, listener1.testSucceededCount_ ); CPPUT_ASSERT_EQUAL( 2, listener2.enterTestCount_ ); CPPUT_ASSERT_EQUAL( 2, listener2.exitTestCount_ ); CPPUT_ASSERT_EQUAL( 2, listener2.testFailedCount_ ); + CPPUT_ASSERT_EQUAL( 2, listener2.testResultCount_ ); + CPPUT_ASSERT_EQUAL( 0, listener2.testSucceededCount_ ); CPPUT_ASSERT_EQUAL( 1, listener3.enterTestCount_ ); CPPUT_ASSERT_EQUAL( 1, listener3.exitTestCount_ ); CPPUT_ASSERT_EQUAL( 1, listener3.testFailedCount_ ); + CPPUT_ASSERT_EQUAL( 1, listener3.testResultCount_ ); + CPPUT_ASSERT_EQUAL( 0, listener3.testSucceededCount_ ); MockTestListener listener4; *************** *** 295,307 **** --- 307,327 ---- CPPUT_ASSERT_EQUAL( 4, listener1.exitTestCount_ ); CPPUT_ASSERT_EQUAL( 3, listener1.testFailedCount_ ); + CPPUT_ASSERT_EQUAL( 4, listener1.testResultCount_ ); + CPPUT_ASSERT_EQUAL( 1, listener1.testSucceededCount_ ); CPPUT_ASSERT_EQUAL( 3, listener2.enterTestCount_ ); CPPUT_ASSERT_EQUAL( 3, listener2.exitTestCount_ ); CPPUT_ASSERT_EQUAL( 3, listener2.testFailedCount_ ); + CPPUT_ASSERT_EQUAL( 3, listener2.testResultCount_ ); + CPPUT_ASSERT_EQUAL( 0, listener2.testSucceededCount_ ); CPPUT_ASSERT_EQUAL( 2, listener3.enterTestCount_ ); CPPUT_ASSERT_EQUAL( 2, listener3.exitTestCount_ ); CPPUT_ASSERT_EQUAL( 2, listener3.testFailedCount_ ); + CPPUT_ASSERT_EQUAL( 2, listener3.testResultCount_ ); + CPPUT_ASSERT_EQUAL( 0, listener3.testSucceededCount_ ); CPPUT_ASSERT_EQUAL( 1, listener4.enterTestCount_ ); CPPUT_ASSERT_EQUAL( 1, listener4.exitTestCount_ ); CPPUT_ASSERT_EQUAL( 1, listener4.testFailedCount_ ); + CPPUT_ASSERT_EQUAL( 1, listener4.testResultCount_ ); + CPPUT_ASSERT_EQUAL( 0, listener4.testSucceededCount_ ); /* DummyTestSuite suite; *************** *** 321,328 **** CaptureMessageTestListener listener; context.add( listener ); ! context.appendGuard( CppUT::TestFailureGuardPtr( ! new CustomException1TestFailureGuard() ) ); ! context.appendGuard( CppUT::TestFailureGuardPtr( ! new CustomException2TestFailureGuard() ) ); DummyTest dummyTest; --- 341,348 ---- CaptureMessageTestListener listener; context.add( listener ); ! context.appendGuard( CppUT::TestExceptionGuardPtr( ! new CustomException1TestExceptionGuard() ) ); ! context.appendGuard( CppUT::TestExceptionGuardPtr( ! new CustomException2TestExceptionGuard() ) ); DummyTest dummyTest; Index: testfixturetest.cpp =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cpputtest/testfixturetest.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** testfixturetest.cpp 8 Jun 2004 20:23:25 -0000 1.1.1.1 --- testfixturetest.cpp 5 Aug 2004 20:52:46 -0000 1.2 *************** *** 156,160 **** CppUT::TestPtr suite = EmptyFixture::suite(); CppUT::TestContext context; ! CppUT::Result result; context.add( result ); suite->run( context ); --- 156,160 ---- CppUT::TestPtr suite = EmptyFixture::suite(); CppUT::TestContext context; ! CppUT::TestRunResult result; context.add( result ); suite->run( context ); *************** *** 168,172 **** CppUT::TestPtr suite = TwoTestFixture::suite(); CppUT::TestContext context; ! CppUT::Result result; context.add( result ); suite->run( context ); --- 168,172 ---- CppUT::TestPtr suite = TwoTestFixture::suite(); CppUT::TestContext context; ! CppUT::TestRunResult result; context.add( result ); suite->run( context ); *************** *** 181,185 **** CppUT::TestPtr suite = ExtendTestFixture::suite(); CppUT::TestContext context; ! CppUT::Result result; context.add( result ); suite->run( context ); --- 181,185 ---- CppUT::TestPtr suite = ExtendTestFixture::suite(); CppUT::TestContext context; ! CppUT::TestRunResult result; context.add( result ); suite->run( context ); *************** *** 194,198 **** CppUT::TestPtr suite = ConcretTestFixture::suite(); CppUT::TestContext context; ! CppUT::Result result; context.add( result ); suite->run( context ); --- 194,198 ---- CppUT::TestPtr suite = ConcretTestFixture::suite(); CppUT::TestContext context; ! CppUT::TestRunResult result; context.add( result ); suite->run( context ); *************** *** 207,211 **** CppUT::TestPtr suite = NoSharedFixtureTest::suite(); CppUT::TestContext context; ! CppUT::Result result; context.add( result ); SharedFixtureTestBase::instances_.clear(); --- 207,211 ---- CppUT::TestPtr suite = NoSharedFixtureTest::suite(); CppUT::TestContext context; ! CppUT::TestRunResult result; context.add( result ); SharedFixtureTestBase::instances_.clear(); *************** *** 222,226 **** CppUT::TestPtr suite = SharedFixtureTest::suite(); CppUT::TestContext context; ! CppUT::Result result; context.add( result ); SharedFixtureTestBase::instances_.clear(); --- 222,226 ---- CppUT::TestPtr suite = SharedFixtureTest::suite(); CppUT::TestContext context; ! CppUT::TestRunResult result; context.add( result ); SharedFixtureTestBase::instances_.clear(); --- NEW FILE: commandlineoptionstest.h --- #ifndef CPPUT_COMMANDLINEOPTIONS_H_INCLUDED #define CPPUT_COMMANDLINEOPTIONS_H_INCLUDED # include <cpput/assert.h> # include <cpput/testfixture.h> # include <cpput/registry.h> # include <cpputtools/configuration.h> class CommandLineOptionsTest : public CppUT::TestFixture { public: CPPUT_TESTSUITE_BEGIN( CommandLineOptionsTest ); CPPUT_TEST( testParseShortOption ); CPPUT_TEST( testLongOption ); CPPUT_TEST( testErrorOnBadOptionName ); CPPUT_TEST( testParseShortOptionAdjascentParameter ); CPPUT_TEST( testParseShortOptionNextParameter ); CPPUT_TEST( testParserLongOptionAdjascentParameter ); CPPUT_TEST( testParserLongOptionNextParameter ); CPPUT_TEST( testStoreParameterValues ); CPPUT_TEST( testValuesLookUpAsShortOrLong ); CPPUT_TEST( testParseRequiredParameter ); CPPUT_TEST( testCustomValidator ); CPPUT_TEST( testEnumerationValidator ); CPPUT_TESTSUITE_END(); void setUp(); void tearDown(); void testParseShortOption(); void testLongOption(); void testErrorOnBadOptionName(); void testParseShortOptionAdjascentParameter(); void testParseShortOptionNextParameter(); void testParserLongOptionAdjascentParameter(); void testParserLongOptionNextParameter(); void testValuesLookUpAsShortOrLong(); void testStoreParameterValues(); void testParseRequiredParameter(); void testCustomValidator(); void testEnumerationValidator(); private: void checkParse( CppUTTools::CommandLineOptions::OptionsDescription &description, const char *argv[] ); void checkParseBadOption( CppUTTools::CommandLineOptions::OptionsDescription &description, const char *argv[], const std::string &badOptionName ); enum LogLevel { fatal = 1, warning, info }; CppUTTools::CommandLineOptions::OptionsValues *values_; }; #endif // CPPUT_COMMANDLINEOPTIONS_H_INCLUDED Index: cpputtest.dsp =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cpputtest/cpputtest.dsp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** cpputtest.dsp 8 Jun 2004 20:23:24 -0000 1.1.1.1 --- cpputtest.dsp 5 Aug 2004 20:52:46 -0000 1.2 *************** *** 52,56 **** # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\build\cpput\release" # Begin Special Build Tool ! TargetPath=\prg\vc\Lib\CppUT\build\cpputtest\release\cpputtest.exe SOURCE="$(InputPath)" PostBuild_Desc=Testing cpput library... --- 52,56 ---- # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\build\cpput\release" # Begin Special Build Tool ! TargetPath=\prg\vc\Lib\cppunit2\build\cpputtest\release\cpputtest.exe SOURCE="$(InputPath)" PostBuild_Desc=Testing cpput library... *************** *** 82,86 **** # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\build\cpput\debug" # Begin Special Build Tool ! TargetPath=\prg\vc\Lib\CppUT\build\cpputtest\debug\cpputtest.exe SOURCE="$(InputPath)" PostBuild_Desc=Testing cpput library... --- 82,86 ---- # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\build\cpput\debug" # Begin Special Build Tool ! TargetPath=\prg\vc\Lib\cppunit2\build\cpputtest\debug\cpputtest.exe SOURCE="$(InputPath)" PostBuild_Desc=Testing cpput library... *************** *** 112,115 **** --- 112,123 ---- # Begin Source File + SOURCE=.\commandlineoptions.cpp + # End Source File + # Begin Source File + + SOURCE=.\commandlineoptions.h + # End Source File + # Begin Source File + SOURCE=.\enumeratortest.cpp # End Source File --- testresult.cpp DELETED --- Index: mocktestlistener.h =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cpputtest/mocktestlistener.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** mocktestlistener.h 8 Jun 2004 20:23:24 -0000 1.1.1.1 --- mocktestlistener.h 5 Aug 2004 20:52:46 -0000 1.2 *************** *** 10,13 **** --- 10,15 ---- MockTestListener() : testFailedCount_( 0 ) + , testSucceededCount_( 0 ) + , testResultCount_( 0 ) , enterTestCount_( 0 ) , exitTestCount_( 0 ) *************** *** 17,24 **** } ! void testFailed( const CppUT::TestFailure &failure, ! CppUT::TestContext &context ) { ! ++testFailedCount_; } --- 19,32 ---- } ! // overridden from CppUT::TestListener ! ! void processTestResult( CppUT::TestResult &result, ! CppUT::TestContext &context ) { ! ++testResultCount_; ! if ( result.failed() ) ! ++testFailedCount_; ! else ! ++testSucceededCount_; } *************** *** 46,49 **** --- 54,59 ---- int testFailedCount_; + int testSucceededCount_; + int testResultCount_; int enterTestCount_; int exitTestCount_; Index: testfunctor.cpp =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cpputtest/testfunctor.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** testfunctor.cpp 8 Jun 2004 20:23:25 -0000 1.1.1.1 --- testfunctor.cpp 5 Aug 2004 20:52:46 -0000 1.2 *************** *** 1,4 **** #include <cpput/assert.h> ! #include <cpput/assertexception.h> #include <cpput/functor.h> #include <iostream> --- 1,4 ---- #include <cpput/assert.h> ! #include <cpput/resultexception.h> #include <cpput/functor.h> #include <iostream> Index: testbasicassertion.cpp =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cpputtest/testbasicassertion.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** testbasicassertion.cpp 8 Jun 2004 20:23:25 -0000 1.1.1.1 --- testbasicassertion.cpp 5 Aug 2004 20:52:46 -0000 1.2 *************** *** 1,4 **** #include <cpput/assert.h> ! #include <cpput/assertexception.h> #include <iostream> --- 1,4 ---- #include <cpput/assert.h> ! #include <cpput/resultexception.h> #include <iostream> *************** *** 73,76 **** --- 73,79 ---- try { + CPPUT_ASSERT_THROW( CPPUT_SUCCEED( CppUT::Message( "warning..." ) ), + CppUT::SuccessException ); + // CPPUT_ASSERT CPPUT_ASSERT_ASSERTION_PASS( CPPUT_ASSERT( true ) ); Index: cpputtest.vcproj =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cpputtest/cpputtest.vcproj,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** cpputtest.vcproj 8 Jun 2004 20:23:24 -0000 1.1.1.1 --- cpputtest.vcproj 5 Aug 2004 20:52:46 -0000 1.2 *************** *** 163,166 **** --- 163,172 ---- </File> <File + RelativePath=".\commandlineoptionstest.cpp"> + </File> + <File + RelativePath=".\commandlineoptionstest.h"> + </File> + <File RelativePath="enumeratortest.cpp"> </File> *************** *** 202,208 **** </File> <File - RelativePath=".\testresult.cpp"> - </File> - <File RelativePath=".\testtestcase.cpp"> </File> --- 208,211 ---- *************** *** 211,214 **** --- 214,220 ---- </File> <File + RelativePath=".\testtestrunresult.cpp"> + </File> + <File RelativePath=".\testtestsuite.cpp"> </File> |