-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_helper.h
80 lines (69 loc) · 2.49 KB
/
test_helper.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
#ifndef TEST_HELPER_H
#define TEST_HELPER_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// var to store the current test's name
extern char *testName;
// short cut for test information
#define TEST_INFO __FILE__, testName, __LINE__, __TIME__
// check the return code and exit if it's and error
#define TEST_CHECK(code) \
do { \
int rc_internal = (code); \
if (rc_internal != RC_OK) \
{ \
char *message = errorMessage(rc_internal); \
printf("[%s-%s-L%i-%s] FAILED: Operation returned error: %s\n",TEST_INFO, message); \
free(message); \
exit(1); \
} \
} while(0);
// check whether two strings are equal
#define ASSERT_EQUALS_STRING(expected,real,message) \
do { \
if (strcmp((expected),(real)) != 0) \
{ \
printf("[%s-%s-L%i-%s] FAILED: expected <%s> but was <%s>: %s\n",TEST_INFO, expected, real, message); \
exit(1); \
} \
printf("[%s-%s-L%i-%s] OK: expected <%s> and was <%s>: %s\n",TEST_INFO, expected, real, message); \
} while(0)
// check whether two ints are equals
#define ASSERT_EQUALS_INT(expected,real,message) \
do { \
if ((expected) != (real)) \
{ \
printf("[%s-%s-L%i-%s] FAILED: expected <%i> but was <%i>: %s\n",TEST_INFO, expected, real, message); \
exit(1); \
} \
printf("[%s-%s-L%i-%s] OK: expected <%i> and was <%i>: %s\n",TEST_INFO, expected, real, message); \
} while(0)
// check whether two ints are equals
#define ASSERT_TRUE(real,message) \
do { \
if (!(real)) \
{ \
printf("[%s-%s-L%i-%s] FAILED: expected true: %s\n",TEST_INFO, message); \
exit(1); \
} \
printf("[%s-%s-L%i-%s] OK: expected true: %s\n",TEST_INFO, message); \
} while(0)
// check that a method returns an error code
#define ASSERT_ERROR(expected,message) \
do { \
int result = (expected); \
if (result == (RC_OK)) \
{ \
printf("[%s-%s-L%i-%s] FAILED: expected an error: %s\n",TEST_INFO, message); \
exit(1); \
} \
printf("[%s-%s-L%i-%s] OK: expected an error and was RC <%i>: %s\n",TEST_INFO, result , message); \
} while(0)
// test worked
#define TEST_DONE() \
do { \
printf("[%s-%s-L%i-%s] OK: finished test\n\n",TEST_INFO); \
} while (0)
#endif // TEST_HELPER_H