summaryrefslogtreecommitdiff
path: root/src/resources/resourcemanager/resourcemanager_unittest.cc
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-07-07 17:05:13 +0300
committerAndrei Karas <akaras@inbox.ru>2017-07-07 17:53:24 +0300
commit130f07fd84bfdf781eb42903b3fcbabc26199a3a (patch)
treee4e560c32177e0a64867c5d1584d9bf64b57bbce /src/resources/resourcemanager/resourcemanager_unittest.cc
parent9bbd191307c97c7589f93a64a4eb9abf3f11c46b (diff)
downloadplus-130f07fd84bfdf781eb42903b3fcbabc26199a3a.tar.gz
plus-130f07fd84bfdf781eb42903b3fcbabc26199a3a.tar.bz2
plus-130f07fd84bfdf781eb42903b3fcbabc26199a3a.tar.xz
plus-130f07fd84bfdf781eb42903b3fcbabc26199a3a.zip
Move unit tests into unittests directory.
Diffstat (limited to 'src/resources/resourcemanager/resourcemanager_unittest.cc')
-rw-r--r--src/resources/resourcemanager/resourcemanager_unittest.cc701
1 files changed, 0 insertions, 701 deletions
diff --git a/src/resources/resourcemanager/resourcemanager_unittest.cc b/src/resources/resourcemanager/resourcemanager_unittest.cc
deleted file mode 100644
index 2efbc2ab1..000000000
--- a/src/resources/resourcemanager/resourcemanager_unittest.cc
+++ /dev/null
@@ -1,701 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "test/unittests.h"
-
-#include "client.h"
-#include "dirs.h"
-#include "logger.h"
-#include "graphicsmanager.h"
-
-#include "being/actorsprite.h"
-
-#include "fs/virtfs/fs.h"
-
-#include "gui/gui.h"
-
-#include "resources/sdlimagehelper.h"
-
-#include "resources/resourcemanager/resourcemanager.h"
-
-#include "utils/env.h"
-#include "utils/delete2.h"
-
-#include <unistd.h>
-
-PRAGMA48(GCC diagnostic push)
-PRAGMA48(GCC diagnostic ignored "-Wshadow")
-#ifndef USE_SDL2
-#include <SDL.h>
-#endif // USE_SDL2
-PRAGMA48(GCC diagnostic pop)
-
-#include "debug.h"
-
-namespace
-{
- int testResouceCounter = 0;
-
- class TestResource : public Resource
- {
- public:
- TestResource() :
- Resource()
- {
- testResouceCounter ++;
- }
-
- ~TestResource()
- {
- testResouceCounter --;
- }
- };
-
- struct TestLoader final
- {
- std::string path;
- static Resource *load(const void *const v)
- {
- BLOCK_START("TestLoader::load")
- if (v == nullptr)
- {
- BLOCK_END("TestLoader::load")
- return nullptr;
- }
-
- Resource *const res = new TestResource();
- BLOCK_END("TestLoader::load")
- return res;
- }
- };
-
-} // namespace
-
-TEST_CASE("resourcemanager leak test1", "")
-{
- logger = new Logger();
- REQUIRE(gui == nullptr);
- ResourceManager::cleanOrphans(true);
- ResourceManager::deleteInstance();
- delete2(logger);
-}
-
-TEST_CASE("resourcemanager", "resourcemanager")
-{
- setEnv("SDL_VIDEODRIVER", "dummy");
-
- client = new Client;
- XML::initXML();
- SDL_Init(SDL_INIT_VIDEO);
- logger = new Logger();
- VirtFs::mountDirSilent("data", Append_false);
- VirtFs::mountDirSilent("../data", Append_false);
-
- imageHelper = new SDLImageHelper();
-#ifdef USE_SDL2
- SDLImageHelper::setRenderer(graphicsManager.createRenderer(
- graphicsManager.createWindow(640, 480, 0,
- SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
-#else // USE_SDL2
-
- graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
-#endif // USE_SDL2
-
- ActorSprite::load();
-
- Dirs::initRootDir();
- Dirs::initHomeDir();
-
-// ConfigManager::initConfiguration();
-// getConfigDefaults2(config.getDefaultValues());
-
- while (ResourceManager::cleanOrphans(true))
- continue;
-
- testResouceCounter = 0;
- const size_t resSize = ResourceManager::getResources().size();
-
- SECTION("resourcemanager get 0")
- {
- REQUIRE(testResouceCounter == 0);
- REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- }
-
- SECTION("resourcemanager get 1")
- {
- REQUIRE(testResouceCounter == 0);
- TestLoader rl = { "test1" };
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res != nullptr);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res->decRef();
- REQUIRE(res->mRefCount == 0);
- }
-
- SECTION("resourcemanager get 2")
- {
- TestLoader rl = { "test1" };
- Resource *const res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(res != nullptr);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res->mRefCount == 1);
- res->mSource = "source 1";
- REQUIRE(res->mSource == "source 1");
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- Resource *const res2 = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(res2 != nullptr);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res->mRefCount == 2);
- REQUIRE(res2->mRefCount == 2);
- REQUIRE(res->mIdPath == res2->mIdPath);
- REQUIRE(res2->mSource == "source 1");
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res2);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res->decRef();
- res2->decRef();
- REQUIRE(res->mRefCount == 0);
- }
-
- SECTION("resourcemanager get 3")
- {
- TestLoader rl = { "test1" };
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(res != nullptr);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res->mSource = "source 1";
- res->decRef();
- REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
- REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- REQUIRE(res->mRefCount == 0);
- }
-
- SECTION("resourcemanager get 4")
- {
- TestLoader rl = { "test1" };
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(res != nullptr);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res->mSource = "source 1";
- res->decRef();
- REQUIRE(res->mRefCount == 0);
- REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
- REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
-
- Resource *const res2 = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(res2 != nullptr);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res2->mRefCount == 1);
- REQUIRE(res->mIdPath == res2->mIdPath);
- REQUIRE(res2->mSource == "source 1");
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res2);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res2->decRef();
- REQUIRE(res->mRefCount == 0);
- }
-
- SECTION("resourcemanager get 5")
- {
- TestLoader rl = { "test1" };
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(ResourceManager::isInCache("test1") == true);
- REQUIRE(res != nullptr);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res->mSource = "source 1";
- res->decRef();
- REQUIRE(res->mRefCount == 0);
- REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
- REQUIRE(ResourceManager::getOrphanedResources().size() == 1);
- REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
-
- sleep(33);
- ResourceManager::cleanOrphans();
- REQUIRE(ResourceManager::isInCache("test1") == false);
- REQUIRE(testResouceCounter == 0);
- REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
-
- Resource *const res2 = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(ResourceManager::isInCache("test1") == true);
- REQUIRE(res2 != nullptr);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res2->mRefCount == 1);
- REQUIRE(res2->mSource.empty());
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res2);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res2->decRef();
- REQUIRE(res2->mRefCount == 0);
- }
-
- SECTION("resourcemanager get 6")
- {
- TestLoader rl = { "test1" };
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(res != nullptr);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res->mRefCount == 1);
- res->mSource = "source 1";
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
-
- Resource *const res2 = ResourceManager::get("test2",
- TestLoader::load, &rl);
- REQUIRE(res2 != nullptr);
- REQUIRE(testResouceCounter == 2);
- REQUIRE(res2->mRefCount == 1);
- REQUIRE(res2->mSource.empty());
- REQUIRE(ResourceManager::getResources().size() == 2 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getResources()["test2"] == res2);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res->decRef();
- res2->decRef();
- REQUIRE(res->mRefCount == 0);
- REQUIRE(res2->mRefCount == 0);
- }
-
- SECTION("resourcemanager getFromCache 1")
- {
- TestLoader rl = { "test1" };
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(res != nullptr);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- Resource *const res2 = ResourceManager::getFromCache("test1");
- REQUIRE(res2 != nullptr);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res2->mRefCount == 2);
- REQUIRE(res == res2);
- REQUIRE(res2->mSource.empty());
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res2);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res->decRef();
- res->decRef();
- REQUIRE(res->mRefCount == 0);
- }
-
- SECTION("resourcemanager getFromCache 2")
- {
- TestLoader rl = { "test1" };
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(res != nullptr);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res->decRef();
- REQUIRE(res->mRefCount == 0);
- Resource *const res2 = ResourceManager::getFromCache("test1");
- REQUIRE(res2 != nullptr);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res2->mRefCount == 1);
- REQUIRE(res == res2);
- REQUIRE(res2->mSource.empty());
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res2);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res->decRef();
- REQUIRE(res->mRefCount == 0);
- }
-
- SECTION("resourcemanager getFromCache 3")
- {
- TestLoader rl = { "test1" };
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(res != nullptr);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res->mRefCount == 1);
- res->mSource = "source 1";
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
-
- Resource *const res2 = ResourceManager::get("test2",
- TestLoader::load, &rl);
- REQUIRE(res2 != nullptr);
- REQUIRE(testResouceCounter == 2);
- REQUIRE(res2->mRefCount == 1);
- REQUIRE(res2->mSource.empty());
- REQUIRE(ResourceManager::getResources().size() == 2 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getResources()["test2"] == res2);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
-
- Resource *const resC = ResourceManager::getFromCache("test1");
- Resource *const res2C = ResourceManager::getFromCache("test2");
- REQUIRE(resC != nullptr);
- REQUIRE(res2C != nullptr);
- REQUIRE(testResouceCounter == 2);
- REQUIRE(res == resC);
- REQUIRE(res2 == res2C);
- REQUIRE(resC->mRefCount == 2);
- REQUIRE(res2C->mRefCount == 2);
- REQUIRE(ResourceManager::getResources().size() == 2 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == resC);
- REQUIRE(ResourceManager::getResources()["test2"] == res2C);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
-
- res->decRef();
- res->decRef();
- res2->decRef();
- res2->decRef();
- REQUIRE(res->mRefCount == 0);
- REQUIRE(res2->mRefCount == 0);
- }
-
- SECTION("resourcemanager addResource 1")
- {
- REQUIRE(testResouceCounter == 0);
- Resource *res = new TestResource();
- REQUIRE(testResouceCounter == 1);
- ResourceManager::addResource("test1", res);
- REQUIRE(res != nullptr);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res->decRef();
- REQUIRE(res->mRefCount == 0);
- }
-
- SECTION("resourcemanager isInCache 1")
- {
- REQUIRE(testResouceCounter == 0);
- TestLoader rl = { "test1" };
- REQUIRE(ResourceManager::isInCache("test1") == false);
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(ResourceManager::isInCache("test1") == true);
- REQUIRE(ResourceManager::isInCache("test2") == false);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res != nullptr);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res->decRef();
- REQUIRE(res->mRefCount == 0);
- }
-
- SECTION("resourcemanager getTempResource 1")
- {
- TestLoader rl = { "test1" };
- REQUIRE(ResourceManager::getTempResource("test1") == nullptr);
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(res != nullptr);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- Resource *const res2 = ResourceManager::getTempResource("test1");
- REQUIRE(ResourceManager::getTempResource("test2") == nullptr);
- REQUIRE(res2 != nullptr);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res2->mRefCount == 1);
- REQUIRE(res == res2);
- REQUIRE(res2->mSource.empty());
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res2);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res->decRef();
- REQUIRE(res->mRefCount == 0);
- }
-
- SECTION("resourcemanager moveToDeleted 1")
- {
- REQUIRE(testResouceCounter == 0);
- TestLoader rl = { "test1" };
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res != nullptr);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- ResourceManager::moveToDeleted(res);
- REQUIRE(testResouceCounter == 0);
- REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- }
-
- SECTION("resourcemanager moveToDeleted 2")
- {
- REQUIRE(testResouceCounter == 0);
- TestLoader rl = { "test1" };
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- res->incRef();
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res != nullptr);
- REQUIRE(res->mRefCount == 2);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- ResourceManager::moveToDeleted(res);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().size() == 1);
- res->decRef();
- }
-
- SECTION("resourcemanager moveToDeleted 3")
- {
- REQUIRE(testResouceCounter == 0);
- TestLoader rl = { "test1" };
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res != nullptr);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
-
- res->decRef();
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res->mRefCount == 0);
- REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
- REQUIRE(ResourceManager::getOrphanedResources().size() == 1);
- REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
-
- ResourceManager::moveToDeleted(res);
- REQUIRE(testResouceCounter == 0);
- REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- }
-
- SECTION("resourcemanager decRefDelete 1")
- {
- REQUIRE(testResouceCounter == 0);
- TestLoader rl = { "test1" };
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res != nullptr);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
-
- ResourceManager::decRefDelete(res);
- REQUIRE(testResouceCounter == 0);
- REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- }
-
- SECTION("resourcemanager cleanUp 1")
- {
- REQUIRE(testResouceCounter == 0);
- TestLoader rl = { "test1" };
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res != nullptr);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res->decRef();
-
- ResourceManager::cleanUp(res);
- REQUIRE(testResouceCounter == 0);
- REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
- REQUIRE(ResourceManager::getOrphanedResources().size() == 1);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- ResourceManager::getOrphanedResources().clear();
- }
-
- SECTION("resourcemanager cleanProtected 1")
- {
- REQUIRE(testResouceCounter == 0);
- TestLoader rl = { "test1" };
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res != nullptr);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res->mProtected = true;
- ResourceManager::cleanProtected();
-
- REQUIRE(testResouceCounter == 1);
- REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
- REQUIRE(ResourceManager::getOrphanedResources().size() == 1);
- REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- res->decRef();
- }
-
- SECTION("resourcemanager clearDeleted 1")
- {
- REQUIRE(testResouceCounter == 0);
- TestLoader rl = { "test1" };
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- res->incRef();
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res != nullptr);
- REQUIRE(res->mRefCount == 2);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- ResourceManager::moveToDeleted(res);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().size() == 1);
-
- ResourceManager::clearDeleted();
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().size() == 1);
- res->decRef();
- }
-
- SECTION("resourcemanager clearDeleted 2")
- {
- REQUIRE(testResouceCounter == 0);
- TestLoader rl = { "test1" };
- Resource *res = ResourceManager::get("test1",
- TestLoader::load, &rl);
- res->incRef();
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res != nullptr);
- REQUIRE(res->mRefCount == 2);
- REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
- REQUIRE(ResourceManager::getResources()["test1"] == res);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- ResourceManager::moveToDeleted(res);
- REQUIRE(testResouceCounter == 1);
- REQUIRE(res->mRefCount == 1);
- REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().size() == 1);
-
- res->decRef();
- ResourceManager::clearDeleted();
- REQUIRE(testResouceCounter == 0);
- REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
- REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
- REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- }
-
- delete2(client);
- VirtFs::unmountDirSilent("data");
- VirtFs::unmountDirSilent("../data");
- delete2(logger);
-// VirtFs::deinit();
-}
-
-TEST_CASE("resourcemanager leak test2", "")
-{
- logger = new Logger();
- REQUIRE(gui == nullptr);
- ResourceManager::cleanOrphans(true);
- ResourceManager::deleteInstance();
- delete2(logger);
-}