This source file includes following definitions.
- empty_input
- not_present
- present
- main
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11 #include <crm/common/xml_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 }