-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgentest_test.c
121 lines (111 loc) · 4.55 KB
/
cgentest_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#define free_metadata mock_free_metadata
#define free_metadata_list mock_free_metadata_list
#include "helper.c"
#include "src/cgentest.c"
#include <stdio.h>
#include <stdlib.h>
void mock_free_metadata(struct metadata *metadata) {}
void mock_free_metadata_list(struct metadata_list *list, bool free_member) {}
void filter_test(void) {
struct {
char name[100];
struct {
struct metadata_list *source;
struct metadata_list *target;
} parameters;
struct metadata_list *expected;
} tests[] = {
{.name = "Success on empty both list",
.parameters = {.source =
&(struct metadata_list){.count = 0, .list = NULL},
.target =
&(struct metadata_list){.count = 0, .list = NULL}},
.expected = &(struct metadata_list){.count = 0, .list = NULL}},
{.name = "Success on empty target list",
.parameters =
{.source =
&(struct metadata_list){
.count = 1,
.list =
(struct metadata[]){
{.name = "first", .return_type = {.name = ""}},
}},
.target = &(struct metadata_list){.count = 0, .list = NULL}},
.expected =
&(struct metadata_list){
.count = 1,
.list =
(struct metadata[]){
{.name = "first", .return_type = {.name = ""}},
}}},
{.name = "Success on found item",
.parameters =
{.source =
&(struct metadata_list){.count = 2,
.list =
(struct metadata[]){
{.name = "first",
.return_type = {.name = ""}},
{.name = "second",
.return_type = {.name = ""}},
}},
.target =
&(struct metadata_list){
.count = 1,
.list = (struct metadata[]){{.name = "first_test"}}}},
.expected =
&(struct metadata_list){.count = 1,
.list =
(struct metadata[]){
{.name = "second",
.return_type = {.name = ""}},
}}},
{.name = "Success on not found item",
.parameters =
{.source =
&(struct metadata_list){.count = 2,
.list =
(struct metadata[]){
{.name = "first",
.return_type = {.name = ""}},
{.name = "second",
.return_type = {.name = ""}},
}},
.target =
&(struct metadata_list){
.count = 1,
.list = (struct metadata[]){{.name = "third_test"}}}},
.expected =
&(struct metadata_list){.count = 2,
.list =
(struct metadata[]){
{.name = "first",
.return_type = {.name = ""}},
{.name = "second",
.return_type = {.name = ""}},
}}},
};
size_t length = sizeof(tests) / sizeof(tests[0]);
printf("Running filter_test\n");
for (size_t idx = 0; idx < length; idx++) {
printf(" %s: \t", tests[idx].name);
struct metadata_list *result =
filter(tests[idx].parameters.source, tests[idx].parameters.target);
if (metadatalistiseq(tests[idx].expected, result)) {
printf("Success\n");
} else {
printf("Failed\n");
fprintf(stderr, "Failed on %s:\n", tests[idx].name);
char *expectedstr = metadatalistfmt(tests[idx].expected);
fprintf(stderr, "\tExpecting: \n%s\n", expectedstr);
free(expectedstr);
char *gotstr = metadatalistfmt(result);
fprintf(stderr, "\tGot: \n%s\n", gotstr);
free(gotstr);
}
}
}
int main(void) {
filter_test();
return 0;
}