1 // Copyright (c) 2016 The WebM project authors. All Rights Reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS.  All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 #include "src/block_header_parser.h"
9 
10 #include "gtest/gtest.h"
11 
12 #include "test_utils/parser_test.h"
13 #include "webm/status.h"
14 
15 using webm::BlockHeader;
16 using webm::BlockHeaderParser;
17 using webm::ParserTest;
18 
19 namespace {
20 
21 class BlockHeaderParserTest : public ParserTest<BlockHeaderParser> {};
22 
TEST_F(BlockHeaderParserTest,ValidBlock)23 TEST_F(BlockHeaderParserTest, ValidBlock) {
24   SetReaderData({
25       0x81,  // Track number = 1.
26       0x12, 0x34,  // Timecode = 4660.
27       0x00,  // Flags.
28   });
29 
30   ParseAndVerify();
31 
32   const BlockHeader& block_header = parser_.value();
33 
34   EXPECT_EQ(static_cast<std::uint64_t>(1), block_header.track_number);
35   EXPECT_EQ(0x1234, block_header.timecode);
36   EXPECT_EQ(0x00, block_header.flags);
37 }
38 
TEST_F(BlockHeaderParserTest,IncrementalParse)39 TEST_F(BlockHeaderParserTest, IncrementalParse) {
40   SetReaderData({
41       0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,  // Track number = 2.
42       0xFF, 0xFE,  // Timecode = -2.
43       0xFF,  // Flags.
44   });
45 
46   IncrementalParseAndVerify();
47 
48   const BlockHeader& block_header = parser_.value();
49 
50   EXPECT_EQ(static_cast<std::uint64_t>(2), block_header.track_number);
51   EXPECT_EQ(-2, block_header.timecode);
52   EXPECT_EQ(0xFF, block_header.flags);
53 }
54 
55 }  // namespace
56