proxygen
NegotiatorTest.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/server/Negotiator.h>
13 
14 using namespace testing;
15 
16 namespace fizz {
17 namespace server {
18 namespace test {
19 
20 TEST(NegotiatorTest, TestSingle) {
21  std::vector<std::vector<int>> server = {{1}};
22  std::vector<int> client = {1};
23 
24  EXPECT_EQ(*negotiate(server, client), 1);
25 }
26 
27 TEST(NegotiatorTest, TestSingleMismatch) {
28  std::vector<std::vector<int>> server = {{1}};
29  std::vector<int> client = {2};
30 
31  EXPECT_FALSE(negotiate(server, client).hasValue());
32 }
33 
34 TEST(NegotiatorTest, TestServerPref) {
35  std::vector<std::vector<int>> server = {{1}, {2}, {3}};
36  std::vector<int> client = {3, 1, 2};
37 
38  EXPECT_EQ(*negotiate(server, client), 1);
39 }
40 
41 TEST(NegotiatorTest, TestServerPrefTie) {
42  std::vector<std::vector<int>> server = {{1}, {2, 4}, {3}};
43  std::vector<int> client = {5, 6, 4, 2};
44 
45  EXPECT_EQ(*negotiate(server, client), 4);
46 }
47 
48 TEST(NegotiateTest, TestSingleOrdering) {
49  std::vector<int> server = {1, 2, 3};
50  std::vector<int> client = {3, 1, 2};
51 
52  EXPECT_EQ(*negotiate(server, client), 1);
53 }
54 
55 TEST(NegotiateTest, TestSingleOrderingLast) {
56  std::vector<int> server = {4, 5, 3};
57  std::vector<int> client = {3, 1, 2};
58 
59  EXPECT_EQ(*negotiate(server, client), 3);
60 }
61 
62 TEST(NegotiateTest, TestSingleOrderingNoMatch) {
63  std::vector<int> server = {1, 5, 6};
64  std::vector<int> client = {3, 4, 2};
65 
66  EXPECT_FALSE(negotiate(server, client).hasValue());
67 }
68 
69 TEST(NegotiateTest, TestServerEmptyTier) {
70  std::vector<std::vector<int>> server = {{}, {4}};
71  std::vector<int> client = {3, 4, 2};
72 
73  EXPECT_EQ(*negotiate(server, client), 4);
74 }
75 } // namespace test
76 } // namespace server
77 } // namespace fizz
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
folly::Optional< T > negotiate(const std::vector< std::vector< T >> &serverPref, const std::vector< T > &clientPref)
Definition: Negotiator.h:22
TEST(GTestEnvVarTest, Dummy)
Definition: Actions.h:16
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862