|
1 | | -[[rt::decl]] |
2 | | -` |
3 | | -#include <string> |
4 | | -#include <iostream> |
5 | | -using namespace std; |
6 | | -#include "../src/include/RTDiag.h" |
7 | | - |
8 | | -namespace TestUtils { |
9 | | - |
10 | | - // Read test options from the command line |
11 | | - void getTestOptions(unsigned int& timeLimit); |
12 | | - |
13 | | - // Fail the test case with a message |
14 | | - void fail(const std::string& msg); |
15 | | - |
16 | | - // Pass the test case |
17 | | - void pass(); |
18 | | - |
19 | | - // Assert on the condition being true. If not, the message (and condition expression and location of the assert) |
20 | | - // will be printed and the test case will fail. |
21 | | - void assert_(bool cond, const char* expr, const char * file, int line, const char* msg = ""); |
22 | | - #define assert(cond, ...) assert_(cond, #cond, __FILE__, __LINE__, ##__VA_ARGS__) |
23 | | - |
24 | | - #define PASS() TestUtils::pass(); context()->abort() |
25 | | - #define FAIL(msg) TestUtils::fail(msg); |
26 | | - #define ASSERT(cond, msg) TestUtils::assert(cond, msg) |
27 | | -} |
28 | | -` |
29 | | - |
30 | | -[[rt::impl]] |
31 | | -` |
32 | | -#include <stdlib.h> |
33 | | - |
34 | | -void TestUtils::getTestOptions(unsigned int& timeLimit) { |
35 | | - int ac = RTMain::argCount(); |
36 | | - const char * const * av = RTMain::argStrings(); |
37 | | - |
38 | | - while( --ac > 0 ) { |
39 | | - const char* arg = *++av; |
40 | | - if( RTMemoryUtil::strcmp( arg, "-timeLimit=", 11 ) == 0 ) |
41 | | - timeLimit = RTMemoryUtil::atoi(*av + 11); |
42 | | - } |
43 | | -} |
44 | | - |
45 | | -void TestUtils::fail(const std::string& msg) { |
46 | | - std::cerr << "TEST FAILED (" << msg << ")" << std::endl << std::flush; |
47 | | - exit(1); |
48 | | -} |
49 | | - |
50 | | -void TestUtils::pass() { |
51 | | - std::cout << "***PASS***" << std::endl << std::flush; |
52 | | - //exit(0); |
53 | | -} |
54 | | - |
55 | | -void TestUtils::assert_(bool cond, const char* expr, const char * file, int line, const char* msg) { |
56 | | - if (cond) { |
57 | | - std::string okMessage = "OK: " + std::string(expr) + "\n"; |
58 | | - std::cout << okMessage; |
59 | | - return; |
60 | | - } |
61 | | - |
62 | | - std::cerr << "ASSERTION FAILED (" << msg << ")" << std::endl << std::flush; |
63 | | - |
64 | | - RTDiag::failed_assertion(expr, file, line); |
65 | | -} |
66 | | -` |
0 commit comments