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 #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 }