summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2004-03-13 11:52:57 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2004-03-13 11:52:57 +0000
commit224cf85f2b7fd7ec47cda4788902996349f8c754 (patch)
treef1a835ff25dcd4a6efc46d83b775cdf7d5ba13b1 /examples
parent943bbb17d1339a3cae3b930e3f7f1cb2f9fec297 (diff)
downloadcppunit-224cf85f2b7fd7ec47cda4788902996349f8c754.tar.gz
Examples/cppunittest/TestAssertTest.
examples/cppunittest/TestAssertTest.h: * examples/cppunittest/TestAssertTest.cpp: * examples/cppunittest/XmlUniformiserTest.h: * examples/cppunittest/XmlUniformiserTest.cpp: * include/cppunit/TestAssert.h: add the exception assertion macros from cppunit 2: CPPUNIT_ASSERT_THROW, CPPUNIT_ASSERT_NO_THROW, CPPUNIT_ASSERT_ASSERTION_FAIL, CPPUNIT_ASSERT_ASSERTION_PASS. Updated unit test to use and test the new macros. * include/cppunit/extensions/HelperMacros.h: deprecated the test case factory that check for exception (CPPUNIT_TEST_FAIL & CPPUNIT_TEST_EXCEPTION).
Diffstat (limited to 'examples')
-rw-r--r--examples/cppunittest/TestAssertTest.cpp117
-rw-r--r--examples/cppunittest/TestAssertTest.h21
-rw-r--r--examples/cppunittest/XmlUniformiserTest.cpp13
-rw-r--r--examples/cppunittest/XmlUniformiserTest.h6
4 files changed, 101 insertions, 56 deletions
diff --git a/examples/cppunittest/TestAssertTest.cpp b/examples/cppunittest/TestAssertTest.cpp
index e3b57ac..9481184 100644
--- a/examples/cppunittest/TestAssertTest.cpp
+++ b/examples/cppunittest/TestAssertTest.cpp
@@ -39,16 +39,82 @@ TestAssertTest::tearDown()
void
-TestAssertTest::testAssertTrue()
+TestAssertTest::testAssertThrow()
{
- CPPUNIT_ASSERT( true );
+ CPPUNIT_ASSERT_THROW( throw std::exception( "dummy" ), std::exception );
+
+ try
+ {
+ CPPUNIT_ASSERT_THROW( 1234, std::exception );
+ }
+ catch ( CPPUNIT_NS::Exception & )
+ {
+ return;
+ }
+
+ throw std::exception( "CPPUT_ASSERT_THROW( 1234, std::exception ) did not fail." );
+}
+
+
+void
+TestAssertTest::testAssertNoThrow()
+{
+ CPPUNIT_ASSERT_NO_THROW( 1234 );
+
+ try
+ {
+ CPPUNIT_ASSERT_NO_THROW( throw std::exception( "dummy" ) );
+ }
+ catch ( CPPUNIT_NS::Exception & )
+ {
+ return;
+ }
+ throw std::exception( "CPPUT_ASSERT_NO_THROW( throw std::exception( \"dummy\" ) ) did not fail." );
+}
+
+
+void
+TestAssertTest::testAssertAssertionFail()
+{
+ CPPUNIT_ASSERT_ASSERTION_FAIL( throw CPPUNIT_NS::Exception() );
+
+ try
+ {
+ CPPUNIT_ASSERT_ASSERTION_FAIL( 1234 );
+ }
+ catch ( CPPUNIT_NS::Exception & )
+ {
+ return;
+ }
+
+ throw std::exception( "CPPUNIT_ASSERT_ASSERTION_FAIL( 1234 ) did not fail." );
+}
+
+
+void
+TestAssertTest::testAssertAssertionPass()
+{
+ CPPUNIT_ASSERT_ASSERTION_PASS( 1234 );
+
+ try
+ {
+ CPPUNIT_ASSERT_ASSERTION_PASS( throw CPPUNIT_NS::Exception() );
+ }
+ catch ( CPPUNIT_NS::Exception & )
+ {
+ return;
+ }
+
+ throw std::exception( "CPPUNIT_ASSERT_ASSERTION_PASS did not fail." );
}
void
-TestAssertTest::testAssertFalse()
+TestAssertTest::testAssert()
{
- CPPUNIT_ASSERT( false );
+ CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT( true ) );
+
+ CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT( false ) );
}
@@ -58,15 +124,19 @@ static int foo() { return 1; }
void
TestAssertTest::testAssertEqual()
{
- CPPUNIT_ASSERT_EQUAL( 1, 1 );
- CPPUNIT_ASSERT_EQUAL( 1, foo() );
+ CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT_EQUAL( 1, 1 ) );
+ CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT_EQUAL( 1, foo() ) );
+ CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT_EQUAL( 12345678, 12345678 ) );
+
+ CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_EQUAL( 1, 2 ) );
}
void
TestAssertTest::testAssertMessageTrue()
{
- CPPUNIT_ASSERT_MESSAGE( "This test should not failed", true );
+ CPPUNIT_ASSERT_ASSERTION_PASS(
+ CPPUNIT_ASSERT_MESSAGE( "This test should not failed", true ) );
}
@@ -92,36 +162,11 @@ TestAssertTest::testAssertMessageFalse()
void
TestAssertTest::testAssertDoubleEquals()
{
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.1, 1.2, 0.101 );
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.2, 1.1, 0.101 );
-}
+ CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.1, 1.2, 0.101 ) );
+ CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.2, 1.1, 0.101 ) );
-
-void
-TestAssertTest::testAssertDoubleNotEquals1()
-{
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.1, 1.2, 0.09 );
-}
-
-
-void
-TestAssertTest::testAssertDoubleNotEquals2()
-{
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.2, 1.1, 0.09 );
-}
-
-
-void
-TestAssertTest::testAssertLongEquals()
-{
- CPPUNIT_ASSERT_EQUAL( 12345678, 12345678 );
-}
-
-
-void
-TestAssertTest::testAssertLongNotEquals()
-{
- CPPUNIT_ASSERT_EQUAL( 1, 2 );
+ CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.1, 1.2, 0.09 ) );
+ CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.2, 1.1, 0.09 ) );
}
diff --git a/examples/cppunittest/TestAssertTest.h b/examples/cppunittest/TestAssertTest.h
index 5195588..636cb3a 100644
--- a/examples/cppunittest/TestAssertTest.h
+++ b/examples/cppunittest/TestAssertTest.h
@@ -7,16 +7,15 @@
class TestAssertTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE( TestAssertTest );
- CPPUNIT_TEST( testAssertTrue );
- CPPUNIT_TEST_FAIL( testAssertFalse );
+ CPPUNIT_TEST( testAssertThrow );
+ CPPUNIT_TEST( testAssertNoThrow );
+ CPPUNIT_TEST( testAssertAssertionFail );
+ CPPUNIT_TEST( testAssertAssertionPass );
+ CPPUNIT_TEST( testAssert );
CPPUNIT_TEST( testAssertEqual );
CPPUNIT_TEST( testAssertMessageTrue );
CPPUNIT_TEST( testAssertMessageFalse );
CPPUNIT_TEST( testAssertDoubleEquals );
- CPPUNIT_TEST_FAIL( testAssertDoubleNotEquals1 );
- CPPUNIT_TEST_FAIL( testAssertDoubleNotEquals2 );
- CPPUNIT_TEST( testAssertLongEquals );
- CPPUNIT_TEST_FAIL( testAssertLongNotEquals );
CPPUNIT_TEST( testFail );
CPPUNIT_TEST_SUITE_END();
@@ -28,8 +27,14 @@ public:
virtual void setUp();
virtual void tearDown();
- void testAssertTrue();
- void testAssertFalse();
+ void testAssertThrow();
+ void testAssertNoThrow();
+ void testAssertAssertionFail();
+ void testAssertAssertionPass();
+
+ void testBasicAssertions();
+
+ void testAssert();
void testAssertEqual();
diff --git a/examples/cppunittest/XmlUniformiserTest.cpp b/examples/cppunittest/XmlUniformiserTest.cpp
index 99d7ed0..a04a1dd 100644
--- a/examples/cppunittest/XmlUniformiserTest.cpp
+++ b/examples/cppunittest/XmlUniformiserTest.cpp
@@ -126,15 +126,12 @@ XmlUniformiserTest::testSkipComment()
void
-XmlUniformiserTest::testAssertXmlEqualFail()
+XmlUniformiserTest::testAssertXmlEqual()
{
- CPPUNITTEST_ASSERT_XML_EQUAL( "<Test>", "<Tes>" );
-}
-
-void
-XmlUniformiserTest::testAssertXmlEqualPass()
-{
- CPPUNITTEST_ASSERT_XML_EQUAL( "<Test>", "<Test>" );
+ CPPUNIT_ASSERT_ASSERTION_FAIL(
+ CPPUNITTEST_ASSERT_XML_EQUAL( "<Test>", "<Tes>" ) );
+ CPPUNIT_ASSERT_ASSERTION_PASS(
+ CPPUNITTEST_ASSERT_XML_EQUAL( "<Test>", "<Test>" ) );
}
diff --git a/examples/cppunittest/XmlUniformiserTest.h b/examples/cppunittest/XmlUniformiserTest.h
index a7edf8c..be2d6da 100644
--- a/examples/cppunittest/XmlUniformiserTest.h
+++ b/examples/cppunittest/XmlUniformiserTest.h
@@ -21,8 +21,7 @@ class XmlUniformiserTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST( testSkipComment );
CPPUNIT_TEST( testElementWithContent );
CPPUNIT_TEST( testElementsHierarchyWithContents );
- CPPUNIT_TEST_FAIL( testAssertXmlEqualFail );
- CPPUNIT_TEST( testAssertXmlEqualPass );
+ CPPUNIT_TEST( testAssertXmlEqual );
CPPUNIT_TEST_SUITE_END();
public:
@@ -48,8 +47,7 @@ public:
void testElementWithContent();
void testElementsHierarchyWithContents();
- void testAssertXmlEqualFail();
- void testAssertXmlEqualPass();
+ void testAssertXmlEqual();
private:
void check( const std::string &xml,