aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/util/byte_buffer_test.cc
diff options
context:
space:
mode:
authorGravatar yang-g <yangg@google.com>2016-03-21 14:04:10 -0700
committerGravatar yang-g <yangg@google.com>2016-03-21 14:04:10 -0700
commitf64befd27fb08104fb5d1a7006d4f8ac08510f8f (patch)
tree25ee2dcae1d7e601aa660deae5ae8b35f4e9aa02 /test/cpp/util/byte_buffer_test.cc
parentfb6e13b1b5ba135220c7be1edf3fb6f92e79872b (diff)
Make a copy of ByteBuffer when writing
Diffstat (limited to 'test/cpp/util/byte_buffer_test.cc')
-rw-r--r--test/cpp/util/byte_buffer_test.cc20
1 files changed, 19 insertions, 1 deletions
diff --git a/test/cpp/util/byte_buffer_test.cc b/test/cpp/util/byte_buffer_test.cc
index f36c32cac5..eb9dabcc2a 100644
--- a/test/cpp/util/byte_buffer_test.cc
+++ b/test/cpp/util/byte_buffer_test.cc
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -105,6 +105,24 @@ TEST_F(ByteBufferTest, Dump) {
EXPECT_TRUE(SliceEqual(slices[1], world));
}
+TEST_F(ByteBufferTest, SerializationMakesCopy) {
+ gpr_slice hello = gpr_slice_from_copied_string(kContent1);
+ gpr_slice world = gpr_slice_from_copied_string(kContent2);
+ std::vector<Slice> slices;
+ slices.push_back(Slice(hello, Slice::STEAL_REF));
+ slices.push_back(Slice(world, Slice::STEAL_REF));
+ grpc_byte_buffer* send_buffer = nullptr;
+ bool owned = false;
+ ByteBuffer buffer(&slices[0], 2);
+ slices.clear();
+ auto status = SerializationTraits<ByteBuffer, void>::Serialize(
+ buffer, &send_buffer, &owned);
+ EXPECT_TRUE(status.ok());
+ EXPECT_TRUE(owned);
+ EXPECT_TRUE(send_buffer != nullptr);
+ grpc_byte_buffer_destroy(send_buffer);
+}
+
} // namespace
} // namespace grpc