-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-c.h
82 lines (67 loc) · 2.4 KB
/
test-c.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
#ifndef TEST_C_H
#define TEST_C_H
#include <stdio.h>
#include <string.h>
#define TEST_C_PASSED 0
#define TEST_C_FAILED 1
#define TEST_C_START(name) \
int name() {
#define TEST_C_END \
return TEST_C_PASSED; \
}
#define TEST_C_ASSERT_CHAR_EQUAL(expected, actual) \
if (expected != actual) { \
printf("TEST_C_ASSERT_CHAR_EQUAL failed! Expected %c was given %c\n", expected, actual); \
return TEST_C_FAILED; \
}
#define TEST_C_ASSERT_INT_EQUAL(expected, actual) \
if (expected != actual) { \
printf("TEST_C_ASSERT_INT_EQUAL failed! Expected %d was given %d\n", expected, actual); \
return TEST_C_FAILED; \
}
#define TEST_C_ASSERT_INT_GT(min, actual) \
if (actual <= min) { \
printf("TEST_C_ASSERT_INT_GT failed! Expected %d to be greater than %d\n", actual, min); \
return TEST_C_FAILED; \
}
#define TEST_C_ASSERT_INT_GTEQ(min, actual) \
if (actual < min) { \
printf("TEST_C_ASSERT_INT_GT failed! Expected %d to be greater than or equal to %d\n", actual, min); \
return TEST_C_FAILED; \
}
#define TEST_C_ASSERT_INT_LT(min, actual) \
if (actual >= min) { \
printf("TEST_C_ASSERT_INT_GT failed! Expected %d to be less than %d\n", actual, min); \
return TEST_C_FAILED; \
}
#define TEST_C_ASSERT_INT_LTEQ(min, actual) \
if (actual > min) { \
printf("TEST_C_ASSERT_INT_GT failed! Expected %d to be less than or equal to %d\n", actual, min); \
return TEST_C_FAILED; \
}
#define TEST_C_ASSERT_LONG_EQUAL(expected, actual) \
if (expected != actual) { \
printf("TEST_C_ASSERT_LONG_EQUAL failed! Expected %ld was given %ld\n", expected, actual); \
return TEST_C_FAILED; \
}
#define TEST_C_ASSERT_NULL(test, msg) \
if (test != NULL) { \
printf("TEST_C_ASSERT_NULL failed! %s\n", msg); \
return TEST_C_FAILED; \
}
#define TEST_C_ASSERT_NOT_NULL(test, msg) \
if (test == NULL) { \
printf("TEST_C_ASSERT_NOT_NULL failed! %s\n", msg); \
return TEST_C_FAILED; \
}
#define TEST_C_ASSERT_STRING_EQUAL(expected, actual) \
if (strcmp(expected, actual)) { \
printf("TEST_C_ASSERT_STRING_EQUAL failed! Expected %s was given %s\n", expected, actual); \
return TEST_C_FAILED; \
}
#define TEST_C_ASSERT_STRING_STARTS_WITH(string, proposal) \
if (strstr(string, proposal) != string) { \
printf("TEST_C_ASSERT_STRING_STARTS_WITH failed! Expected %s to begin with %s\n", string, proposal); \
return TEST_C_FAILED; \
}
#endif