Make sure that proper operator function is used for char[N] argument

pull/541/head
Azdul 6 years ago
parent 9f716b9ed8
commit 7940317e42

@ -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)
{

@ -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<typename T, typename = typename std::enable_if<std::is_same<T, char>::value>::type>
bool operator==(const T* const& str) const
{
char const* const data = self()->ro_data();
for(size_t i = 0; i < size; ++i)

Loading…
Cancel
Save