OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/core/quic_utils.h" | 5 #include "net/quic/core/quic_utils.h" |
6 | 6 |
7 #include "net/quic/core/crypto/crypto_protocol.h" | 7 #include "net/quic/core/crypto/crypto_protocol.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "net/quic/platform/api/quic_test.h" |
9 | 9 |
10 using std::string; | 10 using std::string; |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 namespace test { | 13 namespace test { |
14 namespace { | 14 namespace { |
15 | 15 |
16 TEST(QuicUtilsTest, DetermineAddressChangeType) { | 16 class QuicUtilsTest : public QuicTest {}; |
| 17 |
| 18 TEST_F(QuicUtilsTest, DetermineAddressChangeType) { |
17 const string kIPv4String1 = "1.2.3.4"; | 19 const string kIPv4String1 = "1.2.3.4"; |
18 const string kIPv4String2 = "1.2.3.5"; | 20 const string kIPv4String2 = "1.2.3.5"; |
19 const string kIPv4String3 = "1.1.3.5"; | 21 const string kIPv4String3 = "1.1.3.5"; |
20 const string kIPv6String1 = "2001:700:300:1800::f"; | 22 const string kIPv6String1 = "2001:700:300:1800::f"; |
21 const string kIPv6String2 = "2001:700:300:1800:1:1:1:f"; | 23 const string kIPv6String2 = "2001:700:300:1800:1:1:1:f"; |
22 QuicSocketAddress old_address; | 24 QuicSocketAddress old_address; |
23 QuicSocketAddress new_address; | 25 QuicSocketAddress new_address; |
24 QuicIpAddress address; | 26 QuicIpAddress address; |
25 | 27 |
26 EXPECT_EQ(NO_CHANGE, | 28 EXPECT_EQ(NO_CHANGE, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // kPrime = 309485009821345068724781371 | 83 // kPrime = 309485009821345068724781371 |
82 const uint128 kPrime = MakeUint128(16777216, 315); | 84 const uint128 kPrime = MakeUint128(16777216, 315); |
83 const uint8_t* octets = reinterpret_cast<const uint8_t*>(data); | 85 const uint8_t* octets = reinterpret_cast<const uint8_t*>(data); |
84 for (size_t i = 0; i < len; ++i) { | 86 for (size_t i = 0; i < len; ++i) { |
85 hash = hash ^ MakeUint128(0, octets[i]); | 87 hash = hash ^ MakeUint128(0, octets[i]); |
86 hash = hash * kPrime; | 88 hash = hash * kPrime; |
87 } | 89 } |
88 return hash; | 90 return hash; |
89 } | 91 } |
90 | 92 |
91 TEST(QuicUtilsHashTest, ReferenceTest) { | 93 TEST_F(QuicUtilsTest, ReferenceTest) { |
92 std::vector<uint8_t> data(32); | 94 std::vector<uint8_t> data(32); |
93 for (size_t i = 0; i < data.size(); ++i) { | 95 for (size_t i = 0; i < data.size(); ++i) { |
94 data[i] = i % 255; | 96 data[i] = i % 255; |
95 } | 97 } |
96 EXPECT_EQ(IncrementalHashReference(data.data(), data.size()), | 98 EXPECT_EQ(IncrementalHashReference(data.data(), data.size()), |
97 QuicUtils::FNV1a_128_Hash(QuicStringPiece( | 99 QuicUtils::FNV1a_128_Hash(QuicStringPiece( |
98 reinterpret_cast<const char*>(data.data()), data.size()))); | 100 reinterpret_cast<const char*>(data.data()), data.size()))); |
99 } | 101 } |
100 | 102 |
101 } // namespace | 103 } // namespace |
102 } // namespace test | 104 } // namespace test |
103 } // namespace net | 105 } // namespace net |
OLD | NEW |