proxygen
IOBufQueueTest.cpp File Reference
#include <folly/io/IOBufQueue.h>
#include <cstring>
#include <iostream>
#include <stdexcept>
#include <folly/Range.h>
#include <folly/portability/GTest.h>

Go to the source code of this file.

Macros

#define SCL(x)   (x), sizeof(x) - 1
 

Functions

 TEST (IOBufQueue, Simple)
 
 TEST (IOBufQueue, Append)
 
 TEST (IOBufQueue, Append2)
 
 TEST (IOBufQueue, AppendStringPiece)
 
 TEST (IOBufQueue, Split)
 
 TEST (IOBufQueue, SplitAtMost)
 
 TEST (IOBufQueue, SplitZero)
 
 TEST (IOBufQueue, Preallocate)
 
 TEST (IOBufQueue, Wrap)
 
 TEST (IOBufQueue, Trim)
 
 TEST (IOBufQueue, TrimStartAtMost)
 
 TEST (IOBufQueue, TrimEndAtMost)
 
 TEST (IOBufQueue, TrimPack)
 
 TEST (IOBufQueue, Prepend)
 
 TEST (IOBufQueue, PopFirst)
 
 TEST (IOBufQueue, AppendToString)
 
 TEST (IOBufQueue, Gather)
 

Macro Definition Documentation

#define SCL (   x)    (x), sizeof(x) - 1

Definition at line 34 of file IOBufQueueTest.cpp.

Referenced by TEST().

Function Documentation

TEST ( IOBufQueue  ,
Simple   
)

Definition at line 62 of file IOBufQueueTest.cpp.

References folly::IOBufQueue::append(), EXPECT_EQ, folly::IOBufQueue::front(), and SCL.

62  {
63  IOBufQueue queue(clOptions);
64  EXPECT_EQ(nullptr, queue.front());
65  queue.append(SCL(""));
66  EXPECT_EQ(nullptr, queue.front());
67  queue.append(unique_ptr<IOBuf>());
68  EXPECT_EQ(nullptr, queue.front());
69  string emptyString;
70  queue.append(emptyString);
71  EXPECT_EQ(nullptr, queue.front());
72 }
#define SCL(x)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( IOBufQueue  ,
Append   
)

Definition at line 74 of file IOBufQueueTest.cpp.

References folly::IOBufQueue::append(), folly::IOBuf::computeChainDataLength(), EXPECT_EQ, EXPECT_NE, folly::IOBufQueue::front(), folly::IOBufQueue::move(), and SCL.

74  {
75  IOBufQueue queue(clOptions);
76  queue.append(SCL("Hello"));
77  IOBufQueue queue2(clOptions);
78  queue2.append(SCL(", "));
79  queue2.append(SCL("World"));
80  checkConsistency(queue);
81  checkConsistency(queue2);
82  queue.append(queue2.move());
83  checkConsistency(queue);
84  checkConsistency(queue2);
85  const IOBuf* chain = queue.front();
86  EXPECT_NE((IOBuf*)nullptr, chain);
87  EXPECT_EQ(12, chain->computeChainDataLength());
88  EXPECT_EQ(nullptr, queue2.front());
89 }
#define SCL(x)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
TEST ( IOBufQueue  ,
Append2   
)

Definition at line 91 of file IOBufQueueTest.cpp.

References folly::IOBufQueue::append(), folly::IOBuf::computeChainDataLength(), EXPECT_EQ, EXPECT_NE, folly::IOBufQueue::front(), and SCL.

91  {
92  IOBufQueue queue(clOptions);
93  queue.append(SCL("Hello"));
94  IOBufQueue queue2(clOptions);
95  queue2.append(SCL(", "));
96  queue2.append(SCL("World"));
97  checkConsistency(queue);
98  checkConsistency(queue2);
99  queue.append(queue2);
100  checkConsistency(queue);
101  checkConsistency(queue2);
102  const IOBuf* chain = queue.front();
103  EXPECT_NE((IOBuf*)nullptr, chain);
104  EXPECT_EQ(12, chain->computeChainDataLength());
105  EXPECT_EQ(nullptr, queue2.front());
106 }
#define SCL(x)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
TEST ( IOBufQueue  ,
AppendStringPiece   
)

Definition at line 108 of file IOBufQueueTest.cpp.

References folly::IOBufQueue::append(), folly::IOBuf::computeChainDataLength(), folly::IOBuf::data(), EXPECT_EQ, folly::IOBufQueue::front(), s, and string.

108  {
109  std::string s("Hello, World");
110  IOBufQueue queue(clOptions);
111  IOBufQueue queue2(clOptions);
112  queue.append(s.data(), s.length());
113  queue2.append(s);
114  checkConsistency(queue);
115  checkConsistency(queue2);
116  const IOBuf* chain = queue.front();
117  const IOBuf* chain2 = queue2.front();
118  EXPECT_EQ(s.length(), chain->computeChainDataLength());
119  EXPECT_EQ(s.length(), chain2->computeChainDataLength());
120  EXPECT_EQ(0, memcmp(chain->data(), chain2->data(), s.length()));
121 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const uint8_t * data() const
Definition: IOBuf.h:499
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
const char * string
Definition: Conv.cpp:212
static set< string > s
TEST ( IOBufQueue  ,
Split   
)

Definition at line 123 of file IOBufQueueTest.cpp.

References folly::IOBufQueue::append(), folly::IOBuf::computeChainDataLength(), EXPECT_EQ, EXPECT_THROW, folly::IOBufQueue::front(), prefix(), SCL, and folly::IOBufQueue::split().

123  {
124  IOBufQueue queue(clOptions);
125  queue.append(stringToIOBuf(SCL("Hello")));
126  queue.append(stringToIOBuf(SCL(",")));
127  queue.append(stringToIOBuf(SCL(" ")));
128  queue.append(stringToIOBuf(SCL("")));
129  queue.append(stringToIOBuf(SCL("World")));
130  checkConsistency(queue);
131  EXPECT_EQ(12, queue.front()->computeChainDataLength());
132 
133  unique_ptr<IOBuf> prefix(queue.split(1));
134  checkConsistency(queue);
135  EXPECT_EQ(1, prefix->computeChainDataLength());
136  EXPECT_EQ(11, queue.front()->computeChainDataLength());
137  prefix = queue.split(2);
138  checkConsistency(queue);
139  EXPECT_EQ(2, prefix->computeChainDataLength());
140  EXPECT_EQ(9, queue.front()->computeChainDataLength());
141  prefix = queue.split(3);
142  checkConsistency(queue);
143  EXPECT_EQ(3, prefix->computeChainDataLength());
144  EXPECT_EQ(6, queue.front()->computeChainDataLength());
145  prefix = queue.split(1);
146  checkConsistency(queue);
147  EXPECT_EQ(1, prefix->computeChainDataLength());
148  EXPECT_EQ(5, queue.front()->computeChainDataLength());
149  prefix = queue.split(5);
150  checkConsistency(queue);
151  EXPECT_EQ(5, prefix->computeChainDataLength());
152  EXPECT_EQ((IOBuf*)nullptr, queue.front());
153 
154  queue.append(stringToIOBuf(SCL("Hello,")));
155  queue.append(stringToIOBuf(SCL(" World")));
156  checkConsistency(queue);
157  EXPECT_THROW({ prefix = queue.split(13); }, std::underflow_error);
158  checkConsistency(queue);
159 }
#define SCL(x)
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
bool prefix(Cursor &c, uint32_t expected)
TEST ( IOBufQueue  ,
SplitAtMost   
)

Definition at line 161 of file IOBufQueueTest.cpp.

References folly::IOBufQueue::append(), folly::IOBufQueue::empty(), EXPECT_EQ, EXPECT_TRUE, SCL, and folly::IOBufQueue::splitAtMost().

161  {
162  IOBufQueue queue(clOptions);
163  queue.append(stringToIOBuf(SCL("Hello,")));
164  queue.append(stringToIOBuf(SCL(" World")));
165  auto buf = queue.splitAtMost(9999);
166  EXPECT_EQ(buf->computeChainDataLength(), 12);
167  EXPECT_TRUE(queue.empty());
168 }
#define SCL(x)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
TEST ( IOBufQueue  ,
SplitZero   
)

Definition at line 170 of file IOBufQueueTest.cpp.

References folly::IOBufQueue::append(), EXPECT_EQ, SCL, and folly::IOBufQueue::split().

170  {
171  IOBufQueue queue(clOptions);
172  queue.append(stringToIOBuf(SCL("Hello world")));
173  auto buf = queue.split(0);
174  EXPECT_EQ(buf->computeChainDataLength(), 0);
175 }
#define SCL(x)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( IOBufQueue  ,
Preallocate   
)

Definition at line 177 of file IOBufQueueTest.cpp.

References folly::IOBufQueue::append(), folly::IOBuf::computeChainDataLength(), EXPECT_EQ, EXPECT_GE, EXPECT_LE, EXPECT_NE, folly::IOBufQueue::front(), folly::IOBufQueue::postallocate(), folly::IOBufQueue::preallocate(), and SCL.

177  {
178  IOBufQueue queue(clOptions);
179  queue.append(string("Hello"));
180  pair<void*, std::size_t> writable = queue.preallocate(2, 64, 64);
181  checkConsistency(queue);
182  EXPECT_NE((void*)nullptr, writable.first);
183  EXPECT_LE(2, writable.second);
184  EXPECT_GE(64, writable.second);
185  memcpy(writable.first, SCL(", "));
186  queue.postallocate(2);
187  checkConsistency(queue);
188  EXPECT_EQ(7, queue.front()->computeChainDataLength());
189  queue.append(SCL("World"));
190  checkConsistency(queue);
191  EXPECT_EQ(12, queue.front()->computeChainDataLength());
192  // There are not 2048 bytes available, this will alloc a new buf
193  writable = queue.preallocate(2048, 4096);
194  checkConsistency(queue);
195  EXPECT_LE(2048, writable.second);
196  // IOBuf allocates more than newAllocationSize, and we didn't cap it
197  EXPECT_GE(writable.second, 4096);
198  queue.postallocate(writable.second);
199  // queue has no empty space, make sure we allocate at least min, even if
200  // newAllocationSize < min
201  writable = queue.preallocate(1024, 1, 1024);
202  checkConsistency(queue);
203  EXPECT_EQ(1024, writable.second);
204 }
#define EXPECT_LE(val1, val2)
Definition: gtest.h:1928
#define SCL(x)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_GE(val1, val2)
Definition: gtest.h:1932
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
Definition: Traits.h:577
TEST ( IOBufQueue  ,
Wrap   
)

Definition at line 206 of file IOBufQueueTest.cpp.

References EXPECT_EQ, folly::IOBufQueue::move(), and folly::IOBufQueue::wrapBuffer().

206  {
207  IOBufQueue queue(clOptions);
208  const char* buf = "hello world goodbye";
209  size_t len = strlen(buf);
210  queue.wrapBuffer(buf, len, 6);
211  auto iob = queue.move();
212  EXPECT_EQ((len - 1) / 6 + 1, iob->countChainElements());
213  iob->unshare();
214  iob->coalesce();
215  EXPECT_EQ(
216  StringPiece(buf),
217  StringPiece(reinterpret_cast<const char*>(iob->data()), iob->length()));
218 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Range< const char * > StringPiece
TEST ( IOBufQueue  ,
Trim   
)

Definition at line 220 of file IOBufQueueTest.cpp.

References a, folly::IOBufQueue::append(), folly::IOBuf::append(), folly::IOBuf::computeChainDataLength(), folly::IOBuf::countChainElements(), EXPECT_EQ, EXPECT_THROW, folly::IOBufQueue::front(), folly::IOBuf::length(), folly::gen::move, folly::IOBuf::prev(), folly::IOBufQueue::trimEnd(), and folly::IOBufQueue::trimStart().

220  {
221  IOBufQueue queue(clOptions);
222  unique_ptr<IOBuf> a = IOBuf::create(4);
223  a->append(4);
224  queue.append(std::move(a));
225  checkConsistency(queue);
226  a = IOBuf::create(6);
227  a->append(6);
228  queue.append(std::move(a));
229  checkConsistency(queue);
230  a = IOBuf::create(8);
231  a->append(8);
232  queue.append(std::move(a));
233  checkConsistency(queue);
234  a = IOBuf::create(10);
235  a->append(10);
236  queue.append(std::move(a));
237  checkConsistency(queue);
238 
239  EXPECT_EQ(4, queue.front()->countChainElements());
240  EXPECT_EQ(28, queue.front()->computeChainDataLength());
241  EXPECT_EQ(4, queue.front()->length());
242 
243  queue.trimStart(1);
244  checkConsistency(queue);
245  EXPECT_EQ(4, queue.front()->countChainElements());
246  EXPECT_EQ(27, queue.front()->computeChainDataLength());
247  EXPECT_EQ(3, queue.front()->length());
248 
249  queue.trimStart(5);
250  checkConsistency(queue);
251  EXPECT_EQ(3, queue.front()->countChainElements());
252  EXPECT_EQ(22, queue.front()->computeChainDataLength());
253  EXPECT_EQ(4, queue.front()->length());
254 
255  queue.trimEnd(1);
256  checkConsistency(queue);
257  EXPECT_EQ(3, queue.front()->countChainElements());
258  EXPECT_EQ(21, queue.front()->computeChainDataLength());
259  EXPECT_EQ(9, queue.front()->prev()->length());
260 
261  queue.trimEnd(20);
262  checkConsistency(queue);
263  EXPECT_EQ(1, queue.front()->countChainElements());
264  EXPECT_EQ(1, queue.front()->computeChainDataLength());
265  EXPECT_EQ(1, queue.front()->prev()->length());
266 
267  queue.trimEnd(1);
268  checkConsistency(queue);
269  EXPECT_EQ(nullptr, queue.front());
270 
271  EXPECT_THROW(queue.trimStart(2), std::underflow_error);
272  checkConsistency(queue);
273 
274  EXPECT_THROW(queue.trimEnd(30), std::underflow_error);
275  checkConsistency(queue);
276 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
char a
void append(std::size_t amount)
Definition: IOBuf.h:689
TEST ( IOBufQueue  ,
TrimStartAtMost   
)

Definition at line 278 of file IOBufQueueTest.cpp.

References a, folly::IOBufQueue::append(), folly::IOBuf::append(), folly::IOBufQueue::chainLength(), folly::IOBuf::computeChainDataLength(), folly::IOBuf::countChainElements(), EXPECT_EQ, folly::IOBufQueue::front(), folly::IOBuf::length(), folly::gen::move, and folly::IOBufQueue::trimStartAtMost().

278  {
279  IOBufQueue queue(clOptions);
280  unique_ptr<IOBuf> a = IOBuf::create(4);
281  a->append(4);
282  queue.append(std::move(a));
283  checkConsistency(queue);
284  a = IOBuf::create(6);
285  a->append(6);
286  queue.append(std::move(a));
287  checkConsistency(queue);
288  a = IOBuf::create(8);
289  a->append(8);
290  queue.append(std::move(a));
291  checkConsistency(queue);
292  a = IOBuf::create(10);
293  a->append(10);
294  queue.append(std::move(a));
295  checkConsistency(queue);
296 
297  EXPECT_EQ(4, queue.front()->countChainElements());
298  EXPECT_EQ(28, queue.front()->computeChainDataLength());
299  EXPECT_EQ(4, queue.front()->length());
300 
301  queue.trimStartAtMost(1);
302  checkConsistency(queue);
303  EXPECT_EQ(4, queue.front()->countChainElements());
304  EXPECT_EQ(27, queue.front()->computeChainDataLength());
305  EXPECT_EQ(3, queue.front()->length());
306 
307  queue.trimStartAtMost(50);
308  checkConsistency(queue);
309  EXPECT_EQ(nullptr, queue.front());
310  EXPECT_EQ(0, queue.chainLength());
311 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
char a
void append(std::size_t amount)
Definition: IOBuf.h:689
TEST ( IOBufQueue  ,
TrimEndAtMost   
)

Definition at line 313 of file IOBufQueueTest.cpp.

References a, folly::IOBufQueue::append(), folly::IOBuf::append(), folly::IOBufQueue::chainLength(), folly::IOBuf::computeChainDataLength(), folly::IOBuf::countChainElements(), EXPECT_EQ, folly::IOBufQueue::front(), folly::IOBuf::length(), folly::gen::move, and folly::IOBufQueue::trimEndAtMost().

313  {
314  IOBufQueue queue(clOptions);
315  unique_ptr<IOBuf> a = IOBuf::create(4);
316  a->append(4);
317  queue.append(std::move(a));
318  checkConsistency(queue);
319  a = IOBuf::create(6);
320  a->append(6);
321  queue.append(std::move(a));
322  checkConsistency(queue);
323  a = IOBuf::create(8);
324  a->append(8);
325  queue.append(std::move(a));
326  checkConsistency(queue);
327  a = IOBuf::create(10);
328  a->append(10);
329  queue.append(std::move(a));
330  checkConsistency(queue);
331 
332  EXPECT_EQ(4, queue.front()->countChainElements());
333  EXPECT_EQ(28, queue.front()->computeChainDataLength());
334  EXPECT_EQ(4, queue.front()->length());
335 
336  queue.trimEndAtMost(1);
337  checkConsistency(queue);
338  EXPECT_EQ(4, queue.front()->countChainElements());
339  EXPECT_EQ(27, queue.front()->computeChainDataLength());
340  EXPECT_EQ(4, queue.front()->length());
341 
342  queue.trimEndAtMost(50);
343  checkConsistency(queue);
344  EXPECT_EQ(nullptr, queue.front());
345  EXPECT_EQ(0, queue.chainLength());
346 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
char a
void append(std::size_t amount)
Definition: IOBuf.h:689
TEST ( IOBufQueue  ,
TrimPack   
)

Definition at line 348 of file IOBufQueueTest.cpp.

References a, folly::IOBufQueue::append(), folly::IOBuf::append(), folly::IOBuf::computeChainDataLength(), folly::IOBuf::countChainElements(), EXPECT_EQ, EXPECT_THROW, folly::IOBufQueue::front(), folly::IOBuf::length(), folly::gen::move, folly::IOBuf::prev(), folly::IOBufQueue::trimEnd(), and folly::IOBufQueue::trimStart().

348  {
349  IOBufQueue queue(clOptions);
350  unique_ptr<IOBuf> a = IOBuf::create(64);
351  a->append(4);
352  queue.append(std::move(a), true);
353  checkConsistency(queue);
354  a = IOBuf::create(6);
355  a->append(6);
356  queue.append(std::move(a), true);
357  checkConsistency(queue);
358  a = IOBuf::create(8);
359  a->append(8);
360  queue.append(std::move(a), true);
361  checkConsistency(queue);
362  a = IOBuf::create(10);
363  a->append(10);
364  queue.append(std::move(a), true);
365  checkConsistency(queue);
366 
367  EXPECT_EQ(1, queue.front()->countChainElements());
368  EXPECT_EQ(28, queue.front()->computeChainDataLength());
369  EXPECT_EQ(28, queue.front()->length());
370 
371  queue.trimStart(1);
372  checkConsistency(queue);
373  EXPECT_EQ(1, queue.front()->countChainElements());
374  EXPECT_EQ(27, queue.front()->computeChainDataLength());
375  EXPECT_EQ(27, queue.front()->length());
376 
377  queue.trimStart(5);
378  checkConsistency(queue);
379  EXPECT_EQ(1, queue.front()->countChainElements());
380  EXPECT_EQ(22, queue.front()->computeChainDataLength());
381  EXPECT_EQ(22, queue.front()->length());
382 
383  queue.trimEnd(1);
384  checkConsistency(queue);
385  EXPECT_EQ(1, queue.front()->countChainElements());
386  EXPECT_EQ(21, queue.front()->computeChainDataLength());
387  EXPECT_EQ(21, queue.front()->prev()->length());
388 
389  queue.trimEnd(20);
390  checkConsistency(queue);
391  EXPECT_EQ(1, queue.front()->countChainElements());
392  EXPECT_EQ(1, queue.front()->computeChainDataLength());
393  EXPECT_EQ(1, queue.front()->prev()->length());
394 
395  queue.trimEnd(1);
396  checkConsistency(queue);
397  EXPECT_EQ(nullptr, queue.front());
398 
399  EXPECT_THROW(queue.trimStart(2), std::underflow_error);
400  checkConsistency(queue);
401 
402  EXPECT_THROW(queue.trimEnd(30), std::underflow_error);
403  checkConsistency(queue);
404 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
char a
void append(std::size_t amount)
Definition: IOBuf.h:689
TEST ( IOBufQueue  ,
Prepend   
)

Definition at line 406 of file IOBufQueueTest.cpp.

References folly::IOBufQueue::append(), folly::IOBuf::create(), EXPECT_EQ, EXPECT_THROW, folly::IOBufQueue::move(), folly::gen::move, folly::IOBufQueue::prepend(), and SCL.

406  {
407  folly::IOBufQueue queue;
408 
409  auto buf = folly::IOBuf::create(10);
410  buf->advance(5);
411  queue.append(std::move(buf));
412 
413  queue.append(SCL(" World"));
414  queue.prepend(SCL("Hello"));
415 
416  EXPECT_THROW(queue.prepend(SCL("x")), std::overflow_error);
417 
418  auto out = queue.move();
419  out->coalesce();
420  EXPECT_EQ(
421  "Hello World",
422  StringPiece(reinterpret_cast<const char*>(out->data()), out->length()));
423 }
#define SCL(x)
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
void prepend(const void *buf, std::size_t n)
Definition: IOBufQueue.cpp:132
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
static std::unique_ptr< IOBuf > create(std::size_t capacity)
Definition: IOBuf.cpp:229
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
Range< const char * > StringPiece
TEST ( IOBufQueue  ,
PopFirst   
)

Definition at line 425 of file IOBufQueueTest.cpp.

References folly::IOBufQueue::append(), folly::IOBufQueue::chainLength(), folly::IOBuf::computeChainDataLength(), EXPECT_EQ, folly::gen::first, folly::IOBufQueue::front(), i, folly::IOBufQueue::pop_front(), and strings.

425  {
426  IOBufQueue queue(IOBufQueue::cacheChainLength());
427  const char* strings[] = {"Hello", ",", " ", "", "World"};
428 
429  const size_t numStrings = sizeof(strings) / sizeof(*strings);
430  size_t chainLength = 0;
431  for (size_t i = 0; i < numStrings; ++i) {
432  queue.append(stringToIOBuf(strings[i], strlen(strings[i])));
433  checkConsistency(queue);
434  chainLength += strlen(strings[i]);
435  }
436 
437  unique_ptr<IOBuf> first;
438  for (size_t i = 0; i < numStrings; ++i) {
439  checkConsistency(queue);
440  EXPECT_EQ(chainLength, queue.front()->computeChainDataLength());
441  EXPECT_EQ(chainLength, queue.chainLength());
442  first = queue.pop_front();
443  chainLength -= strlen(strings[i]);
444  EXPECT_EQ(strlen(strings[i]), first->computeChainDataLength());
445  }
446  checkConsistency(queue);
447  EXPECT_EQ(chainLength, queue.chainLength());
448 
449  EXPECT_EQ((IOBuf*)nullptr, queue.front());
450  first = queue.pop_front();
451  EXPECT_EQ((IOBuf*)nullptr, first.get());
452 
453  checkConsistency(queue);
454  EXPECT_EQ((IOBuf*)nullptr, queue.front());
455  EXPECT_EQ(0, queue.chainLength());
456 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static vector< fbstring > strings
constexpr detail::First first
Definition: Base-inl.h:2553
TEST ( IOBufQueue  ,
AppendToString   
)

Definition at line 458 of file IOBufQueueTest.cpp.

References folly::IOBufQueue::append(), folly::IOBufQueue::appendToString(), EXPECT_EQ, s, and string.

458  {
459  IOBufQueue queue;
460  queue.append("hello ", 6);
461  queue.append("world", 5);
462  std::string s;
463  queue.appendToString(s);
464  EXPECT_EQ("hello world", s);
465 }
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void appendToString(std::string &out) const
Definition: IOBufQueue.cpp:340
const char * string
Definition: Conv.cpp:212
static set< string > s
TEST ( IOBufQueue  ,
Gather   
)

Definition at line 467 of file IOBufQueueTest.cpp.

References folly::IOBufQueue::append(), folly::IOBuf::data(), EXPECT_EQ, folly::IOBufQueue::front(), folly::IOBufQueue::gather(), folly::IOBuf::length(), s, and SCL.

467  {
468  IOBufQueue queue;
469 
470  queue.append(stringToIOBuf(SCL("hello ")));
471  queue.append(stringToIOBuf(SCL("world")));
472 
473  EXPECT_EQ(queue.front()->length(), 6);
474  queue.gather(11);
475  EXPECT_EQ(queue.front()->length(), 11);
476 
477  StringPiece s(
478  reinterpret_cast<const char*>(queue.front()->data()),
479  queue.front()->length());
480  EXPECT_EQ("hello world", s);
481 }
#define SCL(x)
const folly::IOBuf * front() const
Definition: IOBufQueue.h:476
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const uint8_t * data() const
Definition: IOBuf.h:499
std::size_t length() const
Definition: IOBuf.h:533
static set< string > s
Range< const char * > StringPiece
void gather(std::size_t maxLength)
Definition: IOBufQueue.cpp:361