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/virtual_block_parser.h"
9
10 #include "gtest/gtest.h"
11
12 #include "test_utils/element_parser_test.h"
13 #include "webm/id.h"
14 #include "webm/status.h"
15
16 using webm::ElementParserTest;
17 using webm::Id;
18 using webm::kUnknownElementSize;
19 using webm::Status;
20 using webm::VirtualBlock;
21 using webm::VirtualBlockParser;
22
23 namespace {
24
25 class VirtualBlockParserTest
26 : public ElementParserTest<VirtualBlockParser, Id::kBlockVirtual> {};
27
TEST_F(VirtualBlockParserTest,InvalidSize)28 TEST_F(VirtualBlockParserTest, InvalidSize) {
29 TestInit(3, Status::kInvalidElementSize);
30 TestInit(kUnknownElementSize, Status::kInvalidElementSize);
31 }
32
TEST_F(VirtualBlockParserTest,InvalidBlock)33 TEST_F(VirtualBlockParserTest, InvalidBlock) {
34 SetReaderData({
35 0x40, 0x01, // Track number = 1.
36 0x00, 0x00, // Timecode = 0.
37 0x00, // Flags.
38 });
39
40 // Initialize with 1 byte short.
41 ParseAndExpectResult(Status::kInvalidElementValue, reader_.size() - 1);
42 }
43
TEST_F(VirtualBlockParserTest,ValidBlock)44 TEST_F(VirtualBlockParserTest, ValidBlock) {
45 SetReaderData({
46 0x81, // Track number = 1.
47 0x12, 0x34, // Timecode = 4660.
48 0x00, // Flags.
49 });
50
51 ParseAndVerify();
52
53 const VirtualBlock virtual_block = parser_.value();
54
55 EXPECT_EQ(static_cast<std::uint64_t>(1), virtual_block.track_number);
56 EXPECT_EQ(0x1234, virtual_block.timecode);
57 }
58
TEST_F(VirtualBlockParserTest,IncrementalParse)59 TEST_F(VirtualBlockParserTest, IncrementalParse) {
60 SetReaderData({
61 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, // Track number = 2.
62 0xFF, 0xFE, // Timecode = -2.
63 0x00, // Flags.
64 });
65
66 IncrementalParseAndVerify();
67
68 const VirtualBlock virtual_block = parser_.value();
69
70 EXPECT_EQ(static_cast<std::uint64_t>(2), virtual_block.track_number);
71 EXPECT_EQ(-2, virtual_block.timecode);
72 }
73
74 } // namespace
75