GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/utils/stringutils.cc Lines: 1207 1207 100.0 %
Date: 2021-03-17 Branches: 4156 10800 38.5 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-2019  The ManaPlus Developers
4
 *  Copyright (C) 2019-2021  Andrei Karas
5
 *
6
 *  This file is part of The ManaPlus Client.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#include "unittests/unittests.h"
23
24
#include "configuration.h"
25
26
#include "const/utils/utf8.h"
27
28
#include "fs/virtfs/fs.h"
29
30
#include "utils/dtor.h"
31
32
#include "utils/translation/translationmanager.h"
33
34
#include "resources/iteminfo.h"
35
36
#include "resources/db/itemdb.h"
37
38
#include "resources/resourcemanager/resourcemanager.h"
39
40
#include "debug.h"
41
42
3
TEST_CASE("stringuntils  trim 1", "")
43
{
44
4
    std::string str = "str";
45




4
    REQUIRE("str" == trim(str));
46
47
    str = " str";
48




4
    REQUIRE("str" == trim(str));
49




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




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




4
    REQUIRE(trim(str).empty());
58
1
}
59
60
3
TEST_CASE("stringuntils toLower 1", "")
61
{
62
4
    std::string str = "str";
63




4
    REQUIRE("str" == toLower(str));
64
65
    str = " StR";
66




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




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




4
    REQUIRE(toLower(str).empty());
76
1
}
77
78
3
TEST_CASE("stringuntils toUpper 1", "")
79
{
80
4
    std::string str = "str";
81




4
    REQUIRE("STR" == toUpper(str));
82
83
    str = " StR";
84




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




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




4
    REQUIRE(toUpper(str).empty());
94
1
}
95
96
3
TEST_CASE("stringuntils atox 1", "")
97
{
98
4
    std::string str = "0x10";
99




4
    REQUIRE(16 == atox(str));
100
101
    str = "0x0";
102




4
    REQUIRE(0 == atox(str));
103
104
    str = "0x1";
105




4
    REQUIRE(1 == atox(str));
106
107
    str = "0x0x0x0x0x0x0x0";
108




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




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




4
    REQUIRE(0 == atox(str));
119
120
    str = "0x";
121




4
    REQUIRE(0 == atox(str));
122
123
    str = "zzz";
124




4
    REQUIRE(0 == atox(str));
125
1
}
126
127
3
TEST_CASE("stringuntils ipToString 1", "")
128
{
129




7
    REQUIRE("0.0.0.0" == std::string(ipToString(0)));
130




7
    REQUIRE("219.255.210.73" == std::string(ipToString(1238564827)));
131
1
}
132
133
3
TEST_CASE("stringuntils toString 1", "")
134
{
135




6
    REQUIRE(strprintf("%d", 0) == toString(0));
136




6
    REQUIRE(strprintf("%d", -1) == toString(-1));
137




6
    REQUIRE(strprintf("%d", 30000000) == toString(30000000));
138




6
    REQUIRE(strprintf("%d", -10000000) == toString(-10000000));
139




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




6
    REQUIRE(strprintf("%d", 3000) == toString(CAST_U16(3000)));
142




6
    REQUIRE(strprintf("%d", 123) == toString(CAST_U8(123)));
143




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




6
    REQUIRE(strprintf("%f", 3.1F) == toString(3.1F));
146




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



5
    REQUIRE(toStringPrint(0) == "0 0x0");
152



5
    REQUIRE(toStringPrint(10) == "10 0xa");
153



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




7
    REQUIRE(parse2Int("", a, b) == false);
162



4
    REQUIRE(a == -1);
163



4
    REQUIRE(b == -1);
164
165
1
    a = -1;
166
1
    b = -1;
167




7
    REQUIRE(parse2Int(",", a, b) == false);
168



4
    REQUIRE(a == -1);
169



4
    REQUIRE(b == -1);
170
171
1
    a = -1;
172
1
    b = -1;
173




7
    REQUIRE(parse2Int("10,20", a, b) == true);
174



4
    REQUIRE(a == 10);
175



4
    REQUIRE(b == 20);
176
177
1
    a = -1;
178
1
    b = -1;
179




7
    REQUIRE(parse2Int("10 20", a, b) == true);
180



4
    REQUIRE(a == 10);
181



4
    REQUIRE(b == 20);
182
183
1
    a = -1;
184
1
    b = -1;
185




7
    REQUIRE(parse2Int("10 z20", a, b) == true);
186



4
    REQUIRE(a == 10);
187



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




7
    REQUIRE(parse2Str("", str1, str2) == false);
196



4
    REQUIRE(str1 == "-");
197



4
    REQUIRE(str2 == "-");
198
199




7
    REQUIRE(parse2Str(",", str1, str2) == false);
200



4
    REQUIRE(str1 == "-");
201



4
    REQUIRE(str2 == "-");
202
203
1
    str1 = "-";
204
    str2 = "-";
205




7
    REQUIRE(parse2Str("test line", str1, str2) == true);
206



4
    REQUIRE(str1 == "test");
207



4
    REQUIRE(str2 == "line");
208
209
1
    str1 = "-";
210
    str2 = "-";
211




7
    REQUIRE(parse2Str("test,line", str1, str2) == true);
212



4
    REQUIRE(str1 == "test");
213



4
    REQUIRE(str2 == "line");
214
1
}
215
216
3
TEST_CASE("stringuntils parseNumber 1", "")
217
{
218




7
    REQUIRE(parseNumber("") == 0);
219




7
    REQUIRE(parseNumber("0x") == 0);
220




7
    REQUIRE(parseNumber("10") == 10);
221




7
    REQUIRE(parseNumber("h10") == 16);
222




7
    REQUIRE(parseNumber("x100") == 256);
223




7
    REQUIRE(parseNumber("0x20") == 32);
224
1
}
225
226
3
TEST_CASE("stringuntils removeToken 1", "")
227
{
228
1
    std::string str;
229
230




8
    REQUIRE(removeToken(str, " ").empty());
231



4
    REQUIRE(str.empty());
232
233
    str = "test";
234




8
    REQUIRE(removeToken(str, " ").empty());
235



4
    REQUIRE(str.empty());
236
237
    str = "test line";
238




8
    REQUIRE(removeToken(str, " ") == "line");
239



4
    REQUIRE(str == "line");
240
241
    str = "test,line";
242




8
    REQUIRE(removeToken(str, ",") == "line");
243



4
    REQUIRE(str == "line");
244
245
    str = "test line";
246




8
    REQUIRE(removeToken(str, ",").empty());
247



4
    REQUIRE(str.empty());
248
249
    str = ",line";
250




8
    REQUIRE(removeToken(str, ",").empty());
251



4
    REQUIRE(str.empty());
252
1
}
253
254
3
TEST_CASE("stringuntils strprintf 1", "")
255
{
256



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




487806
        REQUIRE(strprintf("%d", f) == toString(f));
277
    }
278
1
}
279
280
3
TEST_CASE("stringuntils removeColors 1", "")
281
{
282




8
    REQUIRE(removeColors("").empty());
283




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




8
    REQUIRE("##" == removeColors("##"));
285




8
    REQUIRE(removeColors("##1").empty());
286




8
    REQUIRE("2" == removeColors("##12"));
287




8
    REQUIRE("1##" == removeColors("1##"));
288




8
    REQUIRE("1" == removeColors("1##2"));
289




8
    REQUIRE("13" == removeColors("1##23"));
290




8
    REQUIRE("#1#2" == removeColors("#1#2"));
291




8
    REQUIRE("#1" == removeColors("#1##2"));
292
1
}
293
294
3
TEST_CASE("stringuntils compareStrI 1", "")
295
{
296
2
    std::string str1;
297
1
    std::string str2;
298




4
    REQUIRE(0 == compareStrI(str1, str2));
299
300
1
    str1 = "test";
301
    str2 = "test";
302




4
    REQUIRE(0 == compareStrI(str1, str2));
303
304
1
    str1 = "test";
305
    str2 = "test1";
306




4
    REQUIRE(0 > compareStrI(str1, str2));
307
308
1
    str1 = "test";
309
    str2 = "aest1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
310




4
    REQUIRE(0 < compareStrI(str1, str2));
311
312
1
    str1 = "testaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
313
    str2 = "testaa";
314




4
    REQUIRE(0 < compareStrI(str1, str2));
315
1
}
316
317
3
TEST_CASE("stringuntils isWordSeparator 1", "")
318
{
319



3
    REQUIRE(isWordSeparator(' '));
320



3
    REQUIRE(isWordSeparator(','));
321



3
    REQUIRE(isWordSeparator('.'));
322



3
    REQUIRE(isWordSeparator('\"'));
323



3
    REQUIRE(!isWordSeparator(0));
324



3
    REQUIRE(!isWordSeparator('a'));
325



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





11
    REQUIRE(findSameSubstring("", "").empty());
334
335
1
    str1 = "test line";
336
    str2 = "test line";
337




5
    REQUIRE("test line" == findSameSubstring(str1, str2));
338
339
1
    str1 = "test li";
340
    str2 = "test line";
341




5
    REQUIRE("test li" == findSameSubstring(str1, str2));
342
343
1
    str1 = "test li";
344
    str2 = "est li";
345




5
    REQUIRE(findSameSubstring(str1, str2).empty());
346
1
}
347
348
3
TEST_CASE("stringuntils findSameSubstringI", "")
349
{
350
2
    std::string str1;
351
1
    std::string str2;
352
353





11
    REQUIRE(findSameSubstringI("", "").empty());
354
355
1
    str1 = "tEst line";
356
    str2 = "tesT line";
357




5
    REQUIRE("tEst line" == findSameSubstringI(str1, str2));
358
359
1
    str1 = "test Li";
360
    str2 = "test lINe";
361




5
    REQUIRE("test Li" == findSameSubstringI(str1, str2));
362
363
1
    str1 = "test lINe";
364
    str2 = "test Li";
365




5
    REQUIRE("test lI" == findSameSubstringI(str1, str2));
366
367
1
    str1 = "teSt li";
368
    str2 = "est li";
369




5
    REQUIRE(findSameSubstringI(str1, str2).empty());
370
1
}
371
372
3
TEST_CASE("stringuntils findI 1", "")
373
{
374




10
    REQUIRE(0 == findI("", ""));
375




10
    REQUIRE(std::string::npos == findI("test", "line"));
376




10
    REQUIRE(0 == findI("test line", "t"));
377




10
    REQUIRE(0 == findI("test line", "te"));
378




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




7
    REQUIRE(std::string::npos == findI("", vect1));
389




7
    REQUIRE(0 == findI("test", vect1));
390




7
    REQUIRE(0 == findI("tesT lIne", vect1));
391




7
    REQUIRE(5 == findI("teoT line", vect1));
392




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




4
    REQUIRE(10 == decodeStr(str));
399
400
    str.clear();
401




4
    REQUIRE(0 == decodeStr(str));
402
403
3
    str = encodeStr(10, 2);
404




4
    REQUIRE(10 == decodeStr(str));
405
406
3
    str = encodeStr(100, 3);
407




4
    REQUIRE(100 == decodeStr(str));
408
409
3
    str = encodeStr(1000, 4);
410




4
    REQUIRE(1000 == decodeStr(str));
411
1
}
412
413
3
TEST_CASE("stringuntils extractNameFromSprite 1", "")
414
{
415




8
    REQUIRE(extractNameFromSprite("").empty());
416




8
    REQUIRE("test" == extractNameFromSprite("test"));
417




8
    REQUIRE("test" == extractNameFromSprite("test.qwe"));
418




8
    REQUIRE("line" == extractNameFromSprite("test/line.zzz"));
419




8
    REQUIRE("line" == extractNameFromSprite("test\\line.zzz"));
420




8
    REQUIRE("line" == extractNameFromSprite("test/test2\\line.zzz"));
421




8
    REQUIRE("line" == extractNameFromSprite("test\\test2/line.zzz"));
422
1
}
423
424
3
TEST_CASE("stringuntils removeSpriteIndex 1", "")
425
{
426




8
    REQUIRE(removeSpriteIndex("").empty());
427




8
    REQUIRE("test" == removeSpriteIndex("test"));
428




8
    REQUIRE("test" == removeSpriteIndex("test[1]"));
429




8
    REQUIRE("line" == removeSpriteIndex("test/line[12]"));
430




8
    REQUIRE("line" == removeSpriteIndex("test\\line[12]"));
431




8
    REQUIRE("line" == removeSpriteIndex("test/test2\\line[12]"));
432




8
    REQUIRE("line" == removeSpriteIndex("test\\test2/line[1]"));
433
1
}
434
435
3
TEST_CASE("stringutils getSafeUtf8String 1", "")
436
{
437
    const char *str;
438
4
    str = getSafeUtf8String("");
439



4
    REQUIRE(str != nullptr);
440



4
    REQUIRE(strcmp("", str) == 0);
441



4
    REQUIRE(str[0] == '\0');
442



4
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
443
1
    delete [] str;
444
445
4
    str = getSafeUtf8String("test line");
446



4
    REQUIRE(str != nullptr);
447



4
    REQUIRE(strcmp("test line", str) == 0);
448



4
    REQUIRE(str[strlen("test line")] == '\0');
449



4
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
450
1
    delete [] str;
451
452
4
    str = getSafeUtf8String("1");
453



4
    REQUIRE(str != nullptr);
454



4
    REQUIRE(strcmp("1", str) == 0);
455



4
    REQUIRE(str[1] == '\0');
456



4
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
457
1
    delete [] str;
458
1
}
459
460
3
TEST_CASE("stringutils getSafeUtf8String 2", "")
461
{
462
    char *str;
463
464
4
    getSafeUtf8String("test", nullptr);
465
466
1
    str = new char[65535];
467
4
    getSafeUtf8String("", str);
468



4
    REQUIRE(str != nullptr);
469



4
    REQUIRE(strcmp("", str) == 0);
470



4
    REQUIRE(str[0] == '\0');
471



4
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
472
1
    delete [] str;
473
474
1
    str = new char[65535];
475
4
    getSafeUtf8String("test line", str);
476



4
    REQUIRE(str != nullptr);
477



4
    REQUIRE(strcmp("test line", str) == 0);
478



4
    REQUIRE(str[strlen("test line")] == '\0');
479



4
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
480
1
    delete [] str;
481
482
1
    str = new char[65535];
483
4
    getSafeUtf8String("1", str);
484



4
    REQUIRE(str != nullptr);
485



4
    REQUIRE(strcmp("1", str) == 0);
486



4
    REQUIRE(str[1] == '\0');
487



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



4
    REQUIRE(str != nullptr);
499



4
    REQUIRE(strcmp(data2, str) == 0);
500



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




8
    REQUIRE(getFileName("").empty());
509




8
    REQUIRE("file" == getFileName("file"));
510




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




8
    REQUIRE("file" == getFileName("test\\file1/file"));
512




8
    REQUIRE(getFileName("file/").empty());
513




8
    REQUIRE("file" == getFileName("/file"));
514
1
}
515
516
3
TEST_CASE("stringuntils getFileDir 1", "")
517
{
518




8
    REQUIRE(getFileDir("").empty());
519




8
    REQUIRE("file" == getFileDir("file"));
520




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




8
    REQUIRE("test\\file1" == getFileDir("test\\file1/file"));
522




8
    REQUIRE("file" == getFileDir("file/"));
523




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




4
    REQUIRE(replaceAll(str1, str2, str3).empty());
533
534
1
    str1 = "this is test line";
535
1
    str2 = "";
536
    str3 = "";
537




4
    REQUIRE("this is test line" == replaceAll(str1, str2, str3));
538
539
1
    str1 = "this is test line";
540
1
    str2 = "is ";
541
    str3 = "";
542




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




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

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



4
    REQUIRE(str.empty());
556
1
    str = "test line";
557

4
    replaceRecursiveAll(str, "line", '.');
558



4
    REQUIRE(str == "test .");
559
1
    str = "11112222";
560

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



4
    REQUIRE(str == "12222");
562
1
    str = "122221";
563

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



4
    REQUIRE(str == "122221");
565
1
    str = "1222211";
566

4
    replaceRecursiveAll(str, "11", '1');
567



4
    REQUIRE(str == "122221");
568
1
    str = "11112222";
569

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



4
    REQUIRE(str == "111222");
571
1
    str = "111122224";
572

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



4
    REQUIRE(str == "1112224");
574
1
    str = "3111122224";
575

4
    replaceRecursiveAll(str, "112", '1');
576



4
    REQUIRE(str == "31112224");
577
1
    str = "121212";
578

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



4
    REQUIRE(str == "111");
580
1
    str = "1121212";
581

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



4
    REQUIRE(str == "1111");
583
1
    str = "11212122";
584

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



4
    REQUIRE(str == "1111");
586
1
    str = "112121222";
587

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



4
    REQUIRE(str == "1111");
589
1
    str = "112211221122";
590

4
    replaceRecursiveAll(str, "12", '1');
591



4
    REQUIRE(str == "111111");
592
1
}
593
594
3
TEST_CASE("stringuntils getBoolFromString 1", "")
595
{
596




6
    REQUIRE(getBoolFromString("true"));
597




6
    REQUIRE(getBoolFromString("yes"));
598




6
    REQUIRE(getBoolFromString("on"));
599




6
    REQUIRE(!getBoolFromString("false"));
600




6
    REQUIRE(!getBoolFromString("no"));
601




6
    REQUIRE(!getBoolFromString("off"));
602




6
    REQUIRE(getBoolFromString("1"));
603




6
    REQUIRE(!getBoolFromString("0"));
604




6
    REQUIRE(getBoolFromString("2"));
605
606




6
    REQUIRE(getBoolFromString(" true"));
607




6
    REQUIRE(getBoolFromString("yes "));
608




6
    REQUIRE(getBoolFromString(" on"));
609




6
    REQUIRE(!getBoolFromString("false "));
610




6
    REQUIRE(!getBoolFromString(" no"));
611




6
    REQUIRE(!getBoolFromString("off "));
612




6
    REQUIRE(getBoolFromString(" 1"));
613




6
    REQUIRE(!getBoolFromString("0 "));
614




6
    REQUIRE(getBoolFromString(" 2"));
615
616




6
    REQUIRE(getBoolFromString("tRue "));
617




6
    REQUIRE(getBoolFromString(" Yes"));
618




6
    REQUIRE(getBoolFromString("ON "));
619




6
    REQUIRE(!getBoolFromString(" fALse"));
620




6
    REQUIRE(!getBoolFromString("nO "));
621




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




7
    REQUIRE(parseBoolean("true") == 1);
627




7
    REQUIRE(parseBoolean("yes") == 1);
628




7
    REQUIRE(parseBoolean("on") == 1);
629




7
    REQUIRE(parseBoolean("false") == 0);
630




7
    REQUIRE(parseBoolean("no") == 0);
631




7
    REQUIRE(parseBoolean("off") == 0);
632




7
    REQUIRE(parseBoolean("1") == 1);
633




7
    REQUIRE(parseBoolean("0") == 0);
634




7
    REQUIRE(parseBoolean("2") == -1);
635




7
    REQUIRE(parseBoolean("test") == -1);
636




7
    REQUIRE(parseBoolean("") == -1);
637
638




7
    REQUIRE(parseBoolean("true ") == 1);
639




7
    REQUIRE(parseBoolean(" yes") == 1);
640




7
    REQUIRE(parseBoolean("on ") == 1);
641




7
    REQUIRE(parseBoolean(" false") == 0);
642




7
    REQUIRE(parseBoolean("no ") == 0);
643




7
    REQUIRE(parseBoolean(" off") == 0);
644




7
    REQUIRE(parseBoolean("1 ") == 1);
645




7
    REQUIRE(parseBoolean(" 0") == 0);
646




7
    REQUIRE(parseBoolean("2 ") == -1);
647




7
    REQUIRE(parseBoolean(" test") == -1);
648




7
    REQUIRE(parseBoolean(" ") == -1);
649
650




7
    REQUIRE(parseBoolean(" tRue") == 1);
651




7
    REQUIRE(parseBoolean("Yes ") == 1);
652




7
    REQUIRE(parseBoolean(" ON") == 1);
653




7
    REQUIRE(parseBoolean("FaLse ") == 0);
654




7
    REQUIRE(parseBoolean(" nO") == 0);
655




7
    REQUIRE(parseBoolean("oFf ") == 0);
656




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

4
    splitToIntSet(tokens, "", ',');
663



5
    REQUIRE(tokens.empty() == true);
664
665
1
    tokens.clear();
666

4
    splitToIntSet(tokens, "10z,aa,-1", ',');
667



5
    REQUIRE(tokens.size() == 3);
668



6
    REQUIRE(tokens.find(10) != tokens.end());
669



6
    REQUIRE(tokens.find(0) != tokens.end());
670



6
    REQUIRE(tokens.find(-1) != tokens.end());
671
672
1
    tokens.clear();
673

4
    splitToIntSet(tokens, "10,2,30", ',');
674



5
    REQUIRE(tokens.size() == 3);
675



6
    REQUIRE(tokens.find(10) != tokens.end());
676



6
    REQUIRE(tokens.find(2) != tokens.end());
677



6
    REQUIRE(tokens.find(30) != tokens.end());
678
679
1
    tokens.clear();
680

4
    splitToIntSet(tokens, "10,2,30,", ',');
681



5
    REQUIRE(tokens.size() == 3);
682



6
    REQUIRE(tokens.find(10) != tokens.end());
683



6
    REQUIRE(tokens.find(2) != tokens.end());
684



6
    REQUIRE(tokens.find(30) != tokens.end());
685
686
1
    tokens.clear();
687

4
    splitToIntSet(tokens, "10,2;30", ',');
688



5
    REQUIRE(tokens.size() == 2);
689



6
    REQUIRE(tokens.find(10) != tokens.end());
690



6
    REQUIRE(tokens.find(2) != tokens.end());
691
692
1
    tokens.clear();
693

4
    splitToIntSet(tokens, "10;20;30", ';');
694



5
    REQUIRE(tokens.size() == 3);
695



6
    REQUIRE(tokens.find(10) != tokens.end());
696



6
    REQUIRE(tokens.find(20) != tokens.end());
697



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

6
    tokens = splitToIntList("", ',');
704



5
    REQUIRE(tokens.empty() == true);
705
706
1
    tokens.clear();
707

6
    tokens = splitToIntList("10z,a,-1", ',');
708



5
    REQUIRE(tokens.size() == 3);
709



5
    REQUIRE(tokens.front() == 10);
710
1
    tokens.pop_front();
711



5
    REQUIRE(tokens.front() == 0);
712
1
    tokens.pop_front();
713



5
    REQUIRE(tokens.front() == -1);
714
1
    tokens.pop_front();
715
716
1
    tokens.clear();
717

6
    tokens = splitToIntList("10,2,30", ',');
718



5
    REQUIRE(tokens.size() == 3);
719



5
    REQUIRE(tokens.front() == 10);
720
1
    tokens.pop_front();
721



5
    REQUIRE(tokens.front() == 2);
722
1
    tokens.pop_front();
723



5
    REQUIRE(tokens.front() == 30);
724
1
    tokens.pop_front();
725
726
1
    tokens.clear();
727

6
    tokens = splitToIntList("10,2,30,", ',');
728



5
    REQUIRE(tokens.size() == 3);
729



5
    REQUIRE(tokens.front() == 10);
730
1
    tokens.pop_front();
731



5
    REQUIRE(tokens.front() == 2);
732
1
    tokens.pop_front();
733



5
    REQUIRE(tokens.front() == 30);
734
1
    tokens.pop_front();
735
736
1
    tokens.clear();
737

6
    tokens = splitToIntList("10,2;30", ',');
738



5
    REQUIRE(tokens.size() == 2);
739



5
    REQUIRE(tokens.front() == 10);
740
1
    tokens.pop_front();
741



5
    REQUIRE(tokens.front() == 2);
742
1
    tokens.pop_front();
743
744
1
    tokens.clear();
745

6
    tokens = splitToIntList("10;20;30", ';');
746



5
    REQUIRE(tokens.size() == 3);
747



5
    REQUIRE(tokens.front() == 10);
748
1
    tokens.pop_front();
749



5
    REQUIRE(tokens.front() == 20);
750
1
    tokens.pop_front();
751



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

4
    splitToStringSet(tokens, "", ',');
759



5
    REQUIRE(tokens.empty() == true);
760
761
1
    tokens.clear();
762

4
    splitToStringSet(tokens, "10q,2w,30e", ',');
763



5
    REQUIRE(tokens.size() == 3);
764




9
    REQUIRE(tokens.find("10q") != tokens.end());
765




9
    REQUIRE(tokens.find("2w") != tokens.end());
766




9
    REQUIRE(tokens.find("30e") != tokens.end());
767
768
1
    tokens.clear();
769

4
    splitToStringSet(tokens, "10q,2w,30e,", ',');
770



5
    REQUIRE(tokens.size() == 3);
771




9
    REQUIRE(tokens.find("10q") != tokens.end());
772




9
    REQUIRE(tokens.find("2w") != tokens.end());
773




9
    REQUIRE(tokens.find("30e") != tokens.end());
774
775
1
    tokens.clear();
776

4
    splitToStringSet(tokens, "10q,,30e", ',');
777



5
    REQUIRE(tokens.size() == 2);
778




9
    REQUIRE(tokens.find("10q") != tokens.end());
779




9
    REQUIRE(tokens.find("30e") != tokens.end());
780
781
1
    tokens.clear();
782

4
    splitToStringSet(tokens, "10q,2w,30e,", ',');
783



5
    REQUIRE(tokens.size() == 3);
784




9
    REQUIRE(tokens.find("10q") != tokens.end());
785




9
    REQUIRE(tokens.find("2w") != tokens.end());
786




9
    REQUIRE(tokens.find("30e") != tokens.end());
787
788
1
    tokens.clear();
789

4
    splitToStringSet(tokens, "10w,2w;30e", ',');
790



5
    REQUIRE(tokens.size() == 2);
791




9
    REQUIRE(tokens.find("10w") != tokens.end());
792




9
    REQUIRE(tokens.find("2w;30e") != tokens.end());
793
794
1
    tokens.clear();
795

4
    splitToStringSet(tokens, "10q;20w;30e", ';');
796



5
    REQUIRE(tokens.size() == 3);
797




9
    REQUIRE(tokens.find("10q") != tokens.end());
798




9
    REQUIRE(tokens.find("20w") != tokens.end());
799




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

4
    splitToIntVector(tokens, "", ',');
806



5
    REQUIRE(tokens.empty() == true);
807
808
1
    tokens.clear();
809

4
    splitToIntVector(tokens, "10,2,30", ',');
810



5
    REQUIRE(tokens.size() == 3);
811



4
    REQUIRE(tokens[0] == 10);
812



5
    REQUIRE(tokens[1] == 2);
813



5
    REQUIRE(tokens[2] == 30);
814
815
1
    tokens.clear();
816

4
    splitToIntVector(tokens, "10,2a,z30", ',');
817



5
    REQUIRE(tokens.size() == 3);
818



4
    REQUIRE(tokens[0] == 10);
819



5
    REQUIRE(tokens[1] == 2);
820



5
    REQUIRE(tokens[2] == 0);
821
822
1
    tokens.clear();
823

4
    splitToIntVector(tokens, "10,2,30,", ',');
824



5
    REQUIRE(tokens.size() == 3);
825



4
    REQUIRE(tokens[0] == 10);
826



5
    REQUIRE(tokens[1] == 2);
827



5
    REQUIRE(tokens[2] == 30);
828
829
1
    tokens.clear();
830

4
    splitToIntVector(tokens, "10,,30", ',');
831



5
    REQUIRE(tokens.size() == 2);
832



4
    REQUIRE(tokens[0] == 10);
833



5
    REQUIRE(tokens[1] == 30);
834
835
1
    tokens.clear();
836

4
    splitToIntVector(tokens, "10,2;30", ',');
837



5
    REQUIRE(tokens.size() == 2);
838



4
    REQUIRE(tokens[0] == 10);
839



5
    REQUIRE(tokens[1] == 2);
840
841
1
    tokens.clear();
842

4
    splitToIntVector(tokens, "10;20;30", ';');
843



5
    REQUIRE(tokens.size() == 3);
844



4
    REQUIRE(tokens[0] == 10);
845



5
    REQUIRE(tokens[1] == 20);
846



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

4
    splitToStringVector(tokens, "", ',');
853



5
    REQUIRE(tokens.empty() == true);
854
855
1
    tokens.clear();
856

4
    splitToStringVector(tokens, "t,line,zz", ',');
857



5
    REQUIRE(tokens.size() == 3);
858



4
    REQUIRE(tokens[0] == "t");
859



5
    REQUIRE(tokens[1] == "line");
860



5
    REQUIRE(tokens[2] == "zz");
861
862
1
    tokens.clear();
863

4
    splitToStringVector(tokens, "t,line,zz,", ',');
864



5
    REQUIRE(tokens.size() == 3);
865



4
    REQUIRE(tokens[0] == "t");
866



5
    REQUIRE(tokens[1] == "line");
867



5
    REQUIRE(tokens[2] == "zz");
868
869
1
    tokens.clear();
870

4
    splitToStringVector(tokens, "t,,zz", ',');
871



5
    REQUIRE(tokens.size() == 2);
872



4
    REQUIRE(tokens[0] == "t");
873



5
    REQUIRE(tokens[1] == "zz");
874
875
1
    tokens.clear();
876

4
    splitToStringVector(tokens, "10,a2;30", ',');
877



5
    REQUIRE(tokens.size() == 2);
878



4
    REQUIRE(tokens[0] == "10");
879



5
    REQUIRE(tokens[1] == "a2;30");
880
881
1
    tokens.clear();
882

4
    splitToStringVector(tokens, "a10;b;3line", ';');
883



5
    REQUIRE(tokens.size() == 3);
884



4
    REQUIRE(tokens[0] == "a10");
885



5
    REQUIRE(tokens[1] == "b");
886



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



4
    REQUIRE(str.empty());
896
897
1
    str = "test";
898
1
    replaceSpecialChars(str);
899



4
    REQUIRE("test" == str);
900
901
1
    str = "&";
902
1
    replaceSpecialChars(str);
903



4
    REQUIRE("&" == str);
904
905
1
    str = "&1";
906
1
    replaceSpecialChars(str);
907



4
    REQUIRE("&1" == str);
908
909
1
    str = "&33";
910
1
    replaceSpecialChars(str);
911



4
    REQUIRE("&33" == str);
912
913
1
    str = "&33;";
914
1
    replaceSpecialChars(str);
915



4
    REQUIRE("!" == str);
916
917
1
    str = "&33z;";
918
1
    replaceSpecialChars(str);
919



4
    REQUIRE("&33z;" == str);
920
921
1
    str = "1&33;";
922
1
    replaceSpecialChars(str);
923



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



4
    REQUIRE("!2" == str);
928
929
1
    str = "&33;&";
930
1
    replaceSpecialChars(str);
931



4
    REQUIRE("!&" == str);
932
933
1
    str = "test line&33;";
934
1
    replaceSpecialChars(str);
935



4
    REQUIRE("test line!" == str);
936
1
}
937
938
3
TEST_CASE("stringuntils normalize 1", "")
939
{
940




8
    REQUIRE(normalize("").empty());
941




8
    REQUIRE(normalize("test") == "test");
942




8
    REQUIRE(normalize("Test") == "test");
943




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




8
    REQUIRE(normalize("test line ") == "test line");
945




8
    REQUIRE(normalize(" tEst line") == "test line");
946




8
    REQUIRE(normalize("test lIne ") == "test line");
947
1
}
948
949
3
TEST_CASE("stringuntils combineDye 1", "")
950
{
951




11
    REQUIRE(combineDye("", "").empty());
952




11
    REQUIRE("test" == combineDye("test", ""));
953




11
    REQUIRE("|line" == combineDye("", "line"));
954




11
    REQUIRE("test|line" == combineDye("test", "line"));
955




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




11
    REQUIRE("aaa|line" == combineDye("aaa|w", "line"));
957




11
    REQUIRE("test|line" == combineDye("test|w", "line"));
958
1
}
959
960
3
TEST_CASE("stringuntils combineDye 2", "")
961
{
962




11
    REQUIRE(combineDye2("", "").empty());
963




11
    REQUIRE("test" == combineDye2("test", ""));
964




11
    REQUIRE("test" == combineDye2("test", "W"));
965




11
    REQUIRE(combineDye2("", "line").empty());
966




11
    REQUIRE("test.xml" == combineDye2("test.xml", "123"));
967




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




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




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




11
    REQUIRE(combineDye3("", "").empty());
978




11
    REQUIRE("test" == combineDye3("test", ""));
979




11
    REQUIRE(combineDye3("", "line").empty());
980




11
    REQUIRE("test.xml|123" == combineDye3("test.xml", "123"));
981




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




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




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




5
    REQUIRE(packList(list).empty());
993
994
2
    list.push_back(std::string());
995




5
    REQUIRE("|" == packList(list));
996
997
1
    list.clear();
998

4
    list.push_back("test");
999




5
    REQUIRE("test" == packList(list));
1000
1001

4
    list.push_back("line");
1002




5
    REQUIRE("test|line" == packList(list));
1003
1004

4
    list.push_back("2");
1005




5
    REQUIRE("test|line|2" == packList(list));
1006
1007
1
    list.clear();
1008

4
    list.push_back("|test");
1009

4
    list.push_back("line");
1010




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




5
    REQUIRE(stringToHexPath(str).empty());
1019
1020
    str = "a";
1021




5
    REQUIRE("%61/" == stringToHexPath(str));
1022
1023
    str = "ab";
1024




5
    REQUIRE("%61/%62" == stringToHexPath(str));
1025
1026
    str = "abc";
1027




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




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



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



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



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



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




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




6
    REQUIRE(findLast(str, "line"));
1067
1068
    str = "test line";
1069




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




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




6
    REQUIRE(findFirst(str, "test"));
1081
1082
    str = "test";
1083




7
    REQUIRE(findFirst(str, "test line") == false);
1084
1085
    str = "test line";
1086




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




6
    REQUIRE(findCutLast(str, ""));
1095



4
    REQUIRE(str.empty());
1096
1097
    str = "test line";
1098




6
    REQUIRE(findCutLast(str, "line"));
1099



4
    REQUIRE("test " == str);
1100
1101
    str = "test line";
1102




7
    REQUIRE(findCutLast(str, "lin") == false);
1103



4
    REQUIRE("test line" == str);
1104
1105
    str = "test";
1106




7
    REQUIRE(findCutLast(str, "test line") == false);
1107



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

4
    cutLast(str, "");
1116



4
    REQUIRE(str.empty());
1117
1118
1
    str = "test line";
1119

4
    cutLast(str, "line");
1120



4
    REQUIRE("test " == str);
1121
1122
1
    str = "test line";
1123

4
    cutLast(str, "lin");
1124



4
    REQUIRE("test line" == str);
1125
1126
1
    str = "test";
1127

4
    cutLast(str, "test line");
1128



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




6
    REQUIRE(findCutFirst(str, ""));
1137



4
    REQUIRE(str.empty());
1138
1139
    str = "test line";
1140




6
    REQUIRE(findCutFirst(str, "test"));
1141



4
    REQUIRE(" line" == str);
1142
1143
    str = "test line";
1144




7
    REQUIRE(findCutFirst(str, "est") == false);
1145



4
    REQUIRE("test line" == str);
1146
1147
    str = "test";
1148




7
    REQUIRE(findCutFirst(str, "test line") == false);
1149



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

4
    cutFirst(str, "");
1158



4
    REQUIRE(str.empty());
1159
1160
1
    str = "test line";
1161

4
    cutFirst(str, "test");
1162



4
    REQUIRE(" line" == str);
1163
1164
1
    str = "test line";
1165

4
    cutFirst(str, "est");
1166



4
    REQUIRE("test line" == str);
1167
1168
1
    str = "test";
1169

4
    cutFirst(str, "test line");
1170



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




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




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




4
    REQUIRE("test" == removeProtocol(str));
1185
1
}
1186
1187
3
TEST_CASE("stringuntils strStartWith 1", "")
1188
{
1189




9
    REQUIRE(strStartWith("", ""));
1190




9
    REQUIRE(!strStartWith("", "1"));
1191




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




9
    REQUIRE(strStartWith("test line", "test line"));
1193




9
    REQUIRE(!strStartWith("test line", "est"));
1194
1
}
1195
1196
3
TEST_CASE("stringuntils encodeLinkText", "")
1197
{
1198
2
    std::string str;
1199
1200

5
    str = encodeLinkText("test line");
1201



4
    REQUIRE(str == "test line");
1202

5
    str = encodeLinkText("test|line");
1203



4
    REQUIRE(str == "test\342\235\230line");
1204

5
    str = encodeLinkText("test||line");
1205



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

5
    str = encodeLinkText("test|line");
1213



4
    REQUIRE(str == "test\342\235\230line");
1214
3
    str = decodeLinkText(str);
1215



4
    REQUIRE(str == "test|line");
1216
1
}
1217
1218
3
TEST_CASE("stringuntils isDigit", "")
1219
{
1220




6
    REQUIRE_FALSE(isDigit(""));
1221




6
    REQUIRE(isDigit("1"));
1222




6
    REQUIRE(isDigit("123"));
1223




6
    REQUIRE_FALSE(isDigit("+123"));
1224




6
    REQUIRE_FALSE(isDigit("-123"));
1225




6
    REQUIRE_FALSE(isDigit("1.23"));
1226




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




10
    REQUIRE(findAny("test line", ",", 0) == std::string::npos);
1232




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




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




10
    REQUIRE(findAny("test ,line", ", ", 0) == 4U);
1235




10
    REQUIRE(findAny("test, line", " ,", 2) == 4U);
1236




10
    REQUIRE(findAny("test ,line", " ,", 3) == 4U);
1237




10
    REQUIRE(findAny("\"one\",,two, tree", ",", 5) == 5U);
1238
1
}
1239
1240
3
TEST_CASE("stringuntils escapeString", "")
1241
{
1242




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




8
    REQUIRE(escapeString("1") == "\"1\"");
1244




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




8
    REQUIRE(escapeString("\"") == "\"\\\"\"");
1246




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




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




8
    REQUIRE(escapeString("12\"\"3") == "\"12\\\"\\\"3\"");
1249




8
    REQUIRE(escapeString("\"123\"") == "\"\\\"123\\\"\"");
1250




8
    REQUIRE(escapeString("\\") == "\"\\\"");
1251




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



4
    REQUIRE(path.empty());
1261
1
    path = "/";
1262
1
    sanitizePath(path);
1263



4
    REQUIRE(path == dirSeparator);
1264
1
    path = "/\\";
1265
1
    sanitizePath(path);
1266



4
    REQUIRE(path == dirSeparator);
1267
1
    path = "\\/";
1268
1
    sanitizePath(path);
1269



4
    REQUIRE(path == dirSeparator);
1270
1
    path = "//";
1271
1
    sanitizePath(path);
1272



4
    REQUIRE(path == dirSeparator);
1273
1
    path = "///";
1274
1
    sanitizePath(path);
1275



4
    REQUIRE(path == dirSeparator);
1276
1
    path = "//\\/";
1277
1
    sanitizePath(path);
1278



4
    REQUIRE(path == dirSeparator);
1279
1
    path = "///\\";
1280
1
    sanitizePath(path);
1281



4
    REQUIRE(path == dirSeparator);
1282
1
    path = "\\";
1283
1
    sanitizePath(path);
1284



4
    REQUIRE(path == dirSeparator);
1285
1
    path = "\\\\";
1286
1
    sanitizePath(path);
1287



4
    REQUIRE(path == dirSeparator);
1288
1
    path = "\\/\\";
1289
1
    sanitizePath(path);
1290



4
    REQUIRE(path == dirSeparator);
1291
1
    path = "\\\\/";
1292
1
    sanitizePath(path);
1293



4
    REQUIRE(path == dirSeparator);
1294
1
    path = "test";
1295
1
    sanitizePath(path);
1296



4
    REQUIRE(path == "test");
1297
1
    path = "./test";
1298
1
    sanitizePath(path);
1299




6
    REQUIRE(path == "." + sep + "test");
1300
1
    path = "test line";
1301
1
    sanitizePath(path);
1302



4
    REQUIRE(path == "test line");
1303
1
    path = "dir/test";
1304
1
    sanitizePath(path);
1305




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





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




6
    REQUIRE(path == "dir" + sep + "test");
1312
1
    path = "dir///test";
1313
1
    sanitizePath(path);
1314




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




6
    REQUIRE(path == "dir" + sep + "test");
1318
1
    path = "dir/\\//test";
1319
1
    sanitizePath(path);
1320




6
    REQUIRE(path == "dir" + sep + "test");
1321
1
    path = "dir\\test";
1322
1
    sanitizePath(path);
1323




6
    REQUIRE(path == "dir" + sep + "test");
1324
1
    path = "dir/test/";
1325
1
    sanitizePath(path);
1326





7
    REQUIRE(path == "dir" + sep + "test" + sep);
1327
1
    path = "dir/test\\";
1328
1
    sanitizePath(path);
1329





7
    REQUIRE(path == "dir" + sep + "test" + sep);
1330
1
    path = "/very\\long/dir\\with\\sepa/ra/tors";
1331
1
    sanitizePath(path);
1332










17
    REQUIRE(path == sep + "very" + sep + "long" + sep + \
1333
        "dir" + sep + "with" + sep + "sepa" + sep + "ra" + sep + "tors");
1334
1
    path = "/very\\long/dir\\\\with\\sepa//ra/tors";
1335
1
    sanitizePath(path);
1336










17
    REQUIRE(path == sep + "very" + sep + "long" + sep + \
1337
        "dir" + sep + "with" + sep + "sepa" + sep + "ra" + sep + "tors");
1338
1
}
1339
1340
3
TEST_CASE("stringuntils pathJoin1", "")
1341
{
1342
4
    const std::string sep = dirSeparator;
1343
1344





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




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




8
    REQUIRE(pathJoin("", sep) == sep);
1347




7
    REQUIRE(pathJoin(sep, sep) == sep);
1348






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






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






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






9
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2") == "dir1" + sep + "dir2");
1352









18
    REQUIRE(pathJoin("dir1" + sep + "dir2" + sep + "dir3", "dir4") ==
1353
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4");
1354









16
    REQUIRE(pathJoin("dir1" + sep + "dir2" + sep, "dir3" + sep + "dir4") ==
1355
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4");
1356









15
    REQUIRE(pathJoin("dir1" + sep + "dir2", "dir3" + sep + "dir4") ==
1357
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4");
1358









16
    REQUIRE(pathJoin("dir1" + sep + "dir2", sep + "dir3" + sep + "dir4") ==
1359
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4");
1360
1
}
1361
1362
3
TEST_CASE("stringuntils pathJoin2", "")
1363
{
1364
4
    const std::string sep = dirSeparator;
1365
1366





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





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





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





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




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




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




8
    REQUIRE(pathJoin("", sep, sep) == sep);
1373




7
    REQUIRE(pathJoin(sep, sep, sep) == sep);
1374
1375







18
    REQUIRE(pathJoin("dir1", "dir2", "dir3") ==
1376
        "dir1" + sep + "dir2" + sep + "dir3");
1377







16
    REQUIRE(pathJoin("dir1" + sep, "dir2", "dir3") ==
1378
        "dir1" + sep + "dir2" + sep + "dir3");
1379







16
    REQUIRE(pathJoin("dir1", sep + "dir2", "dir3") ==
1380
        "dir1" + sep + "dir2" + sep + "dir3");
1381







16
    REQUIRE(pathJoin("dir1", "dir2" + sep, "dir3") ==
1382
        "dir1" + sep + "dir2" + sep + "dir3");
1383







16
    REQUIRE(pathJoin("dir1", "dir2", sep + "dir3") ==
1384
        "dir1" + sep + "dir2" + sep + "dir3");
1385








17
    REQUIRE(pathJoin("dir1", "dir2", "dir3" + sep) ==
1386
        "dir1" + sep + "dir2" + sep + "dir3" + sep);
1387







14
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2", "dir3") ==
1388
        "dir1" + sep + "dir2" + sep + "dir3");
1389







14
    REQUIRE(pathJoin("dir1" + sep, "dir2" + sep, "dir3") ==
1390
        "dir1" + sep + "dir2" + sep + "dir3");
1391







14
    REQUIRE(pathJoin("dir1" + sep, "dir2", sep + "dir3") ==
1392
        "dir1" + sep + "dir2" + sep + "dir3");
1393








15
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2" + sep, "dir3") ==
1394
        "dir1" + sep + "dir2" + sep + "dir3");
1395







12
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2", sep + "dir3") ==
1396
        "dir1" + sep + "dir2" + sep + "dir3");
1397








15
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2" + sep, "dir3") ==
1398
        "dir1" + sep + "dir2" + sep + "dir3");
1399








13
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2" + sep, sep + "dir3") ==
1400
        "dir1" + sep + "dir2" + sep + "dir3");
1401











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











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











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











19
    REQUIRE(pathJoin("dir1" + sep + "dir2",
1412
        sep + "dir3" + sep + "dir4",
1413
        sep + "dir5") ==
1414
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4" + sep + "dir5");
1415
1
}
1416
1417
3
TEST_CASE("stringuntils urlJoin", "")
1418
{
1419




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




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




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




11
    REQUIRE(urlJoin("/", "/") == "/");
1423




11
    REQUIRE(urlJoin("dir1", "dir2") == "dir1/dir2");
1424




11
    REQUIRE(urlJoin("dir1/", "dir2") == "dir1/dir2");
1425




11
    REQUIRE(urlJoin("dir1", "/dir2") == "dir1/dir2");
1426




11
    REQUIRE(urlJoin("dir1/", "/dir2") == "dir1/dir2");
1427




11
    REQUIRE(urlJoin("dir1/dir2/dir3", "dir4") == "dir1/dir2/dir3/dir4");
1428




11
    REQUIRE(urlJoin("dir1/dir2/", "dir3/dir4") == "dir1/dir2/dir3/dir4");
1429




11
    REQUIRE(urlJoin("dir1/dir2", "dir3/dir4") == "dir1/dir2/dir3/dir4");
1430




11
    REQUIRE(urlJoin("dir1/dir2", "/dir3/dir4") == "dir1/dir2/dir3/dir4");
1431
1
}
1432
1433
3
TEST_CASE("stringuntils secureChatCommand", "")
1434
{
1435
2
    std::string str;
1436
1
    secureChatCommand(str);
1437



4
    REQUIRE(str.empty());
1438
1
    str = "test";
1439
1
    secureChatCommand(str);
1440



4
    REQUIRE(str == "test");
1441
1
    str = "test line";
1442
1
    secureChatCommand(str);
1443



4
    REQUIRE(str == "test line");
1444
1
    str = "/test";
1445
1
    secureChatCommand(str);
1446



4
    REQUIRE(str == "_/test");
1447
1
    str = "@test";
1448
1
    secureChatCommand(str);
1449



4
    REQUIRE(str == "_@test");
1450
1
    str = "#test";
1451
1
    secureChatCommand(str);
1452



4
    REQUIRE(str == "_#test");
1453
1
}
1454
1455
3
TEST_CASE("stringuntils rfindSepatator", "")
1456
{
1457




10
    REQUIRE(rfindSepatator("test1") == std::string("test1").rfind('/'));
1458




10
    REQUIRE(rfindSepatator("test2/") == std::string("test2/").rfind('/'));
1459




10
    REQUIRE(rfindSepatator("test3\\") == std::string("test3\\").rfind('\\'));
1460




10
    REQUIRE(rfindSepatator("test4/qqq") ==
1461
        std::string("test4/qqq").rfind('/'));
1462




10
    REQUIRE(rfindSepatator("test5\\qqq") ==
1463
        std::string("test5\\qqq").rfind('\\'));
1464




10
    REQUIRE(rfindSepatator("test6/qqq/www") ==
1465
        std::string("test6/qqq/www").rfind('/'));
1466




10
    REQUIRE(rfindSepatator("test7\\qqq\\www") ==
1467
        std::string("test7\\qqq\\www").rfind('\\'));
1468




10
    REQUIRE(rfindSepatator("/test8") == std::string("/test8").rfind('/'));
1469




10
    REQUIRE(rfindSepatator("\\test9") == std::string("\\test9").rfind('\\'));
1470




10
    REQUIRE(rfindSepatator("test10/qqq\\www") ==
1471
        std::string("test10/qqq\\www").rfind('\\'));
1472




10
    REQUIRE(rfindSepatator("test11\\qqq/www") ==
1473
        std::string("test11\\qqq/www").rfind('/'));
1474
1
}
1475
1476
#ifdef ENABLE_NLS
1477
3
TEST_CASE("stringuntils timeDiffToString", "")
1478
{
1479



5
    REQUIRE(timeDiffToString(60 * 60 * 24 * 7) == "1 week");
1480



5
    REQUIRE(timeDiffToString(60 * 60 * 24 * 7 * 2 +
1481
        60 * 60 * 24 * 3
1482
        ) == "2 weeks, 3 days");
1483



5
    REQUIRE(timeDiffToString(60 * 60 * 24 * 7 * 2 +
1484
        60 * 60 * 24 * 3 +
1485
        60 * 60 * 4
1486
        ) == "2 weeks, 3 days, 4 hours");
1487



5
    REQUIRE(timeDiffToString(60 * 60 * 24 * 7 * 2 +
1488
        60 * 60 * 24 * 3 +
1489
        60 * 60 * 4 +
1490
        60 * 7
1491
        ) == "2 weeks, 3 days, 4 hours, 7 minutes");
1492



5
    REQUIRE(timeDiffToString(60 * 60 * 24 * 7 * 2 +
1493
        60 * 60 * 24 * 3 +
1494
        60 * 60 * 4 +
1495
        60 * 7 +
1496
        10
1497
        ) == "2 weeks, 3 days, 4 hours, 7 minutes, 10 seconds");
1498



5
    REQUIRE(timeDiffToString(5) == "5 seconds");
1499



5
    REQUIRE(timeDiffToString(0) == "0 seconds");
1500



5
    REQUIRE(timeDiffToString(60 * 60 * 24 * 3
1501
        ) == "3 days");
1502



5
    REQUIRE(timeDiffToString(60 * 60 * 4
1503
        ) == "4 hours");
1504



5
    REQUIRE(timeDiffToString(60 * 7
1505
        ) == "7 minutes");
1506
1
}
1507
#endif  // ENABLE_NLS
1508
1509
7
TEST_CASE("stringuntils replaceItemLinks", "")
1510
{
1511
20
    VirtFs::mountDirSilent("data", Append_false);
1512
20
    VirtFs::mountDirSilent("../data", Append_false);
1513
20
    VirtFs::mountDirSilent("data/test", Append_false);
1514
20
    VirtFs::mountDirSilent("../data/test", Append_false);
1515
1516
5
    TranslationManager::init();
1517
5
    ItemDB::NamedItemInfos &namedInfos = ItemDB::getNamedItemInfosTest();
1518
5
    ItemDB::ItemInfos &infos = ItemDB::getItemInfosTest();
1519
5
    setPathsDefaults(paths);
1520
5
    ItemInfo *info = new ItemInfo;
1521
10
    info->setId(123456);
1522
25
    info->setName("test name 1");
1523
20
    namedInfos["test name 1"] = info;
1524
5
    infos[123456] = info;
1525
1526
5
    info = new ItemInfo;
1527
10
    info->setId(123);
1528
25
    info->setName("test name 2");
1529
20
    namedInfos["test name 2"] = info;
1530
20
    namedInfos["qqq"] = info;
1531
5
    infos[123] = info;
1532
1533
10
    std::string str;
1534
1535



35
    SECTION("empty")
1536
    {
1537
1
        str = "test line";
1538
1
        replaceItemLinks(str);
1539



4
        REQUIRE(str == "test line");
1540
1541
1
        str = "";
1542
1
        replaceItemLinks(str);
1543



4
        REQUIRE(str.empty());
1544
1545
1
        str = "[]";
1546
1
        replaceItemLinks(str);
1547



4
        REQUIRE(str == "[]");
1548
1549
1
        str = "[qqq]";
1550
1
        replaceItemLinks(str);
1551



4
        REQUIRE(str == "[@@123|qqq@@]");
1552
1553
1
        str = "[,]";
1554
1
        replaceItemLinks(str);
1555



4
        REQUIRE(str == "[,]");
1556
1557
1
        str = "[, ]";
1558
1
        replaceItemLinks(str);
1559



4
        REQUIRE(str == "[, ]");
1560
    }
1561
1562



35
    SECTION("simple")
1563
    {
1564
1
        str = "[test name 1]";
1565
1
        replaceItemLinks(str);
1566



4
        REQUIRE(str == "[@@123456|test name 1@@]");
1567
1568
1
        str = "text1 [test name 1] text2";
1569
1
        replaceItemLinks(str);
1570



4
        REQUIRE(str == "text1 [@@123456|test name 1@@] text2");
1571
1572
1
        str = "[test name 1][test name 1]";
1573
1
        replaceItemLinks(str);
1574



4
        REQUIRE(str == "[@@123456|test name 1@@][@@123456|test name 1@@]");
1575
1576
1
        str = "[test name 1] [test name 1]";
1577
1
        replaceItemLinks(str);
1578



4
        REQUIRE(str == "[@@123456|test name 1@@] [@@123456|test name 1@@]");
1579
1580
1
        str = "test1 [test name 1]test2[test name 1] test3";
1581
1
        replaceItemLinks(str);
1582



4
        REQUIRE(str == "test1 [@@123456|test name 1@@]test2"
1583
            "[@@123456|test name 1@@] test3");
1584
1585
// failing because assert
1586
//        str = "[test name 1] [no link]";
1587
//        replaceItemLinks(str);
1588
//        REQUIRE(str == "[@@123456|test name 1@@] [no link]");
1589
1590
1
        str = "[test name 1,test name 2]";
1591
1
        replaceItemLinks(str);
1592



4
        REQUIRE(str == "[@@123456,123|@@]");
1593
1594
1
        str = "[test name 1, test name 2 ]";
1595
1
        replaceItemLinks(str);
1596



4
        REQUIRE(str == "[@@123456,123|@@]");
1597
    }
1598
1599



35
    SECTION("broken")
1600
    {
1601
1
        str = "[";
1602
1
        replaceItemLinks(str);
1603



4
        REQUIRE(str == "[");
1604
1605
1
        str = "]";
1606
1
        replaceItemLinks(str);
1607



4
        REQUIRE(str == "]");
1608
1609
1
        str = "][";
1610
1
        replaceItemLinks(str);
1611



4
        REQUIRE(str == "][");
1612
1613
1
        str = "]]";
1614
1
        replaceItemLinks(str);
1615



4
        REQUIRE(str == "]]");
1616
1617
1
        str = "]t";
1618
1
        replaceItemLinks(str);
1619



4
        REQUIRE(str == "]t");
1620
1621
1
        str = "t[";
1622
1
        replaceItemLinks(str);
1623



4
        REQUIRE(str == "t[");
1624
1625
1
        str = "t]";
1626
1
        replaceItemLinks(str);
1627



4
        REQUIRE(str == "t]");
1628
1629
1
        str = "[[[";
1630
1
        replaceItemLinks(str);
1631



4
        REQUIRE(str == "[[[");
1632
1633
1
        str = "[[]";
1634
1
        replaceItemLinks(str);
1635



4
        REQUIRE(str == "[[]");
1636
1637
1
        str = "[[t";
1638
1
        replaceItemLinks(str);
1639



4
        REQUIRE(str == "[[t");
1640
1641
1
        str = "[][";
1642
1
        replaceItemLinks(str);
1643



4
        REQUIRE(str == "[][");
1644
1645
1
        str = "[]]";
1646
1
        replaceItemLinks(str);
1647



4
        REQUIRE(str == "[]]");
1648
1649
1
        str = "[]t";
1650
1
        replaceItemLinks(str);
1651



4
        REQUIRE(str == "[]t");
1652
1653
1
        str = "[t[";
1654
1
        replaceItemLinks(str);
1655



4
        REQUIRE(str == "[t[");
1656
1657
// failing because assert
1658
//        str = "[t]";
1659
//        replaceItemLinks(str);
1660
//        REQUIRE(str == "[t]");
1661
1662
1
        str = "t[[";
1663
1
        replaceItemLinks(str);
1664



4
        REQUIRE(str == "t[[");
1665
1666
1
        str = "t[]";
1667
1
        replaceItemLinks(str);
1668



4
        REQUIRE(str == "t[]");
1669
1670
1
        str = "t[[";
1671
1
        replaceItemLinks(str);
1672



4
        REQUIRE(str == "t[[");
1673
1674
1
        str = "]]]";
1675
1
        replaceItemLinks(str);
1676



4
        REQUIRE(str == "]]]");
1677
    }
1678
1679



35
    SECTION("broken2")
1680
    {
1681
1
        str = "[][]";
1682
1
        replaceItemLinks(str);
1683



4
        REQUIRE(str == "[][]");
1684
1685
1
        str = "[[]]";
1686
1
        replaceItemLinks(str);
1687



4
        REQUIRE(str == "[[]]");
1688
1689
1
        str = "][[]";
1690
1
        replaceItemLinks(str);
1691



4
        REQUIRE(str == "][[]");
1692
    }
1693
1694



35
    SECTION("broken3")
1695
    {
1696
1
        str = "[[test name 1]]";
1697
1
        replaceItemLinks(str);
1698



4
        REQUIRE(str == "[[@@123456|test name 1@@]]");
1699
1700
1
        str = "[[test name 1]";
1701
1
        replaceItemLinks(str);
1702



4
        REQUIRE(str == "[[@@123456|test name 1@@]");
1703
1704
1
        str = "[[qqq] name 1]";
1705
1
        replaceItemLinks(str);
1706



4
        REQUIRE(str == "[[@@123|qqq@@] name 1]");
1707
1708
1
        str = "[[test name 1]test name 1]";
1709
1
        replaceItemLinks(str);
1710



4
        REQUIRE(str == "[[@@123456|test name 1@@]test name 1]");
1711
1712
1
        str = "[[test name 1[]test name 1]";
1713
1
        replaceItemLinks(str);
1714



4
        REQUIRE(str == "[[test name 1[]test name 1]");
1715
1716
1
        str = "[[test name 1],test name2,test name 1]";
1717
1
        replaceItemLinks(str);
1718



4
        REQUIRE(str == "[[@@123456|test name 1@@],test name2,test name 1]");
1719
1720
1
        str = "[[ test name 1], test name2,test name 1 ]";
1721
1
        replaceItemLinks(str);
1722



4
        REQUIRE(str == "[[@@123456|test name 1@@], test name2,test name 1 ]");
1723
1724
1
        str = "[[test name 1,test name2[]test name 1]";
1725
1
        replaceItemLinks(str);
1726



4
        REQUIRE(str == "[[test name 1,test name2[]test name 1]");
1727
1728
1
        str = "[[test name 1 ,test name2[] test name 1]";
1729
1
        replaceItemLinks(str);
1730



4
        REQUIRE(str == "[[test name 1 ,test name2[] test name 1]");
1731
    }
1732
5
    ResourceManager::deleteInstance();
1733
5
    delete_all(infos);
1734
5
    infos.clear();
1735
5
    namedInfos.clear();
1736

20
    VirtFs::unmountDirSilent("data");
1737

20
    VirtFs::unmountDirSilent("../data");
1738

20
    VirtFs::unmountDirSilent("data/test");
1739

20
    VirtFs::unmountDirSilent("../data/test");
1740

8
}