This source file includes following definitions.
- assert_set_score
- value_is_name_plus_plus
- value_is_name_plus_equals_integer
- target_is_NULL
- name_is_NULL
- value_is_NULL
- value_is_wrong_name
- value_is_only_an_integer
- variable_is_initialized_to_be_non_numeric
- variable_is_initialized_to_be_non_numeric_2
- variable_is_initialized_to_be_numeric_and_decimal_point_containing
- variable_is_initialized_to_be_numeric_and_decimal_point_containing_2
- variable_is_initialized_to_be_numeric_and_decimal_point_containing_3
- value_is_non_numeric
- value_is_numeric_and_decimal_point_containing
- value_is_numeric_and_decimal_point_containing_2
- value_is_numeric_and_decimal_point_containing_3
- name_is_undefined
- assignment_result_is_too_large
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
13
14 #include <glib.h>
15
16 #include "crmcommon_private.h"
17
18
19
20
21
22
23
24
25
26
27
28
29 static void
30 assert_set_score(const char *initial, const char *new,
31 const char *reference_val, int reference_rc)
32 {
33 const char *name = "X";
34 xmlNode *test_xml = pcmk__xe_create(NULL, "test_xml");
35
36 crm_xml_add(test_xml, name, initial);
37 assert_int_equal(pcmk__xe_set_score(test_xml, name, new), reference_rc);
38 assert_string_equal(crm_element_value(test_xml, name), reference_val);
39
40 free_xml(test_xml);
41 }
42
43 static void
44 value_is_name_plus_plus(void **state)
45 {
46 assert_set_score("5", "X++", "6", pcmk_rc_ok);
47 }
48
49 static void
50 value_is_name_plus_equals_integer(void **state)
51 {
52 assert_set_score("5", "X+=2", "7", pcmk_rc_ok);
53 }
54
55
56
57 static void
58 target_is_NULL(void **state)
59 {
60
61 assert_int_equal(pcmk__xe_set_score(NULL, "X", "X++"), EINVAL);
62 }
63
64 static void
65 name_is_NULL(void **state)
66 {
67 xmlNode *test_xml = pcmk__xe_create(NULL, "test_xml");
68
69 crm_xml_add(test_xml, "X", "5");
70
71
72 assert_int_equal(pcmk__xe_set_score(test_xml, NULL, "X++"), EINVAL);
73 assert_string_equal(crm_element_value(test_xml, "X"), "5");
74
75 free_xml(test_xml);
76 }
77
78 static void
79 value_is_NULL(void **state)
80 {
81 assert_set_score("5", NULL, "5", pcmk_rc_ok);
82 }
83
84
85
86 static void
87 value_is_wrong_name(void **state)
88 {
89 assert_set_score("5", "Y++", "Y++", pcmk_rc_ok);
90 }
91
92 static void
93 value_is_only_an_integer(void **state)
94 {
95 assert_set_score("5", "2", "2", pcmk_rc_ok);
96 }
97
98
99
100 static void
101 variable_is_initialized_to_be_non_numeric(void **state)
102 {
103 assert_set_score("hello", "X++", "1", pcmk_rc_ok);
104 }
105
106 static void
107 variable_is_initialized_to_be_non_numeric_2(void **state)
108 {
109 assert_set_score("hello", "X+=2", "2", pcmk_rc_ok);
110 }
111
112 static void
113 variable_is_initialized_to_be_numeric_and_decimal_point_containing(void **state)
114 {
115 assert_set_score("5.01", "X++", "6", pcmk_rc_ok);
116 }
117
118 static void
119 variable_is_initialized_to_be_numeric_and_decimal_point_containing_2(void **state)
120 {
121 assert_set_score("5.50", "X++", "6", pcmk_rc_ok);
122 }
123
124 static void
125 variable_is_initialized_to_be_numeric_and_decimal_point_containing_3(void **state)
126 {
127 assert_set_score("5.99", "X++", "6", pcmk_rc_ok);
128 }
129
130 static void
131 value_is_non_numeric(void **state)
132 {
133 assert_set_score("5", "X+=hello", "5", pcmk_rc_ok);
134 }
135
136 static void
137 value_is_numeric_and_decimal_point_containing(void **state)
138 {
139 assert_set_score("5", "X+=2.01", "7", pcmk_rc_ok);
140 }
141
142 static void
143 value_is_numeric_and_decimal_point_containing_2(void **state)
144 {
145 assert_set_score("5", "X+=1.50", "6", pcmk_rc_ok);
146 }
147
148 static void
149 value_is_numeric_and_decimal_point_containing_3(void **state)
150 {
151 assert_set_score("5", "X+=1.99", "6", pcmk_rc_ok);
152 }
153
154
155
156 static void
157 name_is_undefined(void **state)
158 {
159 assert_set_score(NULL, "X++", "X++", pcmk_rc_ok);
160 }
161
162
163
164 static void
165 assignment_result_is_too_large(void **state)
166 {
167 assert_set_score("5", "X+=100000000000", "1000000", pcmk_rc_ok);
168 }
169
170 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, NULL,
171 cmocka_unit_test(value_is_name_plus_plus),
172 cmocka_unit_test(value_is_name_plus_equals_integer),
173 cmocka_unit_test(target_is_NULL),
174 cmocka_unit_test(name_is_NULL),
175 cmocka_unit_test(value_is_NULL),
176 cmocka_unit_test(value_is_wrong_name),
177 cmocka_unit_test(value_is_only_an_integer),
178 cmocka_unit_test(variable_is_initialized_to_be_non_numeric),
179 cmocka_unit_test(variable_is_initialized_to_be_non_numeric_2),
180 cmocka_unit_test(variable_is_initialized_to_be_numeric_and_decimal_point_containing),
181 cmocka_unit_test(variable_is_initialized_to_be_numeric_and_decimal_point_containing_2),
182 cmocka_unit_test(variable_is_initialized_to_be_numeric_and_decimal_point_containing_3),
183 cmocka_unit_test(value_is_non_numeric),
184 cmocka_unit_test(value_is_numeric_and_decimal_point_containing),
185 cmocka_unit_test(value_is_numeric_and_decimal_point_containing_2),
186 cmocka_unit_test(value_is_numeric_and_decimal_point_containing_3),
187 cmocka_unit_test(name_is_undefined),
188 cmocka_unit_test(assignment_result_is_too_large))