Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Feb 27, 2018
1 parent 7b82a4a commit e822a5f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
18 changes: 15 additions & 3 deletions test/entt/core/hashed_string.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
#include <cstddef>
#include <gtest/gtest.h>
#include <entt/core/hashed_string.hpp>

constexpr bool check(const char *str) {
constexpr bool ptr(const char *str) {
using hash_type = entt::HashedString::hash_type;

return (static_cast<hash_type>(entt::HashedString{str}) == entt::HashedString{str}
&& static_cast<const char *>(entt::HashedString{str}) == str
&& entt::HashedString{str} == entt::HashedString{str}
&& !(entt::HashedString{str} != entt::HashedString{str}));
}

template<std::size_t N>
constexpr bool ref(const char (&str)[N]) {
using hash_type = entt::HashedString::hash_type;

return (static_cast<hash_type>(entt::HashedString{str}) == entt::HashedString{str}
Expand All @@ -12,7 +23,8 @@ constexpr bool check(const char *str) {

TEST(HashedString, Constexprness) {
// how would you test a constepxr otherwise?
static_assert(check("foobar"), "!");
static_assert(ptr("foo"), "!");
static_assert(ref("bar"), "!");
ASSERT_TRUE(true);
}

Expand All @@ -29,7 +41,7 @@ TEST(HashedString, Functionalities) {
ASSERT_EQ(static_cast<const char *>(barHs), bar);

ASSERT_TRUE(fooHs == fooHs);
ASSERT_FALSE(fooHs == barHs);
ASSERT_TRUE(fooHs != barHs);

entt::HashedString hs{"foobar"};

Expand Down
2 changes: 2 additions & 0 deletions test/entt/entity/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ TEST(DefaultRegistry, Functionalities) {

ASSERT_EQ(registry.size(), entt::DefaultRegistry::size_type{0});
ASSERT_NO_THROW(registry.reserve(42));
ASSERT_NO_THROW(registry.reserve<int>(8));
ASSERT_NO_THROW(registry.reserve<char>(8));
ASSERT_TRUE(registry.empty());

ASSERT_EQ(registry.capacity(), entt::DefaultRegistry::size_type{0});
Expand Down
2 changes: 2 additions & 0 deletions test/entt/resource/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ TEST(ResourceCache, Functionalities) {
ASSERT_FALSE(cache.contains(hs2));

ASSERT_FALSE(cache.load<BrokenLoader>(hs1, 42));
ASSERT_FALSE(cache.reload<BrokenLoader>(hs1, 42));

ASSERT_EQ(cache.size(), entt::ResourceCache<Resource>::size_type{});
ASSERT_TRUE(cache.empty());
ASSERT_FALSE(cache.contains(hs1));
ASSERT_FALSE(cache.contains(hs2));

ASSERT_TRUE(cache.load<Loader>(hs1, 42));
ASSERT_TRUE(cache.reload<Loader>(hs1, 42));

ASSERT_NE(cache.size(), entt::ResourceCache<Resource>::size_type{});
ASSERT_FALSE(cache.empty());
Expand Down
15 changes: 15 additions & 0 deletions test/entt/signal/sigh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ TEST(SigH, Clear) {
ASSERT_TRUE(sigh.empty());
}

TEST(SigH, Swap) {
entt::SigH<void(int &)> sigh1;
entt::SigH<void(int &)> sigh2;

sigh1.connect<&S::f>();

ASSERT_FALSE(sigh1.empty());
ASSERT_TRUE(sigh2.empty());

std::swap(sigh1, sigh2);

ASSERT_TRUE(sigh1.empty());
ASSERT_FALSE(sigh2.empty());
}

TEST(SigH, Functions) {
entt::SigH<void(int &)> sigh;
int v = 0;
Expand Down
15 changes: 15 additions & 0 deletions test/entt/signal/signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ TEST(Signal, Clear) {
ASSERT_TRUE(signal.empty());
}

TEST(Signal, Swap) {
entt::Signal<void(const int &)> sig1;
entt::Signal<void(const int &)> sig2;

sig1.connect<&S::f>();

ASSERT_FALSE(sig1.empty());
ASSERT_TRUE(sig2.empty());

std::swap(sig1, sig2);

ASSERT_TRUE(sig1.empty());
ASSERT_FALSE(sig2.empty());
}

TEST(Signal, Functions) {
entt::Signal<void(const int &)> signal;
auto val = S::i + 1;
Expand Down

0 comments on commit e822a5f

Please sign in to comment.