Skip to content

Commit

Permalink
test: continue the internal rework
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Nov 17, 2023
1 parent 8372292 commit c785260
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
9 changes: 3 additions & 6 deletions test/entt/common/throwing_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@

namespace test {

class throwing_type {
struct test_exception {};

public:
using exception_type = test_exception;
struct throwing_type_exception {};

struct throwing_type {
throwing_type(bool mode)
: trigger{mode} {}

throwing_type(const throwing_type &other)
: trigger{other.trigger} {
if(trigger) {
throw exception_type{};
throw throwing_type_exception{};
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/entt/core/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ TEST(AllocateUnique, Functionalities) {
test::throwing_allocator<test::throwing_type>::trigger_on_allocate = true;

ASSERT_THROW((entt::allocate_unique<test::throwing_type>(allocator, false)), test::throwing_allocator<test::throwing_type>::exception_type);
ASSERT_THROW((entt::allocate_unique<test::throwing_type>(allocator, test::throwing_type{true})), test::throwing_type::exception_type);

ASSERT_THROW((entt::allocate_unique<test::throwing_type>(allocator, test::throwing_type{true})), test::throwing_type_exception);

std::unique_ptr<test::throwing_type, entt::allocation_deleter<test::throwing_allocator<test::throwing_type>>> ptr = entt::allocate_unique<test::throwing_type>(allocator, false);

Expand Down
10 changes: 5 additions & 5 deletions test/entt/entity/sigh_mixin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,21 +559,21 @@ TEST(SighMixin, ThrowingComponent) {
const test::throwing_type value[2u]{true, false};

// strong exception safety
ASSERT_THROW(pool.emplace(entity[0u], value[0u]), typename test::throwing_type::exception_type);
ASSERT_THROW(pool.emplace(entity[0u], value[0u]), test::throwing_type_exception);
ASSERT_TRUE(pool.empty());

// basic exception safety
ASSERT_THROW(pool.insert(std::begin(entity), std::end(entity), value[0u]), typename test::throwing_type::exception_type);
ASSERT_THROW(pool.insert(std::begin(entity), std::end(entity), value[0u]), test::throwing_type_exception);
ASSERT_EQ(pool.size(), 0u);
ASSERT_FALSE(pool.contains(entity[1u]));

// basic exception safety
ASSERT_THROW(pool.insert(std::begin(entity), std::end(entity), std::begin(value)), typename test::throwing_type::exception_type);
ASSERT_THROW(pool.insert(std::begin(entity), std::end(entity), std::begin(value)), test::throwing_type_exception);
ASSERT_EQ(pool.size(), 0u);
ASSERT_FALSE(pool.contains(entity[1u]));

// basic exception safety
ASSERT_THROW(pool.insert(std::rbegin(entity), std::rend(entity), std::rbegin(value)), typename test::throwing_type::exception_type);
ASSERT_THROW(pool.insert(std::rbegin(entity), std::rend(entity), std::rbegin(value)), test::throwing_type_exception);
ASSERT_EQ(pool.size(), 1u);
ASSERT_TRUE(pool.contains(entity[1u]));
ASSERT_EQ(pool.get(entity[1u]), value[1u]);
Expand All @@ -583,7 +583,7 @@ TEST(SighMixin, ThrowingComponent) {
pool.emplace(entity[0u], value[1u].throw_on_copy());

// basic exception safety
ASSERT_THROW(pool.erase(entity[1u]), typename test::throwing_type::exception_type);
ASSERT_THROW(pool.erase(entity[1u]), test::throwing_type_exception);
ASSERT_EQ(pool.size(), 2u);
ASSERT_TRUE(pool.contains(entity[0u]));
ASSERT_TRUE(pool.contains(entity[1u]));
Expand Down
10 changes: 5 additions & 5 deletions test/entt/entity/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1803,21 +1803,21 @@ TEST(Storage, ThrowingComponent) {
const test::throwing_type value[2u]{true, false};

// strong exception safety
ASSERT_THROW(pool.emplace(entity[0u], value[0u]), typename test::throwing_type::exception_type);
ASSERT_THROW(pool.emplace(entity[0u], value[0u]), test::throwing_type_exception);
ASSERT_TRUE(pool.empty());

// basic exception safety
ASSERT_THROW(pool.insert(std::begin(entity), std::end(entity), value[0u]), typename test::throwing_type::exception_type);
ASSERT_THROW(pool.insert(std::begin(entity), std::end(entity), value[0u]), test::throwing_type_exception);
ASSERT_EQ(pool.size(), 0u);
ASSERT_FALSE(pool.contains(entity[1u]));

// basic exception safety
ASSERT_THROW(pool.insert(std::begin(entity), std::end(entity), std::begin(value)), typename test::throwing_type::exception_type);
ASSERT_THROW(pool.insert(std::begin(entity), std::end(entity), std::begin(value)), test::throwing_type_exception);
ASSERT_EQ(pool.size(), 0u);
ASSERT_FALSE(pool.contains(entity[1u]));

// basic exception safety
ASSERT_THROW(pool.insert(std::rbegin(entity), std::rend(entity), std::rbegin(value)), typename test::throwing_type::exception_type);
ASSERT_THROW(pool.insert(std::rbegin(entity), std::rend(entity), std::rbegin(value)), test::throwing_type_exception);
ASSERT_EQ(pool.size(), 1u);
ASSERT_TRUE(pool.contains(entity[1u]));
ASSERT_EQ(pool.get(entity[1u]), value[1u]);
Expand All @@ -1827,7 +1827,7 @@ TEST(Storage, ThrowingComponent) {
pool.emplace(entity[0u], value[1u].throw_on_copy());

// basic exception safety
ASSERT_THROW(pool.erase(entity[1u]), typename test::throwing_type::exception_type);
ASSERT_THROW(pool.erase(entity[1u]), test::throwing_type_exception);
ASSERT_EQ(pool.size(), 2u);
ASSERT_TRUE(pool.contains(entity[0u]));
ASSERT_TRUE(pool.contains(entity[1u]));
Expand Down

0 comments on commit c785260

Please sign in to comment.