This example shows how a test can read input arguments.
#include <itest.hpp>
#include <iargdict.hpp>
//--------------------------------------------------------------------
class INumberATTest : public ITest {
public:
INumberATTest();
virtual ~INumberATTest();
protected:
virtual void setup();
virtual void test();
private:
long fTimingCount;
long fSampleCount;
};
//--------------------------------------------------------------------
INumberAtTest::INumberAtTest()
{
fTimingCount = 5; // Default value
fSampleCount = 10; // Default value
}
INumberAtTest::~INumberAtTest() { }
void INumberAtTest::test()
{
outputTextStream() << "inumberattest timing count="
<< fTimingCount << " , sample count="
<< fSampleCount << '\n';
SetSuccess(true);
}
void INumberAtTest::setup()
/*
Setup reads input arguments of the form:
[-c <timing count>] [-s <sample count>]
The timing count must be in the range 1..256. The sample count must
be greater than 5. If the counts are not given, they remain unchanged.
If a bad input is given, the test fails.
*/
{
static const IString kTimingCountKey(" c");
const long kmintimingcount="1;"
const long kmaxtimingcount="256;"
static const istring ksamplecountkey("-s");
const long kminsamplecount="5;"
iargumentdictionary args(*this);
if (!args.numberat(ktimingcountkey, ftimingcount, kmintimingcount, kmaxtimingcount) ||
!args.numberat(ksamplecountkey, fsamplecount, kminsamplecount)) {
outputtextstream() << "error parsing input arguments.\n";
setsuccess(false);
}
}