Преглед изворни кода

test: make tests for hashed string work when id_type is std::uint64_t

Michele Caini пре 4 година
родитељ
комит
9090f84611
1 измењених фајлова са 31 додато и 16 уклоњено
  1. 31 16
      test/entt/core/hashed_string.cpp

+ 31 - 16
test/entt/core/hashed_string.cpp

@@ -4,6 +4,21 @@
 #include <gtest/gtest.h>
 #include <entt/core/hashed_string.hpp>
 
+template<typename>
+struct foobar_t;
+
+template<>
+struct foobar_t<std::uint32_t> {
+    static constexpr auto value = 0xbf9cf968;
+};
+
+template<>
+struct foobar_t<std::uint64_t> {
+    static constexpr auto value = 0x85944171f73967e8;
+};
+
+inline constexpr auto foobar_v = foobar_t<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>);
@@ -29,8 +44,8 @@ TEST(HashedString, Functionalities) {
 
     entt::hashed_string hs{"foobar"};
 
-    ASSERT_EQ(static_cast<hash_type>(hs), 0xbf9cf968);
-    ASSERT_EQ(hs.value(), 0xbf9cf968);
+    ASSERT_EQ(static_cast<hash_type>(hs), foobar_v);
+    ASSERT_EQ(hs.value(), foobar_v);
 
     ASSERT_EQ(foo_hs, "foo"_hs);
     ASSERT_NE(bar_hs, "foo"_hs);
@@ -59,9 +74,9 @@ TEST(HashedString, Correctness) {
     const char *foobar = "foobar";
     std::string_view view{"foobar__", 6};
 
-    ASSERT_EQ(entt::hashed_string{foobar}, 0xbf9cf968);
-    ASSERT_EQ(entt::hashed_string::value(foobar), 0xbf9cf968);
-    ASSERT_EQ(entt::hashed_string::value(view.data(), view.size()), 0xbf9cf968);
+    ASSERT_EQ(entt::hashed_string{foobar}, foobar_v);
+    ASSERT_EQ(entt::hashed_string::value(foobar), foobar_v);
+    ASSERT_EQ(entt::hashed_string::value(view.data(), view.size()), foobar_v);
 }
 
 TEST(HashedString, Constexprness) {
@@ -69,13 +84,13 @@ TEST(HashedString, Constexprness) {
     constexpr std::string_view view{"foobar__", 6};
 
     static_assert(entt::hashed_string{"quux"} == "quux"_hs);
-    static_assert(entt::hashed_string{"foobar"} == 0xbf9cf968);
+    static_assert(entt::hashed_string{"foobar"} == foobar_v);
 
     static_assert(entt::hashed_string::value("quux") == "quux"_hs);
-    static_assert(entt::hashed_string::value("foobar") == 0xbf9cf968);
+    static_assert(entt::hashed_string::value("foobar") == foobar_v);
 
     static_assert(entt::hashed_string::value("quux", 4) == "quux"_hs);
-    static_assert(entt::hashed_string::value(view.data(), view.size()) == 0xbf9cf968);
+    static_assert(entt::hashed_string::value(view.data(), view.size()) == foobar_v);
 }
 
 TEST(HashedWString, Functionalities) {
@@ -98,8 +113,8 @@ TEST(HashedWString, Functionalities) {
 
     entt::hashed_wstring hws{L"foobar"};
 
-    ASSERT_EQ(static_cast<hash_type>(hws), 0xbf9cf968);
-    ASSERT_EQ(hws.value(), 0xbf9cf968);
+    ASSERT_EQ(static_cast<hash_type>(hws), foobar_v);
+    ASSERT_EQ(hws.value(), foobar_v);
 
     ASSERT_EQ(foo_hws, L"foo"_hws);
     ASSERT_NE(bar_hws, L"foo"_hws);
@@ -118,9 +133,9 @@ TEST(HashedWString, Correctness) {
     const wchar_t *foobar = L"foobar";
     std::wstring_view view{L"foobar__", 6};
 
-    ASSERT_EQ(entt::hashed_wstring{foobar}, 0xbf9cf968);
-    ASSERT_EQ(entt::hashed_wstring::value(foobar), 0xbf9cf968);
-    ASSERT_EQ(entt::hashed_wstring::value(view.data(), view.size()), 0xbf9cf968);
+    ASSERT_EQ(entt::hashed_wstring{foobar}, foobar_v);
+    ASSERT_EQ(entt::hashed_wstring::value(foobar), foobar_v);
+    ASSERT_EQ(entt::hashed_wstring::value(view.data(), view.size()), foobar_v);
 }
 
 TEST(HashedWString, Constexprness) {
@@ -128,11 +143,11 @@ TEST(HashedWString, Constexprness) {
     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"} == 0xbf9cf968);
+    static_assert(entt::hashed_wstring{L"foobar"} == foobar_v);
 
     static_assert(entt::hashed_wstring::value(L"quux") == L"quux"_hws);
-    static_assert(entt::hashed_wstring::value(L"foobar") == 0xbf9cf968);
+    static_assert(entt::hashed_wstring::value(L"foobar") == foobar_v);
 
     static_assert(entt::hashed_wstring::value(L"quux", 4) == L"quux"_hws);
-    static_assert(entt::hashed_wstring::value(view.data(), view.size()) == 0xbf9cf968);
+    static_assert(entt::hashed_wstring::value(view.data(), view.size()) == foobar_v);
 }