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

Side by Side Diff: media/base/bit_reader_unittest.cc

Issue 10780026: Add HE AAC support to ISO BMFF. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove unused functions and variables. Created 8 years, 5 months 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
(Empty)
1 // Copyright (c) 2012 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/base/bit_reader.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace media {
10
11 TEST(BitReaderTest, EmptyStreamTest) {
12 uint8 value8 = 0xff;
13 BitReader reader(NULL, 0);
14
15 EXPECT_EQ(reader.NumBitsLeft(), 0);
16 EXPECT_TRUE(reader.ReadBits(0, &value8));
17 EXPECT_TRUE(reader.SkipBits(0));
18 EXPECT_EQ(reader.NumBitsLeft(), 0);
19 EXPECT_FALSE(reader.ReadBits(1, &value8));
20 EXPECT_FALSE(reader.SkipBits(1));
21 EXPECT_EQ(value8, 0);
22 }
23
24 TEST(BitReaderTest, NormalOperationTest) {
25 uint8 value8;
26 uint64 value64;
27 // 0101 0101 1001 1001 repeats 4 times
28 uint8 buffer[] = {0x55, 0x99, 0x55, 0x99, 0x55, 0x99, 0x55, 0x99};
29 BitReader reader1(buffer, 6); // Initialize with 6 bytes only
30
31 EXPECT_EQ(reader1.NumBitsLeft(), 48);
32 EXPECT_TRUE(reader1.ReadBits(1, &value8));
33 EXPECT_EQ(value8, 0);
34 EXPECT_TRUE(reader1.ReadBits(8, &value8));
35 EXPECT_EQ(value8, 0xab); // 1010 1011
36 EXPECT_EQ(reader1.NumBitsLeft(), 39);
37 EXPECT_TRUE(reader1.SkipBits(7));
38 EXPECT_TRUE(reader1.ReadBits(32, &value64));
39 EXPECT_EQ(value64, 0x55995599u);
40 EXPECT_EQ(reader1.NumBitsLeft(), 0);
41 EXPECT_FALSE(reader1.SkipBits(1));
42 EXPECT_FALSE(reader1.ReadBits(1, &value8));
43 EXPECT_TRUE(reader1.SkipBits(0));
44 value8 = 0xff;
45 EXPECT_TRUE(reader1.ReadBits(0, &value8));
46 EXPECT_EQ(value8, 0);
47
48 BitReader reader2(buffer, 8);
49 EXPECT_TRUE(reader2.ReadBits(64, &value64));
50 EXPECT_EQ(value64, 0x5599559955995599ull);
51 EXPECT_EQ(reader2.NumBitsLeft(), 0);
52 EXPECT_FALSE(reader2.ReadBits(1, &value8));
53 EXPECT_FALSE(reader2.SkipBits(1));
54 EXPECT_TRUE(reader2.ReadBits(0, &value8));
55 EXPECT_TRUE(reader2.SkipBits(0));
56 }
57
58 TEST(BitReaderTest, LongSkipTest) {
59 uint8 value8;
60 uint8 buffer[] = {
61 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, // 64 * 1
62 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, // 64 * 2
63 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, // 64 * 3
64 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, // 64 * 4
65 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, // 64 * 5
66 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, // 64 * 6
67 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, // 64 * 7
68 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, // 64 * 8
69 0x87, 0x65
70 };
71 BitReader reader(buffer, sizeof(buffer));
72
73 EXPECT_TRUE(reader.SkipBits(64 * 8 + 8));
74 EXPECT_TRUE(reader.ReadBits(8, &value8));
75 EXPECT_EQ(value8, 0x65);
76 EXPECT_EQ(reader.NumBitsLeft(), 0);
77 }
78
79 TEST(BitReaderTest, ReadBeyondEndTest) {
80 uint8 value8;
81 uint8 buffer[] = {0x12};
82 BitReader reader1(buffer, sizeof(buffer));
83
84 EXPECT_TRUE(reader1.SkipBits(4));
85 EXPECT_FALSE(reader1.ReadBits(5, &value8));
86 EXPECT_FALSE(reader1.ReadBits(1, &value8));
87 EXPECT_FALSE(reader1.SkipBits(1));
88 EXPECT_TRUE(reader1.ReadBits(0, &value8));
89 EXPECT_TRUE(reader1.SkipBits(0));
90
91 BitReader reader2(buffer, sizeof(buffer));
92
93 EXPECT_TRUE(reader2.SkipBits(4));
94 EXPECT_FALSE(reader2.SkipBits(5));
95 EXPECT_FALSE(reader2.ReadBits(1, &value8));
96 EXPECT_FALSE(reader2.SkipBits(1));
97 EXPECT_TRUE(reader2.ReadBits(0, &value8));
98 EXPECT_TRUE(reader2.SkipBits(0));
99 }
100
101 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698