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/ebml_parser.h"
9
10 #include "gmock/gmock.h"
11 #include "gtest/gtest.h"
12
13 #include "test_utils/element_parser_test.h"
14 #include "webm/id.h"
15
16 using webm::Ebml;
17 using webm::EbmlParser;
18 using webm::ElementParserTest;
19 using webm::Id;
20
21 namespace {
22
23 class EbmlParserTest : public ElementParserTest<EbmlParser, Id::kEbml> {};
24
TEST_F(EbmlParserTest,DefaultParse)25 TEST_F(EbmlParserTest, DefaultParse) {
26 EXPECT_CALL(callback_, OnEbml(metadata_, Ebml{})).Times(1);
27
28 ParseAndVerify();
29 }
30
TEST_F(EbmlParserTest,DefaultValues)31 TEST_F(EbmlParserTest, DefaultValues) {
32 SetReaderData({
33 0x42, 0x86, // ID = 0x4286 (EBMLVersion).
34 0x80, // Size = 0.
35
36 0x42, 0xF7, // ID = 0x42F7 (EBMLReadVersion).
37 0x80, // Size = 0.
38
39 0x42, 0xF2, // ID = 0x42F2 (EBMLMaxIDLength).
40 0x40, 0x00, // Size = 0.
41
42 0x42, 0xF3, // ID = 0x42F3 (EBMLMaxSizeLength).
43 0x80, // Size = 0.
44
45 0xEC, // ID = 0xEC (Void).
46 0x40, 0x00, // Size = 0.
47
48 0x42, 0x82, // ID = 0x4282 (DocType).
49 0x40, 0x00, // Size = 0.
50
51 0x42, 0x87, // ID = 0x4287 (DocTypeVersion).
52 0x80, // Size = 0.
53
54 0x42, 0x85, // ID = 0x4285 (DocTypeReadVersion).
55 0x80, // Size = 0.
56
57 0xEC, // ID = 0xEC (Void).
58 0x82, // Size = 2.
59 0x01, 0x02, // Body.
60 });
61
62 Ebml ebml;
63 ebml.ebml_version.Set(1, true);
64 ebml.ebml_read_version.Set(1, true);
65 ebml.ebml_max_id_length.Set(4, true);
66 ebml.ebml_max_size_length.Set(8, true);
67 ebml.doc_type.Set("matroska", true);
68 ebml.doc_type_version.Set(1, true);
69 ebml.doc_type_read_version.Set(1, true);
70
71 EXPECT_CALL(callback_, OnEbml(metadata_, ebml)).Times(1);
72
73 ParseAndVerify();
74 }
75
TEST_F(EbmlParserTest,CustomValues)76 TEST_F(EbmlParserTest, CustomValues) {
77 SetReaderData({
78 0x42, 0x86, // ID = 0x4286 (EBMLVersion).
79 0x81, // Size = 1.
80 0x02, // Body (value = 2).
81
82 0x42, 0xF7, // ID = 0x42F7 (EBMLReadVersion).
83 0x81, // Size = 1.
84 0x04, // Body (value = 4).
85
86 0x42, 0xF2, // ID = 0x42F2 (EBMLMaxIDLength).
87 0x40, 0x02, // Size = 2.
88 0x00, 0x02, // Body (value = 2).
89
90 0x42, 0xF3, // ID = 0x42F3 (EBMLMaxSizeLength).
91 0x81, // Size = 1.
92 0x04, // Body (value = 4).
93
94 0xEC, // ID = 0xEC (Void).
95 0x40, 0x00, // Size = 0.
96
97 0x42, 0x82, // ID = 0x4282 (DocType).
98 0x40, 0x02, // Size = 2.
99 0x48, 0x69, // Body (value = "Hi").
100
101 0x42, 0x87, // ID = 0x4287 (DocTypeVersion).
102 0x81, // Size = 1.
103 0xFF, // Body (value = 255).
104
105 0x42, 0x85, // ID = 0x4285 (DocTypeReadVersion).
106 0x81, // Size = 1.
107 0x02, // Body (value = 2).
108
109 0xEC, // ID = 0xEC (Void).
110 0x82, // Size = 2.
111 0x01, 0x02, // Body.
112 });
113
114 Ebml ebml;
115 ebml.ebml_version.Set(2, true);
116 ebml.ebml_read_version.Set(4, true);
117 ebml.ebml_max_id_length.Set(2, true);
118 ebml.ebml_max_size_length.Set(4, true);
119 ebml.doc_type.Set("Hi", true);
120 ebml.doc_type_version.Set(255, true);
121 ebml.doc_type_read_version.Set(2, true);
122
123 EXPECT_CALL(callback_, OnEbml(metadata_, ebml)).Times(1);
124
125 ParseAndVerify();
126 }
127
128 } // namespace
129