1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

Add more tests for fixed string

This commit is contained in:
elsid 2022-01-28 03:27:10 +01:00
parent 3877d227f4
commit bf692a4bfa
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

View File

@ -105,3 +105,46 @@ TEST(EsmFixedString, is_pod)
ASSERT_TRUE(std::is_pod<ESM::NAME32>::value);
ASSERT_TRUE(std::is_pod<ESM::NAME64>::value);
}
TEST(EsmFixedString, assign_should_zero_untouched_bytes_for_4)
{
ESM::NAME value;
value = static_cast<uint32_t>(0xFFFFFFFFu);
value.assign(std::string(1, 'a'));
EXPECT_EQ(value, static_cast<uint32_t>('a')) << value.toInt();
}
TEST(EsmFixedString, assign_should_only_truncate_for_4)
{
ESM::NAME value;
value.assign(std::string(5, 'a'));
EXPECT_EQ(value, std::string(4, 'a'));
}
TEST(EsmFixedString, assign_should_truncate_and_set_last_element_to_zero)
{
ESM::FIXED_STRING<17> value;
value.assign(std::string(20, 'a'));
EXPECT_EQ(value, std::string(16, 'a'));
}
TEST(EsmFixedString, assign_should_truncate_and_set_last_element_to_zero_for_32)
{
ESM::NAME32 value;
value.assign(std::string(33, 'a'));
EXPECT_EQ(value, std::string(31, 'a'));
}
TEST(EsmFixedString, assign_should_truncate_and_set_last_element_to_zero_for_64)
{
ESM::NAME64 value;
value.assign(std::string(65, 'a'));
EXPECT_EQ(value, std::string(63, 'a'));
}
TEST(EsmFixedString, assignment_operator_is_supported_for_uint32)
{
ESM::NAME value;
value = static_cast<uint32_t>(0xFEDCBA98u);
EXPECT_EQ(value, static_cast<uint32_t>(0xFEDCBA98u)) << value.toInt();
}