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"), -CRM_SCORE_INFINITY);
36 assert_int_equal(char2score("INFINITY"), CRM_SCORE_INFINITY);
37 assert_int_equal(char2score("+INFINITY"), CRM_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(CRM_SCORE_INFINITY) "00"), CRM_SCORE_INFINITY);
60 assert_int_equal(char2score("-" B(CRM_SCORE_INFINITY) "00"), -CRM_SCORE_INFINITY);
61 }
62
63 static void
64 inside_limits(void **state)
65 {
66 assert_int_equal(char2score("1234"), 1234);
67 assert_int_equal(char2score("-1234"), -1234);
68 }
69
70 PCMK__UNIT_TEST(NULL, NULL,
71 cmocka_unit_test(empty_input),
72 cmocka_unit_test(bad_input),
73 cmocka_unit_test(special_values),
74 cmocka_unit_test(outside_limits),
75 cmocka_unit_test(inside_limits))