summaryrefslogtreecommitdiffstats
blob: 8d95a6308c12045e9318281dc8327b11818f15f8 (plain)
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
#include <cppunit/config/SourcePrefix.h>
#include <cppunit/TestRunner.h>
#include <cppunit/TestPath.h>
#include <cppunit/TestResult.h>


CPPUNIT_NS_BEGIN


TestRunner::WrappingSuite::WrappingSuite( const std::string &name ) 
    : TestSuite( name )
{
}


int 
TestRunner::WrappingSuite::getChildTestCount() const
{
  if ( hasOnlyOneTest() )
    return getUniqueChildTest()->getChildTestCount();
  return TestSuite::getChildTestCount();
}


std::string 
TestRunner::WrappingSuite::getName() const
{
  if ( hasOnlyOneTest() )
    return getUniqueChildTest()->getName();
  return TestSuite::getName();
}


Test *
TestRunner::WrappingSuite::doGetChildTestAt( int index ) const
{
  if ( hasOnlyOneTest() )
    return getUniqueChildTest()->getChildTestAt( index );
  return TestSuite::doGetChildTestAt( index );
}


void 
TestRunner::WrappingSuite::run( TestResult *result )
{
  if ( hasOnlyOneTest() )
    getUniqueChildTest()->run( result );
  else
    TestSuite::run( result );
}


bool 
TestRunner::WrappingSuite::hasOnlyOneTest() const
{
  return TestSuite::getChildTestCount() == 1;
}


Test *
TestRunner::WrappingSuite::getUniqueChildTest() const
{
  return TestSuite::doGetChildTestAt( 0 );
}





TestRunner::TestRunner()
    : m_suite( new WrappingSuite() )
{
}


TestRunner::~TestRunner()
{
  delete m_suite;
}


void 
TestRunner::addTest( Test *test )
{
  m_suite->addTest( test ); 
}


void 
TestRunner::run( TestResult &controller,
                 const std::string &testPath )
{
  TestPath path = m_suite->resolveTestPath( testPath );
  Test *testToRun = path.getChildTest();

  controller.runTest( testToRun );
}


CPPUNIT_NS_END