1 #include "CoreSuite.h"
2 #include "FailureException.h"
3 #include "MockTestCase.h"
4 #include "TestCaseTest.h"
5 #include <cppunit/TestResult.h>
6
7 /*
8 - test have been done to check exception management in run(). other
9 tests need to be added to check the other aspect of TestCase.
10 */
11
12 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestCaseTest,
13 coreSuiteName() );
14
15
TestCaseTest()16 TestCaseTest::TestCaseTest()
17 {
18 }
19
20
~TestCaseTest()21 TestCaseTest::~TestCaseTest()
22 {
23 }
24
25
26 void
setUp()27 TestCaseTest::setUp()
28 {
29 m_testListener = new MockTestListener( "mock-testlistener" );
30 m_result = new CPPUNIT_NS::TestResult();
31 m_result->addListener( m_testListener );
32 }
33
34
35 void
tearDown()36 TestCaseTest::tearDown()
37 {
38 delete m_result;
39 delete m_testListener;
40 }
41
42
43 void
testSetUpFailure()44 TestCaseTest::testSetUpFailure()
45 {
46 checkFailure( true, false, false );
47 }
48
49
50 void
testRunTestFailure()51 TestCaseTest::testRunTestFailure()
52 {
53 checkFailure( false, true, false );
54 }
55
56
57 void
testTearDownFailure()58 TestCaseTest::testTearDownFailure()
59 {
60 checkFailure( false, false, true );
61 }
62
63
64 void
testFailAll()65 TestCaseTest::testFailAll()
66 {
67 checkFailure( true, true, true );
68 }
69
70
71 void
testNoFailure()72 TestCaseTest::testNoFailure()
73 {
74 checkFailure( false, false, false );
75 }
76
77
78 void
checkFailure(bool failSetUp,bool failRunTest,bool failTearDown)79 TestCaseTest::checkFailure( bool failSetUp,
80 bool failRunTest,
81 bool failTearDown )
82 {
83 try
84 {
85 MockTestCase testCase( "mock-test" );
86 if ( failSetUp )
87 testCase.makeSetUpThrow();
88 if ( failRunTest )
89 testCase.makeRunTestThrow();
90 if ( failTearDown )
91 testCase.makeTearDownThrow();
92 testCase.setExpectedSetUpCall( 1 );
93 testCase.setExpectedRunTestCall( failSetUp ? 0 : 1 );
94 testCase.setExpectedTearDownCall( failSetUp ? 0 : 1 );
95
96 testCase.run( m_result );
97
98 testCase.verify();
99 }
100 catch ( FailureException & )
101 {
102 CPPUNIT_ASSERT_MESSAGE( "exception should have been caught", false );
103 }
104 }
105
106
107 void
testCountTestCases()108 TestCaseTest::testCountTestCases()
109 {
110 CPPUNIT_NS::TestCase test;
111 CPPUNIT_ASSERT_EQUAL( 1, test.countTestCases() );
112 }
113
114
115 void
testDefaultConstructor()116 TestCaseTest::testDefaultConstructor()
117 {
118 CPPUNIT_NS::TestCase test;
119 CPPUNIT_ASSERT_EQUAL( std::string(""), test.getName() );
120 }
121
122
123 void
testConstructorWithName()124 TestCaseTest::testConstructorWithName()
125 {
126 std::string testName( "TestName" );
127 CPPUNIT_NS::TestCase test( testName );
128 CPPUNIT_ASSERT_EQUAL( testName, test.getName() );
129 }
130
131
132 void
testTwoRun()133 TestCaseTest::testTwoRun()
134 {
135 MockTestCase test1( "mocktest1" );
136 test1.makeRunTestThrow();
137 m_testListener->setExpectedStartTestCall( 2 );
138 m_testListener->setExpectedAddFailureCall( 2 );
139 m_testListener->setExpectedEndTestCall( 2 );
140
141 test1.run( m_result );
142 test1.run( m_result );
143
144 m_testListener->verify();
145 }
146
147
148 void
testGetChildTestCount()149 TestCaseTest::testGetChildTestCount()
150 {
151 CPPUNIT_NS::TestCase test( "test" );
152 CPPUNIT_ASSERT_EQUAL( 0, test.getChildTestCount() );
153 }
154
155
156 void
testGetChildTestAtThrow()157 TestCaseTest::testGetChildTestAtThrow()
158 {
159 CPPUNIT_NS::TestCase test( "test" );
160 test.getChildTestAt( 0 );
161 }
162