This source file includes following definitions.
- empty_input_string
- input_too_long_for_both
- input_too_long_for_pcmk
- value_not_found
- value_found_pcmk
- value_found_ha
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11 #include <crm/common/unittest_internal.h>
12
13 #include "mock_private.h"
14
15 static void
16 empty_input_string(void **state)
17 {
18 pcmk__mock_getenv = true;
19
20
21 assert_null(pcmk__env_option(NULL));
22 assert_null(pcmk__env_option(""));
23
24 pcmk__mock_getenv = false;
25 }
26
27 static void
28 input_too_long_for_both(void **state)
29 {
30
31
32
33
34
35 char long_opt[NAME_MAX - 2];
36
37 for (int i = 0; i < NAME_MAX - 3; i++) {
38 long_opt[i] = 'a';
39 }
40 long_opt[NAME_MAX - 3] = '\0';
41
42 pcmk__mock_getenv = true;
43
44
45 assert_null(pcmk__env_option(long_opt));
46
47 pcmk__mock_getenv = false;
48 }
49
50 static void
51 input_too_long_for_pcmk(void **state)
52 {
53
54
55
56
57
58
59
60 char long_opt[NAME_MAX - 4];
61 char buf[NAME_MAX];
62
63 for (int i = 0; i < NAME_MAX - 5; i++) {
64 long_opt[i] = 'a';
65 }
66 long_opt[NAME_MAX - 5] = '\0';
67
68 pcmk__mock_getenv = true;
69
70
71
72
73 snprintf(buf, NAME_MAX, "HA_%s", long_opt);
74 expect_string(__wrap_getenv, name, buf);
75 will_return(__wrap_getenv, "value");
76 assert_string_equal(pcmk__env_option(long_opt), "value");
77
78 pcmk__mock_getenv = false;
79 }
80
81 static void
82 value_not_found(void **state)
83 {
84
85 pcmk__mock_getenv = true;
86
87 expect_string(__wrap_getenv, name, "PCMK_env_var");
88 will_return(__wrap_getenv, NULL);
89
90 expect_string(__wrap_getenv, name, "HA_env_var");
91 will_return(__wrap_getenv, NULL);
92
93 assert_null(pcmk__env_option("env_var"));
94
95 pcmk__mock_getenv = false;
96 }
97
98 static void
99 value_found_pcmk(void **state)
100 {
101
102 pcmk__mock_getenv = true;
103
104 expect_string(__wrap_getenv, name, "PCMK_env_var");
105 will_return(__wrap_getenv, "value");
106 assert_string_equal(pcmk__env_option("env_var"), "value");
107
108 pcmk__mock_getenv = false;
109 }
110
111 static void
112 value_found_ha(void **state)
113 {
114
115 pcmk__mock_getenv = true;
116
117 expect_string(__wrap_getenv, name, "PCMK_env_var");
118 will_return(__wrap_getenv, NULL);
119
120 expect_string(__wrap_getenv, name, "HA_env_var");
121 will_return(__wrap_getenv, "value");
122
123 assert_string_equal(pcmk__env_option("env_var"), "value");
124
125 pcmk__mock_getenv = false;
126 }
127
128 PCMK__UNIT_TEST(NULL, NULL,
129 cmocka_unit_test(empty_input_string),
130 cmocka_unit_test(input_too_long_for_both),
131 cmocka_unit_test(input_too_long_for_pcmk),
132 cmocka_unit_test(value_not_found),
133 cmocka_unit_test(value_found_pcmk),
134 cmocka_unit_test(value_found_ha))