Resources (#1)
* start some resource fiddling * start some resource fiddling * initiate a real resource manager * fix color flicker in rendering * delete unintended constructors and add a convenience function to reset the render-image (from the original image, aka. clone again) * [OpenGL deprecation warning] The compiler said that these functions are "deprecated". They seem to be useless anyway... * various improvements * add resource enumerator and documentation * fix constness stuff * use existing iterator for insertion * init unit tests * rm bogus file --------- Co-authored-by: m-aXimilian <keuffnermax@gmail.com>
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "imaging/PixelariumImage.hpp"
|
||||
#include "resources/resource.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
class DummyImage : public pixelarium::imaging::PixelariumImage
|
||||
{
|
||||
// Implement minimal interface if needed for test
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
using pixelarium::resources::ImageResourcePool;
|
||||
|
||||
TEST(ImageResourcePoolTest, SetAndGetResource)
|
||||
{
|
||||
ImageResourcePool pool;
|
||||
auto img = std::make_unique<DummyImage>();
|
||||
auto id = pool.SetResource(std::move(img));
|
||||
auto res = pool.GetResource(id);
|
||||
EXPECT_TRUE(res.has_value());
|
||||
EXPECT_NE(res.value(), nullptr);
|
||||
}
|
||||
|
||||
TEST(ImageResourcePoolTest, SetWrappedRawPointerGet)
|
||||
{
|
||||
ImageResourcePool pool;
|
||||
auto img = new DummyImage();
|
||||
auto id = pool.SetResource(std::unique_ptr<pixelarium::imaging::PixelariumImage>(img));
|
||||
auto res = pool.GetResource(id);
|
||||
EXPECT_TRUE(res.has_value());
|
||||
EXPECT_NE(res.value(), nullptr);
|
||||
}
|
||||
|
||||
TEST(ImageResourcePoolTest, GetNonExistentResourceReturnsEmptyOptional)
|
||||
{
|
||||
ImageResourcePool pool;
|
||||
EXPECT_FALSE(pool.GetResource(12345));
|
||||
}
|
||||
|
||||
TEST(ImageResourcePoolTest, UpdateResourceSuccess)
|
||||
{
|
||||
ImageResourcePool pool;
|
||||
auto id = pool.SetResource(std::make_unique<DummyImage>());
|
||||
auto new_img = std::make_unique<DummyImage>();
|
||||
EXPECT_TRUE(pool.UpdateResource(id, std::move(new_img)));
|
||||
auto res = pool.GetResource(id);
|
||||
EXPECT_TRUE(res.has_value());
|
||||
EXPECT_NE(res.value(), nullptr);
|
||||
}
|
||||
|
||||
TEST(ImageResourcePoolTest, UpdateResourceFail)
|
||||
{
|
||||
ImageResourcePool pool;
|
||||
auto new_img = std::make_unique<DummyImage>();
|
||||
EXPECT_FALSE(pool.UpdateResource(999, std::move(new_img)));
|
||||
}
|
||||
|
||||
TEST(ImageResourcePoolTest, DeleteResourceSuccess)
|
||||
{
|
||||
ImageResourcePool pool;
|
||||
auto id = pool.SetResource(std::make_unique<DummyImage>());
|
||||
EXPECT_TRUE(pool.DeleteResource(id));
|
||||
EXPECT_FALSE(pool.GetResource(id).has_value());
|
||||
}
|
||||
|
||||
TEST(ImageResourcePoolTest, DeleteResourceFail)
|
||||
{
|
||||
ImageResourcePool pool;
|
||||
EXPECT_FALSE(pool.DeleteResource(8907));
|
||||
}
|
||||
|
||||
TEST(ImageResourcePoolTest, EnumerateResources)
|
||||
{
|
||||
ImageResourcePool pool;
|
||||
auto id1 = pool.SetResource(std::make_unique<DummyImage>());
|
||||
auto id2 = pool.SetResource(std::make_unique<DummyImage>());
|
||||
std::vector<size_t> found_ids{};
|
||||
|
||||
std::function<void(size_t, const pixelarium::imaging::PixelariumImage&)> func =
|
||||
[&found_ids](size_t id, const pixelarium::imaging::PixelariumImage&) { found_ids.push_back(id); };
|
||||
pool.EnumerateResources(func);
|
||||
|
||||
EXPECT_EQ(found_ids.size(), 2);
|
||||
EXPECT_NE(std::find(found_ids.begin(), found_ids.end(), id1), found_ids.end());
|
||||
EXPECT_NE(std::find(found_ids.begin(), found_ids.end(), id2), found_ids.end());
|
||||
}
|
||||
Reference in New Issue
Block a user