OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
| 11 #include "webrtc/base/arraysize.h" |
11 #include "webrtc/base/bytebuffer.h" | 12 #include "webrtc/base/bytebuffer.h" |
12 #include "webrtc/base/byteorder.h" | 13 #include "webrtc/base/byteorder.h" |
13 #include "webrtc/base/common.h" | 14 #include "webrtc/base/common.h" |
14 #include "webrtc/base/gunit.h" | 15 #include "webrtc/base/gunit.h" |
15 | 16 |
16 namespace rtc { | 17 namespace rtc { |
17 | 18 |
18 TEST(ByteBufferTest, TestByteOrder) { | 19 TEST(ByteBufferTest, TestByteOrder) { |
19 uint16_t n16 = 1; | 20 uint16_t n16 = 1; |
20 uint32_t n32 = 1; | 21 uint32_t n32 = 1; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 EXPECT_EQ(capacity + 3U, buffer.Length()); | 108 EXPECT_EQ(capacity + 3U, buffer.Length()); |
108 EXPECT_FALSE(buffer.SetReadPosition(pos)); | 109 EXPECT_FALSE(buffer.SetReadPosition(pos)); |
109 read.clear(); | 110 read.clear(); |
110 EXPECT_TRUE(buffer.ReadString(&read, 3)); | 111 EXPECT_TRUE(buffer.ReadString(&read, 3)); |
111 EXPECT_EQ("DEF", read); | 112 EXPECT_EQ("DEF", read); |
112 } | 113 } |
113 | 114 |
114 TEST(ByteBufferTest, TestReadWriteBuffer) { | 115 TEST(ByteBufferTest, TestReadWriteBuffer) { |
115 ByteBuffer::ByteOrder orders[2] = { ByteBuffer::ORDER_HOST, | 116 ByteBuffer::ByteOrder orders[2] = { ByteBuffer::ORDER_HOST, |
116 ByteBuffer::ORDER_NETWORK }; | 117 ByteBuffer::ORDER_NETWORK }; |
117 for (size_t i = 0; i < ARRAY_SIZE(orders); i++) { | 118 for (size_t i = 0; i < arraysize(orders); i++) { |
118 ByteBuffer buffer(orders[i]); | 119 ByteBuffer buffer(orders[i]); |
119 EXPECT_EQ(orders[i], buffer.Order()); | 120 EXPECT_EQ(orders[i], buffer.Order()); |
120 uint8_t ru8; | 121 uint8_t ru8; |
121 EXPECT_FALSE(buffer.ReadUInt8(&ru8)); | 122 EXPECT_FALSE(buffer.ReadUInt8(&ru8)); |
122 | 123 |
123 // Write and read uint8_t. | 124 // Write and read uint8_t. |
124 uint8_t wu8 = 1; | 125 uint8_t wu8 = 1; |
125 buffer.WriteUInt8(wu8); | 126 buffer.WriteUInt8(wu8); |
126 EXPECT_TRUE(buffer.ReadUInt8(&ru8)); | 127 EXPECT_TRUE(buffer.ReadUInt8(&ru8)); |
127 EXPECT_EQ(wu8, ru8); | 128 EXPECT_EQ(wu8, ru8); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 EXPECT_EQ(wu24, ru24); | 203 EXPECT_EQ(wu24, ru24); |
203 EXPECT_TRUE(buffer.ReadUInt32(&ru32)); | 204 EXPECT_TRUE(buffer.ReadUInt32(&ru32)); |
204 EXPECT_EQ(wu32, ru32); | 205 EXPECT_EQ(wu32, ru32); |
205 EXPECT_TRUE(buffer.ReadUInt64(&ru64)); | 206 EXPECT_TRUE(buffer.ReadUInt64(&ru64)); |
206 EXPECT_EQ(wu64, ru64); | 207 EXPECT_EQ(wu64, ru64); |
207 EXPECT_EQ(0U, buffer.Length()); | 208 EXPECT_EQ(0U, buffer.Length()); |
208 } | 209 } |
209 } | 210 } |
210 | 211 |
211 } // namespace rtc | 212 } // namespace rtc |
OLD | NEW |