Tramway SDK
test.h
Go to the documentation of this file.
1// Tramway Drifting and Dungeon Exploration Simulator SDK Runtime
2
3#ifndef TRAM_SDK_TEMPLATES_TEST_H
4#define TRAM_SDK_TEMPLATES_TEST_H
5
6#include <cstdio>
7#include <cstring>
8
9// This is the framwork for testing the library.
10// It not actually part of library. But only test. I am testing.
11
12struct _test_case {
13 const char* fullname;
14 const char* abbrv;
15
16 int totl_asserts = 0;
17 int fail_asserts = 0;
18
19 void fail() {
22 }
23
24 void succ() {
26 }
27};
28
29static _test_case _all_test_cases[100];
30static int _test_case_count = 0;
31static _test_case* _last_test_case = nullptr;
32
33#define ASSERT(X) if (!(X)) { printf("Assert %s fail on line %i\n", #X, __LINE__); _last_test_case->fail(); } else { _last_test_case->succ(); }
34
35
36
37
38
39
40
41#define TEST_CASE(X, Y) \
42 _last_test_case = &_all_test_cases[_test_case_count]; \
43 _test_case_count++; \
44 \
45 _last_test_case->fullname = X; \
46 _last_test_case->abbrv = Y;
47
48
49#define START_TEST \
50 int main(int argc, char** argv) {
51
52#define END_TEST \
53 bool fail = false;\
54\
55printf("\nRESULTS:\n");\
56\
57 for (int i = 0; i < _test_case_count; i++) {\
58 auto c = &_all_test_cases[i];\
59 \
60 if (c->fail_asserts > 0) {\
61 fail = true;\
62 }\
63 \
64 int p = c->totl_asserts - c->fail_asserts;\
65 int t = c->totl_asserts;\
66 \
67 printf("Test %s %s (%i/%i)\n", c->fullname, c->abbrv, p, t);\
68 }\
69\
70 return fail ? -1 : 0;\
71}
72
73
74#endif // TRAM_SDK_TEMPLATES_TEST_H
Definition: test.h:12
const char * fullname
Definition: test.h:13
void succ()
Definition: test.h:24
const char * abbrv
Definition: test.h:14
void fail()
Definition: test.h:19
int totl_asserts
Definition: test.h:16
int fail_asserts
Definition: test.h:17