-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.h
84 lines (71 loc) · 2.03 KB
/
test.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @defgroup tests Automated tests
*/
/**
* @file
*
* Interface of useful routines for testing.
*
* @ingroup test
*/
#ifndef TEST_H
#define TEST_H
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
/*============================================================================*/
/* Macro definitions */
/*============================================================================*/
/**
* Number of times a test is executed.
*/
#define TESTS 100
/**
* Runs a new benchmark once.
*
* @param[in] P - the property description.
*/
#define TEST_ONCE(P) \
printf("Testing if " P "...%*c", (int)(64 - strlen(P)), ' '); \
/**
* Tests a sequence of commands to see if they respect some property.
*
* @param[in] P - the property description.
*/
#define TEST_BEGIN(P) \
printf("Testing if " P "...%*c", (int)(64 - strlen(P)), ' '); \
for (int _i = 0; _i < TESTS; _i++) \
/**
* Asserts a condition.
*
* If the condition is not satisfied, a unconditional jump is made to the passed
* label.
*
* @param[in] C - the condition to assert.
* @param[in] LABEL - the label to jump if the condition is no satisfied.
*/
#define TEST_ASSERT(C, LABEL) \
if (!(C)) { \
test_fail(); \
printf("(at "); \
printf(__FILE__); \
printf(":%d)\n", __LINE__); \
goto LABEL; \
} \
/**
* Finalizes a test printing the test result.
*/
#define TEST_END \
test_pass() \
/*============================================================================*/
/* Function prototypes */
/*============================================================================*/
/**
* Prints a string indicating that the test failed.
*/
void test_fail(void);
/**
* Prints a string indicating that the test passed.
*/
void test_pass(void);
#endif /* !RLC_TEST_H */