This source file includes following definitions.
- setup
- teardown
- unknown_is_lesser
- none_is_greater
- next_is_before_none
- known_numeric
- case_insensitive
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/xml.h>
13 #include <crm/common/unittest_internal.h>
14 #include <crm/common/xml_internal.h>
15 #include "crmcommon_private.h"
16
17 static int
18 setup(void **state)
19 {
20 setenv("PCMK_schema_directory", PCMK__TEST_SCHEMA_DIR, 1);
21 crm_schema_init();
22 return 0;
23 }
24
25 static int
26 teardown(void **state)
27 {
28 crm_schema_cleanup();
29 unsetenv("PCMK_schema_directory");
30 return 0;
31 }
32
33
34
35
36 static void
37 unknown_is_lesser(void **state)
38 {
39 assert_true(pcmk__cmp_schemas_by_name("pacemaker-0.1",
40 "pacemaker-0.2") == 0);
41 assert_true(pcmk__cmp_schemas_by_name("pacemaker-0.1",
42 "pacemaker-1.0") < 0);
43 assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.0",
44 "pacemaker-0.1") > 0);
45 assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.1", NULL) < 0);
46 assert_true(pcmk__cmp_schemas_by_name(NULL, "pacemaker-0.0") > 0);
47
48
49
50
51 assert_true(pcmk__cmp_schemas_by_name("pacemaker-0.6",
52 "pacemaker-next") < 0);
53 assert_true(pcmk__cmp_schemas_by_name("pacemaker-next",
54 "pacemaker-0.7") > 0);
55 }
56
57
58 static void
59 none_is_greater(void **state)
60 {
61 assert_true(pcmk__cmp_schemas_by_name(NULL, NULL) == 0);
62 assert_true(pcmk__cmp_schemas_by_name(NULL, PCMK_VALUE_NONE) == 0);
63 assert_true(pcmk__cmp_schemas_by_name(PCMK_VALUE_NONE, NULL) == 0);
64 assert_true(pcmk__cmp_schemas_by_name(PCMK_VALUE_NONE,
65 PCMK_VALUE_NONE) == 0);
66
67 assert_true(pcmk__cmp_schemas_by_name("pacemaker-3.0",
68 PCMK_VALUE_NONE) < 0);
69 assert_true(pcmk__cmp_schemas_by_name(PCMK_VALUE_NONE,
70 "pacemaker-1.0") > 0);
71
72
73 assert_true(pcmk__cmp_schemas_by_name("pacemaker-next",
74 PCMK_VALUE_NONE) < 0);
75 assert_true(pcmk__cmp_schemas_by_name(PCMK_VALUE_NONE,
76 "pacemaker-next") > 0);
77 }
78
79
80
81 static void
82 next_is_before_none(void **state)
83 {
84 assert_true(pcmk__cmp_schemas_by_name("pacemaker-next",
85 "pacemaker-next") == 0);
86 assert_true(pcmk__cmp_schemas_by_name(NULL, "pacemaker-next") > 0);
87 assert_true(pcmk__cmp_schemas_by_name("pacemaker-next", NULL) < 0);
88 assert_true(pcmk__cmp_schemas_by_name("pacemaker-3.0",
89 "pacemaker-next") < 0);
90 assert_true(pcmk__cmp_schemas_by_name("pacemaker-next",
91 "pacemaker-1.0") > 0);
92 }
93
94 static void
95 known_numeric(void **state)
96 {
97 assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.0",
98 "pacemaker-1.0") == 0);
99 assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.2",
100 "pacemaker-1.0") > 0);
101 assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.2",
102 "pacemaker-2.0") < 0);
103 }
104
105 static void
106 case_insensitive(void **state)
107 {
108 assert_true(pcmk__cmp_schemas_by_name("Pacemaker-1.0",
109 "pacemaker-1.0") == 0);
110 assert_true(pcmk__cmp_schemas_by_name("PACEMAKER-1.2",
111 "pacemaker-1.0") > 0);
112 assert_true(pcmk__cmp_schemas_by_name("PaceMaker-1.2",
113 "pacemaker-2.0") < 0);
114 }
115
116 PCMK__UNIT_TEST(setup, teardown,
117 cmocka_unit_test(unknown_is_lesser),
118 cmocka_unit_test(none_is_greater),
119 cmocka_unit_test(next_is_before_none),
120 cmocka_unit_test(known_numeric),
121 cmocka_unit_test(case_insensitive));