| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 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/bitbuffer.h" | 12 #include "webrtc/base/bitbuffer.h" |
| 12 #include "webrtc/base/bytebuffer.h" | 13 #include "webrtc/base/bytebuffer.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(BitBufferTest, ConsumeBits) { | 19 TEST(BitBufferTest, ConsumeBits) { |
| 19 const uint8_t bytes[64] = {0}; | 20 const uint8_t bytes[64] = {0}; |
| 20 BitBuffer buffer(bytes, 32); | 21 BitBuffer buffer(bytes, 32); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 EXPECT_TRUE(buffer.ReadUInt16(&val16)); | 295 EXPECT_TRUE(buffer.ReadUInt16(&val16)); |
| 295 EXPECT_EQ(0x3456u, val16); | 296 EXPECT_EQ(0x3456u, val16); |
| 296 EXPECT_TRUE(buffer.ReadUInt32(&val32)); | 297 EXPECT_TRUE(buffer.ReadUInt32(&val32)); |
| 297 EXPECT_EQ(0x789ABCDEu, val32); | 298 EXPECT_EQ(0x789ABCDEu, val32); |
| 298 } | 299 } |
| 299 | 300 |
| 300 TEST(BitBufferWriterTest, SymmetricGolomb) { | 301 TEST(BitBufferWriterTest, SymmetricGolomb) { |
| 301 char test_string[] = "my precious"; | 302 char test_string[] = "my precious"; |
| 302 uint8_t bytes[64] = {0}; | 303 uint8_t bytes[64] = {0}; |
| 303 BitBufferWriter buffer(bytes, 64); | 304 BitBufferWriter buffer(bytes, 64); |
| 304 for (size_t i = 0; i < ARRAY_SIZE(test_string); ++i) { | 305 for (size_t i = 0; i < arraysize(test_string); ++i) { |
| 305 EXPECT_TRUE(buffer.WriteExponentialGolomb(test_string[i])); | 306 EXPECT_TRUE(buffer.WriteExponentialGolomb(test_string[i])); |
| 306 } | 307 } |
| 307 buffer.Seek(0, 0); | 308 buffer.Seek(0, 0); |
| 308 for (size_t i = 0; i < ARRAY_SIZE(test_string); ++i) { | 309 for (size_t i = 0; i < arraysize(test_string); ++i) { |
| 309 uint32_t val; | 310 uint32_t val; |
| 310 EXPECT_TRUE(buffer.ReadExponentialGolomb(&val)); | 311 EXPECT_TRUE(buffer.ReadExponentialGolomb(&val)); |
| 311 EXPECT_LE(val, std::numeric_limits<uint8_t>::max()); | 312 EXPECT_LE(val, std::numeric_limits<uint8_t>::max()); |
| 312 EXPECT_EQ(test_string[i], static_cast<char>(val)); | 313 EXPECT_EQ(test_string[i], static_cast<char>(val)); |
| 313 } | 314 } |
| 314 } | 315 } |
| 315 | 316 |
| 316 TEST(BitBufferWriterTest, WriteClearsBits) { | 317 TEST(BitBufferWriterTest, WriteClearsBits) { |
| 317 uint8_t bytes[] = {0xFF, 0xFF}; | 318 uint8_t bytes[] = {0xFF, 0xFF}; |
| 318 BitBufferWriter buffer(bytes, 2); | 319 BitBufferWriter buffer(bytes, 2); |
| 319 EXPECT_TRUE(buffer.ConsumeBits(3)); | 320 EXPECT_TRUE(buffer.ConsumeBits(3)); |
| 320 EXPECT_TRUE(buffer.WriteBits(0, 1)); | 321 EXPECT_TRUE(buffer.WriteBits(0, 1)); |
| 321 EXPECT_EQ(0xEFu, bytes[0]); | 322 EXPECT_EQ(0xEFu, bytes[0]); |
| 322 EXPECT_TRUE(buffer.WriteBits(0, 3)); | 323 EXPECT_TRUE(buffer.WriteBits(0, 3)); |
| 323 EXPECT_EQ(0xE1u, bytes[0]); | 324 EXPECT_EQ(0xE1u, bytes[0]); |
| 324 EXPECT_TRUE(buffer.WriteBits(0, 2)); | 325 EXPECT_TRUE(buffer.WriteBits(0, 2)); |
| 325 EXPECT_EQ(0xE0u, bytes[0]); | 326 EXPECT_EQ(0xE0u, bytes[0]); |
| 326 EXPECT_EQ(0x7F, bytes[1]); | 327 EXPECT_EQ(0x7F, bytes[1]); |
| 327 } | 328 } |
| 328 | 329 |
| 329 } // namespace rtc | 330 } // namespace rtc |
| OLD | NEW |