This source file includes following definitions.
- bad_input
- expected_input
- repeated_use
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/xml.h>
13 #include <crm/common/unittest_internal.h>
14 #include <crm/common/xml_internal.h>
15
16 static void
17 bad_input(void **state) {
18 xmlNode *node = NULL;
19
20 pcmk__assert_asserts(pcmk__xe_add_node(NULL, NULL, 0));
21
22 node = pcmk__xe_create(NULL, "test");
23
24 pcmk__xe_add_node(node, NULL, 0);
25 assert_null(xmlHasProp(node, (pcmkXmlStr) PCMK__XA_ATTR_HOST));
26 assert_null(xmlHasProp(node, (pcmkXmlStr) PCMK__XA_ATTR_HOST_ID));
27
28 pcmk__xe_add_node(node, NULL, -100);
29 assert_null(xmlHasProp(node, (pcmkXmlStr) PCMK__XA_ATTR_HOST));
30 assert_null(xmlHasProp(node, (pcmkXmlStr) PCMK__XA_ATTR_HOST_ID));
31
32 free_xml(node);
33 }
34
35 static void
36 expected_input(void **state) {
37 xmlNode *node = pcmk__xe_create(NULL, "test");
38 int i;
39
40 pcmk__xe_add_node(node, "somenode", 47);
41 assert_string_equal("somenode",
42 crm_element_value(node, PCMK__XA_ATTR_HOST));
43 assert_int_equal(pcmk_rc_ok,
44 crm_element_value_int(node, PCMK__XA_ATTR_HOST_ID, &i));
45 assert_int_equal(i, 47);
46
47 free_xml(node);
48 }
49
50 static void
51 repeated_use(void **state) {
52 xmlNode *node = pcmk__xe_create(NULL, "test");
53 int i;
54
55
56 pcmk__xe_add_node(node, "nodeA", 1);
57 pcmk__xe_add_node(node, "nodeB", 2);
58 pcmk__xe_add_node(node, "nodeC", 3);
59
60 assert_string_equal("nodeC", crm_element_value(node, PCMK__XA_ATTR_HOST));
61 assert_int_equal(pcmk_rc_ok,
62 crm_element_value_int(node, PCMK__XA_ATTR_HOST_ID, &i));
63 assert_int_equal(i, 3);
64
65 free_xml(node);
66 }
67
68 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, pcmk__xml_test_teardown_group,
69 cmocka_unit_test(bad_input),
70 cmocka_unit_test(expected_input),
71 cmocka_unit_test(repeated_use))