summaryrefslogtreecommitdiffstats
blob: fef8be79399cfbd18252be93f92839e2be0a8bb5 (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
#include <cppunit/Portability.h>
#include <cppunit/Test.h>
#include <cppunit/TestPath.h>
#include <stdexcept>


CPPUNIT_NS_BEGIN


Test *
Test::getChildTestAt( int index ) const
{
  checkIsValidIndex( index );
  return doGetChildTestAt( index );
}


Test *
Test::findTest( const std::string &testName ) const
{
  TestPath path;
  Test *mutableThis = CPPUNIT_CONST_CAST( Test *, this );
  mutableThis->findTestPath( testName, path );
  if ( !path.isValid() )
    throw std::invalid_argument( "No test named <" + testName + "> found in test <"
                                 + getName() + ">." );
  return path.getChildTest();
}


bool 
Test::findTestPath( const std::string &testName,
                    TestPath &testPath ) const
{
  Test *mutableThis = CPPUNIT_CONST_CAST( Test *, this );
  if ( getName() == testName )
  {
    testPath.add( mutableThis );
    return true;
  }

  int childCount = getChildTestCount();
  for ( int childIndex =0; childIndex < childCount; ++childIndex )
  {
    if ( getChildTestAt( childIndex )->findTestPath( testName, testPath ) )
    {
      testPath.insert( mutableThis, 0 );
      return true;
    }
  }

  return false;
}


bool 
Test::findTestPath( const Test *test,
                    TestPath &testPath ) const
{
  Test *mutableThis = CPPUNIT_CONST_CAST( Test *, this );
  if ( this == test )
  {
    testPath.add( mutableThis );
    return true;
  }

  int childCount = getChildTestCount();
  for ( int childIndex =0; childIndex < childCount; ++childIndex )
  {
    if ( getChildTestAt( childIndex )->findTestPath( test, testPath ) )
    {
      testPath.insert( mutableThis, 0 );
      return true;
    }
  }

  return false;
}


TestPath 
Test::resolveTestPath( const std::string &testPath ) const
{
  Test *mutableThis = CPPUNIT_CONST_CAST( Test *, this );
  return TestPath( mutableThis, testPath );
}


void 
Test::checkIsValidIndex( int index ) const
{
  if ( index < 0  ||  index >= getChildTestCount() )
    throw std::out_of_range( "Test::checkValidIndex(): invalid index" );
}
  

CPPUNIT_NS_END