From bf692a4bfae3c8d90aefcd09b55e3fcf45dda543 Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 28 Jan 2022 03:27:10 +0100 Subject: [PATCH] Add more tests for fixed string --- .../esm/test_fixed_string.cpp | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/apps/openmw_test_suite/esm/test_fixed_string.cpp b/apps/openmw_test_suite/esm/test_fixed_string.cpp index bd598cc932..b59f19e7bb 100644 --- a/apps/openmw_test_suite/esm/test_fixed_string.cpp +++ b/apps/openmw_test_suite/esm/test_fixed_string.cpp @@ -105,3 +105,46 @@ TEST(EsmFixedString, is_pod) ASSERT_TRUE(std::is_pod::value); ASSERT_TRUE(std::is_pod::value); } + +TEST(EsmFixedString, assign_should_zero_untouched_bytes_for_4) +{ + ESM::NAME value; + value = static_cast(0xFFFFFFFFu); + value.assign(std::string(1, 'a')); + EXPECT_EQ(value, static_cast('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(0xFEDCBA98u); + EXPECT_EQ(value, static_cast(0xFEDCBA98u)) << value.toInt(); +}