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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 uint64 encoded_val = GolombEncoded(i); | 198 uint64 encoded_val = GolombEncoded(i); |
199 byteBuffer.Clear(); | 199 byteBuffer.Clear(); |
200 byteBuffer.WriteUInt64(encoded_val); | 200 byteBuffer.WriteUInt64(encoded_val); |
201 uint32 decoded_val; | 201 uint32 decoded_val; |
202 EXPECT_TRUE(buffer.Seek(0, 0)); | 202 EXPECT_TRUE(buffer.Seek(0, 0)); |
203 EXPECT_TRUE(buffer.ReadExponentialGolomb(&decoded_val)); | 203 EXPECT_TRUE(buffer.ReadExponentialGolomb(&decoded_val)); |
204 EXPECT_EQ(i, decoded_val); | 204 EXPECT_EQ(i, decoded_val); |
205 } | 205 } |
206 } | 206 } |
207 | 207 |
| 208 TEST(BitBufferTest, SignedGolombValues) { |
| 209 uint8_t golomb_bits[] = { |
| 210 0x80, // 1 |
| 211 0x40, // 010 |
| 212 0x60, // 011 |
| 213 0x20, // 00100 |
| 214 0x38, // 00111 |
| 215 }; |
| 216 int32_t expected[] = {0, 1, -1, 2, -3}; |
| 217 for (size_t i = 0; i < sizeof(golomb_bits); ++i) { |
| 218 BitBuffer buffer(&golomb_bits[i], 1); |
| 219 int32_t decoded_val; |
| 220 ASSERT_TRUE(buffer.ReadSignedExponentialGolomb(&decoded_val)); |
| 221 EXPECT_EQ(expected[i], decoded_val) |
| 222 << "Mismatch in expected/decoded value for golomb_bits[" << i |
| 223 << "]: " << static_cast<int>(golomb_bits[i]); |
| 224 } |
| 225 } |
| 226 |
208 TEST(BitBufferTest, NoGolombOverread) { | 227 TEST(BitBufferTest, NoGolombOverread) { |
209 const uint8 bytes[] = {0x00, 0xFF, 0xFF}; | 228 const uint8 bytes[] = {0x00, 0xFF, 0xFF}; |
210 // Make sure the bit buffer correctly enforces byte length on golomb reads. | 229 // Make sure the bit buffer correctly enforces byte length on golomb reads. |
211 // If it didn't, the above buffer would be valid at 3 bytes. | 230 // If it didn't, the above buffer would be valid at 3 bytes. |
212 BitBuffer buffer(bytes, 1); | 231 BitBuffer buffer(bytes, 1); |
213 uint32 decoded_val; | 232 uint32 decoded_val; |
214 EXPECT_FALSE(buffer.ReadExponentialGolomb(&decoded_val)); | 233 EXPECT_FALSE(buffer.ReadExponentialGolomb(&decoded_val)); |
215 | 234 |
216 BitBuffer longer_buffer(bytes, 2); | 235 BitBuffer longer_buffer(bytes, 2); |
217 EXPECT_FALSE(longer_buffer.ReadExponentialGolomb(&decoded_val)); | 236 EXPECT_FALSE(longer_buffer.ReadExponentialGolomb(&decoded_val)); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 EXPECT_TRUE(buffer.WriteBits(0, 1)); | 319 EXPECT_TRUE(buffer.WriteBits(0, 1)); |
301 EXPECT_EQ(0xEFu, bytes[0]); | 320 EXPECT_EQ(0xEFu, bytes[0]); |
302 EXPECT_TRUE(buffer.WriteBits(0, 3)); | 321 EXPECT_TRUE(buffer.WriteBits(0, 3)); |
303 EXPECT_EQ(0xE1u, bytes[0]); | 322 EXPECT_EQ(0xE1u, bytes[0]); |
304 EXPECT_TRUE(buffer.WriteBits(0, 2)); | 323 EXPECT_TRUE(buffer.WriteBits(0, 2)); |
305 EXPECT_EQ(0xE0u, bytes[0]); | 324 EXPECT_EQ(0xE0u, bytes[0]); |
306 EXPECT_EQ(0x7F, bytes[1]); | 325 EXPECT_EQ(0x7F, bytes[1]); |
307 } | 326 } |
308 | 327 |
309 } // namespace rtc | 328 } // namespace rtc |
OLD | NEW |