c-template
colors_test.c
Go to the documentation of this file.
1
#include <stdio.h>
2
#include <stdbool.h>
3
#include <stdlib.h>
4
#include <stdarg.h>
5
#include <stddef.h>
6
#include <setjmp.h>
7
#include <cmocka.h>
8
#include <assert.h>
9
#include <string.h>
10
#include "../../include/utils/colors.h"
11
12
typedef
struct
args
{
13
COLORS
test_color
;
14
char
*
want_ansi
;
15
}
args
;
16
typedef
struct
test
{
17
args
args
;
18
char
*
name
;
19
}
test
;
20
21
void
test_print_color
(
void
**state);
22
void
test_get_ansi_color_scheme
(
void
**state);
23
void
validate_test_args
(
test
testdata);
24
// TODO(bonedaddy): test format_colored
25
26
void
validate_test_args
(
test
testdata) {
27
// printf("%s\n", format_colored(testdata.args.test_color, testdata.name));
28
char
*scheme =
get_ansi_color_scheme
(testdata.
args
.
test_color
);
29
if
(strcmp(scheme, testdata.
args
.
want_ansi
) == 0) {
30
31
printf(
"%stest %s passed\n"
, scheme, testdata.
name
);
32
return
;
33
}
34
printf(
"test %s failed\n"
, testdata.
name
);
35
}
36
37
#pragma GCC diagnostic ignored "-Wunused-parameter"
38
void
test_get_ansi_color_scheme
(
void
**state) {
39
40
test
tests[8] = {
41
{
42
.
name
=
"red"
,
43
.args = {
44
.test_color =
COLORS_RED
,
45
.want_ansi =
ANSI_COLOR_RED
,
46
},
47
},
48
{
49
.name =
"soft_red"
,
50
.args = {
51
.test_color =
COLORS_SOFT_RED
,
52
.want_ansi =
ANSI_COLOR_SOFT_RED
,
53
},
54
},
55
{
56
.name =
"green"
,
57
.args = {
58
.test_color =
COLORS_GREEN
,
59
.want_ansi =
ANSI_COLOR_GREEN
,
60
},
61
},
62
{
63
.name =
"yellow"
,
64
.args = {
65
.test_color =
COLORS_YELLOW
,
66
.want_ansi =
ANSI_COLOR_YELLOW
,
67
},
68
},
69
{
70
.name =
"blue"
,
71
.args = {
72
.test_color =
COLORS_BLUE
,
73
.want_ansi =
ANSI_COLOR_BLUE
,
74
},
75
},
76
{
77
.name =
"magenta"
,
78
.args = {
79
.test_color =
COLORS_MAGENTA
,
80
.want_ansi =
ANSI_COLOR_MAGENTA
,
81
},
82
},
83
{
84
.name =
"cyan"
,
85
.args = {
86
.test_color =
COLORS_CYAN
,
87
.want_ansi =
ANSI_COLOR_CYAN
,
88
},
89
},
90
{
91
.name =
"reset"
,
92
.args = {
93
.test_color =
COLORS_RESET
,
94
.want_ansi =
ANSI_COLOR_RESET
,
95
},
96
},
97
};
98
for
(
int
i = 0; i < 7; i++) {
99
validate_test_args
(tests[i]);
100
}
101
}
102
103
int
main
(
void
) {
104
const
struct
CMUnitTest tests[] = {
105
cmocka_unit_test(
test_get_ansi_color_scheme
),
106
};
107
return
cmocka_run_group_tests(tests, NULL, NULL);
108
}
validate_test_args
void validate_test_args(test testdata)
Definition:
colors_test.c:26
COLORS_CYAN
@ COLORS_CYAN
Definition:
colors.h:26
COLORS_RED
@ COLORS_RED
Definition:
colors.h:26
COLORS
COLORS
allows short-handed references to ANSI color schemes, and enables easier color selection anytime you ...
Definition:
colors.h:25
test
Definition:
colors_test.c:16
test_print_color
void test_print_color(void **state)
COLORS_MAGENTA
@ COLORS_MAGENTA
Definition:
colors.h:26
test
struct test test
COLORS_GREEN
@ COLORS_GREEN
Definition:
colors.h:26
ANSI_COLOR_RESET
#define ANSI_COLOR_RESET
Definition:
colors.h:20
ANSI_COLOR_YELLOW
#define ANSI_COLOR_YELLOW
Definition:
colors.h:16
COLORS_SOFT_RED
@ COLORS_SOFT_RED
Definition:
colors.h:26
args
Definition:
colors_test.c:12
args::test_color
COLORS test_color
Definition:
colors_test.c:13
args::want_ansi
char * want_ansi
Definition:
colors_test.c:14
test::args
args args
Definition:
colors_test.c:17
args
struct args args
COLORS_RESET
@ COLORS_RESET
Definition:
colors.h:26
COLORS_BLUE
@ COLORS_BLUE
Definition:
colors.h:26
COLORS_YELLOW
@ COLORS_YELLOW
Definition:
colors.h:26
get_ansi_color_scheme
char * get_ansi_color_scheme(COLORS color)
returns an ansi color string to be used with printf
Definition:
colors.c:8
ANSI_COLOR_RED
#define ANSI_COLOR_RED
Definition:
colors.h:13
test::name
char * name
Definition:
colors_test.c:18
ANSI_COLOR_CYAN
#define ANSI_COLOR_CYAN
Definition:
colors.h:19
main
int main(void)
Definition:
colors_test.c:103
ANSI_COLOR_MAGENTA
#define ANSI_COLOR_MAGENTA
Definition:
colors.h:18
ANSI_COLOR_SOFT_RED
#define ANSI_COLOR_SOFT_RED
Definition:
colors.h:14
ANSI_COLOR_BLUE
#define ANSI_COLOR_BLUE
Definition:
colors.h:17
ANSI_COLOR_GREEN
#define ANSI_COLOR_GREEN
Definition:
colors.h:15
test_get_ansi_color_scheme
void test_get_ansi_color_scheme(void **state)
Definition:
colors_test.c:38
src
utils
colors_test.c
Generated by
1.8.17