OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_data_writer.h" | 5 #include "net/quic/core/quic_data_writer.h" |
6 | 6 |
7 #include <cstdint> | 7 #include <cstdint> |
8 | 8 |
9 #include "net/quic/core/quic_data_reader.h" | 9 #include "net/quic/core/quic_data_reader.h" |
| 10 #include "net/quic/core/quic_flags.h" |
| 11 #include "net/quic/test_tools/quic_test_utils.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
11 | 13 |
12 namespace net { | 14 namespace net { |
13 namespace test { | 15 namespace test { |
14 namespace { | 16 namespace { |
15 | 17 |
16 TEST(QuicDataWriterTest, SanityCheckUFloat16Consts) { | 18 TEST(QuicDataWriterTest, SanityCheckUFloat16Consts) { |
17 // Check the arithmetic on the constants - otherwise the values below make | 19 // Check the arithmetic on the constants - otherwise the values below make |
18 // no sense. | 20 // no sense. |
19 EXPECT_EQ(30, kUFloat16MaxExponent); | 21 EXPECT_EQ(30, kUFloat16MaxExponent); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 // Check minimal decoding (previous decoding has previous encoding). | 191 // Check minimal decoding (previous decoding has previous encoding). |
190 EXPECT_EQ(i - 1, *reinterpret_cast<uint16_t*>(writer.data())); | 192 EXPECT_EQ(i - 1, *reinterpret_cast<uint16_t*>(writer.data())); |
191 // Check roundtrip. | 193 // Check roundtrip. |
192 EXPECT_EQ(i, *reinterpret_cast<uint16_t*>(writer.data() + 2)); | 194 EXPECT_EQ(i, *reinterpret_cast<uint16_t*>(writer.data() + 2)); |
193 // Check next decoding. | 195 // Check next decoding. |
194 EXPECT_EQ(i < 4096 ? i + 1 : i, | 196 EXPECT_EQ(i < 4096 ? i + 1 : i, |
195 *reinterpret_cast<uint16_t*>(writer.data() + 4)); | 197 *reinterpret_cast<uint16_t*>(writer.data() + 4)); |
196 } | 198 } |
197 } | 199 } |
198 | 200 |
| 201 TEST(QuicDataWriterTest, WriteConnectionId) { |
| 202 uint64_t connection_id = 0x0011223344556677; |
| 203 char little_endian[] = { |
| 204 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, |
| 205 }; |
| 206 char big_endian[] = { |
| 207 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
| 208 }; |
| 209 const int kBufferLength = sizeof(connection_id); |
| 210 char buffer[kBufferLength]; |
| 211 QuicDataWriter writer(kBufferLength, buffer); |
| 212 writer.WriteConnectionId(connection_id); |
| 213 test::CompareCharArraysWithHexError( |
| 214 "connection_id", buffer, kBufferLength, |
| 215 FLAGS_quic_restart_flag_quic_big_endian_connection_id ? big_endian |
| 216 : little_endian, |
| 217 kBufferLength); |
| 218 |
| 219 uint64_t read_connection_id; |
| 220 QuicDataReader reader(buffer, kBufferLength); |
| 221 reader.ReadConnectionId(&read_connection_id); |
| 222 EXPECT_EQ(connection_id, read_connection_id); |
| 223 } |
| 224 |
199 } // namespace | 225 } // namespace |
200 } // namespace test | 226 } // namespace test |
201 } // namespace net | 227 } // namespace net |
OLD | NEW |