resetting manifest requested domain to floor
[platform/upstream/ccache.git] / test / test_args.c
1 /*
2  * Copyright (C) 2010 Joel Rosdahl
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the Free
6  * Software Foundation; either version 3 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 51
16  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 /*
20  * This file contains tests for the functions operating on struct args.
21  */
22
23 #include "ccache.h"
24 #include "test/framework.h"
25
26 TEST_SUITE(args)
27
28 TEST(args_init_empty)
29 {
30         struct args *args = args_init(0, NULL);
31         CHECK(args);
32         CHECK_INT_EQ(0, args->argc);
33         CHECK(!args->argv[0]);
34         args_free(args);
35 }
36
37 TEST(args_init_populated)
38 {
39         char *argv[] = {"first", "second"};
40         struct args *args = args_init(2, argv);
41         CHECK(args);
42         CHECK_INT_EQ(2, args->argc);
43         CHECK_STR_EQ("first", args->argv[0]);
44         CHECK_STR_EQ("second", args->argv[1]);
45         CHECK(!args->argv[2]);
46         args_free(args);
47 }
48
49 TEST(args_init_from_string)
50 {
51         struct args *args = args_init_from_string("first second\tthird\nfourth");
52         CHECK(args);
53         CHECK_INT_EQ(4, args->argc);
54         CHECK_STR_EQ("first", args->argv[0]);
55         CHECK_STR_EQ("second", args->argv[1]);
56         CHECK_STR_EQ("third", args->argv[2]);
57         CHECK_STR_EQ("fourth", args->argv[3]);
58         CHECK(!args->argv[4]);
59         args_free(args);
60 }
61
62 TEST(args_copy)
63 {
64         struct args *args1 = args_init_from_string("foo");
65         struct args *args2 = args_copy(args1);
66         CHECK_ARGS_EQ_FREE12(args1, args2);
67 }
68
69 TEST(args_add)
70 {
71         struct args *args = args_init_from_string("first");
72         CHECK_INT_EQ(1, args->argc);
73         args_add(args, "second");
74         CHECK_INT_EQ(2, args->argc);
75         CHECK_STR_EQ("second", args->argv[1]);
76         CHECK(!args->argv[2]);
77         args_free(args);
78 }
79
80 TEST(args_extend)
81 {
82         struct args *args1 = args_init_from_string("first");
83         struct args *args2 = args_init_from_string("second third");
84         CHECK_INT_EQ(1, args1->argc);
85         args_extend(args1, args2);
86         CHECK_INT_EQ(3, args1->argc);
87         CHECK_STR_EQ("second", args1->argv[1]);
88         CHECK_STR_EQ("third", args1->argv[2]);
89         CHECK(!args1->argv[3]);
90         args_free(args1);
91         args_free(args2);
92 }
93
94 TEST(args_pop)
95 {
96         struct args *args = args_init_from_string("first second third");
97         args_pop(args, 2);
98         CHECK_INT_EQ(1, args->argc);
99         CHECK_STR_EQ("first", args->argv[0]);
100         CHECK(!args->argv[1]);
101         args_free(args);
102 }
103
104 TEST(args_set)
105 {
106         struct args *args = args_init_from_string("first second third");
107         args_set(args, 1, "2nd");
108         CHECK_INT_EQ(3, args->argc);
109         CHECK_STR_EQ("first", args->argv[0]);
110         CHECK_STR_EQ("2nd", args->argv[1]);
111         CHECK_STR_EQ("third", args->argv[2]);
112         CHECK(!args->argv[3]);
113         args_free(args);
114 }
115
116 TEST(args_remove_first)
117 {
118         struct args *args1 = args_init_from_string("first second third");
119         struct args *args2 = args_init_from_string("second third");
120         args_remove_first(args1);
121         CHECK_ARGS_EQ_FREE12(args1, args2);
122 }
123
124 TEST(args_add_prefix)
125 {
126         struct args *args1 = args_init_from_string("second third");
127         struct args *args2 = args_init_from_string("first second third");
128         args_add_prefix(args1, "first");
129         CHECK_ARGS_EQ_FREE12(args1, args2);
130 }
131
132 TEST(args_strip)
133 {
134         struct args *args1 = args_init_from_string("first xsecond third xfourth");
135         struct args *args2 = args_init_from_string("first third");
136         args_strip(args1, "x");
137         CHECK_ARGS_EQ_FREE12(args1, args2);
138 }
139
140 TEST(args_to_string)
141 {
142         struct args *args = args_init_from_string("first second");
143         CHECK_STR_EQ_FREE2("first second", args_to_string(args));
144         args_free(args);
145 }
146
147 TEST_SUITE_END