Skip to content

Commit

Permalink
bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Jun 18, 2017
1 parent b6a91c9 commit 28448e1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class Registry<Pool<Entity, Components...>> {
} else if(src) {
clone<Comp>(to, from);
} else if(dst) {
destroy(to);
remove<Comp>(to);
}
}

Expand Down
37 changes: 35 additions & 2 deletions test/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,19 @@ TEST(DefaultRegistry, Functionalities) {
ASSERT_NO_THROW(registry.remove<int>(e2));
ASSERT_NO_THROW(registry.accomodate<int>(e1, 1));
ASSERT_NO_THROW(registry.accomodate<int>(e2, 1));
ASSERT_EQ(registry.get<int>(e1), 1);
ASSERT_EQ(registry.get<int>(e2), 1);
ASSERT_EQ(static_cast<const registry_type &>(registry).get<int>(e1), 1);
ASSERT_EQ(static_cast<const registry_type &>(registry).get<int>(e2), 1);

ASSERT_EQ(registry.size(), registry_type::size_type{3});
ASSERT_EQ(registry.capacity(), registry_type::size_type{3});
ASSERT_FALSE(registry.empty());

ASSERT_NO_THROW(registry.destroy(e3));

ASSERT_TRUE(registry.valid(e1));
ASSERT_TRUE(registry.valid(e2));
ASSERT_FALSE(registry.valid(e3));

ASSERT_EQ(registry.size(), registry_type::size_type{2});
ASSERT_EQ(registry.capacity(), registry_type::size_type{3});
ASSERT_FALSE(registry.empty());
Expand Down Expand Up @@ -112,6 +116,35 @@ TEST(DefaultRegistry, Functionalities) {
ASSERT_TRUE(registry.empty<int>());
}

TEST(DefaultRegistry, Copy) {
using registry_type = entt::DefaultRegistry<int, char, double>;

registry_type registry;

registry_type::entity_type e1 = registry.create<int, char>();
registry_type::entity_type e2 = registry.create<int, double>();

ASSERT_TRUE(registry.has<int>(e1));
ASSERT_TRUE(registry.has<char>(e1));
ASSERT_FALSE(registry.has<double>(e1));

ASSERT_TRUE(registry.has<int>(e2));
ASSERT_FALSE(registry.has<char>(e2));
ASSERT_TRUE(registry.has<double>(e2));

ASSERT_NO_THROW(registry.copy(e2, e1));

ASSERT_TRUE(registry.has<int>(e1));
ASSERT_TRUE(registry.has<char>(e1));
ASSERT_FALSE(registry.has<double>(e1));

ASSERT_TRUE(registry.has<int>(e2));
ASSERT_TRUE(registry.has<char>(e2));
ASSERT_FALSE(registry.has<double>(e2));

ASSERT_TRUE(registry.empty<double>());
}

TEST(DefaultRegistry, ViewSingleComponent) {
using registry_type = entt::DefaultRegistry<int, char>;

Expand Down

0 comments on commit 28448e1

Please sign in to comment.