GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/utils/stringutils.cc Lines: 1194 1194 100.0 %
Date: 2018-06-18 21:15:20 Branches: 4091 10626 38.5 %

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 "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 "utils/translation/translationmanager.h"
32
33
#include "resources/iteminfo.h"
34
35
#include "resources/db/itemdb.h"
36
37
#include "resources/resourcemanager/resourcemanager.h"
38
39
#include "debug.h"
40
41
6
TEST_CASE("stringuntils  trim 1", "")
42
{
43
8
    std::string str = "str";
44




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




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




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




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




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




8
    REQUIRE("str" == toLower(str));
63
64
    str = " StR";
65




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




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




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




8
    REQUIRE("STR" == toUpper(str));
81
82
    str = " StR";
83




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




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




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




8
    REQUIRE(16 == atox(str));
99
100
    str = "0x0";
101




8
    REQUIRE(0 == atox(str));
102
103
    str = "0x1";
104




8
    REQUIRE(1 == atox(str));
105
106
    str = "0x0x0x0x0x0x0x0";
107




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




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




8
    REQUIRE(0 == atox(str));
118
119
    str = "0x";
120




8
    REQUIRE(0 == atox(str));
121
122
    str = "zzz";
123




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




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




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




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




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




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




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




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




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




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




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




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




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



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



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



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




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



8
    REQUIRE(a == -1);
162



8
    REQUIRE(b == -1);
163
164
2
    a = -1;
165
2
    b = -1;
166




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



8
    REQUIRE(a == -1);
168



8
    REQUIRE(b == -1);
169
170
2
    a = -1;
171
2
    b = -1;
172




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



8
    REQUIRE(a == 10);
174



8
    REQUIRE(b == 20);
175
176
2
    a = -1;
177
2
    b = -1;
178




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



8
    REQUIRE(a == 10);
180



8
    REQUIRE(b == 20);
181
182
2
    a = -1;
183
2
    b = -1;
184




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



8
    REQUIRE(a == 10);
186



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




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



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



8
    REQUIRE(str2 == "-");
197
198




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



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



8
    REQUIRE(str2 == "-");
201
202
2
    str1 = "-";
203
    str2 = "-";
204




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



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



8
    REQUIRE(str2 == "line");
207
208
2
    str1 = "-";
209
    str2 = "-";
210




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



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



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




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




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




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




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




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




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




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



8
    REQUIRE(str.empty());
231
232
    str = "test";
233




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



8
    REQUIRE(str.empty());
235
236
    str = "test line";
237




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



8
    REQUIRE(str == "line");
239
240
    str = "test,line";
241




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



8
    REQUIRE(str == "line");
243
244
    str = "test line";
245




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



8
    REQUIRE(str.empty());
247
248
    str = ",line";
249




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



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



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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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



6
    REQUIRE(isWordSeparator(' '));
319



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



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



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



6
    REQUIRE(!isWordSeparator(0));
323



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



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





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




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




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




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





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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




8
    REQUIRE(10 == decodeStr(str));
398
399
    str.clear();
400




8
    REQUIRE(0 == decodeStr(str));
401
402
6
    str = encodeStr(10, 2);
403




8
    REQUIRE(10 == decodeStr(str));
404
405
6
    str = encodeStr(100, 3);
406




8
    REQUIRE(100 == decodeStr(str));
407
408
6
    str = encodeStr(1000, 4);
409




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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

8
    str = getSafeUtf8String("");
438



8
    REQUIRE(str != nullptr);
439



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



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



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

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



8
    REQUIRE(str != nullptr);
446



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



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



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

8
    str = getSafeUtf8String("1");
452



8
    REQUIRE(str != nullptr);
453



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



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



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

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

8
    getSafeUtf8String("", str);
467



8
    REQUIRE(str != nullptr);
468



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



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



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

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



8
    REQUIRE(str != nullptr);
476



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



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



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

8
    getSafeUtf8String("1", str);
483



8
    REQUIRE(str != nullptr);
484



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



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



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

8
    getSafeUtf8String(data1, str);
497



8
    REQUIRE(str != nullptr);
498



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



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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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

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



8
    REQUIRE(str.empty());
555
2
    str = "test line";
556

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



8
    REQUIRE(str == "test .");
558
2
    str = "11112222";
559

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



8
    REQUIRE(str == "12222");
561
2
    str = "122221";
562

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



8
    REQUIRE(str == "122221");
564
2
    str = "1222211";
565

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



8
    REQUIRE(str == "122221");
567
2
    str = "11112222";
568

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



8
    REQUIRE(str == "111222");
570
2
    str = "111122224";
571

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



8
    REQUIRE(str == "1112224");
573
2
    str = "3111122224";
574

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



8
    REQUIRE(str == "31112224");
576
2
    str = "121212";
577

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



8
    REQUIRE(str == "111");
579
2
    str = "1121212";
580

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



8
    REQUIRE(str == "1111");
582
2
    str = "11212122";
583

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



8
    REQUIRE(str == "1111");
585
2
    str = "112121222";
586

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



8
    REQUIRE(str == "1111");
588
2
    str = "112211221122";
589

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



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




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




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




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




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




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




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




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




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




12
    REQUIRE(getBoolFromString("2"));
604
605




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




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




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




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




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




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




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




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




12
    REQUIRE(getBoolFromString(" 2"));
614
615




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




14
    REQUIRE(parseBoolean("") == -1);
636
637




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




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




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




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




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




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




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




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




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




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




12
    REQUIRE(parseBoolean(" ") == -1);
648
649




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




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




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




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




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




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




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

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



10
    REQUIRE(tokens.empty() == true);
663
664
2
    tokens.clear();
665

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



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



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



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



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

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



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



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



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



12
    REQUIRE(tokens.find(30) != tokens.end());
677
678
2
    tokens.clear();
679

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



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



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



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



12
    REQUIRE(tokens.find(30) != tokens.end());
684
685
2
    tokens.clear();
686

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



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



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



12
    REQUIRE(tokens.find(2) != tokens.end());
690
691
2
    tokens.clear();
692

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



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



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



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



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

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



10
    REQUIRE(tokens.empty() == true);
704
705
2
    tokens.clear();
706

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



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



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



10
    REQUIRE(tokens.front() == 0);
711
2
    tokens.pop_front();
712



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

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



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



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



10
    REQUIRE(tokens.front() == 2);
721
2
    tokens.pop_front();
722



10
    REQUIRE(tokens.front() == 30);
723
2
    tokens.pop_front();
724
725
2
    tokens.clear();
726

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



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



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



10
    REQUIRE(tokens.front() == 2);
731
2
    tokens.pop_front();
732



10
    REQUIRE(tokens.front() == 30);
733
2
    tokens.pop_front();
734
735
2
    tokens.clear();
736

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



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



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



10
    REQUIRE(tokens.front() == 2);
741
2
    tokens.pop_front();
742
743
2
    tokens.clear();
744

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



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



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



10
    REQUIRE(tokens.front() == 20);
749
2
    tokens.pop_front();
750



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

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



10
    REQUIRE(tokens.empty() == true);
759
760
2
    tokens.clear();
761

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



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




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




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




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

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



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




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




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




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

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



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




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




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

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



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




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




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




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

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



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




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




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

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



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




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




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




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

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



10
    REQUIRE(tokens.empty() == true);
806
807
2
    tokens.clear();
808

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



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



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



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



10
    REQUIRE(tokens[2] == 30);
813
814
2
    tokens.clear();
815

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



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



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



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



10
    REQUIRE(tokens[2] == 0);
820
821
2
    tokens.clear();
822

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



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



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



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



10
    REQUIRE(tokens[2] == 30);
827
828
2
    tokens.clear();
829

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



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



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



10
    REQUIRE(tokens[1] == 30);
833
834
2
    tokens.clear();
835

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



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



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



10
    REQUIRE(tokens[1] == 2);
839
840
2
    tokens.clear();
841

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



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



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



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



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

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



10
    REQUIRE(tokens.empty() == true);
853
854
2
    tokens.clear();
855

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



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



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



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



10
    REQUIRE(tokens[2] == "zz");
860
861
2
    tokens.clear();
862

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



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



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



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



10
    REQUIRE(tokens[2] == "zz");
867
868
2
    tokens.clear();
869

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



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



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



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

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



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



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



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

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



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



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



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



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



8
    REQUIRE(str.empty());
895
896
2
    str = "test";
897
2
    replaceSpecialChars(str);
898



8
    REQUIRE("test" == str);
899
900
2
    str = "&";
901
2
    replaceSpecialChars(str);
902



8
    REQUIRE("&" == str);
903
904
2
    str = "&1";
905
2
    replaceSpecialChars(str);
906



8
    REQUIRE("&1" == str);
907
908
2
    str = "&33";
909
2
    replaceSpecialChars(str);
910



8
    REQUIRE("&33" == str);
911
912
2
    str = "&33;";
913
2
    replaceSpecialChars(str);
914



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



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



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



8
    REQUIRE("!2" == str);
927
928
2
    str = "&33;&";
929
2
    replaceSpecialChars(str);
930



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



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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




10
    REQUIRE(packList(list).empty());
992
993
4
    list.push_back(std::string());
994




10
    REQUIRE("|" == packList(list));
995
996
2
    list.clear();
997

8
    list.push_back("test");
998




10
    REQUIRE("test" == packList(list));
999
1000

8
    list.push_back("line");
1001




10
    REQUIRE("test|line" == packList(list));
1002
1003

8
    list.push_back("2");
1004




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

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

8
    list.push_back("line");
1009




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




10
    REQUIRE(stringToHexPath(str).empty());
1018
1019
    str = "a";
1020




10
    REQUIRE("%61/" == stringToHexPath(str));
1021
1022
    str = "ab";
1023




10
    REQUIRE("%61/%62" == stringToHexPath(str));
1024
1025
    str = "abc";
1026




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




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



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



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



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



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




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




12
    REQUIRE(findLast(str, "line"));
1066
1067
    str = "test line";
1068




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




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




12
    REQUIRE(findFirst(str, "test"));
1080
1081
    str = "test";
1082




14
    REQUIRE(findFirst(str, "test line") == false);
1083
1084
    str = "test line";
1085




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




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



8
    REQUIRE(str.empty());
1095
1096
    str = "test line";
1097




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



8
    REQUIRE("test " == str);
1099
1100
    str = "test line";
1101




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



8
    REQUIRE("test line" == str);
1103
1104
    str = "test";
1105




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



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

8
    cutLast(str, "");
1115



8
    REQUIRE(str.empty());
1116
1117
2
    str = "test line";
1118

8
    cutLast(str, "line");
1119



8
    REQUIRE("test " == str);
1120
1121
2
    str = "test line";
1122

8
    cutLast(str, "lin");
1123



8
    REQUIRE("test line" == str);
1124
1125
2
    str = "test";
1126

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



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




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



8
    REQUIRE(str.empty());
1137
1138
    str = "test line";
1139




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



8
    REQUIRE(" line" == str);
1141
1142
    str = "test line";
1143




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



8
    REQUIRE("test line" == str);
1145
1146
    str = "test";
1147




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



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

8
    cutFirst(str, "");
1157



8
    REQUIRE(str.empty());
1158
1159
2
    str = "test line";
1160

8
    cutFirst(str, "test");
1161



8
    REQUIRE(" line" == str);
1162
1163
2
    str = "test line";
1164

8
    cutFirst(str, "est");
1165



8
    REQUIRE("test line" == str);
1166
1167
2
    str = "test";
1168

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



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




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




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




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




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




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




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




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




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

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



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

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



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

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



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

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



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



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




12
    REQUIRE_FALSE(isDigit(""));
1220




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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



8
    REQUIRE(path.empty());
1260
2
    path = "/";
1261
2
    sanitizePath(path);
1262



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



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



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



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



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



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



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



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



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



8
    REQUIRE(path == dirSeparator);
1290
2
    path = "\\\\/";
1291
2
    sanitizePath(path);
1292



8
    REQUIRE(path == dirSeparator);
1293
2
    path = "test";
1294
2
    sanitizePath(path);
1295



8
    REQUIRE(path == "test");
1296
2
    path = "./test";
1297
2
    sanitizePath(path);
1298




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



8
    REQUIRE(path == "test line");
1302
2
    path = "dir/test";
1303
2
    sanitizePath(path);
1304




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





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




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




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




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




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




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





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





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










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










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





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




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




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




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






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






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






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






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









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









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









30
    REQUIRE(pathJoin("dir1" + sep + "dir2", "dir3" + sep + "dir4") ==
1356
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4");
1357









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





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





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





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





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




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




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




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




14
    REQUIRE(pathJoin(sep, sep, sep) == sep);
1373
1374







36
    REQUIRE(pathJoin("dir1", "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", sep + "dir2", "dir3") ==
1379
        "dir1" + sep + "dir2" + sep + "dir3");
1380







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







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








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







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







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







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








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







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








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








26
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2" + sep, sep + "dir3") ==
1399
        "dir1" + sep + "dir2" + sep + "dir3");
1400











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











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











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











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




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




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




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




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