This source file includes following definitions.
- cib_not_connected
- setup_test
- teardown_test
- bad_arguments
- unknown_ticket
- ticket_exists
- multiple_tickets
- duplicate_tickets
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 #include <pacemaker-internal.h>
18
19 static char *cib_path = NULL;
20
21 static void
22 cib_not_connected(void **state)
23 {
24 xmlNode *xml = NULL;
25 cib_t *cib = cib_new();
26
27
28
29
30
31 assert_int_equal(pcmk__get_ticket_state(cib, "ticketA", &xml), ENOTCONN);
32 cib__clean_up_connection(&cib);
33 }
34
35 static int
36 setup_test(void **state)
37 {
38 cib_path = pcmk__cib_test_copy_cib("tickets.xml");
39
40 if (cib_path == NULL) {
41 return -1;
42 }
43
44 return 0;
45 }
46
47 static int
48 teardown_test(void **state)
49 {
50 pcmk__cib_test_cleanup(cib_path);
51 cib_path = NULL;
52 return 0;
53 }
54
55 static void
56 bad_arguments(void **state)
57 {
58 xmlNode *xml = NULL;
59 cib_t *cib = cib_new();
60
61 cib->cmds->signon(cib, crm_system_name, cib_command);
62
63 pcmk__assert_asserts(pcmk__get_ticket_state(NULL, "ticketA", &xml));
64 pcmk__assert_asserts(pcmk__get_ticket_state(cib, "ticketA", NULL));
65
66 cib__clean_up_connection(&cib);
67 }
68
69 static void
70 unknown_ticket(void **state)
71 {
72 xmlNode *xml = NULL;
73 cib_t *cib = cib_new();
74
75 cib->cmds->signon(cib, crm_system_name, cib_command);
76
77 assert_int_equal(pcmk__get_ticket_state(cib, "XYZ", &xml), ENXIO);
78
79 free_xml(xml);
80 cib__clean_up_connection(&cib);
81 }
82
83 static void
84 ticket_exists(void **state)
85 {
86 xmlNode *xml = NULL;
87 xmlXPathObject *xpath_obj = NULL;
88 cib_t *cib = cib_new();
89
90 cib->cmds->signon(cib, crm_system_name, cib_command);
91
92 assert_int_equal(pcmk__get_ticket_state(cib, "ticketA", &xml), pcmk_rc_ok);
93
94
95
96
97 xpath_obj = xpath_search(xml, "//" PCMK__XE_TICKET_STATE "[@" PCMK_XA_ID "=\"ticketA\"]");
98 assert_int_equal(numXpathResults(xpath_obj), 1);
99
100 freeXpathObject(xpath_obj);
101 free_xml(xml);
102 cib__clean_up_connection(&cib);
103 }
104
105 static void
106 multiple_tickets(void **state)
107 {
108 xmlNode *xml = NULL;
109 xmlNode *ticket_node = NULL;
110 xmlXPathObject *xpath_obj = NULL;
111 cib_t *cib = cib_new();
112
113 cib->cmds->signon(cib, crm_system_name, cib_command);
114
115 assert_int_equal(pcmk__get_ticket_state(cib, NULL, &xml), pcmk_rc_ok);
116
117
118
119
120 xpath_obj = xpath_search(xml, "//" PCMK__XE_TICKET_STATE);
121
122 assert_int_equal(numXpathResults(xpath_obj), 4);
123
124 ticket_node = getXpathResult(xpath_obj, 0);
125 assert_string_equal(crm_element_value(ticket_node, PCMK_XA_ID), "ticketA");
126
127 ticket_node = getXpathResult(xpath_obj, 1);
128 assert_string_equal(crm_element_value(ticket_node, PCMK_XA_ID), "ticketB");
129
130 ticket_node = getXpathResult(xpath_obj, 2);
131 assert_string_equal(crm_element_value(ticket_node, PCMK_XA_ID), "ticketC");
132
133 ticket_node = getXpathResult(xpath_obj, 3);
134 assert_string_equal(crm_element_value(ticket_node, PCMK_XA_ID), "ticketC");
135
136 freeXpathObject(xpath_obj);
137 free_xml(xml);
138 cib__clean_up_connection(&cib);
139 }
140
141 static void
142 duplicate_tickets(void **state)
143 {
144 xmlNode *xml = NULL;
145 xmlXPathObject *xpath_obj = NULL;
146 cib_t *cib = cib_new();
147
148 cib->cmds->signon(cib, crm_system_name, cib_command);
149
150 assert_int_equal(pcmk__get_ticket_state(cib, "ticketC", &xml), pcmk_rc_duplicate_id);
151
152
153
154
155 xpath_obj = xpath_search(xml, "//" PCMK__XE_TICKET_STATE "[@" PCMK_XA_ID "=\"ticketC\"]");
156
157 assert_int_equal(numXpathResults(xpath_obj), 2);
158 freeXpathObject(xpath_obj);
159 free_xml(xml);
160 cib__clean_up_connection(&cib);
161 }
162
163
164
165
166
167
168
169
170
171
172 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, NULL,
173 cmocka_unit_test_setup_teardown(cib_not_connected, setup_test, teardown_test),
174 cmocka_unit_test_setup_teardown(bad_arguments, setup_test, teardown_test),
175 cmocka_unit_test_setup_teardown(unknown_ticket, setup_test, teardown_test),
176 cmocka_unit_test_setup_teardown(ticket_exists, setup_test, teardown_test),
177 cmocka_unit_test_setup_teardown(multiple_tickets, setup_test, teardown_test),
178 cmocka_unit_test_setup_teardown(duplicate_tickets, setup_test, teardown_test))