| 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 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 uint32_t bit_counter = val; | 181 uint32_t bit_counter = val; |
| 182 uint64_t bit_count = 0; | 182 uint64_t bit_count = 0; |
| 183 while (bit_counter > 0) { | 183 while (bit_counter > 0) { |
| 184 bit_count++; | 184 bit_count++; |
| 185 bit_counter >>= 1; | 185 bit_counter >>= 1; |
| 186 } | 186 } |
| 187 return static_cast<uint64_t>(val) << (64 - (bit_count * 2 - 1)); | 187 return static_cast<uint64_t>(val) << (64 - (bit_count * 2 - 1)); |
| 188 } | 188 } |
| 189 | 189 |
| 190 TEST(BitBufferTest, GolombUint32Values) { | 190 TEST(BitBufferTest, GolombUint32Values) { |
| 191 ByteBuffer byteBuffer; | 191 ByteBufferWriter byteBuffer; |
| 192 byteBuffer.Resize(16); | 192 byteBuffer.Resize(16); |
| 193 BitBuffer buffer(reinterpret_cast<const uint8_t*>(byteBuffer.Data()), | 193 BitBuffer buffer(reinterpret_cast<const uint8_t*>(byteBuffer.Data()), |
| 194 byteBuffer.Capacity()); | 194 byteBuffer.Capacity()); |
| 195 // Test over the uint32_t range with a large enough step that the test doesn't | 195 // Test over the uint32_t range with a large enough step that the test doesn't |
| 196 // take forever. Around 20,000 iterations should do. | 196 // take forever. Around 20,000 iterations should do. |
| 197 const int kStep = std::numeric_limits<uint32_t>::max() / 20000; | 197 const int kStep = std::numeric_limits<uint32_t>::max() / 20000; |
| 198 for (uint32_t i = 0; i < std::numeric_limits<uint32_t>::max() - kStep; | 198 for (uint32_t i = 0; i < std::numeric_limits<uint32_t>::max() - kStep; |
| 199 i += kStep) { | 199 i += kStep) { |
| 200 uint64_t encoded_val = GolombEncoded(i); | 200 uint64_t encoded_val = GolombEncoded(i); |
| 201 byteBuffer.Clear(); | 201 byteBuffer.Clear(); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 EXPECT_TRUE(buffer.WriteBits(0, 1)); | 321 EXPECT_TRUE(buffer.WriteBits(0, 1)); |
| 322 EXPECT_EQ(0xEFu, bytes[0]); | 322 EXPECT_EQ(0xEFu, bytes[0]); |
| 323 EXPECT_TRUE(buffer.WriteBits(0, 3)); | 323 EXPECT_TRUE(buffer.WriteBits(0, 3)); |
| 324 EXPECT_EQ(0xE1u, bytes[0]); | 324 EXPECT_EQ(0xE1u, bytes[0]); |
| 325 EXPECT_TRUE(buffer.WriteBits(0, 2)); | 325 EXPECT_TRUE(buffer.WriteBits(0, 2)); |
| 326 EXPECT_EQ(0xE0u, bytes[0]); | 326 EXPECT_EQ(0xE0u, bytes[0]); |
| 327 EXPECT_EQ(0x7F, bytes[1]); | 327 EXPECT_EQ(0x7F, bytes[1]); |
| 328 } | 328 } |
| 329 | 329 |
| 330 } // namespace rtc | 330 } // namespace rtc |
| OLD | NEW |