This source file includes following definitions.
- cib_not_connected
- setup_test
- teardown_test
- invalid_argument
- unknown_ticket
- ticket_exists
- multiple_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_constraints(&xml, NULL), 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 invalid_argument(void **state)
55 {
56 assert_int_equal(pcmk_ticket_constraints(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_constraints(&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_constraints(&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_constraints(&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), 2);
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 freeXpathObject(xpath_obj);
113 free_xml(xml);
114 }
115
116
117
118
119
120
121
122
123
124
125 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, NULL,
126 cmocka_unit_test(cib_not_connected),
127 cmocka_unit_test_setup_teardown(invalid_argument, setup_test, teardown_test),
128 cmocka_unit_test_setup_teardown(unknown_ticket, setup_test, teardown_test),
129 cmocka_unit_test_setup_teardown(ticket_exists, setup_test, teardown_test),
130 cmocka_unit_test_setup_teardown(multiple_tickets, setup_test, teardown_test))