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

Side by Side Diff: content/common/gpu/media/h264_parser_unittest.cc

Issue 10834071: Add unittest for H264BitReader. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove MultiFileStreamParser and empty ctor/dtor. Created 8 years, 4 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
« no previous file with comments | « content/common/gpu/media/h264_parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 break; 65 break;
66 66
67 default: 67 default:
68 // Skip unsupported NALU. 68 // Skip unsupported NALU.
69 DVLOG(4) << "Skipping unsupported NALU"; 69 DVLOG(4) << "Skipping unsupported NALU";
70 break; 70 break;
71 } 71 }
72 } 72 }
73 } 73 }
74 74
75 class H264BitReaderTest : public ::testing::Test {
Ami GONE FROM CHROMIUM 2012/07/31 17:24:15 AFAICT this class's sole purpose is to forward cal
xiaomings 2012/07/31 19:24:32 The class H264BitReader is a private nested class
Ami GONE FROM CHROMIUM 2012/07/31 20:30:25 Any reason not to extract the bitreader outside of
76 public:
77 bool Initialize(const uint8* data, off_t size) {
78 return reader_.Initialize(data, size);
79 }
80
81 bool ReadBits(int num_bits, int *out) {
82 return reader_.ReadBits(num_bits, out);
83 }
84
85 off_t NumBitsLeft() {
86 return reader_.NumBitsLeft();
87 }
88
89 bool HasMoreRBSPData() {
90 return reader_.HasMoreRBSPData();
91 }
92
93 private:
94 H264Parser::H264BitReader reader_;
95 };
96
97 TEST_F(H264BitReaderTest, ReadStreamWithoutEscapeAndTrailingZeroBytes) {
98 const unsigned char rbsp[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xa0};
99 int dummy = 0;
100
101 EXPECT_TRUE(Initialize(rbsp, sizeof(rbsp)));
102
103 EXPECT_TRUE(ReadBits(1, &dummy));
104 EXPECT_EQ(dummy, 0x00);
105 EXPECT_EQ(NumBitsLeft(), 47);
106 EXPECT_TRUE(HasMoreRBSPData());
107
108 EXPECT_TRUE(ReadBits(8, &dummy));
109 EXPECT_EQ(dummy, 0x02);
110 EXPECT_EQ(NumBitsLeft(), 39);
111 EXPECT_TRUE(HasMoreRBSPData());
112
113 EXPECT_TRUE(ReadBits(31, &dummy));
114 EXPECT_EQ(dummy, 0x23456789);
115 EXPECT_EQ(NumBitsLeft(), 8);
116 EXPECT_TRUE(HasMoreRBSPData());
117
118 EXPECT_TRUE(ReadBits(1, &dummy));
119 EXPECT_EQ(dummy, 1);
120 EXPECT_EQ(NumBitsLeft(), 7);
121 EXPECT_TRUE(HasMoreRBSPData());
122
123 EXPECT_TRUE(ReadBits(1, &dummy));
124 EXPECT_EQ(dummy, 0);
125 EXPECT_EQ(NumBitsLeft(), 6);
126 EXPECT_FALSE(HasMoreRBSPData());
127 }
128
129 TEST_F(H264BitReaderTest, EmptyStream) {
130 const unsigned char rbsp[] = {0x80, 0x00, 0x00};
131
132 EXPECT_FALSE(Initialize(rbsp, 0));
133 EXPECT_FALSE(Initialize(rbsp, 1));
134 EXPECT_FALSE(Initialize(rbsp, sizeof(rbsp)));
135 }
136
137 TEST_F(H264BitReaderTest, SingleByteStream) {
138 const unsigned char rbsp[] = {0x18};
139 int dummy = 0;
140
141 EXPECT_TRUE(Initialize(rbsp, sizeof(rbsp)));
142 EXPECT_EQ(NumBitsLeft(), 8);
143 EXPECT_TRUE(HasMoreRBSPData());
144
145 EXPECT_TRUE(ReadBits(4, &dummy));
146 EXPECT_EQ(dummy, 0x01);
147 EXPECT_EQ(NumBitsLeft(), 4);
148 EXPECT_FALSE(HasMoreRBSPData());
149 }
150
151 TEST_F(H264BitReaderTest, StopBitOccupyFullByte) {
152 const unsigned char rbsp[] = {0xab, 0x80};
153 int dummy = 0;
154
155 EXPECT_TRUE(Initialize(rbsp, sizeof(rbsp)));
156 EXPECT_EQ(NumBitsLeft(), 16);
157 EXPECT_TRUE(HasMoreRBSPData());
158
159 EXPECT_TRUE(ReadBits(8, &dummy));
160 EXPECT_EQ(dummy, 0xab);
161 EXPECT_EQ(NumBitsLeft(), 8);
162 EXPECT_FALSE(HasMoreRBSPData());
163 }
164
165 TEST_F(H264BitReaderTest, ReadFailure) {
166 const unsigned char rbsp[] = {0x18};
167 int dummy = 0;
168
169 EXPECT_TRUE(Initialize(rbsp, 1));
170 EXPECT_FALSE(ReadBits(5, &dummy));
171 }
172
173 TEST_F(H264BitReaderTest, MalformedStream) {
174 const unsigned char rbsp[] = {0x00, 0x00, 0x03, 0x00, 0x00};
175
176 EXPECT_FALSE(Initialize(rbsp, 1));
177 EXPECT_FALSE(Initialize(rbsp, sizeof(rbsp)));
178 }
179
180 TEST_F(H264BitReaderTest, EscapeSequence) {
181 const unsigned char rbsp[] =
182 {0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x03};
183 int dummy = 0;
184
185 EXPECT_TRUE(Initialize(rbsp, sizeof(rbsp)));
186
187 EXPECT_TRUE(ReadBits(8, &dummy));
188 EXPECT_EQ(dummy, 0x00);
189 EXPECT_EQ(NumBitsLeft(), 80);
190 EXPECT_TRUE(HasMoreRBSPData());
191
192 EXPECT_TRUE(ReadBits(24, &dummy));
193 EXPECT_EQ(dummy, 0x00);
194 EXPECT_EQ(NumBitsLeft(), 48);
195 EXPECT_TRUE(HasMoreRBSPData());
196
197 EXPECT_TRUE(ReadBits(15, &dummy));
198 EXPECT_EQ(dummy, 0x01);
199 EXPECT_EQ(NumBitsLeft(), 25);
200 EXPECT_FALSE(HasMoreRBSPData());
201 }
202
203 TEST_F(H264BitReaderTest, NonEscapeFollowedByStopBit) {
204 const unsigned char rbsp[] = {0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00};
205 int dummy = 0;
206
207 EXPECT_TRUE(Initialize(rbsp, sizeof(rbsp)));
208 EXPECT_TRUE(ReadBits(23, &dummy));
209 EXPECT_EQ(dummy, 0x03);
210 EXPECT_EQ(NumBitsLeft(), 33);
211 EXPECT_FALSE(HasMoreRBSPData());
212 }
213
214 TEST_F(H264BitReaderTest, TrailingZero) {
215 const unsigned char rbsp[] = {0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00};
216 int dummy = 0;
217
218 EXPECT_TRUE(Initialize(rbsp, sizeof(rbsp)));
219 EXPECT_TRUE(ReadBits(8, &dummy));
220 EXPECT_EQ(dummy, 0x01);
221 EXPECT_TRUE(HasMoreRBSPData());
222 EXPECT_TRUE(ReadBits(15, &dummy));
223 EXPECT_EQ(dummy, 0x01);
224 EXPECT_FALSE(HasMoreRBSPData());
225 }
226
75 int main(int argc, char **argv) { 227 int main(int argc, char **argv) {
76 ::testing::InitGoogleTest(&argc, argv); 228 ::testing::InitGoogleTest(&argc, argv);
77 CommandLine::Init(argc, argv); 229 CommandLine::Init(argc, argv);
78 230
79 const CommandLine::SwitchMap& switches = 231 const CommandLine::SwitchMap& switches =
80 CommandLine::ForCurrentProcess()->GetSwitches(); 232 CommandLine::ForCurrentProcess()->GetSwitches();
81 for (CommandLine::SwitchMap::const_iterator it = switches.begin(); 233 for (CommandLine::SwitchMap::const_iterator it = switches.begin();
82 it != switches.end(); ++it) { 234 it != switches.end(); ++it) {
83 if (it->first == "test_stream") { 235 if (it->first == "test_stream") {
84 test_stream_filename = it->second.c_str(); 236 test_stream_filename = it->second.c_str();
85 } else if (it->first == "num_nalus") { 237 } else if (it->first == "num_nalus") {
86 CHECK(base::StringToInt(it->second, &num_nalus)); 238 CHECK(base::StringToInt(it->second, &num_nalus));
87 } else { 239 } else {
88 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; 240 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second;
89 } 241 }
90 } 242 }
91 243
92 return RUN_ALL_TESTS(); 244 return RUN_ALL_TESTS();
93 } 245 }
94
OLDNEW
« no previous file with comments | « content/common/gpu/media/h264_parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698