summaryrefslogtreecommitdiff
path: root/libutils/String8_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2021-06-10 16:42:20 -0700
committerElliott Hughes <enh@google.com>2021-06-10 16:42:20 -0700
commit59682761fb4ea24b91292bc53cfe9fbf5e3cfc63 (patch)
treeb0908677474a373189fdca003eb4f9eee1b5cafc /libutils/String8_test.cpp
parent8f654d8a99738d096e2a7bf87324a515ec0c33bc (diff)
Check for overflow in String8::real_append.
Bug: http://b/178822418 Test: new tests Change-Id: I73631a070ade0689441abe5645ba5a5f64a58675
Diffstat (limited to 'libutils/String8_test.cpp')
-rw-r--r--libutils/String8_test.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/libutils/String8_test.cpp b/libutils/String8_test.cpp
index 9efcc6fa4..1356cd08f 100644
--- a/libutils/String8_test.cpp
+++ b/libutils/String8_test.cpp
@@ -15,13 +15,14 @@
*/
#define LOG_TAG "String8_test"
+
#include <utils/Log.h>
#include <utils/String8.h>
#include <utils/String16.h>
#include <gtest/gtest.h>
-namespace android {
+using namespace android;
class String8Test : public testing::Test {
protected:
@@ -101,4 +102,15 @@ TEST_F(String8Test, ValidUtf16Conversion) {
String8 valid = String8(String16(tmp));
EXPECT_STREQ(valid, "abcdef");
}
+
+TEST_F(String8Test, append) {
+ String8 s;
+ EXPECT_EQ(OK, s.append("foo"));
+ EXPECT_STREQ("foo", s);
+ EXPECT_EQ(OK, s.append("bar"));
+ EXPECT_STREQ("foobar", s);
+ EXPECT_EQ(OK, s.append("baz", 0));
+ EXPECT_STREQ("foobar", s);
+ EXPECT_EQ(NO_MEMORY, s.append("baz", SIZE_MAX));
+ EXPECT_STREQ("foobar", s);
}