WIP: tests + bug fixing

This commit is contained in:
Michele Caini
2017-09-08 15:34:54 +02:00
parent ed98ae3e70
commit 63c1b046e0
5 changed files with 55 additions and 3 deletions

View File

@@ -6,7 +6,7 @@ include(ExternalProject)
ExternalProject_Add(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
GIT_TAG release-1.8.0
DOWNLOAD_DIR ${GOOGLETEST_DEPS_DIR}
TMP_DIR ${GOOGLETEST_DEPS_DIR}/tmp
STAMP_DIR ${GOOGLETEST_DEPS_DIR}/stamp

View File

@@ -224,7 +224,6 @@ public:
void swap(index_type lhs, index_type rhs) {
std::swap(instances[SparseSet<Index>::get(lhs)], instances[SparseSet<Index>::get(rhs)]);
SparseSet<Index>::swap(lhs, rhs);
}
template<typename Compare>

View File

@@ -11,7 +11,7 @@ set(TARGET_BENCHMARK benchmark)
# Test TARGET_ENTT
add_executable(${TARGET_ENTT} registry.cpp sparse_set.cpp tag_handler.cpp)
add_executable(${TARGET_ENTT} ident.cpp registry.cpp sparse_set.cpp tag_handler.cpp)
target_include_directories(${TARGET_ENTT} PRIVATE ${PROJECT_SRC_DIR})
target_link_libraries(${TARGET_ENTT} PRIVATE ${COMMON_LINK_LIBS})
add_test(NAME ${TARGET_ENTT} COMMAND ${TARGET_ENTT})

26
test/ident.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include <gtest/gtest.h>
#include <ident.hpp>
struct A {};
struct B {};
TEST(Identifier, Uniqueness) {
constexpr auto ID = entt::ident<A, B>;
constexpr A a;
constexpr B b;
ASSERT_NE(ID.get<A>(), ID.get<B>());
ASSERT_EQ(ID.get<A>(), ID.get<decltype(a)>());
ASSERT_NE(ID.get<A>(), ID.get<decltype(b)>());
ASSERT_EQ(ID.get<A>(), ID.get<A>());
ASSERT_EQ(ID.get<B>(), ID.get<B>());
// test uses in constant expressions
switch(ID.get<B>()) {
case ID.get<A>():
FAIL();
break;
case ID.get<B>():
SUCCEED();
}
}

View File

@@ -149,6 +149,33 @@ TEST(DefaultRegistry, Copy) {
registry.reset();
}
TEST(DefaultRegistry, Swap) {
using registry_type = entt::DefaultRegistry<int, char>;
registry_type registry;
registry_type::entity_type e1 = registry.create<int, char>();
registry_type::entity_type e2 = registry.create<int, char>();
registry.get<int>(e1) = 0;
registry.get<char>(e1) = 'a';
registry.get<int>(e2) = 1;
registry.get<char>(e2) = 'b';
registry.swap<int>(e1, e2);
ASSERT_EQ(registry.get<int>(e1), 1);
ASSERT_EQ(registry.get<char>(e1), 'a');
ASSERT_EQ(registry.get<int>(e2), 0);
ASSERT_EQ(registry.get<char>(e2), 'b');
registry.reset();
}
TEST(DefaultRegistry, Sort) {
// TODO
}
TEST(DefaultRegistry, ViewSingleComponent) {
using registry_type = entt::DefaultRegistry<int, char>;