Parametrized test case

   1 #include <cpput/testcase.h>
   2 #include <cpput/testsuite.h>
   3 #include <cpput/testrunner.h>    // cppunit2 testrunner for opentest
   4 #include <cpput/assert.h>
   5 #include <opentest/texttestdriver.h>
   6 #include <opentest/properties.h>
   7 
   8 
   9 static void testMultiply( int x, int y, int expected_result )
  10 {
  11    int result = x * y;
  12    CPPUT_ASSERT_EQUAL( expected_result, result );
  13 }
  14 
  15 
  16 
  17 int main( int argc, const char *argv[] )
  18 {
  19    CppUT::TestSuitePtr allSuite = CppUT::makeTestSuite( "All tests" );
  20    allSuite->add( CppUT::makeTestCase( 
  21        CppTL::bind_cfn( testMultiply, 7, 2, 7*2 ), 
  22        "multiply 7*2" ) );
  23    allSuite->add( CppUT::makeTestCase( 
  24       CppTL::bind_cfn( testMultiply, 7, 5, 7*4 ), 
  25       "multiply 7*5 (failing demo)" ) );
  26 
  27    CppUT::TestRunner runner;
  28    CppUT::AbstractTestSuitePtr rootSuite = 
  29       CppTL::staticPointerCast<CppUT::AbstractTestSuite>( allSuite );
  30    runner.setRootSuite( rootSuite );
  31 
  32    OpenTest::TextTestDriver driver( runner );
  33    bool sucessful = driver.run();
  34    return sucessful ? 0 : 1;
  35 }

CppUnit2/ParametrizedTestCase (last edited 2008-02-26 06:29:55 by localhost)

SourceForge.net Logo