summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/atlas/atlasmanager.cpp16
-rw-r--r--src/resources/atlas/atlasresource.cpp2
-rw-r--r--src/resources/dye/dye_unittest.cc21
-rw-r--r--src/resources/dye/dyepalette_unittest.cc19
-rw-r--r--src/resources/image/image.cpp2
-rw-r--r--src/resources/loaders/atlasloader.cpp2
-rw-r--r--src/resources/loaders/emptyatlasloader.cpp2
-rw-r--r--src/resources/loaders/imageloader.cpp2
-rw-r--r--src/resources/loaders/imagesetloader.cpp2
-rw-r--r--src/resources/loaders/musicloader.cpp2
-rw-r--r--src/resources/loaders/rescaledloader.cpp2
-rw-r--r--src/resources/loaders/shaderloader.cpp2
-rw-r--r--src/resources/loaders/shaderprogramloader.cpp2
-rw-r--r--src/resources/loaders/soundloader.cpp2
-rw-r--r--src/resources/loaders/spritedefloader.cpp2
-rw-r--r--src/resources/loaders/subimageloader.cpp2
-rw-r--r--src/resources/loaders/subimagesetloader.cpp2
-rw-r--r--src/resources/loaders/walklayerloader.cpp2
-rw-r--r--src/resources/loaders/xmlloader.cpp2
-rw-r--r--src/resources/map/maplayer_unittest.cc3
-rw-r--r--src/resources/map/speciallayer_unittest.cc23
-rw-r--r--src/resources/memorymanager.cpp8
-rw-r--r--src/resources/resource.cpp2
-rw-r--r--src/resources/resource.h20
-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
-rw-r--r--src/resources/sprite/animatedsprite.cpp2
-rw-r--r--src/resources/sprite/animatedsprite_unittest.cc19
29 files changed, 573 insertions, 451 deletions
diff --git a/src/resources/atlas/atlasmanager.cpp b/src/resources/atlas/atlasmanager.cpp
index b9107a757..91749e597 100644
--- a/src/resources/atlas/atlasmanager.cpp
+++ b/src/resources/atlas/atlasmanager.cpp
@@ -132,12 +132,12 @@ void AtlasManager::loadImages(const StringVect &files,
const std::string str = *it;
// check is image with same name already in cache
// and if yes, move it to deleted set
- Resource *const res = resourceManager->getTempResource(str);
+ Resource *const res = ResourceManager::getTempResource(str);
if (res)
{
// increase counter because in moveToDeleted it will be decreased.
res->incRef();
- resourceManager->moveToDeleted(res);
+ ResourceManager::moveToDeleted(res);
}
std::string path = str;
@@ -181,12 +181,12 @@ void AtlasManager::loadEmptyImages(const StringVect &files,
const std::string str = *it;
// check is image with same name already in cache
// and if yes, move it to deleted set
- Resource *const res = resourceManager->getTempResource(str);
+ Resource *const res = ResourceManager::getTempResource(str);
if (res)
{
// increase counter because in moveToDeleted it will be decreased.
res->incRef();
- resourceManager->moveToDeleted(res);
+ ResourceManager::moveToDeleted(res);
}
Image *const image = new Image(0,
@@ -395,14 +395,14 @@ void AtlasManager::injectToResources(const AtlasResource *const resource)
{
Image *const image = atlas->atlasImage;
if (image)
- resourceManager->addResource(atlas->name, image);
+ ResourceManager::addResource(atlas->name, image);
FOR_EACH (std::vector<AtlasItem*>::iterator, it2, atlas->items)
{
AtlasItem *const item = *it2;
if (!item)
continue;
// add each atlas sub image to resources
- resourceManager->addResource(item->name, item->image);
+ ResourceManager::addResource(item->name, item->image);
}
}
}
@@ -422,7 +422,7 @@ void AtlasManager::moveToDeleted(AtlasResource *const resource)
if (image)
{
// move each atlas image to deleted
- resourceManager->moveToDeleted(image);
+ ResourceManager::moveToDeleted(image);
}
FOR_EACH (std::vector<AtlasItem*>::iterator, it2, atlas->items)
{
@@ -433,7 +433,7 @@ void AtlasManager::moveToDeleted(AtlasResource *const resource)
if (image2)
{
// move each atlas sub image to deleted
- resourceManager->moveToDeleted(image2);
+ ResourceManager::moveToDeleted(image2);
}
}
}
diff --git a/src/resources/atlas/atlasresource.cpp b/src/resources/atlas/atlasresource.cpp
index 5f2a3d3c7..06ae62542 100644
--- a/src/resources/atlas/atlasresource.cpp
+++ b/src/resources/atlas/atlasresource.cpp
@@ -53,7 +53,7 @@ AtlasResource::~AtlasResource()
delete atlas;
}
}
- resourceManager->clearDeleted(false);
+ ResourceManager::clearDeleted(false);
}
void AtlasResource::incRef()
diff --git a/src/resources/dye/dye_unittest.cc b/src/resources/dye/dye_unittest.cc
index 4323a28f6..f31097cbe 100644
--- a/src/resources/dye/dye_unittest.cc
+++ b/src/resources/dye/dye_unittest.cc
@@ -28,6 +28,8 @@
#include "fs/virtfs/virtfs.h"
+#include "gui/gui.h"
+
#include "resources/sdlimagehelper.h"
#ifdef USE_SDL2
#include "resources/surfaceimagehelper.h"
@@ -53,6 +55,15 @@
#ifdef USE_OPENGL
+TEST_CASE("Dye leak test1")
+{
+ logger = new Logger();
+ REQUIRE(gui == nullptr);
+ ResourceManager::cleanOrphans(true);
+ ResourceManager::deleteInstance();
+ delete2(logger);
+}
+
TEST_CASE("Dye replaceSOGLColor 1 1")
{
DyePalette palette("#00ff00,000011", 6);
@@ -2357,7 +2368,6 @@ TEST_CASE("Dye real dye")
client = new Client;
SDL_Init(SDL_INIT_VIDEO);
logger = new Logger();
- ResourceManager::init();
VirtFs::mountDirSilent("data", Append_false);
VirtFs::mountDirSilent("../data", Append_false);
VirtFs::mountDirSilent("data/test", Append_false);
@@ -2400,3 +2410,12 @@ TEST_CASE("Dye real dye")
delete2(logger);
// VirtFs::deinit();
}
+
+TEST_CASE("Dye leak test2")
+{
+ logger = new Logger();
+ REQUIRE(gui == nullptr);
+ ResourceManager::cleanOrphans(true);
+ ResourceManager::deleteInstance();
+ delete2(logger);
+}
diff --git a/src/resources/dye/dyepalette_unittest.cc b/src/resources/dye/dyepalette_unittest.cc
index 14e5e5d49..280a74ead 100644
--- a/src/resources/dye/dyepalette_unittest.cc
+++ b/src/resources/dye/dyepalette_unittest.cc
@@ -52,6 +52,15 @@
#include "debug.h"
+TEST_CASE("DyePalette leak test1")
+{
+ logger = new Logger();
+ REQUIRE(gui == nullptr);
+ ResourceManager::cleanOrphans(true);
+ ResourceManager::deleteInstance();
+ delete2(logger);
+}
+
TEST_CASE("DyePalette tests")
{
setEnv("SDL_VIDEODRIVER", "dummy");
@@ -60,7 +69,6 @@ TEST_CASE("DyePalette tests")
XML::initXML();
SDL_Init(SDL_INIT_VIDEO);
logger = new Logger();
- ResourceManager::init();
VirtFs::mountDirSilent("data", Append_false);
VirtFs::mountDirSilent("../data", Append_false);
VirtFs::mountDirSilent("data/test", Append_false);
@@ -399,3 +407,12 @@ TEST_CASE("DyePalette tests")
delete2(logger);
// VirtFs::deinit();
}
+
+TEST_CASE("DyePalette leak test2")
+{
+ logger = new Logger();
+ REQUIRE(gui == nullptr);
+ ResourceManager::cleanOrphans(true);
+ ResourceManager::deleteInstance();
+ delete2(logger);
+}
diff --git a/src/resources/image/image.cpp b/src/resources/image/image.cpp
index 390bf6cf1..f295be9cb 100644
--- a/src/resources/image/image.cpp
+++ b/src/resources/image/image.cpp
@@ -215,7 +215,7 @@ void Image::SDLCleanCache()
i != i_end; ++i)
{
if (mSDLSurface != i->second)
- resourceManager->scheduleDelete(i->second);
+ ResourceManager::scheduleDelete(i->second);
i->second = nullptr;
}
mAlphaCache.clear();
diff --git a/src/resources/loaders/atlasloader.cpp b/src/resources/loaders/atlasloader.cpp
index c5f6691a3..1faa98b44 100644
--- a/src/resources/loaders/atlasloader.cpp
+++ b/src/resources/loaders/atlasloader.cpp
@@ -56,7 +56,7 @@ Resource *Loader::getAtlas(const std::string &name,
const StringVect &files)
{
AtlasLoader rl = { name, &files };
- return resourceManager->get("atlas_" + name, AtlasLoader::load, &rl);
+ return ResourceManager::get("atlas_" + name, AtlasLoader::load, &rl);
}
#endif // USE_OPENGL
diff --git a/src/resources/loaders/emptyatlasloader.cpp b/src/resources/loaders/emptyatlasloader.cpp
index 81d99cd51..6fe2f1463 100644
--- a/src/resources/loaders/emptyatlasloader.cpp
+++ b/src/resources/loaders/emptyatlasloader.cpp
@@ -57,7 +57,7 @@ Resource *Loader::getEmptyAtlas(const std::string &name,
const StringVect &files)
{
EmptyAtlasLoader rl = { name, &files };
- return resourceManager->get("atlas_" + name, EmptyAtlasLoader::load, &rl);
+ return ResourceManager::get("atlas_" + name, EmptyAtlasLoader::load, &rl);
}
#endif // USE_OPENGL
diff --git a/src/resources/loaders/imageloader.cpp b/src/resources/loaders/imageloader.cpp
index 2bfba2706..5ae883886 100644
--- a/src/resources/loaders/imageloader.cpp
+++ b/src/resources/loaders/imageloader.cpp
@@ -85,6 +85,6 @@ namespace
Image *Loader::getImage(const std::string &idPath)
{
DyedImageLoader rl = { idPath };
- return static_cast<Image*>(resourceManager->get(idPath,
+ return static_cast<Image*>(ResourceManager::get(idPath,
DyedImageLoader::load, &rl));
}
diff --git a/src/resources/loaders/imagesetloader.cpp b/src/resources/loaders/imagesetloader.cpp
index 6ec02c699..468b97120 100644
--- a/src/resources/loaders/imagesetloader.cpp
+++ b/src/resources/loaders/imagesetloader.cpp
@@ -74,6 +74,6 @@ ImageSet *Loader::getImageSet(const std::string &imagePath,
"x").append(toString(
h)).append(
"]");
- return static_cast<ImageSet*>(resourceManager->get(str,
+ return static_cast<ImageSet*>(ResourceManager::get(str,
ImageSetLoader::load, &rl));
}
diff --git a/src/resources/loaders/musicloader.cpp b/src/resources/loaders/musicloader.cpp
index f23a9fc70..0d482b8a6 100644
--- a/src/resources/loaders/musicloader.cpp
+++ b/src/resources/loaders/musicloader.cpp
@@ -78,6 +78,6 @@ namespace
SDLMusic *Loader::getMusic(const std::string &idPath)
{
ResourceLoader rl = { idPath };
- return static_cast<SDLMusic*>(resourceManager->get(
+ return static_cast<SDLMusic*>(ResourceManager::get(
idPath, ResourceLoader::load, &rl));
}
diff --git a/src/resources/loaders/rescaledloader.cpp b/src/resources/loaders/rescaledloader.cpp
index c4c315227..e4a9112f1 100644
--- a/src/resources/loaders/rescaledloader.cpp
+++ b/src/resources/loaders/rescaledloader.cpp
@@ -72,6 +72,6 @@ Image *Loader::getRescaled(const Image *const image,
"_rescaled%dx%d", width, height);
const RescaledLoader rl = { image, width, height };
Image *const img = static_cast<Image *const>(
- resourceManager->get(idPath, RescaledLoader::load, &rl));
+ ResourceManager::get(idPath, RescaledLoader::load, &rl));
return img;
}
diff --git a/src/resources/loaders/shaderloader.cpp b/src/resources/loaders/shaderloader.cpp
index f06c9d219..d2ffba348 100644
--- a/src/resources/loaders/shaderloader.cpp
+++ b/src/resources/loaders/shaderloader.cpp
@@ -61,7 +61,7 @@ Resource *Loader::getShader(const unsigned int type,
const std::string &name)
{
ShaderLoader rl = { name, type };
- return resourceManager->get("shader_" + name, ShaderLoader::load, &rl);
+ return ResourceManager::get("shader_" + name, ShaderLoader::load, &rl);
}
#endif // USE_OPENGL
diff --git a/src/resources/loaders/shaderprogramloader.cpp b/src/resources/loaders/shaderprogramloader.cpp
index d48e1aa9f..763536a6c 100644
--- a/src/resources/loaders/shaderprogramloader.cpp
+++ b/src/resources/loaders/shaderprogramloader.cpp
@@ -66,7 +66,7 @@ Resource *Loader::getShaderProgram(const std::string &vertex,
const bool isNewShader)
{
ShaderProgramLoader rl = { vertex, fragment, isNewShader };
- return resourceManager->get("program_" + vertex + " + " + fragment,
+ return ResourceManager::get("program_" + vertex + " + " + fragment,
ShaderProgramLoader::load, &rl);
}
diff --git a/src/resources/loaders/soundloader.cpp b/src/resources/loaders/soundloader.cpp
index be71a5ddb..bff769755 100644
--- a/src/resources/loaders/soundloader.cpp
+++ b/src/resources/loaders/soundloader.cpp
@@ -73,6 +73,6 @@ namespace
SoundEffect *Loader::getSoundEffect(const std::string &idPath)
{
ResourceLoader rl = { idPath };
- return static_cast<SoundEffect*>(resourceManager->get(
+ return static_cast<SoundEffect*>(ResourceManager::get(
idPath, ResourceLoader::load, &rl));
}
diff --git a/src/resources/loaders/spritedefloader.cpp b/src/resources/loaders/spritedefloader.cpp
index c140c8f73..bdc0c40f0 100644
--- a/src/resources/loaders/spritedefloader.cpp
+++ b/src/resources/loaders/spritedefloader.cpp
@@ -63,6 +63,6 @@ SpriteDef *Loader::getSprite(const std::string &path,
"[").append(toString(
variant).append(
"]"));
- return static_cast<SpriteDef*>(resourceManager->get(str,
+ return static_cast<SpriteDef*>(ResourceManager::get(str,
SpriteDefLoader::load, &rl));
}
diff --git a/src/resources/loaders/subimageloader.cpp b/src/resources/loaders/subimageloader.cpp
index f2f7ad7de..804e957a5 100644
--- a/src/resources/loaders/subimageloader.cpp
+++ b/src/resources/loaders/subimageloader.cpp
@@ -85,6 +85,6 @@ Image *Loader::getSubImage(Image *const parent,
"x").append(
toString(height)).append(
"]");
- return static_cast<Image*>(resourceManager->get(str,
+ return static_cast<Image*>(ResourceManager::get(str,
SubImageLoader::load, &rl));
}
diff --git a/src/resources/loaders/subimagesetloader.cpp b/src/resources/loaders/subimagesetloader.cpp
index c8d0fba74..6ca43cb32 100644
--- a/src/resources/loaders/subimagesetloader.cpp
+++ b/src/resources/loaders/subimagesetloader.cpp
@@ -73,6 +73,6 @@ ImageSet *Loader::getSubImageSet(Image *const parent,
"x").append(toString(
height)).append(
"]");
- return static_cast<ImageSet*>(resourceManager->get(str,
+ return static_cast<ImageSet*>(ResourceManager::get(str,
SubImageSetLoader::load, &rl));
}
diff --git a/src/resources/loaders/walklayerloader.cpp b/src/resources/loaders/walklayerloader.cpp
index 71f94539a..99d7a251f 100644
--- a/src/resources/loaders/walklayerloader.cpp
+++ b/src/resources/loaders/walklayerloader.cpp
@@ -58,7 +58,7 @@ WalkLayer *Loader::getWalkLayer(const std::string &name,
Map *const map)
{
WalkLayerLoader rl = {name, map};
- return static_cast<WalkLayer*>(resourceManager->get("map_" + name,
+ return static_cast<WalkLayer*>(ResourceManager::get("map_" + name,
WalkLayerLoader::load, &rl));
}
#else // DYECMD
diff --git a/src/resources/loaders/xmlloader.cpp b/src/resources/loaders/xmlloader.cpp
index ac005bc06..74dd46ef9 100644
--- a/src/resources/loaders/xmlloader.cpp
+++ b/src/resources/loaders/xmlloader.cpp
@@ -58,7 +58,7 @@ XML::Document *Loader::getXml(const std::string &idPath,
const SkipError skipError)
{
ResourceLoader rl = { idPath, useResman, skipError };
- return static_cast<XML::Document*>(resourceManager->get(
+ return static_cast<XML::Document*>(ResourceManager::get(
idPath, ResourceLoader::load, &rl));
}
diff --git a/src/resources/map/maplayer_unittest.cc b/src/resources/map/maplayer_unittest.cc
index 945c52b0e..e8066029c 100644
--- a/src/resources/map/maplayer_unittest.cc
+++ b/src/resources/map/maplayer_unittest.cc
@@ -1649,7 +1649,6 @@ TEST_CASE("MapLayer draw")
TEST_CASE("MapLayer drawSpecialLayer (specialLayer)")
{
logger = new Logger;
- ResourceManager::init();
VirtFs::mountDirSilent("data", Append_false);
VirtFs::mountDirSilent("../data", Append_false);
@@ -2002,7 +2001,6 @@ TEST_CASE("MapLayer drawSpecialLayer (specialLayer)")
TEST_CASE("MapLayer drawSpecialLayer (tempLayer)")
{
logger = new Logger;
- ResourceManager::init();
VirtFs::mountDirSilent("data", Append_false);
VirtFs::mountDirSilent("../data", Append_false);
@@ -2361,7 +2359,6 @@ TEST_CASE("MapLayer drawSpecialLayer (tempLayer)")
TEST_CASE("MapLayer drawFringe")
{
logger = new Logger;
- ResourceManager::init();
VirtFs::mountDirSilent("data", Append_false);
VirtFs::mountDirSilent("../data", Append_false);
diff --git a/src/resources/map/speciallayer_unittest.cc b/src/resources/map/speciallayer_unittest.cc
index 93270d7e5..d43daaac8 100644
--- a/src/resources/map/speciallayer_unittest.cc
+++ b/src/resources/map/speciallayer_unittest.cc
@@ -30,6 +30,8 @@
#include "fs/virtfs/virtfs.h"
+#include "gui/gui.h"
+
#include "utils/delete2.h"
#include "resources/sdlimagehelper.h"
@@ -40,11 +42,19 @@
#include "debug.h"
+TEST_CASE("SpecialLayer leak test1")
+{
+ logger = new Logger();
+ REQUIRE(gui == nullptr);
+ ResourceManager::cleanOrphans(true);
+ ResourceManager::deleteInstance();
+ delete2(logger);
+}
+
TEST_CASE("SpecialLayer updateCache")
{
logger = new Logger;
client = new Client;
- ResourceManager::init();
VirtFs::mountDirSilent("data", Append_false);
VirtFs::mountDirSilent("../data", Append_false);
@@ -260,9 +270,18 @@ TEST_CASE("SpecialLayer updateCache")
}
delete layer;
- resourceManager->cleanOrphans();
+ ResourceManager::cleanOrphans();
delete2(client);
VirtFs::unmountDirSilent("data");
VirtFs::unmountDirSilent("../data");
delete2(logger);
}
+
+TEST_CASE("SpecialLayer leak test2")
+{
+ logger = new Logger();
+ REQUIRE(gui == nullptr);
+ ResourceManager::cleanOrphans(true);
+ ResourceManager::deleteInstance();
+ delete2(logger);
+}
diff --git a/src/resources/memorymanager.cpp b/src/resources/memorymanager.cpp
index 01e67eb1b..55d157c5f 100644
--- a/src/resources/memorymanager.cpp
+++ b/src/resources/memorymanager.cpp
@@ -80,14 +80,12 @@ void MemoryManager::printAllMemory(ChatTab *const tab A_DYECMD_UNUSED)
{
if (!logger)
return;
+
#ifdef DYECMD
- if (resourceManager)
- resourceManager->calcMemory(0);
+ ResourceManager::calcMemory(0);
#else // DYECMD
- int sz = 0;
- if (resourceManager)
- sz += resourceManager->calcMemory(0);
+ int sz = ResourceManager::calcMemory(0);
if (tab)
{
// TRANSLATORS: memory usage chat message
diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp
index 0d01f440c..e75df7b44 100644
--- a/src/resources/resource.cpp
+++ b/src/resources/resource.cpp
@@ -66,7 +66,7 @@ void Resource::decRef()
if (mRefCount == 0 && !mNotCount)
{
// Warn the manager that this resource is no longer used.
- resourceManager->release(this);
+ ResourceManager::release(this);
}
}
diff --git a/src/resources/resource.h b/src/resources/resource.h
index e9f7e0531..4b2f57229 100644
--- a/src/resources/resource.h
+++ b/src/resources/resource.h
@@ -32,17 +32,15 @@
*/
class Resource notfinal : public MemoryCounter
{
- friend class ResourceManager;
-
public:
/**
* Constructor
*/
Resource() :
MemoryCounter(),
+ mTimeStamp(0),
mIdPath(),
mSource(),
- mTimeStamp(0),
mRefCount(0),
mProtected(false),
#ifdef DEBUG_DUMP_LEAKS
@@ -57,6 +55,11 @@ class Resource notfinal : public MemoryCounter
A_DELETE_COPY(Resource)
/**
+ * Destructor.
+ */
+ virtual ~Resource();
+
+ /**
* Increments the internal reference count.
*/
virtual void incRef();
@@ -76,6 +79,9 @@ class Resource notfinal : public MemoryCounter
const std::string &getIdPath() const noexcept2 A_WARN_UNUSED
{ return mIdPath; }
+ void setIdPath(const std::string &path)
+ { mIdPath = path; }
+
/**
* Return refCount for this resource.
*/
@@ -110,19 +116,15 @@ class Resource notfinal : public MemoryCounter
{ mDumped = n; }
#endif // DEBUG_DUMP_LEAKS
+ time_t mTimeStamp; /**< Time at which the resource was orphaned. */
+
#ifndef UNITTESTS
protected:
#endif // UNITTESTS
- /**
- * Destructor.
- */
- virtual ~Resource();
-
std::string mIdPath; /**< Path identifying this resource. */
std::string mSource;
private:
- time_t mTimeStamp; /**< Time at which the resource was orphaned. */
unsigned int mRefCount; /**< Reference count. */
bool mProtected;
bool mNotCount;
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);
+}
diff --git a/src/resources/sprite/animatedsprite.cpp b/src/resources/sprite/animatedsprite.cpp
index 960a5ea00..3e9250e13 100644
--- a/src/resources/sprite/animatedsprite.cpp
+++ b/src/resources/sprite/animatedsprite.cpp
@@ -90,7 +90,7 @@ AnimatedSprite *AnimatedSprite::delayedLoad(const std::string &restrict
{
if (!mEnableCache)
return load(filename, variant);
- Resource *restrict const res = resourceManager->getFromCache(
+ Resource *restrict const res = ResourceManager::getFromCache(
filename, variant);
if (res)
{
diff --git a/src/resources/sprite/animatedsprite_unittest.cc b/src/resources/sprite/animatedsprite_unittest.cc
index d17177a6d..f48b10b4b 100644
--- a/src/resources/sprite/animatedsprite_unittest.cc
+++ b/src/resources/sprite/animatedsprite_unittest.cc
@@ -54,6 +54,15 @@
#include "debug.h"
+TEST_CASE("AnimatedSprite leak test1")
+{
+ logger = new Logger();
+ REQUIRE(gui == nullptr);
+ ResourceManager::cleanOrphans(true);
+ ResourceManager::deleteInstance();
+ delete2(logger);
+}
+
TEST_CASE("AnimatedSprite tests", "animatedsprite")
{
setEnv("SDL_VIDEODRIVER", "dummy");
@@ -63,7 +72,6 @@ TEST_CASE("AnimatedSprite tests", "animatedsprite")
XML::initXML();
SDL_Init(SDL_INIT_VIDEO);
logger = new Logger();
- ResourceManager::init();
VirtFs::mountDirSilent("data", Append_false);
VirtFs::mountDirSilent("../data", Append_false);
mainGraphics = new SDLGraphics;
@@ -196,3 +204,12 @@ TEST_CASE("AnimatedSprite tests", "animatedsprite")
delete2(logger);
// VirtFs::deinit();
}
+
+TEST_CASE("AnimatedSprite leak test2")
+{
+ logger = new Logger();
+ REQUIRE(gui == nullptr);
+ ResourceManager::cleanOrphans(true);
+ ResourceManager::deleteInstance();
+ delete2(logger);
+}