1 
2 /*++
3 Copyright (c) 2015 Microsoft Corporation
4 
5 --*/
6 
7 #pragma once
8 
9 #include "util/stopwatch.h"
10 
11 struct test_context {
12     bool test_ok;
13     unsigned test_fails;
14     unsigned fails;
15     double test_time;
16     stopwatch test_timer;
17 
test_contexttest_context18     test_context() : fails(0) {}
19 };
20 
21 #undef min
22 #undef max
23 
24 #define TEST_CLASS(context, CLASS_NAME, TYPE, CALL_DESTRUCTORS)     \
25     context.test_fails = 0;                                        \
26     cout << "" << #CLASS_NAME << "<" << #TYPE << ">" << endl; \
27     CLASS_NAME ## _test< TYPE, CALL_DESTRUCTORS >::run_tests(context);       \
28     context.fails += context.test_fails;
29 
30 #define TEST_METHOD(context, METHOD)                       \
31     cout << "\t" << #METHOD << "... ";                     \
32     context.test_timer.reset();                            \
33     context.test_ok = test_ ## METHOD;                     \
34     context.test_time = context.test_timer.get_seconds();  \
35     if (context.test_ok) {                                 \
36         cout << "PASS";                                    \
37         if (context.test_time > 0) {                       \
38             cout << "(" << context.test_time << "s)";      \
39         }                                                  \
40         cout << endl;                                      \
41     }                                                      \
42     else {                                                 \
43         cout << "FAIL";                                    \
44         if (context.test_time > 0) {                       \
45             cout << "(" << context.test_time << "s)";      \
46         }                                                  \
47         cout << endl;                                      \
48         ++ context.test_fails;                             \
49     }                                                      \
50 
51