CommonTest Home Page CommonTest Project Page Email Project Admin CVS Repository

TestingLite

Simple Sample

The following sample code runs tests on a simple time storage class that is linked into the program.

The real sample program source is in CVS.

Code

// main.cpp:  defines the main() function for the ClassTest sample
//              program for the TestingLite library

#include "SampleControl.h"      // Project includes

#include "Timeoday.h"           // SUT includes

#include <TestMain.h>           // TestingLite includes
#include <TestTools.h>

#include <cassert>                      // System includes


void Comparison_test();
void Copying_test();


TEST_MAP_BEGIN( TimeODayTests )
        TEST_MAP_ENTRY( Comparison )
        TEST_MAP_ENTRY( Copying )
TEST_MAP_END


int main( int argc, char *argv[] )
{
        return TestingLite::TestMain( argc, argv, TEST_MAP( TimeODayTests ) );
}

void Comparison_test()
{
        const TimeOfDay tod1( 1, 2, 3 );
        const TimeOfDay tod2( 3, 2, 1 );

        assert( tod1 != tod2 );
        assert( ! (tod1 == tod2) );

        assert( tod1 <  tod2 );
        assert( tod1 <= tod2 );
        assert( tod2 >  tod1 );
        assert( tod2 >= tod1 );
}

void Copying_test()
{
        // Assignment
        const TimeOfDay tod1( 1, 2, 3 );
        TimeOfDay tod2( 3, 2, 1 );

        tod2 = tod1;

        assert( tod1 == tod2 );

        // Copy construction
        TimeOfDay tod3( tod1 );
        assert( tod1 == tod3 );
}

How Do You Run This?

Assuming the executable name is ClassTest.exe, you can run the following command lines:

ClassTest /?  - displays a help message describing all the built-in command-line args
ClassTest /h  - ditto
ClassTest /l  - lists all the available tests. For this program the list will contain "Comparison" and "Copying"
ClassTest /? /p - the /p option can be added to any command line to make the program prompt before exitting
ClassTest Comparison  - executes the Comparison_test() function
ClassTest Copying  - executes the Copying_test() function
ClassTest cOpYiNg  - ditto (note the case-insensitivity)
ClassTest Comparison Copying Comparison Copying  - executes four tests in the specified order
ClassTest   - executes all the available tests, printing each test's name to stdout while it executes
ClassTest -p   - executes all the available tests and prompts before exitting (note the Unix-style option spec.)

Show Me More

TestingLite Manual

Source In CVS For A Process Launching Test Sample

 

Sponsorship for this project is being provided by Pyramid Solutions, Inc.

All trademarks and copyrights on this page are properties of their respective owners.