This source file includes following definitions.
- getenv_returns_invalid
- getenv_returns_valid
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
13
14 #include "mock_private.h"
15
16 static void
17 getenv_returns_invalid(void **state)
18 {
19 const char *result;
20
21 pcmk__mock_getenv = true;
22
23 expect_string(__wrap_getenv, name, "TMPDIR");
24 will_return(__wrap_getenv, NULL);
25 result = pcmk__get_tmpdir();
26 assert_string_equal(result, "/tmp");
27
28 expect_string(__wrap_getenv, name, "TMPDIR");
29 will_return(__wrap_getenv, "");
30 result = pcmk__get_tmpdir();
31 assert_string_equal(result, "/tmp");
32
33 expect_string(__wrap_getenv, name, "TMPDIR");
34 will_return(__wrap_getenv, "subpath");
35 result = pcmk__get_tmpdir();
36 assert_string_equal(result, "/tmp");
37
38 pcmk__mock_getenv = false;
39 }
40
41 static void
42 getenv_returns_valid(void **state)
43 {
44 const char *result;
45
46 pcmk__mock_getenv = true;
47
48 expect_string(__wrap_getenv, name, "TMPDIR");
49 will_return(__wrap_getenv, "/var/tmp");
50 result = pcmk__get_tmpdir();
51 assert_string_equal(result, "/var/tmp");
52
53 expect_string(__wrap_getenv, name, "TMPDIR");
54 will_return(__wrap_getenv, "/");
55 result = pcmk__get_tmpdir();
56 assert_string_equal(result, "/");
57
58 expect_string(__wrap_getenv, name, "TMPDIR");
59 will_return(__wrap_getenv, "/tmp/abcd.1234");
60 result = pcmk__get_tmpdir();
61 assert_string_equal(result, "/tmp/abcd.1234");
62
63 pcmk__mock_getenv = false;
64 }
65
66 PCMK__UNIT_TEST(NULL, NULL,
67 cmocka_unit_test(getenv_returns_invalid),
68 cmocka_unit_test(getenv_returns_valid))