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);
115 r = config_parse_exec("fake", 5, "section",
117 "-@/RValue argv0 r1 ; "
121 c1 = c1->command_next;
122 check_execcommand(c1,
123 "/RValue", "argv0", "r1", true);
125 c1 = c1->command_next;
126 check_execcommand(c1,
127 "/goo/goo", "/goo/goo", "boo", false);
129 /* trailing semicolon */
130 r = config_parse_exec("fake", 5, "section",
132 "-@/RValue argv0 r1 ; ",
135 c1 = c1->command_next;
136 check_execcommand(c1,
137 "/RValue", "argv0", "r1", true);
139 assert_se(c1->command_next == NULL);
141 exec_command_free_list(c);
144 int main(int argc, char *argv[]) {
146 test_unit_file_get_set();
147 test_config_parse_exec();