2 * Unix SMB/CIFS implementation.
4 * Copyright (C) 2020 Andreas Schneider <asn@samba.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "lib/replace/replace.h"
29 #include "lib/util/util_paths.c"
31 static int setup(void **state
)
33 TALLOC_CTX
*mem_ctx
= talloc_new(NULL
);
35 assert_non_null(mem_ctx
);
41 static int teardown(void **state
)
43 TALLOC_CTX
*mem_ctx
= *state
;
49 static void test_get_user_home_dir(void **state
)
51 TALLOC_CTX
*mem_ctx
= *state
;
52 struct passwd
*pwd
= getpwuid(getuid());
55 user
= get_user_home_dir(mem_ctx
);
56 assert_non_null(user
);
57 assert_string_equal(user
, pwd
->pw_dir
);
62 static void test_path_expand_tilde(void **state
)
64 TALLOC_CTX
*mem_ctx
= *state
;
67 const char *user
= NULL
;
70 user
= getenv("USER");
72 user
= getenv("LOGNAME");
75 /* In certain CIs there no such variables */
77 struct passwd
*pw
= getpwuid(getuid());
83 home
= getenv("HOME");
84 assert_non_null(home
);
85 snprintf(h
, sizeof(h
), "%s/.cache", home
);
87 d
= path_expand_tilde(mem_ctx
, "~/.cache");
89 assert_string_equal(d
, h
);
92 snprintf(h
, sizeof(h
), "%s/.cache/X~", home
);
93 d
= path_expand_tilde(mem_ctx
, "~/.cache/X~");
94 assert_string_equal(d
, h
);
97 d
= path_expand_tilde(mem_ctx
, "/guru/meditation");
99 assert_string_equal(d
, "/guru/meditation");
102 snprintf(h
, sizeof(h
), "~%s/.cache", user
);
103 d
= path_expand_tilde(mem_ctx
, h
);
106 snprintf(h
, sizeof(h
), "%s/.cache", home
);
107 assert_string_equal(d
, h
);
111 int main(int argc
, char *argv
[])
114 const struct CMUnitTest tests
[] = {
115 cmocka_unit_test(test_get_user_home_dir
),
116 cmocka_unit_test(test_path_expand_tilde
),
120 cmocka_set_test_filter(argv
[1]);
122 cmocka_set_message_output(CM_OUTPUT_SUBUNIT
);
124 rc
= cmocka_run_group_tests(tests
, setup
, teardown
);