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

Unified Diff: base/pickle_unittest.cc

Issue 1524613002: [mojo] Use base::Pickle for Message storage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: happy compiler happy robots Created 5 years 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') | mojo/public/cpp/bindings/BUILD.gn » ('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 f58e7eceaf45c9bee7c1729f0913b197c0fa3c47..6804614d9fadca6e3c42feb471ea7e04d43b7261 100644
--- a/base/pickle_unittest.cc
+++ b/base/pickle_unittest.cc
@@ -524,4 +524,50 @@ TEST(PickleTest, DeepCopyResize) {
EXPECT_EQ(pickle.capacity_after_header(), pickle2.capacity_after_header());
}
+namespace {
+
+// Publicly exposes the ClaimBytes interface for testing.
+class TestingPickle : public Pickle {
+ public:
+ TestingPickle() {}
+
+ void* ClaimBytes(size_t num_bytes) { return Pickle::ClaimBytes(num_bytes); }
+};
+
+} // namespace
+
+// Checks that claimed bytes are zero-initialized.
+TEST(PickleTest, ClaimBytesInitialization) {
+ static const int kChunkSize = 64;
+ TestingPickle pickle;
+ const char* bytes = static_cast<const char*>(pickle.ClaimBytes(kChunkSize));
+ for (size_t i = 0; i < kChunkSize; ++i) {
+ EXPECT_EQ(0, bytes[i]);
+ }
+}
+
+// Checks that ClaimBytes properly advances the write offset.
+TEST(PickleTest, ClaimBytes) {
+ std::string data("Hello, world!");
+
+ TestingPickle pickle;
+ pickle.WriteSizeT(data.size());
+ void* bytes = pickle.ClaimBytes(data.size());
+ pickle.WriteInt(42);
+ memcpy(bytes, data.data(), data.size());
+
+ PickleIterator iter(pickle);
+ size_t out_data_length;
+ EXPECT_TRUE(iter.ReadSizeT(&out_data_length));
+ EXPECT_EQ(data.size(), out_data_length);
+
+ const char* out_data = nullptr;
+ EXPECT_TRUE(iter.ReadBytes(&out_data, out_data_length));
+ EXPECT_EQ(data, std::string(out_data, out_data_length));
+
+ int out_value;
+ EXPECT_TRUE(iter.ReadInt(&out_value));
+ EXPECT_EQ(42, out_value);
+}
+
} // namespace base
« no previous file with comments | « base/pickle.cc ('k') | mojo/public/cpp/bindings/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698