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 htons(1), htons(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 arraysize(kFrameData) * sizeof(uint16)); | 22 arraysize(kFrameData) * sizeof(uint16)); |
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(1u, 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(1<<31), | 38 htonl(1), htonl(1<<31), |
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); |
49 | 49 |
50 EXPECT_TRUE(frame_reader.ReadUInt32(&uint32_val)); | 50 EXPECT_TRUE(frame_reader.ReadUInt32(&uint32_val)); |
51 EXPECT_TRUE(frame_reader.IsDoneReading()); | 51 EXPECT_TRUE(frame_reader.IsDoneReading()); |
52 EXPECT_EQ(static_cast<uint32>(1<<31), uint32_val); | 52 EXPECT_EQ(1u<<31, uint32_val); |
53 } | 53 } |
54 | 54 |
55 TEST(SpdyFrameReaderTest, ReadStringPiece16) { | 55 TEST(SpdyFrameReaderTest, ReadStringPiece16) { |
56 // Frame data in network byte order. | 56 // Frame data in network byte order. |
57 const char kFrameData[] = { | 57 const char kFrameData[] = { |
58 0x00, 0x02, // uint16(2) | 58 0x00, 0x02, // uint16(2) |
59 0x48, 0x69, // "Hi" | 59 0x48, 0x69, // "Hi" |
60 0x00, 0x10, // uint16(16) | 60 0x00, 0x10, // uint16(16) |
61 0x54, 0x65, 0x73, 0x74, | 61 0x54, 0x65, 0x73, 0x74, |
62 0x69, 0x6e, 0x67, 0x2c, | 62 0x69, 0x6e, 0x67, 0x2c, |
(...skipping 177 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 |