Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6bcbeeaf authored by Devin Moore's avatar Devin Moore Committed by Steven Moreland
Browse files

libutils: add unit tests for invalid utf-8 and utf-16 strings

Characters get dropped during the conversionis between 8 and 16.

Test: atest libutils_test
Change-Id: Ie76dd38e97968137555ba2ab7ce188c9122ed06e
parent dd5184f8
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -215,4 +215,16 @@ TEST(String16Test, EmptyStringIsStatic) {
    EXPECT_TRUE(tmp.isStaticString());
}

TEST(String16Test, OverreadUtf8Conversion) {
    char tmp[] = {'a', static_cast<char>(0xe0), '\0'};
    String16 another(tmp);
    EXPECT_TRUE(another.size() == 0);
}

TEST(String16Test, ValidUtf8Conversion) {
    String16 another("abcdef");
    EXPECT_EQ(6U, another.size());
    EXPECT_STR16EQ(another, u"abcdef");
}

}  // namespace android
+5 −0
Original line number Diff line number Diff line
@@ -96,4 +96,9 @@ TEST_F(String8Test, CheckUtf32Conversion) {
    EXPECT_EQ(10U, string8.length());
}

TEST_F(String8Test, ValidUtf16Conversion) {
    char16_t tmp[] = u"abcdef";
    String8 valid = String8(String16(tmp));
    EXPECT_STREQ(valid, "abcdef");
}
}