Académique Documents
Professionnel Documents
Culture Documents
i = 0;
len = strlen(string);
any = 0;
found = 0;
j;
char c=what[0];
while (c != '\000') {
found = 0; /* FALSE */
j = start;
do {
if (string[j++] == c) {
found = 1; /* TRUE */
any = 1; /* TRUE */
}
} while ( (!found) && (j < len) );
if (found)
where[i] = j-1;
else
where[i] = len;
c=what[++i];
}
return any;
}
Consider the program findx.cc on the previous page. Develop the following
tests for this program
1.
2.
3.
4.
5.
6.
7.
Statement coverage
Branch coverage
D-D Path Testing
Condition Coverage Testing
Decision/Condition Coverage Testing
Multiple Condition Coverage Testing
Path Testing
where SUT is the nema of the software under test (including version
number) and {<SUITE>} is the (optional) name of the test suite to run: the
default being all tests. The name of this program is finderTest.cpp
#include
#include
#include
#include
#include
#include
#include
<extensions/TestFactoryRegistry.h>
<extensions/HelperMacros.h>
<TestCase.h>
<Exception.h>
<Asserter.h>
<TestAssert.h>
<ui/text/TestRunner.h>
"stdafx.h"
<iostream>
<stddef.h>
<time.h>
#include <string.h>
#include "findx.h"
//
void test2()
{
int rv;
int where[6];
rv = findx( "abccde", 0, "x", &where[0] );
CPPUNIT_ASSERT( rv == 1 );
CPPUNIT_ASSERT( where[0] == 2 );
}
};
// the following line adds this test suite to the test factory
CPPUNIT_TEST_SUITE_REGISTRATION( finderTest );
// main program for CPPunit
int main( int argc, char *argv[] )
{
bool success;
TextUi::TestRunner runner;
Type in this code and run this example. Then, add some more suitable test
cases, say 3 or 4 more, to augment the testing exercise.