From 0e39de88f304ad5d8f01d2bd44dc63f165e788cb Mon Sep 17 00:00:00 2001 From: Jianfeng Tang Date: Wed, 14 Dec 2022 09:40:49 -0800 Subject: [PATCH] Add unit test for BufQueue::clone Summary: As titled. Reviewed By: afrind Differential Revision: D42036127 fbshipit-source-id: ae7fa598bd233e14261011be62de7e25f7d16ca2 --- quic/common/test/BufUtilTest.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/quic/common/test/BufUtilTest.cpp b/quic/common/test/BufUtilTest.cpp index db471c81e..8f5ac83dc 100644 --- a/quic/common/test/BufUtilTest.cpp +++ b/quic/common/test/BufUtilTest.cpp @@ -176,6 +176,28 @@ TEST(BufQueue, TrimStartAtMost) { checkConsistency(queue); } +TEST(BufQueue, CloneBufNull) { + BufQueue queue; + auto buf = queue.clone(); + EXPECT_EQ(nullptr, buf); +} + +TEST(BufQueue, CloneBuf) { + std::string s("Hello, World"); + BufQueue queue; + queue.append(IOBuf::copyBuffer(s.data(), s.length())); + auto buf = queue.clone(); + const IOBuf* chain = queue.front(); + EXPECT_EQ(s.length(), chain->computeChainDataLength()); + EXPECT_EQ(s.length(), buf->computeChainDataLength()); + EXPECT_EQ(0, memcmp(chain->data(), buf->data(), s.length())); + queue.append(IOBuf::copyBuffer(s.data(), s.length())); + EXPECT_EQ(2 * s.length(), chain->computeChainDataLength()); + EXPECT_EQ(s.length(), buf->computeChainDataLength()); + buf = queue.clone(); + EXPECT_EQ(2 * s.length(), buf->computeChainDataLength()); +} + TEST(BufAppender, TestPushAlreadyFits) { std::unique_ptr data = folly::IOBuf::create(10); BufAppender appender(data.get(), 10);