OLD | NEW |
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 Loading... |
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, |
63 MockWebMParserClient* client) { | 64 MockWebMParserClient* client) { |
64 | 65 |
65 InSequence s; | 66 InSequence s; |
66 EXPECT_CALL(*client, OnListStart(kWebMIdCluster)).WillOnce(Return(true)); | 67 EXPECT_CALL(*client, OnListStart(kWebMIdCluster)).WillOnce(Return(true)); |
67 EXPECT_CALL(*client, OnUInt(kWebMIdTimecode, 0)).WillOnce(Return(true)); | 68 EXPECT_CALL(*client, OnUInt(kWebMIdTimecode, timecode)) |
| 69 .WillOnce(Return(true)); |
68 | 70 |
69 for (int i = 0; i < block_count; i++) { | 71 for (int i = 0; i < block_count; i++) { |
70 EXPECT_CALL(*client, OnSimpleBlock(block_info[i].track_num, | 72 EXPECT_CALL(*client, OnSimpleBlock(block_info[i].track_num, |
71 block_info[i].timestamp, | 73 block_info[i].timestamp, |
72 _, _, _)) | 74 _, _, _)) |
73 .WillOnce(Return(true)); | 75 .WillOnce(Return(true)); |
74 } | 76 } |
75 | 77 |
76 EXPECT_CALL(*client, OnListEnd(kWebMIdCluster)).WillOnce(Return(true)); | 78 if (is_complete_cluster) |
| 79 EXPECT_CALL(*client, OnListEnd(kWebMIdCluster)).WillOnce(Return(true)); |
77 } | 80 } |
78 | 81 |
79 TEST_F(WebMParserTest, EmptyCluster) { | 82 TEST_F(WebMParserTest, EmptyCluster) { |
80 const uint8 kEmptyCluster[] = { | 83 const uint8 kEmptyCluster[] = { |
81 0x1F, 0x43, 0xB6, 0x75, 0x80 // CLUSTER (size = 0) | 84 0x1F, 0x43, 0xB6, 0x75, 0x80 // CLUSTER (size = 0) |
82 }; | 85 }; |
83 int size = sizeof(kEmptyCluster); | 86 int size = sizeof(kEmptyCluster); |
84 | 87 |
85 InSequence s; | 88 InSequence s; |
86 EXPECT_CALL(client_, OnListStart(kWebMIdCluster)).WillOnce(Return(true)); | 89 EXPECT_CALL(client_, OnListStart(kWebMIdCluster)).WillOnce(Return(true)); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 const SimpleBlockInfo kBlockInfo[] = { | 207 const SimpleBlockInfo kBlockInfo[] = { |
205 { 0, 1 }, | 208 { 0, 1 }, |
206 { 1, 2 }, | 209 { 1, 2 }, |
207 { 0, 3 }, | 210 { 0, 3 }, |
208 { 0, 4 }, | 211 { 0, 4 }, |
209 { 1, 4 }, | 212 { 1, 4 }, |
210 }; | 213 }; |
211 int block_count = arraysize(kBlockInfo); | 214 int block_count = arraysize(kBlockInfo); |
212 | 215 |
213 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 216 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
214 CreateClusterExpectations(0, kBlockInfo, block_count, &client_); | 217 CreateClusterExpectations(0, kBlockInfo, block_count, true, &client_); |
215 | 218 |
216 WebMListParser parser(kWebMIdCluster); | 219 WebMListParser parser(kWebMIdCluster); |
217 int result = parser.Parse(cluster->data(), cluster->size(), &client_); | 220 int result = parser.Parse(cluster->data(), cluster->size(), &client_); |
218 EXPECT_EQ(cluster->size(), result); | 221 EXPECT_EQ(cluster->size(), result); |
219 EXPECT_TRUE(parser.IsParsingComplete()); | 222 EXPECT_TRUE(parser.IsParsingComplete()); |
220 } | 223 } |
221 | 224 |
222 TEST_F(WebMParserTest, ParseListElementWithMultipleCalls) { | 225 TEST_F(WebMParserTest, ParseListElementWithMultipleCalls) { |
223 const SimpleBlockInfo kBlockInfo[] = { | 226 const SimpleBlockInfo kBlockInfo[] = { |
224 { 0, 1 }, | 227 { 0, 1 }, |
225 { 1, 2 }, | 228 { 1, 2 }, |
226 { 0, 3 }, | 229 { 0, 3 }, |
227 { 0, 4 }, | 230 { 0, 4 }, |
228 { 1, 4 }, | 231 { 1, 4 }, |
229 }; | 232 }; |
230 int block_count = arraysize(kBlockInfo); | 233 int block_count = arraysize(kBlockInfo); |
231 | 234 |
232 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 235 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
233 CreateClusterExpectations(0, kBlockInfo, block_count, &client_); | 236 CreateClusterExpectations(0, kBlockInfo, block_count, true, &client_); |
234 | 237 |
235 const uint8* data = cluster->data(); | 238 const uint8* data = cluster->data(); |
236 int size = cluster->size(); | 239 int size = cluster->size(); |
237 int default_parse_size = 3; | 240 int default_parse_size = 3; |
238 WebMListParser parser(kWebMIdCluster); | 241 WebMListParser parser(kWebMIdCluster); |
239 int parse_size = std::min(default_parse_size, size); | 242 int parse_size = std::min(default_parse_size, size); |
240 | 243 |
241 while (size > 0) { | 244 while (size > 0) { |
242 int result = parser.Parse(data, parse_size, &client_); | 245 int result = parser.Parse(data, parse_size, &client_); |
243 EXPECT_GE(result, 0); | 246 EXPECT_GE(result, 0); |
(...skipping 10 matching lines...) Expand all Loading... |
254 parse_size = default_parse_size; | 257 parse_size = default_parse_size; |
255 | 258 |
256 data += result; | 259 data += result; |
257 size -= result; | 260 size -= result; |
258 | 261 |
259 EXPECT_EQ((size == 0), parser.IsParsingComplete()); | 262 EXPECT_EQ((size == 0), parser.IsParsingComplete()); |
260 } | 263 } |
261 EXPECT_TRUE(parser.IsParsingComplete()); | 264 EXPECT_TRUE(parser.IsParsingComplete()); |
262 } | 265 } |
263 | 266 |
| 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 |
264 } // namespace media | 304 } // namespace media |
OLD | NEW |