operator accessories for component wrappers

This commit is contained in:
2019-05-14 12:42:38 +07:00
parent c08d4995f6
commit d7456c4228
3 changed files with 107 additions and 0 deletions

View File

@@ -29,4 +29,11 @@ add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES})
target_link_libraries(${PROJECT_NAME}
Catch2
ecs.hpp)
target_compile_options(${PROJECT_NAME}
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:
/W4>
PRIVATE
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
-Wall -Wextra -Wpedantic>)
add_test(${PROJECT_NAME} ${PROJECT_NAME})

View File

@@ -518,6 +518,54 @@ TEST_CASE("registry") {
REQUIRE_FALSE(c1.remove());
}
{
using namespace ecs::detail;
ecs::registry w;
ecs::entity e1 = w.create_entity();
ecs::component<position_c> c1 = w.wrap_component<position_c>(e1);
ecs::const_component<position_c> c2 = w.wrap_component<position_c>(e1);
REQUIRE_FALSE(c1);
REQUIRE_FALSE(as_const(c1));
REQUIRE_FALSE(c2);
REQUIRE_FALSE(as_const(c2));
REQUIRE_THROWS_AS(*c1, std::logic_error);
REQUIRE_THROWS_AS(*as_const(c1), std::logic_error);
REQUIRE_THROWS_AS(*c2, std::logic_error);
REQUIRE_THROWS_AS(*as_const(c2), std::logic_error);
c1.assign(1,2);
REQUIRE(c1);
REQUIRE(as_const(c1));
REQUIRE(c2);
REQUIRE(as_const(c2));
REQUIRE(*c1 == position_c(1,2));
REQUIRE(*as_const(c1) == position_c(1,2));
REQUIRE(*c2 == position_c(1,2));
REQUIRE(*as_const(c2) == position_c(1,2));
REQUIRE(c1->x == 1);
REQUIRE(c1->y == 2);
REQUIRE(as_const(c1)->x == 1);
REQUIRE(as_const(c1)->y == 2);
REQUIRE(c2->x == 1);
REQUIRE(c2->y == 2);
REQUIRE(as_const(c2)->x == 1);
REQUIRE(as_const(c2)->y == 2);
c1.remove();
REQUIRE_FALSE(c1);
REQUIRE_FALSE(as_const(c1));
REQUIRE_FALSE(c2);
REQUIRE_FALSE(as_const(c2));
}
}
SECTION("prototypes") {
{