test-fileio.c revision 98f59e59e0c31ffcb953d3a7dba0da5e6f2f55f7
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek This file is part of systemd.
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek Copyright 2013 Lennart Poettering
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek systemd is free software; you can redistribute it and/or modify it
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek under the terms of the GNU Lesser General Public License as published by
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek the Free Software Foundation; either version 2.1 of the License, or
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek (at your option) any later version.
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek systemd is distributed in the hope that it will be useful, but
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek WITHOUT ANY WARRANTY; without even the implied warranty of
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek Lesser General Public License for more details.
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek You should have received a copy of the GNU Lesser General Public License
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek along with systemd; If not, see <http://www.gnu.org/licenses/>.
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic void test_parse_env_file(void) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek char t[] = "/tmp/test-parse-env-file-XXXXXX";
29fc0ddcd737af906986d4029579d4dfe838ba02Zbigniew Jędrzejewski-Szmek _cleanup_free_ char *one = NULL, *two = NULL, *three = NULL, *four = NULL, *five = NULL,
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek *six = NULL, *seven = NULL, *eight = NULL, *nine = NULL, *ten = NULL;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek _cleanup_strv_free_ char **a = NULL, **b = NULL;
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek "invalid line\n"
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek "invalid line #comment\n"
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek "three = \"333\n"
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek "four = \'44\\\"44\'\n"
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek "five = \'55\\\'55\' \"FIVE\" cinco \n"
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek "six = seis sechs\\\n"
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek "seven=\"sevenval\" #nocomment\n"
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek "eight=eightval #nocomment\n"
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek "export nine=nineval\n"
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek assert_se(streq(a[0], "one=BAR"));
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek assert_se(streq(a[1], "two=bar"));
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek assert_se(streq(a[2], "three=333\nxxxx"));
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek assert_se(streq(a[3], "four=44\"44"));
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek assert_se(streq(a[4], "five=55\'55FIVEcinco"));
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek assert_se(streq(a[5], "six=seis sechs sis"));
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek assert_se(streq(a[6], "seven=sevenval#nocomment"));
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek assert_se(streq(a[7], "eight=eightval #nocomment"));
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek assert_se(streq(a[8], "export nine=nineval"));
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek strv_env_clean_log(a, "/tmp/test-fileio");
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek log_info("one=[%s]", strna(one));
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek log_info("two=[%s]", strna(two));
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek log_info("three=[%s]", strna(three));
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek log_info("four=[%s]", strna(four));
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek log_info("five=[%s]", strna(five));
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek log_info("six=[%s]", strna(six));
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek log_info("seven=[%s]", strna(seven));
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek log_info("eight=[%s]", strna(eight));
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek log_info("export nine=[%s]", strna(nine));
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek log_info("ten=[%s]", strna(nine));
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek assert_se(streq(three, "333\nxxxx"));
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek assert_se(streq(four, "44\"44"));
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek assert_se(streq(five, "55\'55FIVEcinco"));
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek assert_se(streq(six, "seis sechs sis"));
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek assert_se(streq(seven, "sevenval#nocomment"));
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek assert_se(streq(eight, "eightval #nocomment"));
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek assert_se(streq(nine, "nineval"));
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek r = write_env_file("/tmp/test-fileio", a);
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek r = load_env_file("/tmp/test-fileio", NULL, &b);
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmekint main(int argc, char *argv[]) {