Fix broken ByteBuffer copy ctor

pull/15517/head
Ara Ayvazyan 7 years ago
parent 18ce0cf26e
commit 8d06d097bc
  1. 5
      src/cpp/util/byte_buffer_cc.cc
  2. 7
      test/cpp/util/byte_buffer_test.cc

@ -43,8 +43,9 @@ Status ByteBuffer::Dump(std::vector<Slice>* slices) const {
return Status::OK; return Status::OK;
} }
ByteBuffer::ByteBuffer(const ByteBuffer& buf) ByteBuffer::ByteBuffer(const ByteBuffer& buf) : buffer_(nullptr) {
: buffer_(grpc_byte_buffer_copy(buf.buffer_)) {} operator=(buf);
}
ByteBuffer& ByteBuffer::operator=(const ByteBuffer& buf) { ByteBuffer& ByteBuffer::operator=(const ByteBuffer& buf) {
if (this != &buf) { if (this != &buf) {

@ -38,6 +38,13 @@ const char* kContent2 = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy world";
class ByteBufferTest : public ::testing::Test {}; class ByteBufferTest : public ::testing::Test {};
TEST_F(ByteBufferTest, CopyCtor) {
ByteBuffer buffer1;
EXPECT_FALSE(buffer1.Valid());
ByteBuffer buffer2 = buffer1;
EXPECT_FALSE(buffer2.Valid());
}
TEST_F(ByteBufferTest, CreateFromSingleSlice) { TEST_F(ByteBufferTest, CreateFromSingleSlice) {
Slice s(kContent1); Slice s(kContent1);
ByteBuffer buffer(&s, 1); ByteBuffer buffer(&s, 1);

Loading…
Cancel
Save