1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2012 Lennart Poettering
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.
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.
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/>.
31 #include "load-fragment.h"
33 static void test_unit_file_get_set(void) {
39 h = hashmap_new(string_hash_func, string_compare_func);
42 r = unit_file_get_list(UNIT_FILE_SYSTEM, NULL, h);
43 log_info("unit_file_get_list: %s", strerror(-r));
46 HASHMAP_FOREACH(p, h, i)
47 printf("%s = %s\n", p->path, unit_file_state_to_string(p->state));
49 unit_file_list_free(h);
52 static void check_execcommand(ExecCommand *c,
58 log_info("%s %s %s %s",
59 c->path, c->argv[0], c->argv[1], c->argv[2]);
60 assert_se(streq(c->path, path));
61 assert_se(streq(c->argv[0], argv0));
62 assert_se(streq(c->argv[1], argv1));
63 assert_se(c->argv[2] == NULL);
64 assert_se(c->ignore == ignore);
67 static void test_config_parse_exec(void) {
68 /* int config_parse_exec( */
69 /* const char *filename, */
71 /* const char *section, */
72 /* const char *lvalue, */
74 /* const char *rvalue, */
79 ExecCommand *c = NULL, *c1;
82 r = config_parse_exec("fake", 1, "section",
83 "LValue", 0, "/RValue r1",
86 check_execcommand(c, "/RValue", "/RValue", "r1", false);
88 r = config_parse_exec("fake", 2, "section",
89 "LValue", 0, "/RValue///slashes/// r1",
94 check_execcommand(c1, "/RValue/slashes", "/RValue///slashes///",
98 r = config_parse_exec("fake", 3, "section",
99 "LValue", 0, "@/RValue///slashes2/// argv0 r1",
102 c1 = c1->command_next;
103 check_execcommand(c1, "/RValue/slashes2", "argv0", "r1", false);
105 /* ignore && honour_argv0 */
106 r = config_parse_exec("fake", 4, "section",
107 "LValue", 0, "-@/RValue///slashes3/// argv0a r1",
110 c1 = c1->command_next;
111 check_execcommand(c1,
112 "/RValue/slashes3", "argv0a", "r1", true);
114 /* ignore && honour_argv0 */
115 r = config_parse_exec("fake", 4, "section",
116 "LValue", 0, "@-/RValue///slashes4/// argv0b r1",
119 c1 = c1->command_next;
120 check_execcommand(c1,
121 "/RValue/slashes4", "argv0b", "r1", true);
123 /* ignore && ignore */
124 r = config_parse_exec("fake", 4, "section",
125 "LValue", 0, "--/RValue argv0 r1",
128 assert_se(c1->command_next == NULL);
130 /* ignore && ignore */
131 r = config_parse_exec("fake", 4, "section",
132 "LValue", 0, "-@-/RValue argv0 r1",
135 assert_se(c1->command_next == NULL);
138 r = config_parse_exec("fake", 5, "section",
140 "-@/RValue argv0 r1 ; "
144 c1 = c1->command_next;
145 check_execcommand(c1,
146 "/RValue", "argv0", "r1", true);
148 c1 = c1->command_next;
149 check_execcommand(c1,
150 "/goo/goo", "/goo/goo", "boo", false);
152 /* trailing semicolon */
153 r = config_parse_exec("fake", 5, "section",
155 "-@/RValue argv0 r1 ; ",
158 c1 = c1->command_next;
159 check_execcommand(c1,
160 "/RValue", "argv0", "r1", true);
162 assert_se(c1->command_next == NULL);
164 /* escaped semicolon */
165 r = config_parse_exec("fake", 5, "section",
170 c1 = c1->command_next;
171 check_execcommand(c1,
172 "/usr/bin/find", "/usr/bin/find", ";", false);
174 exec_command_free_list(c);
177 int main(int argc, char *argv[]) {
179 test_unit_file_get_set();
180 test_config_parse_exec();