pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
pcmk__cmp_schemas_by_name_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2024 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 General Public License version 2
7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
12 #include <crm/common/xml.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);
22  return 0;
23 }
24 
25 static int
26 teardown(void **state)
27 {
29  unsetenv("PCMK_schema_directory");
30  return 0;
31 }
32 
33 // NULL schema name defaults to the "none" schema
34 // @COMPAT none is deprecated since 2.1.8
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  /* @COMPAT pacemaker-next is deprecated since 2.1.5,
49  * and pacemaker-0.6 and pacemaker-0.7 since 2.1.8
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 // @COMPAT none is deprecated since 2.1.8
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);
65  PCMK_VALUE_NONE) == 0);
66 
67  assert_true(pcmk__cmp_schemas_by_name("pacemaker-3.0",
68  PCMK_VALUE_NONE) < 0);
70  "pacemaker-1.0") > 0);
71 
72  // @COMPAT pacemaker-next is deprecated since 2.1.5
73  assert_true(pcmk__cmp_schemas_by_name("pacemaker-next",
74  PCMK_VALUE_NONE) < 0);
76  "pacemaker-next") > 0);
77 }
78 
79 // @COMPAT pacemaker-next is deprecated since 2.1.5
80 // @COMPAT none is deprecated since 2.1.8
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));
int pcmk__cmp_schemas_by_name(const char *schema1_name, const char *schema2_name)
Definition: schemas.c:691
void crm_schema_init(void)
Definition: schemas.c:470
void crm_schema_cleanup(void)
Definition: schemas.c:643
#define PCMK_VALUE_NONE
Definition: options.h:178
Wrappers for and extensions to libxml2.
PCMK__UNIT_TEST(setup, teardown, cmocka_unit_test(unknown_is_lesser), cmocka_unit_test(none_is_greater), cmocka_unit_test(next_is_before_none), cmocka_unit_test(known_numeric), cmocka_unit_test(case_insensitive))