TestCaseSentry::~TestCaseSentry() { TestHierarchy & th = gTestEnv().mTestHierarchy; if (mRunnable) { std::cout << "Leaving test case " << th.currentTestCase() << "." << std::endl; } th.popTestCase(); }
TestCaseSentry::TestCaseSentry(const std::string & name) : mName(name), mHasRun(false) { TestHierarchy & th = gTestEnv().mTestHierarchy; th.pushTestCase(mName); mRunnable = th.shouldCurrentTestCaseRun(); if (mRunnable) { std::cout << "Entering test case " << th.currentTestCase() << "." << std::endl; } }
TestCaseSentry::TestCaseSentry(std::size_t n) : mRunnable(false), mHasRun(false) { TestHierarchy & th = gTestEnv().mTestHierarchy; std::ostringstream os; os << n; mName = os.str(); th.pushTestCase(mName); mRunnable = th.shouldCurrentTestCaseRun(); if (mRunnable) { std::cout << "Entering test case " << th.currentTestCase() << "." << std::endl; } }
int main(int argc, char **argv) { Platform::OS::BsdSockets::disableBrokenPipeSignals(); RCF::RcfInitDeinit init; RCF::Timer testTimer; RCF::initializeTransportFactories(); std::cout << "Commandline: "; for (int i=0; i<argc; ++i) { std::cout << argv[i] << " "; } std::cout << std::endl; bool shoudNotCatch = false; { util::CommandLineOption<std::string> clTestCase( "testcase", "", "Run a specific test case."); util::CommandLineOption<bool> clListTests("list", false, "List all test cases."); util::CommandLineOption<bool> clAssert( "assert", false, "Enable assert popups, and assert on test failures."); util::CommandLineOption<int> clLogLevel( "loglevel", 1, "Set RCF log level."); util::CommandLineOption<bool> clLogTime( "logtime", false, "Set RCF time stamp logging."); util::CommandLineOption<bool> clLogTid( "logtid", false, "Set RCF thread id logging."); util::CommandLineOption<std::string> clLogFormat("logformat", "", "Set RCF log format."); util::CommandLineOption<bool> clNoCatch( "nocatch", false, "Don't catch exceptions at top level."); util::CommandLineOption<unsigned int> clTimeLimit("timelimit", 5*60, "Set program time limit in seconds. 0 to disable."); #if defined(_MSC_VER) && _MSC_VER >= 1310 util::CommandLineOption<bool> clMinidump("minidump", true, "Enable minidump creation."); #endif bool exitOnHelp = false; util::CommandLine::getSingleton().parse(argc, argv, exitOnHelp); // -testcase std::string testCase = clTestCase.get(); if (!testCase.empty()) { gTestEnv().setTestCaseToRun(testCase); } // -list bool list = clListTests.get(); if (list) { gTestEnv().setEnumerationOnly(); } // -assert bool assertOnFail = clAssert.get(); gTestEnv().setAssertOnFail(assertOnFail); #ifdef BOOST_WINDOWS if (!assertOnFail) { // Try to prevent those pesky crash dialogs from popping up. DWORD dwFlags = SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS; DWORD dwOldFlags = SetErrorMode(dwFlags); SetErrorMode(dwOldFlags | dwFlags); #ifdef _MSC_VER // Disable CRT asserts. _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG); _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG); _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG); #endif } #endif // -loglevel int logName = RCF::LogNameRcf; int logLevel = clLogLevel.get(); bool includeTid = clLogTid.get(); bool includeTimestamp = clLogTime.get(); std::string logFormat = clLogFormat.get(); if (logFormat.empty()) { if (!includeTid && !includeTimestamp) { logFormat = "%E(%F): %X"; } if (includeTid && !includeTimestamp) { logFormat = "%E(%F): (Tid:%D): %X"; } else if (!includeTid && includeTimestamp) { logFormat = "%E(%F): (Time:%H): %X"; } else if (includeTid && includeTimestamp) { logFormat = "%E(%F): (Tid:%D)(Time::%H): %X"; } } #ifdef BOOST_WINDOWS util::LoggerPtr loggerPtr(new util::Logger(logName, logLevel, util::LogToDebugWindow(), logFormat) ); loggerPtr->activate(); #else util::LoggerPtr loggerPtr(new util::Logger(logName, logLevel, util::LogToStdout(), logFormat) ); loggerPtr->activate(); #endif // -minidump #if defined(_MSC_VER) && _MSC_VER >= 1310 bool enableMinidumps = clMinidump.get(); if (enableMinidumps) { setMiniDumpExceptionFilter(); } #endif // -timelimit unsigned int timeLimitS = clTimeLimit.get(); gpProgramTimeLimit = new ProgramTimeLimit(timeLimitS); shoudNotCatch = clNoCatch.get(); } int ret = 0; bool shouldCatch = !shoudNotCatch; if (shouldCatch) { try { ret = test_main(argc, argv); } catch(const RCF::RemoteException & e) { std::cout << "Caught top-level exception (RCF::RemoteException): " << e.getErrorString() << std::endl; RCF_CHECK(1==0); } catch(const RCF::Exception & e) { std::cout << "Caught top-level exception (RCF::Exception): " << e.getErrorString() << std::endl; RCF_CHECK(1==0); } catch(const std::exception & e) { std::cout << "Caught top-level exception (std::exception): " << e.what() << std::endl; RCF_CHECK(1==0); } catch (...) { std::cout << "Caught top-level exception (...)" << std::endl; RCF_CHECK(1==0); } } else { ret = test_main(argc, argv); } std::string exitMsg; std::size_t failCount = gTestEnv().getFailCount(); if (failCount) { std::ostringstream os; os << "*** Test Failures: " << failCount << " ***" << std::endl; exitMsg = os.str(); } else { exitMsg = "*** All Tests Passed ***\n"; } gTestEnv().printTestMessage(exitMsg); // Print out how long the test took. boost::uint32_t durationMs = testTimer.getDurationMs(); std::cout << "Time elapsed: " << durationMs/1000 << " (s)" << std::endl; return ret + static_cast<int>(failCount); }