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

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-2017  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
6
TEST_CASE("parameters basic 1", "")
28
{
29
2
    StringVect pars;
30





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



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





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



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



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



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



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





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



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





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



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



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



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



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





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



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



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





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



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



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



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





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



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



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



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





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



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



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



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



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





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



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



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



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



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





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



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



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



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



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





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



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



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



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



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





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



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



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



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



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





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



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



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



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



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





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



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



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



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



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





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



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



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



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



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





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



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



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





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



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



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





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



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



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





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



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



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





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



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



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





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



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



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





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



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



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





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



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



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





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



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



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





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



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



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





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



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



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





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



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



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





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



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



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





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



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



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



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





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



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



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





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



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



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





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



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





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



8
    REQUIRE(pars.empty());
327

8
}