Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3072)

Unified Diff: base/pickle_unittest.cc

Issue 987033003: Adding StringPiece read/write support to pickle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/pickle.cc ('k') | ipc/ipc_perftest_support.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/pickle_unittest.cc
diff --git a/base/pickle_unittest.cc b/base/pickle_unittest.cc
index 1fa1f32d49c736548ec36bbb8ac0aeb32c46b28c..466d32ad86705d15541c1c9cda3e6055e849372d 100644
--- a/base/pickle_unittest.cc
+++ b/base/pickle_unittest.cc
@@ -30,10 +30,13 @@ const double testdouble = 2.71828182845904523;
const std::string teststring("Hello world"); // note non-aligned string length
const std::wstring testwstring(L"Hello, world");
const base::string16 teststring16(base::ASCIIToUTF16("Hello, world"));
+const char testrawstring[] = "Hello new world"; // Test raw string writing
+// Test raw char16 writing, assumes UTF16 encoding is ANSI for alpha chars.
+const base::char16 testrawstring16[] = {'A', 'l', 'o', 'h', 'a', 0};
const char testdata[] = "AAA\0BBB\0";
const int testdatalen = arraysize(testdata) - 1;
-// checks that the result
+// checks that the results can be read correctly from the Pickle
void VerifyResult(const Pickle& pickle) {
PickleIterator iter(pickle);
@@ -91,6 +94,14 @@ void VerifyResult(const Pickle& pickle) {
EXPECT_TRUE(iter.ReadString16(&outstring16));
EXPECT_EQ(teststring16, outstring16);
+ base::StringPiece outstringpiece;
+ EXPECT_TRUE(iter.ReadStringPiece(&outstringpiece));
+ EXPECT_EQ(testrawstring, outstringpiece);
+
+ base::StringPiece16 outstringpiece16;
+ EXPECT_TRUE(iter.ReadStringPiece16(&outstringpiece16));
+ EXPECT_EQ(testrawstring16, outstringpiece16);
+
const char* outdata;
int outdatalen;
EXPECT_TRUE(iter.ReadData(&outdata, &outdatalen));
@@ -121,6 +132,8 @@ TEST(PickleTest, EncodeDecode) {
EXPECT_TRUE(pickle.WriteString(teststring));
EXPECT_TRUE(pickle.WriteWString(testwstring));
EXPECT_TRUE(pickle.WriteString16(teststring16));
+ EXPECT_TRUE(pickle.WriteString(testrawstring));
+ EXPECT_TRUE(pickle.WriteString16(testrawstring16));
EXPECT_TRUE(pickle.WriteData(testdata, testdatalen));
VerifyResult(pickle);
« no previous file with comments | « base/pickle.cc ('k') | ipc/ipc_perftest_support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698