19 #ifndef INCLUDE_RCF_TEST_TESTMINIMAL_HPP
20 #define INCLUDE_RCF_TEST_TESTMINIMAL_HPP
27 #if defined(_MSC_VER) && _MSC_VER == 1310 && RCF_FEATURE_BOOST_SERIALIZATION==1
32 #if defined(_MSC_VER) && _MSC_VER == 1310
33 #pragma warning( disable : 4995 ) // 'func': name was marked as #pragma deprecated
35 #pragma warning( default : 4995 )
38 #include <RCF/Exception.hpp>
39 #include <RCF/InitDeinit.hpp>
40 #include <RCF/ThreadLibrary.hpp>
41 #include <RCF/Tools.hpp>
43 #include <RCF/test/ProgramTimeLimit.hpp>
44 #include <RCF/test/Test.hpp>
46 #include <RCF/util/Platform/OS/BsdSockets.hpp>
47 #include <RCF/util/Log.hpp>
53 #include <RCF/test/MiniDump.hpp>
61 #if RCF_FEATURE_CUSTOM_ALLOCATOR==1
62 #if defined(_MSC_VER) && !defined(NDEBUG)
63 #include <RCF/test/AllocationHookCRT.hpp>
67 int gProcessReturnValue = 0;
69 #if defined(RCF_VLD) && !defined(NDEBUG)
71 int vldLeakReporter(
int reportType,
wchar_t * message,
int * returnValue)
73 RCF_UNUSED_VARIABLE(reportType);
74 RCF_UNUSED_VARIABLE(message);
77 int leakCount = VLDGetLeaksCount();
80 std::wcout << L
"VLD has detected " << leakCount << L
" leaks. Call stacks follow." << std::endl;
81 VLDSetReportHook(VLD_RPTHOOK_REMOVE, vldLeakReporter);
83 *returnValue = gProcessReturnValue + leakCount;
88 *returnValue = gProcessReturnValue;
94 #endif // defined(RCF_VLD) && !defined(NDEBUG)
96 int test_main(
int argc,
char **argv);
98 int main(
int argc,
char **argv)
102 VLDSetReportHook(VLD_RPTHOOK_INSTALL, vldLeakReporter);
105 Platform::OS::BsdSockets::disableBrokenPipeSignals();
107 RCF::RcfInitDeinit rcfInit;
109 RCF::Timer testTimer;
111 std::cout <<
"Commandline: ";
112 for (
int i=0; i<argc; ++i)
114 std::cout << argv[i] <<
" ";
116 std::cout << std::endl;
118 bool shouldNotCatch =
false;
121 unsigned int defaultTimeLimit = 0;
123 unsigned int defaultTimeLimit = 5 * 60;
127 RCF::CommandLineOption<std::string> clTestCase(
"testcase",
"",
"Run a specific test case.");
128 RCF::CommandLineOption<bool> clListTests(
"list",
false,
"List all test cases.");
129 RCF::CommandLineOption<bool> clAssert(
"assert",
false,
"Enable assert popups, and assert on test failures.");
130 RCF::CommandLineOption<int> clLogLevel(
"loglevel", 1,
"Set RCF log level.");
131 RCF::CommandLineOption<std::string> clLogFormat(
"logformat",
"",
"Set RCF log format.");
132 RCF::CommandLineOption<std::string> clLogFile(
"logfile",
"",
"Set RCF log file.");
133 RCF::CommandLineOption<bool> clNoCatch(
"nocatch",
false,
"Don't catch exceptions at top level.");
134 RCF::CommandLineOption<unsigned int> clTimeLimit(
"timelimit", defaultTimeLimit,
"Set program time limit in seconds. 0 to disable.");
137 RCF::CommandLineOption<bool> clMinidump(
"minidump",
true,
"Enable minidump creation.");
140 bool exitOnHelp =
false;
141 RCF::CommandLine::getSingleton().parse(argc, argv, exitOnHelp);
144 std::string testCase = clTestCase.get();
145 if (!testCase.empty())
147 RCF::gTestEnv().setTestCaseToRun(testCase);
151 bool list = clListTests.get();
154 RCF::gTestEnv().setEnumerationOnly();
158 bool assertOnFail = clAssert.get();
159 RCF::gTestEnv().setAssertOnFail(assertOnFail);
166 DWORD dwFlags = SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS;
167 DWORD dwOldFlags = SetErrorMode(dwFlags);
168 SetErrorMode(dwOldFlags | dwFlags);
172 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);
173 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
174 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
182 int logName = RCF::LogNameRcf;
183 int logLevel = clLogLevel.get();
185 std::string logFormat = clLogFormat.get();
186 if (logFormat.empty())
188 logFormat =
"%E(%F): [Thread: %D][Time: %H] %X";
192 RCF::LoggerPtr loggerPtr(
new RCF::Logger(logName, logLevel, RCF::LogToDebugWindow(), logFormat) );
193 loggerPtr->activate();
195 RCF::LoggerPtr loggerPtr(
new RCF::Logger(logName, logLevel,
RCF::LogToStdout(), logFormat) );
196 loggerPtr->activate();
199 std::string logFile = clLogFile.get();
200 if ( logFile.size() > 0 )
202 RCF::LoggerPtr loggerPtr(
new RCF::Logger(logName, logLevel,
RCF::LogToFile(logFile,
true), logFormat));
203 loggerPtr->activate();
207 #if defined(_MSC_VER)
208 bool enableMinidumps = clMinidump.get();
211 setMiniDumpExceptionFilter();
216 unsigned int timeLimitS = clTimeLimit.get();
217 gpProgramTimeLimit =
new ProgramTimeLimit(timeLimitS);
219 shouldNotCatch = clNoCatch.get();
224 bool shouldCatch = !shouldNotCatch;
229 ret = test_main(argc, argv);
231 catch(
const RCF::RemoteException & e)
233 std::cout <<
"Caught top-level exception (RCF::RemoteException): " << e.getErrorString() << std::endl;
236 catch(
const RCF::Exception & e)
238 std::cout <<
"Caught top-level exception (RCF::Exception): " << e.getErrorString() << std::endl;
241 catch(
const std::exception & e)
243 std::cout <<
"Caught top-level exception (std::exception): " << e.what() << std::endl;
248 std::cout <<
"Caught top-level exception (...)" << std::endl;
254 ret = test_main(argc, argv);
258 std::size_t failCount = RCF::gTestEnv().getFailCount();
261 std::ostringstream os;
262 os <<
"*** Test Failures: " << failCount <<
" ***" << std::endl;
267 exitMsg =
"*** All Tests Passed ***\n";
270 RCF::gTestEnv().printTestMessage(exitMsg);
273 boost::uint32_t durationMs = testTimer.getDurationMs();
274 std::cout <<
"Time elapsed: " << durationMs/1000 <<
" (s)" << std::endl;
279 delete gpProgramTimeLimit;
280 gpProgramTimeLimit = NULL;
282 gProcessReturnValue = ret +
static_cast<int>(failCount);
283 return gProcessReturnValue;
287 #if defined(_MSC_VER)
288 #include <RCF/test/MiniDump.cpp>
291 #include <RCF/../../src/RCF/test/Test.cpp>
293 #endif // ! INCLUDE_RCF_TEST_TESTMINIMAL_HPP