mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 16:29:55 +00:00
Add unit tests for ESM::FIXED_STRING
This commit is contained in:
parent
d5dfa89060
commit
5ae1864062
2 changed files with 77 additions and 0 deletions
|
@ -9,6 +9,8 @@ if (GTEST_FOUND)
|
|||
mwworld/test_store.cpp
|
||||
|
||||
mwdialogue/test_keywordsearch.cpp
|
||||
|
||||
esm/test_fixed_string.cpp
|
||||
)
|
||||
|
||||
source_group(apps\\openmw_test_suite FILES openmw_test_suite.cpp ${UNITTEST_SRC_FILES})
|
||||
|
|
75
apps/openmw_test_suite/esm/test_fixed_string.cpp
Normal file
75
apps/openmw_test_suite/esm/test_fixed_string.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "components/esm/esmcommon.hpp"
|
||||
|
||||
TEST(EsmFixedString, operator__eq_ne)
|
||||
{
|
||||
{
|
||||
SCOPED_TRACE("asdc == asdc");
|
||||
ESM::NAME name;
|
||||
name.assign("asdc");
|
||||
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");
|
||||
ESM::NAME name;
|
||||
name.assign("asdc");
|
||||
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]");
|
||||
ESM::NAME name;
|
||||
name.assign("asdc");
|
||||
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)
|
||||
{
|
||||
{
|
||||
SCOPED_TRACE("4 bytes");
|
||||
ESM::NAME empty = ESM::NAME();
|
||||
EXPECT_TRUE(empty == "");
|
||||
EXPECT_TRUE(empty == static_cast<uint32_t>(0));
|
||||
EXPECT_TRUE(empty != "some string");
|
||||
EXPECT_TRUE(empty != static_cast<uint32_t>(42));
|
||||
}
|
||||
{
|
||||
SCOPED_TRACE("32 bytes");
|
||||
ESM::NAME32 empty = ESM::NAME32();
|
||||
EXPECT_TRUE(empty == "");
|
||||
EXPECT_TRUE(empty != "some string");
|
||||
}
|
||||
}
|
||||
|
||||
TEST(EsmFixedString, struct_size)
|
||||
{
|
||||
ASSERT_EQ(4, sizeof(ESM::NAME));
|
||||
ASSERT_EQ(32, sizeof(ESM::NAME32));
|
||||
ASSERT_EQ(64, sizeof(ESM::NAME64));
|
||||
ASSERT_EQ(256, sizeof(ESM::NAME256));
|
||||
}
|
||||
|
||||
TEST(EsmFixedString, DISABLED_is_pod)
|
||||
{
|
||||
/* TODO: enable in C++11
|
||||
* ASSERT_TRUE(std::is_pod<ESM::NAME>::value);
|
||||
* ASSERT_TRUE(std::is_pod<ESM::NAME32>::value);
|
||||
* ASSERT_TRUE(std::is_pod<ESM::NAME64>::value);
|
||||
* ASSERT_TRUE(std::is_pod<ESM::NAME256>::value);
|
||||
*/
|
||||
}
|
Loading…
Reference in a new issue