diff options
author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-06-11 18:56:23 +0000 |
---|---|---|
committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-06-11 18:56:23 +0000 |
commit | 0c5051a8acf83fd77a6094177eb0711d3f90d997 (patch) | |
tree | a0757b1cae952576f4497d40ccf3aa70a2bf84c8 /examples/cppunittest/TestAssertTest.cpp | |
parent | 021d0a2611777a06d948735e0ad36cb90ffd413b (diff) | |
download | cppunit-0c5051a8acf83fd77a6094177eb0711d3f90d997.tar.gz |
Examples/cppunittest/TestResultTest.
examples/cppunittest/TestResultTest.*: renamed TestListenerTest.*
* examples/cppunittest/*: added unit tests for:
HelperMacros, TestAssert, TestCaller, TestCase, TestFailure,
TestResult, TestSuite, TestDecoratorTest, TestSetUp, RepeatedTestTest,
Orthodox, Exception.
Diffstat (limited to 'examples/cppunittest/TestAssertTest.cpp')
-rw-r--r-- | examples/cppunittest/TestAssertTest.cpp | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/examples/cppunittest/TestAssertTest.cpp b/examples/cppunittest/TestAssertTest.cpp new file mode 100644 index 0000000..c6eb73c --- /dev/null +++ b/examples/cppunittest/TestAssertTest.cpp @@ -0,0 +1,143 @@ +#include "TestAssertTest.h" + +/* + Note: + - tests need to be added to test asserEquals() template function and + use of assertion traits. Some check may need to be added to check + the message content in Exception. + - code need to be refactored with the use of a test caller that expect + an exception. + */ + + +CPPUNIT_TEST_SUITE_REGISTRATION( TestAssertTest ); + + +TestAssertTest::TestAssertTest() +{ +} + + +TestAssertTest::~TestAssertTest() +{ +} + + +void +TestAssertTest::setUp() +{ +} + + +void +TestAssertTest::tearDown() +{ +} + +void +TestAssertTest::testAssertTrue() +{ + CPPUNIT_ASSERT( true ); +} + + +void +TestAssertTest::testAssertFalse() +{ + bool exceptionCatched = false; + try + { + CPPUNIT_ASSERT( false ); + } + catch( CppUnit::Exception & ) + { + exceptionCatched = true; // ok, we were expecting an exception. + } + + CPPUNIT_ASSERT( exceptionCatched ); +} + + +void +TestAssertTest::testAssertMessageTrue() +{ + CPPUNIT_ASSERT_MESSAGE( "This test should not failed", true ); +} + + +void +TestAssertTest::testAssertMessageFalse() +{ + bool exceptionCatched = false; + std::string message( "This test message should not be seen" ); + try + { + CPPUNIT_ASSERT_MESSAGE( message, false ); + } + catch( CppUnit::Exception &e ) + { + CPPUNIT_ASSERT_EQUAL( message, std::string( e.what() ) ); + exceptionCatched = true; // ok, we were expecting an exception. + } + + CPPUNIT_ASSERT( exceptionCatched ); +} + + +void +TestAssertTest::testAssertDoubleEquals() +{ + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.1, 1.2, 0.101 ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.2, 1.1, 0.101 ); +} + + +void +TestAssertTest::testAssertDoubleNotEquals() +{ + checkDoubleNotEquals( 1.1, 1.2, 0.09 ); + checkDoubleNotEquals( 1.2, 1.1, 0.09 ); +} + + +void +TestAssertTest::checkDoubleNotEquals( double expected, + double actual, + double delta ) +{ + bool exceptionCatched = false; + try + { + CPPUNIT_ASSERT_DOUBLES_EQUAL( expected, actual, delta ); + } + catch( CppUnit::Exception & ) + { + exceptionCatched = true; // ok, we were expecting an exception. + } + + CPPUNIT_ASSERT( exceptionCatched ); +} + + +void +TestAssertTest::testAssertLongEquals() +{ + CPPUNIT_ASSERT_EQUAL( 12345678, 12345678 ); +} + + +void +TestAssertTest::testAssertLongNotEquals() +{ + bool exceptionCatched = false; + try + { + CPPUNIT_ASSERT_EQUAL( 1, 2 ); + } + catch( CppUnit::Exception & ) + { + exceptionCatched = true; // ok, we were expecting an exception. + } + + CPPUNIT_ASSERT( exceptionCatched ); +} |