1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 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/>.
28 static void test_strv_env_merge(void) {
29 _cleanup_strv_free_ char **a = NULL, **b = NULL, **r = NULL;
31 a = strv_new("FOO=BAR", "WALDO=WALDO", "WALDO=", "PIEP", "SCHLUMPF=SMURF", NULL);
32 b = strv_new("FOO=KKK", "FOO=", "PIEP=", "SCHLUMPF=SMURFF", "NANANANA=YES", NULL);
34 r = strv_env_merge(2, a, b);
35 assert(streq(r[0], "FOO="));
36 assert(streq(r[1], "WALDO="));
37 assert(streq(r[2], "PIEP"));
38 assert(streq(r[3], "SCHLUMPF=SMURFF"));
39 assert(streq(r[4], "PIEP="));
40 assert(streq(r[5], "NANANANA=YES"));
41 assert(strv_length(r) == 6);
44 assert(streq(r[0], "PIEP"));
45 assert(streq(r[1], "SCHLUMPF=SMURFF"));
46 assert(streq(r[2], "NANANANA=YES"));
47 assert(strv_length(r) == 3);
50 static void test_replace_env_arg(void) {
56 const char *line[] = {
68 _cleanup_strv_free_ char **r = NULL;
70 r = replace_env_argv((char**) line, (char**) env);
71 assert(streq(r[0], "FOO$FOO"));
72 assert(streq(r[1], "FOO$FOOFOO"));
73 assert(streq(r[2], "FOOBAR BAR$FOO"));
74 assert(streq(r[3], "FOOBAR BAR"));
75 assert(streq(r[4], "BAR BAR"));
76 assert(streq(r[5], "BAR"));
77 assert(streq(r[6], "BAR"));
78 assert(streq(r[7], "BAR BARwaldo"));
79 assert(streq(r[8], "${FOO"));
80 assert(strv_length(r) == 9);
83 static void test_one_normalize(const char *input, const char *output)
85 _cleanup_free_ char *t;
87 t = normalize_env_assignment(input);
88 assert(streq(t, output));
91 static void test_normalize_env_assignment(void) {
92 test_one_normalize("foo=bar", "foo=bar");
93 test_one_normalize("=bar", "=bar");
94 test_one_normalize("foo=", "foo=");
95 test_one_normalize("=", "=");
96 test_one_normalize("", "");
97 test_one_normalize("a=\"waldo\"", "a=waldo");
98 test_one_normalize("a=\"waldo", "a=\"waldo");
99 test_one_normalize("a=waldo\"", "a=waldo\"");
100 test_one_normalize("a=\'", "a='");
101 test_one_normalize("a=\'\'", "a=");
102 test_one_normalize(" xyz ", "xyz");
103 test_one_normalize(" xyz = bar ", "xyz=bar");
104 test_one_normalize(" xyz = 'bar ' ", "xyz=bar ");
105 test_one_normalize(" ' xyz' = 'bar ' ", "' xyz'=bar ");
108 int main(int argc, char *argv[]) {
109 test_strv_env_merge();
110 test_replace_env_arg();
111 test_normalize_env_assignment();