pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
pcmk__xpath_node_id_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2021-2022 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU General Public License version 2
7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
12 #include <crm/msg_xml.h>
15 
16 static void
17 empty_input(void **state) {
18  assert_null(pcmk__xpath_node_id(NULL, "lrm"));
19  assert_null(pcmk__xpath_node_id("", "lrm"));
20  assert_null(pcmk__xpath_node_id("/blah/blah", NULL));
21  assert_null(pcmk__xpath_node_id("/blah/blah", ""));
22  assert_null(pcmk__xpath_node_id(NULL, NULL));
23 }
24 
25 static void
26 no_quotes(void **state) {
27  const char *xpath = "/some/xpath/lrm[@" XML_ATTR_ID "=xyz]";
29 }
30 
31 static void
32 not_present(void **state) {
33  const char *xpath = "/some/xpath/string[@" XML_ATTR_ID "='xyz']";
34  assert_null(pcmk__xpath_node_id(xpath, "lrm"));
35 
36  xpath = "/some/xpath/containing[@" XML_ATTR_ID "='lrm']";
37  assert_null(pcmk__xpath_node_id(xpath, "lrm"));
38 }
39 
40 static void
41 present(void **state) {
42  char *s = NULL;
43  const char *xpath = "/some/xpath/containing/lrm[@" XML_ATTR_ID "='xyz']";
44 
45  s = pcmk__xpath_node_id(xpath, "lrm");
46  assert_int_equal(strcmp(s, "xyz"), 0);
47  free(s);
48 
49  xpath = "/some/other/lrm[@" XML_ATTR_ID "='xyz']/xpath";
50  s = pcmk__xpath_node_id(xpath, "lrm");
51  assert_int_equal(strcmp(s, "xyz"), 0);
52  free(s);
53 }
54 
55 PCMK__UNIT_TEST(NULL, NULL,
56  cmocka_unit_test(empty_input),
57  cmocka_unit_test(no_quotes),
58  cmocka_unit_test(not_present),
59  cmocka_unit_test(present))
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(bad_input), cmocka_unit_test(not_found), cmocka_unit_test(find_attrB), cmocka_unit_test(find_attrA_matching))
char * pcmk__xpath_node_id(const char *xpath, const char *node)
Definition: xpath.c:312
#define XML_ATTR_ID
Definition: msg_xml.h:156
#define pcmk__assert_asserts(stmt)