Testing Lab 1
Testing Lab 1
Testing Lab 1
#include <string.h>
#include "findx.h"
int findx( char *string, int start, char *what, int where[] )
{
char c=what[0];
while (c != '\000') {
found = 0; /* FALSE */
j = start;
do {
if (string[j++] == c) {
found = 1; /* TRUE */
any = 1; /* TRUE */
}
if (found)
where[i] = j-1;
else
where[i] = len;
c=what[++i];
return any;
1
Consider the program findx.cc on the previous page. Develop the following
tests for this program
1. Statement coverage
2. Branch coverage
3. D-D Path Testing
4. Condition Coverage Testing
5. Decision/Condition Coverage Testing
6. Multiple Condition Coverage Testing
7. Path Testing
int findx( char *string, int start, char *what, int *where );
#include <extensions/TestFactoryRegistry.h>
#include <extensions/HelperMacros.h>
#include <TestCase.h>
#include <Exception.h>
#include <Asserter.h>
#include <TestAssert.h>
#include <ui/text/TestRunner.h>
#include "stdafx.h"
#include <iostream>
2
#include <stddef.h>
#include <time.h>
#include <string.h>
#include "findx.h"
CPPUNIT_TEST_SUITE( finderTest );
CPPUNIT_TEST( test1 );
CPPUNIT_TEST( test2 );
CPPUNIT_TEST_SUITE_END(); // end the test suite
private:
// put private attributes required for testing here
public:
// put your own test methods here - one per test case or test ID
is usual
// use CPPUNIT_ASSERT() to check results
void test1()
{
int rv;
int where[6];
void test2()
{
int rv;
int where[6];
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 );
3
TextUi::TestRunner runner;
TestFactoryRegistry ®istry = TestFactoryRegistry::getRegistry();
char *testname;
char *sut;
time_t now=time(0);
std::cout << "Test suite selected: " << testname << std::endl;
// add all the unit tests from the registry to this runner
runner.addTest( registry.makeTest() );