[email protected] | cc7ec7f | 2014-01-25 20:32:51 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame^] | 5 | #include "net/quic/quic_utils_chromium.h" |
[email protected] | cc7ec7f | 2014-01-25 20:32:51 | [diff] [blame] | 6 | |
| 7 | #include <map> |
| 8 | |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 9 | #include "net/third_party/quic/core/crypto/crypto_protocol.h" |
[email protected] | cc7ec7f | 2014-01-25 20:32:51 | [diff] [blame] | 10 | #include "testing/gtest/include/gtest/gtest.h" |
| 11 | |
[email protected] | cc7ec7f | 2014-01-25 20:32:51 | [diff] [blame] | 12 | namespace net { |
| 13 | namespace test { |
| 14 | namespace { |
| 15 | |
rch | 8458180 | 2017-05-01 18:53:58 | [diff] [blame] | 16 | TEST(QuicUtilsChromiumTest, ParseQuicConnectionOptions) { |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 17 | quic::QuicTagVector empty_options = ParseQuicConnectionOptions(""); |
rch | 4c967ea | 2016-12-22 01:41:07 | [diff] [blame] | 18 | EXPECT_TRUE(empty_options.empty()); |
| 19 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 20 | quic::QuicTagVector parsed_options = |
| 21 | ParseQuicConnectionOptions("TIMER,TBBR,REJ"); |
| 22 | quic::QuicTagVector expected_options; |
| 23 | expected_options.push_back(quic::kTIME); |
| 24 | expected_options.push_back(quic::kTBBR); |
| 25 | expected_options.push_back(quic::kREJ); |
rch | 4c967ea | 2016-12-22 01:41:07 | [diff] [blame] | 26 | EXPECT_EQ(expected_options, parsed_options); |
| 27 | } |
| 28 | |
[email protected] | cc7ec7f | 2014-01-25 20:32:51 | [diff] [blame] | 29 | TEST(QuicUtilsChromiumTest, FindOrNullTest) { |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 30 | std::map<int, int> m; |
[email protected] | cc7ec7f | 2014-01-25 20:32:51 | [diff] [blame] | 31 | m[0] = 2; |
| 32 | |
| 33 | // Check FindOrNull |
| 34 | int* p1 = FindOrNull(m, 0); |
| 35 | CHECK_EQ(*p1, 2); |
| 36 | ++(*p1); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 37 | const std::map<int, int>& const_m = m; |
[email protected] | cc7ec7f | 2014-01-25 20:32:51 | [diff] [blame] | 38 | const int* p2 = FindOrNull(const_m, 0); |
| 39 | CHECK_EQ(*p2, 3); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 40 | CHECK(FindOrNull(m, 1) == nullptr); |
[email protected] | cc7ec7f | 2014-01-25 20:32:51 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | TEST(QuicUtilsChromiumTest, FindOrDieTest) { |
| 44 | std::map<int, int> m; |
| 45 | m[10] = 15; |
| 46 | EXPECT_EQ(15, FindOrDie(m, 10)); |
| 47 | // TODO(rtenneti): Use the latest DEATH macros after merging with latest rch's |
| 48 | // changes. |
| 49 | // ASSERT_DEATH(FindOrDie(m, 8), "Map key not found: 8"); |
| 50 | |
| 51 | // Make sure the non-const reference returning version works. |
| 52 | FindOrDie(m, 10) = 20; |
| 53 | EXPECT_EQ(20, FindOrDie(m, 10)); |
| 54 | |
| 55 | // Make sure we can lookup values in a const map. |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 56 | const std::map<int, int>& const_m = m; |
[email protected] | cc7ec7f | 2014-01-25 20:32:51 | [diff] [blame] | 57 | EXPECT_EQ(20, FindOrDie(const_m, 10)); |
| 58 | } |
| 59 | |
| 60 | } // namespace |
| 61 | } // namespace test |
| 62 | } // namespace net |