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