more tests
This commit is contained in:
@@ -474,7 +474,7 @@ class ContinuousLoader final {
|
||||
|
||||
each(archive, [&archive, member..., this](auto entity) {
|
||||
entity = restore(entity);
|
||||
auto &tag = registry.template attach<Tag>(entity);
|
||||
auto &tag = registry.template assign<Tag>(entt::tag_type_t{}, entity);
|
||||
archive(tag);
|
||||
|
||||
using accumulator_type = int[];
|
||||
|
||||
@@ -267,9 +267,7 @@ TEST(Snapshot, Continuous) {
|
||||
src.create();
|
||||
}
|
||||
|
||||
src.each([&src](auto entity) {
|
||||
src.destroy(entity);
|
||||
});
|
||||
src.reset();
|
||||
|
||||
for(int i = 0; i < 5; ++i) {
|
||||
entity = src.create();
|
||||
@@ -487,3 +485,54 @@ TEST(Snapshot, ContinuousMoreOnShrink) {
|
||||
|
||||
ASSERT_FALSE(dst.valid(entity));
|
||||
}
|
||||
|
||||
TEST(Snapshot, SyncDataMembers) {
|
||||
using entity_type = entt::DefaultRegistry::entity_type;
|
||||
|
||||
entt::DefaultRegistry src;
|
||||
entt::DefaultRegistry dst;
|
||||
|
||||
entt::ContinuousLoader<entity_type> loader{dst};
|
||||
|
||||
using storage_type = std::tuple<
|
||||
std::queue<entity_type>,
|
||||
std::queue<WhatAComponent>
|
||||
>;
|
||||
|
||||
storage_type storage;
|
||||
OutputArchive<storage_type> output{storage};
|
||||
InputArchive<storage_type> input{storage};
|
||||
|
||||
src.create();
|
||||
src.create();
|
||||
|
||||
src.reset();
|
||||
|
||||
auto parent = src.create();
|
||||
auto child = src.create();
|
||||
|
||||
src.assign<WhatAComponent>(entt::tag_type_t{}, child, parent).quux.push_back(parent);
|
||||
src.assign<WhatAComponent>(child, child).quux.push_back(child);
|
||||
|
||||
src.snapshot().entities(output)
|
||||
.component<WhatAComponent>(output)
|
||||
.tag<WhatAComponent>(output);
|
||||
|
||||
loader.entities(input)
|
||||
.component<WhatAComponent>(input, &WhatAComponent::bar, &WhatAComponent::quux)
|
||||
.tag<WhatAComponent>(input, &WhatAComponent::bar, &WhatAComponent::quux);
|
||||
|
||||
ASSERT_FALSE(dst.valid(parent));
|
||||
ASSERT_FALSE(dst.valid(child));
|
||||
|
||||
ASSERT_TRUE(dst.has<WhatAComponent>());
|
||||
ASSERT_EQ(dst.attachee<WhatAComponent>(), loader.map(child));
|
||||
ASSERT_EQ(dst.get<WhatAComponent>().bar, loader.map(parent));
|
||||
ASSERT_EQ(dst.get<WhatAComponent>().quux[0], loader.map(parent));
|
||||
ASSERT_TRUE(dst.has<WhatAComponent>(loader.map(child)));
|
||||
|
||||
const auto &component = dst.get<WhatAComponent>(loader.map(child));
|
||||
|
||||
ASSERT_EQ(component.bar, loader.map(child));
|
||||
ASSERT_EQ(component.quux[0], loader.map(child));
|
||||
}
|
||||
|
||||
@@ -79,6 +79,15 @@ TEST(SparseSetNoType, DataBeginEnd) {
|
||||
ASSERT_EQ(*(begin++), 3u);
|
||||
|
||||
ASSERT_EQ(begin, end);
|
||||
|
||||
auto cbegin = set.cbegin();
|
||||
auto cend = set.cend();
|
||||
|
||||
ASSERT_NE(cbegin, cend);
|
||||
ASSERT_EQ(cbegin+3, cend);
|
||||
ASSERT_NE(cbegin, cend);
|
||||
ASSERT_EQ(cbegin += 3, cend);
|
||||
ASSERT_EQ(cbegin, cend);
|
||||
}
|
||||
|
||||
TEST(SparseSetNoType, RespectDisjoint) {
|
||||
@@ -324,6 +333,15 @@ TEST(SparseSetWithType, RawBeginEnd) {
|
||||
ASSERT_EQ(*(begin++), 6);
|
||||
ASSERT_EQ(*(begin++), 3);
|
||||
ASSERT_EQ(begin, end);
|
||||
|
||||
auto cbegin = set.cbegin();
|
||||
auto cend = set.cend();
|
||||
|
||||
ASSERT_NE(cbegin, cend);
|
||||
ASSERT_EQ(cbegin+3, cend);
|
||||
ASSERT_NE(cbegin, cend);
|
||||
ASSERT_EQ(cbegin += 3, cend);
|
||||
ASSERT_EQ(cbegin, cend);
|
||||
}
|
||||
|
||||
TEST(SparseSetWithType, SortOrdered) {
|
||||
|
||||
@@ -46,6 +46,37 @@ TEST(View, SingleComponent) {
|
||||
ASSERT_TRUE(view.empty());
|
||||
}
|
||||
|
||||
TEST(View, SingleComponentBeginEnd) {
|
||||
entt::DefaultRegistry registry;
|
||||
auto view = registry.view<int>();
|
||||
|
||||
for(auto i = 0; i < 3; ++i) {
|
||||
registry.assign<int>(registry.create());
|
||||
}
|
||||
|
||||
auto begin = view.begin();
|
||||
auto end = view.end();
|
||||
|
||||
ASSERT_NE(begin, end);
|
||||
ASSERT_NE(++begin, end);
|
||||
ASSERT_NE(begin++, end);
|
||||
ASSERT_EQ(begin+1, end);
|
||||
ASSERT_NE(begin, end);
|
||||
ASSERT_EQ((begin += 1), end);
|
||||
ASSERT_EQ(begin, end);
|
||||
|
||||
auto cbegin = view.cbegin();
|
||||
auto cend = view.cend();
|
||||
|
||||
ASSERT_NE(cbegin, cend);
|
||||
ASSERT_NE(++cbegin, cend);
|
||||
ASSERT_NE(cbegin++, cend);
|
||||
ASSERT_EQ(cbegin+1, cend);
|
||||
ASSERT_NE(cbegin, cend);
|
||||
ASSERT_EQ((cbegin += 1), cend);
|
||||
ASSERT_EQ(cbegin, cend);
|
||||
}
|
||||
|
||||
TEST(View, SingleComponentContains) {
|
||||
entt::DefaultRegistry registry;
|
||||
|
||||
@@ -86,13 +117,8 @@ TEST(View, SingleComponentEmpty) {
|
||||
TEST(View, SingleComponentEach) {
|
||||
entt::DefaultRegistry registry;
|
||||
|
||||
const auto e0 = registry.create();
|
||||
registry.assign<int>(e0);
|
||||
registry.assign<char>(e0);
|
||||
|
||||
const auto e1 = registry.create();
|
||||
registry.assign<int>(e1);
|
||||
registry.assign<char>(e1);
|
||||
registry.assign<int>(registry.create());
|
||||
registry.assign<int>(registry.create());
|
||||
|
||||
auto view = registry.view<int>();
|
||||
const auto &cview = static_cast<const decltype(view) &>(view);
|
||||
@@ -155,6 +181,39 @@ TEST(View, MultipleComponent) {
|
||||
ASSERT_TRUE(view.empty());
|
||||
}
|
||||
|
||||
TEST(View, MultipleComponentBeginEnd) {
|
||||
entt::DefaultRegistry registry;
|
||||
auto view = registry.view<int, char>();
|
||||
|
||||
for(auto i = 0; i < 3; ++i) {
|
||||
const auto entity = registry.create();
|
||||
registry.assign<int>(entity);
|
||||
registry.assign<char>(entity);
|
||||
}
|
||||
|
||||
auto begin = view.begin();
|
||||
auto end = view.end();
|
||||
|
||||
ASSERT_NE(begin, end);
|
||||
ASSERT_NE(++begin, end);
|
||||
ASSERT_NE(begin++, end);
|
||||
ASSERT_EQ(begin+1, end);
|
||||
ASSERT_NE(begin, end);
|
||||
ASSERT_EQ((begin += 1), end);
|
||||
ASSERT_EQ(begin, end);
|
||||
|
||||
auto cbegin = view.cbegin();
|
||||
auto cend = view.cend();
|
||||
|
||||
ASSERT_NE(cbegin, cend);
|
||||
ASSERT_NE(++cbegin, cend);
|
||||
ASSERT_NE(cbegin++, cend);
|
||||
ASSERT_EQ(cbegin+1, cend);
|
||||
ASSERT_NE(cbegin, cend);
|
||||
ASSERT_EQ((cbegin += 1), cend);
|
||||
ASSERT_EQ(cbegin, cend);
|
||||
}
|
||||
|
||||
TEST(View, MultipleComponentContains) {
|
||||
entt::DefaultRegistry registry;
|
||||
|
||||
@@ -315,6 +374,39 @@ TEST(PersistentView, NoPrepare) {
|
||||
ASSERT_TRUE(view.empty());
|
||||
}
|
||||
|
||||
TEST(PersistentView, BeginEnd) {
|
||||
entt::DefaultRegistry registry;
|
||||
auto view = registry.persistent<int, char>();
|
||||
|
||||
for(auto i = 0; i < 3; ++i) {
|
||||
const auto entity = registry.create();
|
||||
registry.assign<int>(entity);
|
||||
registry.assign<char>(entity);
|
||||
}
|
||||
|
||||
auto begin = view.begin();
|
||||
auto end = view.end();
|
||||
|
||||
ASSERT_NE(begin, end);
|
||||
ASSERT_NE(++begin, end);
|
||||
ASSERT_NE(begin++, end);
|
||||
ASSERT_EQ(begin+1, end);
|
||||
ASSERT_NE(begin, end);
|
||||
ASSERT_EQ((begin += 1), end);
|
||||
ASSERT_EQ(begin, end);
|
||||
|
||||
auto cbegin = view.cbegin();
|
||||
auto cend = view.cend();
|
||||
|
||||
ASSERT_NE(cbegin, cend);
|
||||
ASSERT_NE(++cbegin, cend);
|
||||
ASSERT_NE(cbegin++, cend);
|
||||
ASSERT_EQ(cbegin+1, cend);
|
||||
ASSERT_NE(cbegin, cend);
|
||||
ASSERT_EQ((cbegin += 1), cend);
|
||||
ASSERT_EQ(cbegin, cend);
|
||||
}
|
||||
|
||||
TEST(PersistentView, Contains) {
|
||||
entt::DefaultRegistry registry;
|
||||
|
||||
@@ -488,3 +580,22 @@ TEST(RawView, Empty) {
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(RawView, Each) {
|
||||
entt::DefaultRegistry registry;
|
||||
|
||||
registry.assign<int>(registry.create(), 1);
|
||||
registry.assign<int>(registry.create(), 3);
|
||||
|
||||
auto view = registry.raw<int>();
|
||||
const auto &cview = static_cast<const decltype(view) &>(view);
|
||||
std::size_t cnt = 0;
|
||||
|
||||
view.each([&cnt](int &v) { cnt += (v % 2); });
|
||||
|
||||
ASSERT_EQ(cnt, std::size_t{2});
|
||||
|
||||
cview.each([&cnt](const int &v) { cnt -= (v % 2); });
|
||||
|
||||
ASSERT_EQ(cnt, std::size_t{0});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user