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

Side by Side Diff: media/webm/webm_parser_unittest.cc

Issue 8989041: Revert 115214 (caused media_unittests failure in FFmpegGlueTest, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « media/webm/webm_cluster_parser.cc ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/webm/cluster_builder.h" 5 #include "media/webm/cluster_builder.h"
6 #include "media/webm/webm_constants.h" 6 #include "media/webm/webm_constants.h"
7 #include "media/webm/webm_parser.h" 7 #include "media/webm/webm_parser.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 for (int i = 0; i < block_count; i++) 54 for (int i = 0; i < block_count; i++)
55 AddSimpleBlock(&cb, block_info[i].track_num, block_info[i].timestamp); 55 AddSimpleBlock(&cb, block_info[i].track_num, block_info[i].timestamp);
56 56
57 return cb.Finish(); 57 return cb.Finish();
58 } 58 }
59 59
60 static void CreateClusterExpectations(int timecode, 60 static void CreateClusterExpectations(int timecode,
61 const SimpleBlockInfo* block_info, 61 const SimpleBlockInfo* block_info,
62 int block_count, 62 int block_count,
63 bool is_complete_cluster,
64 MockWebMParserClient* client) { 63 MockWebMParserClient* client) {
65 64
66 InSequence s; 65 InSequence s;
67 EXPECT_CALL(*client, OnListStart(kWebMIdCluster)).WillOnce(Return(true)); 66 EXPECT_CALL(*client, OnListStart(kWebMIdCluster)).WillOnce(Return(true));
68 EXPECT_CALL(*client, OnUInt(kWebMIdTimecode, timecode)) 67 EXPECT_CALL(*client, OnUInt(kWebMIdTimecode, 0)).WillOnce(Return(true));
69 .WillOnce(Return(true));
70 68
71 for (int i = 0; i < block_count; i++) { 69 for (int i = 0; i < block_count; i++) {
72 EXPECT_CALL(*client, OnSimpleBlock(block_info[i].track_num, 70 EXPECT_CALL(*client, OnSimpleBlock(block_info[i].track_num,
73 block_info[i].timestamp, 71 block_info[i].timestamp,
74 _, _, _)) 72 _, _, _))
75 .WillOnce(Return(true)); 73 .WillOnce(Return(true));
76 } 74 }
77 75
78 if (is_complete_cluster) 76 EXPECT_CALL(*client, OnListEnd(kWebMIdCluster)).WillOnce(Return(true));
79 EXPECT_CALL(*client, OnListEnd(kWebMIdCluster)).WillOnce(Return(true));
80 } 77 }
81 78
82 TEST_F(WebMParserTest, EmptyCluster) { 79 TEST_F(WebMParserTest, EmptyCluster) {
83 const uint8 kEmptyCluster[] = { 80 const uint8 kEmptyCluster[] = {
84 0x1F, 0x43, 0xB6, 0x75, 0x80 // CLUSTER (size = 0) 81 0x1F, 0x43, 0xB6, 0x75, 0x80 // CLUSTER (size = 0)
85 }; 82 };
86 int size = sizeof(kEmptyCluster); 83 int size = sizeof(kEmptyCluster);
87 84
88 InSequence s; 85 InSequence s;
89 EXPECT_CALL(client_, OnListStart(kWebMIdCluster)).WillOnce(Return(true)); 86 EXPECT_CALL(client_, OnListStart(kWebMIdCluster)).WillOnce(Return(true));
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 const SimpleBlockInfo kBlockInfo[] = { 204 const SimpleBlockInfo kBlockInfo[] = {
208 { 0, 1 }, 205 { 0, 1 },
209 { 1, 2 }, 206 { 1, 2 },
210 { 0, 3 }, 207 { 0, 3 },
211 { 0, 4 }, 208 { 0, 4 },
212 { 1, 4 }, 209 { 1, 4 },
213 }; 210 };
214 int block_count = arraysize(kBlockInfo); 211 int block_count = arraysize(kBlockInfo);
215 212
216 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); 213 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
217 CreateClusterExpectations(0, kBlockInfo, block_count, true, &client_); 214 CreateClusterExpectations(0, kBlockInfo, block_count, &client_);
218 215
219 WebMListParser parser(kWebMIdCluster); 216 WebMListParser parser(kWebMIdCluster);
220 int result = parser.Parse(cluster->data(), cluster->size(), &client_); 217 int result = parser.Parse(cluster->data(), cluster->size(), &client_);
221 EXPECT_EQ(cluster->size(), result); 218 EXPECT_EQ(cluster->size(), result);
222 EXPECT_TRUE(parser.IsParsingComplete()); 219 EXPECT_TRUE(parser.IsParsingComplete());
223 } 220 }
224 221
225 TEST_F(WebMParserTest, ParseListElementWithMultipleCalls) { 222 TEST_F(WebMParserTest, ParseListElementWithMultipleCalls) {
226 const SimpleBlockInfo kBlockInfo[] = { 223 const SimpleBlockInfo kBlockInfo[] = {
227 { 0, 1 }, 224 { 0, 1 },
228 { 1, 2 }, 225 { 1, 2 },
229 { 0, 3 }, 226 { 0, 3 },
230 { 0, 4 }, 227 { 0, 4 },
231 { 1, 4 }, 228 { 1, 4 },
232 }; 229 };
233 int block_count = arraysize(kBlockInfo); 230 int block_count = arraysize(kBlockInfo);
234 231
235 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); 232 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
236 CreateClusterExpectations(0, kBlockInfo, block_count, true, &client_); 233 CreateClusterExpectations(0, kBlockInfo, block_count, &client_);
237 234
238 const uint8* data = cluster->data(); 235 const uint8* data = cluster->data();
239 int size = cluster->size(); 236 int size = cluster->size();
240 int default_parse_size = 3; 237 int default_parse_size = 3;
241 WebMListParser parser(kWebMIdCluster); 238 WebMListParser parser(kWebMIdCluster);
242 int parse_size = std::min(default_parse_size, size); 239 int parse_size = std::min(default_parse_size, size);
243 240
244 while (size > 0) { 241 while (size > 0) {
245 int result = parser.Parse(data, parse_size, &client_); 242 int result = parser.Parse(data, parse_size, &client_);
246 EXPECT_GE(result, 0); 243 EXPECT_GE(result, 0);
(...skipping 10 matching lines...) Expand all
257 parse_size = default_parse_size; 254 parse_size = default_parse_size;
258 255
259 data += result; 256 data += result;
260 size -= result; 257 size -= result;
261 258
262 EXPECT_EQ((size == 0), parser.IsParsingComplete()); 259 EXPECT_EQ((size == 0), parser.IsParsingComplete());
263 } 260 }
264 EXPECT_TRUE(parser.IsParsingComplete()); 261 EXPECT_TRUE(parser.IsParsingComplete());
265 } 262 }
266 263
267 TEST_F(WebMParserTest, TestReset) {
268 InSequence s;
269
270 const SimpleBlockInfo kBlockInfo[] = {
271 { 0, 1 },
272 { 1, 2 },
273 { 0, 3 },
274 { 0, 4 },
275 { 1, 4 },
276 };
277 int block_count = arraysize(kBlockInfo);
278
279 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
280
281 // First expect all but the last block.
282 CreateClusterExpectations(0, kBlockInfo, block_count - 1, false, &client_);
283
284 // Now expect all blocks.
285 CreateClusterExpectations(0, kBlockInfo, block_count, true, &client_);
286
287 WebMListParser parser(kWebMIdCluster);
288
289 // Send slightly less than the full cluster so all but the last block is
290 // parsed.
291 int result = parser.Parse(cluster->data(), cluster->size() - 1, &client_);
292 EXPECT_GT(result, 0);
293 EXPECT_LT(result, cluster->size());
294 EXPECT_FALSE(parser.IsParsingComplete());
295
296 parser.Reset();
297
298 // Now parse a whole cluster to verify that all the blocks will get parsed.
299 result = parser.Parse(cluster->data(), cluster->size(), &client_);
300 EXPECT_EQ(result, cluster->size());
301 EXPECT_TRUE(parser.IsParsingComplete());
302 }
303
304 } // namespace media 264 } // namespace media
OLDNEW
« no previous file with comments | « media/webm/webm_cluster_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698