This source file includes following definitions.
- empty_input
- bad_input
- special_values
- outside_limits
- inside_limits
- main
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdarg.h>
13 #include <stddef.h>
14 #include <stdint.h>
15 #include <setjmp.h>
16 #include <cmocka.h>
17
18 extern int pcmk__score_red;
19 extern int pcmk__score_green;
20 extern int pcmk__score_yellow;
21
22 static void
23 empty_input(void **state)
24 {
25 assert_int_equal(char2score(NULL), 0);
26 }
27
28 static void
29 bad_input(void **state)
30 {
31 assert_int_equal(char2score("PQRST"), 0);
32 assert_int_equal(char2score("3.141592"), 3);
33 assert_int_equal(char2score("0xf00d"), 0);
34 }
35
36 static void
37 special_values(void **state)
38 {
39 assert_int_equal(char2score("-INFINITY"), -CRM_SCORE_INFINITY);
40 assert_int_equal(char2score("INFINITY"), CRM_SCORE_INFINITY);
41 assert_int_equal(char2score("+INFINITY"), CRM_SCORE_INFINITY);
42
43 pcmk__score_red = 10;
44 pcmk__score_green = 20;
45 pcmk__score_yellow = 30;
46
47 assert_int_equal(char2score("red"), pcmk__score_red);
48 assert_int_equal(char2score("green"), pcmk__score_green);
49 assert_int_equal(char2score("yellow"), pcmk__score_yellow);
50
51 assert_int_equal(char2score("ReD"), pcmk__score_red);
52 assert_int_equal(char2score("GrEeN"), pcmk__score_green);
53 assert_int_equal(char2score("yElLoW"), pcmk__score_yellow);
54 }
55
56
57 #define A(x) #x
58 #define B(x) A(x)
59
60 static void
61 outside_limits(void **state)
62 {
63 assert_int_equal(char2score(B(CRM_SCORE_INFINITY) "00"), CRM_SCORE_INFINITY);
64 assert_int_equal(char2score("-" B(CRM_SCORE_INFINITY) "00"), -CRM_SCORE_INFINITY);
65 }
66
67 static void
68 inside_limits(void **state)
69 {
70 assert_int_equal(char2score("1234"), 1234);
71 assert_int_equal(char2score("-1234"), -1234);
72 }
73
74 int main(int argc, char **argv)
75 {
76 const struct CMUnitTest tests[] = {
77 cmocka_unit_test(empty_input),
78 cmocka_unit_test(bad_input),
79 cmocka_unit_test(special_values),
80 cmocka_unit_test(outside_limits),
81 cmocka_unit_test(inside_limits),
82 };
83
84 cmocka_set_message_output(CM_OUTPUT_TAP);
85 return cmocka_run_group_tests(tests, NULL, NULL);
86 }