From DirtSimpleExample, on behalf of CppUnit. ---- #include #include #include #include #include #include class E''''''xampleTestCase : public CppUnit::TestCase { CPPUNIT_TEST_SUITE( E''''''xampleTestCase ); CPPUNIT_TEST( example ); CPPUNIT_TEST( anotherExample ); CPPUNIT_TEST( testEquals ); CPPUNIT_TEST_SUITE_END(); double m_value1; double m_value2; void example (); void anotherExample (); void testEquals (); public: void setUp (); }; CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( E''''''xampleTestCase, "E''''''xampleTestCase" ); void E''''''xampleTestCase::setUp () { m_value1 = 2.0; m_value2 = 3.0; } void E''''''xampleTestCase::example () { CPPUNIT_ASSERT (1 == 1); } void E''''''xampleTestCase::anotherExample () { CPPUNIT_ASSERT (2 == 2); } void E''''''xampleTestCase::testEquals () { std::auto_ptr l1 (new long (12)); std::auto_ptr l2 (new long (12)); CPPUNIT_ASSERT_DOUBLES_EQUAL (m_value1, 2.0, 0.01); CPPUNIT_ASSERT_DOUBLES_EQUAL (m_value2, 3.0, 0.01); CPPUNIT_ASSERT_EQUAL (12, 12); CPPUNIT_ASSERT_EQUAL (12L, 12L); CPPUNIT_ASSERT_EQUAL (*l1, *l2); CPPUNIT_ASSERT(12L == 12L); CPPUNIT_ASSERT_DOUBLES_EQUAL (12.0, 11.99, 0.5); } CppUnit::Test *suite() { CppUnit::T''''''estFactoryRegistry ®istry = CppUnit::T''''''estFactoryRegistry::getRegistry(); registry.registerFactory( &CppUnit::T''''''estFactoryRegistry::getRegistry( "E''''''xampleTestCase" ) ); return registry.makeTest(); } int main( int argc, char* argv[] ) { // if command line contains "-selftest" then this is the post build check // => the output must be in the compiler error format. bool selfTest = (argc > 1) && (std::string("-selftest") == argv[1]); CppUnit::T''''''extUi::TestRunner runner; runner.addTest( suite() ); // Add the top suite to the test runner if ( selfTest ) { // Change the default outputter to a compiler error format outputter // The test runner owns the new outputter. runner.setOutputter( CppUnit::C''''''ompilerOutputter::defaultOutputter( &runner.result(), std::cerr ) ); } // Run the test. bool wasSucessful = runner.run( "" ); // Return error code 1 if any tests failed. return wasSucessful ? 0 : 1; }