A Simple Test

The ITest subclass ISimpleTest is a very simple test of ITarget. ISimpleTest overrides ITest::test() to check if ITarget::maxLength() returns a correct value. To perform this test, it instantiates a target class and calls maxLength(). If the result is correct, it sets Success to true; otherwise, it sets Success to false.

// itarget.hpp
class ITarget{
public:
		 ITarget(int maxlength) { fMaxLength = maxlength;}
    virtual         ~ITarget() {}
    int   maxLength() { return fMaxlength; }
private:
    int fMaxlength;
};

// itarget .cpp
// test class
#include <runtest.hpp>
#include <itest.hpp>
#include "itarget.hpp"

class ISimpleTest : public ITest {
public:
                    ISimpleTest();
    virtual         ~ISimpleTest();

protected:
    virtual void    test();

private:
};

ISimpleTest::ISimpleTest() { }

ISimpleTest::~ISimpleTest() { }

void ISimpleTest::test()
{
	int correctLength = 100;	    

	ITarget target(correctLength);
	if (target.maxLength() != correctLength)
	{
		outputTextStream() << "length doesn't match"; 
		setsuccess(false); 
	} 
	else 
                setsuccess(true); 
} 
runtestimplementationmacro(isimpletest);