test: code coverage

This commit is contained in:
Michele Caini
2021-03-27 18:17:13 +01:00
parent 059334a861
commit 66bbeae7da
7 changed files with 86 additions and 57 deletions

View File

@@ -13,7 +13,7 @@ jobs:
- name: Compile tests
working-directory: build
env:
CXXFLAGS: "--coverage -O0 -fprofile-arcs -fno-inline -fno-inline-small-functions -fno-default-inline"
CXXFLAGS: "--coverage -O0 -fprofile-arcs -ftest-coverage -fno-inline -fno-inline-small-functions -fno-default-inline"
CXX: g++
run: |
cmake -DENTT_BUILD_TESTING=ON -DENTT_BUILD_LIB=ON -DENTT_BUILD_EXAMPLE=ON ..

View File

@@ -5,8 +5,12 @@
#include <entt/core/any.hpp>
struct fat {
fat(double v1, double v2, double v3, double v4)
: value{v1, v2, v3, v4}
{}
double value[4];
inline static int counter = 0;
inline static int counter{0};
~fat() { ++counter; }
@@ -46,7 +50,7 @@ TEST(Any, SBO) {
}
TEST(Any, NoSBO) {
fat instance{{.1, .2, .3, .4}};
fat instance{.1, .2, .3, .4};
entt::any any{instance};
ASSERT_TRUE(any);
@@ -197,7 +201,7 @@ TEST(Any, SBODirectAssignment) {
}
TEST(Any, NoSBOInPlaceTypeConstruction) {
fat instance{{.1, .2, .3, .4}};
fat instance{.1, .2, .3, .4};
entt::any any{std::in_place_type<fat>, instance};
ASSERT_TRUE(any);
@@ -209,12 +213,12 @@ TEST(Any, NoSBOInPlaceTypeConstruction) {
ASSERT_TRUE(other);
ASSERT_EQ(other.type(), entt::type_id<fat>());
ASSERT_EQ(entt::any_cast<fat>(other), (fat{{.1, .2, .3, .4}}));
ASSERT_EQ(entt::any_cast<fat>(other), (fat{.1, .2, .3, .4}));
ASSERT_EQ(other.data(), any.data());
}
TEST(Any, NoSBOAsRefConstruction) {
fat instance{{.1, .2, .3, .4}};
fat instance{.1, .2, .3, .4};
entt::any any{std::ref(instance)};
ASSERT_TRUE(any);
@@ -236,12 +240,12 @@ TEST(Any, NoSBOAsRefConstruction) {
ASSERT_TRUE(other);
ASSERT_EQ(other.type(), entt::type_id<fat>());
ASSERT_EQ(entt::any_cast<fat>(other), (fat{{.1, .2, .3, .4}}));
ASSERT_EQ(entt::any_cast<fat>(other), (fat{.1, .2, .3, .4}));
ASSERT_EQ(other.data(), any.data());
}
TEST(Any, NoSBOAsConstRefConstruction) {
fat instance{{.1, .2, .3, .4}};
fat instance{.1, .2, .3, .4};
entt::any any{std::cref(instance)};
ASSERT_TRUE(any);
@@ -263,12 +267,12 @@ TEST(Any, NoSBOAsConstRefConstruction) {
ASSERT_TRUE(other);
ASSERT_EQ(other.type(), entt::type_id<fat>());
ASSERT_EQ(entt::any_cast<fat>(other), (fat{{.1, .2, .3, .4}}));
ASSERT_EQ(entt::any_cast<fat>(other), (fat{.1, .2, .3, .4}));
ASSERT_EQ(other.data(), any.data());
}
TEST(Any, NoSBOCopyConstruction) {
fat instance{{.1, .2, .3, .4}};
fat instance{.1, .2, .3, .4};
entt::any any{instance};
entt::any other{any};
@@ -281,7 +285,7 @@ TEST(Any, NoSBOCopyConstruction) {
}
TEST(Any, NoSBOCopyAssignment) {
fat instance{{.1, .2, .3, .4}};
fat instance{.1, .2, .3, .4};
entt::any any{instance};
entt::any other{3};
@@ -296,7 +300,7 @@ TEST(Any, NoSBOCopyAssignment) {
}
TEST(Any, NoSBOMoveConstruction) {
fat instance{{.1, .2, .3, .4}};
fat instance{.1, .2, .3, .4};
entt::any any{instance};
entt::any other{std::move(any)};
@@ -308,7 +312,7 @@ TEST(Any, NoSBOMoveConstruction) {
}
TEST(Any, NoSBOMoveAssignment) {
fat instance{{.1, .2, .3, .4}};
fat instance{.1, .2, .3, .4};
entt::any any{instance};
entt::any other{3};
@@ -322,7 +326,7 @@ TEST(Any, NoSBOMoveAssignment) {
}
TEST(Any, NoSBODirectAssignment) {
fat instance{{.1, .2, .3, .4}};
fat instance{.1, .2, .3, .4};
entt::any any{};
any = instance;
@@ -403,7 +407,7 @@ TEST(Any, SBOMoveInvalidate) {
}
TEST(Any, NoSBOMoveInvalidate) {
fat instance{{.1, .2, .3, .4}};
fat instance{.1, .2, .3, .4};
entt::any any{instance};
entt::any other{std::move(any)};
entt::any valid = std::move(other);
@@ -434,7 +438,7 @@ TEST(Any, SBODestruction) {
TEST(Any, NoSBODestruction) {
{
entt::any any{fat{}};
entt::any any{fat{1., 2., 3., 4.}};
fat::counter = 0;
}
@@ -491,13 +495,13 @@ TEST(Any, SBOSwap) {
}
TEST(Any, NoSBOSwap) {
entt::any lhs{fat{{.1, .2, .3, .4}}};
entt::any rhs{fat{{.4, .3, .2, .1}}};
entt::any lhs{fat{.1, .2, .3, .4}};
entt::any rhs{fat{.4, .3, .2, .1}};
std::swap(lhs, rhs);
ASSERT_EQ(entt::any_cast<fat>(lhs), (fat{{.4, .3, .2, .1}}));
ASSERT_EQ(entt::any_cast<fat>(rhs), (fat{{.1, .2, .3, .4}}));
ASSERT_EQ(entt::any_cast<fat>(lhs), (fat{.4, .3, .2, .1}));
ASSERT_EQ(entt::any_cast<fat>(rhs), (fat{.1, .2, .3, .4}));
}
TEST(Any, VoidSwap) {
@@ -511,7 +515,7 @@ TEST(Any, VoidSwap) {
}
TEST(Any, SBOWithNoSBOSwap) {
entt::any lhs{fat{{.1, .2, .3, .4}}};
entt::any lhs{fat{.1, .2, .3, .4}};
entt::any rhs{'c'};
std::swap(lhs, rhs);
@@ -521,7 +525,7 @@ TEST(Any, SBOWithNoSBOSwap) {
ASSERT_EQ(entt::any_cast<fat>(&lhs), nullptr);
ASSERT_EQ(entt::any_cast<char>(&rhs), nullptr);
ASSERT_EQ(entt::any_cast<char>(lhs), 'c');
ASSERT_EQ(entt::any_cast<fat>(rhs), (fat{{.1, .2, .3, .4}}));
ASSERT_EQ(entt::any_cast<fat>(rhs), (fat{.1, .2, .3, .4}));
}
TEST(Any, SBOWithRefSwap) {
@@ -602,7 +606,7 @@ TEST(Any, SBOWithVoidSwap) {
TEST(Any, NoSBOWithRefSwap) {
int value = 3;
entt::any lhs{std::ref(value)};
entt::any rhs{fat{{.1, .2, .3, .4}}};
entt::any rhs{fat{.1, .2, .3, .4}};
std::swap(lhs, rhs);
@@ -610,7 +614,7 @@ TEST(Any, NoSBOWithRefSwap) {
ASSERT_EQ(rhs.type(), entt::type_id<int>());
ASSERT_EQ(entt::any_cast<int>(&lhs), nullptr);
ASSERT_EQ(entt::any_cast<fat>(&rhs), nullptr);
ASSERT_EQ(entt::any_cast<fat>(lhs), (fat{{.1, .2, .3, .4}}));
ASSERT_EQ(entt::any_cast<fat>(lhs), (fat{.1, .2, .3, .4}));
ASSERT_EQ(entt::any_cast<int>(rhs), 3);
ASSERT_EQ(rhs.data(), &value);
}
@@ -618,7 +622,7 @@ TEST(Any, NoSBOWithRefSwap) {
TEST(Any, NoSBOWithConstRefSwap) {
int value = 3;
entt::any lhs{std::cref(value)};
entt::any rhs{fat{{.1, .2, .3, .4}}};
entt::any rhs{fat{.1, .2, .3, .4}};
std::swap(lhs, rhs);
@@ -626,14 +630,14 @@ TEST(Any, NoSBOWithConstRefSwap) {
ASSERT_EQ(rhs.type(), entt::type_id<int>());
ASSERT_EQ(entt::any_cast<int>(&lhs), nullptr);
ASSERT_EQ(entt::any_cast<fat>(&rhs), nullptr);
ASSERT_EQ(entt::any_cast<fat>(lhs), (fat{{.1, .2, .3, .4}}));
ASSERT_EQ(entt::any_cast<fat>(lhs), (fat{.1, .2, .3, .4}));
ASSERT_EQ(entt::any_cast<int>(rhs), 3);
ASSERT_EQ(rhs.data(), nullptr);
ASSERT_EQ(std::as_const(rhs).data(), &value);
}
TEST(Any, NoSBOWithEmptySwap) {
entt::any lhs{fat{{.1, .2, .3, .4}}};
entt::any lhs{fat{.1, .2, .3, .4}};
entt::any rhs{};
std::swap(lhs, rhs);
@@ -642,7 +646,7 @@ TEST(Any, NoSBOWithEmptySwap) {
ASSERT_EQ(rhs.type(), entt::type_id<fat>());
ASSERT_EQ(entt::any_cast<fat>(&lhs), nullptr);
ASSERT_EQ(entt::any_cast<double>(&rhs), nullptr);
ASSERT_EQ(entt::any_cast<fat>(rhs), (fat{{.1, .2, .3, .4}}));
ASSERT_EQ(entt::any_cast<fat>(rhs), (fat{.1, .2, .3, .4}));
std::swap(lhs, rhs);
@@ -650,11 +654,11 @@ TEST(Any, NoSBOWithEmptySwap) {
ASSERT_EQ(lhs.type(), entt::type_id<fat>());
ASSERT_EQ(entt::any_cast<double>(&lhs), nullptr);
ASSERT_EQ(entt::any_cast<fat>(&rhs), nullptr);
ASSERT_EQ(entt::any_cast<fat>(lhs), (fat{{.1, .2, .3, .4}}));
ASSERT_EQ(entt::any_cast<fat>(lhs), (fat{.1, .2, .3, .4}));
}
TEST(Any, NoSBOWithVoidSwap) {
entt::any lhs{fat{{.1, .2, .3, .4}}};
entt::any lhs{fat{.1, .2, .3, .4}};
entt::any rhs{std::in_place_type<void>};
std::swap(lhs, rhs);
@@ -663,7 +667,7 @@ TEST(Any, NoSBOWithVoidSwap) {
ASSERT_EQ(rhs.type(), entt::type_id<fat>());
ASSERT_EQ(entt::any_cast<fat>(&lhs), nullptr);
ASSERT_EQ(entt::any_cast<double>(&rhs), nullptr);
ASSERT_EQ(entt::any_cast<fat>(rhs), (fat{{.1, .2, .3, .4}}));
ASSERT_EQ(entt::any_cast<fat>(rhs), (fat{.1, .2, .3, .4}));
std::swap(lhs, rhs);
@@ -671,7 +675,7 @@ TEST(Any, NoSBOWithVoidSwap) {
ASSERT_EQ(lhs.type(), entt::type_id<fat>());
ASSERT_EQ(entt::any_cast<double>(&lhs), nullptr);
ASSERT_EQ(entt::any_cast<fat>(&rhs), nullptr);
ASSERT_EQ(entt::any_cast<fat>(lhs), (fat{{.1, .2, .3, .4}}));
ASSERT_EQ(entt::any_cast<fat>(lhs), (fat{.1, .2, .3, .4}));
}
TEST(Any, AsRef) {
@@ -755,7 +759,7 @@ TEST(Any, Comparable) {
int value = 42;
test('c', 'a');
test(fat{{.1, .2, .3, .4}}, fat{{.0, .1, .2, .3}});
test(fat{.1, .2, .3, .4}, fat{.0, .1, .2, .3});
test(std::ref(value), 3);
test(3, std::cref(value));
}

View File

@@ -14,9 +14,17 @@ struct base_t {
int value{3};
};
struct derived_t: base_t {};
struct derived_t: base_t {
derived_t() {}
};
struct clazz_t {
clazz_t()
: i{0},
j{1},
base{}
{}
int i{0};
const int j{1};
base_t base{};
@@ -533,7 +541,7 @@ TEST_F(MetaData, FromBase) {
using namespace entt::literals;
auto type = entt::resolve<derived_t>();
derived_t instance;
derived_t instance{};
ASSERT_TRUE(type.data("value"_hs));

View File

@@ -20,7 +20,9 @@ struct base_t {
int value{3};
};
struct derived_t: base_t {};
struct derived_t: base_t {
derived_t() {}
};
struct func_t {
int f(const base_t &, int a, int b) {
@@ -400,7 +402,7 @@ TEST_F(MetaFunc, FromBase) {
using namespace entt::literals;
auto type = entt::resolve<derived_t>();
derived_t instance;
derived_t instance{};
ASSERT_TRUE(type.func("func"_hs));
ASSERT_EQ(type.func("func"_hs).parent(), entt::resolve<base_t>());

View File

@@ -9,6 +9,14 @@ struct fake_process: entt::process<fake_process<Delta>, Delta> {
using process_type = entt::process<fake_process<Delta>, Delta>;
using delta_type = typename process_type::delta_type;
fake_process()
: init_invoked{false},
update_invoked{false},
succeeded_invoked{false},
failed_invoked{false},
aborted_invoked{false}
{}
void succeed() noexcept { process_type::succeed(); }
void fail() noexcept { process_type::fail(); }
void pause() noexcept { process_type::pause(); }
@@ -27,15 +35,15 @@ struct fake_process: entt::process<fake_process<Delta>, Delta> {
update_invoked = true;
}
bool init_invoked{false};
bool update_invoked{false};
bool succeeded_invoked{false};
bool failed_invoked{false};
bool aborted_invoked{false};
bool init_invoked;
bool update_invoked;
bool succeeded_invoked;
bool failed_invoked;
bool aborted_invoked;
};
TEST(Process, Basics) {
fake_process<int> process;
fake_process<int> process{};
ASSERT_FALSE(process.alive());
ASSERT_FALSE(process.dead());
@@ -71,7 +79,7 @@ TEST(Process, Basics) {
}
TEST(Process, Succeeded) {
fake_process<fake_delta> process;
fake_process<fake_delta> process{};
process.tick({});
process.tick({});
@@ -90,7 +98,7 @@ TEST(Process, Succeeded) {
}
TEST(Process, Fail) {
fake_process<int> process;
fake_process<int> process{};
process.tick(0);
process.tick(0);
@@ -109,7 +117,7 @@ TEST(Process, Fail) {
}
TEST(Process, Data) {
fake_process<fake_delta> process;
fake_process<fake_delta> process{};
int value = 0;
process.tick({});
@@ -130,7 +138,7 @@ TEST(Process, Data) {
}
TEST(Process, AbortNextTick) {
fake_process<int> process;
fake_process<int> process{};
process.tick(0);
process.abort();
@@ -148,7 +156,7 @@ TEST(Process, AbortNextTick) {
}
TEST(Process, AbortImmediately) {
fake_process<fake_delta> process;
fake_process<fake_delta> process{};
process.tick({});
process.abort(true);

View File

@@ -49,8 +49,8 @@ TEST(Scheduler, Functionalities) {
ASSERT_TRUE(scheduler.empty());
scheduler.attach<foo_process>(
[&updated](){ updated = true; },
[&aborted](){ aborted = true; }
[&updated](){ updated = true; },
[&aborted](){ aborted = true; }
);
ASSERT_NE(scheduler.size(), 0u);
@@ -74,16 +74,22 @@ TEST(Scheduler, Functionalities) {
TEST(Scheduler, Then) {
entt::scheduler<int> scheduler;
// failing process with successor
scheduler.attach<succeeded_process>()
.then<succeeded_process>()
.then<failed_process>()
.then<succeeded_process>();
.then<succeeded_process>()
.then<failed_process>()
.then<succeeded_process>();
// failing process without successor
scheduler.attach<succeeded_process>()
.then<succeeded_process>()
.then<failed_process>();
for(auto i = 0; i < 8; ++i) {
scheduler.update(0);
}
ASSERT_EQ(succeeded_process::invoked, 2u);
ASSERT_EQ(succeeded_process::invoked, 4u);
}
TEST(Scheduler, Functor) {

View File

@@ -5,7 +5,8 @@
struct an_event {};
struct another_event {};
struct one_more_event {};
// makes the type non-aggregate
struct one_more_event { one_more_event(int) {} };
struct receiver {
static void forward(entt::dispatcher &dispatcher, an_event &event) {
@@ -21,8 +22,8 @@ TEST(Dispatcher, Functionalities) {
entt::dispatcher dispatcher;
receiver receiver;
dispatcher.trigger<one_more_event>();
dispatcher.enqueue<one_more_event>();
dispatcher.trigger<one_more_event>(42);
dispatcher.enqueue<one_more_event>(42);
dispatcher.update<one_more_event>();
dispatcher.sink<an_event>().connect<&receiver::receive>(receiver);