mutable handle

This commit is contained in:
Michele Caini
2019-05-21 15:02:30 +02:00
parent c126b64892
commit d4a64e93e0
3 changed files with 38 additions and 21 deletions

View File

@@ -2,7 +2,7 @@
#include <gtest/gtest.h>
#include <entt/resource/cache.hpp>
struct resource { const int value; };
struct resource { int value; };
struct loader: entt::resource_loader<loader, resource> {
std::shared_ptr<resource> load(int value) const {
@@ -91,3 +91,19 @@ TEST(Resource, Functionalities) {
ASSERT_TRUE(std::is_copy_assignable_v<entt::resource_handle<resource>>);
ASSERT_TRUE(std::is_move_assignable_v<entt::resource_handle<resource>>);
}
TEST(Resource, MutableHandle) {
entt::resource_cache<resource> cache;
constexpr auto hs = entt::hashed_string{"res"};
auto handle = cache.load<loader>(hs, 0);
ASSERT_TRUE(handle);
++handle.get().value;
++static_cast<resource &>(handle).value;
++(*handle).value;
++handle->value;
ASSERT_EQ(cache.handle(hs)->value, 4);
}