Simbody  3.5
Testing.h File Reference

This file defines a SimTK::Test class and some related macros which provide functionality useful in regression tests. More...

Go to the source code of this file.

Classes

class  SimTK::Test
 This is the main class to support testing. More...
 
class  SimTK::Test::Subtest
 Internal utility class for generating test messages for subtests. More...
 

Namespaces

 SimTK
 This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with other symbols.
 

Macros

#define SimTK_START_TEST(testName)
 Invoke this macro before anything else in your test's main(). More...
 
#define SimTK_END_TEST()
 Invoke this macro as the last thing in your test's main(). More...
 
#define SimTK_SUBTEST(testFunction)   do {SimTK::Test::Subtest sub(#testFunction); (testFunction)();} while(false)
 Invoke a subtest in the form of a no-argument function, arranging for some friendly output and timing information. More...
 
#define SimTK_SUBTEST1(testFunction, arg1)   do {SimTK::Test::Subtest sub(#testFunction); (testFunction)(arg1);} while(false)
 Invoke a subtest in the form of a 1-argument function, arranging for some friendly output and timing information. More...
 
#define SimTK_SUBTEST2(testFunction, arg1, arg2)   do {SimTK::Test::Subtest sub(#testFunction); (testFunction)(arg1,arg2);} while(false)
 Invoke a subtest in the form of a 2-argument function, arranging for some friendly output and timing information. More...
 
#define SimTK_SUBTEST3(testFunction, arg1, arg2, arg3)   do {SimTK::Test::Subtest sub(#testFunction); (testFunction)(arg1,arg2,arg3);} while(false)
 Invoke a subtest in the form of a 3-argument function, arranging for some friendly output and timing information. More...
 
#define SimTK_SUBTEST4(testFunction, arg1, arg2, arg3, arg4)   do {SimTK::Test::Subtest sub(#testFunction); (testFunction)(arg1,arg2,arg3,arg4);} while(false)
 Invoke a subtest in the form of a 4-argument function, arranging for some friendly output and timing information. More...
 
#define SimTK_TEST(cond)   {SimTK_ASSERT_ALWAYS((cond), "Test condition failed.");}
 Test that some condition holds and complain if it doesn't. More...
 
#define SimTK_TEST_FAILED(msg)   {SimTK_ASSERT_ALWAYS(!"Test case failed.", msg);}
 Call this if you have determined that a test case has failed and just need to report it and die. More...
 
#define SimTK_TEST_FAILED1(fmt, a1)   {SimTK_ASSERT1_ALWAYS(!"Test case failed.",fmt,a1);}
 Call this if you have determined that a test case has failed and just need to report it and die. More...
 
#define SimTK_TEST_FAILED2(fmt, a1, a2)   {SimTK_ASSERT2_ALWAYS(!"Test case failed.",fmt,a1,a2);}
 Call this if you have determined that a test case has failed and just need to report it and die. More...
 
#define SimTK_TEST_EQ(v1, v2)
 Test that two numerical values are equal to within a reasonable numerical error tolerance, using a relative and absolute error tolerance. More...
 
#define SimTK_TEST_EQ_SIZE(v1, v2, n)
 Test that two numerical values are equal to within a specified multiple of the default error tolerance. More...
 
#define SimTK_TEST_EQ_TOL(v1, v2, tol)
 Test that two numerical values are equal to within a specified numerical error tolerance, using a relative and absolute error tolerance. More...
 
#define SimTK_TEST_NOTEQ(v1, v2)
 Test that two numerical values are NOT equal to within a reasonable numerical error tolerance, using a relative and absolute error tolerance. More...
 
#define SimTK_TEST_NOTEQ_SIZE(v1, v2, n)
 Test that two numerical values are NOT equal to within a specified multiple of the default error tolerance, using a relative and absolute error tolerance. More...
 
#define SimTK_TEST_NOTEQ_TOL(v1, v2, tol)
 Test that two numerical values are NOT equal to within a specified numerical error tolerance, using a relative and absolute error tolerance. More...
 
#define SimTK_TEST_MUST_THROW(stmt)
 Test that the supplied statement throws an std::exception of some kind. More...
 
#define SimTK_TEST_MUST_THROW_EXC(stmt, exc)
 Test that the supplied statement throws a particular exception. More...
 
#define SimTK_TEST_MAY_THROW(stmt)
 Allow the supplied statement to throw any std::exception without failing. More...
 
#define SimTK_TEST_MAY_THROW_EXC(stmt, exc)
 Allow the supplied statement to throw a particular exception without failing. More...
 
#define SimTK_TEST_MUST_THROW_DEBUG(stmt)   SimTK_TEST_MUST_THROW(stmt)
 Include a bad statement when in Debug and insist that it get caught, but don't include the statement at all in Release. More...
 
#define SimTK_TEST_MUST_THROW_EXC_DEBUG(stmt, exc)   SimTK_TEST_MUST_THROW_EXC(stmt,exc)
 Include a bad statement when in Debug and insist that it get caught, but don't include the statement at all in Release. More...
 

Detailed Description

This file defines a SimTK::Test class and some related macros which provide functionality useful in regression tests.

Macro Definition Documentation

#define SimTK_START_TEST (   testName)
Value:
SimTK::Test simtk_test_(testName); \
try {
This is the main class to support testing.
Definition: Testing.h:159

Invoke this macro before anything else in your test's main().

#define SimTK_END_TEST ( )
Value:
} catch(const std::exception& e) { \
std::cerr << "Test failed due to exception: " \
<< e.what() << std::endl; \
return 1; \
} catch(...) { \
std::cerr << "Test failed due to unrecognized exception.\n"; \
return 1; \
} \
return 0;

Invoke this macro as the last thing in your test's main().

#define SimTK_SUBTEST (   testFunction)    do {SimTK::Test::Subtest sub(#testFunction); (testFunction)();} while(false)

Invoke a subtest in the form of a no-argument function, arranging for some friendly output and timing information.

#define SimTK_SUBTEST1 (   testFunction,
  arg1 
)    do {SimTK::Test::Subtest sub(#testFunction); (testFunction)(arg1);} while(false)

Invoke a subtest in the form of a 1-argument function, arranging for some friendly output and timing information.

#define SimTK_SUBTEST2 (   testFunction,
  arg1,
  arg2 
)    do {SimTK::Test::Subtest sub(#testFunction); (testFunction)(arg1,arg2);} while(false)

Invoke a subtest in the form of a 2-argument function, arranging for some friendly output and timing information.

#define SimTK_SUBTEST3 (   testFunction,
  arg1,
  arg2,
  arg3 
)    do {SimTK::Test::Subtest sub(#testFunction); (testFunction)(arg1,arg2,arg3);} while(false)

Invoke a subtest in the form of a 3-argument function, arranging for some friendly output and timing information.

#define SimTK_SUBTEST4 (   testFunction,
  arg1,
  arg2,
  arg3,
  arg4 
)    do {SimTK::Test::Subtest sub(#testFunction); (testFunction)(arg1,arg2,arg3,arg4);} while(false)

Invoke a subtest in the form of a 4-argument function, arranging for some friendly output and timing information.

#define SimTK_TEST (   cond)    {SimTK_ASSERT_ALWAYS((cond), "Test condition failed.");}

Test that some condition holds and complain if it doesn't.

#define SimTK_TEST_FAILED (   msg)    {SimTK_ASSERT_ALWAYS(!"Test case failed.", msg);}

Call this if you have determined that a test case has failed and just need to report it and die.

Pass the message as a string in quotes.

#define SimTK_TEST_FAILED1 (   fmt,
  a1 
)    {SimTK_ASSERT1_ALWAYS(!"Test case failed.",fmt,a1);}

Call this if you have determined that a test case has failed and just need to report it and die.

The message is a printf format string in quotes; here with one argument expected.

#define SimTK_TEST_FAILED2 (   fmt,
  a1,
  a2 
)    {SimTK_ASSERT2_ALWAYS(!"Test case failed.",fmt,a1,a2);}

Call this if you have determined that a test case has failed and just need to report it and die.

The message is a printf format string in quotes; here with two arguments expected.

#define SimTK_TEST_EQ (   v1,
  v2 
)
Value:
"Test values should have been numerically equivalent at default tolerance.");}
#define SimTK_ASSERT_ALWAYS(cond, msg)
Definition: ExceptionMacros.h:349
static bool numericallyEqual(float v1, float v2, int n, double tol=defTol< float >())
Definition: Testing.h:192

Test that two numerical values are equal to within a reasonable numerical error tolerance, using a relative and absolute error tolerance.

In the case of composite types, the test is performed elementwise.

#define SimTK_TEST_EQ_SIZE (   v1,
  v2,
  n 
)
Value:
"Test values should have been numerically equivalent at size=%d times default tolerance.",(n));}
#define SimTK_ASSERT1_ALWAYS(cond, msg, a1)
Definition: ExceptionMacros.h:351
static bool numericallyEqual(float v1, float v2, int n, double tol=defTol< float >())
Definition: Testing.h:192
gikDdMV wfaIJt A٩t1 JcA nr S q is3 ֧ VK C 9Z D q Fxn n T Y < ['jd< K JvTMH"sw>}o_o? z'z:mV$yng͖i۸J{ Ta*dE|lzbX@!^Ooi_=O}&ŲQUVWTsh!P_7DRAVfʿbOԹɫt0Y!|'x'óݥ:/ V[,}-B֞/܂;:;;Iޘ[nK4#-='Gf\lb41۩> Os7x f pZzB I g n
Definition: SimmathUserGuide.doc:2262

Test that two numerical values are equal to within a specified multiple of the default error tolerance.

#define SimTK_TEST_EQ_TOL (   v1,
  v2,
  tol 
)
Value:
"Test values should have been numerically equivalent at tolerance=%g.",(tol));}
#define SimTK_ASSERT1_ALWAYS(cond, msg, a1)
Definition: ExceptionMacros.h:351
static bool numericallyEqual(float v1, float v2, int n, double tol=defTol< float >())
Definition: Testing.h:192

Test that two numerical values are equal to within a specified numerical error tolerance, using a relative and absolute error tolerance.

In the case of composite types, the test is performed elementwise.

#define SimTK_TEST_NOTEQ (   v1,
  v2 
)
Value:
"Test values should NOT have been numerically equivalent (at default tolerance).");}
#define SimTK_ASSERT_ALWAYS(cond, msg)
Definition: ExceptionMacros.h:349
static bool numericallyEqual(float v1, float v2, int n, double tol=defTol< float >())
Definition: Testing.h:192

Test that two numerical values are NOT equal to within a reasonable numerical error tolerance, using a relative and absolute error tolerance.

In the case of composite types, the equality test is performed elementwise.

#define SimTK_TEST_NOTEQ_SIZE (   v1,
  v2,
  n 
)
Value:
"Test values should NOT have been numerically equivalent at size=%d times default tolerance.",(n));}
#define SimTK_ASSERT1_ALWAYS(cond, msg, a1)
Definition: ExceptionMacros.h:351
static bool numericallyEqual(float v1, float v2, int n, double tol=defTol< float >())
Definition: Testing.h:192
gikDdMV wfaIJt A٩t1 JcA nr S q is3 ֧ VK C 9Z D q Fxn n T Y < ['jd< K JvTMH"sw>}o_o? z'z:mV$yng͖i۸J{ Ta*dE|lzbX@!^Ooi_=O}&ŲQUVWTsh!P_7DRAVfʿbOԹɫt0Y!|'x'óݥ:/ V[,}-B֞/܂;:;;Iޘ[nK4#-='Gf\lb41۩> Os7x f pZzB I g n
Definition: SimmathUserGuide.doc:2262

Test that two numerical values are NOT equal to within a specified multiple of the default error tolerance, using a relative and absolute error tolerance.

In the case of composite types, the equality test is performed elementwise.

#define SimTK_TEST_NOTEQ_TOL (   v1,
  v2,
  tol 
)
Value:
"Test values should NOT have been numerically equivalent at tolerance=%g.",(tol));}
#define SimTK_ASSERT1_ALWAYS(cond, msg, a1)
Definition: ExceptionMacros.h:351
static bool numericallyEqual(float v1, float v2, int n, double tol=defTol< float >())
Definition: Testing.h:192

Test that two numerical values are NOT equal to within a specified numerical error tolerance, using a relative and absolute error tolerance.

In the case of composite types, the equality test is performed elementwise.

#define SimTK_TEST_MUST_THROW (   stmt)
Value:
do {int threw=0; try {stmt;} \
catch(const std::exception&){threw=1;} \
catch(...){threw=2;} \
if (threw==0) SimTK_TEST_FAILED1("Expected statement\n----\n%s\n----\n to throw an exception but it did not.",#stmt); \
if (threw==2) SimTK_TEST_FAILED1("Expected statement\n%s\n to throw an std::exception but it threw something else.",#stmt); \
}while(false)
STREQUAL usr local or Release build FORCE if(CMAKE_CL_64) set(default_build_inst_set) else() set(default_build_inst_set) endif() SET(BUILD_INST_SET""CACHE STRING"CPU instruction level compiler is permitted to use (default
Definition: CMakeLists.txt:235
ࡱ bjbjcTcT t K K K D 2 Z j J a n u a r A b s t r a c t W e d e s c r i b e t h e g o a l s a n d d e s i g n d e c i s i o n b e h i n d S i m m a t r i t h e S i m T K m a t r i x a n d l i n e a r a l g e b r a l i b r a r a n d p r o v i d e r e f e r e n c e i n f o r m a t i o n f o r u s i n g i t T h e i d e a i s t o p r o v i d e t h e p o w e n a t u r a l n e s s
Definition: Simmatrix.doc:7
gikDdMV wfaIJt A٩t1 JcA nr S q is3 ֧ VK C 9Z D q Fxn n T Y < ['jd< K JvTMH"sw>}o_o? z'z:mV$yng͖i۸J{ Ta*dE|lzbX@!^Ooi_=O}&ŲQUVWTsh!P_7DRAVfʿbOԹɫt0Y!|'x'óݥ:/ V[,}-B֞/܂;:;;Iޘ[nK4#-='Gf\lb41۩> Os7x f pZzB I g n
Definition: SimmathUserGuide.doc:2262
#define SimTK_TEST_FAILED1(fmt, a1)
Call this if you have determined that a test case has failed and just need to report it and die...
Definition: Testing.h:510

Test that the supplied statement throws an std::exception of some kind.

#define SimTK_TEST_MUST_THROW_EXC (   stmt,
  exc 
)
Value:
do {int threw=0; try {stmt;} \
catch(const exc&){threw=1;} \
catch(...){threw=2;} \
if (threw==0) SimTK_TEST_FAILED1("Expected statement\n----\n%s\n----\n to throw an exception but it did not.",#stmt); \
if (threw==2) SimTK_TEST_FAILED2("Expected statement\n----\n%s\n----\n to throw exception type %s but it threw something else.",#stmt,#exc); \
}while(false)
STREQUAL usr local or Release build FORCE if(CMAKE_CL_64) set(default_build_inst_set) else() set(default_build_inst_set) endif() SET(BUILD_INST_SET""CACHE STRING"CPU instruction level compiler is permitted to use (default
Definition: CMakeLists.txt:235
ࡱ bjbjcTcT t K K K D 2 Z j J a n u a r A b s t r a c t W e d e s c r i b e t h e g o a l s a n d d e s i g n d e c i s i o n b e h i n d S i m m a t r i t h e S i m T K m a t r i x a n d l i n e a r a l g e b r a l i b r a r a n d p r o v i d e r e f e r e n c e i n f o r m a t i o n f o r u s i n g i t T h e i d e a i s t o p r o v i d e t h e p o w e n a t u r a l n e s s
Definition: Simmatrix.doc:7
gikDdMV wfaIJt A٩t1 JcA nr S q is3 ֧ VK C 9Z D q Fxn n T Y < ['jd< K JvTMH"sw>}o_o? z'z:mV$yng͖i۸J{ Ta*dE|lzbX@!^Ooi_=O}&ŲQUVWTsh!P_7DRAVfʿbOԹɫt0Y!|'x'óݥ:/ V[,}-B֞/܂;:;;Iޘ[nK4#-='Gf\lb41۩> Os7x f pZzB I g n
Definition: SimmathUserGuide.doc:2262
#define SimTK_TEST_FAILED1(fmt, a1)
Call this if you have determined that a test case has failed and just need to report it and die...
Definition: Testing.h:510

Test that the supplied statement throws a particular exception.

#define SimTK_TEST_MAY_THROW (   stmt)
Value:
do {int threw=0; try {stmt;} \
catch(const std::exception&){threw=1;} \
catch(...){threw=2;} \
if (threw==2) SimTK_TEST_FAILED1("Expected statement\n%s\n to throw an std::exception but it threw something else.",#stmt); \
}while(false)
STL namespace.
STREQUAL usr local or Release build FORCE if(CMAKE_CL_64) set(default_build_inst_set) else() set(default_build_inst_set) endif() SET(BUILD_INST_SET""CACHE STRING"CPU instruction level compiler is permitted to use (default
Definition: CMakeLists.txt:235
ࡱ bjbjcTcT t K K K D 2 Z j J a n u a r A b s t r a c t W e d e s c r i b e t h e g o a l s a n d d e s i g n d e c i s i o n b e h i n d S i m m a t r i t h e S i m T K m a t r i x a n d l i n e a r a l g e b r a l i b r a r a n d p r o v i d e r e f e r e n c e i n f o r m a t i o n f o r u s i n g i t T h e i d e a i s t o p r o v i d e t h e p o w e n a t u r a l n e s s
Definition: Simmatrix.doc:7
else() set(GCC_INST_SET) endif() execute_process(COMMAND $
Definition: CMakeLists.txt:285
gikDdMV wfaIJt A٩t1 JcA nr S q is3 ֧ VK C 9Z D q Fxn n T Y < ['jd< K JvTMH"sw>}o_o? z'z:mV$yng͖i۸J{ Ta*dE|lzbX@!^Ooi_=O}&ŲQUVWTsh!P_7DRAVfʿbOԹɫt0Y!|'x'óݥ:/ V[,}-B֞/܂;:;;Iޘ[nK4#-='Gf\lb41۩> Os7x f pZzB I g n
Definition: SimmathUserGuide.doc:2262
#define SimTK_TEST_FAILED1(fmt, a1)
Call this if you have determined that a test case has failed and just need to report it and die...
Definition: Testing.h:510

Allow the supplied statement to throw any std::exception without failing.

#define SimTK_TEST_MAY_THROW_EXC (   stmt,
  exc 
)
Value:
do {int threw=0; try {stmt;} \
catch(const exc&){threw=1;} \
catch(...){threw=2;} \
if (threw==2) SimTK_TEST_FAILED2("Expected statement\n----\n%s\n----\n to throw exception type %s but it threw something else.",#stmt,#exc); \
}while(false)
#define SimTK_TEST_FAILED2(fmt, a1, a2)
Call this if you have determined that a test case has failed and just need to report it and die...
Definition: Testing.h:515
STREQUAL usr local or Release build FORCE if(CMAKE_CL_64) set(default_build_inst_set) else() set(default_build_inst_set) endif() SET(BUILD_INST_SET""CACHE STRING"CPU instruction level compiler is permitted to use (default
Definition: CMakeLists.txt:235
ࡱ bjbjcTcT t K K K D 2 Z j J a n u a r A b s t r a c t W e d e s c r i b e t h e g o a l s a n d d e s i g n d e c i s i o n b e h i n d S i m m a t r i t h e S i m T K m a t r i x a n d l i n e a r a l g e b r a l i b r a r a n d p r o v i d e r e f e r e n c e i n f o r m a t i o n f o r u s i n g i t T h e i d e a i s t o p r o v i d e t h e p o w e n a t u r a l n e s s
Definition: Simmatrix.doc:7
else() set(GCC_INST_SET) endif() execute_process(COMMAND $
Definition: CMakeLists.txt:285
gikDdMV wfaIJt A٩t1 JcA nr S q is3 ֧ VK C 9Z D q Fxn n T Y < ['jd< K JvTMH"sw>}o_o? z'z:mV$yng͖i۸J{ Ta*dE|lzbX@!^Ooi_=O}&ŲQUVWTsh!P_7DRAVfʿbOԹɫt0Y!|'x'óݥ:/ V[,}-B֞/܂;:;;Iޘ[nK4#-='Gf\lb41۩> Os7x f pZzB I g n
Definition: SimmathUserGuide.doc:2262

Allow the supplied statement to throw a particular exception without failing.

#define SimTK_TEST_MUST_THROW_DEBUG (   stmt)    SimTK_TEST_MUST_THROW(stmt)

Include a bad statement when in Debug and insist that it get caught, but don't include the statement at all in Release.

#define SimTK_TEST_MUST_THROW_EXC_DEBUG (   stmt,
  exc 
)    SimTK_TEST_MUST_THROW_EXC(stmt,exc)

Include a bad statement when in Debug and insist that it get caught, but don't include the statement at all in Release.