|
|
@@ -3,27 +3,25 @@
|
|
|
#include <gtest/gtest.h>
|
|
|
#include <entt/core/hashed_string.hpp>
|
|
|
|
|
|
-template<typename>
|
|
|
-struct expected;
|
|
|
-
|
|
|
-template<>
|
|
|
-struct expected<std::uint32_t> {
|
|
|
- static constexpr auto value = 0xbf9cf968;
|
|
|
-};
|
|
|
-
|
|
|
-template<>
|
|
|
-struct expected<std::uint64_t> {
|
|
|
- static constexpr auto value = 0x85944171f73967e8;
|
|
|
+struct BasicHashedString: ::testing::Test {
|
|
|
+ static constexpr auto expected() noexcept {
|
|
|
+ if constexpr(std::is_same_v<entt::id_type, std::uint32_t>) {
|
|
|
+ return 0xbf9cf968;
|
|
|
+ } else if constexpr(std::is_same_v<entt::id_type, std::uint64_t>) {
|
|
|
+ return 0x85944171f73967e8;
|
|
|
+ }
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
-inline constexpr auto expected_v = expected<entt::id_type>::value;
|
|
|
+using HashedString = BasicHashedString;
|
|
|
+using HashedWString = BasicHashedString;
|
|
|
|
|
|
-TEST(BasicHashedString, DeductionGuide) {
|
|
|
+TEST_F(BasicHashedString, DeductionGuide) {
|
|
|
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) {
|
|
|
+TEST_F(HashedString, Functionalities) {
|
|
|
using namespace entt::literals;
|
|
|
using hash_type = entt::hashed_string::hash_type;
|
|
|
|
|
|
@@ -45,8 +43,8 @@ TEST(HashedString, Functionalities) {
|
|
|
|
|
|
const entt::hashed_string hs{"foobar"};
|
|
|
|
|
|
- ASSERT_EQ(static_cast<hash_type>(hs), expected_v);
|
|
|
- ASSERT_EQ(hs.value(), expected_v);
|
|
|
+ ASSERT_EQ(static_cast<hash_type>(hs), expected());
|
|
|
+ ASSERT_EQ(hs.value(), expected());
|
|
|
|
|
|
ASSERT_EQ(foo_hs, "foo"_hs);
|
|
|
ASSERT_NE(bar_hs, "foo"_hs);
|
|
|
@@ -62,7 +60,7 @@ TEST(HashedString, Functionalities) {
|
|
|
ASSERT_EQ(empty_hs, foo_hs);
|
|
|
}
|
|
|
|
|
|
-TEST(HashedString, Empty) {
|
|
|
+TEST_F(HashedString, Empty) {
|
|
|
using hash_type = entt::hashed_string::hash_type;
|
|
|
|
|
|
const entt::hashed_string hs{};
|
|
|
@@ -72,24 +70,24 @@ TEST(HashedString, Empty) {
|
|
|
ASSERT_EQ(static_cast<const char *>(hs), nullptr);
|
|
|
}
|
|
|
|
|
|
-TEST(HashedString, Correctness) {
|
|
|
+TEST_F(HashedString, Correctness) {
|
|
|
const char *foobar = "foobar";
|
|
|
const std::string_view view{"foobar__", 6};
|
|
|
|
|
|
- ASSERT_EQ(entt::hashed_string{foobar}, expected_v);
|
|
|
- ASSERT_EQ((entt::hashed_string{view.data(), view.size()}), expected_v);
|
|
|
- ASSERT_EQ(entt::hashed_string{"foobar"}, expected_v);
|
|
|
+ ASSERT_EQ(entt::hashed_string{foobar}, expected());
|
|
|
+ ASSERT_EQ((entt::hashed_string{view.data(), view.size()}), expected());
|
|
|
+ ASSERT_EQ(entt::hashed_string{"foobar"}, expected());
|
|
|
|
|
|
- ASSERT_EQ(entt::hashed_string::value(foobar), expected_v);
|
|
|
- ASSERT_EQ(entt::hashed_string::value(view.data(), view.size()), expected_v);
|
|
|
- ASSERT_EQ(entt::hashed_string::value("foobar"), expected_v);
|
|
|
+ ASSERT_EQ(entt::hashed_string::value(foobar), expected());
|
|
|
+ ASSERT_EQ(entt::hashed_string::value(view.data(), view.size()), expected());
|
|
|
+ ASSERT_EQ(entt::hashed_string::value("foobar"), expected());
|
|
|
|
|
|
ASSERT_EQ(entt::hashed_string{foobar}.size(), 6u);
|
|
|
ASSERT_EQ((entt::hashed_string{view.data(), view.size()}).size(), 6u);
|
|
|
ASSERT_EQ(entt::hashed_string{"foobar"}.size(), 6u);
|
|
|
}
|
|
|
|
|
|
-TEST(HashedString, Order) {
|
|
|
+TEST_F(HashedString, Order) {
|
|
|
using namespace entt::literals;
|
|
|
const entt::hashed_string lhs = "foo"_hs;
|
|
|
const entt::hashed_string rhs = "bar"_hs;
|
|
|
@@ -104,21 +102,21 @@ TEST(HashedString, Order) {
|
|
|
ASSERT_GE(lhs, rhs);
|
|
|
}
|
|
|
|
|
|
-TEST(HashedString, Constexprness) {
|
|
|
+TEST_F(HashedString, Constexprness) {
|
|
|
using namespace entt::literals;
|
|
|
constexpr std::string_view view{"foobar__", 6};
|
|
|
|
|
|
ASSERT_EQ(entt::hashed_string{"quux"}, "quux"_hs);
|
|
|
- ASSERT_EQ(entt::hashed_string{"foobar"}, expected_v);
|
|
|
+ ASSERT_EQ(entt::hashed_string{"foobar"}, expected());
|
|
|
|
|
|
ASSERT_EQ(entt::hashed_string::value("quux"), "quux"_hs);
|
|
|
- ASSERT_EQ(entt::hashed_string::value("foobar"), expected_v);
|
|
|
+ ASSERT_EQ(entt::hashed_string::value("foobar"), expected());
|
|
|
|
|
|
ASSERT_EQ((entt::hashed_string{"quux", 4}), "quux"_hs);
|
|
|
- ASSERT_EQ((entt::hashed_string{view.data(), view.size()}), expected_v);
|
|
|
+ ASSERT_EQ((entt::hashed_string{view.data(), view.size()}), expected());
|
|
|
|
|
|
ASSERT_EQ((entt::hashed_string::value("quux", 4)), "quux"_hs);
|
|
|
- ASSERT_EQ((entt::hashed_string::value(view.data(), view.size())), expected_v);
|
|
|
+ ASSERT_EQ((entt::hashed_string::value(view.data(), view.size())), expected());
|
|
|
|
|
|
ASSERT_LT(entt::hashed_string{"bar"}, "foo"_hs);
|
|
|
ASSERT_LE(entt::hashed_string{"bar"}, "bar"_hs);
|
|
|
@@ -127,7 +125,7 @@ TEST(HashedString, Constexprness) {
|
|
|
ASSERT_GE(entt::hashed_string{"foo"}, "foo"_hs);
|
|
|
}
|
|
|
|
|
|
-TEST(HashedWString, Functionalities) {
|
|
|
+TEST_F(HashedWString, Functionalities) {
|
|
|
using namespace entt::literals;
|
|
|
using hash_type = entt::hashed_wstring::hash_type;
|
|
|
|
|
|
@@ -149,14 +147,14 @@ TEST(HashedWString, Functionalities) {
|
|
|
|
|
|
const entt::hashed_wstring hws{L"foobar"};
|
|
|
|
|
|
- ASSERT_EQ(static_cast<hash_type>(hws), expected_v);
|
|
|
- ASSERT_EQ(hws.value(), expected_v);
|
|
|
+ ASSERT_EQ(static_cast<hash_type>(hws), expected());
|
|
|
+ ASSERT_EQ(hws.value(), expected());
|
|
|
|
|
|
ASSERT_EQ(foo_hws, L"foo"_hws);
|
|
|
ASSERT_NE(bar_hws, L"foo"_hws);
|
|
|
}
|
|
|
|
|
|
-TEST(HashedWString, Empty) {
|
|
|
+TEST_F(HashedWString, Empty) {
|
|
|
using hash_type = entt::hashed_wstring::hash_type;
|
|
|
|
|
|
const entt::hashed_wstring hws{};
|
|
|
@@ -166,24 +164,24 @@ TEST(HashedWString, Empty) {
|
|
|
ASSERT_EQ(static_cast<const wchar_t *>(hws), nullptr);
|
|
|
}
|
|
|
|
|
|
-TEST(HashedWString, Correctness) {
|
|
|
+TEST_F(HashedWString, Correctness) {
|
|
|
const wchar_t *foobar = L"foobar";
|
|
|
const std::wstring_view view{L"foobar__", 6};
|
|
|
|
|
|
- ASSERT_EQ(entt::hashed_wstring{foobar}, expected_v);
|
|
|
- ASSERT_EQ((entt::hashed_wstring{view.data(), view.size()}), expected_v);
|
|
|
- ASSERT_EQ(entt::hashed_wstring{L"foobar"}, expected_v);
|
|
|
+ ASSERT_EQ(entt::hashed_wstring{foobar}, expected());
|
|
|
+ ASSERT_EQ((entt::hashed_wstring{view.data(), view.size()}), expected());
|
|
|
+ ASSERT_EQ(entt::hashed_wstring{L"foobar"}, expected());
|
|
|
|
|
|
- ASSERT_EQ(entt::hashed_wstring::value(foobar), expected_v);
|
|
|
- ASSERT_EQ(entt::hashed_wstring::value(view.data(), view.size()), expected_v);
|
|
|
- ASSERT_EQ(entt::hashed_wstring::value(L"foobar"), expected_v);
|
|
|
+ ASSERT_EQ(entt::hashed_wstring::value(foobar), expected());
|
|
|
+ ASSERT_EQ(entt::hashed_wstring::value(view.data(), view.size()), expected());
|
|
|
+ ASSERT_EQ(entt::hashed_wstring::value(L"foobar"), expected());
|
|
|
|
|
|
ASSERT_EQ(entt::hashed_wstring{foobar}.size(), 6u);
|
|
|
ASSERT_EQ((entt::hashed_wstring{view.data(), view.size()}).size(), 6u);
|
|
|
ASSERT_EQ(entt::hashed_wstring{L"foobar"}.size(), 6u);
|
|
|
}
|
|
|
|
|
|
-TEST(HashedWString, Order) {
|
|
|
+TEST_F(HashedWString, Order) {
|
|
|
using namespace entt::literals;
|
|
|
const entt::hashed_wstring lhs = L"foo"_hws;
|
|
|
const entt::hashed_wstring rhs = L"bar"_hws;
|
|
|
@@ -198,21 +196,21 @@ TEST(HashedWString, Order) {
|
|
|
ASSERT_GE(lhs, rhs);
|
|
|
}
|
|
|
|
|
|
-TEST(HashedWString, Constexprness) {
|
|
|
+TEST_F(HashedWString, Constexprness) {
|
|
|
using namespace entt::literals;
|
|
|
constexpr std::wstring_view view{L"foobar__", 6};
|
|
|
|
|
|
ASSERT_EQ(entt::hashed_wstring{L"quux"}, L"quux"_hws);
|
|
|
- ASSERT_EQ(entt::hashed_wstring{L"foobar"}, expected_v);
|
|
|
+ ASSERT_EQ(entt::hashed_wstring{L"foobar"}, expected());
|
|
|
|
|
|
ASSERT_EQ(entt::hashed_wstring::value(L"quux"), L"quux"_hws);
|
|
|
- ASSERT_EQ(entt::hashed_wstring::value(L"foobar"), expected_v);
|
|
|
+ ASSERT_EQ(entt::hashed_wstring::value(L"foobar"), expected());
|
|
|
|
|
|
ASSERT_EQ((entt::hashed_wstring{L"quux", 4}), L"quux"_hws);
|
|
|
- ASSERT_EQ((entt::hashed_wstring{view.data(), view.size()}), expected_v);
|
|
|
+ ASSERT_EQ((entt::hashed_wstring{view.data(), view.size()}), expected());
|
|
|
|
|
|
ASSERT_EQ((entt::hashed_wstring::value(L"quux", 4)), L"quux"_hws);
|
|
|
- ASSERT_EQ((entt::hashed_wstring::value(view.data(), view.size())), expected_v);
|
|
|
+ ASSERT_EQ((entt::hashed_wstring::value(view.data(), view.size())), expected());
|
|
|
|
|
|
ASSERT_LT(entt::hashed_wstring{L"bar"}, L"foo"_hws);
|
|
|
ASSERT_LE(entt::hashed_wstring{L"bar"}, L"bar"_hws);
|