proxygen
TypesTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #include <gmock/gmock.h>
10 #include <gtest/gtest.h>
11 
12 #include <folly/io/Cursor.h>
13 #include <folly/io/IOBuf.h>
14 
15 #include <fizz/record/Types.h>
16 
17 using namespace folly;
18 using namespace folly::io;
19 
20 using testing::_;
21 using namespace testing;
22 
23 namespace fizz {
24 namespace test {
25 
26 TEST(TestTypes, WriteAndRead24BitsNormal) {
27  uint32_t len = 0x102030;
28  auto buf = IOBuf::create(3);
29  Appender appender(buf.get(), 0);
30  detail::writeBits24(len, appender);
31 
32  EXPECT_EQ(0x10, buf->data()[0]);
33  EXPECT_EQ(0x20, buf->data()[1]);
34  EXPECT_EQ(0x30, buf->data()[2]);
35 
36  Cursor cursor(buf.get());
37  uint32_t actualLength = detail::readBits24(cursor);
38  EXPECT_EQ(len, actualLength);
39 }
40 
41 TEST(TestTypes, Write24BitsOverflow) {
42  uint32_t len = 0x10203040;
43  auto buf = IOBuf::create(3);
44  Appender appender(buf.get(), 0);
45  EXPECT_THROW(detail::writeBits24(len, appender), std::runtime_error);
46 }
47 
48 TEST(TestTypes, Write24BitsBuffer) {
49  auto buf = IOBuf::create(0x1020);
50  buf->append(0x1020);
51 
52  auto out = IOBuf::create(10);
53  Appender appender(out.get(), 10);
54  detail::writeBuf<detail::bits24>(buf, appender);
55  EXPECT_EQ(buf->length() + 3, out->computeChainDataLength());
56 }
57 
58 TEST(TestTypes, Write24BitsBufferOverflow) {
61 
62  auto out = IOBuf::create(10);
63  Appender appender(out.get(), 0);
65  detail::writeBuf<detail::bits24>(buf, appender), std::runtime_error);
66 }
67 
68 TEST(TestTypes, WriteBuf) {
69  auto buf = IOBuf::create(20);
70  buf->append(20);
71 
72  auto out1 = IOBuf::create(10);
73  Appender appender1(out1.get(), 10);
74  detail::writeBuf<uint16_t>(buf, appender1);
75  EXPECT_EQ(2 + buf->length(), out1->computeChainDataLength());
76 
77  auto out2 = IOBuf::create(10);
78  Appender appender2(out2.get(), 10);
79  detail::writeBuf<uint64_t>(buf, appender2);
80  EXPECT_EQ(8 + buf->length(), out2->computeChainDataLength());
81 }
82 } // namespace test
83 } // namespace fizz
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
static std::unique_ptr< IOBuf > create(std::size_t capacity)
Definition: IOBuf.cpp:229
LogLevel max
Definition: LogLevel.cpp:31
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
testing::Types< PerfectIndexMapTestsTemplateParams< HTTPHeaderCode, HTTP_HEADER_OTHER, HTTP_HEADER_NONE, HTTPCommonHeaders::hash, false, true, HTTPHeaderCodeCommonOffset, HTTPCommonHeaders::num_header_codes >, PerfectIndexMapTestsTemplateParams< HTTPHeaderCode, HTTP_HEADER_OTHER, HTTP_HEADER_NONE, HTTPCommonHeaders::hash, true, true, HTTPHeaderCodeCommonOffset, HTTPCommonHeaders::num_header_codes >, PerfectIndexMapTestsTemplateParams< HTTPHeaderCode, HTTP_HEADER_OTHER, HTTP_HEADER_NONE, HTTPCommonHeaders::hash, true, false, HTTPHeaderCodeCommonOffset, HTTPCommonHeaders::num_header_codes >, PerfectIndexMapTestsTemplateParams< HTTPHeaderCode, HTTP_HEADER_OTHER, HTTP_HEADER_NONE, HTTPCommonHeaders::hash, false, false, HTTPHeaderCodeCommonOffset, HTTPCommonHeaders::num_header_codes > > TestTypes
void writeBits24(T len, folly::io::Appender &out)
Definition: Types-inl.h:102
Definition: Actions.h:16
uint32_t readBits24(folly::io::Cursor &cursor)
Definition: Types-inl.h:210
const internal::AnythingMatcher _
TEST(SequencedExecutor, CPUThreadPoolExecutor)