Skip to content

Commit

Permalink
test: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Sep 19, 2023
1 parent 14706c8 commit 1280367
Show file tree
Hide file tree
Showing 13 changed files with 526 additions and 529 deletions.
46 changes: 23 additions & 23 deletions test/entt/core/compressed_pair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,24 @@ TEST(CompressedPair, Size) {
empty_type empty;
};

static_assert(sizeof(entt::compressed_pair<int, int>) == sizeof(int[2u]));
static_assert(sizeof(entt::compressed_pair<empty_type, int>) == sizeof(int));
static_assert(sizeof(entt::compressed_pair<int, empty_type>) == sizeof(int));
static_assert(sizeof(entt::compressed_pair<int, empty_type>) < sizeof(local));
static_assert(sizeof(entt::compressed_pair<int, empty_type>) < sizeof(std::pair<int, empty_type>));
ASSERT_EQ(sizeof(entt::compressed_pair<int, int>), sizeof(int[2u]));
ASSERT_EQ(sizeof(entt::compressed_pair<empty_type, int>), sizeof(int));
ASSERT_EQ(sizeof(entt::compressed_pair<int, empty_type>), sizeof(int));
ASSERT_LT(sizeof(entt::compressed_pair<int, empty_type>), sizeof(local));
ASSERT_LT(sizeof(entt::compressed_pair<int, empty_type>), sizeof(std::pair<int, empty_type>));
}

TEST(CompressedPair, ConstructCopyMove) {
static_assert(!std::is_default_constructible_v<entt::compressed_pair<non_default_constructible, empty_type>>);
static_assert(std::is_default_constructible_v<entt::compressed_pair<move_only_type, empty_type>>);
ASSERT_FALSE((std::is_default_constructible_v<entt::compressed_pair<non_default_constructible, empty_type>>));
ASSERT_TRUE((std::is_default_constructible_v<entt::compressed_pair<move_only_type, empty_type>>));

static_assert(std::is_copy_constructible_v<entt::compressed_pair<non_default_constructible, empty_type>>);
static_assert(!std::is_copy_constructible_v<entt::compressed_pair<move_only_type, empty_type>>);
static_assert(std::is_copy_assignable_v<entt::compressed_pair<non_default_constructible, empty_type>>);
static_assert(!std::is_copy_assignable_v<entt::compressed_pair<move_only_type, empty_type>>);
ASSERT_TRUE((std::is_copy_constructible_v<entt::compressed_pair<non_default_constructible, empty_type>>));
ASSERT_FALSE((std::is_copy_constructible_v<entt::compressed_pair<move_only_type, empty_type>>));
ASSERT_TRUE((std::is_copy_assignable_v<entt::compressed_pair<non_default_constructible, empty_type>>));
ASSERT_FALSE((std::is_copy_assignable_v<entt::compressed_pair<move_only_type, empty_type>>));

static_assert(std::is_move_constructible_v<entt::compressed_pair<move_only_type, empty_type>>);
static_assert(std::is_move_assignable_v<entt::compressed_pair<move_only_type, empty_type>>);
ASSERT_TRUE((std::is_move_constructible_v<entt::compressed_pair<move_only_type, empty_type>>));
ASSERT_TRUE((std::is_move_assignable_v<entt::compressed_pair<move_only_type, empty_type>>));

entt::compressed_pair copyable{non_default_constructible{42}, empty_type{}};
auto by_copy{copyable};
Expand Down Expand Up @@ -104,9 +104,9 @@ TEST(CompressedPair, DeductionGuide) {
empty_type empty{};
entt::compressed_pair pair{value, 3};

static_assert(std::is_same_v<decltype(entt::compressed_pair{empty_type{}, empty}), entt::compressed_pair<empty_type, empty_type>>);
testing::StaticAssertTypeEq<decltype(entt::compressed_pair{empty_type{}, empty}), entt::compressed_pair<empty_type, empty_type>>();
testing::StaticAssertTypeEq<decltype(pair), entt::compressed_pair<int, int>>();

ASSERT_TRUE((std::is_same_v<decltype(pair), entt::compressed_pair<int, int>>));
ASSERT_EQ(pair.first(), 42);
ASSERT_EQ(pair.second(), 3);
}
Expand All @@ -115,11 +115,11 @@ TEST(CompressedPair, Getters) {
entt::compressed_pair pair{3, empty_type{}};
const auto &cpair = pair;

static_assert(std::is_same_v<decltype(pair.first()), int &>);
static_assert(std::is_same_v<decltype(pair.second()), empty_type &>);
testing::StaticAssertTypeEq<decltype(pair.first()), int &>();
testing::StaticAssertTypeEq<decltype(pair.second()), empty_type &>();

static_assert(std::is_same_v<decltype(cpair.first()), const int &>);
static_assert(std::is_same_v<decltype(cpair.second()), const empty_type &>);
testing::StaticAssertTypeEq<decltype(cpair.first()), const int &>();
testing::StaticAssertTypeEq<decltype(cpair.second()), const empty_type &>();

ASSERT_EQ(pair.first(), cpair.first());
ASSERT_EQ(&pair.second(), &cpair.second());
Expand Down Expand Up @@ -169,14 +169,14 @@ TEST(CompressedPair, Get) {
ASSERT_EQ(cfirst, 3);
ASSERT_EQ(csecond, 4);

static_assert(std::is_same_v<decltype(cfirst), const int>);
static_assert(std::is_same_v<decltype(csecond), const int>);
testing::StaticAssertTypeEq<decltype(cfirst), const int>();
testing::StaticAssertTypeEq<decltype(csecond), const int>();

auto [tfirst, tsecond] = entt::compressed_pair{9, 99};

ASSERT_EQ(tfirst, 9);
ASSERT_EQ(tsecond, 99);

static_assert(std::is_same_v<decltype(cfirst), const int>);
static_assert(std::is_same_v<decltype(csecond), const int>);
testing::StaticAssertTypeEq<decltype(cfirst), const int>();
testing::StaticAssertTypeEq<decltype(csecond), const int>();
}
53 changes: 26 additions & 27 deletions test/entt/core/hashed_string.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <cstdint>
#include <string>
#include <string_view>
#include <type_traits>
#include <gtest/gtest.h>
#include <entt/core/hashed_string.hpp>

Expand All @@ -21,8 +20,8 @@ struct expected<std::uint64_t> {
inline constexpr auto expected_v = expected<entt::id_type>::value;

TEST(BasicHashedString, DeductionGuide) {
static_assert(std::is_same_v<decltype(entt::basic_hashed_string{"foo"}), entt::hashed_string>);
static_assert(std::is_same_v<decltype(entt::basic_hashed_string{L"foo"}), entt::hashed_wstring>);
testing::StaticAssertTypeEq<decltype(entt::basic_hashed_string{"foo"}), entt::hashed_string>();
testing::StaticAssertTypeEq<decltype(entt::basic_hashed_string{L"foo"}), entt::hashed_wstring>();
}

TEST(HashedString, Functionalities) {
Expand Down Expand Up @@ -110,23 +109,23 @@ TEST(HashedString, Constexprness) {
using namespace entt::literals;
constexpr std::string_view view{"foobar__", 6};

static_assert(entt::hashed_string{"quux"} == "quux"_hs);
static_assert(entt::hashed_string{"foobar"} == expected_v);
ASSERT_EQ(entt::hashed_string{"quux"}, "quux"_hs);
ASSERT_EQ(entt::hashed_string{"foobar"}, expected_v);

static_assert(entt::hashed_string::value("quux") == "quux"_hs);
static_assert(entt::hashed_string::value("foobar") == expected_v);
ASSERT_EQ(entt::hashed_string::value("quux"), "quux"_hs);
ASSERT_EQ(entt::hashed_string::value("foobar"), expected_v);

static_assert(entt::hashed_string{"quux", 4} == "quux"_hs);
static_assert(entt::hashed_string{view.data(), view.size()} == expected_v);
ASSERT_EQ((entt::hashed_string{"quux", 4}), "quux"_hs);
ASSERT_EQ((entt::hashed_string{view.data(), view.size()}), expected_v);

static_assert(entt::hashed_string::value("quux", 4) == "quux"_hs);
static_assert(entt::hashed_string::value(view.data(), view.size()) == expected_v);
ASSERT_EQ((entt::hashed_string::value("quux", 4)), "quux"_hs);
ASSERT_EQ((entt::hashed_string::value(view.data(), view.size())), expected_v);

static_assert(entt::hashed_string{"bar"} < "foo"_hs);
static_assert(entt::hashed_string{"bar"} <= "bar"_hs);
ASSERT_LT(entt::hashed_string{"bar"}, "foo"_hs);
ASSERT_LE(entt::hashed_string{"bar"}, "bar"_hs);

static_assert(entt::hashed_string{"foo"} > "bar"_hs);
static_assert(entt::hashed_string{"foo"} >= "foo"_hs);
ASSERT_GT(entt::hashed_string{"foo"}, "bar"_hs);
ASSERT_GE(entt::hashed_string{"foo"}, "foo"_hs);
}

TEST(HashedWString, Functionalities) {
Expand Down Expand Up @@ -204,21 +203,21 @@ TEST(HashedWString, Constexprness) {
using namespace entt::literals;
constexpr std::wstring_view view{L"foobar__", 6};

static_assert(entt::hashed_wstring{L"quux"} == L"quux"_hws);
static_assert(entt::hashed_wstring{L"foobar"} == expected_v);
ASSERT_EQ(entt::hashed_wstring{L"quux"}, L"quux"_hws);
ASSERT_EQ(entt::hashed_wstring{L"foobar"}, expected_v);

static_assert(entt::hashed_wstring::value(L"quux") == L"quux"_hws);
static_assert(entt::hashed_wstring::value(L"foobar") == expected_v);
ASSERT_EQ(entt::hashed_wstring::value(L"quux"), L"quux"_hws);
ASSERT_EQ(entt::hashed_wstring::value(L"foobar"), expected_v);

static_assert(entt::hashed_wstring{L"quux", 4} == L"quux"_hws);
static_assert(entt::hashed_wstring{view.data(), view.size()} == expected_v);
ASSERT_EQ((entt::hashed_wstring{L"quux", 4}), L"quux"_hws);
ASSERT_EQ((entt::hashed_wstring{view.data(), view.size()}), expected_v);

static_assert(entt::hashed_wstring::value(L"quux", 4) == L"quux"_hws);
static_assert(entt::hashed_wstring::value(view.data(), view.size()) == expected_v);
ASSERT_EQ((entt::hashed_wstring::value(L"quux", 4)), L"quux"_hws);
ASSERT_EQ((entt::hashed_wstring::value(view.data(), view.size())), expected_v);

static_assert(entt::hashed_wstring{L"bar"} < L"foo"_hws);
static_assert(entt::hashed_wstring{L"bar"} <= L"bar"_hws);
ASSERT_LT(entt::hashed_wstring{L"bar"}, L"foo"_hws);
ASSERT_LE(entt::hashed_wstring{L"bar"}, L"bar"_hws);

static_assert(entt::hashed_wstring{L"foo"} > L"bar"_hws);
static_assert(entt::hashed_wstring{L"foo"} >= L"foo"_hws);
ASSERT_GT(entt::hashed_wstring{L"foo"}, L"bar"_hws);
ASSERT_GE(entt::hashed_wstring{L"foo"}, L"foo"_hws);
}
38 changes: 16 additions & 22 deletions test/entt/core/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,29 +133,26 @@ TEST(UsesAllocatorConstructionArgs, NoUsesAllocatorConstruction) {
const auto value = 42;
const auto args = entt::uses_allocator_construction_args<int>(std::allocator<int>{}, value);

static_assert(std::tuple_size_v<decltype(args)> == 1u);
static_assert(std::is_same_v<decltype(args), const std::tuple<const int &>>);

ASSERT_EQ(std::tuple_size_v<decltype(args)>, 1u);
testing::StaticAssertTypeEq<decltype(args), const std::tuple<const int &>>();
ASSERT_EQ(std::get<0>(args), value);
}

TEST(UsesAllocatorConstructionArgs, LeadingAllocatorConvention) {
const auto value = 42;
const auto args = entt::uses_allocator_construction_args<std::tuple<int, char>>(std::allocator<int>{}, value, 'c');

static_assert(std::tuple_size_v<decltype(args)> == 4u);
static_assert(std::is_same_v<decltype(args), const std::tuple<std::allocator_arg_t, const std::allocator<int> &, const int &, char &&>>);

ASSERT_EQ(std::tuple_size_v<decltype(args)>, 4u);
testing::StaticAssertTypeEq<decltype(args), const std::tuple<std::allocator_arg_t, const std::allocator<int> &, const int &, char &&>>();
ASSERT_EQ(std::get<2>(args), value);
}

TEST(UsesAllocatorConstructionArgs, TrailingAllocatorConvention) {
const auto size = 42u;
const auto args = entt::uses_allocator_construction_args<std::vector<int>>(std::allocator<int>{}, size);

static_assert(std::tuple_size_v<decltype(args)> == 2u);
static_assert(std::is_same_v<decltype(args), const std::tuple<const unsigned int &, const std::allocator<int> &>>);

ASSERT_EQ(std::tuple_size_v<decltype(args)>, 2u);
testing::StaticAssertTypeEq<decltype(args), const std::tuple<const unsigned int &, const std::allocator<int> &>>();
ASSERT_EQ(std::get<0>(args), size);
}

Expand All @@ -164,45 +161,42 @@ TEST(UsesAllocatorConstructionArgs, PairPiecewiseConstruct) {
const auto tup = std::make_tuple(size);
const auto args = entt::uses_allocator_construction_args<std::pair<int, std::vector<int>>>(std::allocator<int>{}, std::piecewise_construct, std::make_tuple(3), tup);

static_assert(std::tuple_size_v<decltype(args)> == 3u);
static_assert(std::is_same_v<decltype(args), const std::tuple<std::piecewise_construct_t, std::tuple<int &&>, std::tuple<const unsigned int &, const std::allocator<int> &>>>);

ASSERT_EQ(std::tuple_size_v<decltype(args)>, 3u);
testing::StaticAssertTypeEq<decltype(args), const std::tuple<std::piecewise_construct_t, std::tuple<int &&>, std::tuple<const unsigned int &, const std::allocator<int> &>>>();
ASSERT_EQ(std::get<0>(std::get<2>(args)), size);
}

TEST(UsesAllocatorConstructionArgs, PairNoArgs) {
[[maybe_unused]] const auto args = entt::uses_allocator_construction_args<std::pair<int, std::vector<int>>>(std::allocator<int>{});

static_assert(std::tuple_size_v<decltype(args)> == 3u);
static_assert(std::is_same_v<decltype(args), const std::tuple<std::piecewise_construct_t, std::tuple<>, std::tuple<const std::allocator<int> &>>>);
ASSERT_EQ(std::tuple_size_v<decltype(args)>, 3u);
testing::StaticAssertTypeEq<decltype(args), const std::tuple<std::piecewise_construct_t, std::tuple<>, std::tuple<const std::allocator<int> &>>>();
}

TEST(UsesAllocatorConstructionArgs, PairValues) {
const auto size = 42u;
const auto args = entt::uses_allocator_construction_args<std::pair<int, std::vector<int>>>(std::allocator<int>{}, 3, size);

static_assert(std::tuple_size_v<decltype(args)> == 3u);
static_assert(std::is_same_v<decltype(args), const std::tuple<std::piecewise_construct_t, std::tuple<int &&>, std::tuple<const unsigned int &, const std::allocator<int> &>>>);

ASSERT_EQ(std::tuple_size_v<decltype(args)>, 3u);
testing::StaticAssertTypeEq<decltype(args), const std::tuple<std::piecewise_construct_t, std::tuple<int &&>, std::tuple<const unsigned int &, const std::allocator<int> &>>>();
ASSERT_EQ(std::get<0>(std::get<2>(args)), size);
}

TEST(UsesAllocatorConstructionArgs, PairConstLValueReference) {
const auto value = std::make_pair(3, 42u);
const auto args = entt::uses_allocator_construction_args<std::pair<int, std::vector<int>>>(std::allocator<int>{}, value);

static_assert(std::tuple_size_v<decltype(args)> == 3u);
static_assert(std::is_same_v<decltype(args), const std::tuple<std::piecewise_construct_t, std::tuple<const int &>, std::tuple<const unsigned int &, const std::allocator<int> &>>>);

ASSERT_EQ(std::tuple_size_v<decltype(args)>, 3u);
testing::StaticAssertTypeEq<decltype(args), const std::tuple<std::piecewise_construct_t, std::tuple<const int &>, std::tuple<const unsigned int &, const std::allocator<int> &>>>();
ASSERT_EQ(std::get<0>(std::get<1>(args)), 3);
ASSERT_EQ(std::get<0>(std::get<2>(args)), 42u);
}

TEST(UsesAllocatorConstructionArgs, PairRValueReference) {
[[maybe_unused]] const auto args = entt::uses_allocator_construction_args<std::pair<int, std::vector<int>>>(std::allocator<int>{}, std::make_pair(3, 42u));

static_assert(std::tuple_size_v<decltype(args)> == 3u);
static_assert(std::is_same_v<decltype(args), const std::tuple<std::piecewise_construct_t, std::tuple<int &&>, std::tuple<unsigned int &&, const std::allocator<int> &>>>);
ASSERT_EQ(std::tuple_size_v<decltype(args)>, 3u);
testing::StaticAssertTypeEq<decltype(args), const std::tuple<std::piecewise_construct_t, std::tuple<int &&>, std::tuple<unsigned int &&, const std::allocator<int> &>>>();
}

TEST(MakeObjUsingAllocator, Functionalities) {
Expand Down
27 changes: 14 additions & 13 deletions test/entt/core/tuple.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
#include <tuple>
#include <utility>
#include <gtest/gtest.h>
#include <entt/core/tuple.hpp>

TEST(Tuple, IsTuple) {
static_assert(!entt::is_tuple_v<int>);
static_assert(entt::is_tuple_v<std::tuple<>>);
static_assert(entt::is_tuple_v<std::tuple<int>>);
static_assert(entt::is_tuple_v<std::tuple<int, char>>);
ASSERT_FALSE(entt::is_tuple_v<int>);
ASSERT_TRUE(entt::is_tuple_v<std::tuple<>>);
ASSERT_TRUE(entt::is_tuple_v<std::tuple<int>>);
ASSERT_TRUE((entt::is_tuple_v<std::tuple<int, char>>));
}

TEST(Tuple, UnwrapTuple) {
auto single = std::make_tuple(42);
auto multi = std::make_tuple(42, 'c');
auto ref = std::forward_as_tuple(std::get<0>(single));

ASSERT_TRUE((std::is_same_v<decltype(entt::unwrap_tuple(single)), int &>));
ASSERT_TRUE((std::is_same_v<decltype(entt::unwrap_tuple(multi)), std::tuple<int, char> &>));
ASSERT_TRUE((std::is_same_v<decltype(entt::unwrap_tuple(ref)), int &>));
testing::StaticAssertTypeEq<decltype(entt::unwrap_tuple(single)), int &>();
testing::StaticAssertTypeEq<decltype(entt::unwrap_tuple(multi)), std::tuple<int, char> &>();
testing::StaticAssertTypeEq<decltype(entt::unwrap_tuple(ref)), int &>();

ASSERT_TRUE((std::is_same_v<decltype(entt::unwrap_tuple(std::move(single))), int &&>));
ASSERT_TRUE((std::is_same_v<decltype(entt::unwrap_tuple(std::move(multi))), std::tuple<int, char> &&>));
ASSERT_TRUE((std::is_same_v<decltype(entt::unwrap_tuple(std::move(ref))), int &>));
testing::StaticAssertTypeEq<decltype(entt::unwrap_tuple(std::move(single))), int &&>();
testing::StaticAssertTypeEq<decltype(entt::unwrap_tuple(std::move(multi))), std::tuple<int, char> &&>();
testing::StaticAssertTypeEq<decltype(entt::unwrap_tuple(std::move(ref))), int &>();

ASSERT_TRUE((std::is_same_v<decltype(entt::unwrap_tuple(std::as_const(single))), const int &>));
ASSERT_TRUE((std::is_same_v<decltype(entt::unwrap_tuple(std::as_const(multi))), const std::tuple<int, char> &>));
ASSERT_TRUE((std::is_same_v<decltype(entt::unwrap_tuple(std::as_const(ref))), int &>));
testing::StaticAssertTypeEq<decltype(entt::unwrap_tuple(std::as_const(single))), const int &>();
testing::StaticAssertTypeEq<decltype(entt::unwrap_tuple(std::as_const(multi))), const std::tuple<int, char> &>();
testing::StaticAssertTypeEq<decltype(entt::unwrap_tuple(std::as_const(ref))), int &>();

ASSERT_EQ(entt::unwrap_tuple(single), 42);
ASSERT_EQ(entt::unwrap_tuple(multi), multi);
Expand Down
8 changes: 4 additions & 4 deletions test/entt/core/type_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ TEST(TypeName, Functionalities) {
}

TEST(TypeInfo, Functionalities) {
static_assert(std::is_copy_constructible_v<entt::type_info>);
static_assert(std::is_move_constructible_v<entt::type_info>);
static_assert(std::is_copy_assignable_v<entt::type_info>);
static_assert(std::is_move_assignable_v<entt::type_info>);
ASSERT_TRUE(std::is_copy_constructible_v<entt::type_info>);
ASSERT_TRUE(std::is_move_constructible_v<entt::type_info>);
ASSERT_TRUE(std::is_copy_assignable_v<entt::type_info>);
ASSERT_TRUE(std::is_move_assignable_v<entt::type_info>);

entt::type_info info{std::in_place_type<int>};
entt::type_info other{std::in_place_type<void>};
Expand Down
Loading

0 comments on commit 1280367

Please sign in to comment.