This source file includes following definitions.
- setup
- teardown
- assert_schema_0
- last_is_0
- last_is_not_0
- schema_0_missing
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <glib.h>
15
16 #include <crm/common/unittest_internal.h>
17 #include "crmcommon_private.h"
18
19 #define SCHEMA_PREFIX PCMK__TEST_SCHEMA_DIR "/find_x_0/pacemaker-"
20
21 static int
22 setup(void **state)
23 {
24
25 setenv("PCMK_schema_directory", PCMK__TEST_SCHEMA_DIR "/find_x_0", 1);
26 return 0;
27 }
28
29 static int
30 teardown(void **state)
31 {
32 unsetenv("PCMK_schema_directory");
33 return 0;
34 }
35
36 static void
37 assert_schema_0(int schema_index, const char *schema_name)
38 {
39 GList *entry = NULL;
40 pcmk__schema_t *schema = NULL;
41
42 entry = pcmk__find_x_0_schema();
43 assert_non_null(entry);
44
45 schema = entry->data;
46 assert_non_null(schema);
47
48 assert_int_equal(schema->schema_index, schema_index);
49 assert_string_equal(schema->name, schema_name);
50 }
51
52 static void
53 last_is_0(void **state)
54 {
55
56
57
58 crm_schema_init();
59 assert_schema_0(14, "pacemaker-3.0");
60 crm_schema_cleanup();
61 }
62
63 static void
64 last_is_not_0(void **state)
65 {
66
67
68
69 assert_int_equal(0, rename(SCHEMA_PREFIX "3.0.rng",
70 SCHEMA_PREFIX "3.0.bak"));
71 crm_schema_init();
72 assert_schema_0(3, "pacemaker-2.0");
73 assert_int_equal(0, rename(SCHEMA_PREFIX "3.0.bak",
74 SCHEMA_PREFIX "3.0.rng"));
75 crm_schema_cleanup();
76 }
77
78 static void
79 schema_0_missing(void **state)
80 {
81
82
83
84 assert_int_equal(0, rename(SCHEMA_PREFIX "3.0.rng",
85 SCHEMA_PREFIX "3.0.bak"));
86 assert_int_equal(0, rename(SCHEMA_PREFIX "2.0.rng",
87 SCHEMA_PREFIX "2.0.bak"));
88 crm_schema_init();
89 assert_schema_0(3, "pacemaker-2.1");
90 assert_int_equal(0, rename(SCHEMA_PREFIX "2.0.bak",
91 SCHEMA_PREFIX "2.0.rng"));
92 assert_int_equal(0, rename(SCHEMA_PREFIX "3.0.bak",
93 SCHEMA_PREFIX "3.0.rng"));
94 crm_schema_cleanup();
95 }
96
97 PCMK__UNIT_TEST(setup, teardown,
98 cmocka_unit_test(last_is_0),
99 cmocka_unit_test(last_is_not_0),
100 cmocka_unit_test(schema_0_missing))