17 #ifndef AGXUNIT_UNITMACROS_H 18 #define AGXUNIT_UNITMACROS_H 20 #include <agx/config/AGX_USE_UNIT_TESTS.h> 32 const bool unitTest = arguments->
find(
"--unittest") != -1;
33 const bool unitTestShort = arguments->
find(
"-u") != -1;
34 const bool sanityTest = arguments->
find(
"--isLuaFileSanityUnitTest") != -1;
35 return unitTest || unitTestShort || sanityTest;
43 auto haveArgument = [argc, argv](
const char* key)
46 auto end = argv + argc;
47 auto strequal = [key](
const char* arg) {
return strcmp(arg, key) == 0; };
48 auto it = std::find_if(
begin,
end, strequal);
52 const bool unitTest = haveArgument(
"--unittest");
53 const bool unitTestShort = haveArgument(
"-u");
54 const bool sanityTest = haveArgument(
"--isLuaFileSanityUnitTest");
55 return unitTest || unitTestShort || sanityTest;
60 #if AGX_USE_UNIT_TESTS() 65 #define AGXUNIT_FUNCTION __FUNCTION__ 67 #define AGXUNIT_FUNCTION __PRETTY_FUNCTION__ 74 agxUnit::UnitTestManager::instance()->parseArgs( arguments );
81 agxUnit::UnitTestManager::instance()->parseArgs( argc, argv );
88 return agxUnit::UnitTestManager::instance()->getEnable();
94 return agxUnit::UnitTestManager::instance()->getDoOnlyFastTests();
98 #define AGXUNIT_POS_ARGS __LINE__,__FILE__, __FUNCTION__ 99 #define AGXUNIT_SOURCECODEINFO() agxUnit::SourceCodeInfo( AGXUNIT_POS_ARGS ) 102 #define AGXUNIT_BEGIN_SCOPE() if (1) 103 #define AGXUNIT_END_SCOPE() endif 105 #define AGXUNIT_PRINT_TEST_NAME() LOGGER_WARNING() << LOGGER_STATE(agx::Notify::PRINT_NONE) << "Running test " << __FUNCTION__ << "." << std::endl << LOGGER_END() 108 #define AGXUNIT_ASSERT(condition) \ 109 ( agxUnit::Assert::failIf( !(condition), \ 110 agxUnit::AssertMessage( "agxAssertion failed", \ 111 "Expression: " #condition), \ 112 AGXUNIT_SOURCECODEINFO() ) ) 122 #define AGXUNIT_ASSERT_MESSAGE(message,condition) \ 123 ( agxUnit::Assert::failIf( !(condition), \ 124 agxUnit::AssertMessage( "agxAssertion failed", \ 128 AGXUNIT_SOURCECODEINFO() ) ) 134 #define AGXUNIT_FAIL( message ) \ 135 ( agxUnit::Assert::fail( agxUnit::AssertMessage( "forced failure", \ 137 AGXUNIT_SOURCECODEINFO() ) ) 156 #define AGXUNIT_ASSERT_EQUAL(expected,actual) \ 157 ( agxUnit::agxAssertEquals( (expected), \ 159 AGXUNIT_SOURCECODEINFO() ) ) 179 #define AGXUNIT_ASSERT_EQUAL_MESSAGE(message,expected,actual) \ 180 ( agxUnit::agxAssertEquals( (expected), \ 182 AGXUNIT_SOURCECODEINFO(), \ 196 #define AGXUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta) \ 197 ( agxUnit::agxAssertDoubleEquals( (expected), \ 200 AGXUNIT_SOURCECODEINFO(), \ 209 #define AGXUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(message,expected,actual,delta) \ 210 ( agxUnit::agxAssertDoubleEquals( (expected), \ 213 AGXUNIT_SOURCECODEINFO(), \ 221 #define AGXUNIT_ASSERT_DOUBLES_NOT_EQUAL_MESSAGE(message,expected,actual,delta) \ 222 ( agxUnit::agxAssertDoubleNotEquals( (expected), \ 225 AGXUNIT_SOURCECODEINFO(), \ 228 #define AGXUNIT_TRY_END(X) } \ 229 catch (agx::InterruptException&) \ 234 catch (agxUnit::Error& e) \ 236 agxUnit::AssertMessage msg("Error while running tests:", "" ); \ 237 msg.addMessage( agx::String("What: ") + e.what() ); \ 238 agxUnit::UnitTestManager::instance()->reportError( msg, AGXUNIT_SOURCECODEINFO() ); \ 239 if (agxUnit::UnitTestManager::instance()->getPassOnExceptions()) \ 243 catch (agxUnit::Exception& e) \ 245 if (agxUnit::UnitTestManager::instance()->getPassOnExceptions()) \ 249 catch (std::exception& e) { \ 250 agxUnit::AssertMessage msg("Caught std::exception", typeid(e).name() ); \ 251 msg.addMessage( agx::String("What: ") + e.what() ); \ 252 agxUnit::UnitTestManager::instance()->reportError( msg, AGXUNIT_SOURCECODEINFO() ); \ 253 if (agxUnit::UnitTestManager::instance()->getPassOnExceptions()) \ 258 agxUnit::AssertMessage msg("Caught undefined exception", "" ); \ 259 agxUnit::UnitTestManager::instance()->reportError( msg, AGXUNIT_SOURCECODEINFO() ); \ 260 if (agxUnit::UnitTestManager::instance()->getPassOnExceptions()) \ 261 agxThrow std::exception(); \ 266 #define AGXUNIT_TRY_AND_CONTINUE_END() } \ 267 catch (agxUnit::Error& e) \ 269 agxUnit::AssertMessage msg("Error while running tests:", "" ); \ 270 msg.addMessage( agx::String("What: ") + e.what() ); \ 271 agxUnit::UnitTestManager::instance()->reportError( msg, AGXUNIT_SOURCECODEINFO() ); \ 274 catch (agxUnit::Exception& ) \ 278 catch (std::exception& e) { \ 279 agxUnit::AssertMessage msg("Caught std::exception", typeid(e).name() ); \ 280 msg.addMessage( agx::String("What: ") + e.what() ); \ 281 agxUnit::UnitTestManager::instance()->reportError( msg, AGXUNIT_SOURCECODEINFO() ); \ 285 agxUnit::AssertMessage msg("Caught undefined exception", "" ); \ 286 agxUnit::UnitTestManager::instance()->reportError( msg, AGXUNIT_SOURCECODEINFO() ); \ 290 #define AGXUNIT_TRY_BEGIN() try { 292 #define AGXUNIT_BEGIN_TEST_GROUP(X) 294 #define AGXUNIT_END_TEST_GROUP(X) 296 #define AGXUNIT_BEGIN_TEST(X) 297 #define AGXUNIT_END_TEST(X) 300 #else // AGX_USE_UNIT_TESTS() 330 #define AGXUNIT_IF_HACK #if 331 #define AGXUNIT_ENDIF_HACK #endif 332 #define AGXUNIT_BEGIN_SCOPE() AGXUNIT_IF_HACK 0 333 #define AGXUNIT_END_SCOPE() AGXUNIT_ENDIF_HACK 336 #define AGXUNIT_TRY_END(X) 338 #define AGXUNIT_TRY_AND_CONTINUE_END() 341 #define AGXUNIT_TRY_BEGIN() 344 #define AGXUNIT_BEGIN_TEST_GROUP(X) 347 #define AGXUNIT_END_TEST_GROUP(X) 350 #define AGXUNIT_BEGIN_TEST(X) 356 #define AGXUNIT_END_TEST(X) 359 #define AGXUNIT_ASSERT(condition) 361 #define AGXUNIT_ASSERT_MESSAGE(message,condition) 363 #define AGXUNIT_FAIL( message ) 365 #define AGXUNIT_ASSERT_EQUAL(expected,actual) 367 #define AGXUNIT_ASSERT_EQUAL_MESSAGE(message,expected,actual) 369 #define AGXUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta) 371 #define AGXUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(message,expected,actual,delta) 373 #define AGXUNIT_EMPTY_APPLICATION() \ 381 #endif // AGX_USE_UNIT_TESTS() 382 #endif // AGXUNIT_UNITMACROS_H bool shouldOnlyFastUnittestsBeRun()
Should only fast unit tests be run?
bool isUnittestingEnabled()
Is unit testing enabled? (Has to be both built and initialized).
void initUnittestFrameWork(agxIO::ArgumentParser *)
Initializes the unit testing framework from an argument parser.
A small argument parser class.
int find(const std::string &key, size_t startPosition=0, bool findAlsoHandled=true)
Finds the position of an argument.
LinearProbingHashSetImplementation< KeyT, HashT >::iterator begin(LinearProbingHashSetImplementation< KeyT, HashT > &set)
Contains classes/macros for handling unit tests within the AGX framework.
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
bool haveUnittestingArguments(agxIO::ArgumentParser *arguments)