blob: d791294e850a71a62e0954465230703e57354d57 [file] [log] [blame]
[email protected]cc7ec7f2014-01-25 20:32:511// 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 Hamiltona3ee93a72018-08-01 22:03:085#include "net/quic/quic_utils_chromium.h"
[email protected]cc7ec7f2014-01-25 20:32:516
7#include <map>
8
Ryan Hamilton56b10c5d2018-05-11 13:40:169#include "net/third_party/quic/core/crypto/crypto_protocol.h"
[email protected]cc7ec7f2014-01-25 20:32:5110#include "testing/gtest/include/gtest/gtest.h"
11
[email protected]cc7ec7f2014-01-25 20:32:5112namespace net {
13namespace test {
14namespace {
15
rch84581802017-05-01 18:53:5816TEST(QuicUtilsChromiumTest, ParseQuicConnectionOptions) {
Ryan Hamilton8d9ee76e2018-05-29 23:52:5217 quic::QuicTagVector empty_options = ParseQuicConnectionOptions("");
rch4c967ea2016-12-22 01:41:0718 EXPECT_TRUE(empty_options.empty());
19
Ryan Hamilton8d9ee76e2018-05-29 23:52:5220 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);
rch4c967ea2016-12-22 01:41:0726 EXPECT_EQ(expected_options, parsed_options);
27}
28
[email protected]cc7ec7f2014-01-25 20:32:5129TEST(QuicUtilsChromiumTest, FindOrNullTest) {
rch872e00e2016-12-02 02:48:1830 std::map<int, int> m;
[email protected]cc7ec7f2014-01-25 20:32:5131 m[0] = 2;
32
33 // Check FindOrNull
34 int* p1 = FindOrNull(m, 0);
35 CHECK_EQ(*p1, 2);
36 ++(*p1);
rch872e00e2016-12-02 02:48:1837 const std::map<int, int>& const_m = m;
[email protected]cc7ec7f2014-01-25 20:32:5138 const int* p2 = FindOrNull(const_m, 0);
39 CHECK_EQ(*p2, 3);
rtennetibe635732014-10-02 22:51:4240 CHECK(FindOrNull(m, 1) == nullptr);
[email protected]cc7ec7f2014-01-25 20:32:5141}
42
43TEST(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.
rch872e00e2016-12-02 02:48:1856 const std::map<int, int>& const_m = m;
[email protected]cc7ec7f2014-01-25 20:32:5157 EXPECT_EQ(20, FindOrDie(const_m, 10));
58}
59
60} // namespace
61} // namespace test
62} // namespace net