GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/resources/resourcemanager/resourcemanager.cc Lines: 514 514 100.0 %
Date: 2021-03-17 Branches: 2198 5668 38.8 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2013-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 "client.h"
25
#include "configmanager.h"
26
#include "configuration.h"
27
#include "dirs.h"
28
#include "graphicsmanager.h"
29
30
#include "being/actorsprite.h"
31
32
#include "fs/virtfs/fs.h"
33
34
#include "gui/userpalette.h"
35
#include "gui/theme.h"
36
37
#include "resources/sdlimagehelper.h"
38
39
#include "resources/resourcemanager/resourcemanager.h"
40
41
#include "utils/env.h"
42
#include "utils/delete2.h"
43
44
#include <unistd.h>
45
46
PRAGMA48(GCC diagnostic push)
47
PRAGMA48(GCC diagnostic ignored "-Wshadow")
48
#ifndef USE_SDL2
49
#include <SDL.h>
50
#endif  // USE_SDL2
51
PRAGMA48(GCC diagnostic pop)
52
53
#include "debug.h"
54
55
namespace
56
{
57
    int testResouceCounter = 0;
58
59
    class TestResource : public Resource
60
    {
61
        public:
62
23
            TestResource() :
63
46
                Resource()
64
            {
65
23
                testResouceCounter ++;
66
23
            }
67
68
23
            ~TestResource()
69
46
            {
70
23
                testResouceCounter --;
71
23
            }
72
    };
73
74
38
    struct TestLoader final
75
    {
76
        std::string path;
77
22
        static Resource *load(const void *const v)
78
        {
79
            BLOCK_START("TestLoader::load")
80
22
            if (v == nullptr)
81
            {
82
                BLOCK_END("TestLoader::load")
83
                return nullptr;
84
            }
85
86
22
            Resource *const res = new TestResource();
87
            BLOCK_END("TestLoader::load")
88
            return res;
89
        }
90
    };
91
92
}  // namespace
93
94
23
TEST_CASE("resourcemanager", "resourcemanager")
95
{
96
21
    setEnv("SDL_VIDEODRIVER", "dummy");
97
98
21
    client = new Client;
99
21
    XML::initXML();
100
21
    SDL_Init(SDL_INIT_VIDEO);
101
84
    VirtFs::mountDirSilent("data", Append_false);
102
84
    VirtFs::mountDirSilent("../data", Append_false);
103
104
42
    imageHelper = new SDLImageHelper();
105
106
21
    Dirs::initRootDir();
107
21
    Dirs::initHomeDir();
108
109
21
    setBrandingDefaults(branding);
110
21
    ConfigManager::initConfiguration();
111
112
#ifdef USE_SDL2
113
21
    SDLImageHelper::setRenderer(graphicsManager.createRenderer(
114
        GraphicsManager::createWindow(640, 480, 0,
115
21
        SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
116
#else  // USE_SDL2
117
118
    GraphicsManager::createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
119
#endif  // USE_SDL2
120
121
21
    userPalette = new UserPalette;
122
123
21
    theme = new Theme;
124
21
    Theme::selectSkin();
125
126
21
    ActorSprite::load();
127
128
//    ConfigManager::initConfiguration();
129
//    setConfigDefaults2(config);
130
131
42
    while (ResourceManager::cleanOrphans(true))
132
        continue;
133
134
21
    testResouceCounter = 0;
135
42
    const size_t resSize = ResourceManager::getResources().size();
136
137



147
    SECTION("resourcemanager get 0")
138
    {
139



4
        REQUIRE(testResouceCounter == 0);
140




5
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
141




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
142




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
143
    }
144
145



147
    SECTION("resourcemanager get 1")
146
    {
147



4
        REQUIRE(testResouceCounter == 0);
148
4
        TestLoader rl = { "test1" };
149

4
        Resource *res = ResourceManager::get("test1",
150
1
            TestLoader::load, &rl);
151



4
        REQUIRE(testResouceCounter == 1);
152



4
        REQUIRE(res != nullptr);
153



4
        REQUIRE(res->mRefCount == 1);
154




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
155





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
156




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
157




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
158
1
        res->decRef();
159



4
        REQUIRE(res->mRefCount == 0);
160
    }
161
162



147
    SECTION("resourcemanager get 2")
163
    {
164
4
        TestLoader rl = { "test1" };
165

4
        Resource *const res = ResourceManager::get("test1",
166
1
            TestLoader::load, &rl);
167



4
        REQUIRE(res != nullptr);
168



4
        REQUIRE(testResouceCounter == 1);
169



4
        REQUIRE(res->mRefCount == 1);
170
1
        res->mSource = "source 1";
171



4
        REQUIRE(res->mSource == "source 1");
172




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
173





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
174




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
175




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
176

4
        Resource *const res2 = ResourceManager::get("test1",
177
1
            TestLoader::load, &rl);
178



4
        REQUIRE(res2 != nullptr);
179



4
        REQUIRE(testResouceCounter == 1);
180



4
        REQUIRE(res->mRefCount == 2);
181



4
        REQUIRE(res2->mRefCount == 2);
182



4
        REQUIRE(res->mIdPath == res2->mIdPath);
183



4
        REQUIRE(res2->mSource == "source 1");
184




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
185





7
        REQUIRE(ResourceManager::getResources()["test1"] == res2);
186




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
187




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
188
1
        res->decRef();
189
1
        res2->decRef();
190



4
        REQUIRE(res->mRefCount == 0);
191
    }
192
193



147
    SECTION("resourcemanager get 3")
194
    {
195
4
        TestLoader rl = { "test1" };
196

4
        Resource *res = ResourceManager::get("test1",
197
1
            TestLoader::load, &rl);
198



4
        REQUIRE(res != nullptr);
199



4
        REQUIRE(testResouceCounter == 1);
200



4
        REQUIRE(res->mRefCount == 1);
201




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
202





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
203




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
204




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
205
2
        res->mSource = "source 1";
206
1
        res->decRef();
207




5
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
208





7
        REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
209




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
210



4
        REQUIRE(res->mRefCount == 0);
211
    }
212
213



147
    SECTION("resourcemanager get 4")
214
    {
215
4
        TestLoader rl = { "test1" };
216

4
        Resource *res = ResourceManager::get("test1",
217
1
            TestLoader::load, &rl);
218



4
        REQUIRE(res != nullptr);
219



4
        REQUIRE(testResouceCounter == 1);
220



4
        REQUIRE(res->mRefCount == 1);
221




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
222





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
223




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
224




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
225
2
        res->mSource = "source 1";
226
1
        res->decRef();
227



4
        REQUIRE(res->mRefCount == 0);
228




5
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
229





7
        REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
230




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
231
232

4
        Resource *const res2 = ResourceManager::get("test1",
233
1
            TestLoader::load, &rl);
234



4
        REQUIRE(res2 != nullptr);
235



4
        REQUIRE(testResouceCounter == 1);
236



4
        REQUIRE(res2->mRefCount == 1);
237



4
        REQUIRE(res->mIdPath == res2->mIdPath);
238



4
        REQUIRE(res2->mSource == "source 1");
239




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
240





7
        REQUIRE(ResourceManager::getResources()["test1"] == res2);
241




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
242




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
243
1
        res2->decRef();
244



4
        REQUIRE(res->mRefCount == 0);
245
    }
246
247



147
    SECTION("resourcemanager get 5")
248
    {
249
4
        TestLoader rl = { "test1" };
250

4
        Resource *res = ResourceManager::get("test1",
251
1
            TestLoader::load, &rl);
252




7
        REQUIRE(ResourceManager::isInCache("test1") == true);
253



4
        REQUIRE(res != nullptr);
254



4
        REQUIRE(testResouceCounter == 1);
255



4
        REQUIRE(res->mRefCount == 1);
256




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
257





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
258




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
259




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
260
2
        res->mSource = "source 1";
261
1
        res->decRef();
262



4
        REQUIRE(res->mRefCount == 0);
263




5
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
264




5
        REQUIRE(ResourceManager::getOrphanedResources().size() == 1);
265





7
        REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
266




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
267
268
1
        sleep(33);
269
1
        ResourceManager::cleanOrphans(false);
270




7
        REQUIRE(ResourceManager::isInCache("test1") == false);
271



4
        REQUIRE(testResouceCounter == 0);
272




5
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
273




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
274




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
275
276

4
        Resource *const res2 = ResourceManager::get("test1",
277
1
            TestLoader::load, &rl);
278




7
        REQUIRE(ResourceManager::isInCache("test1") == true);
279



4
        REQUIRE(res2 != nullptr);
280



4
        REQUIRE(testResouceCounter == 1);
281



4
        REQUIRE(res2->mRefCount == 1);
282



4
        REQUIRE(res2->mSource.empty());
283




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
284





7
        REQUIRE(ResourceManager::getResources()["test1"] == res2);
285




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
286




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
287
1
        res2->decRef();
288



4
        REQUIRE(res2->mRefCount == 0);
289
    }
290
291



147
    SECTION("resourcemanager get 6")
292
    {
293
4
        TestLoader rl = { "test1" };
294

4
        Resource *res = ResourceManager::get("test1",
295
1
            TestLoader::load, &rl);
296



4
        REQUIRE(res != nullptr);
297



4
        REQUIRE(testResouceCounter == 1);
298



4
        REQUIRE(res->mRefCount == 1);
299
1
        res->mSource = "source 1";
300




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
301





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
302




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
303




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
304
305

4
        Resource *const res2 = ResourceManager::get("test2",
306
1
            TestLoader::load, &rl);
307



4
        REQUIRE(res2 != nullptr);
308



4
        REQUIRE(testResouceCounter == 2);
309



4
        REQUIRE(res2->mRefCount == 1);
310



4
        REQUIRE(res2->mSource.empty());
311




5
        REQUIRE(ResourceManager::getResources().size() == 2 + resSize);
312





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
313





7
        REQUIRE(ResourceManager::getResources()["test2"] == res2);
314




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
315




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
316
1
        res->decRef();
317
1
        res2->decRef();
318



4
        REQUIRE(res->mRefCount == 0);
319



4
        REQUIRE(res2->mRefCount == 0);
320
    }
321
322



147
    SECTION("resourcemanager getFromCache 1")
323
    {
324
4
        TestLoader rl = { "test1" };
325

4
        Resource *res = ResourceManager::get("test1",
326
1
            TestLoader::load, &rl);
327



4
        REQUIRE(res != nullptr);
328



4
        REQUIRE(testResouceCounter == 1);
329



4
        REQUIRE(res->mRefCount == 1);
330




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
331





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
332




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
333




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
334

4
        Resource *const res2 = ResourceManager::getFromCache("test1");
335



4
        REQUIRE(res2 != nullptr);
336



4
        REQUIRE(testResouceCounter == 1);
337



4
        REQUIRE(res2->mRefCount == 2);
338



4
        REQUIRE(res == res2);
339



4
        REQUIRE(res2->mSource.empty());
340




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
341





7
        REQUIRE(ResourceManager::getResources()["test1"] == res2);
342




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
343




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
344
1
        res->decRef();
345
1
        res->decRef();
346



4
        REQUIRE(res->mRefCount == 0);
347
    }
348
349



147
    SECTION("resourcemanager getFromCache 2")
350
    {
351
4
        TestLoader rl = { "test1" };
352

4
        Resource *res = ResourceManager::get("test1",
353
1
            TestLoader::load, &rl);
354



4
        REQUIRE(res != nullptr);
355



4
        REQUIRE(testResouceCounter == 1);
356



4
        REQUIRE(res->mRefCount == 1);
357




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
358





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
359




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
360




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
361
1
        res->decRef();
362



4
        REQUIRE(res->mRefCount == 0);
363

4
        Resource *const res2 = ResourceManager::getFromCache("test1");
364



4
        REQUIRE(res2 != nullptr);
365



4
        REQUIRE(testResouceCounter == 1);
366



4
        REQUIRE(res2->mRefCount == 1);
367



4
        REQUIRE(res == res2);
368



4
        REQUIRE(res2->mSource.empty());
369




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
370





7
        REQUIRE(ResourceManager::getResources()["test1"] == res2);
371




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
372




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
373
1
        res->decRef();
374



4
        REQUIRE(res->mRefCount == 0);
375
    }
376
377



147
    SECTION("resourcemanager getFromCache 3")
378
    {
379
4
        TestLoader rl = { "test1" };
380

4
        Resource *res = ResourceManager::get("test1",
381
1
            TestLoader::load, &rl);
382



4
        REQUIRE(res != nullptr);
383



4
        REQUIRE(testResouceCounter == 1);
384


3
        REQUIRE(res->mRefCount == 1);
385
1
        res->mSource = "source 1";
386




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
387





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
388




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
389




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
390
391

4
        Resource *const res2 = ResourceManager::get("test2",
392
1
            TestLoader::load, &rl);
393



4
        REQUIRE(res2 != nullptr);
394



4
        REQUIRE(testResouceCounter == 2);
395



4
        REQUIRE(res2->mRefCount == 1);
396



4
        REQUIRE(res2->mSource.empty());
397




5
        REQUIRE(ResourceManager::getResources().size() == 2 + resSize);
398





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
399





7
        REQUIRE(ResourceManager::getResources()["test2"] == res2);
400




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
401




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
402
403

4
        Resource *const resC = ResourceManager::getFromCache("test1");
404

4
        Resource *const res2C = ResourceManager::getFromCache("test2");
405



4
        REQUIRE(resC != nullptr);
406



4
        REQUIRE(res2C != nullptr);
407



4
        REQUIRE(testResouceCounter == 2);
408



4
        REQUIRE(res == resC);
409



4
        REQUIRE(res2 == res2C);
410



4
        REQUIRE(resC->mRefCount == 2);
411



4
        REQUIRE(res2C->mRefCount == 2);
412




5
        REQUIRE(ResourceManager::getResources().size() == 2 + resSize);
413





7
        REQUIRE(ResourceManager::getResources()["test1"] == resC);
414





7
        REQUIRE(ResourceManager::getResources()["test2"] == res2C);
415




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
416




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
417
418
1
        res->decRef();
419
1
        res->decRef();
420
1
        res2->decRef();
421
1
        res2->decRef();
422



4
        REQUIRE(res->mRefCount == 0);
423



4
        REQUIRE(res2->mRefCount == 0);
424
    }
425
426



147
    SECTION("resourcemanager addResource 1")
427
    {
428



4
        REQUIRE(testResouceCounter == 0);
429

1
        Resource *res = new TestResource();
430



4
        REQUIRE(testResouceCounter == 1);
431

4
        ResourceManager::addResource("test1", res);
432



4
        REQUIRE(res != nullptr);
433



4
        REQUIRE(res->mRefCount == 1);
434




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
435





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
436




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
437




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
438
1
        res->decRef();
439



4
        REQUIRE(res->mRefCount == 0);
440
    }
441
442



147
    SECTION("resourcemanager isInCache 1")
443
    {
444



4
        REQUIRE(testResouceCounter == 0);
445
4
        TestLoader rl = { "test1" };
446




7
        REQUIRE(ResourceManager::isInCache("test1") == false);
447

4
        Resource *res = ResourceManager::get("test1",
448
1
            TestLoader::load, &rl);
449




7
        REQUIRE(ResourceManager::isInCache("test1") == true);
450




7
        REQUIRE(ResourceManager::isInCache("test2") == false);
451



4
        REQUIRE(testResouceCounter == 1);
452



4
        REQUIRE(res != nullptr);
453



4
        REQUIRE(res->mRefCount == 1);
454




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
455





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
456




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
457




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
458
1
        res->decRef();
459



4
        REQUIRE(res->mRefCount == 0);
460
    }
461
462



147
    SECTION("resourcemanager getTempResource 1")
463
    {
464
4
        TestLoader rl = { "test1" };
465




7
        REQUIRE(ResourceManager::getTempResource("test1") == nullptr);
466

4
        Resource *res = ResourceManager::get("test1",
467
1
            TestLoader::load, &rl);
468



4
        REQUIRE(res != nullptr);
469



4
        REQUIRE(testResouceCounter == 1);
470



4
        REQUIRE(res->mRefCount == 1);
471




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
472





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
473




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
474




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
475

4
        Resource *const res2 = ResourceManager::getTempResource("test1");
476




7
        REQUIRE(ResourceManager::getTempResource("test2") == nullptr);
477



4
        REQUIRE(res2 != nullptr);
478



4
        REQUIRE(testResouceCounter == 1);
479



4
        REQUIRE(res2->mRefCount == 1);
480



4
        REQUIRE(res == res2);
481



4
        REQUIRE(res2->mSource.empty());
482




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
483





7
        REQUIRE(ResourceManager::getResources()["test1"] == res2);
484




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
485




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
486
1
        res->decRef();
487



4
        REQUIRE(res->mRefCount == 0);
488
    }
489
490



147
    SECTION("resourcemanager moveToDeleted 1")
491
    {
492



4
        REQUIRE(testResouceCounter == 0);
493
4
        TestLoader rl = { "test1" };
494

4
        Resource *res = ResourceManager::get("test1",
495
1
            TestLoader::load, &rl);
496



4
        REQUIRE(testResouceCounter == 1);
497



4
        REQUIRE(res != nullptr);
498



4
        REQUIRE(res->mRefCount == 1);
499




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
500





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
501




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
502




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
503
1
        ResourceManager::moveToDeleted(res);
504



4
        REQUIRE(testResouceCounter == 0);
505




5
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
506




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
507




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
508
    }
509
510



147
    SECTION("resourcemanager moveToDeleted 2")
511
    {
512



4
        REQUIRE(testResouceCounter == 0);
513
4
        TestLoader rl = { "test1" };
514

4
        Resource *res = ResourceManager::get("test1",
515
1
            TestLoader::load, &rl);
516
1
        res->incRef();
517



4
        REQUIRE(testResouceCounter == 1);
518



4
        REQUIRE(res != nullptr);
519



4
        REQUIRE(res->mRefCount == 2);
520




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
521





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
522




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
523




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
524
1
        ResourceManager::moveToDeleted(res);
525



4
        REQUIRE(testResouceCounter == 1);
526



4
        REQUIRE(res->mRefCount == 1);
527




5
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
528




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
529




5
        REQUIRE(ResourceManager::getDeletedResources().size() == 1);
530
1
        res->decRef();
531
    }
532
533



147
    SECTION("resourcemanager moveToDeleted 3")
534
    {
535



4
        REQUIRE(testResouceCounter == 0);
536
4
        TestLoader rl = { "test1" };
537

4
        Resource *res = ResourceManager::get("test1",
538
1
            TestLoader::load, &rl);
539



4
        REQUIRE(testResouceCounter == 1);
540



4
        REQUIRE(res != nullptr);
541



4
        REQUIRE(res->mRefCount == 1);
542




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
543





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
544




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
545




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
546
547
1
        res->decRef();
548



4
        REQUIRE(testResouceCounter == 1);
549



4
        REQUIRE(res->mRefCount == 0);
550




5
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
551




5
        REQUIRE(ResourceManager::getOrphanedResources().size() == 1);
552





7
        REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
553




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
554
555
1
        ResourceManager::moveToDeleted(res);
556



4
        REQUIRE(testResouceCounter == 0);
557




5
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
558




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
559




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
560
    }
561
562



147
    SECTION("resourcemanager decRefDelete 1")
563
    {
564



4
        REQUIRE(testResouceCounter == 0);
565
4
        TestLoader rl = { "test1" };
566

4
        Resource *res = ResourceManager::get("test1",
567
1
            TestLoader::load, &rl);
568



4
        REQUIRE(testResouceCounter == 1);
569



4
        REQUIRE(res != nullptr);
570



4
        REQUIRE(res->mRefCount == 1);
571




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
572





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
573




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
574




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
575
576
1
        ResourceManager::decRefDelete(res);
577



4
        REQUIRE(testResouceCounter == 0);
578




5
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
579




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
580




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
581
    }
582
583



147
    SECTION("resourcemanager cleanUp 1")
584
    {
585



4
        REQUIRE(testResouceCounter == 0);
586
4
        TestLoader rl = { "test1" };
587

4
        Resource *res = ResourceManager::get("test1",
588
1
            TestLoader::load, &rl);
589



4
        REQUIRE(testResouceCounter == 1);
590



4
        REQUIRE(res != nullptr);
591



4
        REQUIRE(res->mRefCount == 1);
592




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
593





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
594




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
595




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
596
1
        res->decRef();
597
598
1
        ResourceManager::cleanUp(res);
599



4
        REQUIRE(testResouceCounter == 0);
600




5
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
601




5
        REQUIRE(ResourceManager::getOrphanedResources().size() == 1);
602




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
603
2
        ResourceManager::getOrphanedResources().clear();
604
    }
605
606



147
    SECTION("resourcemanager cleanProtected 1")
607
    {
608



4
        REQUIRE(testResouceCounter == 0);
609
4
        TestLoader rl = { "test1" };
610

4
        Resource *res = ResourceManager::get("test1",
611
1
            TestLoader::load, &rl);
612



4
        REQUIRE(testResouceCounter == 1);
613



4
        REQUIRE(res != nullptr);
614



4
        REQUIRE(res->mRefCount == 1);
615




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
616





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
617




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
618




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
619
1
        res->mProtected = true;
620
1
        ResourceManager::cleanProtected();
621
622



4
        REQUIRE(testResouceCounter == 1);
623




5
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
624




5
        REQUIRE(ResourceManager::getOrphanedResources().size() == 1);
625





7
        REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
626




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
627
1
        res->decRef();
628
    }
629
630



147
    SECTION("resourcemanager clearDeleted 1")
631
    {
632



4
        REQUIRE(testResouceCounter == 0);
633
4
        TestLoader rl = { "test1" };
634

4
        Resource *res = ResourceManager::get("test1",
635
1
            TestLoader::load, &rl);
636
1
        res->incRef();
637



4
        REQUIRE(testResouceCounter == 1);
638



4
        REQUIRE(res != nullptr);
639



4
        REQUIRE(res->mRefCount == 2);
640




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
641





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
642




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
643




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
644
1
        ResourceManager::moveToDeleted(res);
645



4
        REQUIRE(testResouceCounter == 1);
646



4
        REQUIRE(res->mRefCount == 1);
647




5
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
648




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
649




5
        REQUIRE(ResourceManager::getDeletedResources().size() == 1);
650
651
1
        ResourceManager::clearDeleted(true);
652



4
        REQUIRE(testResouceCounter == 1);
653



4
        REQUIRE(res->mRefCount == 1);
654




5
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
655




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
656




5
        REQUIRE(ResourceManager::getDeletedResources().size() == 1);
657
1
        res->decRef();
658
    }
659
660



147
    SECTION("resourcemanager clearDeleted 2")
661
    {
662



4
        REQUIRE(testResouceCounter == 0);
663
4
        TestLoader rl = { "test1" };
664

4
        Resource *res = ResourceManager::get("test1",
665
1
            TestLoader::load, &rl);
666
1
        res->incRef();
667



4
        REQUIRE(testResouceCounter == 1);
668



4
        REQUIRE(res != nullptr);
669



4
        REQUIRE(res->mRefCount == 2);
670




5
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
671





7
        REQUIRE(ResourceManager::getResources()["test1"] == res);
672




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
673




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
674
1
        ResourceManager::moveToDeleted(res);
675



4
        REQUIRE(testResouceCounter == 1);
676



4
        REQUIRE(res->mRefCount == 1);
677




5
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
678




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
679




5
        REQUIRE(ResourceManager::getDeletedResources().size() == 1);
680
681
1
        res->decRef();
682
1
        ResourceManager::clearDeleted(true);
683



4
        REQUIRE(testResouceCounter == 0);
684




5
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
685




5
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
686




5
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
687
    }
688
689
21
    delete2(userPalette)
690
21
    delete2(theme)
691
21
    delete2(client)
692
84
    VirtFs::unmountDirSilent("data");
693
84
    VirtFs::unmountDirSilent("../data");
694

24
}