GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/gui/fonts/textchunklist.cc Lines: 352 352 100.0 %
Date: 2017-11-29 Branches: 992 2572 38.6 %

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



8
    REQUIRE(0 == list.size);
33



8
    REQUIRE(nullptr == list.start);
34



8
    REQUIRE(nullptr == list.end);
35



8
    REQUIRE(list.search.empty());
36



8
    REQUIRE(list.searchWidth.empty());
37
2
}
38
39
6
TEST_CASE("TextChunkList add 1", "TextChunkList")
40
{
41
4
    TextChunkList list;
42
43
    TextChunk *const chunk = new TextChunk("test",
44

12
        Color(1, 2, 3), Color(2, 3, 4), nullptr);
45
46
2
    list.insertFirst(chunk);
47
48



8
    REQUIRE(1 == list.size);
49



8
    REQUIRE(chunk == list.start);
50



8
    REQUIRE(chunk == list.end);
51



8
    REQUIRE(nullptr == chunk->prev);
52



8
    REQUIRE(nullptr == chunk->next);
53
54



10
    REQUIRE(1 == list.search.size());
55




14
    REQUIRE(chunk == (*list.search.find(TextChunkSmall(
56
        chunk->text, chunk->color, chunk->color2))).second);
57
58



10
    REQUIRE(1 == list.searchWidth.size());
59



12
    REQUIRE(chunk == (*list.searchWidth.find(chunk->text)).second);
60
2
    delete chunk;
61
2
}
62
63
6
TEST_CASE("TextChunkList add 2", "TextChunkList")
64
{
65
4
    TextChunkList list;
66
67
    TextChunk *const chunk1 = new TextChunk("test",
68

12
        Color(1, 2, 3), Color(3, 4, 5), nullptr);
69
    TextChunk *const chunk2 = new TextChunk("test",
70

12
        Color(2, 3, 4), Color(4, 5, 6), nullptr);
71
72
2
    list.insertFirst(chunk2);
73
2
    list.insertFirst(chunk1);
74
75



8
    REQUIRE(2 == list.size);
76



8
    REQUIRE(chunk1 == list.start);
77



8
    REQUIRE(chunk2 == list.end);
78



8
    REQUIRE(nullptr == chunk1->prev);
79



8
    REQUIRE(chunk2 == chunk1->next);
80



8
    REQUIRE(chunk1 == chunk2->prev);
81



8
    REQUIRE(nullptr == chunk2->next);
82
83



10
    REQUIRE(2 == list.search.size());
84




14
    REQUIRE(chunk1 == (*list.search.find(TextChunkSmall(
85
        chunk1->text, chunk1->color, chunk1->color2))).second);
86




14
    REQUIRE(chunk2 == (*list.search.find(TextChunkSmall(
87
        chunk2->text, chunk2->color, chunk2->color2))).second);
88
89



10
    REQUIRE(1 == list.searchWidth.size());
90



12
    REQUIRE(chunk1 == (*list.searchWidth.find(chunk1->text)).second);
91
2
    delete chunk1;
92
2
    delete chunk2;
93
2
}
94
95
6
TEST_CASE("TextChunkList addRemoveBack 1", "TextChunkList")
96
{
97
4
    TextChunkList list;
98
99
    TextChunk *const chunk = new TextChunk("test",
100

12
        Color(1, 2, 3), Color(1, 2, 3), nullptr);
101
102
2
    list.insertFirst(chunk);
103
2
    list.removeBack();
104
105



8
    REQUIRE(0 == list.size);
106



8
    REQUIRE(nullptr == list.start);
107



8
    REQUIRE(nullptr == list.end);
108



8
    REQUIRE(list.search.empty());
109



8
    REQUIRE(list.searchWidth.empty());
110
2
}
111
112
6
TEST_CASE("TextChunkList addRemoveBack 2", "TextChunkList")
113
{
114
4
    TextChunkList list;
115
116
    TextChunk *const chunk1 = new TextChunk("test",
117

12
        Color(1, 2, 3), Color(1, 2, 3), nullptr);
118
    TextChunk *const chunk2 = new TextChunk("test2",
119

12
        Color(1, 2, 4), Color(1, 2, 5), nullptr);
120
121
2
    list.insertFirst(chunk2);
122
2
    list.insertFirst(chunk1);
123
2
    list.removeBack();
124
125



8
    REQUIRE(1 == list.size);
126



8
    REQUIRE(chunk1 == list.start);
127



8
    REQUIRE(chunk1 == list.end);
128



8
    REQUIRE(nullptr == chunk1->prev);
129



8
    REQUIRE(nullptr == chunk1->next);
130
131



10
    REQUIRE(1 == list.search.size());
132




14
    REQUIRE(chunk1 == (*list.search.find(TextChunkSmall(
133
        chunk1->text, chunk1->color, chunk1->color2))).second);
134
135



10
    REQUIRE(1 == list.searchWidth.size());
136



12
    REQUIRE(chunk1 == (*list.searchWidth.find(chunk1->text)).second);
137
2
    delete chunk1;
138
2
}
139
140
6
TEST_CASE("TextChunkList addRemoveBack 3", "TextChunkList")
141
{
142
4
    TextChunkList list;
143
144
    TextChunk *const chunk1 = new TextChunk("test",
145

12
        Color(1, 2, 3), Color(1, 2, 3), nullptr);
146
    TextChunk *const chunk2 = new TextChunk("test2",
147

12
        Color(2, 3, 4), Color(2, 3, 4), nullptr);
148
149
2
    list.insertFirst(chunk2);
150
2
    list.insertFirst(chunk1);
151
2
    list.removeBack(2);
152
153



8
    REQUIRE(0 == list.size);
154



8
    REQUIRE(nullptr == list.start);
155



8
    REQUIRE(nullptr == list.end);
156
157



8
    REQUIRE(list.search.empty());
158



8
    REQUIRE(list.searchWidth.empty());
159
2
}
160
161
6
TEST_CASE("TextChunkList addRemoveBack 4", "TextChunkList")
162
{
163
4
    TextChunkList list;
164
165
    TextChunk *const chunk1 = new TextChunk("test",
166

12
        Color(1, 2, 3), Color(1, 2, 3), nullptr);
167
    TextChunk *const chunk2 = new TextChunk("test2",
168

12
        Color(2, 3, 4), Color(2, 3, 4), nullptr);
169
    TextChunk *const chunk3 = new TextChunk("test",
170

12
        Color(3, 4, 5), Color(3, 4, 5), nullptr);
171
172
2
    list.insertFirst(chunk3);
173
2
    list.insertFirst(chunk2);
174
2
    list.insertFirst(chunk1);
175
2
    list.removeBack();
176
2
    list.removeBack();
177
178



8
    REQUIRE(1 == list.size);
179



8
    REQUIRE(chunk1 == list.start);
180



8
    REQUIRE(chunk1 == list.end);
181



8
    REQUIRE(nullptr == chunk1->prev);
182



8
    REQUIRE(nullptr == chunk1->next);
183
184



10
    REQUIRE(1 == list.search.size());
185




14
    REQUIRE(chunk1 == (*list.search.find(TextChunkSmall(
186
        chunk1->text, chunk1->color, chunk1->color2))).second);
187
188



8
    REQUIRE(list.searchWidth.empty());
189
2
    delete chunk1;
190
2
}
191
192
6
TEST_CASE("TextChunkList moveToFirst 1", "TextChunkList")
193
{
194
4
    TextChunkList list;
195
196
    TextChunk *const chunk = new TextChunk("test",
197

12
        Color(1, 2, 3), Color(2, 3, 4), nullptr);
198
199
2
    list.insertFirst(chunk);
200
2
    list.moveToFirst(chunk);
201
202



8
    REQUIRE(1 == list.size);
203



8
    REQUIRE(chunk == list.start);
204



8
    REQUIRE(chunk == list.end);
205



8
    REQUIRE(nullptr == chunk->prev);
206



8
    REQUIRE(nullptr == chunk->next);
207
2
    delete chunk;
208
2
}
209
210
6
TEST_CASE("TextChunkList moveToFirst 2", "TextChunkList")
211
{
212
4
    TextChunkList list;
213
214
    TextChunk *const chunk1 = new TextChunk("test",
215

12
        Color(1, 2, 3), Color(1, 2, 3), nullptr);
216
    TextChunk *const chunk2 = new TextChunk("test",
217

12
        Color(2, 3, 4), Color(1, 2, 3), nullptr);
218
219
2
    list.insertFirst(chunk1);
220
2
    list.insertFirst(chunk2);
221
2
    list.moveToFirst(chunk1);
222
223



8
    REQUIRE(2 == list.size);
224



8
    REQUIRE(chunk1 == list.start);
225



8
    REQUIRE(chunk2 == list.end);
226



8
    REQUIRE(nullptr == chunk1->prev);
227



8
    REQUIRE(chunk2 == chunk1->next);
228



8
    REQUIRE(chunk1 == chunk2->prev);
229



8
    REQUIRE(nullptr == chunk2->next);
230
2
    delete chunk1;
231
2
    delete chunk2;
232
2
}
233
234
6
TEST_CASE("TextChunkList moveToFirst 3", "TextChunkList")
235
{
236
4
    TextChunkList list;
237
238
    TextChunk *const chunk1 = new TextChunk("test",
239

12
        Color(1, 2, 3), Color(1, 2, 3), nullptr);
240
    TextChunk *const chunk2 = new TextChunk("test",
241

12
        Color(1, 2, 4), Color(1, 2, 3), nullptr);
242
    TextChunk *const chunk3 = new TextChunk("test",
243

12
        Color(1, 2, 5), Color(1, 2, 3), nullptr);
244
245
2
    list.insertFirst(chunk3);
246
2
    list.insertFirst(chunk1);
247
2
    list.insertFirst(chunk2);
248
2
    list.moveToFirst(chunk1);
249
250



8
    REQUIRE(3 == list.size);
251



8
    REQUIRE(chunk1 == list.start);
252



8
    REQUIRE(chunk3 == list.end);
253



8
    REQUIRE(nullptr == chunk1->prev);
254



8
    REQUIRE(chunk2 == chunk1->next);
255



8
    REQUIRE(chunk1 == chunk2->prev);
256



8
    REQUIRE(chunk3 == chunk2->next);
257



8
    REQUIRE(chunk2 == chunk3->prev);
258



8
    REQUIRE(nullptr == chunk3->next);
259
2
    delete chunk1;
260
2
    delete chunk2;
261
2
    delete chunk3;
262
2
}
263
264
6
TEST_CASE("TextChunkList moveToFirst 4", "TextChunkList")
265
{
266
4
    TextChunkList list;
267
268
    TextChunk *const chunk1 = new TextChunk("test",
269

12
        Color(), Color(), nullptr);
270
    TextChunk *const chunk2 = new TextChunk("test2",
271

12
        Color(), Color(), nullptr);
272
    TextChunk *const chunk3 = new TextChunk("test3",
273

12
        Color(), Color(), nullptr);
274
275
2
    list.insertFirst(chunk1);
276
2
    list.insertFirst(chunk3);
277
2
    list.insertFirst(chunk2);
278
2
    list.moveToFirst(chunk1);
279
280



8
    REQUIRE(3 == list.size);
281



8
    REQUIRE(chunk1 == list.start);
282



8
    REQUIRE(chunk3 == list.end);
283



8
    REQUIRE(nullptr == chunk1->prev);
284



8
    REQUIRE(chunk2 == chunk1->next);
285



8
    REQUIRE(chunk1 == chunk2->prev);
286



8
    REQUIRE(chunk3 == chunk2->next);
287



8
    REQUIRE(chunk2 == chunk3->prev);
288



8
    REQUIRE(nullptr == chunk3->next);
289
2
    delete chunk1;
290
2
    delete chunk2;
291
2
    delete chunk3;
292
2
}
293
294
6
TEST_CASE("TextChunkList clear 1", "TextChunkList")
295
{
296
4
    TextChunkList list;
297
2
    const int chunksLeft = textChunkCnt;
298
299
    TextChunk *const chunk = new TextChunk("test",
300

12
        Color(), Color(), nullptr);
301
302
2
    list.insertFirst(chunk);
303
2
    list.clear();
304
305



8
    REQUIRE(0 == list.size);
306



8
    REQUIRE(nullptr == list.start);
307



8
    REQUIRE(nullptr == list.end);
308



8
    REQUIRE(chunksLeft == textChunkCnt);
309



8
    REQUIRE(list.search.empty());
310



8
    REQUIRE(list.searchWidth.empty());
311
2
}
312
313
6
TEST_CASE("TextChunkList clear 2", "TextChunkList")
314
{
315
4
    TextChunkList list;
316
2
    const int chunksLeft = textChunkCnt;
317
318
    TextChunk *const chunk1 = new TextChunk("test",
319

12
        Color(1, 2, 3), Color(2, 0, 0), nullptr);
320
    TextChunk *const chunk2 = new TextChunk("test",
321

12
        Color(1, 2, 3), Color(2, 0, 1), nullptr);
322
    TextChunk *const chunk3 = new TextChunk("test",
323

12
        Color(1, 2, 3), Color(2, 0, 2), nullptr);
324
325
2
    list.insertFirst(chunk1);
326
2
    list.insertFirst(chunk2);
327
2
    list.insertFirst(chunk3);
328
2
    list.clear();
329
330



8
    REQUIRE(0 == list.size);
331



8
    REQUIRE(nullptr == list.start);
332



8
    REQUIRE(nullptr == list.end);
333



8
    REQUIRE(chunksLeft == textChunkCnt);
334



8
    REQUIRE(list.search.empty());
335



8
    REQUIRE(list.searchWidth.empty());
336
2
}
337
338
6
TEST_CASE("TextChunkList clear 3", "TextChunkList")
339
{
340
4
    TextChunkList list;
341
2
    const int chunksLeft = textChunkCnt;
342
343
    TextChunk *const chunk1 = new TextChunk("test",
344

12
        Color(1, 2, 3), Color(2, 0, 0), nullptr);
345
    TextChunk *const chunk2 = new TextChunk("test",
346

12
        Color(1, 2, 3), Color(2, 0, 1), nullptr);
347
    TextChunk *const chunk3 = new TextChunk("test",
348

12
        Color(1, 2, 3), Color(2, 0, 2), nullptr);
349
350
2
    list.insertFirst(chunk1);
351
2
    list.insertFirst(chunk2);
352
2
    list.insertFirst(chunk3);
353
2
    list.moveToFirst(chunk1);
354



8
    REQUIRE((chunksLeft + 3) == textChunkCnt);
355



10
    REQUIRE(3 == list.search.size());
356



10
    REQUIRE(1 == list.searchWidth.size());
357
358
2
    list.removeBack();
359



8
    REQUIRE((chunksLeft + 2) == textChunkCnt);
360



10
    REQUIRE(2 == list.search.size());
361



8
    REQUIRE(list.searchWidth.empty());
362
363
2
    list.clear();
364



8
    REQUIRE(chunksLeft == textChunkCnt);
365



8
    REQUIRE(list.search.empty());
366



8
    REQUIRE(list.searchWidth.empty());
367
2
}
368
369
6
TEST_CASE("TextChunkList clear 4", "TextChunkList")
370
{
371
4
    TextChunkList list;
372
2
    const int chunksLeft = textChunkCnt;
373
374
    TextChunk *const chunk1 = new TextChunk("test",
375

12
        Color(1, 2, 3), Color(2, 0, 0), nullptr);
376
    TextChunk *const chunk2 = new TextChunk("test",
377

12
        Color(1, 2, 3), Color(2, 0, 1), nullptr);
378
    TextChunk *const chunk3 = new TextChunk("test3",
379

12
        Color(1, 2, 3), Color(2, 0, 2), nullptr);
380
381
2
    list.insertFirst(chunk1);
382
2
    list.insertFirst(chunk2);
383
2
    list.insertFirst(chunk3);
384
2
    list.moveToFirst(chunk2);
385



8
    REQUIRE((chunksLeft + 3) == textChunkCnt);
386



10
    REQUIRE(3 == list.search.size());
387



10
    REQUIRE(2 == list.searchWidth.size());
388
389
2
    list.removeBack(2);
390



8
    REQUIRE((chunksLeft + 1) == textChunkCnt);
391



10
    REQUIRE(1 == list.search.size());
392



8
    REQUIRE(list.searchWidth.empty());
393
394
2
    list.clear();
395



8
    REQUIRE(chunksLeft == textChunkCnt);
396



8
    REQUIRE(list.search.empty());
397



8
    REQUIRE(list.searchWidth.empty());
398
2
}
399
400
6
TEST_CASE("TextChunkList remove 1", "TextChunkList")
401
{
402
4
    TextChunkList list;
403
2
    const int chunksLeft = textChunkCnt;
404
405
    TextChunk *const chunk = new TextChunk("test",
406

12
        Color(), Color(), nullptr);
407
408
2
    list.insertFirst(chunk);
409
2
    list.remove(chunk);
410
2
    delete chunk;
411
412



8
    REQUIRE(0 == list.size);
413



8
    REQUIRE(nullptr == list.start);
414



8
    REQUIRE(nullptr == list.end);
415



8
    REQUIRE(chunksLeft == textChunkCnt);
416



8
    REQUIRE(list.search.empty());
417



8
    REQUIRE(list.searchWidth.empty());
418
2
}
419
420
6
TEST_CASE("TextChunkList remove 2", "TextChunkList")
421
{
422
4
    TextChunkList list;
423
2
    const int chunksLeft = textChunkCnt;
424
425
    TextChunk *const chunk1 = new TextChunk("test1",
426

12
        Color(1, 2, 3), Color(2, 0, 0), nullptr);
427
    TextChunk *const chunk2 = new TextChunk("test2",
428

12
        Color(1, 2, 3), Color(2, 0, 1), nullptr);
429
    TextChunk *const chunk3 = new TextChunk("test3",
430

12
        Color(1, 2, 3), Color(2, 0, 2), nullptr);
431
432
2
    list.insertFirst(chunk1);
433
2
    list.insertFirst(chunk2);
434
2
    list.insertFirst(chunk3);
435
2
    list.remove(chunk1);
436
2
    delete chunk1;
437
438



8
    REQUIRE(2 == list.size);
439



8
    REQUIRE(chunk3 == list.start);
440



8
    REQUIRE(chunk2 == list.end);
441



8
    REQUIRE((chunksLeft + 2) == textChunkCnt);
442



10
    REQUIRE(2 == list.search.size());
443



10
    REQUIRE(2 == list.searchWidth.size());
444
2
    delete chunk2;
445
2
    delete chunk3;
446
2
}
447
448
6
TEST_CASE("TextChunkList remove 3", "TextChunkList")
449
{
450
4
    TextChunkList list;
451
2
    const int chunksLeft = textChunkCnt;
452
453
    TextChunk *const chunk1 = new TextChunk("test1",
454

12
        Color(1, 2, 3), Color(2, 0, 0), nullptr);
455
    TextChunk *const chunk2 = new TextChunk("test2",
456

12
        Color(1, 2, 3), Color(2, 0, 1), nullptr);
457
    TextChunk *const chunk3 = new TextChunk("test3",
458

12
        Color(1, 2, 3), Color(2, 0, 2), nullptr);
459
460
2
    list.insertFirst(chunk1);
461
2
    list.insertFirst(chunk2);
462
2
    list.insertFirst(chunk3);
463
2
    list.remove(chunk2);
464
2
    delete chunk2;
465
466



8
    REQUIRE(2 == list.size);
467



8
    REQUIRE(chunk3 == list.start);
468



8
    REQUIRE(chunk1 == list.end);
469



8
    REQUIRE((chunksLeft + 2) == textChunkCnt);
470



10
    REQUIRE(2 == list.search.size());
471



10
    REQUIRE(2 == list.searchWidth.size());
472
2
    delete chunk1;
473
2
    delete chunk3;
474
2
}
475
476
6
TEST_CASE("TextChunkList sort 1", "TextChunkList")
477
{
478
    TextChunkSmall item1("test line1",
479

12
        Color(1, 2, 3), Color(1, 2, 3));
480
    TextChunkSmall item2("test line1",
481

12
        Color(1, 2, 3), Color(1, 2, 3));
482
    TextChunkSmall item3("test line2",
483

12
        Color(1, 2, 3), Color(1, 2, 3));
484




8
    REQUIRE(false == (item1 < item2));
485




8
    REQUIRE(false == (item2 < item1));
486



8
    REQUIRE(item1 < item3);
487




8
    REQUIRE(false == (item3 < item1));
488
2
}
489
490
6
TEST_CASE("TextChunkList sort 2", "TextChunkList")
491
{
492
    TextChunkSmall item1("test line1",
493

12
        Color(1, 2, 3), Color(1, 2, 3));
494
    TextChunkSmall item2("test line1",
495

12
        Color(2, 3, 4), Color(1, 2, 3));
496



8
    REQUIRE(item1 < item2);
497




8
    REQUIRE(false == (item2 < item1));
498
2
}
499
500
6
TEST_CASE("TextChunkList sort 3", "TextChunkList")
501
{
502
    TextChunkSmall item1("test line1",
503

12
        Color(1, 2, 3), Color(1, 2, 3));
504
    TextChunkSmall item2("test line1",
505

12
        Color(1, 3, 4), Color(1, 2, 3));
506



8
    REQUIRE(item1 < item2);
507




8
    REQUIRE(false == (item2 < item1));
508
2
}
509
510
6
TEST_CASE("TextChunkList sort 4", "TextChunkList")
511
{
512
    TextChunkSmall item1("test line1",
513

12
        Color(1, 2, 3), Color(1, 2, 3));
514
    TextChunkSmall item2("test line1",
515

12
        Color(1, 2, 4), Color(1, 2, 3));
516



8
    REQUIRE(item1 < item2);
517




8
    REQUIRE(false == (item2 < item1));
518
2
}
519
520
6
TEST_CASE("TextChunkList sort 5", "TextChunkList")
521
{
522
    TextChunkSmall item1("test line1",
523

12
        Color(1, 2, 3), Color(1, 2, 3));
524
    TextChunkSmall item2("test line1",
525

12
        Color(1, 2, 3), Color(2, 2, 3));
526



8
    REQUIRE(item1 < item2);
527




8
    REQUIRE(false == (item2 < item1));
528
2
}
529
530
6
TEST_CASE("TextChunkList sort 6", "TextChunkList")
531
{
532
    TextChunkSmall item1("test line1",
533

12
        Color(1, 2, 3), Color(1, 2, 3));
534
    TextChunkSmall item2("test line1",
535

12
        Color(1, 2, 3), Color(1, 3, 3));
536



8
    REQUIRE(item1 < item2);
537




8
    REQUIRE(false == (item2 < item1));
538
2
}
539
540
6
TEST_CASE("TextChunkList sort 7", "TextChunkList")
541
{
542
    TextChunkSmall item1("test line1",
543

12
        Color(1, 2, 3), Color(1, 2, 3));
544
    TextChunkSmall item2("test line1",
545

12
        Color(1, 2, 3), Color(1, 2, 4));
546



8
    REQUIRE(item1 < item2);
547




8
    REQUIRE(false == (item2 < item1));
548

8
}