| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/filters/h264_bitstream_buffer.h" | |
| 6 #include "testing/gtest/include/gtest/gtest.h" | |
| 7 | |
| 8 namespace media { | |
| 9 | |
| 10 namespace { | |
| 11 const uint64 kTestPattern = 0xfedcba0987654321; | |
| 12 } | |
| 13 | |
| 14 class H264BitstreamBufferAppendBitsTest | |
| 15 : public ::testing::TestWithParam<size_t> {}; | |
| 16 | |
| 17 // TODO(posciak): More tests! | |
| 18 | |
| 19 TEST_P(H264BitstreamBufferAppendBitsTest, AppendAndVerifyBits) { | |
| 20 H264BitstreamBuffer b; | |
| 21 uint64 num_bits = GetParam(); | |
| 22 // TODO(posciak): Tests for >64 bits. | |
| 23 ASSERT_LE(num_bits, 64u); | |
| 24 uint64 num_bytes = (num_bits + 7) / 8; | |
| 25 | |
| 26 b.AppendBits(num_bits, kTestPattern); | |
| 27 b.FlushReg(); | |
| 28 | |
| 29 EXPECT_EQ(b.BytesInBuffer(), num_bytes); | |
| 30 | |
| 31 uint8* ptr = b.data(); | |
| 32 uint64 got = 0; | |
| 33 uint64 expected = kTestPattern; | |
| 34 | |
| 35 if (num_bits < 64) | |
| 36 expected &= ((1ull << num_bits) - 1); | |
| 37 | |
| 38 while (num_bits > 8) { | |
| 39 got |= (*ptr & 0xff); | |
| 40 num_bits -= 8; | |
| 41 got <<= (num_bits > 8 ? 8 : num_bits); | |
| 42 ptr++; | |
| 43 } | |
| 44 if (num_bits > 0) { | |
| 45 uint64 temp = (*ptr & 0xff); | |
| 46 temp >>= (8 - num_bits); | |
| 47 got |= temp; | |
| 48 } | |
| 49 EXPECT_EQ(got, expected) << std::hex << "0x" << got << " vs 0x" << expected; | |
| 50 } | |
| 51 | |
| 52 INSTANTIATE_TEST_CASE_P(AppendNumBits, | |
| 53 H264BitstreamBufferAppendBitsTest, | |
| 54 ::testing::Range(1ul, 65ul)); | |
| 55 } // namespace media | |
| OLD | NEW |