GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/utils/parameters.cc Lines: 217 217 100.0 %
Date: 2018-11-12 Branches: 724 1920 37.7 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-2018  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "unittests/unittests.h"
22
23
#include "utils/parameters.h"
24
25
#include "debug.h"
26
27
3
TEST_CASE("parameters basic 1", "")
28
{
29
1
    StringVect pars;
30





10
    REQUIRE(splitParameters(pars, "", ",", '\"') == true);
31



4
    REQUIRE(pars.empty());
32
1
}
33
34
3
TEST_CASE("parameters basic 2", "")
35
{
36
1
    StringVect pars;
37





10
    REQUIRE(splitParameters(pars, "one,two, tree", ",", '\"') == true);
38



5
    REQUIRE(pars.size() == 3);
39



4
    REQUIRE(pars[0] == "one");
40



5
    REQUIRE(pars[1] == "two");
41



5
    REQUIRE(pars[2] == "tree");
42
1
}
43
44
3
TEST_CASE("parameters basic 3", "")
45
{
46
1
    StringVect pars;
47





10
    REQUIRE(splitParameters(pars, ", ,,,", ",", '\"') == true);
48



4
    REQUIRE(pars.empty());
49
1
}
50
51
3
TEST_CASE("parameters basic 4", "")
52
{
53
1
    StringVect pars;
54





10
    REQUIRE(splitParameters(pars, "one,,two, tree", ",", '\"') == true);
55



5
    REQUIRE(pars.size() == 3);
56



4
    REQUIRE(pars[0] == "one");
57



5
    REQUIRE(pars[1] == "two");
58



5
    REQUIRE(pars[2] == "tree");
59
1
}
60
61
3
TEST_CASE("parameters escape 1", "")
62
{
63
1
    StringVect pars;
64





10
    REQUIRE(splitParameters(pars, "\\\"", ",", '\"') == true);
65



5
    REQUIRE(pars.size() == 1);
66



4
    REQUIRE(pars[0] == "\"");
67
1
}
68
69
3
TEST_CASE("parameters escape 2", "")
70
{
71
1
    StringVect pars;
72





10
    REQUIRE(splitParameters(pars, "\\\", test", ",", '\"') == true);
73



5
    REQUIRE(pars.size() == 2);
74



4
    REQUIRE(pars[0] == "\"");
75



5
    REQUIRE(pars[1] == "test");
76
1
}
77
78
3
TEST_CASE("parameters escape 3", "")
79
{
80
1
    StringVect pars;
81





10
    REQUIRE(splitParameters(pars, "test,\\\"", ",", '\"') == true);
82



5
    REQUIRE(pars.size() == 2);
83



4
    REQUIRE(pars[0] == "test");
84



5
    REQUIRE(pars[1] == "\"");
85
1
}
86
87
3
TEST_CASE("parameters quote 1", "")
88
{
89
1
    StringVect pars;
90





10
    REQUIRE(splitParameters(pars, "\"one\",,two, tree", ",", '\"') == true);
91



5
    REQUIRE(pars.size() == 3);
92



4
    REQUIRE(pars[0] == "one");
93



5
    REQUIRE(pars[1] == "two");
94



5
    REQUIRE(pars[2] == "tree");
95
1
}
96
97
3
TEST_CASE("parameters quote 2", "")
98
{
99
1
    StringVect pars;
100





10
    REQUIRE(splitParameters(pars, "\"\",,two, tree", ",", '\"') == true);
101



5
    REQUIRE(pars.size() == 3);
102



4
    REQUIRE(pars[0].empty());
103



5
    REQUIRE(pars[1] == "two");
104



5
    REQUIRE(pars[2] == "tree");
105
1
}
106
107
3
TEST_CASE("parameters quote 3", "")
108
{
109
1
    StringVect pars;
110





10
    REQUIRE(splitParameters(pars, "\"one test\",,two, tree", ",", '\"') ==
111
        true);
112



5
    REQUIRE(pars.size() == 3);
113



4
    REQUIRE(pars[0] == "one test");
114



5
    REQUIRE(pars[1] == "two");
115



5
    REQUIRE(pars[2] == "tree");
116
1
}
117
118
3
TEST_CASE("parameters quote 4", "")
119
{
120
1
    StringVect pars;
121





10
    REQUIRE(splitParameters(pars, "\"\\\"one test\\\"\",,two, tree", ",", '\"')
122
        == true);
123



5
    REQUIRE(pars.size() == 3);
124



4
    REQUIRE(pars[0] == "\"one test\"");
125



5
    REQUIRE(pars[1] == "two");
126



5
    REQUIRE(pars[2] == "tree");
127
1
}
128
129
3
TEST_CASE("parameters quote 5", "")
130
{
131
1
    StringVect pars;
132





10
    REQUIRE(splitParameters(pars, "\"\\\"one \\\"test\\\"\",,two, tree",
133
        ",", '\"') == true);
134



5
    REQUIRE(pars.size() == 3);
135



4
    REQUIRE(pars[0] == "\"one \"test\"");
136



5
    REQUIRE(pars[1] == "two");
137



5
    REQUIRE(pars[2] == "tree");
138
1
}
139
140
3
TEST_CASE("parameters quote 6", "")
141
{
142
1
    StringVect pars;
143





10
    REQUIRE(splitParameters(pars, "\"one, test\",,two, tree", ",", '\"')
144
        == true);
145



5
    REQUIRE(pars.size() == 3);
146



4
    REQUIRE(pars[0] == "one, test");
147



5
    REQUIRE(pars[1] == "two");
148



5
    REQUIRE(pars[2] == "tree");
149
1
}
150
151
3
TEST_CASE("parameters quote 7", "")
152
{
153
1
    StringVect pars;
154





10
    REQUIRE(splitParameters(pars, "\"\\\"one, test\\\"\",,two, tree",
155
        ",", '\"') == true);
156



5
    REQUIRE(pars.size() == 3);
157



4
    REQUIRE(pars[0] == "\"one, test\"");
158



5
    REQUIRE(pars[1] == "two");
159



5
    REQUIRE(pars[2] == "tree");
160
1
}
161
162
3
TEST_CASE("parameters quote 8", "")
163
{
164
1
    StringVect pars;
165





10
    REQUIRE(splitParameters(pars, "\"\\\"\",,two, tree", ",", '\"')
166
        == true);
167



5
    REQUIRE(pars.size() == 3);
168



4
    REQUIRE(pars[0] == "\"");
169



5
    REQUIRE(pars[1] == "two");
170



5
    REQUIRE(pars[2] == "tree");
171
1
}
172
173
3
TEST_CASE("parameters quote 9", "")
174
{
175
1
    StringVect pars;
176





10
    REQUIRE(splitParameters(pars, "\"\\\",,two, tree", ",", '\"')
177
        == true);
178



5
    REQUIRE(pars.size() == 1);
179



4
    REQUIRE(pars[0] == "\"\",,two, tree");
180
1
}
181
182
3
TEST_CASE("parameters quote 10", "")
183
{
184
1
    StringVect pars;
185





10
    REQUIRE(splitParameters(pars, "\"", ",", '\"')
186
        == true);
187



5
    REQUIRE(pars.size() == 1);
188



4
    REQUIRE(pars[0] == "\"");
189
1
}
190
191
3
TEST_CASE("parameters quote 11", "")
192
{
193
1
    StringVect pars;
194





10
    REQUIRE(splitParameters(pars, "\\\"", ",", '\"')
195
        == true);
196



5
    REQUIRE(pars.size() == 1);
197



4
    REQUIRE(pars[0] == "\"");
198
1
}
199
200
3
TEST_CASE("parameters quote 12", "")
201
{
202
1
    StringVect pars;
203





10
    REQUIRE(splitParameters(pars, ",\"", ",", '\"')
204
        == true);
205



5
    REQUIRE(pars.size() == 1);
206



4
    REQUIRE(pars[0] == "\"");
207
1
}
208
209
3
TEST_CASE("parameters quote 13", "")
210
{
211
1
    StringVect pars;
212





10
    REQUIRE(splitParameters(pars, "\",", ",", '\"')
213
        == true);
214



5
    REQUIRE(pars.size() == 1);
215



4
    REQUIRE(pars[0] == "\",");
216
1
}
217
218
3
TEST_CASE("parameters quote 14", "")
219
{
220
1
    StringVect pars;
221





10
    REQUIRE(splitParameters(pars, "\\\",", ",", '\"')
222
        == true);
223



5
    REQUIRE(pars.size() == 1);
224



4
    REQUIRE(pars[0] == "\"");
225
1
}
226
227
3
TEST_CASE("parameters quote 15", "")
228
{
229
1
    StringVect pars;
230





10
    REQUIRE(splitParameters(pars, ",\\\"", ",", '\"')
231
        == true);
232



5
    REQUIRE(pars.size() == 1);
233



4
    REQUIRE(pars[0] == "\"");
234
1
}
235
236
3
TEST_CASE("parameters quote 16", "")
237
{
238
1
    StringVect pars;
239





10
    REQUIRE(splitParameters(pars, "\"one test\"", ",", '\"') ==
240
        true);
241



5
    REQUIRE(pars.size() == 1);
242



4
    REQUIRE(pars[0] == "one test");
243
1
}
244
245
3
TEST_CASE("parameters quote 17", "")
246
{
247
1
    StringVect pars;
248





10
    REQUIRE(splitParameters(pars, "\"one, test\"", ",", '\"') ==
249
        true);
250



5
    REQUIRE(pars.size() == 1);
251



4
    REQUIRE(pars[0] == "one, test");
252
1
}
253
254
3
TEST_CASE("parameters quote 18", "")
255
{
256
1
    StringVect pars;
257





10
    REQUIRE(splitParameters(pars, "\"one\\\" test\"", ",", '\"') ==
258
        true);
259



5
    REQUIRE(pars.size() == 1);
260



4
    REQUIRE(pars[0] == "one\" test");
261
1
}
262
263
3
TEST_CASE("parameters quote 19", "")
264
{
265
1
    StringVect pars;
266





10
    REQUIRE(splitParameters(pars, "\"one\\\" ,test\"", ",", '\"') ==
267
        true);
268



5
    REQUIRE(pars.size() == 1);
269



4
    REQUIRE(pars[0] == "one\" ,test");
270
1
}
271
272
3
TEST_CASE("parameters quote 20", "")
273
{
274
1
    StringVect pars;
275





10
    REQUIRE(splitParameters(pars, "\"one\\\" test,\"", ",", '\"') ==
276
        true);
277



5
    REQUIRE(pars.size() == 1);
278



4
    REQUIRE(pars[0] == "one\" test,");
279
1
}
280
281
3
TEST_CASE("parameters complex 1", "")
282
{
283
1
    StringVect pars;
284





10
    REQUIRE(splitParameters(pars, "\"test\" \"line\"", ",", '\"') == true);
285



5
    REQUIRE(pars.size() == 1);
286



4
    REQUIRE(pars[0] == "test\" \"line");
287
1
}
288
289
3
TEST_CASE("parameters complex 2", "")
290
{
291
1
    StringVect pars;
292





10
    REQUIRE(splitParameters(pars, "\"test\", \"line\"", ",", '\"') == true);
293



5
    REQUIRE(pars.size() == 2);
294



4
    REQUIRE(pars[0] == "test");
295



5
    REQUIRE(pars[1] == "line");
296
1
}
297
298
3
TEST_CASE("parameters complex 3", "")
299
{
300
1
    StringVect pars;
301





10
    REQUIRE(splitParameters(pars, "\"test,\" \"line\"", ",", '\"') == true);
302



5
    REQUIRE(pars.size() == 1);
303



4
    REQUIRE(pars[0] == "test,\" \"line");
304
1
}
305
306
3
TEST_CASE("parameters broken 1", "")
307
{
308
1
    StringVect pars;
309





10
    REQUIRE(splitParameters(pars, "\"", ",", '\"') == true);
310



5
    REQUIRE(pars.size() == 1);
311



4
    REQUIRE(pars[0] == "\"");
312
1
}
313
314
3
TEST_CASE("parameters broken 2", "")
315
{
316
1
    StringVect pars;
317





10
    REQUIRE(splitParameters(pars, ",", ",", '\"') == true);
318



4
    REQUIRE(pars.empty());
319
1
}
320
321
3
TEST_CASE("parameters broken 3", "")
322
{
323
1
    StringVect pars;
324





10
    REQUIRE(splitParameters(pars,
325
        ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,", ",", '\"') == true);
326



4
    REQUIRE(pars.empty());
327

4
}