proxygen
CertDecompressionManagerTest.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 <gtest/gtest.h>
10 
13 
14 using namespace folly;
15 using namespace testing;
16 
17 namespace fizz {
18 namespace test {
19 
21  public:
22  void SetUp() override {
23  manager_ = std::make_unique<CertDecompressionManager>();
24  }
25 
26  void TearDown() override {}
27 
28  protected:
30  return static_cast<CertificateCompressionAlgorithm>(n);
31  }
32 
33  std::shared_ptr<MockCertificateDecompressor> makeMockDecompressor(
34  uint16_t n) {
35  auto comp = std::make_shared<MockCertificateDecompressor>();
36  EXPECT_CALL(*comp, getAlgorithm()).WillOnce(Return(toAlgo(n)));
37  return comp;
38  }
39 
40  std::unique_ptr<CertDecompressionManager> manager_;
41 };
42 
44  auto decomp1 = makeMockDecompressor(1);
45  auto decomp2 = makeMockDecompressor(2);
46 
47  manager_->setDecompressors(
48  {std::static_pointer_cast<CertificateDecompressor>(decomp1),
49  std::static_pointer_cast<CertificateDecompressor>(decomp2)});
50 
51  auto supported = manager_->getSupportedAlgorithms();
52  EXPECT_EQ(supported.size(), 2);
53  EXPECT_EQ(supported[0], toAlgo(1));
54  EXPECT_EQ(supported[1], toAlgo(2));
55  auto fetchedDecomp1 = manager_->getDecompressor(toAlgo(1));
56  auto fetchedDecomp2 = manager_->getDecompressor(toAlgo(2));
57  auto invalidDecomp = manager_->getDecompressor(toAlgo(3));
58  EXPECT_EQ(decomp1, fetchedDecomp1);
59  EXPECT_EQ(decomp2, fetchedDecomp2);
60  EXPECT_EQ(invalidDecomp, nullptr);
61 }
62 
63 TEST_F(CertDecompressionManagerTest, TestSameOverwrites) {
64  auto decomp1 = makeMockDecompressor(1);
65  auto decomp2 = makeMockDecompressor(1);
66  auto decomp3 = makeMockDecompressor(2);
67 
68  manager_->setDecompressors(
69  {std::static_pointer_cast<CertificateDecompressor>(decomp1),
70  std::static_pointer_cast<CertificateDecompressor>(decomp2),
71  std::static_pointer_cast<CertificateDecompressor>(decomp3)});
72 
73  auto supported = manager_->getSupportedAlgorithms();
74  EXPECT_EQ(supported.size(), 2);
75  EXPECT_EQ(supported[0], toAlgo(1));
76  EXPECT_EQ(supported[1], toAlgo(2));
77  auto fetchedDecomp1 = manager_->getDecompressor(toAlgo(1));
78  auto fetchedDecomp2 = manager_->getDecompressor(toAlgo(2));
79  EXPECT_EQ(decomp2, fetchedDecomp1);
80  EXPECT_NE(decomp1, fetchedDecomp1);
81  EXPECT_EQ(decomp3, fetchedDecomp2);
82 }
83 
84 } // namespace test
85 } // namespace fizz
CertificateCompressionAlgorithm
Definition: Types.h:167
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
CertificateCompressionAlgorithm toAlgo(uint16_t n)
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
Definition: Actions.h:16
TEST_F(AsyncSSLSocketWriteTest, write_coalescing1)
std::unique_ptr< CertDecompressionManager > manager_
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
#define EXPECT_CALL(obj, call)
internal::ReturnAction< R > Return(R value)
std::shared_ptr< MockCertificateDecompressor > makeMockDecompressor(uint16_t n)