test: cleanup
This commit is contained in:
@@ -1258,68 +1258,66 @@ TEST_F(Any, ForwardAsAny) {
|
||||
}
|
||||
|
||||
TEST_F(Any, NotCopyableType) {
|
||||
auto test = [](entt::any any, entt::any other) {
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_TRUE(other);
|
||||
|
||||
ASSERT_TRUE(any.owner());
|
||||
ASSERT_FALSE(other.owner());
|
||||
ASSERT_EQ(any.type(), other.type());
|
||||
|
||||
ASSERT_FALSE(any.assign(other));
|
||||
ASSERT_FALSE(any.assign(std::move(other)));
|
||||
|
||||
entt::any copy{any};
|
||||
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_FALSE(copy);
|
||||
|
||||
ASSERT_TRUE(any.owner());
|
||||
ASSERT_TRUE(copy.owner());
|
||||
|
||||
copy = any;
|
||||
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_FALSE(copy);
|
||||
|
||||
ASSERT_TRUE(any.owner());
|
||||
ASSERT_TRUE(copy.owner());
|
||||
};
|
||||
|
||||
const not_copyable value{};
|
||||
test(entt::any{std::in_place_type<not_copyable>}, entt::forward_as_any(value));
|
||||
entt::any any{std::in_place_type<not_copyable>};
|
||||
entt::any other = entt::forward_as_any(value);
|
||||
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_TRUE(other);
|
||||
|
||||
ASSERT_TRUE(any.owner());
|
||||
ASSERT_FALSE(other.owner());
|
||||
ASSERT_EQ(any.type(), other.type());
|
||||
|
||||
ASSERT_FALSE(any.assign(other));
|
||||
ASSERT_FALSE(any.assign(std::move(other)));
|
||||
|
||||
entt::any copy{any};
|
||||
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_FALSE(copy);
|
||||
|
||||
ASSERT_TRUE(any.owner());
|
||||
ASSERT_TRUE(copy.owner());
|
||||
|
||||
copy = any;
|
||||
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_FALSE(copy);
|
||||
|
||||
ASSERT_TRUE(any.owner());
|
||||
ASSERT_TRUE(copy.owner());
|
||||
}
|
||||
|
||||
TEST_F(Any, NotMovableType) {
|
||||
auto test = [](entt::any any, entt::any other) {
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_TRUE(other);
|
||||
entt::any any{std::in_place_type<not_movable>};
|
||||
entt::any other{std::in_place_type<not_movable>};
|
||||
|
||||
ASSERT_TRUE(any.owner());
|
||||
ASSERT_TRUE(other.owner());
|
||||
ASSERT_EQ(any.type(), other.type());
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_TRUE(other);
|
||||
|
||||
ASSERT_TRUE(any.assign(other));
|
||||
ASSERT_TRUE(any.assign(std::move(other)));
|
||||
ASSERT_TRUE(any.owner());
|
||||
ASSERT_TRUE(other.owner());
|
||||
ASSERT_EQ(any.type(), other.type());
|
||||
|
||||
entt::any copy{any};
|
||||
ASSERT_TRUE(any.assign(other));
|
||||
ASSERT_TRUE(any.assign(std::move(other)));
|
||||
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_TRUE(copy);
|
||||
entt::any copy{any};
|
||||
|
||||
ASSERT_TRUE(any.owner());
|
||||
ASSERT_TRUE(copy.owner());
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_TRUE(copy);
|
||||
|
||||
copy = any;
|
||||
ASSERT_TRUE(any.owner());
|
||||
ASSERT_TRUE(copy.owner());
|
||||
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_TRUE(copy);
|
||||
copy = any;
|
||||
|
||||
ASSERT_TRUE(any.owner());
|
||||
ASSERT_TRUE(copy.owner());
|
||||
};
|
||||
ASSERT_TRUE(any);
|
||||
ASSERT_TRUE(copy);
|
||||
|
||||
test(entt::any{std::in_place_type<not_movable>}, entt::any{std::in_place_type<not_movable>});
|
||||
ASSERT_TRUE(any.owner());
|
||||
ASSERT_TRUE(copy.owner());
|
||||
}
|
||||
|
||||
TEST_F(Any, Array) {
|
||||
@@ -1390,28 +1388,36 @@ TEST_F(Any, SBOVsZeroedSBOSize) {
|
||||
ASSERT_EQ(valid, same.data());
|
||||
}
|
||||
|
||||
TEST_F(Any, Alignment) {
|
||||
TEST_F(Any, SboAlignment) {
|
||||
static constexpr auto alignment = alignof(over_aligned);
|
||||
|
||||
auto test = [](auto *target, auto cb) {
|
||||
const auto *data = target[0].data();
|
||||
|
||||
ASSERT_TRUE((reinterpret_cast<std::uintptr_t>(target[0u].data()) % alignment) == 0u);
|
||||
ASSERT_TRUE((reinterpret_cast<std::uintptr_t>(target[1u].data()) % alignment) == 0u);
|
||||
|
||||
std::swap(target[0], target[1]);
|
||||
|
||||
ASSERT_TRUE((reinterpret_cast<std::uintptr_t>(target[0u].data()) % alignment) == 0u);
|
||||
ASSERT_TRUE((reinterpret_cast<std::uintptr_t>(target[1u].data()) % alignment) == 0u);
|
||||
|
||||
cb(data, target[1].data());
|
||||
};
|
||||
|
||||
entt::basic_any<alignment> nosbo[2] = {over_aligned{}, over_aligned{}};
|
||||
test(nosbo, [](auto *pre, auto *post) { ASSERT_EQ(pre, post); });
|
||||
|
||||
entt::basic_any<alignment, alignment> sbo[2] = {over_aligned{}, over_aligned{}};
|
||||
test(sbo, [](auto *pre, auto *post) { ASSERT_NE(pre, post); });
|
||||
const auto *data = sbo[0].data();
|
||||
|
||||
ASSERT_TRUE((reinterpret_cast<std::uintptr_t>(sbo[0u].data()) % alignment) == 0u);
|
||||
ASSERT_TRUE((reinterpret_cast<std::uintptr_t>(sbo[1u].data()) % alignment) == 0u);
|
||||
|
||||
std::swap(sbo[0], sbo[1]);
|
||||
|
||||
ASSERT_TRUE((reinterpret_cast<std::uintptr_t>(sbo[0u].data()) % alignment) == 0u);
|
||||
ASSERT_TRUE((reinterpret_cast<std::uintptr_t>(sbo[1u].data()) % alignment) == 0u);
|
||||
|
||||
ASSERT_NE(data, sbo[1].data());
|
||||
}
|
||||
|
||||
TEST_F(Any, NoSboAlignment) {
|
||||
static constexpr auto alignment = alignof(over_aligned);
|
||||
entt::basic_any<alignment> nosbo[2] = {over_aligned{}, over_aligned{}};
|
||||
const auto *data = nosbo[0].data();
|
||||
|
||||
ASSERT_TRUE((reinterpret_cast<std::uintptr_t>(nosbo[0u].data()) % alignment) == 0u);
|
||||
ASSERT_TRUE((reinterpret_cast<std::uintptr_t>(nosbo[1u].data()) % alignment) == 0u);
|
||||
|
||||
std::swap(nosbo[0], nosbo[1]);
|
||||
|
||||
ASSERT_TRUE((reinterpret_cast<std::uintptr_t>(nosbo[0u].data()) % alignment) == 0u);
|
||||
ASSERT_TRUE((reinterpret_cast<std::uintptr_t>(nosbo[1u].data()) % alignment) == 0u);
|
||||
|
||||
ASSERT_EQ(data, nosbo[1].data());
|
||||
}
|
||||
|
||||
TEST_F(Any, AggregatesMustWork) {
|
||||
|
||||
@@ -784,26 +784,41 @@ TEST(SparseSetDeathTest, SwapEntity) {
|
||||
}
|
||||
|
||||
TEST(SparseSet, Clear) {
|
||||
auto test = [](auto set) {
|
||||
set.emplace(entt::entity{3});
|
||||
set.emplace(entt::entity{42});
|
||||
set.emplace(entt::entity{9});
|
||||
set.erase(entt::entity{42});
|
||||
entt::sparse_set set{entt::deletion_policy::in_place};
|
||||
|
||||
ASSERT_FALSE(set.empty());
|
||||
set.emplace(entt::entity{3});
|
||||
set.emplace(entt::entity{42});
|
||||
set.emplace(entt::entity{9});
|
||||
set.erase(entt::entity{42});
|
||||
|
||||
set.clear();
|
||||
ASSERT_FALSE(set.empty());
|
||||
ASSERT_EQ(set.size(), 3u);
|
||||
ASSERT_EQ(*set.begin(), entt::entity{9});
|
||||
|
||||
ASSERT_TRUE(set.empty());
|
||||
ASSERT_EQ(set.size(), 0u);
|
||||
set.clear();
|
||||
|
||||
ASSERT_EQ(set.find(entt::entity{3}), set.end());
|
||||
ASSERT_EQ(set.find(entt::entity{42}), set.end());
|
||||
ASSERT_EQ(set.find(entt::entity{9}), set.end());
|
||||
};
|
||||
ASSERT_TRUE(set.empty());
|
||||
ASSERT_EQ(set.size(), 0u);
|
||||
|
||||
test(entt::sparse_set{});
|
||||
test(entt::sparse_set{entt::deletion_policy::in_place});
|
||||
ASSERT_EQ(set.find(entt::entity{3}), set.end());
|
||||
ASSERT_EQ(set.find(entt::entity{9}), set.end());
|
||||
|
||||
set.emplace(entt::entity{3});
|
||||
set.emplace(entt::entity{42});
|
||||
set.emplace(entt::entity{9});
|
||||
|
||||
ASSERT_FALSE(set.empty());
|
||||
ASSERT_EQ(set.size(), 3u);
|
||||
ASSERT_EQ(*set.begin(), entt::entity{9});
|
||||
|
||||
set.clear();
|
||||
|
||||
ASSERT_TRUE(set.empty());
|
||||
ASSERT_EQ(set.size(), 0u);
|
||||
|
||||
ASSERT_EQ(set.find(entt::entity{3}), set.end());
|
||||
ASSERT_EQ(set.find(entt::entity{42}), set.end());
|
||||
ASSERT_EQ(set.find(entt::entity{9}), set.end());
|
||||
}
|
||||
|
||||
TEST(SparseSet, Iterator) {
|
||||
|
||||
@@ -324,17 +324,15 @@ TEST(SingleComponentView, Find) {
|
||||
|
||||
TEST(SingleComponentView, EmptyTypes) {
|
||||
entt::registry registry;
|
||||
auto create = [&](auto... component) {
|
||||
const auto entt = registry.create();
|
||||
(registry.emplace<decltype(component)>(entt, component), ...);
|
||||
return entt;
|
||||
};
|
||||
entt::entity entities[2u];
|
||||
|
||||
const auto entity = create(0, empty_type{});
|
||||
create('c');
|
||||
registry.create(std::begin(entities), std::end(entities));
|
||||
registry.emplace<int>(entities[0u], 0);
|
||||
registry.emplace<empty_type>(entities[0u]);
|
||||
registry.emplace<char>(entities[1u], 'c');
|
||||
|
||||
registry.view<empty_type>().each([entity](const auto entt) {
|
||||
ASSERT_EQ(entity, entt);
|
||||
registry.view<empty_type>().each([&](const auto entt) {
|
||||
ASSERT_EQ(entities[0u], entt);
|
||||
});
|
||||
|
||||
registry.view<empty_type>().each([check = true]() mutable {
|
||||
@@ -344,11 +342,11 @@ TEST(SingleComponentView, EmptyTypes) {
|
||||
|
||||
for(auto [entt]: registry.view<empty_type>().each()) {
|
||||
static_assert(std::is_same_v<decltype(entt), entt::entity>);
|
||||
ASSERT_EQ(entity, entt);
|
||||
ASSERT_EQ(entities[0u], entt);
|
||||
}
|
||||
|
||||
registry.view<int>().each([entity](const auto entt, int) {
|
||||
ASSERT_EQ(entity, entt);
|
||||
registry.view<int>().each([&](const auto entt, int) {
|
||||
ASSERT_EQ(entities[0u], entt);
|
||||
});
|
||||
|
||||
registry.view<int>().each([check = true](int) mutable {
|
||||
@@ -359,7 +357,7 @@ TEST(SingleComponentView, EmptyTypes) {
|
||||
for(auto [entt, iv]: registry.view<int>().each()) {
|
||||
static_assert(std::is_same_v<decltype(entt), entt::entity>);
|
||||
static_assert(std::is_same_v<decltype(iv), int &>);
|
||||
ASSERT_EQ(entity, entt);
|
||||
ASSERT_EQ(entities[0u], entt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -131,6 +131,22 @@ struct MetaFunc: ::testing::Test {
|
||||
void TearDown() override {
|
||||
entt::meta_reset();
|
||||
}
|
||||
|
||||
std::size_t reset_and_check() {
|
||||
std::size_t count = 0;
|
||||
|
||||
for(auto func: entt::resolve<func_t>().func()) {
|
||||
count += static_cast<bool>(func);
|
||||
}
|
||||
|
||||
SetUp();
|
||||
|
||||
for(auto func: entt::resolve<func_t>().func()) {
|
||||
count -= static_cast<bool>(func);
|
||||
}
|
||||
|
||||
return count;
|
||||
};
|
||||
};
|
||||
|
||||
using MetaFuncDeathTest = MetaFunc;
|
||||
@@ -567,23 +583,7 @@ TEST_F(MetaFunc, ExternalMemberFunction) {
|
||||
TEST_F(MetaFunc, ReRegistration) {
|
||||
using namespace entt::literals;
|
||||
|
||||
auto reset_and_check = [this]() {
|
||||
int count = 0;
|
||||
|
||||
for(auto func: entt::resolve<func_t>().func()) {
|
||||
count += static_cast<bool>(func);
|
||||
}
|
||||
|
||||
SetUp();
|
||||
|
||||
for(auto func: entt::resolve<func_t>().func()) {
|
||||
count -= static_cast<bool>(func);
|
||||
}
|
||||
|
||||
ASSERT_EQ(count, 0);
|
||||
};
|
||||
|
||||
reset_and_check();
|
||||
ASSERT_EQ(reset_and_check(), 0u);
|
||||
|
||||
func_t instance{};
|
||||
auto type = entt::resolve<func_t>();
|
||||
@@ -607,5 +607,5 @@ TEST_F(MetaFunc, ReRegistration) {
|
||||
ASSERT_TRUE(type.invoke("f"_hs, instance, 0));
|
||||
ASSERT_TRUE(type.invoke("f"_hs, instance, 0, 0));
|
||||
|
||||
reset_and_check();
|
||||
ASSERT_EQ(reset_and_check(), 0u);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user