diff --git a/apps/openmw_test_suite/esm/test_fixed_string.cpp b/apps/openmw_test_suite/esm/test_fixed_string.cpp index 89a390ff6..dc88a5f63 100644 --- a/apps/openmw_test_suite/esm/test_fixed_string.cpp +++ b/apps/openmw_test_suite/esm/test_fixed_string.cpp @@ -37,6 +37,42 @@ TEST(EsmFixedString, operator__eq_ne) EXPECT_TRUE(name == ss); } } +TEST(EsmFixedString, operator__eq_ne_const) +{ + { + SCOPED_TRACE("asdc == asdc (const)"); + ESM::NAME name; + name.assign("asdc"); + const char s[4] = { 'a', 's', 'd', 'c' }; + std::string ss(s, 4); + + EXPECT_TRUE(name == s); + EXPECT_TRUE(name == ss.c_str()); + EXPECT_TRUE(name == ss); + } + { + SCOPED_TRACE("asdc == asdcx (const)"); + ESM::NAME name; + name.assign("asdc"); + const char s[5] = { 'a', 's', 'd', 'c', 'x' }; + std::string ss(s, 5); + + EXPECT_TRUE(name != s); + EXPECT_TRUE(name != ss.c_str()); + EXPECT_TRUE(name != ss); + } + { + SCOPED_TRACE("asdc == asdc[NULL] (const)"); + ESM::NAME name; + name.assign("asdc"); + const char s[5] = { 'a', 's', 'd', 'c', '\0' }; + std::string ss(s, 5); + + EXPECT_TRUE(name == s); + EXPECT_TRUE(name == ss.c_str()); + EXPECT_TRUE(name == ss); + } +} TEST(EsmFixedString, empty_strings) { diff --git a/components/esm/esmcommon.hpp b/components/esm/esmcommon.hpp index d635ba6df..97ce88556 100644 --- a/components/esm/esmcommon.hpp +++ b/components/esm/esmcommon.hpp @@ -35,7 +35,10 @@ public: return false; return std::strncmp(self()->ro_data(), str, size) == 0; } - bool operator==(const char* const str) const + + //this operator will not be used for char[N], only for char* + template::value>::type> + bool operator==(const T* const& str) const { char const* const data = self()->ro_data(); for(size_t i = 0; i < size; ++i)