|
|
@@ -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);
|
|
|
+ const not_copyable value{};
|
|
|
+ entt::any any{std::in_place_type<not_copyable>};
|
|
|
+ entt::any other = entt::forward_as_any(value);
|
|
|
|
|
|
- ASSERT_TRUE(any.owner());
|
|
|
- ASSERT_FALSE(other.owner());
|
|
|
- ASSERT_EQ(any.type(), other.type());
|
|
|
+ ASSERT_TRUE(any);
|
|
|
+ ASSERT_TRUE(other);
|
|
|
|
|
|
- ASSERT_FALSE(any.assign(other));
|
|
|
- ASSERT_FALSE(any.assign(std::move(other)));
|
|
|
+ ASSERT_TRUE(any.owner());
|
|
|
+ ASSERT_FALSE(other.owner());
|
|
|
+ ASSERT_EQ(any.type(), other.type());
|
|
|
|
|
|
- entt::any copy{any};
|
|
|
+ ASSERT_FALSE(any.assign(other));
|
|
|
+ ASSERT_FALSE(any.assign(std::move(other)));
|
|
|
|
|
|
- ASSERT_TRUE(any);
|
|
|
- ASSERT_FALSE(copy);
|
|
|
+ entt::any copy{any};
|
|
|
|
|
|
- ASSERT_TRUE(any.owner());
|
|
|
- ASSERT_TRUE(copy.owner());
|
|
|
+ ASSERT_TRUE(any);
|
|
|
+ ASSERT_FALSE(copy);
|
|
|
|
|
|
- copy = any;
|
|
|
+ ASSERT_TRUE(any.owner());
|
|
|
+ ASSERT_TRUE(copy.owner());
|
|
|
|
|
|
- ASSERT_TRUE(any);
|
|
|
- ASSERT_FALSE(copy);
|
|
|
+ copy = any;
|
|
|
|
|
|
- ASSERT_TRUE(any.owner());
|
|
|
- ASSERT_TRUE(copy.owner());
|
|
|
- };
|
|
|
+ ASSERT_TRUE(any);
|
|
|
+ ASSERT_FALSE(copy);
|
|
|
|
|
|
- const not_copyable value{};
|
|
|
- test(entt::any{std::in_place_type<not_copyable>}, entt::forward_as_any(value));
|
|
|
+ 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);
|
|
|
+ entt::basic_any<alignment, alignment> sbo[2] = {over_aligned{}, over_aligned{}};
|
|
|
+ const auto *data = sbo[0].data();
|
|
|
|
|
|
- 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);
|
|
|
+ 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(target[0], target[1]);
|
|
|
+ std::swap(sbo[0], sbo[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);
|
|
|
+ ASSERT_TRUE((reinterpret_cast<std::uintptr_t>(sbo[0u].data()) % alignment) == 0u);
|
|
|
+ ASSERT_TRUE((reinterpret_cast<std::uintptr_t>(sbo[1u].data()) % alignment) == 0u);
|
|
|
|
|
|
- cb(data, target[1].data());
|
|
|
- };
|
|
|
+ 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{}};
|
|
|
- test(nosbo, [](auto *pre, auto *post) { ASSERT_EQ(pre, post); });
|
|
|
+ const auto *data = nosbo[0].data();
|
|
|
|
|
|
- entt::basic_any<alignment, alignment> sbo[2] = {over_aligned{}, over_aligned{}};
|
|
|
- test(sbo, [](auto *pre, auto *post) { ASSERT_NE(pre, post); });
|
|
|
+ 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) {
|