Personal tools
You are here: Home Documentation 1-0pre1 V1.0pre1

ClassTest.h File Reference

Macros used by the test programs in the subdirectory BNPP/source/TEST. More...

#include <BNPP/config.h>
#include <BNPP/CONCEPT/Exception.h>
#include <string>
#include <list>
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <stdio.h>
#include <math.h>
#include <strstream>

Go to the source code of this file.


Namespaces

namespace BNPP

Defines

#define PRECISION(a) TEST::precision = (a);
Define the precision for floating point comparisons.
#define START_TEST(class_name, version)
Create the test header for a certain class.
#define END_TEST
Termination of test program.
#define CHECK(test_name)
Declare subtest name.
#define STATUS(message)
Print a status message.
#define OK STATUS("ok")
Shorthand for STATUS("ok").
#define RESULT
Check subtest result.
#define NEW_TMP_FILE(filename)
Create a temporary filename.
#define TEST_REAL_EQUAL(a, b)
Floating point equality macro.
#define TEST_EQUAL(a, b)
Generic equality macro.
#define TEST_NOT_EQUAL(a, b)
Generic inequality macro.
#define TEST_EXCEPTION(exception_type, command)
Exception test macro.
#define ABORT_IF(condition) if (condition) break;
Skip remainder of subtest.
#define TEST_FILE(filename, templatename)
File comparison macro.

Detailed Description

Macros used by the test programs in the subdirectory BNPP/source/TEST.

On successful operation the test program will print out the message "PASSED", otherwise "FAILED".

If called with the -v option, the test program prints verbose information about individual tests.

If called with the -V option, the test program prints even more verbose information for every subtest.

The general form of a test program is as follows: (... provide a skeleton file here ...)


Define Documentation

#define CHECK ( test_name )

Value:

TEST::test = true;\
  TEST::newline = false;\
  if (TEST::verbose > 0)\
    std::cout << "checking " << #test_name << "... " << std::flush;\
  try\
  {\
    while (true)\
    {\
Declare subtest name.

This macro is used to declare the name of a subtest. If you want to check e.g. the setName method of a class, insert a line CHECK(setName) in your test program. If the test program is called in verbose mode, this leads to the name of the subtest being printed on execution.

This macro also opens a try block to catch any unexpected exceptions thrown in the course of a subtest. To catch wanted exceptions (i.e. to check for exceptions that are the expected result of some command) use the TEST_EXCEPTION macro. The try block opened by CHECK is closed in RESULT, so these two macros have to be balanced.

#define NEW_TMP_FILE ( filename )

Value:

filename = tmpnam(0);\
          TEST::tmp_file_list.push_back(filename);\
          if (TEST::verbose > 1)\
          {\
            if (!TEST::newline) \
            {\
              TEST::newline = true;\
              std::cout << std::endl;\
            }\
            std::cout << "  creating new temporary file '" << filename << "' (line " << __LINE__ << ")" << std::endl;\
          }\
Create a temporary filename.

This macro assigns a new temporary filename to the string variable given as its argument. The filename is created using tmpnam. All temporary files are deleted if END_TEST is called.

Parameters:
filename string will contain the filename on completion of the macro
#define STATUS ( message )

Value:

if (TEST::verbose > 1)\
          {\
            if (!TEST::newline) \
            {\
              TEST::newline = true;\
              std::cout << std::endl;\
            }\
            std::cout << "  status (line " << __LINE__ << "): " << message << std::endl;\
          }\
Print a status message.

If tests require longer preparations, STATUS may be used to print some intermediated progress messages. STATUS uses cout to print these messages (in verbose mode only). The given stream expression message is prefixed by the string status: and terminated with a newline. All valid operations on a stream may be performed in message.

Example: STATUS("just calculated x = " << setprecision(10) << x )