pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
pcmk__get_schema_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2023-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 static void
34 assert_schema(const char *name, int expected_index)
35 {
36  GList *schema_entry = NULL;
37  pcmk__schema_t *schema = NULL;
38 
39  schema_entry = pcmk__get_schema(name);
40  assert_non_null(schema_entry);
41 
42  schema = schema_entry->data;
43  assert_non_null(schema);
44 
45  assert_int_equal(schema->schema_index, expected_index);
46 }
47 
48 static void
49 unknown_schema(void **state)
50 {
51  assert_null(pcmk__get_schema(""));
52  assert_null(pcmk__get_schema("blahblah"));
53  assert_null(pcmk__get_schema("pacemaker-2.47"));
54  assert_null(pcmk__get_schema("pacemaker-47.0"));
55 }
56 
57 static void
58 known_schema(void **state)
59 {
60  // @COMPAT none is deprecated since 2.1.8
61  assert_schema(NULL, 16); // defaults to "none"
62 
63  assert_schema("pacemaker-1.0", 0);
64  assert_schema("pacemaker-1.2", 1);
65  assert_schema("pacemaker-2.0", 3);
66  assert_schema("pacemaker-2.5", 8);
67  assert_schema("pacemaker-3.0", 14);
68 }
69 
70 static void
71 case_insensitive(void **state)
72 {
73  assert_schema("PACEMAKER-1.0", 0);
74  assert_schema("pAcEmAkEr-2.0", 3);
75  assert_schema("paceMAKER-3.0", 14);
76 }
77 
78 PCMK__UNIT_TEST(setup, teardown,
79  cmocka_unit_test(unknown_schema),
80  cmocka_unit_test(known_schema),
81  cmocka_unit_test(case_insensitive));
const char * name
Definition: cib.c:26
void crm_schema_init(void)
Definition: schemas.c:470
void crm_schema_cleanup(void)
Definition: schemas.c:643
GList * pcmk__get_schema(const char *name)
Definition: schemas.c:663
Wrappers for and extensions to libxml2.
PCMK__UNIT_TEST(setup, teardown, cmocka_unit_test(unknown_schema), cmocka_unit_test(known_schema), cmocka_unit_test(case_insensitive))