pacemaker  2.1.4-dc6eb4362
Scalable High-Availability cluster resource manager
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 #include <stdarg.h>
14 #include <stddef.h>
15 #include <stdint.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <setjmp.h>
19 #include <cmocka.h>
20 
21 static void
22 empty_input(void **state) {
23  assert_null(pcmk__xpath_node_id(NULL, "lrm"));
24  assert_null(pcmk__xpath_node_id("", "lrm"));
25  assert_null(pcmk__xpath_node_id("/blah/blah", NULL));
26  assert_null(pcmk__xpath_node_id("/blah/blah", ""));
27  assert_null(pcmk__xpath_node_id(NULL, NULL));
28 }
29 
30 static void
31 not_present(void **state) {
32  assert_null(pcmk__xpath_node_id("/some/xpath/string[@id='xyz']", "lrm"));
33  assert_null(pcmk__xpath_node_id("/some/xpath/containing[@id='lrm']", "lrm"));
34 }
35 
36 static void
37 present(void **state) {
38  char *s = NULL;
39 
40  s = pcmk__xpath_node_id("/some/xpath/containing/lrm[@id='xyz']", "lrm");
41  assert_int_equal(strcmp(s, "xyz"), 0);
42  free(s);
43 
44  s = pcmk__xpath_node_id("/some/other/lrm[@id='xyz']/xpath", "lrm");
45  assert_int_equal(strcmp(s, "xyz"), 0);
46  free(s);
47 }
48 
49 int
50 main(int argc, char **argv)
51 {
52  const struct CMUnitTest tests[] = {
53  cmocka_unit_test(empty_input),
54  cmocka_unit_test(not_present),
55  cmocka_unit_test(present),
56  };
57 
58  cmocka_set_message_output(CM_OUTPUT_TAP);
59  return cmocka_run_group_tests(tests, NULL, NULL);
60 }
char * pcmk__xpath_node_id(const char *xpath, const char *node)
Definition: xpath.c:303
int main(int argc, char **argv)