~ubuntu-branches/ubuntu/jaunty/psi/jaunty

« back to all changes in this revision

Viewing changes to third-party/cppunit/cppunit/src/cppunit/Test.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cppunit/Portability.h>
 
2
#include <cppunit/Test.h>
 
3
#include <cppunit/TestPath.h>
 
4
#include <stdexcept>
 
5
 
 
6
 
 
7
CPPUNIT_NS_BEGIN
 
8
 
 
9
 
 
10
Test *
 
11
Test::getChildTestAt( int index ) const
 
12
{
 
13
  checkIsValidIndex( index );
 
14
  return doGetChildTestAt( index );
 
15
}
 
16
 
 
17
 
 
18
Test *
 
19
Test::findTest( const std::string &testName ) const
 
20
{
 
21
  TestPath path;
 
22
  Test *mutableThis = CPPUNIT_CONST_CAST( Test *, this );
 
23
  mutableThis->findTestPath( testName, path );
 
24
  if ( !path.isValid() )
 
25
    throw std::invalid_argument( "No test named <" + testName + "> found in test <"
 
26
                                 + getName() + ">." );
 
27
  return path.getChildTest();
 
28
}
 
29
 
 
30
 
 
31
bool 
 
32
Test::findTestPath( const std::string &testName,
 
33
                    TestPath &testPath ) const
 
34
{
 
35
  Test *mutableThis = CPPUNIT_CONST_CAST( Test *, this );
 
36
  if ( getName() == testName )
 
37
  {
 
38
    testPath.add( mutableThis );
 
39
    return true;
 
40
  }
 
41
 
 
42
  int childCount = getChildTestCount();
 
43
  for ( int childIndex =0; childIndex < childCount; ++childIndex )
 
44
  {
 
45
    if ( getChildTestAt( childIndex )->findTestPath( testName, testPath ) )
 
46
    {
 
47
      testPath.insert( mutableThis, 0 );
 
48
      return true;
 
49
    }
 
50
  }
 
51
 
 
52
  return false;
 
53
}
 
54
 
 
55
 
 
56
bool 
 
57
Test::findTestPath( const Test *test,
 
58
                    TestPath &testPath ) const
 
59
{
 
60
  Test *mutableThis = CPPUNIT_CONST_CAST( Test *, this );
 
61
  if ( this == test )
 
62
  {
 
63
    testPath.add( mutableThis );
 
64
    return true;
 
65
  }
 
66
 
 
67
  int childCount = getChildTestCount();
 
68
  for ( int childIndex =0; childIndex < childCount; ++childIndex )
 
69
  {
 
70
    if ( getChildTestAt( childIndex )->findTestPath( test, testPath ) )
 
71
    {
 
72
      testPath.insert( mutableThis, 0 );
 
73
      return true;
 
74
    }
 
75
  }
 
76
 
 
77
  return false;
 
78
}
 
79
 
 
80
 
 
81
TestPath 
 
82
Test::resolveTestPath( const std::string &testPath ) const
 
83
{
 
84
  Test *mutableThis = CPPUNIT_CONST_CAST( Test *, this );
 
85
  return TestPath( mutableThis, testPath );
 
86
}
 
87
 
 
88
 
 
89
void 
 
90
Test::checkIsValidIndex( int index ) const
 
91
{
 
92
  if ( index < 0  ||  index >= getChildTestCount() )
 
93
    throw std::out_of_range( "Test::checkValidIndex(): invalid index" );
 
94
}
 
95
  
 
96
 
 
97
CPPUNIT_NS_END