GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/resources/resourcemanager/resourcemanager.cc Lines: 513 513 100.0 %
Date: 2017-11-29 Branches: 2202 5680 38.8 %

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 "client.h"
24
#include "configmanager.h"
25
#include "configuration.h"
26
#include "dirs.h"
27
#include "graphicsmanager.h"
28
29
#include "being/actorsprite.h"
30
31
#include "fs/virtfs/fs.h"
32
33
#include "gui/userpalette.h"
34
#include "gui/theme.h"
35
36
#include "resources/sdlimagehelper.h"
37
38
#include "resources/resourcemanager/resourcemanager.h"
39
40
#include "utils/env.h"
41
#include "utils/delete2.h"
42
43
#include <unistd.h>
44
45
PRAGMA48(GCC diagnostic push)
46
PRAGMA48(GCC diagnostic ignored "-Wshadow")
47
#ifndef USE_SDL2
48
#include <SDL.h>
49
#endif  // USE_SDL2
50
PRAGMA48(GCC diagnostic pop)
51
52
#include "debug.h"
53
54
namespace
55
{
56
    int testResouceCounter = 0;
57
58
    class TestResource : public Resource
59
    {
60
        public:
61
46
            TestResource() :
62
92
                Resource()
63
            {
64
46
                testResouceCounter ++;
65
46
            }
66
67
46
            ~TestResource()
68
92
            {
69
46
                testResouceCounter --;
70
46
            }
71
    };
72
73
76
    struct TestLoader final
74
    {
75
        std::string path;
76
44
        static Resource *load(const void *const v)
77
        {
78
            BLOCK_START("TestLoader::load")
79
44
            if (v == nullptr)
80
            {
81
                BLOCK_END("TestLoader::load")
82
                return nullptr;
83
            }
84
85
44
            Resource *const res = new TestResource();
86
            BLOCK_END("TestLoader::load")
87
            return res;
88
        }
89
    };
90
91
}  // namespace
92
93
46
TEST_CASE("resourcemanager", "resourcemanager")
94
{
95
42
    setEnv("SDL_VIDEODRIVER", "dummy");
96
97
42
    client = new Client;
98
42
    XML::initXML();
99
42
    SDL_Init(SDL_INIT_VIDEO);
100

168
    VirtFs::mountDirSilent("data", Append_false);
101

168
    VirtFs::mountDirSilent("../data", Append_false);
102
103
84
    imageHelper = new SDLImageHelper();
104
105
42
    Dirs::initRootDir();
106
42
    Dirs::initHomeDir();
107
108
42
    setBrandingDefaults(branding);
109
42
    ConfigManager::initConfiguration();
110
111
#ifdef USE_SDL2
112
    SDLImageHelper::setRenderer(graphicsManager.createRenderer(
113
        graphicsManager.createWindow(640, 480, 0,
114
        SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
115
#else  // USE_SDL2
116
117
42
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
118
#endif  // USE_SDL2
119
120
42
    userPalette = new UserPalette;
121
122
42
    theme = new Theme;
123
42
    Theme::selectSkin();
124
125
42
    ActorSprite::load();
126
127
//    ConfigManager::initConfiguration();
128
//    setConfigDefaults2(config);
129
130
84
    while (ResourceManager::cleanOrphans(true))
131
        continue;
132
133
42
    testResouceCounter = 0;
134
84
    const size_t resSize = ResourceManager::getResources().size();
135
136



294
    SECTION("resourcemanager get 0")
137
    {
138



8
        REQUIRE(testResouceCounter == 0);
139




10
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
140




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
141




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
142
    }
143
144



294
    SECTION("resourcemanager get 1")
145
    {
146



8
        REQUIRE(testResouceCounter == 0);
147
8
        TestLoader rl = { "test1" };
148

8
        Resource *res = ResourceManager::get("test1",
149
2
            TestLoader::load, &rl);
150



8
        REQUIRE(testResouceCounter == 1);
151



8
        REQUIRE(res != nullptr);
152



8
        REQUIRE(res->mRefCount == 1);
153




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
154





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
155




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
156




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
157
2
        res->decRef();
158



8
        REQUIRE(res->mRefCount == 0);
159
    }
160
161



294
    SECTION("resourcemanager get 2")
162
    {
163
8
        TestLoader rl = { "test1" };
164

8
        Resource *const res = ResourceManager::get("test1",
165
2
            TestLoader::load, &rl);
166



8
        REQUIRE(res != nullptr);
167



8
        REQUIRE(testResouceCounter == 1);
168



8
        REQUIRE(res->mRefCount == 1);
169
2
        res->mSource = "source 1";
170



8
        REQUIRE(res->mSource == "source 1");
171




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
172





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
173




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
174




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
175

8
        Resource *const res2 = ResourceManager::get("test1",
176
2
            TestLoader::load, &rl);
177



8
        REQUIRE(res2 != nullptr);
178



8
        REQUIRE(testResouceCounter == 1);
179



8
        REQUIRE(res->mRefCount == 2);
180



8
        REQUIRE(res2->mRefCount == 2);
181



8
        REQUIRE(res->mIdPath == res2->mIdPath);
182



8
        REQUIRE(res2->mSource == "source 1");
183




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
184





14
        REQUIRE(ResourceManager::getResources()["test1"] == res2);
185




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
186




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
187
2
        res->decRef();
188
2
        res2->decRef();
189



8
        REQUIRE(res->mRefCount == 0);
190
    }
191
192



294
    SECTION("resourcemanager get 3")
193
    {
194
8
        TestLoader rl = { "test1" };
195

8
        Resource *res = ResourceManager::get("test1",
196
2
            TestLoader::load, &rl);
197



8
        REQUIRE(res != nullptr);
198



8
        REQUIRE(testResouceCounter == 1);
199



8
        REQUIRE(res->mRefCount == 1);
200




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
201





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
202




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
203




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




10
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
207





14
        REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
208




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
209



8
        REQUIRE(res->mRefCount == 0);
210
    }
211
212



294
    SECTION("resourcemanager get 4")
213
    {
214
8
        TestLoader rl = { "test1" };
215

8
        Resource *res = ResourceManager::get("test1",
216
2
            TestLoader::load, &rl);
217



8
        REQUIRE(res != nullptr);
218



8
        REQUIRE(testResouceCounter == 1);
219



8
        REQUIRE(res->mRefCount == 1);
220




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
221





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
222




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
223




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



8
        REQUIRE(res->mRefCount == 0);
227




10
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
228





14
        REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
229




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
230
231

8
        Resource *const res2 = ResourceManager::get("test1",
232
2
            TestLoader::load, &rl);
233



8
        REQUIRE(res2 != nullptr);
234



8
        REQUIRE(testResouceCounter == 1);
235



8
        REQUIRE(res2->mRefCount == 1);
236



8
        REQUIRE(res->mIdPath == res2->mIdPath);
237



8
        REQUIRE(res2->mSource == "source 1");
238




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
239





14
        REQUIRE(ResourceManager::getResources()["test1"] == res2);
240




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
241




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
242
2
        res2->decRef();
243



8
        REQUIRE(res->mRefCount == 0);
244
    }
245
246



294
    SECTION("resourcemanager get 5")
247
    {
248
8
        TestLoader rl = { "test1" };
249

8
        Resource *res = ResourceManager::get("test1",
250
2
            TestLoader::load, &rl);
251




14
        REQUIRE(ResourceManager::isInCache("test1") == true);
252



8
        REQUIRE(res != nullptr);
253



8
        REQUIRE(testResouceCounter == 1);
254



8
        REQUIRE(res->mRefCount == 1);
255




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
256





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
257




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
258




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



8
        REQUIRE(res->mRefCount == 0);
262




10
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
263




10
        REQUIRE(ResourceManager::getOrphanedResources().size() == 1);
264





14
        REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
265




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
266
267
2
        sleep(33);
268
2
        ResourceManager::cleanOrphans();
269




14
        REQUIRE(ResourceManager::isInCache("test1") == false);
270



8
        REQUIRE(testResouceCounter == 0);
271




10
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
272




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
273




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
274
275

8
        Resource *const res2 = ResourceManager::get("test1",
276
2
            TestLoader::load, &rl);
277




14
        REQUIRE(ResourceManager::isInCache("test1") == true);
278



8
        REQUIRE(res2 != nullptr);
279



8
        REQUIRE(testResouceCounter == 1);
280



8
        REQUIRE(res2->mRefCount == 1);
281



8
        REQUIRE(res2->mSource.empty());
282




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
283





14
        REQUIRE(ResourceManager::getResources()["test1"] == res2);
284




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
285




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
286
2
        res2->decRef();
287



8
        REQUIRE(res2->mRefCount == 0);
288
    }
289
290



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

8
        Resource *res = ResourceManager::get("test1",
294
2
            TestLoader::load, &rl);
295



8
        REQUIRE(res != nullptr);
296



8
        REQUIRE(testResouceCounter == 1);
297



8
        REQUIRE(res->mRefCount == 1);
298
2
        res->mSource = "source 1";
299




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
300





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
301




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
302




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
303
304

8
        Resource *const res2 = ResourceManager::get("test2",
305
2
            TestLoader::load, &rl);
306



8
        REQUIRE(res2 != nullptr);
307



8
        REQUIRE(testResouceCounter == 2);
308



8
        REQUIRE(res2->mRefCount == 1);
309



8
        REQUIRE(res2->mSource.empty());
310




10
        REQUIRE(ResourceManager::getResources().size() == 2 + resSize);
311





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
312





14
        REQUIRE(ResourceManager::getResources()["test2"] == res2);
313




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
314




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
315
2
        res->decRef();
316
2
        res2->decRef();
317



8
        REQUIRE(res->mRefCount == 0);
318



8
        REQUIRE(res2->mRefCount == 0);
319
    }
320
321



294
    SECTION("resourcemanager getFromCache 1")
322
    {
323
8
        TestLoader rl = { "test1" };
324

8
        Resource *res = ResourceManager::get("test1",
325
2
            TestLoader::load, &rl);
326



8
        REQUIRE(res != nullptr);
327



8
        REQUIRE(testResouceCounter == 1);
328



8
        REQUIRE(res->mRefCount == 1);
329




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
330





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
331




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
332




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
333

8
        Resource *const res2 = ResourceManager::getFromCache("test1");
334



8
        REQUIRE(res2 != nullptr);
335



8
        REQUIRE(testResouceCounter == 1);
336



8
        REQUIRE(res2->mRefCount == 2);
337



8
        REQUIRE(res == res2);
338



8
        REQUIRE(res2->mSource.empty());
339




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
340





14
        REQUIRE(ResourceManager::getResources()["test1"] == res2);
341




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
342




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
343
2
        res->decRef();
344
2
        res->decRef();
345



8
        REQUIRE(res->mRefCount == 0);
346
    }
347
348



294
    SECTION("resourcemanager getFromCache 2")
349
    {
350
8
        TestLoader rl = { "test1" };
351

8
        Resource *res = ResourceManager::get("test1",
352
2
            TestLoader::load, &rl);
353



8
        REQUIRE(res != nullptr);
354



8
        REQUIRE(testResouceCounter == 1);
355



8
        REQUIRE(res->mRefCount == 1);
356




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
357





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
358




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
359




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
360
2
        res->decRef();
361



8
        REQUIRE(res->mRefCount == 0);
362

8
        Resource *const res2 = ResourceManager::getFromCache("test1");
363



8
        REQUIRE(res2 != nullptr);
364



8
        REQUIRE(testResouceCounter == 1);
365



8
        REQUIRE(res2->mRefCount == 1);
366



8
        REQUIRE(res == res2);
367



8
        REQUIRE(res2->mSource.empty());
368




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
369





14
        REQUIRE(ResourceManager::getResources()["test1"] == res2);
370




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
371




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
372
2
        res->decRef();
373



8
        REQUIRE(res->mRefCount == 0);
374
    }
375
376



294
    SECTION("resourcemanager getFromCache 3")
377
    {
378
8
        TestLoader rl = { "test1" };
379

8
        Resource *res = ResourceManager::get("test1",
380
2
            TestLoader::load, &rl);
381



8
        REQUIRE(res != nullptr);
382



8
        REQUIRE(testResouceCounter == 1);
383



8
        REQUIRE(res->mRefCount == 1);
384
2
        res->mSource = "source 1";
385




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
386





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
387




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
388




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
389
390

8
        Resource *const res2 = ResourceManager::get("test2",
391
2
            TestLoader::load, &rl);
392



8
        REQUIRE(res2 != nullptr);
393



8
        REQUIRE(testResouceCounter == 2);
394



8
        REQUIRE(res2->mRefCount == 1);
395



8
        REQUIRE(res2->mSource.empty());
396




10
        REQUIRE(ResourceManager::getResources().size() == 2 + resSize);
397





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
398





14
        REQUIRE(ResourceManager::getResources()["test2"] == res2);
399




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
400




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
401
402

8
        Resource *const resC = ResourceManager::getFromCache("test1");
403

8
        Resource *const res2C = ResourceManager::getFromCache("test2");
404



8
        REQUIRE(resC != nullptr);
405



8
        REQUIRE(res2C != nullptr);
406



8
        REQUIRE(testResouceCounter == 2);
407



8
        REQUIRE(res == resC);
408



8
        REQUIRE(res2 == res2C);
409



8
        REQUIRE(resC->mRefCount == 2);
410



8
        REQUIRE(res2C->mRefCount == 2);
411




10
        REQUIRE(ResourceManager::getResources().size() == 2 + resSize);
412





14
        REQUIRE(ResourceManager::getResources()["test1"] == resC);
413





14
        REQUIRE(ResourceManager::getResources()["test2"] == res2C);
414




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
415




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
416
417
2
        res->decRef();
418
2
        res->decRef();
419
2
        res2->decRef();
420
2
        res2->decRef();
421



8
        REQUIRE(res->mRefCount == 0);
422



8
        REQUIRE(res2->mRefCount == 0);
423
    }
424
425



294
    SECTION("resourcemanager addResource 1")
426
    {
427



8
        REQUIRE(testResouceCounter == 0);
428

2
        Resource *res = new TestResource();
429



8
        REQUIRE(testResouceCounter == 1);
430

8
        ResourceManager::addResource("test1", res);
431



8
        REQUIRE(res != nullptr);
432



8
        REQUIRE(res->mRefCount == 1);
433




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
434





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
435




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
436




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
437
2
        res->decRef();
438



8
        REQUIRE(res->mRefCount == 0);
439
    }
440
441



294
    SECTION("resourcemanager isInCache 1")
442
    {
443



8
        REQUIRE(testResouceCounter == 0);
444
8
        TestLoader rl = { "test1" };
445




14
        REQUIRE(ResourceManager::isInCache("test1") == false);
446

8
        Resource *res = ResourceManager::get("test1",
447
2
            TestLoader::load, &rl);
448




14
        REQUIRE(ResourceManager::isInCache("test1") == true);
449




14
        REQUIRE(ResourceManager::isInCache("test2") == false);
450



8
        REQUIRE(testResouceCounter == 1);
451



8
        REQUIRE(res != nullptr);
452



8
        REQUIRE(res->mRefCount == 1);
453




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
454





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
455




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
456




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
457
2
        res->decRef();
458



8
        REQUIRE(res->mRefCount == 0);
459
    }
460
461



294
    SECTION("resourcemanager getTempResource 1")
462
    {
463
8
        TestLoader rl = { "test1" };
464




14
        REQUIRE(ResourceManager::getTempResource("test1") == nullptr);
465

8
        Resource *res = ResourceManager::get("test1",
466
2
            TestLoader::load, &rl);
467



8
        REQUIRE(res != nullptr);
468



8
        REQUIRE(testResouceCounter == 1);
469



8
        REQUIRE(res->mRefCount == 1);
470




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
471





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
472




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
473




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
474

8
        Resource *const res2 = ResourceManager::getTempResource("test1");
475




14
        REQUIRE(ResourceManager::getTempResource("test2") == nullptr);
476



8
        REQUIRE(res2 != nullptr);
477



8
        REQUIRE(testResouceCounter == 1);
478



8
        REQUIRE(res2->mRefCount == 1);
479



8
        REQUIRE(res == res2);
480



8
        REQUIRE(res2->mSource.empty());
481




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
482





14
        REQUIRE(ResourceManager::getResources()["test1"] == res2);
483




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
484




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
485
2
        res->decRef();
486



8
        REQUIRE(res->mRefCount == 0);
487
    }
488
489



294
    SECTION("resourcemanager moveToDeleted 1")
490
    {
491



8
        REQUIRE(testResouceCounter == 0);
492
8
        TestLoader rl = { "test1" };
493

8
        Resource *res = ResourceManager::get("test1",
494
2
            TestLoader::load, &rl);
495



8
        REQUIRE(testResouceCounter == 1);
496



8
        REQUIRE(res != nullptr);
497



8
        REQUIRE(res->mRefCount == 1);
498




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
499





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
500




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
501




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
502
2
        ResourceManager::moveToDeleted(res);
503



8
        REQUIRE(testResouceCounter == 0);
504




10
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
505




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
506




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
507
    }
508
509



294
    SECTION("resourcemanager moveToDeleted 2")
510
    {
511



8
        REQUIRE(testResouceCounter == 0);
512
8
        TestLoader rl = { "test1" };
513

8
        Resource *res = ResourceManager::get("test1",
514
2
            TestLoader::load, &rl);
515
2
        res->incRef();
516



8
        REQUIRE(testResouceCounter == 1);
517



8
        REQUIRE(res != nullptr);
518



8
        REQUIRE(res->mRefCount == 2);
519




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
520





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
521




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
522




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
523
2
        ResourceManager::moveToDeleted(res);
524



8
        REQUIRE(testResouceCounter == 1);
525



8
        REQUIRE(res->mRefCount == 1);
526




10
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
527




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
528




10
        REQUIRE(ResourceManager::getDeletedResources().size() == 1);
529
2
        res->decRef();
530
    }
531
532



294
    SECTION("resourcemanager moveToDeleted 3")
533
    {
534



8
        REQUIRE(testResouceCounter == 0);
535
8
        TestLoader rl = { "test1" };
536

8
        Resource *res = ResourceManager::get("test1",
537
2
            TestLoader::load, &rl);
538



8
        REQUIRE(testResouceCounter == 1);
539



8
        REQUIRE(res != nullptr);
540



8
        REQUIRE(res->mRefCount == 1);
541




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
542





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
543




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
544




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
545
546
2
        res->decRef();
547



8
        REQUIRE(testResouceCounter == 1);
548



8
        REQUIRE(res->mRefCount == 0);
549




10
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
550




10
        REQUIRE(ResourceManager::getOrphanedResources().size() == 1);
551





14
        REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
552




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
553
554
2
        ResourceManager::moveToDeleted(res);
555



8
        REQUIRE(testResouceCounter == 0);
556




10
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
557




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
558




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
559
    }
560
561



294
    SECTION("resourcemanager decRefDelete 1")
562
    {
563



8
        REQUIRE(testResouceCounter == 0);
564
8
        TestLoader rl = { "test1" };
565

8
        Resource *res = ResourceManager::get("test1",
566
2
            TestLoader::load, &rl);
567



8
        REQUIRE(testResouceCounter == 1);
568



8
        REQUIRE(res != nullptr);
569



8
        REQUIRE(res->mRefCount == 1);
570




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
571





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
572




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
573




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
574
575
2
        ResourceManager::decRefDelete(res);
576



8
        REQUIRE(testResouceCounter == 0);
577




10
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
578




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
579




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
580
    }
581
582



294
    SECTION("resourcemanager cleanUp 1")
583
    {
584



8
        REQUIRE(testResouceCounter == 0);
585
8
        TestLoader rl = { "test1" };
586

8
        Resource *res = ResourceManager::get("test1",
587
2
            TestLoader::load, &rl);
588



8
        REQUIRE(testResouceCounter == 1);
589



8
        REQUIRE(res != nullptr);
590



8
        REQUIRE(res->mRefCount == 1);
591




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
592





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
593




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
594




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
595
2
        res->decRef();
596
597
2
        ResourceManager::cleanUp(res);
598



8
        REQUIRE(testResouceCounter == 0);
599




10
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
600




10
        REQUIRE(ResourceManager::getOrphanedResources().size() == 1);
601




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
602
4
        ResourceManager::getOrphanedResources().clear();
603
    }
604
605



294
    SECTION("resourcemanager cleanProtected 1")
606
    {
607



8
        REQUIRE(testResouceCounter == 0);
608
8
        TestLoader rl = { "test1" };
609

8
        Resource *res = ResourceManager::get("test1",
610
2
            TestLoader::load, &rl);
611



8
        REQUIRE(testResouceCounter == 1);
612



8
        REQUIRE(res != nullptr);
613



8
        REQUIRE(res->mRefCount == 1);
614




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
615





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
616




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
617




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
618
2
        res->mProtected = true;
619
2
        ResourceManager::cleanProtected();
620
621



8
        REQUIRE(testResouceCounter == 1);
622




10
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
623




10
        REQUIRE(ResourceManager::getOrphanedResources().size() == 1);
624





14
        REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
625




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
626
2
        res->decRef();
627
    }
628
629



294
    SECTION("resourcemanager clearDeleted 1")
630
    {
631



8
        REQUIRE(testResouceCounter == 0);
632
8
        TestLoader rl = { "test1" };
633

8
        Resource *res = ResourceManager::get("test1",
634
2
            TestLoader::load, &rl);
635
2
        res->incRef();
636



8
        REQUIRE(testResouceCounter == 1);
637



8
        REQUIRE(res != nullptr);
638



8
        REQUIRE(res->mRefCount == 2);
639




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
640





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
641




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
642




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
643
2
        ResourceManager::moveToDeleted(res);
644



8
        REQUIRE(testResouceCounter == 1);
645



8
        REQUIRE(res->mRefCount == 1);
646




10
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
647




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
648




10
        REQUIRE(ResourceManager::getDeletedResources().size() == 1);
649
650
2
        ResourceManager::clearDeleted();
651



8
        REQUIRE(testResouceCounter == 1);
652



8
        REQUIRE(res->mRefCount == 1);
653




10
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
654




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
655




10
        REQUIRE(ResourceManager::getDeletedResources().size() == 1);
656
2
        res->decRef();
657
    }
658
659



294
    SECTION("resourcemanager clearDeleted 2")
660
    {
661



8
        REQUIRE(testResouceCounter == 0);
662
8
        TestLoader rl = { "test1" };
663

8
        Resource *res = ResourceManager::get("test1",
664
2
            TestLoader::load, &rl);
665
2
        res->incRef();
666



8
        REQUIRE(testResouceCounter == 1);
667



8
        REQUIRE(res != nullptr);
668



8
        REQUIRE(res->mRefCount == 2);
669




10
        REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
670





14
        REQUIRE(ResourceManager::getResources()["test1"] == res);
671




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
672




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
673
2
        ResourceManager::moveToDeleted(res);
674



8
        REQUIRE(testResouceCounter == 1);
675



8
        REQUIRE(res->mRefCount == 1);
676




10
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
677




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
678




10
        REQUIRE(ResourceManager::getDeletedResources().size() == 1);
679
680
2
        res->decRef();
681
2
        ResourceManager::clearDeleted();
682



8
        REQUIRE(testResouceCounter == 0);
683




10
        REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
684




10
        REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
685




10
        REQUIRE(ResourceManager::getDeletedResources().empty() == true);
686
    }
687
688
42
    delete2(userPalette);
689
42
    delete2(theme);
690
42
    delete2(client);
691

168
    VirtFs::unmountDirSilent("data");
692

168
    VirtFs::unmountDirSilent("../data");
693

48
}