9 #include <gtest/gtest.h> 14 using namespace folly;
19 TEST(IOBufUtilTest, TrimBytes) {
28 auto bufLen = buf->computeChainDataLength();
29 constexpr
size_t trimLen = 6;
30 std::array<uint8_t, trimLen> trimData;
36 EXPECT_EQ(bufLen - trimLen, buf->computeChainDataLength());
40 TEST(IOBufUtilTest, TransformBufferInplace) {
48 expected->append(buf->computeChainDataLength());
49 memset(expected->writableData(),
'w', expected->length());
53 memset(out,
'w', len);
65 TEST(IOBufUtilTest, TransformBufferWithFragmentedBuffer) {
80 fragmented->prependChain(
std::move(fragment1));
81 fragmented->prependChain(
std::move(fragment2));
82 fragmented->prependChain(
std::move(fragment3));
83 fragmented->prependChain(
std::move(fragment4));
84 fragmented->prependChain(
std::move(fragment5));
87 *buf, *fragmented, [](
uint8_t* out,
const uint8_t* in,
size_t len) {
96 if (len + internalOffset < 8) {
98 memcpy(block + internalOffset, in, len);
99 internalOffset += len;
103 size_t outOffset = 0;
105 auto numToWrite = 8 * ((internalOffset + len) / 8);
106 if (internalOffset > 0) {
107 memcpy(out, block, internalOffset);
108 outOffset += internalOffset;
109 numToWrite -= internalOffset;
114 memcpy(out + outOffset, in, numToWrite);
116 if (len > numToWrite) {
117 auto numToBuf = len - numToWrite;
118 DCHECK(numToBuf < 8);
119 memcpy(block, in + numToWrite, numToBuf);
120 internalOffset = numToBuf;
122 return numToWrite + outOffset;
125 size_t internalOffset = 0;
129 TEST(IOBufUtilTest, TransformBufferBlocks) {
135 transformBufferBlocks<8>(
137 return writer.
copy(out, in, len);
143 TEST(IOBufUtilTest, TransformBufferBlocksSplit) {
152 transformBufferBlocks<8>(
154 return writer.
copy(out, in, len);
160 TEST(IOBufUtilTest, TransformBufferBlocksInputFragmented) {
175 transformBufferBlocks<8>(
177 return writer.
copy(out, in, len);
183 TEST(IOBufUtilTest, TransformBufferBlocksOutputFragmented) {
198 transformBufferBlocks<8>(
200 return writer.
copy(out, in, len);
206 TEST(IOBufUtilTest, TransformBufferBlocksInputFragmented2) {
211 transformBufferBlocks<8>(
213 return writer.
copy(out, in, len);
219 TEST(IOBufUtilTest, TransformBufferBlocksFragmented) {
240 transformBufferBlocks<8>(
242 return writer.
copy(out, in, len);
static std::unique_ptr< IOBuf > create(std::size_t capacity)
void trimBytes(IOBuf &buf, folly::MutableByteRange trimmed)
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
—— Concurrent Priority Queue Implementation ——
void transformBuffer(const folly::IOBuf &in, folly::IOBuf &out, Func func)
const_range_type castToConst() const
#define EXPECT_TRUE(condition)
std::unique_ptr< IOBuf > createBuf(size_t len)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
TEST(SequencedExecutor, CPUThreadPoolExecutor)
size_t copy(uint8_t *out, const uint8_t *in, size_t len)