From 6f329f3d40fa5828cf341fa7efd727cb52c24cd9 Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 3 Mar 2023 13:53:50 +0100 Subject: [PATCH] Add tests for ESM::RefId --- apps/openmw_test_suite/CMakeLists.txt | 1 + apps/openmw_test_suite/esm/testrefid.cpp | 126 +++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 apps/openmw_test_suite/esm/testrefid.cpp diff --git a/apps/openmw_test_suite/CMakeLists.txt b/apps/openmw_test_suite/CMakeLists.txt index 4fe4cde9d0..ae5723cd25 100644 --- a/apps/openmw_test_suite/CMakeLists.txt +++ b/apps/openmw_test_suite/CMakeLists.txt @@ -23,6 +23,7 @@ file(GLOB UNITTEST_SRC_FILES esm/test_fixed_string.cpp esm/variant.cpp + esm/testrefid.cpp lua/test_lua.cpp lua/test_scriptscontainer.cpp diff --git a/apps/openmw_test_suite/esm/testrefid.cpp b/apps/openmw_test_suite/esm/testrefid.cpp new file mode 100644 index 0000000000..08f4b4256b --- /dev/null +++ b/apps/openmw_test_suite/esm/testrefid.cpp @@ -0,0 +1,126 @@ +#include + +#include + +#include +#include + +namespace ESM +{ + namespace + { + using namespace ::testing; + + TEST(ESMRefIdTest, defaultConstructedIsEmpty) + { + const RefId refId; + EXPECT_TRUE(refId.empty()); + } + + TEST(ESMRefIdTest, stringRefIdIsNotEmpty) + { + const RefId refId = RefId::stringRefId("ref_id"); + EXPECT_FALSE(refId.empty()); + } + + TEST(ESMRefIdTest, formIdRefIdIsNotEmpty) + { + const RefId refId = RefId::formIdRefId(42); + EXPECT_FALSE(refId.empty()); + } + + TEST(ESMRefIdTest, defaultConstructedIsEqualToItself) + { + const RefId refId; + EXPECT_EQ(refId, refId); + } + + TEST(ESMRefIdTest, defaultConstructedIsEqualToDefaultConstructed) + { + const RefId a; + const RefId b; + EXPECT_EQ(a, b); + } + + TEST(ESMRefIdTest, defaultConstructedIsNotEqualToDebugStringRefId) + { + const RefId a; + const RefId b = RefId::stringRefId("b"); + EXPECT_NE(a, b); + } + + TEST(ESMRefIdTest, defaultConstructedIsNotEqualToFormIdRefId) + { + const RefId a; + const RefId b = RefId::formIdRefId(42); + EXPECT_NE(a, b); + } + + TEST(ESMRefIdTest, defaultConstructedIsNotEqualToDebugStringLiteral) + { + const RefId a; + EXPECT_NE(a, "foo"); + } + + TEST(ESMRefIdTest, stringRefIdIsEqualToTheSameStringLiteralValue) + { + const RefId refId = RefId::stringRefId("ref_id"); + EXPECT_EQ(refId, "ref_id"); + } + + TEST(ESMRefIdTest, stringRefIdIsCaseInsensitiveEqualToTheSameStringLiteralValue) + { + const RefId refId = RefId::stringRefId("ref_id"); + EXPECT_EQ(refId, "REF_ID"); + } + + TEST(ESMRefIdTest, stringRefIdIsEqualToTheSameStringRefId) + { + const RefId a = RefId::stringRefId("ref_id"); + const RefId b = RefId::stringRefId("ref_id"); + EXPECT_EQ(a, b); + } + + TEST(ESMRefIdTest, stringRefIdIsCaseInsensitiveEqualToTheSameStringRefId) + { + const RefId lower = RefId::stringRefId("ref_id"); + const RefId upper = RefId::stringRefId("REF_ID"); + EXPECT_EQ(lower, upper); + } + + TEST(ESMRefIdTest, stringRefIdIsEqualToItself) + { + const RefId refId = RefId::stringRefId("ref_id"); + EXPECT_EQ(refId, refId); + } + + TEST(ESMRefIdTest, stringRefIdIsCaseInsensitiveLessByContent) + { + const RefId a = RefId::stringRefId("a"); + const RefId b = RefId::stringRefId("B"); + EXPECT_LT(a, b); + } + + TEST(ESMRefIdTest, stringRefIdHasCaseInsensitiveHash) + { + const RefId lower = RefId::stringRefId("a"); + const RefId upper = RefId::stringRefId("A"); + const std::hash hash; + EXPECT_EQ(hash(lower), hash(upper)); + } + + TEST(ESMRefIdTest, hasCaseInsensitiveEqualityWithStringView) + { + const RefId a = RefId::stringRefId("a"); + const std::string_view b = "A"; + EXPECT_EQ(a, b); + } + + TEST(ESMRefIdTest, hasCaseInsensitiveLessWithStringView) + { + const RefId a = RefId::stringRefId("a"); + const std::string_view b = "B"; + EXPECT_LT(a, b); + } + } +}