pacemaker  2.1.0-7c3f660
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pcmk__xpath_node_id_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2021 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>
12 
13 static void
14 empty_input(void) {
15  g_assert_null(pcmk__xpath_node_id(NULL, "lrm"));
16  g_assert_null(pcmk__xpath_node_id("", "lrm"));
17  g_assert_null(pcmk__xpath_node_id("/blah/blah", NULL));
18  g_assert_null(pcmk__xpath_node_id("/blah/blah", ""));
19  g_assert_null(pcmk__xpath_node_id(NULL, NULL));
20 }
21 
22 static void
23 not_present(void) {
24  g_assert_null(pcmk__xpath_node_id("/some/xpath/string[@id='xyz']", "lrm"));
25  g_assert_null(pcmk__xpath_node_id("/some/xpath/containing[@id='lrm']", "lrm"));
26 }
27 
28 static void
29 present(void) {
30  char *s = NULL;
31 
32  s = pcmk__xpath_node_id("/some/xpath/containing/lrm[@id='xyz']", "lrm");
33  g_assert_cmpint(strcmp(s, "xyz"), ==, 0);
34  free(s);
35 
36  s = pcmk__xpath_node_id("/some/other/lrm[@id='xyz']/xpath", "lrm");
37  g_assert_cmpint(strcmp(s, "xyz"), ==, 0);
38  free(s);
39 }
40 
41 int
42 main(int argc, char **argv)
43 {
44  g_test_init(&argc, &argv, NULL);
45 
46  g_test_add_func("/common/xpath/node_id/empty_input", empty_input);
47  g_test_add_func("/common/xpath/node_id/not_present", not_present);
48  g_test_add_func("/common/xpath/node_id/present", present);
49  return g_test_run();
50 }
int main(int argc, char **argv)
char * pcmk__xpath_node_id(const char *xpath, const char *node)
Definition: xpath.c:303