proxygen
WriteChainAsyncTransportWrapperTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
21 
22 using namespace testing;
23 using testing::_;
24 
25 namespace folly {
26 namespace test {
27 
29  : public WriteChainAsyncTransportWrapper<folly::AsyncTransportWrapper> {
30  public:
33  }
34 
36  writeChain,
37  void(
39  std::shared_ptr<folly::IOBuf>,
41 
42  // gmock doesn't work with the IOBuf&& so we have to wrap this.
43  void writeChain(
44  WriteCallback* callback,
45  std::unique_ptr<folly::IOBuf>&& iob,
47  writeChain(callback, std::shared_ptr<folly::IOBuf>(iob.release()), flags);
48  }
49 
50  // Allow this to be constructed on the stack for easier testing.
52 };
53 
54 MATCHER_P(BufMatches, expected, "") {
56  return eq(*arg, *expected);
57 }
58 
59 TEST(WriteChainAsyncTransportWrapperTest, TestSimpleIov) {
61  auto buf = folly::IOBuf::copyBuffer("foo");
62 
63  EXPECT_CALL(transport, writeChain(_, BufMatches(buf.get()), _));
64 
65  auto iov = buf->getIov();
66  transport.writev(nullptr, iov.data(), iov.size());
67 }
68 
69 TEST(WriteChainAsyncTransportWrapperTest, TestChainedIov) {
71  auto buf = folly::IOBuf::copyBuffer("hello");
72  buf->prependChain(folly::IOBuf::copyBuffer("world"));
73 
74  EXPECT_CALL(transport, writeChain(_, BufMatches(buf.get()), _));
75 
76  auto iov = buf->getIov();
77  transport.writev(nullptr, iov.data(), iov.size());
78 }
79 
80 TEST(WriteChainAsyncTransportWrapperTest, TestSimpleBuf) {
82  auto buf = folly::IOBuf::copyBuffer("foobar");
83 
84  EXPECT_CALL(transport, writeChain(_, BufMatches(buf.get()), _));
85 
86  transport.write(nullptr, buf->data(), buf->length());
87 }
88 
89 } // namespace test
90 } // namespace folly
flags
Definition: http_parser.h:127
void writev(folly::AsyncTransportWrapper::WriteCallback *callback, const iovec *vec, size_t count, folly::WriteFlags flags=folly::WriteFlags::NONE) override
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
#define nullptr
Definition: http_parser.c:41
#define MOCK_METHOD3(m,...)
void write(folly::AsyncTransportWrapper::WriteCallback *callback, const void *buf, size_t bytes, folly::WriteFlags flags=folly::WriteFlags::NONE) override
TEST(GTestEnvVarTest, Dummy)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
void writeChain(WriteCallback *callback, std::unique_ptr< folly::IOBuf > &&iob, folly::WriteFlags flags=folly::WriteFlags::NONE) override
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
MATCHER_P(BufMatches, expected,"")