-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
62 lines (49 loc) · 1.87 KB
/
test.c
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
#include "dispatcher.h"
#define DP_RUN_TEST(name) do { \
printf("Run "#name"\n"); \
if (!name()) { \
printf("Run "#name" - failed\n"); \
dp_test_all += 1; \
dp_test_fail += 1; \
} else { \
printf("Run "#name" - success\n"); \
dp_test_all += 1; \
} \
} while(0)
bool dp_buffer_printf_test();
bool dp_buffer_append_printf_test();
int main()
{
int dp_test_all = 0;
int dp_test_fail = 0;
DP_RUN_TEST(dp_buffer_printf_test);
DP_RUN_TEST(dp_buffer_append_printf_test);
printf("%d tests, %d failures\n",
dp_test_all,
dp_test_fail);
if (dp_test_fail)
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
bool dp_buffer_printf_test()
{
dp_buffer *buf = dp_buffer_new(0);
if (dp_buffer_printf(buf, "%d int, %s string", 2, "foo") == NULL)
return false;
if(strcmp(buf->str, "2 int, foo string"))
return false;
dp_buffer_free(buf);
return true;
}
bool dp_buffer_append_printf_test()
{
dp_buffer *buf = dp_buffer_new(0);
if (dp_buffer_printf(buf, "%d int, %s string", 2, "foo") == NULL)
return false;
if (dp_buffer_append_printf(buf, "%d int, %s string", 2, "foo") == NULL)
return false;
if(strcmp(buf->str, "2 int, foo string2 int, foo string"))
return false;
dp_buffer_free(buf);
return true;
}