]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-path-lookup.c
util-lib: split our string related calls from util.[ch] into its own file string...
[thirdparty/systemd.git] / src / test / test-path-lookup.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2014 Zbigniew Jędrzejewski-Szmek
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <sys/stat.h>
23
24 #include "log.h"
25 #include "path-lookup.h"
26 #include "rm-rf.h"
27 #include "string-util.h"
28 #include "strv.h"
29
30 static void test_paths(ManagerRunningAs running_as, bool personal) {
31 char template[] = "/tmp/test-path-lookup.XXXXXXX";
32
33 _cleanup_lookup_paths_free_ LookupPaths lp = {};
34 char *exists, *not;
35
36 assert_se(mkdtemp(template));
37 exists = strjoina(template, "/exists");
38 assert_se(mkdir(exists, 0755) == 0);
39 not = strjoina(template, "/not");
40
41 assert_se(lookup_paths_init(&lp, running_as, personal, NULL, exists, not, not) == 0);
42
43 assert_se(!strv_isempty(lp.unit_path));
44 assert_se(strv_contains(lp.unit_path, exists));
45 assert_se(strv_contains(lp.unit_path, not));
46
47 assert_se(rm_rf(template, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
48 }
49
50 static void print_generator_paths(ManagerRunningAs running_as) {
51 _cleanup_strv_free_ char **paths;
52 char **dir;
53
54 log_info("Generators dirs (%s):", running_as == MANAGER_SYSTEM ? "system" : "user");
55
56 paths = generator_paths(running_as);
57 STRV_FOREACH(dir, paths)
58 log_info(" %s", *dir);
59 }
60
61 int main(int argc, char **argv) {
62 log_set_max_level(LOG_DEBUG);
63 log_parse_environment();
64 log_open();
65
66 test_paths(MANAGER_SYSTEM, false);
67 test_paths(MANAGER_SYSTEM, true);
68 test_paths(MANAGER_USER, false);
69 test_paths(MANAGER_USER, true);
70
71 print_generator_paths(MANAGER_SYSTEM);
72 print_generator_paths(MANAGER_USER);
73
74 return EXIT_SUCCESS;
75 }