This source file includes following definitions.
- setup
- teardown
- assert_schema
- unknown_schema
- known_schema
- 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 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
61 assert_schema(NULL, 16);
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));