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 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 EXPECT_EQ(wu24, ru24); | 189 EXPECT_EQ(wu24, ru24); |
190 EXPECT_TRUE(read_buf9.ReadUInt32(&ru32)); | 190 EXPECT_TRUE(read_buf9.ReadUInt32(&ru32)); |
191 EXPECT_EQ(wu32, ru32); | 191 EXPECT_EQ(wu32, ru32); |
192 EXPECT_TRUE(read_buf9.ReadUInt64(&ru64)); | 192 EXPECT_TRUE(read_buf9.ReadUInt64(&ru64)); |
193 EXPECT_EQ(wu64, ru64); | 193 EXPECT_EQ(wu64, ru64); |
194 EXPECT_EQ(0U, read_buf9.Length()); | 194 EXPECT_EQ(0U, read_buf9.Length()); |
195 buffer.Clear(); | 195 buffer.Clear(); |
196 } | 196 } |
197 } | 197 } |
198 | 198 |
| 199 TEST(ByteBufferTest, TestReadWriteUVarint) { |
| 200 ByteBufferWriter::ByteOrder orders[2] = {ByteBufferWriter::ORDER_HOST, |
| 201 ByteBufferWriter::ORDER_NETWORK}; |
| 202 for (ByteBufferWriter::ByteOrder& order : orders) { |
| 203 ByteBufferWriter write_buffer(order); |
| 204 size_t size = 0; |
| 205 EXPECT_EQ(size, write_buffer.Length()); |
| 206 |
| 207 write_buffer.WriteUVarint(1u); |
| 208 ++size; |
| 209 EXPECT_EQ(size, write_buffer.Length()); |
| 210 |
| 211 write_buffer.WriteUVarint(2u); |
| 212 ++size; |
| 213 EXPECT_EQ(size, write_buffer.Length()); |
| 214 |
| 215 write_buffer.WriteUVarint(27u); |
| 216 ++size; |
| 217 EXPECT_EQ(size, write_buffer.Length()); |
| 218 |
| 219 write_buffer.WriteUVarint(149u); |
| 220 size += 2; |
| 221 EXPECT_EQ(size, write_buffer.Length()); |
| 222 |
| 223 write_buffer.WriteUVarint(68719476736u); |
| 224 size += 6; |
| 225 EXPECT_EQ(size, write_buffer.Length()); |
| 226 |
| 227 ByteBufferReader read_buffer(write_buffer.Data(), write_buffer.Length(), |
| 228 order); |
| 229 EXPECT_EQ(size, read_buffer.Length()); |
| 230 uint64_t val1, val2, val3, val4, val5; |
| 231 |
| 232 ASSERT_TRUE(read_buffer.ReadUVarint(&val1)); |
| 233 EXPECT_EQ(1u, val1); |
| 234 --size; |
| 235 EXPECT_EQ(size, read_buffer.Length()); |
| 236 |
| 237 ASSERT_TRUE(read_buffer.ReadUVarint(&val2)); |
| 238 EXPECT_EQ(2u, val2); |
| 239 --size; |
| 240 EXPECT_EQ(size, read_buffer.Length()); |
| 241 |
| 242 ASSERT_TRUE(read_buffer.ReadUVarint(&val3)); |
| 243 EXPECT_EQ(27u, val3); |
| 244 --size; |
| 245 EXPECT_EQ(size, read_buffer.Length()); |
| 246 |
| 247 ASSERT_TRUE(read_buffer.ReadUVarint(&val4)); |
| 248 EXPECT_EQ(149u, val4); |
| 249 size -= 2; |
| 250 EXPECT_EQ(size, read_buffer.Length()); |
| 251 |
| 252 ASSERT_TRUE(read_buffer.ReadUVarint(&val5)); |
| 253 EXPECT_EQ(68719476736u, val5); |
| 254 size -= 6; |
| 255 EXPECT_EQ(size, read_buffer.Length()); |
| 256 } |
| 257 } |
| 258 |
199 } // namespace rtc | 259 } // namespace rtc |
OLD | NEW |