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