-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger_test.c
52 lines (45 loc) · 1.3 KB
/
logger_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
#include "src/logger.c"
#include <stdio.h>
#include <stdlib.h>
void map_from_level_test(void) {
struct {
char name[100];
struct {
const int level;
} parameters;
enum log_level expected;
} tests[] = {
{.name = "Success map to ERROR",
.parameters = {.level = 0},
.expected = ERROR_LEVEL},
{.name = "Success map to WARN",
.parameters = {.level = 1},
.expected = WARN_LEVEL},
{.name = "Success map to INFO",
.parameters = {.level = 2},
.expected = INFO_LEVEL},
{.name = "Success map to DEBUG",
.parameters = {.level = 3},
.expected = DEBUG_LEVEL},
{.name = "Success default to DEBUG",
.parameters = {.level = 69},
.expected = DEBUG_LEVEL},
};
size_t length = sizeof(tests) / sizeof(tests[0]);
printf("Running map_from_level_test\n");
for (size_t idx = 0; idx < length; idx++) {
printf(" %s: \t", tests[idx].name);
enum log_level result = map_from_level(tests[idx].parameters.level);
if (tests[idx].expected == result) {
printf("Success\n");
} else {
printf("Failed\n");
fprintf(stderr, "Failed on %s:\n\tExpecting: %d\n\tGot: %d\n",
tests[idx].name, tests[idx].expected, result);
}
}
}
int main(void) {
map_from_level_test();
return 0;
}