From b229ca3aba40c51c62405db5085b1c43dbc8a1d7 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 22 Jan 2025 10:16:44 +0100 Subject: [PATCH] test: const correctness --- test/entt/core/any.cpp | 4 +- test/entt/entity/view.cpp | 72 ++++++++++++++++----------------- test/entt/meta/meta_context.cpp | 2 +- test/entt/meta/meta_data.cpp | 6 +-- test/entt/meta/meta_factory.cpp | 2 +- test/entt/meta/meta_func.cpp | 6 +-- test/lib/view/shared/lib.cpp | 2 +- 7 files changed, 47 insertions(+), 47 deletions(-) diff --git a/test/entt/core/any.cpp b/test/entt/core/any.cpp index 81660d1c4..04e050024 100644 --- a/test/entt/core/any.cpp +++ b/test/entt/core/any.cpp @@ -103,7 +103,7 @@ TEST(Any, SBOInPlaceConstruction) { TEST(Any, SBOInPlaceNullptrConstruction) { int *instance = nullptr; - entt::any any{std::in_place, instance}; + const entt::any any{std::in_place, instance}; ASSERT_FALSE(any); ASSERT_FALSE(any.owner()); @@ -421,7 +421,7 @@ TEST(Any, NoSBOInPlaceConstruction) { TEST(Any, NoSBOInPlaceNullptrConstruction) { fat *instance = nullptr; - entt::any any{std::in_place, instance}; + const entt::any any{std::in_place, instance}; ASSERT_FALSE(any); ASSERT_FALSE(any.owner()); diff --git a/test/entt/entity/view.cpp b/test/entt/entity/view.cpp index c7c72d768..8c803964c 100644 --- a/test/entt/entity/view.cpp +++ b/test/entt/entity/view.cpp @@ -14,8 +14,8 @@ TEST(SingleStorageView, Functionalities) { entt::storage storage{}; - entt::basic_view view{storage}; - entt::basic_view cview{std::as_const(storage)}; + const entt::basic_view view{storage}; + const entt::basic_view cview{std::as_const(storage)}; const std::array entity{entt::entity{1}, entt::entity{3}}; ASSERT_TRUE(view.empty()); @@ -113,7 +113,7 @@ TEST(SingleStorageView, Constructors) { TEST(SingleStorageView, Handle) { entt::storage storage{}; - entt::basic_view view{storage}; + const entt::basic_view view{storage}; const entt::entity entity{0}; const auto *handle = view.handle(); @@ -133,8 +133,8 @@ TEST(SingleStorageView, Handle) { TEST(SingleStorageView, ElementAccess) { entt::storage storage{}; - entt::basic_view view{storage}; - entt::basic_view cview{std::as_const(storage)}; + const entt::basic_view view{storage}; + const entt::basic_view cview{std::as_const(storage)}; const std::array entity{entt::entity{1}, entt::entity{3}}; storage.emplace(entity[0u], 4); @@ -146,7 +146,7 @@ TEST(SingleStorageView, ElementAccess) { TEST(SingleStorageView, Contains) { entt::storage storage{}; - entt::basic_view view{storage}; + const entt::basic_view view{storage}; const std::array entity{entt::entity{1}, entt::entity{3}}; storage.emplace(entity[0u]); @@ -160,7 +160,7 @@ TEST(SingleStorageView, Contains) { TEST(SingleStorageView, Empty) { entt::storage storage{}; - entt::basic_view view{storage}; + const entt::basic_view view{storage}; ASSERT_EQ(view.size(), 0u); ASSERT_EQ(view.begin(), view.end()); @@ -169,8 +169,8 @@ TEST(SingleStorageView, Empty) { TEST(SingleStorageView, Each) { std::tuple, entt::storage> storage{}; - entt::basic_view view{std::forward_as_tuple(std::get<0>(storage)), std::forward_as_tuple(std::get<1>(storage))}; - entt::basic_view cview{std::as_const(std::get<0>(storage))}; + const entt::basic_view view{std::forward_as_tuple(std::get<0>(storage)), std::forward_as_tuple(std::get<1>(storage))}; + const entt::basic_view cview{std::as_const(std::get<0>(storage))}; const std::array entity{entt::entity{0}, entt::entity{1}}; std::get<0>(storage).emplace(entity[0u], 0); @@ -214,8 +214,8 @@ TEST(SingleStorageView, Each) { TEST(SingleStorageView, ConstNonConstAndAllInBetween) { entt::storage storage{}; - entt::basic_view view{storage}; - entt::basic_view cview{std::as_const(storage)}; + const entt::basic_view view{storage}; + const entt::basic_view cview{std::as_const(storage)}; const entt::entity entity{0}; ASSERT_EQ(view.size(), 0u); @@ -255,8 +255,8 @@ TEST(SingleStorageView, ConstNonConstAndAllInBetween) { TEST(SingleStorageView, ConstNonConstAndAllInBetweenWithEmptyType) { entt::storage storage{}; - entt::basic_view view{storage}; - entt::basic_view cview{std::as_const(storage)}; + const entt::basic_view view{storage}; + const entt::basic_view cview{std::as_const(storage)}; const entt::entity entity{0}; ASSERT_EQ(view.size(), 0u); @@ -281,7 +281,7 @@ TEST(SingleStorageView, ConstNonConstAndAllInBetweenWithEmptyType) { TEST(SingleStorageView, Find) { entt::storage storage{}; - entt::basic_view view{storage}; + const entt::basic_view view{storage}; const std::array entity{entt::entity{0}, entt::entity{1}, entt::entity{2}}; storage.emplace(entity[0u]); @@ -303,7 +303,7 @@ TEST(SingleStorageView, Find) { TEST(SingleStorageView, EmptyType) { entt::storage storage{}; - entt::basic_view view{storage}; + const entt::basic_view view{storage}; const entt::entity entity{0}; storage.emplace(entity); @@ -325,7 +325,7 @@ TEST(SingleStorageView, EmptyType) { TEST(SingleStorageView, FrontBack) { entt::storage storage{}; - entt::basic_view view{std::as_const(storage)}; + const entt::basic_view view{std::as_const(storage)}; const std::array entity{entt::entity{1}, entt::entity{3}}; ASSERT_EQ(view.front(), static_cast(entt::null)); @@ -619,8 +619,8 @@ TEST(SingleStorageView, StorageEntity) { TEST(MultiStorageView, Functionalities) { std::tuple, entt::storage> storage{}; - entt::basic_view view{std::get<0>(storage), std::get<1>(storage)}; - entt::basic_view cview{std::as_const(std::get<0>(storage)), std::as_const(std::get<1>(storage))}; + const entt::basic_view view{std::get<0>(storage), std::get<1>(storage)}; + const entt::basic_view cview{std::as_const(std::get<0>(storage)), std::as_const(std::get<1>(storage))}; const std::array entity{entt::entity{1}, entt::entity{3}}; std::get<1>(storage).emplace(entity[0u], '1'); @@ -759,7 +759,7 @@ TEST(MultiStorageView, Handle) { TEST(MultiStorageView, Iterator) { std::tuple, entt::storage> storage{}; - entt::basic_view view{std::get<0>(storage), std::get<1>(storage)}; + const entt::basic_view view{std::get<0>(storage), std::get<1>(storage)}; const std::array entity{entt::entity{0}, entt::entity{1}}; std::get<0>(storage).insert(entity.begin(), entity.end()); @@ -787,8 +787,8 @@ TEST(MultiStorageView, Iterator) { TEST(MultiStorageView, ElementAccess) { std::tuple, entt::storage> storage{}; - entt::basic_view view{std::get<0>(storage), std::get<1>(storage)}; - entt::basic_view cview{std::as_const(std::get<0>(storage)), std::as_const(std::get<1>(storage))}; + const entt::basic_view view{std::get<0>(storage), std::get<1>(storage)}; + const entt::basic_view cview{std::as_const(std::get<0>(storage)), std::as_const(std::get<1>(storage))}; const std::array entity{entt::entity{1}, entt::entity{3}}; std::get<0>(storage).emplace(entity[0u], 4); @@ -803,7 +803,7 @@ TEST(MultiStorageView, ElementAccess) { TEST(MultiStorageView, Contains) { std::tuple, entt::storage> storage{}; - entt::basic_view view{std::get<0>(storage), std::get<1>(storage)}; + const entt::basic_view view{std::get<0>(storage), std::get<1>(storage)}; const std::array entity{entt::entity{1}, entt::entity{3}}; std::get<0>(storage).emplace(entity[0u]); @@ -872,8 +872,8 @@ TEST(MultiStorageView, UseAndRefresh) { TEST(MultiStorageView, Each) { std::tuple, entt::storage, entt::storage> storage{}; - entt::basic_view view{std::forward_as_tuple(std::get<0>(storage), std::get<1>(storage)), std::forward_as_tuple(std::get<2>(storage))}; - entt::basic_view cview{std::as_const(std::get<0>(storage)), std::as_const(std::get<1>(storage))}; + const entt::basic_view view{std::forward_as_tuple(std::get<0>(storage), std::get<1>(storage)), std::forward_as_tuple(std::get<2>(storage))}; + const entt::basic_view cview{std::as_const(std::get<0>(storage)), std::as_const(std::get<1>(storage))}; const std::array entity{entt::entity{0}, entt::entity{1}}; std::get<0>(storage).emplace(entity[0u], 0); @@ -976,7 +976,7 @@ TEST(MultiStorageView, EachWithSuggestedType) { TEST(MultiStorageView, EachWithHoles) { std::tuple, entt::storage> storage{}; - entt::basic_view view{std::get<0>(storage), std::get<1>(storage)}; + const entt::basic_view view{std::get<0>(storage), std::get<1>(storage)}; const std::array entity{entt::entity{0}, entt::entity{1}, entt::entity{2}}; std::get<0>(storage).emplace(entity[0u], '0'); @@ -1000,7 +1000,7 @@ TEST(MultiStorageView, EachWithHoles) { TEST(MultiStorageView, ConstNonConstAndAllInBetween) { std::tuple, entt::storage, entt::storage> storage{}; - entt::basic_view view{std::get<0>(storage), std::get<1>(storage), std::as_const(std::get<2>(storage))}; + const entt::basic_view view{std::get<0>(storage), std::get<1>(storage), std::as_const(std::get<2>(storage))}; const entt::entity entity{0}; ASSERT_EQ(view.size_hint(), 0u); @@ -1035,7 +1035,7 @@ TEST(MultiStorageView, ConstNonConstAndAllInBetween) { TEST(MultiStorageView, Find) { std::tuple, entt::storage> storage{}; - entt::basic_view view{std::get<0>(storage), std::as_const(std::get<1>(storage))}; + const entt::basic_view view{std::get<0>(storage), std::as_const(std::get<1>(storage))}; const std::array entity{entt::entity{0}, entt::entity{1}, entt::entity{2}}; std::get<0>(storage).emplace(entity[0u]); @@ -1061,7 +1061,7 @@ TEST(MultiStorageView, Find) { TEST(MultiStorageView, Exclude) { std::tuple, entt::storage> storage{}; - entt::basic_view view{std::forward_as_tuple(std::get<0>(storage)), std::forward_as_tuple(std::as_const(std::get<1>(storage)))}; + const entt::basic_view view{std::forward_as_tuple(std::get<0>(storage)), std::forward_as_tuple(std::as_const(std::get<1>(storage)))}; const std::array entity{entt::entity{0}, entt::entity{1}, entt::entity{2}, entt::entity{3}}; std::get<0>(storage).emplace(entity[0u], 0); @@ -1137,7 +1137,7 @@ TEST(MultiStorageView, EmptyType) { TEST(MultiStorageView, FrontBack) { std::tuple, entt::storage> storage{}; - entt::basic_view view{std::as_const(std::get<0>(storage)), std::as_const(std::get<1>(storage))}; + const entt::basic_view view{std::as_const(std::get<0>(storage)), std::as_const(std::get<1>(storage))}; const std::array entity{entt::entity{0}, entt::entity{1}, entt::entity{2}}; ASSERT_EQ(view.front(), static_cast(entt::null)); @@ -1186,7 +1186,7 @@ TEST(MultiStorageView, DeductionGuide) { TEST(MultiStorageView, IterableViewAlgorithmCompatibility) { std::tuple, entt::storage> storage{}; - entt::basic_view view{std::as_const(std::get<0>(storage)), std::as_const(std::get<1>(storage))}; + const entt::basic_view view{std::as_const(std::get<0>(storage)), std::as_const(std::get<1>(storage))}; const entt::entity entity{0}; std::get<0>(storage).emplace(entity); @@ -1248,7 +1248,7 @@ TEST(MultiStorageView, StableType) { TEST(MultiStorageView, StableTypeWithExclude) { std::tuple, entt::storage> storage{}; - entt::basic_view view{std::forward_as_tuple(std::get<0>(storage)), std::forward_as_tuple(std::get<1>(storage))}; + const entt::basic_view view{std::forward_as_tuple(std::get<0>(storage)), std::forward_as_tuple(std::get<1>(storage))}; const std::array entity{entt::entity{1}, entt::entity{3}}; const entt::entity tombstone = entt::tombstone; @@ -1425,7 +1425,7 @@ TEST(MultiStorageView, SwapStorage) { TEST(MultiStorageView, StorageEntity) { std::tuple, entt::storage> storage{}; - entt::basic_view view{std::get<0>(storage), std::get<1>(storage)}; + const entt::basic_view view{std::get<0>(storage), std::get<1>(storage)}; const std::array entity{std::get<0>(storage).generate(), std::get<0>(storage).generate()}; std::get<1>(storage).emplace(entity[0u]); @@ -1458,7 +1458,7 @@ TEST(MultiStorageView, StorageEntity) { TEST(MultiStorageView, StorageEntityWithExclude) { std::tuple, entt::storage, entt::storage> storage{}; - entt::basic_view view{std::forward_as_tuple(std::get<0>(storage), std::get<1>(storage)), std::forward_as_tuple(std::get<2>(storage))}; + const entt::basic_view view{std::forward_as_tuple(std::get<0>(storage), std::get<1>(storage)), std::forward_as_tuple(std::get<2>(storage))}; const std::array entity{std::get<0>(storage).generate(), std::get<0>(storage).generate(), std::get<0>(storage).generate()}; std::get<1>(storage).emplace(entity[0u]); @@ -1495,7 +1495,7 @@ TEST(MultiStorageView, StorageEntityWithExclude) { TEST(MultiStorageView, StorageEntityExcludeOnly) { std::tuple, entt::storage> storage{}; - entt::basic_view view{std::forward_as_tuple(std::get<0>(storage)), std::forward_as_tuple(std::get<1>(storage))}; + const entt::basic_view view{std::forward_as_tuple(std::get<0>(storage)), std::forward_as_tuple(std::get<1>(storage))}; const std::array entity{std::get<0>(storage).generate(), std::get<0>(storage).generate(), std::get<0>(storage).generate()}; std::get<1>(storage).emplace(entity[2u]); @@ -1537,9 +1537,9 @@ TEST(View, Pipe) { std::get<3>(storage).emplace(entity[1u]); entt::basic_view view1{std::forward_as_tuple(std::get<0>(storage)), std::forward_as_tuple(std::as_const(std::get<1>(storage)))}; - entt::basic_view view2{std::forward_as_tuple(std::as_const(std::get<0>(storage))), std::forward_as_tuple(std::get<4>(storage))}; + const entt::basic_view view2{std::forward_as_tuple(std::as_const(std::get<0>(storage))), std::forward_as_tuple(std::get<4>(storage))}; entt::basic_view view3{std::get<2>(storage)}; - entt::basic_view view4{std::as_const(std::get<3>(storage))}; + const entt::basic_view view4{std::as_const(std::get<3>(storage))}; testing::StaticAssertTypeEq(storage)), decltype(view1 | view3)>(); testing::StaticAssertTypeEq(std::as_const(storage))), decltype(view1 | view4)>(); diff --git a/test/entt/meta/meta_context.cpp b/test/entt/meta/meta_context.cpp index 90d92b7f0..844e7bc18 100644 --- a/test/entt/meta/meta_context.cpp +++ b/test/entt/meta/meta_context.cpp @@ -306,7 +306,7 @@ TEST_F(MetaContext, MetaCtor) { ASSERT_EQ(any.cast().value, 0); ASSERT_EQ(other.cast().value, 0); - argument argument{2}; + const argument argument{2}; any = global.construct(argument); other = local.construct(argument); diff --git a/test/entt/meta/meta_data.cpp b/test/entt/meta/meta_data.cpp index e768eec64..5772d27b0 100644 --- a/test/entt/meta/meta_data.cpp +++ b/test/entt/meta/meta_data.cpp @@ -148,7 +148,7 @@ struct MetaData: ::testing::Test { using MetaDataDeathTest = MetaData; TEST_F(MetaData, SafeWhenEmpty) { - entt::meta_data data{}; + const entt::meta_data data{}; ASSERT_FALSE(data); ASSERT_EQ(data, entt::meta_data{}); @@ -196,8 +196,8 @@ TEST_F(MetaData, Custom) { ENTT_DEBUG_TEST_F(MetaDataDeathTest, Custom) { using namespace entt::literals; - ASSERT_DEATH([[maybe_unused]] int value = entt::resolve().data("i"_hs).custom(), ""); - ASSERT_DEATH([[maybe_unused]] char value = entt::resolve().data("j"_hs).custom(), ""); + ASSERT_DEATH([[maybe_unused]] const int value = entt::resolve().data("i"_hs).custom(), ""); + ASSERT_DEATH([[maybe_unused]] const char value = entt::resolve().data("j"_hs).custom(), ""); } TEST_F(MetaData, Comparison) { diff --git a/test/entt/meta/meta_factory.cpp b/test/entt/meta/meta_factory.cpp index 44147456e..e93ad83c3 100644 --- a/test/entt/meta/meta_factory.cpp +++ b/test/entt/meta/meta_factory.cpp @@ -347,7 +347,7 @@ TEST_F(MetaFactory, FuncOverload) { clazz instance{1}; entt::meta_factory factory{}; - entt::meta_type type = entt::resolve(); + const entt::meta_type type = entt::resolve(); ASSERT_FALSE(type.func("func"_hs)); diff --git a/test/entt/meta/meta_func.cpp b/test/entt/meta/meta_func.cpp index 6a84b1780..deaae8176 100644 --- a/test/entt/meta/meta_func.cpp +++ b/test/entt/meta/meta_func.cpp @@ -159,7 +159,7 @@ struct MetaFunc: ::testing::Test { using MetaFuncDeathTest = MetaFunc; TEST_F(MetaFunc, SafeWhenEmpty) { - entt::meta_func func{}; + const entt::meta_func func{}; entt::meta_any *args = nullptr; ASSERT_FALSE(func); @@ -212,8 +212,8 @@ TEST_F(MetaFunc, Custom) { ENTT_DEBUG_TEST_F(MetaFuncDeathTest, Custom) { using namespace entt::literals; - ASSERT_DEATH([[maybe_unused]] int value = entt::resolve().func("g"_hs).custom(), ""); - ASSERT_DEATH([[maybe_unused]] char value = entt::resolve().func("h"_hs).custom(), ""); + ASSERT_DEATH([[maybe_unused]] const int value = entt::resolve().func("g"_hs).custom(), ""); + ASSERT_DEATH([[maybe_unused]] const char value = entt::resolve().func("h"_hs).custom(), ""); } TEST_F(MetaFunc, Comparison) { diff --git a/test/lib/view/shared/lib.cpp b/test/lib/view/shared/lib.cpp index ffe925c5e..13c6bc2f3 100644 --- a/test/lib/view/shared/lib.cpp +++ b/test/lib/view/shared/lib.cpp @@ -3,7 +3,7 @@ ENTT_API const void *filter(const view_type &view) { // forces the creation of all symbols for the view type - view_type other{}; + [[maybe_unused]] const view_type other{}; // unset filter fallback should not be accessible across boundaries return view.storage<1u>();