-
-
Notifications
You must be signed in to change notification settings - Fork 870
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include <unordered_set> | ||
#include <gtest/gtest.h> | ||
#include <entt/entity/attachee.hpp> | ||
|
||
TEST(AttacheeNoType, Functionalities) { | ||
entt::Attachee<std::uint64_t> attachee; | ||
|
||
attachee.construct(42u); | ||
|
||
ASSERT_EQ(attachee.get(), 42u); | ||
|
||
attachee.destroy(); | ||
|
||
ASSERT_NE(attachee.get(), 42u); | ||
|
||
(void)entt::Attachee<std::uint64_t>{std::move(attachee)}; | ||
entt::Attachee<std::uint64_t> other; | ||
other = std::move(attachee); | ||
} | ||
|
||
TEST(AttacheeWithType, Functionalities) { | ||
entt::Attachee<std::uint64_t, int> attachee; | ||
const auto &cattachee = attachee; | ||
|
||
attachee.construct(42u, 3); | ||
|
||
ASSERT_EQ(attachee.get(), 3); | ||
ASSERT_EQ(cattachee.get(), 3); | ||
ASSERT_EQ(attachee.Attachee<std::uint64_t>::get(), 42u); | ||
|
||
attachee.move(0u); | ||
|
||
ASSERT_EQ(attachee.get(), 3); | ||
ASSERT_EQ(cattachee.get(), 3); | ||
ASSERT_EQ(attachee.Attachee<std::uint64_t>::get(), 0u); | ||
|
||
attachee.destroy(); | ||
|
||
ASSERT_NE(attachee.Attachee<std::uint64_t>::get(), 0u); | ||
ASSERT_NE(attachee.Attachee<std::uint64_t>::get(), 42u); | ||
} | ||
|
||
TEST(AttacheeWithType, AggregatesMustWork) { | ||
struct AggregateType { int value; }; | ||
// the goal of this test is to enforce the requirements for aggregate types | ||
entt::Attachee<std::uint64_t, AggregateType>{}.construct(0, 42); | ||
} | ||
|
||
TEST(AttacheeWithType, TypesFromStandardTemplateLibraryMustWork) { | ||
// see #37 - this test shouldn't crash, that's all | ||
entt::Attachee<std::uint64_t, std::unordered_set<int>> attachee; | ||
attachee.construct(0).insert(42); | ||
attachee.destroy(); | ||
} | ||
|
||
TEST(AttacheeWithType, MoveOnlyComponent) { | ||
struct MoveOnlyComponent { | ||
MoveOnlyComponent() = default; | ||
~MoveOnlyComponent() = default; | ||
MoveOnlyComponent(const MoveOnlyComponent &) = delete; | ||
MoveOnlyComponent(MoveOnlyComponent &&) = default; | ||
MoveOnlyComponent & operator=(const MoveOnlyComponent &) = delete; | ||
MoveOnlyComponent & operator=(MoveOnlyComponent &&) = default; | ||
}; | ||
|
||
// it's purpose is to ensure that move only components are always accepted | ||
entt::Attachee<std::uint64_t, MoveOnlyComponent> attachee; | ||
(void)attachee; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters