pacemaker  2.1.5-b7adf64e51
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 Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
14 
15 static void
16 empty_input(void **state) {
17  assert_null(pcmk__xpath_node_id(NULL, "lrm"));
18  assert_null(pcmk__xpath_node_id("", "lrm"));
19  assert_null(pcmk__xpath_node_id("/blah/blah", NULL));
20  assert_null(pcmk__xpath_node_id("/blah/blah", ""));
21  assert_null(pcmk__xpath_node_id(NULL, NULL));
22 }
23 
24 static void
25 no_quotes(void **state) {
26  pcmk__assert_asserts(pcmk__xpath_node_id("/some/xpath/lrm[@id=xyz]", "lrm"));
27 }
28 
29 static void
30 not_present(void **state) {
31  assert_null(pcmk__xpath_node_id("/some/xpath/string[@id='xyz']", "lrm"));
32  assert_null(pcmk__xpath_node_id("/some/xpath/containing[@id='lrm']", "lrm"));
33 }
34 
35 static void
36 present(void **state) {
37  char *s = NULL;
38 
39  s = pcmk__xpath_node_id("/some/xpath/containing/lrm[@id='xyz']", "lrm");
40  assert_int_equal(strcmp(s, "xyz"), 0);
41  free(s);
42 
43  s = pcmk__xpath_node_id("/some/other/lrm[@id='xyz']/xpath", "lrm");
44  assert_int_equal(strcmp(s, "xyz"), 0);
45  free(s);
46 }
47 
48 PCMK__UNIT_TEST(NULL, NULL,
49  cmocka_unit_test(empty_input),
50  cmocka_unit_test(no_quotes),
51  cmocka_unit_test(not_present),
52  cmocka_unit_test(present))
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
char * pcmk__xpath_node_id(const char *xpath, const char *node)
Definition: xpath.c:315
#define pcmk__assert_asserts(stmt)