This source file includes following definitions.
- null_args
- no_source_attrs
- copy_one
- copy_multiple
- overwrite
- no_overwrite
- score_update
- no_score_update
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 static void
17 null_args(void **state)
18 {
19
20 xmlNode *xml = pcmk__xe_create(NULL, "test");
21
22 assert_int_equal(pcmk__xe_copy_attrs(NULL, NULL, pcmk__xaf_none), EINVAL);
23 assert_int_equal(pcmk__xe_copy_attrs(NULL, xml, pcmk__xaf_none), EINVAL);
24 assert_int_equal(pcmk__xe_copy_attrs(xml, NULL, pcmk__xaf_none), EINVAL);
25 assert_ptr_equal(xml->properties, NULL);
26
27 free_xml(xml);
28 }
29
30 static void
31 no_source_attrs(void **state)
32 {
33 xmlNode *src = pcmk__xe_create(NULL, "test");
34 xmlNode *target = pcmk__xe_create(NULL, "test");
35
36
37 assert_int_equal(pcmk__xe_copy_attrs(target, src, pcmk__xaf_none),
38 pcmk_rc_ok);
39 assert_ptr_equal(target->properties, NULL);
40
41
42 crm_xml_add(target, "attr", "value");
43 assert_int_equal(pcmk__xe_copy_attrs(target, src, pcmk__xaf_none),
44 pcmk_rc_ok);
45 assert_string_equal(crm_element_value(target, "attr"), "value");
46
47 free_xml(src);
48 free_xml(target);
49 }
50
51 static void
52 copy_one(void **state)
53 {
54 xmlNode *src = pcmk__xe_create(NULL, "test");
55 xmlNode *target = pcmk__xe_create(NULL, "test");
56
57 crm_xml_add(src, "attr", "value");
58
59 assert_int_equal(pcmk__xe_copy_attrs(target, src, pcmk__xaf_none),
60 pcmk_rc_ok);
61 assert_string_equal(crm_element_value(src, "attr"),
62 crm_element_value(target, "attr"));
63
64 free_xml(src);
65 free_xml(target);
66 }
67
68 static void
69 copy_multiple(void **state)
70 {
71 xmlNode *src = pcmk__xe_create(NULL, "test");
72 xmlNode *target = pcmk__xe_create(NULL, "test");
73
74 pcmk__xe_set_props(src,
75 "attr1", "value1",
76 "attr2", "value2",
77 "attr3", "value3",
78 NULL);
79
80 assert_int_equal(pcmk__xe_copy_attrs(target, src, pcmk__xaf_none),
81 pcmk_rc_ok);
82 assert_string_equal(crm_element_value(src, "attr1"),
83 crm_element_value(target, "attr1"));
84 assert_string_equal(crm_element_value(src, "attr2"),
85 crm_element_value(target, "attr2"));
86 assert_string_equal(crm_element_value(src, "attr3"),
87 crm_element_value(target, "attr3"));
88
89 free_xml(src);
90 free_xml(target);
91 }
92
93 static void
94 overwrite(void **state)
95 {
96 xmlNode *src = pcmk__xe_create(NULL, "test");
97 xmlNode *target = pcmk__xe_create(NULL, "test");
98
99 crm_xml_add(src, "attr", "src_value");
100 crm_xml_add(target, "attr", "target_value");
101
102
103 assert_int_equal(pcmk__xe_copy_attrs(target, src, pcmk__xaf_none),
104 pcmk_rc_ok);
105 assert_string_equal(crm_element_value(src, "attr"),
106 crm_element_value(target, "attr"));
107 free_xml(src);
108 free_xml(target);
109 }
110
111 static void
112 no_overwrite(void **state)
113 {
114 xmlNode *src = pcmk__xe_create(NULL, "test");
115 xmlNode *target = pcmk__xe_create(NULL, "test");
116
117 crm_xml_add(src, "attr", "src_value");
118 crm_xml_add(target, "attr", "target_value");
119
120 assert_int_equal(pcmk__xe_copy_attrs(target, src, pcmk__xaf_no_overwrite),
121 pcmk_rc_ok);
122 assert_string_not_equal(crm_element_value(src, "attr"),
123 crm_element_value(target, "attr"));
124
125
126 pcmk__xe_remove_attr(target, "attr");
127
128 assert_int_equal(pcmk__xe_copy_attrs(target, src, pcmk__xaf_no_overwrite),
129 pcmk_rc_ok);
130 assert_string_equal(crm_element_value(src, "attr"),
131 crm_element_value(target, "attr"));
132
133 free_xml(src);
134 free_xml(target);
135 }
136
137 static void
138 score_update(void **state)
139 {
140 xmlNode *src = pcmk__xe_create(NULL, "test");
141 xmlNode *target = pcmk__xe_create(NULL, "test");
142
143 crm_xml_add(src, "plus_plus_attr", "plus_plus_attr++");
144 crm_xml_add(src, "plus_two_attr", "plus_two_attr+=2");
145 crm_xml_add(target, "plus_plus_attr", "1");
146 crm_xml_add(target, "plus_two_attr", "1");
147
148 assert_int_equal(pcmk__xe_copy_attrs(target, src, pcmk__xaf_score_update),
149 pcmk_rc_ok);
150 assert_string_equal(crm_element_value(target, "plus_plus_attr"), "2");
151 assert_string_equal(crm_element_value(target, "plus_two_attr"), "3");
152
153 free_xml(src);
154 free_xml(target);
155 }
156
157 static void
158 no_score_update(void **state)
159 {
160 xmlNode *src = pcmk__xe_create(NULL, "test");
161 xmlNode *target = pcmk__xe_create(NULL, "test");
162
163 crm_xml_add(src, "plus_plus_attr", "plus_plus_attr++");
164 crm_xml_add(src, "plus_two_attr", "plus_two_attr+=2");
165 crm_xml_add(target, "plus_plus_attr", "1");
166 crm_xml_add(target, "plus_two_attr", "1");
167
168
169 assert_int_equal(pcmk__xe_copy_attrs(target, src, pcmk__xaf_none),
170 pcmk_rc_ok);
171 assert_string_equal(crm_element_value(target, "plus_plus_attr"),
172 "plus_plus_attr++");
173 assert_string_equal(crm_element_value(target, "plus_two_attr"),
174 "plus_two_attr+=2");
175
176 free_xml(src);
177 free_xml(target);
178 }
179
180 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, pcmk__xml_test_teardown_group,
181 cmocka_unit_test(null_args),
182 cmocka_unit_test(no_source_attrs),
183 cmocka_unit_test(copy_one),
184 cmocka_unit_test(copy_multiple),
185 cmocka_unit_test(overwrite),
186 cmocka_unit_test(no_overwrite),
187 cmocka_unit_test(score_update),
188 cmocka_unit_test(no_score_update));