summaryrefslogtreecommitdiff
path: root/libutils/String16_test.cpp
diff options
context:
space:
mode:
authorDevin Moore <devinmoore@google.com>2020-10-21 17:25:42 -0700
committerSteven Moreland <smoreland@google.com>2020-11-10 02:54:39 +0000
commit6bcbeeafba41ff55e400464be199c4871223fc45 (patch)
tree586e3f5c9b2814617a47c859b49c7e8cda4b14f3 /libutils/String16_test.cpp
parentdd5184f858b7aafdd388e1773133c0815d865510 (diff)
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
Diffstat (limited to 'libutils/String16_test.cpp')
-rw-r--r--libutils/String16_test.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/libutils/String16_test.cpp b/libutils/String16_test.cpp
index f1f24c394..2505f445d 100644
--- a/libutils/String16_test.cpp
+++ b/libutils/String16_test.cpp
@@ -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