This source file includes following definitions.
- empty_input
- bad_input
- special_values
- outside_limits
- inside_limits
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
13
14 extern int pcmk__score_red;
15 extern int pcmk__score_green;
16 extern int pcmk__score_yellow;
17
18 static void
19 empty_input(void **state)
20 {
21 assert_int_equal(char2score(NULL), 0);
22 }
23
24 static void
25 bad_input(void **state)
26 {
27 assert_int_equal(char2score("PQRST"), 0);
28 assert_int_equal(char2score("3.141592"), 3);
29 assert_int_equal(char2score("0xf00d"), 0);
30 }
31
32 static void
33 special_values(void **state)
34 {
35 assert_int_equal(char2score("-INFINITY"), -PCMK_SCORE_INFINITY);
36 assert_int_equal(char2score("INFINITY"), PCMK_SCORE_INFINITY);
37 assert_int_equal(char2score("+INFINITY"), PCMK_SCORE_INFINITY);
38
39 pcmk__score_red = 10;
40 pcmk__score_green = 20;
41 pcmk__score_yellow = 30;
42
43 assert_int_equal(char2score("red"), pcmk__score_red);
44 assert_int_equal(char2score("green"), pcmk__score_green);
45 assert_int_equal(char2score("yellow"), pcmk__score_yellow);
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
52
53 #define A(x) #x
54 #define B(x) A(x)
55
56 static void
57 outside_limits(void **state)
58 {
59 assert_int_equal(char2score(B(PCMK_SCORE_INFINITY) "00"),
60 PCMK_SCORE_INFINITY);
61 assert_int_equal(char2score("-" B(PCMK_SCORE_INFINITY) "00"),
62 -PCMK_SCORE_INFINITY);
63 }
64
65 static void
66 inside_limits(void **state)
67 {
68 assert_int_equal(char2score("1234"), 1234);
69 assert_int_equal(char2score("-1234"), -1234);
70 }
71
72 PCMK__UNIT_TEST(NULL, NULL,
73 cmocka_unit_test(empty_input),
74 cmocka_unit_test(bad_input),
75 cmocka_unit_test(special_values),
76 cmocka_unit_test(outside_limits),
77 cmocka_unit_test(inside_limits))