1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 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/>.
30 static void test_parse_env_file(void) {
31 char t[] = "/tmp/test-parse-env-file-XXXXXX";
34 _cleanup_free_ char *one = NULL, *two = NULL, *three = NULL, *four = NULL, *five = NULL, *six = NULL, *seven = NULL;
35 _cleanup_strv_free_ char **a = NULL, **b = NULL;
39 fd = mkostemp(t, O_CLOEXEC);
52 "four = \'44\\\"44\'\n"
53 "five = \'55\\\'55\' \"FIVE\" cinco \n"
54 "six = seis sechs\\\n"
74 log_info("one=[%s]", strna(one));
75 log_info("two=[%s]", strna(two));
76 log_info("three=[%s]", strna(three));
77 log_info("four=[%s]", strna(four));
78 log_info("five=[%s]", strna(five));
79 log_info("six=[%s]", strna(six));
80 log_info("seven=[%s]", strna(seven));
82 assert_se(streq(one, "BAR"));
83 assert_se(streq(two, "bar"));
84 assert_se(streq(three, "333\nxxxx"));
85 assert_se(streq(four, "44\"44"));
86 assert_se(streq(five, "55\'55FIVEcinco"));
87 assert_se(streq(six, "seis sechs sis"));
88 assert_se(seven == NULL);
90 r = load_env_file(t, NULL, &a);
94 log_info("Got: <%s>", *i);
96 assert_se(streq(a[0], "one=BAR"));
97 assert_se(streq(a[1], "two=bar"));
98 assert_se(streq(a[2], "three=333\nxxxx"));
99 assert_se(streq(a[3], "four=44\"44"));
100 assert_se(streq(a[4], "five=55\'55FIVEcinco"));
101 assert_se(streq(a[5], "six=seis sechs sis"));
102 assert_se(streq(a[6], "seven="));
103 assert_se(a[7] == NULL);
105 r = write_env_file("/tmp/test-fileio", a);
108 r = load_env_file("/tmp/test-fileio", NULL, &b);
113 log_info("Got2: <%s>", *i);
114 assert_se(streq(*i, a[k++]));
118 unlink("/tmp/test-fileio");
121 int main(int argc, char *argv[]) {
122 test_parse_env_file();