This source file includes following definitions.
- setup_test
- teardown_test
- bad_arguments
- unknown_ticket
- verify_results
- attribute_exists
- default_no_ticket
- default_no_attribute
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/cib/internal.h>
13 #include <crm/common/unittest_internal.h>
14 #include <crm/common/xml.h>
15 #include <pacemaker.h>
16
17 static char *cib_path = NULL;
18
19 static int
20 setup_test(void **state)
21 {
22 cib_path = pcmk__cib_test_copy_cib("tickets.xml");
23
24 if (cib_path == NULL) {
25 return -1;
26 }
27
28 return 0;
29 }
30
31 static int
32 teardown_test(void **state)
33 {
34 pcmk__cib_test_cleanup(cib_path);
35 cib_path = NULL;
36 return 0;
37 }
38
39 static void
40 bad_arguments(void **state)
41 {
42 xmlNode *xml = NULL;
43
44 assert_int_equal(pcmk_ticket_get_attr(NULL, "ticketA", "XYZ", NULL), EINVAL);
45
46 assert_int_equal(pcmk_ticket_get_attr(&xml, NULL, "attrA", NULL), EINVAL);
47 pcmk__assert_validates(xml);
48 free_xml(xml);
49 xml = NULL;
50
51 assert_int_equal(pcmk_ticket_get_attr(&xml, "ticketA", NULL, NULL), EINVAL);
52 pcmk__assert_validates(xml);
53 free_xml(xml);
54 }
55
56 static void
57 unknown_ticket(void **state)
58 {
59 xmlNode *xml = NULL;
60
61
62
63
64
65 assert_int_equal(pcmk_ticket_get_attr(&xml, "XYZ", "attrA", NULL), ENXIO);
66 pcmk__assert_validates(xml);
67 free_xml(xml);
68 xml = NULL;
69
70 assert_int_equal(pcmk_ticket_get_attr(&xml, "ticketA", "XYZ", NULL), ENXIO);
71 pcmk__assert_validates(xml);
72 free_xml(xml);
73 }
74
75 static void
76 verify_results(xmlNode *xml, const char *ticket_id, const char *attr_name,
77 const char *attr_value)
78 {
79 xmlNode *node = NULL;
80 xmlXPathObject *xpath_obj = NULL;
81
82
83
84
85 xpath_obj = xpath_search(xml, "//" PCMK_XE_PACEMAKER_RESULT "/" PCMK_XE_TICKETS "/" PCMK_XE_TICKET);
86 assert_int_equal(numXpathResults(xpath_obj), 1);
87
88 node = getXpathResult(xpath_obj, 0);
89 assert_string_equal(crm_element_value(node, PCMK_XA_ID), ticket_id);
90 freeXpathObject(xpath_obj);
91
92
93
94
95 xpath_obj = xpath_search(xml, "//" PCMK_XE_PACEMAKER_RESULT "/" PCMK_XE_TICKETS "/" PCMK_XE_TICKET
96 "/" PCMK_XE_ATTRIBUTE);
97 assert_int_equal(numXpathResults(xpath_obj), 1);
98
99 node = getXpathResult(xpath_obj, 0);
100 assert_string_equal(crm_element_value(node, PCMK_XA_NAME), attr_name);
101 assert_string_equal(crm_element_value(node, PCMK_XA_VALUE), attr_value);
102
103 freeXpathObject(xpath_obj);
104 }
105
106 static void
107 attribute_exists(void **state)
108 {
109 xmlNode *xml = NULL;
110
111 assert_int_equal(pcmk_ticket_get_attr(&xml, "ticketA", "owner", NULL), pcmk_rc_ok);
112 pcmk__assert_validates(xml);
113
114 verify_results(xml, "ticketA", "owner", "1");
115
116 free_xml(xml);
117 }
118
119 static void
120 default_no_ticket(void **state)
121 {
122 xmlNode *xml = NULL;
123
124 assert_int_equal(pcmk_ticket_get_attr(&xml, "ticketX", "ABC", "DEFAULT"), pcmk_rc_ok);
125 pcmk__assert_validates(xml);
126
127 verify_results(xml, "ticketX", "ABC", "DEFAULT");
128
129 free_xml(xml);
130 }
131
132 static void
133 default_no_attribute(void **state)
134 {
135 xmlNode *xml = NULL;
136
137 assert_int_equal(pcmk_ticket_get_attr(&xml, "ticketA", "ABC", "DEFAULT"), pcmk_rc_ok);
138 pcmk__assert_validates(xml);
139
140 verify_results(xml, "ticketA", "ABC", "DEFAULT");
141
142 free_xml(xml);
143 }
144
145 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, pcmk__xml_test_teardown_group,
146 cmocka_unit_test_setup_teardown(bad_arguments, setup_test, teardown_test),
147 cmocka_unit_test_setup_teardown(unknown_ticket, setup_test, teardown_test),
148 cmocka_unit_test_setup_teardown(attribute_exists, setup_test, teardown_test),
149 cmocka_unit_test_setup_teardown(default_no_ticket, setup_test, teardown_test),
150 cmocka_unit_test_setup_teardown(default_no_attribute, setup_test, teardown_test))