proxygen
ExtensionTestsBase.h
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 #pragma once
10 
11 #include <gmock/gmock.h>
12 #include <gtest/gtest.h>
13 
14 #include <fizz/record/Types.h>
15 #include <folly/String.h>
16 
17 namespace fizz {
18 namespace test {
19 
20 class ExtensionsTest : public testing::Test {
21  protected:
23  auto data = unhexlify(hex);
24  return folly::IOBuf::copyBuffer(data.data(), data.size());
25  }
26 
27  std::vector<Extension> getExtensions(folly::StringPiece hex) {
28  auto buf = ExtensionsTest::getBuf(hex);
29  folly::io::Cursor cursor(buf.get());
30  Extension ext;
31  EXPECT_EQ(detail::read(ext, cursor), buf->computeChainDataLength());
32  EXPECT_TRUE(cursor.isAtEnd());
33  std::vector<Extension> exts;
34  exts.push_back(std::move(ext));
35  return exts;
36  }
37 
38  template <class T>
39  void checkEncode(T&& ext, folly::StringPiece expectedHex) {
40  auto encoded = encodeExtension(std::forward<T>(ext));
41  auto buf = folly::IOBuf::create(0);
42  folly::io::Appender appender(buf.get(), 10);
43  detail::write(encoded, appender);
44  EXPECT_TRUE(folly::IOBufEqualTo()(buf, getBuf(expectedHex)));
45  }
46 };
47 } // namespace test
48 } // namespace fizz
#define T(v)
Definition: http_parser.c:233
bool unhexlify(const InputString &input, OutputString &output)
Definition: String-inl.h:616
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
std::vector< Extension > getExtensions(folly::StringPiece hex)
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
Buf getBuf(folly::StringPiece hex)
size_t read(T &out, folly::io::Cursor &cursor)
Definition: Types-inl.h:258
Definition: Actions.h:16
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
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
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
void checkEncode(T &&ext, folly::StringPiece expectedHex)