summaryrefslogtreecommitdiffstats
path: root/media/webm/webm_parser_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'media/webm/webm_parser_unittest.cc')
-rw-r--r--media/webm/webm_parser_unittest.cc48
1 files changed, 44 insertions, 4 deletions
diff --git a/media/webm/webm_parser_unittest.cc b/media/webm/webm_parser_unittest.cc
index e377fda..3c8600b 100644
--- a/media/webm/webm_parser_unittest.cc
+++ b/media/webm/webm_parser_unittest.cc
@@ -60,11 +60,13 @@ static Cluster* CreateCluster(int timecode,
static void CreateClusterExpectations(int timecode,
const SimpleBlockInfo* block_info,
int block_count,
+ bool is_complete_cluster,
MockWebMParserClient* client) {
InSequence s;
EXPECT_CALL(*client, OnListStart(kWebMIdCluster)).WillOnce(Return(true));
- EXPECT_CALL(*client, OnUInt(kWebMIdTimecode, 0)).WillOnce(Return(true));
+ EXPECT_CALL(*client, OnUInt(kWebMIdTimecode, timecode))
+ .WillOnce(Return(true));
for (int i = 0; i < block_count; i++) {
EXPECT_CALL(*client, OnSimpleBlock(block_info[i].track_num,
@@ -73,7 +75,8 @@ static void CreateClusterExpectations(int timecode,
.WillOnce(Return(true));
}
- EXPECT_CALL(*client, OnListEnd(kWebMIdCluster)).WillOnce(Return(true));
+ if (is_complete_cluster)
+ EXPECT_CALL(*client, OnListEnd(kWebMIdCluster)).WillOnce(Return(true));
}
TEST_F(WebMParserTest, EmptyCluster) {
@@ -211,7 +214,7 @@ TEST_F(WebMParserTest, ParseListElementWithSingleCall) {
int block_count = arraysize(kBlockInfo);
scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
- CreateClusterExpectations(0, kBlockInfo, block_count, &client_);
+ CreateClusterExpectations(0, kBlockInfo, block_count, true, &client_);
WebMListParser parser(kWebMIdCluster);
int result = parser.Parse(cluster->data(), cluster->size(), &client_);
@@ -230,7 +233,7 @@ TEST_F(WebMParserTest, ParseListElementWithMultipleCalls) {
int block_count = arraysize(kBlockInfo);
scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
- CreateClusterExpectations(0, kBlockInfo, block_count, &client_);
+ CreateClusterExpectations(0, kBlockInfo, block_count, true, &client_);
const uint8* data = cluster->data();
int size = cluster->size();
@@ -261,4 +264,41 @@ TEST_F(WebMParserTest, ParseListElementWithMultipleCalls) {
EXPECT_TRUE(parser.IsParsingComplete());
}
+TEST_F(WebMParserTest, TestReset) {
+ InSequence s;
+
+ const SimpleBlockInfo kBlockInfo[] = {
+ { 0, 1 },
+ { 1, 2 },
+ { 0, 3 },
+ { 0, 4 },
+ { 1, 4 },
+ };
+ int block_count = arraysize(kBlockInfo);
+
+ scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
+
+ // First expect all but the last block.
+ CreateClusterExpectations(0, kBlockInfo, block_count - 1, false, &client_);
+
+ // Now expect all blocks.
+ CreateClusterExpectations(0, kBlockInfo, block_count, true, &client_);
+
+ WebMListParser parser(kWebMIdCluster);
+
+ // Send slightly less than the full cluster so all but the last block is
+ // parsed.
+ int result = parser.Parse(cluster->data(), cluster->size() - 1, &client_);
+ EXPECT_GT(result, 0);
+ EXPECT_LT(result, cluster->size());
+ EXPECT_FALSE(parser.IsParsingComplete());
+
+ parser.Reset();
+
+ // Now parse a whole cluster to verify that all the blocks will get parsed.
+ result = parser.Parse(cluster->data(), cluster->size(), &client_);
+ EXPECT_EQ(result, cluster->size());
+ EXPECT_TRUE(parser.IsParsingComplete());
+}
+
} // namespace media