Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Aug 28, 2018
1 parent a0a1f70 commit ea8be64
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/entt/entity/attachee.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ class Attachee<Entity> {
: owner{null}
{}

/*! @brief Default copy constructor. */
Attachee(const Attachee &) = default;
/*! @brief Default move constructor. */
Attachee(Attachee &&) = default;

/*! @brief Default copy assignment operator. @return This attachee. */
Attachee & operator=(const Attachee &) = default;
/*! @brief Default move assignment operator. @return This attachee. */
Attachee & operator=(Attachee &&) = default;

/*! @brief Default destructor. */
virtual ~Attachee() ENTT_NOEXCEPT = default;

Expand Down Expand Up @@ -108,6 +118,18 @@ class Attachee<Entity, Type>: public Attachee<Entity> {
/*! @brief Underlying entity identifier. */
using entity_type = typename underlying_type::entity_type;

using Attachee<Entity>::Attachee;

/*! @brief Copying an attachee isn't allowed. */
Attachee(const Attachee &) = delete;
/*! @brief Moving an attachee isn't allowed. */
Attachee(Attachee &&) = delete;

/*! @brief Copying an attachee isn't allowed. @return This attachee. */
Attachee & operator=(const Attachee &) = delete;
/*! @brief Moving an attachee isn't allowed. @return This attachee. */
Attachee & operator=(Attachee &&) = delete;

/*! @brief Default destructor. */
~Attachee() {
if(underlying_type::get() != null) {
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ SETUP_AND_ADD_TEST(monostate entt/core/monostate.cpp)
# Test entity

SETUP_AND_ADD_TEST(actor entt/entity/actor.cpp)
SETUP_AND_ADD_TEST(attachee entt/entity/attachee.cpp)
SETUP_AND_ADD_TEST(entity entt/entity/entity.cpp)
SETUP_AND_ADD_TEST(helper entt/entity/helper.cpp)
SETUP_AND_ADD_TEST(prototype entt/entity/prototype.cpp)
Expand Down
69 changes: 69 additions & 0 deletions test/entt/entity/attachee.cpp
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;
}
4 changes: 2 additions & 2 deletions test/entt/entity/sparse_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ TEST(SparseSetWithType, Functionalities) {
ASSERT_FALSE(set.has(0));
ASSERT_FALSE(set.has(42));

(void)entt::SparseSet<std::uint64_t>{std::move(set)};
entt::SparseSet<std::uint64_t> other;
(void)entt::SparseSet<std::uint64_t, int>{std::move(set)};
entt::SparseSet<std::uint64_t, int> other;
other = std::move(set);
}

Expand Down

0 comments on commit ea8be64

Please sign in to comment.