From e48596dc6c61e63ee80a67730f56d405e4d3e8c7 Mon Sep 17 00:00:00 2001 From: TsFreddie Date: Sun, 6 Sep 2020 23:57:21 +0100 Subject: [PATCH] Add test cases --- src/test/str.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/test/str.cpp b/src/test/str.cpp index 5785a334b..7da9bf0e8 100644 --- a/src/test/str.cpp +++ b/src/test/str.cpp @@ -208,3 +208,29 @@ TEST(Str, StrCopyNum) str_utf8_truncate(aBuf3, sizeof(aBuf3), foo, 7); EXPECT_STREQ(aBuf3, "Foobaré"); } + +TEST(Str, StrCopyUtf8) +{ + const char *foo = "DDNet最好了"; + char aBuf[64]; + str_utf8_copy(aBuf, foo, 7); + EXPECT_STREQ(aBuf, "DDNet"); + str_utf8_copy(aBuf, foo, 8); + EXPECT_STREQ(aBuf, "DDNet"); + str_utf8_copy(aBuf, foo, 9); + EXPECT_STREQ(aBuf, "DDNet"); + str_utf8_copy(aBuf, foo, 10); + EXPECT_STREQ(aBuf, "DDNet最"); + str_utf8_copy(aBuf, foo, 11); + EXPECT_STREQ(aBuf, "DDNet最"); + str_utf8_copy(aBuf, foo, 12); + EXPECT_STREQ(aBuf, "DDNet最"); + str_utf8_copy(aBuf, foo, 13); + EXPECT_STREQ(aBuf, "DDNet最好"); + str_utf8_copy(aBuf, foo, 14); + EXPECT_STREQ(aBuf, "DDNet最好"); + str_utf8_copy(aBuf, foo, 15); + EXPECT_STREQ(aBuf, "DDNet最好"); + str_utf8_copy(aBuf, foo, 16); + EXPECT_STREQ(aBuf, "DDNet最好了"); +}