proxygen
FizzClientTest.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 <fizz/client/FizzClient.h>
13 #include <fizz/client/PskCache.h>
14 #include <fizz/client/test/Mocks.h>
15 
16 using namespace folly;
17 using namespace testing;
18 
19 namespace fizz {
20 namespace client {
21 namespace test {
22 
23 class MockClientStateMachineInstance : public MockClientStateMachine {
24  public:
26  instance = this;
27  }
28  static MockClientStateMachineInstance* instance;
29 };
30 MockClientStateMachineInstance* MockClientStateMachineInstance::instance;
31 
32 class ActionMoveVisitor : public boost::static_visitor<> {
33  public:
34  template <typename T>
35  void operator()(T&) {}
36 };
37 
39  public:
40  TestFizzClient() : fizzClient_(state_, queue_, visitor_, this) {}
41 
46 };
47 
48 class FizzClientTest : public Test {
49  public:
50  void SetUp() override {
51  context_ = std::make_shared<FizzClientContext>();
52  fizzClient_.reset(new TestFizzClient());
53  }
54 
55  protected:
56  std::shared_ptr<FizzClientContext> context_;
58  std::unique_ptr<TestFizzClient, DelayedDestruction::Destructor> fizzClient_;
59 };
60 
61 TEST_F(FizzClientTest, TestConnect) {
63  *MockClientStateMachineInstance::instance,
64  _processConnect(_, _, _, _, _, _))
65  .WillOnce(InvokeWithoutArgs([] { return Actions(); }));
66  const auto sni = std::string("www.example.com");
67  fizzClient_->fizzClient_.connect(context_, nullptr, sni, folly::none);
68 }
69 
70 TEST_F(FizzClientTest, TestConnectPskIdentity) {
71  std::string psk("psk");
73  *MockClientStateMachineInstance::instance,
74  _processConnect(_, _, _, _, _, _))
75  .WillOnce(
76  Invoke([psk](
77  const State&,
78  std::shared_ptr<const FizzClientContext> context,
79  std::shared_ptr<const CertificateVerifier> verifier,
82  const std::shared_ptr<ClientExtensions>& extensions) {
83  EXPECT_TRUE(cachedPsk);
84  EXPECT_EQ(cachedPsk->psk, psk);
85  EXPECT_EQ(sni, "www.example.com");
86  return Actions();
87  }));
88  const auto sni = std::string("www.example.com");
89  CachedPsk cachedPsk;
90  cachedPsk.psk = psk;
91  fizzClient_->fizzClient_.connect(
92  context_, nullptr, sni, std::move(cachedPsk));
93 }
94 } // namespace test
95 } // namespace client
96 } // namespace fizz
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
context
Definition: CMakeCache.txt:563
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::std T
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
std::unique_ptr< TestFizzClient, DelayedDestruction::Destructor > fizzClient_
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
std::vector< Action > Actions
Definition: Actions.h:81
FizzClient< ActionMoveVisitor, MockClientStateMachineInstance > fizzClient_
Definition: Actions.h:16
TEST_F(AsyncSSLSocketWriteTest, write_coalescing1)
std::shared_ptr< FizzClientContext > context_
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
StringPiece sni
const char * string
Definition: Conv.cpp:212
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
constexpr None none
Definition: Optional.h:87