summaryrefslogtreecommitdiff
path: root/src/resources/resourcemanager
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-04-07 02:48:12 +0300
committerAndrei Karas <akaras@inbox.ru>2017-04-08 16:46:28 +0300
commit27a2dd4fce2d529cd1d96aa5ddce1e74b4f54a2f (patch)
treec2c38e1b4f308ca885dc3c3581560cfbc6833a8e /src/resources/resourcemanager
parentd4e28aa97cbce34a0053d3c02cf070ef9065439f (diff)
downloadmanaverse-27a2dd4fce2d529cd1d96aa5ddce1e74b4f54a2f.tar.gz
manaverse-27a2dd4fce2d529cd1d96aa5ddce1e74b4f54a2f.tar.bz2
manaverse-27a2dd4fce2d529cd1d96aa5ddce1e74b4f54a2f.tar.xz
manaverse-27a2dd4fce2d529cd1d96aa5ddce1e74b4f54a2f.zip
Move resourcemanager from class to namespace.
Diffstat (limited to 'src/resources/resourcemanager')
-rw-r--r--src/resources/resourcemanager/resourcemanager.cpp221
-rw-r--r--src/resources/resourcemanager/resourcemanager.h155
-rw-r--r--src/resources/resourcemanager/resourcemanager_unittest.cc483
3 files changed, 456 insertions, 403 deletions
diff --git a/src/resources/resourcemanager/resourcemanager.cpp b/src/resources/resourcemanager/resourcemanager.cpp
index aed4426b6..a5e5ebac5 100644
--- a/src/resources/resourcemanager/resourcemanager.cpp
+++ b/src/resources/resourcemanager/resourcemanager.cpp
@@ -46,20 +46,17 @@
#include "debug.h"
-ResourceManager *resourceManager = nullptr;
-
-ResourceManager::ResourceManager() :
- deletedSurfaces(),
- mResources(),
- mOrphanedResources(),
- mDeletedResources(),
- mOldestOrphan(0),
- mDestruction(0)
+namespace ResourceManager
{
- logger->log1("Initializing resource manager...");
-}
-ResourceManager::~ResourceManager()
+std::set<SDL_Surface*> deletedSurfaces;
+Resources mResources;
+Resources mOrphanedResources;
+std::set<Resource*> mDeletedResources;
+time_t mOldestOrphan = 0;
+bool mDestruction = false;
+
+void deleteResourceManager()
{
mDestruction = true;
mResources.insert(mOrphanedResources.begin(), mOrphanedResources.end());
@@ -171,26 +168,22 @@ ResourceManager::~ResourceManager()
}
clearDeleted();
clearScheduled();
+ mDestruction = false;
}
-void ResourceManager::init()
-{
- if (!resourceManager)
- resourceManager = new ResourceManager;
-}
-
-void ResourceManager::cleanUp(Resource *const res)
+void cleanUp(Resource *const res)
{
if (!res)
return;
- if (res->mRefCount > 0)
+ const unsigned refCount = res->getRefCount();
+ if (refCount > 0)
{
logger->log("ResourceManager::~ResourceManager() cleaning up %u "
"reference%s to %s",
- res->mRefCount,
- (res->mRefCount == 1) ? "" : "s",
- res->mIdPath.c_str());
+ refCount,
+ (refCount == 1) ? "" : "s",
+ res->getIdPath().c_str());
}
delete res;
@@ -199,7 +192,7 @@ void ResourceManager::cleanUp(Resource *const res)
#endif // DEBUG_LEAKS
}
-void ResourceManager::cleanProtected()
+void cleanProtected()
{
ResourceIterator iter = mResources.begin();
while (iter != mResources.end())
@@ -222,7 +215,7 @@ void ResourceManager::cleanProtected()
}
}
-bool ResourceManager::cleanOrphans(const bool always)
+bool cleanOrphans(const bool always)
{
timeval tv;
gettimeofday(&tv, nullptr);
@@ -266,7 +259,7 @@ bool ResourceManager::cleanOrphans(const bool always)
return status;
}
-void ResourceManager::logResource(const Resource *const res)
+void logResource(const Resource *const res)
{
if (!res)
return;
@@ -278,7 +271,7 @@ void ResourceManager::logResource(const Resource *const res)
const int count = image->getRefCount();
if (count)
src.append(" ").append(toString(count));
- logger->log("resource(%s, %u) %s", res->mIdPath.c_str(),
+ logger->log("resource(%s, %u) %s", res->getIdPath().c_str(),
image->getGLImage(), src.c_str());
}
else
@@ -287,15 +280,36 @@ void ResourceManager::logResource(const Resource *const res)
const int count = res->getRefCount();
if (count > 0)
src.append(" ").append(toString(count));
- logger->log("resource(%s) %s", res->mIdPath.c_str(), src.c_str());
+ logger->log("resource(%s) %s", res->getIdPath().c_str(), src.c_str());
}
#else // USE_OPENGL
- logger->log("resource(%s)", res->mIdPath.c_str());
+ logger->log("resource(%s)", res->getIdPath().c_str());
#endif // USE_OPENGL
}
-void ResourceManager::clearDeleted(const bool full)
+void logResources(const std::string &msg)
+{
+ logger->log("start of resources: " + msg);
+ logger->log("resouces");
+ FOR_EACH(ResourceIterator, it, mResources)
+ {
+ logResource((*it).second);
+ }
+ logger->log("orphaned resouces");
+ FOR_EACH(ResourceIterator, it, mOrphanedResources)
+ {
+ logResource((*it).second);
+ }
+ logger->log("deleted resouces");
+ FOR_EACH(std::set<Resource*>::iterator, it, mDeletedResources)
+ {
+ logResource(*it);
+ }
+ logger->log("end of resources");
+}
+
+void clearDeleted(const bool full)
{
bool status(true);
logger->log1("clear deleted");
@@ -334,17 +348,16 @@ void ResourceManager::clearDeleted(const bool full)
}
}
-
-bool ResourceManager::addResource(const std::string &idPath,
- Resource *const resource)
+bool addResource(const std::string &idPath,
+ Resource *const resource)
{
if (resource)
{
resource->incRef();
- resource->mIdPath = idPath;
+ resource->setIdPath(idPath);
#ifdef DEBUG_IMAGES
logger->log("set name %p, %s", static_cast<void*>(resource),
- resource->mIdPath.c_str());
+ resource->getIdPath().c_str());
#endif // DEBUG_IMAGES
mResources[idPath] = resource;
@@ -353,21 +366,21 @@ bool ResourceManager::addResource(const std::string &idPath,
return false;
}
-Resource *ResourceManager::getFromCache(const std::string &filename,
- const int variant)
+Resource *getFromCache(const std::string &filename,
+ const int variant)
{
std::stringstream ss;
ss << filename << "[" << variant << "]";
return getFromCache(ss.str());
}
-bool ResourceManager::isInCache(const std::string &idPath) const
+bool isInCache(const std::string &idPath)
{
const ResourceCIterator &resIter = mResources.find(idPath);
return (resIter != mResources.end() && resIter->second);
}
-Resource *ResourceManager::getTempResource(const std::string &idPath)
+Resource *getTempResource(const std::string &idPath)
{
const ResourceCIterator &resIter = mResources.find(idPath);
if (resIter != mResources.end())
@@ -379,7 +392,7 @@ Resource *ResourceManager::getTempResource(const std::string &idPath)
return nullptr;
}
-Resource *ResourceManager::getFromCache(const std::string &idPath)
+Resource *getFromCache(const std::string &idPath)
{
// Check if the id exists, and return the value if it does.
ResourceIterator resIter = mResources.find(idPath);
@@ -403,9 +416,9 @@ Resource *ResourceManager::getFromCache(const std::string &idPath)
return nullptr;
}
-Resource *ResourceManager::get(const std::string &idPath,
- generator fun,
- const void *const data)
+Resource *get(const std::string &idPath,
+ generator fun,
+ const void *const data)
{
#ifndef DISABLE_RESOURCE_CACHING
Resource *resource = getFromCache(idPath);
@@ -416,10 +429,10 @@ Resource *ResourceManager::get(const std::string &idPath,
if (resource)
{
resource->incRef();
- resource->mIdPath = idPath;
+ resource->setIdPath(idPath);
#ifdef DEBUG_IMAGES
logger->log("set name %p, %s", static_cast<void*>(resource),
- resource->mIdPath.c_str());
+ resource->getIdPath().c_str());
#endif // DEBUG_IMAGES
mResources[idPath] = resource;
@@ -435,10 +448,10 @@ Resource *ResourceManager::get(const std::string &idPath,
if (resource)
{
resource->incRef();
- resource->mIdPath = idPath;
+ resource->setIdPath(idPath);
#ifdef DEBUG_IMAGES
logger->log("set name %p, %s", static_cast<void*>(resource),
- resource->mIdPath.c_str());
+ resource->getIdPath().c_str());
#endif // DEBUG_IMAGES
}
else
@@ -451,7 +464,7 @@ Resource *ResourceManager::get(const std::string &idPath,
return resource;
}
-void ResourceManager::release(Resource *const res)
+void release(Resource *const res)
{
if (!res || mDestruction)
return;
@@ -466,19 +479,19 @@ void ResourceManager::release(Resource *const res)
return;
}
- ResourceIterator resIter = mResources.find(res->mIdPath);
+ ResourceIterator resIter = mResources.find(res->getIdPath());
if (resIter == mResources.end())
{
reportAlways("no resource in cache: %s",
- res->mIdPath.c_str());
+ res->getIdPath().c_str());
delete res;
return;
}
if (resIter->second != res)
{
reportAlways("in cache other image: %s",
- res->mIdPath.c_str());
+ res->getIdPath().c_str());
delete res;
return;
}
@@ -499,7 +512,7 @@ void ResourceManager::release(Resource *const res)
#endif // DISABLE_RESOURCE_CACHING
}
-void ResourceManager::moveToDeleted(Resource *const res)
+void moveToDeleted(Resource *const res)
{
if (!res)
return;
@@ -509,7 +522,7 @@ void ResourceManager::moveToDeleted(Resource *const res)
if (count == 1)
logResource(res);
res->decRef();
- ResourceIterator resIter = mResources.find(res->mIdPath);
+ ResourceIterator resIter = mResources.find(res->getIdPath());
if (resIter != mResources.end() && resIter->second == res)
{
mResources.erase(resIter);
@@ -517,7 +530,7 @@ void ResourceManager::moveToDeleted(Resource *const res)
}
else
{
- resIter = mOrphanedResources.find(res->mIdPath);
+ resIter = mOrphanedResources.find(res->getIdPath());
if (resIter != mOrphanedResources.end() && resIter->second == res)
{
mOrphanedResources.erase(resIter);
@@ -533,7 +546,7 @@ void ResourceManager::moveToDeleted(Resource *const res)
}
}
-void ResourceManager::decRefDelete(Resource *const res)
+void decRefDelete(Resource *const res)
{
if (!res)
return;
@@ -543,14 +556,14 @@ void ResourceManager::decRefDelete(Resource *const res)
{
logResource(res);
- ResourceIterator resIter = mResources.find(res->mIdPath);
+ ResourceIterator resIter = mResources.find(res->getIdPath());
if (resIter != mResources.end() && resIter->second == res)
{
mResources.erase(resIter);
}
else
{
- resIter = mOrphanedResources.find(res->mIdPath);
+ resIter = mOrphanedResources.find(res->getIdPath());
if (resIter != mOrphanedResources.end() && resIter->second == res)
mOrphanedResources.erase(resIter);
}
@@ -563,55 +576,52 @@ void ResourceManager::decRefDelete(Resource *const res)
}
}
-void ResourceManager::deleteInstance()
+void deleteInstance()
{
#ifdef DUMP_LEAKED_RESOURCES
- if (resourceManager)
- {
- logger->log1("clean orphans start");
- resourceManager->cleanProtected();
- while (resourceManager->cleanOrphans(true))
- continue;
- logger->log1("clean orphans end");
- ResourceIterator iter = resourceManager->mResources.begin();
+ logger->log1("clean orphans start");
+ ResourceManager::cleanProtected();
+ while (ResourceManager::cleanOrphans(true))
+ continue;
+ logger->log1("clean orphans end");
+ ResourceIterator iter = ResourceManager::mResources.begin();
#ifdef UNITTESTS
- bool status(false);
+ bool status(false);
#endif // UNITTESTS
- while (iter != resourceManager->mResources.end())
+ while (iter != ResourceManager::mResources.end())
+ {
+ const Resource *const res = iter->second;
+ if (res)
{
- const Resource *const res = iter->second;
- if (res)
+ if (res->getRefCount())
{
- if (res->getRefCount())
- {
- logger->log(std::string("ResourceLeak: ").append(
- res->getIdPath()).append(" (").append(toString(
- res->getRefCount())).append(")"));
+ logger->log(std::string("ResourceLeak: ").append(
+ res->getIdPath()).append(" (").append(toString(
+ res->getRefCount())).append(")"));
#ifdef UNITTESTS
- status = true;
+ status = true;
#endif // UNITTESTS
- }
}
- ++iter;
}
+ ++iter;
+ }
#ifdef UNITTESTS
- if (status)
- reportAlways("Found leaked resources.");
+ if (status)
+ reportAlways("Found leaked resources.");
#endif // UNITTESTS
- }
#endif // DUMP_LEAKED_RESOURCES
- delete2(resourceManager);
+ deleteResourceManager();
}
-void ResourceManager::scheduleDelete(SDL_Surface *const surface)
+void scheduleDelete(SDL_Surface *const surface)
{
deletedSurfaces.insert(surface);
}
-void ResourceManager::clearScheduled()
+void clearScheduled()
{
BLOCK_START("ResourceManager::clearScheduled")
FOR_EACH (std::set<SDL_Surface*>::iterator, i, deletedSurfaces)
@@ -620,16 +630,16 @@ void ResourceManager::clearScheduled()
BLOCK_END("ResourceManager::clearScheduled")
}
-void ResourceManager::clearCache()
+void clearCache()
{
cleanProtected();
while (cleanOrphans(true))
continue;
}
-int ResourceManager::calcMemoryLocal() const
+int calcMemoryLocal()
{
- int sz = sizeof(ResourceManager);
+ int sz = 24;
FOR_EACH (std::set<SDL_Surface*>::iterator, it, deletedSurfaces)
{
sz += memoryManager.getSurfaceSize(*it);
@@ -637,7 +647,7 @@ int ResourceManager::calcMemoryLocal() const
return sz;
}
-int ResourceManager::calcMemoryChilds(const int level) const
+int calcMemoryChilds(const int level)
{
int sz = 0;
FOR_EACH (ResourceCIterator, it, mResources)
@@ -656,3 +666,38 @@ int ResourceManager::calcMemoryChilds(const int level) const
}
return sz;
}
+
+int calcMemory(const int level)
+{
+ const int sumLocal = calcMemoryLocal();
+ const int sumChilds = calcMemoryChilds(0);
+ memoryManager.printMemory("resource manager",
+ level,
+ sumLocal,
+ sumChilds);
+ return sumLocal + sumChilds;
+}
+
+int size() noexcept2
+{
+ return CAST_S32(mResources.size());
+}
+
+#if defined(DEBUG_DUMP_LEAKS) || defined(UNITTESTS)
+Resources &getResources()
+{
+ return mResources;
+}
+
+Resources &getOrphanedResources()
+{
+ return mOrphanedResources;
+}
+
+const std::set<Resource*> &getDeletedResources()
+{
+ return mDeletedResources;
+}
+#endif // defined(DEBUG_DUMP_LEAKS) || defined(UNITTESTS)
+
+} // namespace ResourceManager
diff --git a/src/resources/resourcemanager/resourcemanager.h b/src/resources/resourcemanager/resourcemanager.h
index 6fff83df0..f279b2b7c 100644
--- a/src/resources/resourcemanager/resourcemanager.h
+++ b/src/resources/resourcemanager/resourcemanager.h
@@ -23,8 +23,6 @@
#ifndef RESOURCES_RESOURCEMANAGER_RESOURCEMANAGER_H
#define RESOURCES_RESOURCEMANAGER_RESOURCEMANAGER_H
-#include "resources/memorycounter.h"
-
#include <map>
#include <set>
@@ -35,124 +33,97 @@ class Resource;
struct SDL_Surface;
struct SDL_RWops;
-/**
- * A class for loading and managing resources.
- */
-class ResourceManager final : public MemoryCounter
+namespace ResourceManager
{
- friend class Resource;
-
- public:
- typedef Resource *(*loader)(SDL_RWops *rw,
- const std::string &name);
- typedef Resource *(&generator)(const void *const data);
-
- ResourceManager();
-
- A_DELETE_COPY(ResourceManager)
-
- /**
- * Destructor. Cleans up remaining resources, warning about resources
- * that were still referenced.
- */
- ~ResourceManager();
+ typedef Resource *(*loader)(SDL_RWops *rw,
+ const std::string &name);
+ typedef Resource *(&generator)(const void *const data);
- /**
- * Creates a resource and adds it to the resource map.
- *
- * @param idPath The resource identifier path.
- * @param fun A function for generating the resource.
- * @param data Extra parameters for the generator.
- * @return A valid resource or <code>NULL</code> if the resource could
- * not be generated.
- */
- Resource *get(const std::string &idPath,
- generator fun,
- const void *const data) A_WARN_UNUSED;
+ typedef std::map<std::string, Resource*> Resources;
+ typedef Resources::iterator ResourceIterator;
+ typedef Resources::const_iterator ResourceCIterator;
- Resource *getFromCache(const std::string &idPath) A_WARN_UNUSED;
+ /**
+ * Cleans up remaining resources, warning about resources
+ * that were still referenced.
+ */
+ void deleteResourceManager();
- Resource *getFromCache(const std::string &filename,
- const int variant) A_WARN_UNUSED;
+ /**
+ * Creates a resource and adds it to the resource map.
+ *
+ * @param idPath The resource identifier path.
+ * @param fun A function for generating the resource.
+ * @param data Extra parameters for the generator.
+ * @return A valid resource or <code>NULL</code> if the resource could
+ * not be generated.
+ */
+ Resource *get(const std::string &idPath,
+ generator fun,
+ const void *const data) A_WARN_UNUSED;
- bool addResource(const std::string &idPath,
- Resource *const resource);
+ Resource *getFromCache(const std::string &idPath) A_WARN_UNUSED;
- /**
- * Releases a resource, placing it in the set of orphaned resources.
- */
- void release(Resource *const res);
+ Resource *getFromCache(const std::string &filename,
+ const int variant) A_WARN_UNUSED;
- void clearDeleted(const bool full = true);
+ bool addResource(const std::string &idPath,
+ Resource *const resource);
- void decRefDelete(Resource *const res);
+ /**
+ * Releases a resource, placing it in the set of orphaned resources.
+ */
+ void release(Resource *const res);
- /**
- * Move resource to deleted resources list.
- */
- void moveToDeleted(Resource *const res);
+ void clearDeleted(const bool full = true);
- void scheduleDelete(SDL_Surface *const surface);
+ void decRefDelete(Resource *const res);
- void clearScheduled();
+ /**
+ * Move resource to deleted resources list.
+ */
+ void moveToDeleted(Resource *const res);
- /**
- * Deletes the class instance if it exists.
- */
- static void deleteInstance();
+ void scheduleDelete(SDL_Surface *const surface);
- int size() const noexcept2 A_WARN_UNUSED
- { return CAST_S32(mResources.size()); }
+ void clearScheduled();
- typedef std::map<std::string, Resource*> Resources;
- typedef Resources::iterator ResourceIterator;
- typedef Resources::const_iterator ResourceCIterator;
+ /**
+ * Deletes the class instance if it exists.
+ */
+ void deleteInstance();
-#ifdef DEBUG_DUMP_LEAKS
- Resources* getResources() A_WARN_UNUSED
- { return &mResources; }
+ int size() noexcept2 A_WARN_UNUSED;
- Resources* getOrphanedResources() A_WARN_UNUSED
- { return &mOrphanedResources; }
-#endif // DEBUG_DUMP_LEAKS
+#if defined(DEBUG_DUMP_LEAKS) || defined(UNITTESTS)
+ Resources &getResources() A_WARN_UNUSED;
- bool cleanOrphans(const bool always = false);
+ Resources &getOrphanedResources() A_WARN_UNUSED;
- void cleanProtected();
+ const std::set<Resource*> &getDeletedResources() A_WARN_UNUSED;
+#endif // defined(DEBUG_DUMP_LEAKS) || defined(UNITTESTS)
- bool isInCache(const std::string &idPath) const A_WARN_UNUSED;
+ bool cleanOrphans(const bool always = false);
- Resource *getTempResource(const std::string &idPath) A_WARN_UNUSED;
+ void cleanProtected();
- void clearCache();
+ bool isInCache(const std::string &idPath) A_WARN_UNUSED;
- int calcMemoryLocal() const override final;
+ Resource *getTempResource(const std::string &idPath) A_WARN_UNUSED;
- int calcMemoryChilds(const int level) const override final;
+ void clearCache();
- std::string getCounterName() const override final
- { return "ResourceManager"; }
+ int calcMemoryLocal();
- static void init();
+ int calcMemoryChilds(const int level);
-#ifndef UNITTESTS
- private:
-#endif // UNITTESTS
- /**
- * Deletes the resource after logging a cleanup message.
- */
- static void cleanUp(Resource *const resource);
+ int calcMemory(const int level);
- static void logResource(const Resource *const res);
+ void cleanUp(Resource *const resource);
- std::set<SDL_Surface*> deletedSurfaces;
- Resources mResources;
- Resources mOrphanedResources;
- std::set<Resource*> mDeletedResources;
- time_t mOldestOrphan;
- bool mDestruction;
-};
+ void logResource(const Resource *const res);
-extern ResourceManager *resourceManager;
+ void logResources(const std::string &msg);
+} // namespace ResourceManager
#endif // RESOURCES_RESOURCEMANAGER_RESOURCEMANAGER_H
diff --git a/src/resources/resourcemanager/resourcemanager_unittest.cc b/src/resources/resourcemanager/resourcemanager_unittest.cc
index c700bfbab..8c8d72868 100644
--- a/src/resources/resourcemanager/resourcemanager_unittest.cc
+++ b/src/resources/resourcemanager/resourcemanager_unittest.cc
@@ -20,6 +20,9 @@
#include "catch.hpp"
#include "client.h"
+#include "configmanager.h"
+#include "configuration.h"
+#include "dirs.h"
#include "logger.h"
#include "graphicsmanager.h"
@@ -27,6 +30,8 @@
#include "fs/virtfs/virtfs.h"
+#include "gui/gui.h"
+
#include "resources/sdlimagehelper.h"
#include "resources/resourcemanager/resourcemanager.h"
@@ -84,6 +89,15 @@ namespace
} // 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");
@@ -92,8 +106,6 @@ TEST_CASE("resourcemanager", "resourcemanager")
XML::initXML();
SDL_Init(SDL_INIT_VIDEO);
logger = new Logger();
- ResourceManager::init();
- ResourceManager *safeResman = resourceManager;
VirtFs::mountDirSilent("data", Append_false);
VirtFs::mountDirSilent("../data", Append_false);
@@ -108,22 +120,40 @@ TEST_CASE("resourcemanager", "resourcemanager")
#endif // USE_SDL2
ActorSprite::load();
- resourceManager = new ResourceManager;
+
+ 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",
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
REQUIRE(testResouceCounter == 1);
REQUIRE(res != nullptr);
REQUIRE(res->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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->getRefCount() == 0);
}
@@ -131,18 +161,18 @@ TEST_CASE("resourcemanager", "resourcemanager")
SECTION("resourcemanager get 2")
{
TestLoader rl = { "test1" };
- Resource *const res = resourceManager->get("test1",
+ Resource *const res = ResourceManager::get("test1",
TestLoader::load, &rl);
REQUIRE(res != nullptr);
REQUIRE(testResouceCounter == 1);
REQUIRE(res->getRefCount() == 1);
res->setSource("source 1");
REQUIRE(res->getSource() == "source 1");
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
- Resource *const res2 = resourceManager->get("test1",
+ 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);
@@ -150,10 +180,10 @@ TEST_CASE("resourcemanager", "resourcemanager")
REQUIRE(res2->getRefCount() == 2);
REQUIRE(res->getIdPath() == res2->getIdPath());
REQUIRE(res2->getSource() == "source 1");
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res2);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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->getRefCount() == 0);
@@ -162,53 +192,53 @@ TEST_CASE("resourcemanager", "resourcemanager")
SECTION("resourcemanager get 3")
{
TestLoader rl = { "test1" };
- Resource *res = resourceManager->get("test1",
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
REQUIRE(res != nullptr);
REQUIRE(testResouceCounter == 1);
REQUIRE(res->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
+ REQUIRE(ResourceManager::getResources()["test1"] == res);
+ REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
+ REQUIRE(ResourceManager::getDeletedResources().empty() == true);
res->setSource("source 1");
res->decRef();
- REQUIRE(resourceManager->mResources.size() == 0);
- REQUIRE(resourceManager->mOrphanedResources["test1"] == res);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
+ REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
+ REQUIRE(ResourceManager::getDeletedResources().empty() == true);
REQUIRE(res->getRefCount() == 0);
}
SECTION("resourcemanager get 4")
{
TestLoader rl = { "test1" };
- Resource *res = resourceManager->get("test1",
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
REQUIRE(res != nullptr);
REQUIRE(testResouceCounter == 1);
REQUIRE(res->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
+ REQUIRE(ResourceManager::getResources()["test1"] == res);
+ REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
+ REQUIRE(ResourceManager::getDeletedResources().empty() == true);
res->setSource("source 1");
res->decRef();
REQUIRE(res->getRefCount() == 0);
- REQUIRE(resourceManager->mResources.size() == 0);
- REQUIRE(resourceManager->mOrphanedResources["test1"] == res);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
+ REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
+ REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- Resource *const res2 = resourceManager->get("test1",
+ Resource *const res2 = ResourceManager::get("test1",
TestLoader::load, &rl);
REQUIRE(res2 != nullptr);
REQUIRE(testResouceCounter == 1);
REQUIRE(res2->getRefCount() == 1);
REQUIRE(res->getIdPath() == res2->getIdPath());
REQUIRE(res2->getSource() == "source 1");
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res2);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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->getRefCount() == 0);
}
@@ -216,43 +246,43 @@ TEST_CASE("resourcemanager", "resourcemanager")
SECTION("resourcemanager get 5")
{
TestLoader rl = { "test1" };
- Resource *res = resourceManager->get("test1",
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
- REQUIRE(resourceManager->isInCache("test1") == true);
+ REQUIRE(ResourceManager::isInCache("test1") == true);
REQUIRE(res != nullptr);
REQUIRE(testResouceCounter == 1);
REQUIRE(res->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
+ REQUIRE(ResourceManager::getResources()["test1"] == res);
+ REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
+ REQUIRE(ResourceManager::getDeletedResources().empty() == true);
res->setSource("source 1");
res->decRef();
REQUIRE(res->getRefCount() == 0);
- REQUIRE(resourceManager->mResources.empty() == true);
- REQUIRE(resourceManager->mOrphanedResources.size() == 1);
- REQUIRE(resourceManager->mOrphanedResources["test1"] == res);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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);
+ ResourceManager::cleanOrphans();
+ REQUIRE(ResourceManager::isInCache("test1") == false);
REQUIRE(testResouceCounter == 0);
- REQUIRE(resourceManager->mResources.empty() == true);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
+ REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
+ REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- Resource *const res2 = resourceManager->get("test1",
+ Resource *const res2 = ResourceManager::get("test1",
TestLoader::load, &rl);
- REQUIRE(resourceManager->isInCache("test1") == true);
+ REQUIRE(ResourceManager::isInCache("test1") == true);
REQUIRE(res2 != nullptr);
REQUIRE(testResouceCounter == 1);
REQUIRE(res2->getRefCount() == 1);
REQUIRE(res2->getSource() == "");
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res2);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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->getRefCount() == 0);
}
@@ -260,28 +290,28 @@ TEST_CASE("resourcemanager", "resourcemanager")
SECTION("resourcemanager get 6")
{
TestLoader rl = { "test1" };
- Resource *res = resourceManager->get("test1",
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
REQUIRE(res != nullptr);
REQUIRE(testResouceCounter == 1);
REQUIRE(res->getRefCount() == 1);
res->setSource("source 1");
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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",
+ Resource *const res2 = ResourceManager::get("test2",
TestLoader::load, &rl);
REQUIRE(res2 != nullptr);
REQUIRE(testResouceCounter == 2);
REQUIRE(res2->getRefCount() == 1);
REQUIRE(res2->getSource() == "");
- REQUIRE(resourceManager->mResources.size() == 2);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mResources["test2"] == res2);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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->getRefCount() == 0);
@@ -291,25 +321,25 @@ TEST_CASE("resourcemanager", "resourcemanager")
SECTION("resourcemanager getFromCache 1")
{
TestLoader rl = { "test1" };
- Resource *res = resourceManager->get("test1",
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
REQUIRE(res != nullptr);
REQUIRE(testResouceCounter == 1);
REQUIRE(res->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
- Resource *const res2 = resourceManager->getFromCache("test1");
+ 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->getRefCount() == 2);
REQUIRE(res == res2);
REQUIRE(res2->getSource() == "");
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res2);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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->getRefCount() == 0);
@@ -318,27 +348,27 @@ TEST_CASE("resourcemanager", "resourcemanager")
SECTION("resourcemanager getFromCache 2")
{
TestLoader rl = { "test1" };
- Resource *res = resourceManager->get("test1",
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
REQUIRE(res != nullptr);
REQUIRE(testResouceCounter == 1);
REQUIRE(res->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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->getRefCount() == 0);
- Resource *const res2 = resourceManager->getFromCache("test1");
+ Resource *const res2 = ResourceManager::getFromCache("test1");
REQUIRE(res2 != nullptr);
REQUIRE(testResouceCounter == 1);
REQUIRE(res2->getRefCount() == 1);
REQUIRE(res == res2);
REQUIRE(res2->getSource() == "");
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res2);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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->getRefCount() == 0);
}
@@ -346,31 +376,31 @@ TEST_CASE("resourcemanager", "resourcemanager")
SECTION("resourcemanager getFromCache 3")
{
TestLoader rl = { "test1" };
- Resource *res = resourceManager->get("test1",
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
REQUIRE(res != nullptr);
REQUIRE(testResouceCounter == 1);
REQUIRE(res->getRefCount() == 1);
res->setSource("source 1");
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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",
+ Resource *const res2 = ResourceManager::get("test2",
TestLoader::load, &rl);
REQUIRE(res2 != nullptr);
REQUIRE(testResouceCounter == 2);
REQUIRE(res2->getRefCount() == 1);
REQUIRE(res2->getSource() == "");
- REQUIRE(resourceManager->mResources.size() == 2);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mResources["test2"] == res2);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
-
- Resource *const resC = resourceManager->getFromCache("test1");
- Resource *const res2C = resourceManager->getFromCache("test2");
+ 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);
@@ -378,11 +408,11 @@ TEST_CASE("resourcemanager", "resourcemanager")
REQUIRE(res2 == res2C);
REQUIRE(resC->getRefCount() == 2);
REQUIRE(res2C->getRefCount() == 2);
- REQUIRE(resourceManager->mResources.size() == 2);
- REQUIRE(resourceManager->mResources["test1"] == resC);
- REQUIRE(resourceManager->mResources["test2"] == res2C);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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();
@@ -397,13 +427,13 @@ TEST_CASE("resourcemanager", "resourcemanager")
REQUIRE(testResouceCounter == 0);
Resource *res = new TestResource();
REQUIRE(testResouceCounter == 1);
- resourceManager->addResource("test1", res);
+ ResourceManager::addResource("test1", res);
REQUIRE(res != nullptr);
REQUIRE(res->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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->getRefCount() == 0);
}
@@ -412,18 +442,18 @@ TEST_CASE("resourcemanager", "resourcemanager")
{
REQUIRE(testResouceCounter == 0);
TestLoader rl = { "test1" };
- REQUIRE(resourceManager->isInCache("test1") == false);
- Resource *res = resourceManager->get("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(ResourceManager::isInCache("test1") == true);
+ REQUIRE(ResourceManager::isInCache("test2") == false);
REQUIRE(testResouceCounter == 1);
REQUIRE(res != nullptr);
REQUIRE(res->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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->getRefCount() == 0);
}
@@ -431,27 +461,27 @@ TEST_CASE("resourcemanager", "resourcemanager")
SECTION("resourcemanager getTempResource 1")
{
TestLoader rl = { "test1" };
- REQUIRE(resourceManager->getTempResource("test1") == nullptr);
- Resource *res = resourceManager->get("test1",
+ REQUIRE(ResourceManager::getTempResource("test1") == nullptr);
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
REQUIRE(res != nullptr);
REQUIRE(testResouceCounter == 1);
REQUIRE(res->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
- Resource *const res2 = resourceManager->getTempResource("test1");
- REQUIRE(resourceManager->getTempResource("test2") == nullptr);
+ 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->getRefCount() == 1);
REQUIRE(res == res2);
REQUIRE(res2->getSource() == "");
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res2);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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->getRefCount() == 0);
}
@@ -460,42 +490,42 @@ TEST_CASE("resourcemanager", "resourcemanager")
{
REQUIRE(testResouceCounter == 0);
TestLoader rl = { "test1" };
- Resource *res = resourceManager->get("test1",
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
REQUIRE(testResouceCounter == 1);
REQUIRE(res != nullptr);
REQUIRE(res->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
- resourceManager->moveToDeleted(res);
+ 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->mResources.empty() == true);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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",
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
res->incRef();
REQUIRE(testResouceCounter == 1);
REQUIRE(res != nullptr);
REQUIRE(res->getRefCount() == 2);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
- resourceManager->moveToDeleted(res);
+ 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->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.empty() == true);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.size() == 1);
+ REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
+ REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
+ REQUIRE(ResourceManager::getDeletedResources().size() == 1);
res->decRef();
}
@@ -503,96 +533,96 @@ TEST_CASE("resourcemanager", "resourcemanager")
{
REQUIRE(testResouceCounter == 0);
TestLoader rl = { "test1" };
- Resource *res = resourceManager->get("test1",
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
REQUIRE(testResouceCounter == 1);
REQUIRE(res != nullptr);
REQUIRE(res->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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->getRefCount() == 0);
- REQUIRE(resourceManager->mResources.empty() == true);
- REQUIRE(resourceManager->mOrphanedResources.size() == 1);
- REQUIRE(resourceManager->mOrphanedResources["test1"] == res);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
+ REQUIRE(ResourceManager::getOrphanedResources().size() == 1);
+ REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
+ REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- resourceManager->moveToDeleted(res);
+ ResourceManager::moveToDeleted(res);
REQUIRE(testResouceCounter == 0);
- REQUIRE(resourceManager->mResources.empty() == true);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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",
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
REQUIRE(testResouceCounter == 1);
REQUIRE(res != nullptr);
REQUIRE(res->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
+ REQUIRE(ResourceManager::getResources()["test1"] == res);
+ REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
+ REQUIRE(ResourceManager::getDeletedResources().empty() == true);
- resourceManager->decRefDelete(res);
+ ResourceManager::decRefDelete(res);
REQUIRE(testResouceCounter == 0);
- REQUIRE(resourceManager->mResources.empty() == true);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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",
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
REQUIRE(testResouceCounter == 1);
REQUIRE(res != nullptr);
REQUIRE(res->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ 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);
+ ResourceManager::cleanUp(res);
REQUIRE(testResouceCounter == 0);
- REQUIRE(resourceManager->mResources.empty() == true);
- REQUIRE(resourceManager->mOrphanedResources.size() == 1);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
- resourceManager->mOrphanedResources.clear();
+ 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",
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
REQUIRE(testResouceCounter == 1);
REQUIRE(res != nullptr);
REQUIRE(res->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ REQUIRE(ResourceManager::getResources().size() == 1 + resSize);
+ REQUIRE(ResourceManager::getResources()["test1"] == res);
+ REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
+ REQUIRE(ResourceManager::getDeletedResources().empty() == true);
res->setProtected(true);
- resourceManager->cleanProtected();
+ ResourceManager::cleanProtected();
REQUIRE(testResouceCounter == 1);
- REQUIRE(resourceManager->mResources.empty() == true);
- REQUIRE(resourceManager->mOrphanedResources.size() == 1);
- REQUIRE(resourceManager->mOrphanedResources["test1"] == res);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
+ REQUIRE(ResourceManager::getOrphanedResources().size() == 1);
+ REQUIRE(ResourceManager::getOrphanedResources()["test1"] == res);
+ REQUIRE(ResourceManager::getDeletedResources().empty() == true);
res->decRef();
}
@@ -600,29 +630,29 @@ TEST_CASE("resourcemanager", "resourcemanager")
{
REQUIRE(testResouceCounter == 0);
TestLoader rl = { "test1" };
- Resource *res = resourceManager->get("test1",
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
res->incRef();
REQUIRE(testResouceCounter == 1);
REQUIRE(res != nullptr);
REQUIRE(res->getRefCount() == 2);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
- resourceManager->moveToDeleted(res);
+ 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->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.empty() == true);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.size() == 1);
+ REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
+ REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
+ REQUIRE(ResourceManager::getDeletedResources().size() == 1);
- resourceManager->clearDeleted();
+ ResourceManager::clearDeleted();
REQUIRE(testResouceCounter == 1);
REQUIRE(res->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.empty() == true);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.size() == 1);
+ REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
+ REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
+ REQUIRE(ResourceManager::getDeletedResources().size() == 1);
res->decRef();
}
@@ -630,36 +660,43 @@ TEST_CASE("resourcemanager", "resourcemanager")
{
REQUIRE(testResouceCounter == 0);
TestLoader rl = { "test1" };
- Resource *res = resourceManager->get("test1",
+ Resource *res = ResourceManager::get("test1",
TestLoader::load, &rl);
res->incRef();
REQUIRE(testResouceCounter == 1);
REQUIRE(res != nullptr);
REQUIRE(res->getRefCount() == 2);
- REQUIRE(resourceManager->mResources.size() == 1);
- REQUIRE(resourceManager->mResources["test1"] == res);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
- resourceManager->moveToDeleted(res);
+ 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->getRefCount() == 1);
- REQUIRE(resourceManager->mResources.empty() == true);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.size() == 1);
+ REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
+ REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
+ REQUIRE(ResourceManager::getDeletedResources().size() == 1);
res->decRef();
- resourceManager->clearDeleted();
+ ResourceManager::clearDeleted();
REQUIRE(testResouceCounter == 0);
- REQUIRE(resourceManager->mResources.empty() == true);
- REQUIRE(resourceManager->mOrphanedResources.empty() == true);
- REQUIRE(resourceManager->mDeletedResources.empty() == true);
+ REQUIRE(ResourceManager::getResources().size() == 0 + resSize);
+ REQUIRE(ResourceManager::getOrphanedResources().empty() == true);
+ REQUIRE(ResourceManager::getDeletedResources().empty() == true);
}
- delete resourceManager;
- resourceManager = safeResman;
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);
+}