Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: media/filters/h264_bitstream_buffer_unittest.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/filters/h264_bitstream_buffer.h" 5 #include "media/filters/h264_bitstream_buffer.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 namespace media { 8 namespace media {
9 9
10 namespace { 10 namespace {
11 const uint64 kTestPattern = 0xfedcba0987654321; 11 const uint64_t kTestPattern = 0xfedcba0987654321;
12 } 12 }
13 13
14 class H264BitstreamBufferAppendBitsTest 14 class H264BitstreamBufferAppendBitsTest
15 : public ::testing::TestWithParam<uint64> {}; 15 : public ::testing::TestWithParam<uint64_t> {};
16 16
17 // TODO(posciak): More tests! 17 // TODO(posciak): More tests!
18 18
19 TEST_P(H264BitstreamBufferAppendBitsTest, AppendAndVerifyBits) { 19 TEST_P(H264BitstreamBufferAppendBitsTest, AppendAndVerifyBits) {
20 H264BitstreamBuffer b; 20 H264BitstreamBuffer b;
21 uint64 num_bits = GetParam(); 21 uint64_t num_bits = GetParam();
22 // TODO(posciak): Tests for >64 bits. 22 // TODO(posciak): Tests for >64 bits.
23 ASSERT_LE(num_bits, 64u); 23 ASSERT_LE(num_bits, 64u);
24 uint64 num_bytes = (num_bits + 7) / 8; 24 uint64_t num_bytes = (num_bits + 7) / 8;
25 25
26 b.AppendBits(num_bits, kTestPattern); 26 b.AppendBits(num_bits, kTestPattern);
27 b.FlushReg(); 27 b.FlushReg();
28 28
29 EXPECT_EQ(b.BytesInBuffer(), num_bytes); 29 EXPECT_EQ(b.BytesInBuffer(), num_bytes);
30 30
31 uint8* ptr = b.data(); 31 uint8_t* ptr = b.data();
32 uint64 got = 0; 32 uint64_t got = 0;
33 uint64 expected = kTestPattern; 33 uint64_t expected = kTestPattern;
34 34
35 if (num_bits < 64) 35 if (num_bits < 64)
36 expected &= ((1ull << num_bits) - 1); 36 expected &= ((1ull << num_bits) - 1);
37 37
38 while (num_bits > 8) { 38 while (num_bits > 8) {
39 got |= (*ptr & 0xff); 39 got |= (*ptr & 0xff);
40 num_bits -= 8; 40 num_bits -= 8;
41 got <<= (num_bits > 8 ? 8 : num_bits); 41 got <<= (num_bits > 8 ? 8 : num_bits);
42 ptr++; 42 ptr++;
43 } 43 }
44 if (num_bits > 0) { 44 if (num_bits > 0) {
45 uint64 temp = (*ptr & 0xff); 45 uint64_t temp = (*ptr & 0xff);
46 temp >>= (8 - num_bits); 46 temp >>= (8 - num_bits);
47 got |= temp; 47 got |= temp;
48 } 48 }
49 EXPECT_EQ(got, expected) << std::hex << "0x" << got << " vs 0x" << expected; 49 EXPECT_EQ(got, expected) << std::hex << "0x" << got << " vs 0x" << expected;
50 } 50 }
51 51
52 INSTANTIATE_TEST_CASE_P(AppendNumBits, 52 INSTANTIATE_TEST_CASE_P(AppendNumBits,
53 H264BitstreamBufferAppendBitsTest, 53 H264BitstreamBufferAppendBitsTest,
54 ::testing::Range(static_cast<uint64>(1), 54 ::testing::Range(static_cast<uint64_t>(1),
55 static_cast<uint64>(65))); 55 static_cast<uint64_t>(65)));
56 } // namespace media 56 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698