GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/resources/resourcemanager/resourcemanager.cc Lines: 513 513 100.0 %
Date: 2018-07-14 Branches: 2198 5672 38.8 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2013-2018  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "unittests/unittests.h"
22
23
#include "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
23
            TestResource() :
62
46
                Resource()
63
            {
64
23
                testResouceCounter ++;
65
23
            }
66
67
23
            ~TestResource()
68
46
            {
69
23
                testResouceCounter --;
70
23
            }
71
    };
72
73
38
    struct TestLoader final
74
    {
75
        std::string path;
76
22
        static Resource *load(const void *const v)
77
        {
78
            BLOCK_START("TestLoader::load")
79
22
            if (v == nullptr)
80
            {
81
                BLOCK_END("TestLoader::load")
82
                return nullptr;
83
            }
84
85
22
            Resource *const res = new TestResource();
86
            BLOCK_END("TestLoader::load")
87
            return res;
88
        }
89
    };
90
91
}  // namespace
92
93
23
TEST_CASE("resourcemanager", "resourcemanager")
94
{
95
21
    setEnv("SDL_VIDEODRIVER", "dummy");
96
97
21
    client = new Client;
98
21
    XML::initXML();
99
21
    SDL_Init(SDL_INIT_VIDEO);
100
84
    VirtFs::mountDirSilent("data", Append_false);
101
84
    VirtFs::mountDirSilent("../data", Append_false);
102
103
42
    imageHelper = new SDLImageHelper();
104
105
21
    Dirs::initRootDir();
106
21
    Dirs::initHomeDir();
107
108
21
    setBrandingDefaults(branding);
109
21
    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
21
    graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
118
#endif  // USE_SDL2
119
120
21
    userPalette = new UserPalette;
121
122
21
    theme = new Theme;
123
21
    Theme::selectSkin();
124
125
21
    ActorSprite::load();
126
127
//    ConfigManager::initConfiguration();
128
//    setConfigDefaults2(config);
129
130
42
    while (ResourceManager::cleanOrphans(true))
131
        continue;
132
133
21
    testResouceCounter = 0;
134
42
    const size_t resSize = ResourceManager::getResources().size();
135
136



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



4
        REQUIRE(testResouceCounter == 0);
139




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




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




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



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



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

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



4
        REQUIRE(testResouceCounter == 1);
151



4
        REQUIRE(res != nullptr);
152



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




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





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




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




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



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



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

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



4
        REQUIRE(res != nullptr);
167



4
        REQUIRE(testResouceCounter == 1);
168



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



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




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





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




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




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

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



4
        REQUIRE(res2 != nullptr);
178



4
        REQUIRE(testResouceCounter == 1);
179



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



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



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



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




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





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




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




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



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



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

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



4
        REQUIRE(res != nullptr);
198



4
        REQUIRE(testResouceCounter == 1);
199



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




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





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




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




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




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





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




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



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



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

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



4
        REQUIRE(res != nullptr);
218



4
        REQUIRE(testResouceCounter == 1);
219



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




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





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




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




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



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




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





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




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

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



4
        REQUIRE(res2 != nullptr);
234



4
        REQUIRE(testResouceCounter == 1);
235



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



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



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




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





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




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




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



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



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

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




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



4
        REQUIRE(res != nullptr);
253



4
        REQUIRE(testResouceCounter == 1);
254



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




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





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




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




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



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




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




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





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




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




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



4
        REQUIRE(testResouceCounter == 0);
271




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




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




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

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




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



4
        REQUIRE(res2 != nullptr);
279



4
        REQUIRE(testResouceCounter == 1);
280



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



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




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





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




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




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



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



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

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



4
        REQUIRE(res != nullptr);
296



4
        REQUIRE(testResouceCounter == 1);
297



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




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





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




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




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

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



4
        REQUIRE(res2 != nullptr);
307



4
        REQUIRE(testResouceCounter == 2);
308



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



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




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





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





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




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




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



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



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



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

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



4
        REQUIRE(res != nullptr);
327



4
        REQUIRE(testResouceCounter == 1);
328



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




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





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




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




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

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



4
        REQUIRE(res2 != nullptr);
335



4
        REQUIRE(testResouceCounter == 1);
336



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



4
        REQUIRE(res == res2);
338



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




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





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




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




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



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



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

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



4
        REQUIRE(res != nullptr);
354



4
        REQUIRE(testResouceCounter == 1);
355



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




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





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




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




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



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

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



4
        REQUIRE(res2 != nullptr);
364



4
        REQUIRE(testResouceCounter == 1);
365



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



4
        REQUIRE(res == res2);
367



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




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





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




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




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



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



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

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



4
        REQUIRE(res != nullptr);
382



4
        REQUIRE(testResouceCounter == 1);
383



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




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





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




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




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

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



4
        REQUIRE(res2 != nullptr);
393



4
        REQUIRE(testResouceCounter == 2);
394



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



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




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





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





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




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




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

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

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



4
        REQUIRE(resC != nullptr);
405



4
        REQUIRE(res2C != nullptr);
406



4
        REQUIRE(testResouceCounter == 2);
407



4
        REQUIRE(res == resC);
408



4
        REQUIRE(res2 == res2C);
409



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



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




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





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





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




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




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



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



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



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



4
        REQUIRE(testResouceCounter == 0);
428

1
        Resource *res = new TestResource();
429



4
        REQUIRE(testResouceCounter == 1);
430

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



4
        REQUIRE(res != nullptr);
432



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




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





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




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




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



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



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



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




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

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




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




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



4
        REQUIRE(testResouceCounter == 1);
451



4
        REQUIRE(res != nullptr);
452



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




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





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




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




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



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



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




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

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



4
        REQUIRE(res != nullptr);
468



4
        REQUIRE(testResouceCounter == 1);
469



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




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





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




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




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

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




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



4
        REQUIRE(res2 != nullptr);
477



4
        REQUIRE(testResouceCounter == 1);
478



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



4
        REQUIRE(res == res2);
480



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




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





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




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




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



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



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



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

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



4
        REQUIRE(testResouceCounter == 1);
496



4
        REQUIRE(res != nullptr);
497



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




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





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




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




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



4
        REQUIRE(testResouceCounter == 0);
504




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




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




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



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



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

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



4
        REQUIRE(testResouceCounter == 1);
517



4
        REQUIRE(res != nullptr);
518



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




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





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




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




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



4
        REQUIRE(testResouceCounter == 1);
525



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




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




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




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



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



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

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



4
        REQUIRE(testResouceCounter == 1);
539



4
        REQUIRE(res != nullptr);
540



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




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





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




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




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



4
        REQUIRE(testResouceCounter == 1);
548



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




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




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





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




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



4
        REQUIRE(testResouceCounter == 0);
556




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




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




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



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



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

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



4
        REQUIRE(testResouceCounter == 1);
568



4
        REQUIRE(res != nullptr);
569



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




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





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




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




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



4
        REQUIRE(testResouceCounter == 0);
577




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




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




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



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



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

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



4
        REQUIRE(testResouceCounter == 1);
589



4
        REQUIRE(res != nullptr);
590



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




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





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




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




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



4
        REQUIRE(testResouceCounter == 0);
599




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




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




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



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



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

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



4
        REQUIRE(testResouceCounter == 1);
612



4
        REQUIRE(res != nullptr);
613



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




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





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




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




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



4
        REQUIRE(testResouceCounter == 1);
622




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




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





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




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



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



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

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



4
        REQUIRE(testResouceCounter == 1);
637



4
        REQUIRE(res != nullptr);
638



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




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





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




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




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



4
        REQUIRE(testResouceCounter == 1);
645



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




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




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




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



4
        REQUIRE(testResouceCounter == 1);
652



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




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




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




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



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



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

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



4
        REQUIRE(testResouceCounter == 1);
667



4
        REQUIRE(res != nullptr);
668



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




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





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




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




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



4
        REQUIRE(testResouceCounter == 1);
675



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




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




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




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



4
        REQUIRE(testResouceCounter == 0);
683




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




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




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

24
}