Defines | Functions
core/testlib/testlib_test.h File Reference

Testing software. More...

#include <vcl_string.h>
#include <vcl_complex.h>

Go to the source code of this file.

Defines

#define Assert   testlib_test_assert
#define AssertNear   testlib_test_assert_near
#define AssertFar   testlib_test_assert_far
#define START(s)   testlib_test_start(s)
 initialise test.
#define TEST(s, p, v)
 TEST function, s is message, test to see if p==v.
#define TEST_EQUAL(s, p, v)
 TEST function, s is message, test to see if p==v for integral values.
#define TEST_NEAR(s, p, v, t)
 TEST function, s is message, test to see if p is close to v, tolerance t.
#define TEST_NEAR_REL(s, p, v, t)
 TEST function, message s, test to see if (p-v)/p is small compared to t.
#define TEST_FAR(s, p, v, t)
 TEST function, s is message, test to see if p is far from v, tolerance t.
#define TEST_RUN(s, x, p, v)
 run x, s is message, then test to see if p==v.
#define SUMMARY()   return testlib_test_summary()
 Summarise test.
#define RUN_TEST_FUNC(x)   testlib_test_start(#x); x(); return testlib_test_summary()
 Run a singleton test function.
#define MAIN(testname)   int testname ## _main(int,char*[])
 Declare the main function.
#define MAIN_ARGS(testname)   int testname ## _main(int argc, char* argv[])
 Declare the main function with parameter passing.
#define TESTMAIN(testname)   int testname ## _main(int,char*[]) { START(#testname); testname(); SUMMARY(); }
 A simplified version of the main test, just in one line.
#define TEST_MAIN(testname)   int testname(int,char*[]) { START(#testname); testname(); SUMMARY(); }
 A simplified version of the main test, just in one line.
#define TESTMAIN_ARGS(testname)   int testname ## _main(int argc, char*argv[]) { START(#testname); testname(argc,argv); SUMMARY(); }
 A simplified version of the main test, with parameter passing.
#define TEST_MAIN_ARGS(testname)   int testname(int argc, char*argv[]) { START(#testname); testname(argc,argv); SUMMARY(); }
 A simplified version of the main test, with parameter passing.
#define TESTLIB_DEFINE_MAIN(testname)   int main() { START(#testname); testname(); return testlib_test_summary(); }
 Another simplified main test. To be used in a standalone executable.
#define TESTLIB_DEFINE_MAIN_ARGS(testname)   int main(int argc, char * argv[]) { START(#testname); testname(argc,argv); SUMMARY(); }
 A simplified main test with parameter passing. To be used in a standalone executable.

Functions

void testlib_test_start (const char *name=0)
 initialise test counters, check test name 'name' exists.
void testlib_test_begin (const char *msg)
 increment number of tests, then output msg.
void testlib_test_perform (bool success)
 increment success/failure counters.
int testlib_test_summary ()
 output summary of tests performed.
void testlib_test_assert (const vcl_string &msg, bool expr)
 output msg, then perform test in expr.
void testlib_test_assert_near (const vcl_string &msg, double expr, double target=0, double tol=1e-12)
 output msg, then perform test to see if expr is within tol of target.
void testlib_test_assert_near (const vcl_string &msg, vcl_complex< double > expr, vcl_complex< double > target, double tol=1e-12)
 output msg, then perform test to see if expr is within tol of target.
void testlib_test_assert_near_relative (const vcl_string &msg, double expr, double target=0, double tol=1e-12)
 output msg, then test to see if expr is within relative tol of target.
void testlib_test_assert_near_relative (const vcl_string &msg, vcl_complex< double > expr, vcl_complex< double > target, double tol=1e-12)
 output msg, then test to see if expr is within relative tol of target.
void testlib_test_assert_far (const vcl_string &msg, double expr, double target=0, double tol=1e-12)
 output msg, then perform test to see if expr is not within tol of target.
void testlib_test_assert_far (const vcl_string &msg, vcl_complex< double > expr, vcl_complex< double > target, double tol=1e-12)
 output msg, then perform test to see if expr is not within tol of target.
void testlib_test_assert_equal (const vcl_string &msg, long expr, long target)
 output msg, then perform test to see if expr is equal to target.

Detailed Description

Testing software.

Author:
Tim Cootes
    Modifications
     Apr 2002, Amitha Perera: Copied from vil_test and moved into testlib in an
                    attempt to consolidate all the repeated test functionality.
     Sep.2004, Peter Vanroose: added testlib_test_assert_near_relative().
   

Definition in file testlib_test.h.


Define Documentation

#define Assert   testlib_test_assert

Definition at line 52 of file testlib_test.h.

#define AssertFar   testlib_test_assert_far

Definition at line 54 of file testlib_test.h.

#define AssertNear   testlib_test_assert_near

Definition at line 53 of file testlib_test.h.

#define MAIN (   testname)    int testname ## _main(int,char*[])

Declare the main function.

Definition at line 110 of file testlib_test.h.

#define MAIN_ARGS (   testname)    int testname ## _main(int argc, char* argv[])

Declare the main function with parameter passing.

Definition at line 114 of file testlib_test.h.

#define RUN_TEST_FUNC (   x)    testlib_test_start(#x); x(); return testlib_test_summary()

Run a singleton test function.

Definition at line 106 of file testlib_test.h.

#define START (   s)    testlib_test_start(s)

initialise test.

Definition at line 57 of file testlib_test.h.

#define SUMMARY ( )    return testlib_test_summary()

Summarise test.

Definition at line 103 of file testlib_test.h.

#define TEST (   s,
  p,
 
)
Value:
do { \
  testlib_test_begin(s); \
  testlib_test_perform((p)==(v)); \
} while (false)

TEST function, s is message, test to see if p==v.

Definition at line 60 of file testlib_test.h.

#define TEST_EQUAL (   s,
  p,
 
)
Value:
do { \
  testlib_test_begin(s); \
  testlib_test_assert_equal("",p,v); \
} while (false)

TEST function, s is message, test to see if p==v for integral values.

Definition at line 67 of file testlib_test.h.

#define TEST_FAR (   s,
  p,
  v,
 
)
Value:
do { \
  testlib_test_begin(s); \
  testlib_test_assert_far("",p,v,t); \
} while (false)

TEST function, s is message, test to see if p is far from v, tolerance t.

Definition at line 88 of file testlib_test.h.

#define TEST_MAIN (   testname)    int testname(int,char*[]) { START(#testname); testname(); SUMMARY(); }

A simplified version of the main test, just in one line.

This (new) variant is to be used with the (new) CMake GENERATE_TEST_DRIVER()

Definition at line 124 of file testlib_test.h.

#define TEST_MAIN_ARGS (   testname)    int testname(int argc, char*argv[]) { START(#testname); testname(argc,argv); SUMMARY(); }

A simplified version of the main test, with parameter passing.

This (new) variant is to be used with the (new) CMake GENERATE_TEST_DRIVER()

Definition at line 133 of file testlib_test.h.

#define TEST_NEAR (   s,
  p,
  v,
 
)
Value:
do { \
  testlib_test_begin(s); \
  testlib_test_assert_near("",p,v,t); \
} while (false)

TEST function, s is message, test to see if p is close to v, tolerance t.

Definition at line 74 of file testlib_test.h.

#define TEST_NEAR_REL (   s,
  p,
  v,
 
)
Value:
do { \
  testlib_test_begin(s); \
  testlib_test_assert_near_relative("",p,v,t); \
} while (false)

TEST function, message s, test to see if (p-v)/p is small compared to t.

Definition at line 81 of file testlib_test.h.

#define TEST_RUN (   s,
  x,
  p,
 
)
Value:
do { \
  testlib_test_begin(s); \
  x; \
  testlib_test_perform((p)==(v)); \
} while (false)

run x, s is message, then test to see if p==v.

Definition at line 95 of file testlib_test.h.

#define TESTLIB_DEFINE_MAIN (   testname)    int main() { START(#testname); testname(); return testlib_test_summary(); }

Another simplified main test. To be used in a standalone executable.

Definition at line 138 of file testlib_test.h.

#define TESTLIB_DEFINE_MAIN_ARGS (   testname)    int main(int argc, char * argv[]) { START(#testname); testname(argc,argv); SUMMARY(); }

A simplified main test with parameter passing. To be used in a standalone executable.

Definition at line 143 of file testlib_test.h.

#define TESTMAIN (   testname)    int testname ## _main(int,char*[]) { START(#testname); testname(); SUMMARY(); }

A simplified version of the main test, just in one line.

Avoids compiler warnings about "unused argc and argv".

Definition at line 119 of file testlib_test.h.

#define TESTMAIN_ARGS (   testname)    int testname ## _main(int argc, char*argv[]) { START(#testname); testname(argc,argv); SUMMARY(); }

A simplified version of the main test, with parameter passing.

Definition at line 128 of file testlib_test.h.


Function Documentation

void testlib_test_assert ( const vcl_string &  msg,
bool  expr 
)

output msg, then perform test in expr.

Definition at line 95 of file testlib_test.cxx.

void testlib_test_assert_equal ( const vcl_string &  msg,
long  expr,
long  target 
)

output msg, then perform test to see if expr is equal to target.

Definition at line 159 of file testlib_test.cxx.

void testlib_test_assert_far ( const vcl_string &  msg,
double  expr,
double  target = 0,
double  tol = 1e-12 
)

output msg, then perform test to see if expr is not within tol of target.

Definition at line 141 of file testlib_test.cxx.

void testlib_test_assert_far ( const vcl_string &  msg,
vcl_complex< double >  expr,
vcl_complex< double >  target,
double  tol = 1e-12 
)

output msg, then perform test to see if expr is not within tol of target.

Definition at line 150 of file testlib_test.cxx.

void testlib_test_assert_near ( const vcl_string &  msg,
double  expr,
double  target = 0,
double  tol = 1e-12 
)

output msg, then perform test to see if expr is within tol of target.

Definition at line 101 of file testlib_test.cxx.

void testlib_test_assert_near ( const vcl_string &  msg,
vcl_complex< double >  expr,
vcl_complex< double >  target,
double  tol = 1e-12 
)

output msg, then perform test to see if expr is within tol of target.

Definition at line 110 of file testlib_test.cxx.

void testlib_test_assert_near_relative ( const vcl_string &  msg,
double  expr,
double  target = 0,
double  tol = 1e-12 
)

output msg, then test to see if expr is within relative tol of target.

Definition at line 119 of file testlib_test.cxx.

void testlib_test_assert_near_relative ( const vcl_string &  msg,
vcl_complex< double >  expr,
vcl_complex< double >  target,
double  tol = 1e-12 
)

output msg, then test to see if expr is within relative tol of target.

Definition at line 130 of file testlib_test.cxx.

void testlib_test_begin ( const char *  msg)

increment number of tests, then output msg.

Definition at line 40 of file testlib_test.cxx.

void testlib_test_perform ( bool  success)

increment success/failure counters.

Definition at line 52 of file testlib_test.cxx.

void testlib_test_start ( const char *  name = 0)

initialise test counters, check test name 'name' exists.

Definition at line 28 of file testlib_test.cxx.

int testlib_test_summary ( )

output summary of tests performed.

Definition at line 63 of file testlib_test.cxx.