b9ccac7c2a00c0aedfa01d0a863410651a71cdf7
[platform/upstream/libpipeline.git] / tests / argstr.c
1 /*
2  * Copyright (C) 2010 Colin Watson.
3  *
4  * This file is part of libpipeline.
5  *
6  * libpipeline is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or (at
9  * your option) any later version.
10  *
11  * libpipeline is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with libpipeline; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
19  * USA.
20  */
21
22 #include <string.h>
23
24 #include "common.h"
25
26 /* Include private definitions so that we can inspect arguments. */
27 #include "pipeline-private.h"
28
29 START_TEST (test_argstr_trivial)
30 {
31         pipecmd *cmd;
32
33         cmd = pipecmd_new_argstr ("/bin/simple");
34         fail_unless (!strcmp (cmd->name, "/bin/simple"));
35         fail_unless (cmd->u.process.argc == 1);
36         fail_unless (!strcmp (cmd->u.process.argv[0], "simple"));
37         pipecmd_free (cmd);
38 }
39 END_TEST
40
41 START_TEST (test_argstr_torture)
42 {
43         pipecmd *cmd;
44
45         cmd = pipecmd_new_argstr
46                 ("x' \\' \\$\\'\\\"\" \\'\\$\\\"\\\\ \" \\\"");
47         fail_unless (!strcmp (cmd->name, "x \\"));
48         fail_unless (cmd->u.process.argc == 3);
49         fail_unless (!strcmp (cmd->u.process.argv[0], "x \\"));
50         fail_unless (!strcmp (cmd->u.process.argv[1], "$'\" \\'$\"\\ "));
51         fail_unless (!strcmp (cmd->u.process.argv[2], "\""));
52         pipecmd_free (cmd);
53 }
54 END_TEST
55
56 START_TEST (test_argstr_exec)
57 {
58         pipecmd *cmd;
59
60         cmd = pipecmd_new_argstr ("exec /bin/foo bar");
61         fail_unless (!strcmp (cmd->name, "/bin/foo"));
62         fail_unless (cmd->u.process.argc == 2);
63         fail_unless (!strcmp (cmd->u.process.argv[0], "foo"));
64         fail_unless (!strcmp (cmd->u.process.argv[1], "bar"));
65 }
66 END_TEST
67
68 Suite *argstr_suite (void)
69 {
70         Suite *s = suite_create ("Argstr");
71
72         TEST_CASE (s, argstr, trivial);
73         TEST_CASE (s, argstr, torture);
74         TEST_CASE (s, argstr, exec);
75
76         return s;
77 }
78
79 MAIN (argstr)