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 <algorithm> | 5 #include <algorithm> |
6 #include <iostream> | 6 #include <iostream> |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/sys_byteorder.h" | 9 #include "base/sys_byteorder.h" |
10 #include "net/spdy/spdy_frame_reader.h" | 10 #include "net/spdy/spdy_frame_reader.h" |
11 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 TEST(SpdyFrameReaderTest, ReadUInt16) { | 15 TEST(SpdyFrameReaderTest, ReadUInt16) { |
16 // Frame data in network byte order. | 16 // Frame data in network byte order. |
17 const uint16 kFrameData[] = { | 17 const uint16 kFrameData[] = { |
18 htons(1), htons(1<<15), | 18 base::HostToNet16(1), base::HostToNet16(1 << 15), |
19 }; | 19 }; |
20 | 20 |
21 SpdyFrameReader frame_reader(reinterpret_cast<const char*>(kFrameData), | 21 SpdyFrameReader frame_reader(reinterpret_cast<const char*>(kFrameData), |
22 sizeof(kFrameData)); | 22 sizeof(kFrameData)); |
23 EXPECT_FALSE(frame_reader.IsDoneReading()); | 23 EXPECT_FALSE(frame_reader.IsDoneReading()); |
24 | 24 |
25 uint16 uint16_val; | 25 uint16 uint16_val; |
26 EXPECT_TRUE(frame_reader.ReadUInt16(&uint16_val)); | 26 EXPECT_TRUE(frame_reader.ReadUInt16(&uint16_val)); |
27 EXPECT_FALSE(frame_reader.IsDoneReading()); | 27 EXPECT_FALSE(frame_reader.IsDoneReading()); |
28 EXPECT_EQ(1, uint16_val); | 28 EXPECT_EQ(1, uint16_val); |
29 | 29 |
30 EXPECT_TRUE(frame_reader.ReadUInt16(&uint16_val)); | 30 EXPECT_TRUE(frame_reader.ReadUInt16(&uint16_val)); |
31 EXPECT_TRUE(frame_reader.IsDoneReading()); | 31 EXPECT_TRUE(frame_reader.IsDoneReading()); |
32 EXPECT_EQ(1<<15, uint16_val); | 32 EXPECT_EQ(1<<15, uint16_val); |
33 } | 33 } |
34 | 34 |
35 TEST(SpdyFrameReaderTest, ReadUInt32) { | 35 TEST(SpdyFrameReaderTest, ReadUInt32) { |
36 // Frame data in network byte order. | 36 // Frame data in network byte order. |
37 const uint32 kFrameData[] = { | 37 const uint32 kFrameData[] = { |
38 htonl(1), htonl(0x80000000), | 38 base::HostToNet32(1), base::HostToNet32(0x80000000), |
39 }; | 39 }; |
40 | 40 |
41 SpdyFrameReader frame_reader(reinterpret_cast<const char *>(kFrameData), | 41 SpdyFrameReader frame_reader(reinterpret_cast<const char *>(kFrameData), |
42 arraysize(kFrameData) * sizeof(uint32)); | 42 arraysize(kFrameData) * sizeof(uint32)); |
43 EXPECT_FALSE(frame_reader.IsDoneReading()); | 43 EXPECT_FALSE(frame_reader.IsDoneReading()); |
44 | 44 |
45 uint32 uint32_val; | 45 uint32 uint32_val; |
46 EXPECT_TRUE(frame_reader.ReadUInt32(&uint32_val)); | 46 EXPECT_TRUE(frame_reader.ReadUInt32(&uint32_val)); |
47 EXPECT_FALSE(frame_reader.IsDoneReading()); | 47 EXPECT_FALSE(frame_reader.IsDoneReading()); |
48 EXPECT_EQ(1u, uint32_val); | 48 EXPECT_EQ(1u, uint32_val); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 240 |
241 SpdyFrameReader frame_reader(kFrameData, arraysize(kFrameData)); | 241 SpdyFrameReader frame_reader(kFrameData, arraysize(kFrameData)); |
242 EXPECT_FALSE(frame_reader.IsDoneReading()); | 242 EXPECT_FALSE(frame_reader.IsDoneReading()); |
243 | 243 |
244 char dest[arraysize(kFrameData) + 2] = {}; | 244 char dest[arraysize(kFrameData) + 2] = {}; |
245 EXPECT_FALSE(frame_reader.ReadBytes(&dest, arraysize(kFrameData) + 1)); | 245 EXPECT_FALSE(frame_reader.ReadBytes(&dest, arraysize(kFrameData) + 1)); |
246 EXPECT_STREQ("", dest); | 246 EXPECT_STREQ("", dest); |
247 } | 247 } |
248 | 248 |
249 } // namespace net | 249 } // namespace net |
OLD | NEW |