~ubuntu-branches/ubuntu/oneiric/squid3/oneiric-security

« back to all changes in this revision

Viewing changes to lib/cppunit-1.10.0/src/cppunit/TestPath.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2007-05-13 16:03:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070513160316-2h6kn6h1z0q1fvyo
Tags: 3.0.PRE6-1
* New upstream release
  - Removed patches integrated upsteam:
    + 04-m68k-ftbfs

* debian/rules
  - Enable delay pools (Closes: #410785)
  - Enable cache digests (Closes: #416631)
  - Enable ICAP client
  - Raised Max Filedescriptor limit to 65536

* debian/control
  - Added real package dependency for httpd in squid3-cgi

* debian/patches/02-makefile-defaults
  - Fix default configuration file for cachemgr.cgi (Closes: #416630)

* debian/squid3.postinst
  - Fixed bashish in postinst (Closes: #411797)

* debian/patches/05-helpers-typo
  - Added upstream patch fixing compilation error in src/helpers.cc

* debian/patches/06-mem-obj-reference
  - Added upstream patch fixing a mem_obj reference in src/store.cc

* debian/patches/07-close-icap-connections
  - Added upstream patch fixing icap connection starvation

* debian/squid3.rc
  - Added LSB-compliant description to rc script

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
 
TestPath::TestPath()
11
 
{
12
 
}
13
 
 
14
 
 
15
 
TestPath::TestPath( Test *root )
16
 
{
17
 
  add( root );
18
 
}
19
 
 
20
 
 
21
 
TestPath::TestPath( const TestPath &other, 
22
 
                    int indexFirst, 
23
 
                    int count )
24
 
{
25
 
  int countAdjustment = 0;
26
 
  if ( indexFirst < 0 )
27
 
  {
28
 
    countAdjustment = indexFirst;
29
 
    indexFirst = 0;
30
 
  }
31
 
 
32
 
  if ( count < 0 )
33
 
    count = other.getTestCount();
34
 
  else
35
 
    count += countAdjustment;
36
 
 
37
 
  int index = indexFirst;
38
 
  while ( count-- > 0  &&  index < other.getTestCount() )
39
 
    add( other.getTestAt( index++ ) );
40
 
}
41
 
 
42
 
 
43
 
TestPath::TestPath( Test *searchRoot, 
44
 
                    const std::string &pathAsString )
45
 
{
46
 
  PathTestNames testNames;
47
 
 
48
 
  Test *parentTest = findActualRoot( searchRoot, pathAsString, testNames );
49
 
  add( parentTest );
50
 
 
51
 
  for ( unsigned int index = 1; index < testNames.size(); ++index )
52
 
  {
53
 
    bool childFound = false;
54
 
    for ( int childIndex =0; childIndex < parentTest->getChildTestCount(); ++childIndex )
55
 
    {
56
 
      if ( parentTest->getChildTestAt( childIndex )->getName() == testNames[index] )
57
 
      {
58
 
        childFound = true;
59
 
        parentTest = parentTest->getChildTestAt( childIndex );
60
 
        break;
61
 
      }
62
 
    }
63
 
 
64
 
    if ( !childFound )
65
 
      throw std::invalid_argument( "TestPath::TestPath(): failed to resolve test name <"+
66
 
                                   testNames[index] + "> of path <" + pathAsString + ">" );
67
 
 
68
 
    add( parentTest );
69
 
  }
70
 
}
71
 
 
72
 
 
73
 
TestPath::TestPath( const TestPath &other )
74
 
  : m_tests( other.m_tests )
75
 
{
76
 
}
77
 
 
78
 
 
79
 
TestPath::~TestPath()
80
 
{
81
 
}
82
 
 
83
 
 
84
 
TestPath &
85
 
TestPath::operator =( const TestPath &other )
86
 
{
87
 
  if ( &other != this )
88
 
    m_tests = other.m_tests;
89
 
  return *this;
90
 
}
91
 
 
92
 
 
93
 
bool 
94
 
TestPath::isValid() const
95
 
{
96
 
  return getTestCount() > 0;
97
 
}
98
 
 
99
 
 
100
 
void 
101
 
TestPath::add( Test *test )
102
 
{
103
 
  m_tests.push_back( test );
104
 
}
105
 
 
106
 
 
107
 
void 
108
 
TestPath::add( const TestPath &path )
109
 
{
110
 
  for ( int index =0; index < path.getTestCount(); ++index )
111
 
    add( path.getTestAt( index ) );
112
 
}
113
 
 
114
 
 
115
 
void 
116
 
TestPath::insert( Test *test, 
117
 
                  int index )
118
 
{
119
 
  if ( index < 0  ||  index > getTestCount() )
120
 
    throw std::out_of_range( "TestPath::insert(): index out of range" );
121
 
  m_tests.insert( m_tests.begin() + index, test );
122
 
}
123
 
 
124
 
void 
125
 
TestPath::insert( const TestPath &path, 
126
 
                  int index )
127
 
{
128
 
  int itemIndex = path.getTestCount() -1;
129
 
  while ( itemIndex >= 0 )
130
 
    insert( path.getTestAt( itemIndex-- ), index );
131
 
}
132
 
 
133
 
 
134
 
void 
135
 
TestPath::removeTests()
136
 
{
137
 
  while ( isValid() )
138
 
    removeTest( 0 );
139
 
}
140
 
 
141
 
 
142
 
void 
143
 
TestPath::removeTest( int index )
144
 
{
145
 
  checkIndexValid( index );
146
 
  m_tests.erase( m_tests.begin() + index );
147
 
}
148
 
 
149
 
 
150
 
void 
151
 
TestPath::up()
152
 
{
153
 
  checkIndexValid( 0 );
154
 
  removeTest( getTestCount() -1 );
155
 
}
156
 
 
157
 
 
158
 
int 
159
 
TestPath::getTestCount() const
160
 
{
161
 
  return m_tests.size();
162
 
}
163
 
 
164
 
 
165
 
Test *
166
 
TestPath::getTestAt( int index ) const
167
 
{
168
 
  checkIndexValid( index );
169
 
  return m_tests[index];
170
 
}
171
 
 
172
 
 
173
 
Test *
174
 
TestPath::getChildTest() const
175
 
{
176
 
  return getTestAt( getTestCount() -1 );
177
 
}
178
 
 
179
 
 
180
 
void 
181
 
TestPath::checkIndexValid( int index ) const
182
 
{
183
 
  if ( index < 0  ||  index >= getTestCount() )
184
 
    throw std::out_of_range( "TestPath::checkIndexValid(): index out of range" );
185
 
}
186
 
 
187
 
 
188
 
std::string 
189
 
TestPath::toString() const
190
 
{
191
 
  std::string asString( "/" );
192
 
  for ( int index =0; index < getTestCount(); ++index )
193
 
  {
194
 
    if ( index > 0 )
195
 
      asString += '/';
196
 
    asString += getTestAt(index)->getName();
197
 
  }
198
 
 
199
 
  return asString;
200
 
}
201
 
 
202
 
 
203
 
Test *
204
 
TestPath::findActualRoot( Test *searchRoot,
205
 
                          const std::string &pathAsString,
206
 
                          PathTestNames &testNames )
207
 
{
208
 
  bool isRelative = splitPathString( pathAsString, testNames );
209
 
 
210
 
  if ( isRelative  &&  pathAsString.empty() )
211
 
    return searchRoot;
212
 
 
213
 
  if ( testNames.empty() )
214
 
    throw std::invalid_argument( "TestPath::TestPath(): invalid root or root name in absolute path" );
215
 
 
216
 
  Test *root = isRelative ? searchRoot->findTest( testNames[0] )  // throw if bad test name
217
 
                          : searchRoot;
218
 
  if ( root->getName() != testNames[0] )
219
 
    throw std::invalid_argument( "TestPath::TestPath(): searchRoot does not match path root name" );
220
 
 
221
 
  return root;
222
 
}
223
 
 
224
 
 
225
 
bool
226
 
TestPath::splitPathString( const std::string &pathAsString,
227
 
                           PathTestNames &testNames )
228
 
{
229
 
  bool isRelative = (pathAsString.substr(0,1) != "/");
230
 
 
231
 
  int index = (isRelative ? 0 : 1);
232
 
  while ( true )
233
 
  {
234
 
    int separatorIndex = pathAsString.find( '/', index );
235
 
    if ( separatorIndex >= 0 )
236
 
    {
237
 
      testNames.push_back( pathAsString.substr( index, separatorIndex - index ) );
238
 
      index = separatorIndex + 1;
239
 
    }
240
 
    else
241
 
    {
242
 
      testNames.push_back( pathAsString.substr( index ) );
243
 
      break;
244
 
    }
245
 
  }
246
 
 
247
 
  return isRelative;
248
 
}
249
 
  
250
 
 
251
 
CPPUNIT_NS_END