GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/utils/stringutils.cc Lines: 1193 1193 100.0 %
Date: 2017-11-29 Branches: 4098 10640 38.5 %

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 "configuration.h"
24
25
#include "const/utils/utf8.h"
26
27
#include "fs/virtfs/fs.h"
28
29
#include "utils/dtor.h"
30
31
#include "resources/iteminfo.h"
32
33
#include "resources/db/itemdb.h"
34
35
#include "resources/resourcemanager/resourcemanager.h"
36
37
#include "debug.h"
38
39
6
TEST_CASE("stringuntils  trim 1", "")
40
{
41
8
    std::string str = "str";
42




8
    REQUIRE("str" == trim(str));
43
44
    str = " str";
45




8
    REQUIRE("str" == trim(str));
46




8
    REQUIRE("str" == trim(str));
47
48
    str = " str   this IS Long Стринг "
49
        "[email protected]#$%^&*()_+`-=[]\\{}|;':\",./<>?   ";
50




8
    REQUIRE("str   this IS Long Стринг [email protected]#$%^&*()_+`-=[]\\{}|;':\",./<>?" ==
51
        trim(str));
52
53
    str = "";
54




8
    REQUIRE(trim(str).empty());
55
2
}
56
57
6
TEST_CASE("stringuntils toLower 1", "")
58
{
59
8
    std::string str = "str";
60




8
    REQUIRE("str" == toLower(str));
61
62
    str = " StR";
63




8
    REQUIRE(" str" == toLower(str));
64
65
    str = " str   this IS Long  "
66
        "[email protected]#$%^&*()_+`-=[]\\{}|;':\",./<>?   ";
67
68




8
    REQUIRE(" str   this is long  [email protected]#$%^&*()_+`-=[]\\{}|;':\",./<>?   " ==
69
        toLower(str));
70
71
    str = "";
72




8
    REQUIRE(toLower(str).empty());
73
2
}
74
75
6
TEST_CASE("stringuntils toUpper 1", "")
76
{
77
8
    std::string str = "str";
78




8
    REQUIRE("STR" == toUpper(str));
79
80
    str = " StR";
81




8
    REQUIRE(" STR" == toUpper(str));
82
83
    str = " str   this IS Long  "
84
        "[email protected]#$%^&*()_+`-=[]\\{}|;':,./<>?   ";
85
86




8
    REQUIRE(" STR   THIS IS LONG  [email protected]#$%^&*()_+`-=[]\\{}|;':,./<>?   " ==
87
        toUpper(str));
88
89
    str = "";
90




8
    REQUIRE(toUpper(str).empty());
91
2
}
92
93
6
TEST_CASE("stringuntils atox 1", "")
94
{
95
8
    std::string str = "0x10";
96




8
    REQUIRE(16 == atox(str));
97
98
    str = "0x0";
99




8
    REQUIRE(0 == atox(str));
100
101
    str = "0x1";
102




8
    REQUIRE(1 == atox(str));
103
104
    str = "0x0x0x0x0x0x0x0";
105




8
    REQUIRE(0 == atox(str));
106
107
2
    str = "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
108
2
    const int k = atox(str);
109
2
    printf("%d\n", k);  // for avoid warning
110
111
    str = "";
112




8
    REQUIRE(0 == atox(str));
113
114
    str = "0";
115




8
    REQUIRE(0 == atox(str));
116
117
    str = "0x";
118




8
    REQUIRE(0 == atox(str));
119
120
    str = "zzz";
121




8
    REQUIRE(0 == atox(str));
122
2
}
123
124
6
TEST_CASE("stringuntils ipToString 1", "")
125
{
126




14
    REQUIRE("0.0.0.0" == std::string(ipToString(0)));
127




14
    REQUIRE("219.255.210.73" == std::string(ipToString(1238564827)));
128
2
}
129
130
6
TEST_CASE("stringuntils toString 1", "")
131
{
132




12
    REQUIRE(strprintf("%d", 0) == toString(0));
133




12
    REQUIRE(strprintf("%d", -1) == toString(-1));
134




12
    REQUIRE(strprintf("%d", 30000000) == toString(30000000));
135




12
    REQUIRE(strprintf("%d", -10000000) == toString(-10000000));
136




12
    REQUIRE(strprintf("%d", 30000000) == toString(
137
        static_cast<signed int>(30000000)));
138




12
    REQUIRE(strprintf("%d", 3000) == toString(CAST_U16(3000)));
139




12
    REQUIRE(strprintf("%d", 123) == toString(CAST_U8(123)));
140




12
    REQUIRE(strprintf("%u", static_cast<uint32_t>(30000000)) == toString(
141
        static_cast<uint32_t>(30000000)));
142




12
    REQUIRE(strprintf("%f", 3.1f) == toString(3.1f));
143




12
    REQUIRE(strprintf("%f", 3.1) == toString(3.1));
144
2
}
145
146
6
TEST_CASE("stringuntils toStringPrint 1", "")
147
{
148



10
    REQUIRE(toStringPrint(0) == "0 0x0");
149



10
    REQUIRE(toStringPrint(10) == "10 0xa");
150



10
    REQUIRE(toStringPrint(255) == "255 0xff");
151
2
}
152
153
6
TEST_CASE("stringuntils parse2Int 1", "")
154
{
155
2
    int a = -1;
156
2
    int b = -1;
157
158




14
    REQUIRE(parse2Int("", a, b) == false);
159



8
    REQUIRE(a == -1);
160



8
    REQUIRE(b == -1);
161
162
2
    a = -1;
163
2
    b = -1;
164




14
    REQUIRE(parse2Int(",", a, b) == false);
165



8
    REQUIRE(a == -1);
166



8
    REQUIRE(b == -1);
167
168
2
    a = -1;
169
2
    b = -1;
170




14
    REQUIRE(parse2Int("10,20", a, b) == true);
171



8
    REQUIRE(a == 10);
172



8
    REQUIRE(b == 20);
173
174
2
    a = -1;
175
2
    b = -1;
176




14
    REQUIRE(parse2Int("10 20", a, b) == true);
177



8
    REQUIRE(a == 10);
178



8
    REQUIRE(b == 20);
179
180
2
    a = -1;
181
2
    b = -1;
182




14
    REQUIRE(parse2Int("10 z20", a, b) == true);
183



8
    REQUIRE(a == 10);
184



8
    REQUIRE(b == 0);
185
2
}
186
187
6
TEST_CASE("stringuntils parse2Str 1", "")
188
{
189
8
    std::string str1 = "-";
190
8
    std::string str2 = "-";
191
192




14
    REQUIRE(parse2Str("", str1, str2) == false);
193



8
    REQUIRE(str1 == "-");
194



8
    REQUIRE(str2 == "-");
195
196




14
    REQUIRE(parse2Str(",", str1, str2) == false);
197



8
    REQUIRE(str1 == "-");
198



8
    REQUIRE(str2 == "-");
199
200
2
    str1 = "-";
201
    str2 = "-";
202




14
    REQUIRE(parse2Str("test line", str1, str2) == true);
203



8
    REQUIRE(str1 == "test");
204



8
    REQUIRE(str2 == "line");
205
206
2
    str1 = "-";
207
    str2 = "-";
208




14
    REQUIRE(parse2Str("test,line", str1, str2) == true);
209



8
    REQUIRE(str1 == "test");
210



8
    REQUIRE(str2 == "line");
211
2
}
212
213
6
TEST_CASE("stringuntils parseNumber 1", "")
214
{
215




14
    REQUIRE(parseNumber("") == 0);
216




14
    REQUIRE(parseNumber("0x") == 0);
217




14
    REQUIRE(parseNumber("10") == 10);
218




14
    REQUIRE(parseNumber("h10") == 16);
219




14
    REQUIRE(parseNumber("x100") == 256);
220




14
    REQUIRE(parseNumber("0x20") == 32);
221
2
}
222
223
6
TEST_CASE("stringuntils removeToken 1", "")
224
{
225
2
    std::string str;
226
227




16
    REQUIRE(removeToken(str, " ").empty());
228



8
    REQUIRE(str.empty());
229
230
    str = "test";
231




16
    REQUIRE(removeToken(str, " ").empty());
232



8
    REQUIRE(str.empty());
233
234
    str = "test line";
235




16
    REQUIRE(removeToken(str, " ") == "line");
236



8
    REQUIRE(str == "line");
237
238
    str = "test,line";
239




16
    REQUIRE(removeToken(str, ",") == "line");
240



8
    REQUIRE(str == "line");
241
242
    str = "test line";
243




16
    REQUIRE(removeToken(str, ",").empty());
244



8
    REQUIRE(str.empty());
245
246
    str = ",line";
247




16
    REQUIRE(removeToken(str, ",").empty());
248



8
    REQUIRE(str.empty());
249
2
}
250
251
6
TEST_CASE("stringuntils strprintf 1", "")
252
{
253



10
    REQUIRE(strprintf("%s very long string. 123456789012345678901234567890"
254
        "+++++++++++++++++++++++++++++++++++++++"
255
        "________________________________"
256
        "***********************************"
257
        "----------------------------------------"
258
        "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| %s",
259
        "test", "end of test") ==
260
        "test very long string. 123456789012345678901234567890"
261
        "+++++++++++++++++++++++++++++++++++++++"
262
        "________________________________"
263
        "***********************************"
264
        "----------------------------------------"
265
        "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| "
266
        "end of test");
267
2
}
268
269
6
TEST_CASE("stringuntils toString 2", "")
270
{
271
162604
    for (int f = 0; f < 10000000; f += 123)
272
    {
273




975612
        REQUIRE(strprintf("%d", f) == toString(f));
274
    }
275
2
}
276
277
6
TEST_CASE("stringuntils removeColors 1", "")
278
{
279




16
    REQUIRE(removeColors("").empty());
280




16
    REQUIRE("#" == removeColors("#"));
281




16
    REQUIRE("##" == removeColors("##"));
282




16
    REQUIRE(removeColors("##1").empty());
283




16
    REQUIRE("2" == removeColors("##12"));
284




16
    REQUIRE("1##" == removeColors("1##"));
285




16
    REQUIRE("1" == removeColors("1##2"));
286




16
    REQUIRE("13" == removeColors("1##23"));
287




16
    REQUIRE("#1#2" == removeColors("#1#2"));
288




16
    REQUIRE("#1" == removeColors("#1##2"));
289
2
}
290
291
6
TEST_CASE("stringuntils compareStrI 1", "")
292
{
293
4
    std::string str1;
294
2
    std::string str2;
295




8
    REQUIRE(0 == compareStrI(str1, str2));
296
297
2
    str1 = "test";
298
    str2 = "test";
299




8
    REQUIRE(0 == compareStrI(str1, str2));
300
301
2
    str1 = "test";
302
    str2 = "test1";
303




8
    REQUIRE(0 > compareStrI(str1, str2));
304
305
2
    str1 = "test";
306
    str2 = "aest1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
307




8
    REQUIRE(0 < compareStrI(str1, str2));
308
309
2
    str1 = "testaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
310
    str2 = "testaa";
311




8
    REQUIRE(0 < compareStrI(str1, str2));
312
2
}
313
314
6
TEST_CASE("stringuntils isWordSeparator 1", "")
315
{
316



6
    REQUIRE(isWordSeparator(' '));
317



6
    REQUIRE(isWordSeparator(','));
318



6
    REQUIRE(isWordSeparator('.'));
319



6
    REQUIRE(isWordSeparator('\"'));
320



6
    REQUIRE(!isWordSeparator(0));
321



6
    REQUIRE(!isWordSeparator('a'));
322



6
    REQUIRE(!isWordSeparator('-'));
323
2
}
324
325
6
TEST_CASE("stringuntils findSameSubstring", "")
326
{
327
4
    std::string str1;
328
2
    std::string str2;
329
330





22
    REQUIRE(findSameSubstring("", "").empty());
331
332
2
    str1 = "test line";
333
    str2 = "test line";
334




10
    REQUIRE("test line" == findSameSubstring(str1, str2));
335
336
2
    str1 = "test li";
337
    str2 = "test line";
338




10
    REQUIRE("test li" == findSameSubstring(str1, str2));
339
340
2
    str1 = "test li";
341
    str2 = "est li";
342




10
    REQUIRE(findSameSubstring(str1, str2).empty());
343
2
}
344
345
6
TEST_CASE("stringuntils findSameSubstringI", "")
346
{
347
4
    std::string str1;
348
2
    std::string str2;
349
350





22
    REQUIRE(findSameSubstringI("", "").empty());
351
352
2
    str1 = "tEst line";
353
    str2 = "tesT line";
354




10
    REQUIRE("tEst line" == findSameSubstringI(str1, str2));
355
356
2
    str1 = "test Li";
357
    str2 = "test lINe";
358




10
    REQUIRE("test Li" == findSameSubstringI(str1, str2));
359
360
2
    str1 = "test lINe";
361
    str2 = "test Li";
362




10
    REQUIRE("test lI" == findSameSubstringI(str1, str2));
363
364
2
    str1 = "teSt li";
365
    str2 = "est li";
366




10
    REQUIRE(findSameSubstringI(str1, str2).empty());
367
2
}
368
369
6
TEST_CASE("stringuntils findI 1", "")
370
{
371




20
    REQUIRE(0 == findI("", ""));
372




20
    REQUIRE(std::string::npos == findI("test", "line"));
373




20
    REQUIRE(0 == findI("test line", "t"));
374




20
    REQUIRE(0 == findI("test line", "te"));
375




20
    REQUIRE(3 == findI("test line", "t l"));
376
2
}
377
378
6
TEST_CASE("stringuntils findI 2", "")
379
{
380
4
    STD_VECTOR <std::string> vect1;
381
10
    vect1.push_back("test");
382
10
    vect1.push_back("line");
383
10
    vect1.push_back("qwe");
384
385




14
    REQUIRE(std::string::npos == findI("", vect1));
386




14
    REQUIRE(0 == findI("test", vect1));
387




14
    REQUIRE(0 == findI("tesT lIne", vect1));
388




14
    REQUIRE(5 == findI("teoT line", vect1));
389




14
    REQUIRE(std::string::npos == findI("zzz", vect1));
390
2
}
391
392
6
TEST_CASE("stringuntils encodeStr 1", "")
393
{
394
4
    std::string str = encodeStr(10, 1);
395




8
    REQUIRE(10 == decodeStr(str));
396
397
    str.clear();
398




8
    REQUIRE(0 == decodeStr(str));
399
400
6
    str = encodeStr(10, 2);
401




8
    REQUIRE(10 == decodeStr(str));
402
403
6
    str = encodeStr(100, 3);
404




8
    REQUIRE(100 == decodeStr(str));
405
406
6
    str = encodeStr(1000, 4);
407




8
    REQUIRE(1000 == decodeStr(str));
408
2
}
409
410
6
TEST_CASE("stringuntils extractNameFromSprite 1", "")
411
{
412




16
    REQUIRE(extractNameFromSprite("").empty());
413




16
    REQUIRE("test" == extractNameFromSprite("test"));
414




16
    REQUIRE("test" == extractNameFromSprite("test.qwe"));
415




16
    REQUIRE("line" == extractNameFromSprite("test/line.zzz"));
416




16
    REQUIRE("line" == extractNameFromSprite("test\\line.zzz"));
417




16
    REQUIRE("line" == extractNameFromSprite("test/test2\\line.zzz"));
418




16
    REQUIRE("line" == extractNameFromSprite("test\\test2/line.zzz"));
419
2
}
420
421
6
TEST_CASE("stringuntils removeSpriteIndex 1", "")
422
{
423




16
    REQUIRE(removeSpriteIndex("").empty());
424




16
    REQUIRE("test" == removeSpriteIndex("test"));
425




16
    REQUIRE("test" == removeSpriteIndex("test[1]"));
426




16
    REQUIRE("line" == removeSpriteIndex("test/line[12]"));
427




16
    REQUIRE("line" == removeSpriteIndex("test\\line[12]"));
428




16
    REQUIRE("line" == removeSpriteIndex("test/test2\\line[12]"));
429




16
    REQUIRE("line" == removeSpriteIndex("test\\test2/line[1]"));
430
2
}
431
432
6
TEST_CASE("stringutils getSafeUtf8String 1", "")
433
{
434
    const char *str;
435

8
    str = getSafeUtf8String("");
436



8
    REQUIRE(str != nullptr);
437



8
    REQUIRE(strcmp("", str) == 0);
438



8
    REQUIRE(str[0] == '\0');
439



8
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
440
2
    delete [] str;
441
442

8
    str = getSafeUtf8String("test line");
443



8
    REQUIRE(str != nullptr);
444



8
    REQUIRE(strcmp("test line", str) == 0);
445



8
    REQUIRE(str[strlen("test line")] == '\0');
446



8
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
447
2
    delete [] str;
448
449

8
    str = getSafeUtf8String("1");
450



8
    REQUIRE(str != nullptr);
451



8
    REQUIRE(strcmp("1", str) == 0);
452



8
    REQUIRE(str[1] == '\0');
453



8
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
454
2
    delete [] str;
455
2
}
456
457
6
TEST_CASE("stringutils getSafeUtf8String 2", "")
458
{
459
    char *str;
460
461

8
    getSafeUtf8String("test", nullptr);
462
463
2
    str = new char[65535];
464

8
    getSafeUtf8String("", str);
465



8
    REQUIRE(str != nullptr);
466



8
    REQUIRE(strcmp("", str) == 0);
467



8
    REQUIRE(str[0] == '\0');
468



8
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
469
2
    delete [] str;
470
471
2
    str = new char[65535];
472

8
    getSafeUtf8String("test line", str);
473



8
    REQUIRE(str != nullptr);
474



8
    REQUIRE(strcmp("test line", str) == 0);
475



8
    REQUIRE(str[strlen("test line")] == '\0');
476



8
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
477
2
    delete [] str;
478
479
2
    str = new char[65535];
480

8
    getSafeUtf8String("1", str);
481



8
    REQUIRE(str != nullptr);
482



8
    REQUIRE(strcmp("1", str) == 0);
483



8
    REQUIRE(str[1] == '\0');
484



8
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
485
2
    delete [] str;
486
487
2
    str = new char[65535];
488
2
    char *data1 = new char[65510];
489
2
    memset(data1, 'a', 65510);
490
2
    data1[65509] = '\0';
491
2
    char *data2 = new char[65510];
492
2
    memset(data2, 'a', 65500);
493
2
    data2[65500] = '\0';
494

8
    getSafeUtf8String(data1, str);
495



8
    REQUIRE(str != nullptr);
496



8
    REQUIRE(strcmp(data2, str) == 0);
497



8
    REQUIRE(str[65500] == '\0');
498
2
    delete [] data1;
499
2
    delete [] data2;
500
2
    delete [] str;
501
2
}
502
503
6
TEST_CASE("stringuntils getFileName 1", "")
504
{
505




16
    REQUIRE(getFileName("").empty());
506




16
    REQUIRE("file" == getFileName("file"));
507




16
    REQUIRE("file" == getFileName("test/file1\\file"));
508




16
    REQUIRE("file" == getFileName("test\\file1/file"));
509




16
    REQUIRE(getFileName("file/").empty());
510




16
    REQUIRE("file" == getFileName("/file"));
511
2
}
512
513
6
TEST_CASE("stringuntils getFileDir 1", "")
514
{
515




16
    REQUIRE(getFileDir("").empty());
516




16
    REQUIRE("file" == getFileDir("file"));
517




16
    REQUIRE("test/file1" == getFileDir("test/file1\\file"));
518




16
    REQUIRE("test\\file1" == getFileDir("test\\file1/file"));
519




16
    REQUIRE("file" == getFileDir("file/"));
520




16
    REQUIRE(getFileDir("/file").empty());
521
2
}
522
523
6
TEST_CASE("stringuntils replaceAll 1", "")
524
{
525
4
    std::string str1;
526
4
    std::string str2;
527
2
    std::string str3;
528
529




8
    REQUIRE(replaceAll(str1, str2, str3).empty());
530
531
2
    str1 = "this is test line";
532
2
    str2 = "";
533
    str3 = "";
534




8
    REQUIRE("this is test line" == replaceAll(str1, str2, str3));
535
536
2
    str1 = "this is test line";
537
2
    str2 = "is ";
538
    str3 = "";
539




8
    REQUIRE("thtest line" == replaceAll(str1, str2, str3));
540
541
2
    str1 = "this is test line";
542
2
    str2 = "";
543
    str3 = "1";
544




8
    REQUIRE("this is test line" == replaceAll(str1, str2, str3));
545
2
}
546
547
6
TEST_CASE("stringuntils replaceRecursiveAll 1", "")
548
{
549
4
    std::string str;
550
2
    str = "";
551

8
    replaceRecursiveAll(str, "line", '.');
552



8
    REQUIRE(str.empty());
553
2
    str = "test line";
554

8
    replaceRecursiveAll(str, "line", '.');
555



8
    REQUIRE(str == "test .");
556
2
    str = "11112222";
557

8
    replaceRecursiveAll(str, "11", '1');
558



8
    REQUIRE(str == "12222");
559
2
    str = "122221";
560

8
    replaceRecursiveAll(str, "11", '1');
561



8
    REQUIRE(str == "122221");
562
2
    str = "1222211";
563

8
    replaceRecursiveAll(str, "11", '1');
564



8
    REQUIRE(str == "122221");
565
2
    str = "11112222";
566

8
    replaceRecursiveAll(str, "112", '1');
567



8
    REQUIRE(str == "111222");
568
2
    str = "111122224";
569

8
    replaceRecursiveAll(str, "112", '1');
570



8
    REQUIRE(str == "1112224");
571
2
    str = "3111122224";
572

8
    replaceRecursiveAll(str, "112", '1');
573



8
    REQUIRE(str == "31112224");
574
2
    str = "121212";
575

8
    replaceRecursiveAll(str, "12", '1');
576



8
    REQUIRE(str == "111");
577
2
    str = "1121212";
578

8
    replaceRecursiveAll(str, "12", '1');
579



8
    REQUIRE(str == "1111");
580
2
    str = "11212122";
581

8
    replaceRecursiveAll(str, "12", '1');
582



8
    REQUIRE(str == "1111");
583
2
    str = "112121222";
584

8
    replaceRecursiveAll(str, "12", '1');
585



8
    REQUIRE(str == "1111");
586
2
    str = "112211221122";
587

8
    replaceRecursiveAll(str, "12", '1');
588



8
    REQUIRE(str == "111111");
589
2
}
590
591
6
TEST_CASE("stringuntils getBoolFromString 1", "")
592
{
593




12
    REQUIRE(getBoolFromString("true"));
594




12
    REQUIRE(getBoolFromString("yes"));
595




12
    REQUIRE(getBoolFromString("on"));
596




12
    REQUIRE(!getBoolFromString("false"));
597




12
    REQUIRE(!getBoolFromString("no"));
598




12
    REQUIRE(!getBoolFromString("off"));
599




12
    REQUIRE(getBoolFromString("1"));
600




12
    REQUIRE(!getBoolFromString("0"));
601




12
    REQUIRE(getBoolFromString("2"));
602
603




12
    REQUIRE(getBoolFromString(" true"));
604




12
    REQUIRE(getBoolFromString("yes "));
605




12
    REQUIRE(getBoolFromString(" on"));
606




12
    REQUIRE(!getBoolFromString("false "));
607




12
    REQUIRE(!getBoolFromString(" no"));
608




12
    REQUIRE(!getBoolFromString("off "));
609




12
    REQUIRE(getBoolFromString(" 1"));
610




12
    REQUIRE(!getBoolFromString("0 "));
611




12
    REQUIRE(getBoolFromString(" 2"));
612
613




12
    REQUIRE(getBoolFromString("tRue "));
614




12
    REQUIRE(getBoolFromString(" Yes"));
615




12
    REQUIRE(getBoolFromString("ON "));
616




12
    REQUIRE(!getBoolFromString(" fALse"));
617




12
    REQUIRE(!getBoolFromString("nO "));
618




12
    REQUIRE(!getBoolFromString(" oFF"));
619
2
}
620
621
6
TEST_CASE("stringuntils parseBoolean 1", "")
622
{
623




14
    REQUIRE(parseBoolean("true") == 1);
624




14
    REQUIRE(parseBoolean("yes") == 1);
625




14
    REQUIRE(parseBoolean("on") == 1);
626




14
    REQUIRE(parseBoolean("false") == 0);
627




14
    REQUIRE(parseBoolean("no") == 0);
628




14
    REQUIRE(parseBoolean("off") == 0);
629




14
    REQUIRE(parseBoolean("1") == 1);
630




14
    REQUIRE(parseBoolean("0") == 0);
631




14
    REQUIRE(parseBoolean("2") == -1);
632




14
    REQUIRE(parseBoolean("test") == -1);
633




14
    REQUIRE(parseBoolean("") == -1);
634
635




14
    REQUIRE(parseBoolean("true ") == 1);
636




14
    REQUIRE(parseBoolean(" yes") == 1);
637




14
    REQUIRE(parseBoolean("on ") == 1);
638




14
    REQUIRE(parseBoolean(" false") == 0);
639




14
    REQUIRE(parseBoolean("no ") == 0);
640




14
    REQUIRE(parseBoolean(" off") == 0);
641




14
    REQUIRE(parseBoolean("1 ") == 1);
642




14
    REQUIRE(parseBoolean(" 0") == 0);
643




14
    REQUIRE(parseBoolean("2 ") == -1);
644




14
    REQUIRE(parseBoolean(" test") == -1);
645




14
    REQUIRE(parseBoolean(" ") == -1);
646
647




12
    REQUIRE(parseBoolean(" tRue") == 1);
648




14
    REQUIRE(parseBoolean("Yes ") == 1);
649




14
    REQUIRE(parseBoolean(" ON") == 1);
650




14
    REQUIRE(parseBoolean("FaLse ") == 0);
651




14
    REQUIRE(parseBoolean(" nO") == 0);
652




14
    REQUIRE(parseBoolean("oFf ") == 0);
653




14
    REQUIRE(parseBoolean(" tEst") == -1);
654
2
}
655
656
6
TEST_CASE("stringuntils splitToIntSet 1", "")
657
{
658
4
    std::set<int> tokens;
659

8
    splitToIntSet(tokens, "", ',');
660



10
    REQUIRE(tokens.empty() == true);
661
662
2
    tokens.clear();
663

8
    splitToIntSet(tokens, "10z,aa,-1", ',');
664



10
    REQUIRE(tokens.size() == 3);
665



12
    REQUIRE(tokens.find(10) != tokens.end());
666



12
    REQUIRE(tokens.find(0) != tokens.end());
667



12
    REQUIRE(tokens.find(-1) != tokens.end());
668
669
2
    tokens.clear();
670

8
    splitToIntSet(tokens, "10,2,30", ',');
671



10
    REQUIRE(tokens.size() == 3);
672



12
    REQUIRE(tokens.find(10) != tokens.end());
673



12
    REQUIRE(tokens.find(2) != tokens.end());
674



12
    REQUIRE(tokens.find(30) != tokens.end());
675
676
2
    tokens.clear();
677

8
    splitToIntSet(tokens, "10,2,30,", ',');
678



10
    REQUIRE(tokens.size() == 3);
679



12
    REQUIRE(tokens.find(10) != tokens.end());
680



12
    REQUIRE(tokens.find(2) != tokens.end());
681



12
    REQUIRE(tokens.find(30) != tokens.end());
682
683
2
    tokens.clear();
684

8
    splitToIntSet(tokens, "10,2;30", ',');
685



10
    REQUIRE(tokens.size() == 2);
686



12
    REQUIRE(tokens.find(10) != tokens.end());
687



12
    REQUIRE(tokens.find(2) != tokens.end());
688
689
2
    tokens.clear();
690

8
    splitToIntSet(tokens, "10;20;30", ';');
691



10
    REQUIRE(tokens.size() == 3);
692



12
    REQUIRE(tokens.find(10) != tokens.end());
693



12
    REQUIRE(tokens.find(20) != tokens.end());
694



12
    REQUIRE(tokens.find(30) != tokens.end());
695
2
}
696
697
6
TEST_CASE("stringuntils splitToIntList 1", "")
698
{
699
4
    std::list<int> tokens;
700

12
    tokens = splitToIntList("", ',');
701



10
    REQUIRE(tokens.empty() == true);
702
703
2
    tokens.clear();
704

12
    tokens = splitToIntList("10z,a,-1", ',');
705



10
    REQUIRE(tokens.size() == 3);
706



10
    REQUIRE(tokens.front() == 10);
707
2
    tokens.pop_front();
708



10
    REQUIRE(tokens.front() == 0);
709
2
    tokens.pop_front();
710



10
    REQUIRE(tokens.front() == -1);
711
2
    tokens.pop_front();
712
713
2
    tokens.clear();
714

12
    tokens = splitToIntList("10,2,30", ',');
715



10
    REQUIRE(tokens.size() == 3);
716



10
    REQUIRE(tokens.front() == 10);
717
2
    tokens.pop_front();
718



10
    REQUIRE(tokens.front() == 2);
719
2
    tokens.pop_front();
720



10
    REQUIRE(tokens.front() == 30);
721
2
    tokens.pop_front();
722
723
2
    tokens.clear();
724

12
    tokens = splitToIntList("10,2,30,", ',');
725



10
    REQUIRE(tokens.size() == 3);
726



10
    REQUIRE(tokens.front() == 10);
727
2
    tokens.pop_front();
728



10
    REQUIRE(tokens.front() == 2);
729
2
    tokens.pop_front();
730



10
    REQUIRE(tokens.front() == 30);
731
2
    tokens.pop_front();
732
733
2
    tokens.clear();
734

12
    tokens = splitToIntList("10,2;30", ',');
735



10
    REQUIRE(tokens.size() == 2);
736



10
    REQUIRE(tokens.front() == 10);
737
2
    tokens.pop_front();
738



10
    REQUIRE(tokens.front() == 2);
739
2
    tokens.pop_front();
740
741
2
    tokens.clear();
742

12
    tokens = splitToIntList("10;20;30", ';');
743



10
    REQUIRE(tokens.size() == 3);
744



10
    REQUIRE(tokens.front() == 10);
745
2
    tokens.pop_front();
746



10
    REQUIRE(tokens.front() == 20);
747
2
    tokens.pop_front();
748



10
    REQUIRE(tokens.front() == 30);
749
2
    tokens.pop_front();
750
2
}
751
752
6
TEST_CASE("stringuntils splitToStringSet 1", "")
753
{
754
4
    std::set<std::string> tokens;
755

8
    splitToStringSet(tokens, "", ',');
756



10
    REQUIRE(tokens.empty() == true);
757
758
2
    tokens.clear();
759

8
    splitToStringSet(tokens, "10q,2w,30e", ',');
760



10
    REQUIRE(tokens.size() == 3);
761




18
    REQUIRE(tokens.find("10q") != tokens.end());
762




18
    REQUIRE(tokens.find("2w") != tokens.end());
763




18
    REQUIRE(tokens.find("30e") != tokens.end());
764
765
2
    tokens.clear();
766

8
    splitToStringSet(tokens, "10q,2w,30e,", ',');
767



10
    REQUIRE(tokens.size() == 3);
768




18
    REQUIRE(tokens.find("10q") != tokens.end());
769




18
    REQUIRE(tokens.find("2w") != tokens.end());
770




18
    REQUIRE(tokens.find("30e") != tokens.end());
771
772
2
    tokens.clear();
773

8
    splitToStringSet(tokens, "10q,,30e", ',');
774



10
    REQUIRE(tokens.size() == 2);
775




18
    REQUIRE(tokens.find("10q") != tokens.end());
776




18
    REQUIRE(tokens.find("30e") != tokens.end());
777
778
2
    tokens.clear();
779

8
    splitToStringSet(tokens, "10q,2w,30e,", ',');
780



10
    REQUIRE(tokens.size() == 3);
781




18
    REQUIRE(tokens.find("10q") != tokens.end());
782




18
    REQUIRE(tokens.find("2w") != tokens.end());
783




18
    REQUIRE(tokens.find("30e") != tokens.end());
784
785
2
    tokens.clear();
786

8
    splitToStringSet(tokens, "10w,2w;30e", ',');
787



10
    REQUIRE(tokens.size() == 2);
788




18
    REQUIRE(tokens.find("10w") != tokens.end());
789




18
    REQUIRE(tokens.find("2w;30e") != tokens.end());
790
791
2
    tokens.clear();
792

8
    splitToStringSet(tokens, "10q;20w;30e", ';');
793



10
    REQUIRE(tokens.size() == 3);
794




18
    REQUIRE(tokens.find("10q") != tokens.end());
795




18
    REQUIRE(tokens.find("20w") != tokens.end());
796




18
    REQUIRE(tokens.find("30e") != tokens.end());
797
2
}
798
799
6
TEST_CASE("stringuntils splitToIntVector 1", "")
800
{
801
4
    STD_VECTOR<int> tokens;
802

8
    splitToIntVector(tokens, "", ',');
803



10
    REQUIRE(tokens.empty() == true);
804
805
2
    tokens.clear();
806

8
    splitToIntVector(tokens, "10,2,30", ',');
807



10
    REQUIRE(tokens.size() == 3);
808



8
    REQUIRE(tokens[0] == 10);
809



10
    REQUIRE(tokens[1] == 2);
810



10
    REQUIRE(tokens[2] == 30);
811
812
2
    tokens.clear();
813

8
    splitToIntVector(tokens, "10,2a,z30", ',');
814



10
    REQUIRE(tokens.size() == 3);
815



8
    REQUIRE(tokens[0] == 10);
816



10
    REQUIRE(tokens[1] == 2);
817



10
    REQUIRE(tokens[2] == 0);
818
819
2
    tokens.clear();
820

8
    splitToIntVector(tokens, "10,2,30,", ',');
821



10
    REQUIRE(tokens.size() == 3);
822



8
    REQUIRE(tokens[0] == 10);
823



10
    REQUIRE(tokens[1] == 2);
824



10
    REQUIRE(tokens[2] == 30);
825
826
2
    tokens.clear();
827

8
    splitToIntVector(tokens, "10,,30", ',');
828



10
    REQUIRE(tokens.size() == 2);
829



8
    REQUIRE(tokens[0] == 10);
830



10
    REQUIRE(tokens[1] == 30);
831
832
2
    tokens.clear();
833

8
    splitToIntVector(tokens, "10,2;30", ',');
834



10
    REQUIRE(tokens.size() == 2);
835



8
    REQUIRE(tokens[0] == 10);
836



10
    REQUIRE(tokens[1] == 2);
837
838
2
    tokens.clear();
839

8
    splitToIntVector(tokens, "10;20;30", ';');
840



10
    REQUIRE(tokens.size() == 3);
841



8
    REQUIRE(tokens[0] == 10);
842



10
    REQUIRE(tokens[1] == 20);
843



10
    REQUIRE(tokens[2] == 30);
844
2
}
845
846
6
TEST_CASE("stringuntils splitToStringVector 1", "")
847
{
848
4
    STD_VECTOR<std::string> tokens;
849

8
    splitToStringVector(tokens, "", ',');
850



10
    REQUIRE(tokens.empty() == true);
851
852
2
    tokens.clear();
853

8
    splitToStringVector(tokens, "t,line,zz", ',');
854



10
    REQUIRE(tokens.size() == 3);
855



8
    REQUIRE(tokens[0] == "t");
856



10
    REQUIRE(tokens[1] == "line");
857



10
    REQUIRE(tokens[2] == "zz");
858
859
2
    tokens.clear();
860

8
    splitToStringVector(tokens, "t,line,zz,", ',');
861



10
    REQUIRE(tokens.size() == 3);
862



8
    REQUIRE(tokens[0] == "t");
863



10
    REQUIRE(tokens[1] == "line");
864



10
    REQUIRE(tokens[2] == "zz");
865
866
2
    tokens.clear();
867

8
    splitToStringVector(tokens, "t,,zz", ',');
868



10
    REQUIRE(tokens.size() == 2);
869



8
    REQUIRE(tokens[0] == "t");
870



10
    REQUIRE(tokens[1] == "zz");
871
872
2
    tokens.clear();
873

8
    splitToStringVector(tokens, "10,a2;30", ',');
874



10
    REQUIRE(tokens.size() == 2);
875



8
    REQUIRE(tokens[0] == "10");
876



10
    REQUIRE(tokens[1] == "a2;30");
877
878
2
    tokens.clear();
879

8
    splitToStringVector(tokens, "a10;b;3line", ';');
880



10
    REQUIRE(tokens.size() == 3);
881



8
    REQUIRE(tokens[0] == "a10");
882



10
    REQUIRE(tokens[1] == "b");
883



10
    REQUIRE(tokens[2] == "3line");
884
2
}
885
886
6
TEST_CASE("stringuntils replaceSpecialChars 1", "")
887
{
888
4
    std::string str;
889
890
2
    str = "";
891
2
    replaceSpecialChars(str);
892



8
    REQUIRE(str.empty());
893
894
2
    str = "test";
895
2
    replaceSpecialChars(str);
896



8
    REQUIRE("test" == str);
897
898
2
    str = "&";
899
2
    replaceSpecialChars(str);
900



8
    REQUIRE("&" == str);
901
902
2
    str = "&1";
903
2
    replaceSpecialChars(str);
904



8
    REQUIRE("&1" == str);
905
906
2
    str = "&33";
907
2
    replaceSpecialChars(str);
908



8
    REQUIRE("&33" == str);
909
910
2
    str = "&33;";
911
2
    replaceSpecialChars(str);
912



8
    REQUIRE("!" == str);
913
914
2
    str = "&33z;";
915
2
    replaceSpecialChars(str);
916



8
    REQUIRE("&33z;" == str);
917
918
2
    str = "1&33;";
919
2
    replaceSpecialChars(str);
920



8
    REQUIRE("1!" == str);
921
922
2
    str = "&33;2";
923
2
    replaceSpecialChars(str);
924



8
    REQUIRE("!2" == str);
925
926
2
    str = "&33;&";
927
2
    replaceSpecialChars(str);
928



8
    REQUIRE("!&" == str);
929
930
2
    str = "test line&33;";
931
2
    replaceSpecialChars(str);
932



8
    REQUIRE("test line!" == str);
933
2
}
934
935
6
TEST_CASE("stringuntils normalize 1", "")
936
{
937




16
    REQUIRE(normalize("").empty());
938




16
    REQUIRE(normalize("test") == "test");
939




16
    REQUIRE(normalize("Test") == "test");
940




16
    REQUIRE(normalize(" test line") == "test line");
941




16
    REQUIRE(normalize("test line ") == "test line");
942




16
    REQUIRE(normalize(" tEst line") == "test line");
943




16
    REQUIRE(normalize("test lIne ") == "test line");
944
2
}
945
946
6
TEST_CASE("stringuntils combineDye 1", "")
947
{
948




22
    REQUIRE(combineDye("", "").empty());
949




22
    REQUIRE("test" == combineDye("test", ""));
950




22
    REQUIRE("|line" == combineDye("", "line"));
951




22
    REQUIRE("test|line" == combineDye("test", "line"));
952




22
    REQUIRE("|line" == combineDye("|w", "line"));
953




22
    REQUIRE("aaa|line" == combineDye("aaa|w", "line"));
954




22
    REQUIRE("test|line" == combineDye("test|w", "line"));
955
2
}
956
957
6
TEST_CASE("stringuntils combineDye 2", "")
958
{
959




22
    REQUIRE(combineDye2("", "").empty());
960




22
    REQUIRE("test" == combineDye2("test", ""));
961




22
    REQUIRE("test" == combineDye2("test", "W"));
962




22
    REQUIRE(combineDye2("", "line").empty());
963




22
    REQUIRE("test.xml" == combineDye2("test.xml", "123"));
964




22
    REQUIRE("test.xml|#43413d,59544f,7a706c" ==
965
        combineDye2("test.xml|#43413d,59544f,7a706c", ""));
966




22
    REQUIRE("test.xml|#43413d,59544f,7a706c:W;" ==
967
        combineDye2("test.xml|#43413d,59544f,7a706c", "W"));
968




22
    REQUIRE("test.xml|#43413d,59544f,7a706c:W;#123456:B;" ==
969
        combineDye2("test.xml|#43413d,59544f,7a706c;#123456", "W;B"));
970
2
}
971
972
6
TEST_CASE("stringuntils combineDye 3", "")
973
{
974




22
    REQUIRE(combineDye3("", "").empty());
975




22
    REQUIRE("test" == combineDye3("test", ""));
976




22
    REQUIRE(combineDye3("", "line").empty());
977




22
    REQUIRE("test.xml|123" == combineDye3("test.xml", "123"));
978




22
    REQUIRE("test.xml|#43413d,59544f,7a706c" ==
979
        combineDye3("test.xml|#43413d,59544f,7a706c", ""));
980




22
    REQUIRE("test.xml|#43413d,59544f,7a706c:W;" ==
981
        combineDye3("test.xml|#43413d,59544f,7a706c", "W"));
982




22
    REQUIRE("test.xml|#43413d,59544f,7a706c:W;#123456:B;" ==
983
        combineDye3("test.xml|#43413d,59544f,7a706c;#123456", "W;B"));
984
2
}
985
986
6
TEST_CASE("stringuntils packList 1", "")
987
{
988
2
    std::list <std::string> list;
989




10
    REQUIRE(packList(list).empty());
990
991
4
    list.push_back(std::string());
992




10
    REQUIRE("|" == packList(list));
993
994
2
    list.clear();
995

8
    list.push_back("test");
996




10
    REQUIRE("test" == packList(list));
997
998

8
    list.push_back("line");
999




10
    REQUIRE("test|line" == packList(list));
1000
1001

8
    list.push_back("2");
1002




10
    REQUIRE("test|line|2" == packList(list));
1003
1004
2
    list.clear();
1005

8
    list.push_back("|test");
1006

8
    list.push_back("line");
1007




10
    REQUIRE("|test|line" == packList(list));
1008
2
}
1009
1010
6
TEST_CASE("stringuntils stringToHexPath 1", "")
1011
{
1012
4
    std::string str;
1013
1014
    str = "";
1015




10
    REQUIRE(stringToHexPath(str).empty());
1016
1017
    str = "a";
1018




10
    REQUIRE("%61/" == stringToHexPath(str));
1019
1020
    str = "ab";
1021




10
    REQUIRE("%61/%62" == stringToHexPath(str));
1022
1023
    str = "abc";
1024




10
    REQUIRE("%61/%62%63" == stringToHexPath(str));
1025
1026
    str = "abcd";
1027




10
    REQUIRE("%61/%62%63%64" == stringToHexPath(str));
1028
2
}
1029
1030
6
TEST_CASE("stringuntils deleteCharLeft 1", "")
1031
{
1032
4
    std::string str;
1033
2
    unsigned int pos = 0;
1034
1035
2
    str = "";
1036
2
    deleteCharLeft(str, nullptr);
1037



8
    REQUIRE(str.empty());
1038
1039
2
    str = "test line";
1040
2
    pos = 4;
1041
2
    deleteCharLeft(str, &pos);
1042



8
    REQUIRE("tes line" == str);
1043
1044
2
    str = "тест line";
1045
2
    pos = 8;
1046
2
    deleteCharLeft(str, &pos);
1047



8
    REQUIRE("тес line" == str);
1048
1049
2
    str = "test line\x0";
1050
2
    pos = 4;
1051
2
    deleteCharLeft(str, &pos);
1052



8
    REQUIRE("tes line\x0" == str);
1053
2
}
1054
1055
6
TEST_CASE("stringuntils findLast 1", "")
1056
{
1057
4
    std::string str;
1058
1059
    str = "";
1060




12
    REQUIRE(findLast(str, ""));
1061
1062
    str = "test line";
1063




12
    REQUIRE(findLast(str, "line"));
1064
1065
    str = "test line";
1066




12
    REQUIRE(!findLast(str, "lin"));
1067
2
}
1068
1069
6
TEST_CASE("stringuntils findFirst 1", "")
1070
{
1071
4
    std::string str;
1072
1073
    str = "";
1074




12
    REQUIRE(findFirst(str, ""));
1075
1076
    str = "test line";
1077




12
    REQUIRE(findFirst(str, "test"));
1078
1079
    str = "test";
1080




14
    REQUIRE(findFirst(str, "test line") == false);
1081
1082
    str = "test line";
1083




14
    REQUIRE(findFirst(str, "est") == false);
1084
2
}
1085
1086
6
TEST_CASE("stringuntils findCutLast 1", "")
1087
{
1088
4
    std::string str;
1089
1090
    str = "";
1091




12
    REQUIRE(findCutLast(str, ""));
1092



8
    REQUIRE(str.empty());
1093
1094
    str = "test line";
1095




12
    REQUIRE(findCutLast(str, "line"));
1096



8
    REQUIRE("test " == str);
1097
1098
    str = "test line";
1099




14
    REQUIRE(findCutLast(str, "lin") == false);
1100



8
    REQUIRE("test line" == str);
1101
1102
    str = "test";
1103




14
    REQUIRE(findCutLast(str, "test line") == false);
1104



8
    REQUIRE("test" == str);
1105
2
}
1106
1107
6
TEST_CASE("stringuntils CutLast 1", "")
1108
{
1109
4
    std::string str;
1110
1111
2
    str = "";
1112

8
    cutLast(str, "");
1113



8
    REQUIRE(str.empty());
1114
1115
2
    str = "test line";
1116

8
    cutLast(str, "line");
1117



8
    REQUIRE("test " == str);
1118
1119
2
    str = "test line";
1120

8
    cutLast(str, "lin");
1121



8
    REQUIRE("test line" == str);
1122
1123
2
    str = "test";
1124

8
    cutLast(str, "test line");
1125



8
    REQUIRE("test" == str);
1126
2
}
1127
1128
6
TEST_CASE("stringuntils findCutFirst 1", "")
1129
{
1130
4
    std::string str;
1131
1132
    str = "";
1133




12
    REQUIRE(findCutFirst(str, ""));
1134



8
    REQUIRE(str.empty());
1135
1136
    str = "test line";
1137




12
    REQUIRE(findCutFirst(str, "test"));
1138



8
    REQUIRE(" line" == str);
1139
1140
    str = "test line";
1141




14
    REQUIRE(findCutFirst(str, "est") == false);
1142



8
    REQUIRE("test line" == str);
1143
1144
    str = "test";
1145




14
    REQUIRE(findCutFirst(str, "test line") == false);
1146



8
    REQUIRE("test" == str);
1147
2
}
1148
1149
6
TEST_CASE("stringuntils cutFirst 1", "")
1150
{
1151
4
    std::string str;
1152
1153
2
    str = "";
1154

8
    cutFirst(str, "");
1155



8
    REQUIRE(str.empty());
1156
1157
2
    str = "test line";
1158

8
    cutFirst(str, "test");
1159



8
    REQUIRE(" line" == str);
1160
1161
2
    str = "test line";
1162

8
    cutFirst(str, "est");
1163



8
    REQUIRE("test line" == str);
1164
1165
2
    str = "test";
1166

8
    cutFirst(str, "test line");
1167



8
    REQUIRE("test" == str);
1168
2
}
1169
1170
6
TEST_CASE("stringuntils removeProtocol 1", "")
1171
{
1172
4
    std::string str;
1173
1174
    str = "";
1175




8
    REQUIRE(removeProtocol(str).empty());
1176
1177
    str = "http://";
1178




8
    REQUIRE(removeProtocol(str).empty());
1179
1180
    str = "http://test";
1181




8
    REQUIRE("test" == removeProtocol(str));
1182
2
}
1183
1184
6
TEST_CASE("stringuntils strStartWith 1", "")
1185
{
1186




18
    REQUIRE(strStartWith("", ""));
1187




18
    REQUIRE(!strStartWith("", "1"));
1188




18
    REQUIRE(strStartWith("test line", "test"));
1189




18
    REQUIRE(strStartWith("test line", "test line"));
1190




18
    REQUIRE(!strStartWith("test line", "est"));
1191
2
}
1192
1193
6
TEST_CASE("stringuntils encodeLinkText", "")
1194
{
1195
4
    std::string str;
1196
1197

10
    str = encodeLinkText("test line");
1198



8
    REQUIRE(str == "test line");
1199

10
    str = encodeLinkText("test|line");
1200



8
    REQUIRE(str == "test\342\235\230line");
1201

10
    str = encodeLinkText("test||line");
1202



8
    REQUIRE(str == "test\342\235\230\342\235\230line");
1203
2
}
1204
1205
6
TEST_CASE("stringuntils decodeLinkText", "")
1206
{
1207
4
    std::string str;
1208
1209

10
    str = encodeLinkText("test|line");
1210



8
    REQUIRE(str == "test\342\235\230line");
1211
6
    str = decodeLinkText(str);
1212



8
    REQUIRE(str == "test|line");
1213
2
}
1214
1215
6
TEST_CASE("stringuntils isDigit", "")
1216
{
1217




12
    REQUIRE_FALSE(isDigit(""));
1218




12
    REQUIRE(isDigit("1"));
1219




12
    REQUIRE(isDigit("123"));
1220




12
    REQUIRE_FALSE(isDigit("+123"));
1221




12
    REQUIRE_FALSE(isDigit("-123"));
1222




12
    REQUIRE_FALSE(isDigit("1.23"));
1223




12
    REQUIRE_FALSE(isDigit("12-34"));
1224
2
}
1225
1226
6
TEST_CASE("stringuntils findAny", "")
1227
{
1228




20
    REQUIRE(findAny("test line", ",", 0) == std::string::npos);
1229




20
    REQUIRE(findAny("test line", " ", 0) == 4U);
1230




20
    REQUIRE(findAny("test, line", ", ", 0) == 4U);
1231




20
    REQUIRE(findAny("test ,line", ", ", 0) == 4U);
1232




20
    REQUIRE(findAny("test, line", " ,", 2) == 4U);
1233




20
    REQUIRE(findAny("test ,line", " ,", 3) == 4U);
1234




20
    REQUIRE(findAny("\"one\",,two, tree", ",", 5) == 5U);
1235
2
}
1236
1237
6
TEST_CASE("stringuntils escapeString", "")
1238
{
1239




16
    REQUIRE(escapeString("") == "\"\"");
1240




16
    REQUIRE(escapeString("1") == "\"1\"");
1241




16
    REQUIRE(escapeString(" ") == "\" \"");
1242




16
    REQUIRE(escapeString("\"") == "\"\\\"\"");
1243




16
    REQUIRE(escapeString("123") == "\"123\"");
1244




16
    REQUIRE(escapeString("12\"3") == "\"12\\\"3\"");
1245




16
    REQUIRE(escapeString("12\"\"3") == "\"12\\\"\\\"3\"");
1246




16
    REQUIRE(escapeString("\"123\"") == "\"\\\"123\\\"\"");
1247




16
    REQUIRE(escapeString("\\") == "\"\\\"");
1248




16
    REQUIRE(escapeString("12\\3") == "\"12\\3\"");
1249
2
}
1250
1251
6
TEST_CASE("stringuntils sanitizePath", "")
1252
{
1253
4
    std::string path;
1254
8
    const std::string sep = dirSeparator;
1255
2
    path = "";
1256
2
    sanitizePath(path);
1257



8
    REQUIRE(path.empty());
1258
2
    path = "/";
1259
2
    sanitizePath(path);
1260



8
    REQUIRE(path == dirSeparator);
1261
2
    path = "/\\";
1262
2
    sanitizePath(path);
1263



8
    REQUIRE(path == dirSeparator);
1264
2
    path = "\\/";
1265
2
    sanitizePath(path);
1266



8
    REQUIRE(path == dirSeparator);
1267
2
    path = "//";
1268
2
    sanitizePath(path);
1269



8
    REQUIRE(path == dirSeparator);
1270
2
    path = "///";
1271
2
    sanitizePath(path);
1272



8
    REQUIRE(path == dirSeparator);
1273
2
    path = "//\\/";
1274
2
    sanitizePath(path);
1275



8
    REQUIRE(path == dirSeparator);
1276
2
    path = "///\\";
1277
2
    sanitizePath(path);
1278



8
    REQUIRE(path == dirSeparator);
1279
2
    path = "\\";
1280
2
    sanitizePath(path);
1281



8
    REQUIRE(path == dirSeparator);
1282
2
    path = "\\\\";
1283
2
    sanitizePath(path);
1284



8
    REQUIRE(path == dirSeparator);
1285
2
    path = "\\/\\";
1286
2
    sanitizePath(path);
1287



8
    REQUIRE(path == dirSeparator);
1288
2
    path = "\\\\/";
1289
2
    sanitizePath(path);
1290



8
    REQUIRE(path == dirSeparator);
1291
2
    path = "test";
1292
2
    sanitizePath(path);
1293



8
    REQUIRE(path == "test");
1294
2
    path = "./test";
1295
2
    sanitizePath(path);
1296




12
    REQUIRE(path == "." + sep + "test");
1297
2
    path = "test line";
1298
2
    sanitizePath(path);
1299



8
    REQUIRE(path == "test line");
1300
2
    path = "dir/test";
1301
2
    sanitizePath(path);
1302




12
    REQUIRE(path == "dir" + sep + "test");
1303
2
    path = "/dir/test";
1304
2
    sanitizePath(path);
1305





14
    REQUIRE(path == sep + "dir" + sep + "test");
1306
2
    path = "dir//test";
1307
2
    sanitizePath(path);
1308




12
    REQUIRE(path == "dir" + sep + "test");
1309
2
    path = "dir///test";
1310
2
    sanitizePath(path);
1311




12
    REQUIRE(path == "dir" + sep + "test");
1312
2
    path = "dir///\\test";
1313
2
    sanitizePath(path);
1314




12
    REQUIRE(path == "dir" + sep + "test");
1315
2
    path = "dir/\\//test";
1316
2
    sanitizePath(path);
1317




12
    REQUIRE(path == "dir" + sep + "test");
1318
2
    path = "dir\\test";
1319
2
    sanitizePath(path);
1320




12
    REQUIRE(path == "dir" + sep + "test");
1321
2
    path = "dir/test/";
1322
2
    sanitizePath(path);
1323





14
    REQUIRE(path == "dir" + sep + "test" + sep);
1324
2
    path = "dir/test\\";
1325
2
    sanitizePath(path);
1326





14
    REQUIRE(path == "dir" + sep + "test" + sep);
1327
2
    path = "/very\\long/dir\\with\\sepa/ra/tors";
1328
2
    sanitizePath(path);
1329










34
    REQUIRE(path == sep + "very" + sep + "long" + sep + \
1330
        "dir" + sep + "with" + sep + "sepa" + sep + "ra" + sep + "tors");
1331
2
    path = "/very\\long/dir\\\\with\\sepa//ra/tors";
1332
2
    sanitizePath(path);
1333










34
    REQUIRE(path == sep + "very" + sep + "long" + sep + \
1334
        "dir" + sep + "with" + sep + "sepa" + sep + "ra" + sep + "tors");
1335
2
}
1336
1337
6
TEST_CASE("stringuntils pathJoin1", "")
1338
{
1339
8
    const std::string sep = dirSeparator;
1340
1341





22
    REQUIRE(pathJoin("", "") == sep);
1342




20
    REQUIRE(pathJoin(sep, "") == sep);
1343




16
    REQUIRE(pathJoin("", sep) == sep);
1344




14
    REQUIRE(pathJoin(sep, sep) == sep);
1345






26
    REQUIRE(pathJoin("dir1", "dir2") == "dir1" + sep + "dir2");
1346






22
    REQUIRE(pathJoin("dir1" + sep, "dir2") == "dir1" + sep + "dir2");
1347






22
    REQUIRE(pathJoin("dir1", sep + "dir2") == "dir1" + sep + "dir2");
1348






18
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2") == "dir1" + sep + "dir2");
1349









36
    REQUIRE(pathJoin("dir1" + sep + "dir2" + sep + "dir3", "dir4") ==
1350
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4");
1351









32
    REQUIRE(pathJoin("dir1" + sep + "dir2" + sep, "dir3" + sep + "dir4") ==
1352
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4");
1353









30
    REQUIRE(pathJoin("dir1" + sep + "dir2", "dir3" + sep + "dir4") ==
1354
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4");
1355









32
    REQUIRE(pathJoin("dir1" + sep + "dir2", sep + "dir3" + sep + "dir4") ==
1356
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4");
1357
2
}
1358
1359
6
TEST_CASE("stringuntils pathJoin2", "")
1360
{
1361
8
    const std::string sep = dirSeparator;
1362
1363





28
    REQUIRE(pathJoin("", "", "") == sep);
1364





26
    REQUIRE(pathJoin(sep, "", "") == sep);
1365





22
    REQUIRE(pathJoin("", sep, "") == sep);
1366





22
    REQUIRE(pathJoin("", "", sep) == sep);
1367




20
    REQUIRE(pathJoin(sep, sep, "") == sep);
1368




20
    REQUIRE(pathJoin(sep, "", sep) == sep);
1369




16
    REQUIRE(pathJoin("", sep, sep) == sep);
1370




14
    REQUIRE(pathJoin(sep, sep, sep) == sep);
1371
1372







36
    REQUIRE(pathJoin("dir1", "dir2", "dir3") ==
1373
        "dir1" + sep + "dir2" + sep + "dir3");
1374







32
    REQUIRE(pathJoin("dir1" + sep, "dir2", "dir3") ==
1375
        "dir1" + sep + "dir2" + sep + "dir3");
1376







32
    REQUIRE(pathJoin("dir1", sep + "dir2", "dir3") ==
1377
        "dir1" + sep + "dir2" + sep + "dir3");
1378







32
    REQUIRE(pathJoin("dir1", "dir2" + sep, "dir3") ==
1379
        "dir1" + sep + "dir2" + sep + "dir3");
1380







32
    REQUIRE(pathJoin("dir1", "dir2", sep + "dir3") ==
1381
        "dir1" + sep + "dir2" + sep + "dir3");
1382








34
    REQUIRE(pathJoin("dir1", "dir2", "dir3" + sep) ==
1383
        "dir1" + sep + "dir2" + sep + "dir3" + sep);
1384







28
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2", "dir3") ==
1385
        "dir1" + sep + "dir2" + sep + "dir3");
1386







28
    REQUIRE(pathJoin("dir1" + sep, "dir2" + sep, "dir3") ==
1387
        "dir1" + sep + "dir2" + sep + "dir3");
1388







28
    REQUIRE(pathJoin("dir1" + sep, "dir2", sep + "dir3") ==
1389
        "dir1" + sep + "dir2" + sep + "dir3");
1390








30
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2" + sep, "dir3") ==
1391
        "dir1" + sep + "dir2" + sep + "dir3");
1392







24
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2", sep + "dir3") ==
1393
        "dir1" + sep + "dir2" + sep + "dir3");
1394








30
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2" + sep, "dir3") ==
1395
        "dir1" + sep + "dir2" + sep + "dir3");
1396








26
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2" + sep, sep + "dir3") ==
1397
        "dir1" + sep + "dir2" + sep + "dir3");
1398











46
    REQUIRE(pathJoin("dir1" + sep + "dir2" + sep + "dir3", "dir4", "dir5") ==
1399
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4" + sep + "dir5");
1400











42
    REQUIRE(pathJoin("dir1" + sep + "dir2" + sep,
1401
        "dir3" + sep + "dir4",
1402
        "dir5") ==
1403
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4" + sep + "dir5");
1404











42
    REQUIRE(pathJoin("dir1" + sep + "dir2",
1405
        "dir3",
1406
        sep + "dir4" + sep + "dir5") ==
1407
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4" + sep + "dir5");
1408











38
    REQUIRE(pathJoin("dir1" + sep + "dir2",
1409
        sep + "dir3" + sep + "dir4",
1410
        sep + "dir5") ==
1411
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4" + sep + "dir5");
1412
2
}
1413
1414
6
TEST_CASE("stringuntils urlJoin", "")
1415
{
1416




22
    REQUIRE(urlJoin("", "") == "/");
1417




22
    REQUIRE(urlJoin("/", "") == "/");
1418




22
    REQUIRE(urlJoin("", "/") == "/");
1419




22
    REQUIRE(urlJoin("/", "/") == "/");
1420