Add IOBufQueue::wrapBuffer, which handles buffers > 4GB.
[folly.git] / folly / experimental / io / test / IOBufQueueTest.cpp
index 58f727a5e07d59a282580fcde56310a72d75deee..9562c2040bc62c966dbbc4e56e5ed7cee981ce73 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include "folly/experimental/io/IOBufQueue.h"
+#include "folly/Range.h"
 
 #include <gflags/gflags.h>
 #include <gtest/gtest.h>
@@ -25,6 +26,7 @@
 
 using folly::IOBuf;
 using folly::IOBufQueue;
+using folly::StringPiece;
 using std::pair;
 using std::string;
 using std::unique_ptr;
@@ -165,6 +167,20 @@ TEST(IOBufQueue, Preallocate) {
   EXPECT_GE(4096, writable.second);
 }
 
+TEST(IOBufQueue, Wrap) {
+  IOBufQueue queue(clOptions);
+  const char* buf = "hello world goodbye";
+  size_t len = strlen(buf);
+  queue.wrapBuffer(buf, len, 6);
+  auto iob = queue.move();
+  EXPECT_EQ((len - 1) / 6 + 1, iob->countChainElements());
+  iob->unshare();
+  iob->coalesce();
+  EXPECT_EQ(StringPiece(buf),
+            StringPiece(reinterpret_cast<const char*>(iob->data()),
+                        iob->length()));
+}
+
 TEST(IOBufQueue, trim) {
   IOBufQueue queue(clOptions);
   unique_ptr<IOBuf> a = IOBuf::create(4);