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/info_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::ElementParserTest;
17 using webm::Id;
18 using webm::Info;
19 using webm::InfoParser;
20
21 namespace {
22
23 class InfoParserTest : public ElementParserTest<InfoParser, Id::kInfo> {};
24
TEST_F(InfoParserTest,DefaultParse)25 TEST_F(InfoParserTest, DefaultParse) {
26 EXPECT_CALL(callback_, OnInfo(metadata_, Info{})).Times(1);
27
28 ParseAndVerify();
29 }
30
TEST_F(InfoParserTest,DefaultValues)31 TEST_F(InfoParserTest, DefaultValues) {
32 SetReaderData({
33 0x2A, 0xD7, 0xB1, // ID = 0x2AD7B1 (TimecodeScale).
34 0x80, // Size = 0.
35
36 0x44, 0x89, // ID = 0x4489 (Duration).
37 0x20, 0x00, 0x00, // Size = 0.
38
39 0x44, 0x61, // ID = 0x4461 (DateUTC).
40 0x20, 0x00, 0x00, // Size = 0.
41
42 0x7B, 0xA9, // ID = 0x7BA9 (Title).
43 0x20, 0x00, 0x00, // Size = 0.
44
45 0x4D, 0x80, // ID = 0x4D80 (MuxingApp).
46 0x20, 0x00, 0x00, // Size = 0.
47
48 0x57, 0x41, // ID = 0x5741 (WritingApp).
49 0x20, 0x00, 0x00, // Size = 0.
50 });
51
52 Info info;
53 info.timecode_scale.Set(1000000, true);
54 info.duration.Set(0, true);
55 info.date_utc.Set(0, true);
56 info.title.Set("", true);
57 info.muxing_app.Set("", true);
58 info.writing_app.Set("", true);
59
60 EXPECT_CALL(callback_, OnInfo(metadata_, info)).Times(1);
61
62 ParseAndVerify();
63 }
64
TEST_F(InfoParserTest,CustomValues)65 TEST_F(InfoParserTest, CustomValues) {
66 SetReaderData({
67 0x2A, 0xD7, 0xB1, // ID = 0x2AD7B1 (TimecodeScale).
68 0x10, 0x00, 0x00, 0x01, // Size = 1.
69 0x01, // Body (value = 1).
70
71 0x44, 0x89, // ID = 0x4489 (Duration).
72 0x84, // Size = 4.
73 0x4D, 0x8E, 0xF3, 0xC2, // Body (value = 299792448.0f).
74
75 0x44, 0x61, // ID = 0x4461 (DateUTC).
76 0x88, // Size = 8.
77 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Body (value = -1).
78
79 0x7B, 0xA9, // ID = 0x7BA9 (Title).
80 0x10, 0x00, 0x00, 0x03, // Size = 3.
81 0x66, 0x6F, 0x6F, // Body (value = "foo").
82
83 0x4D, 0x80, // ID = 0x4D80 (MuxingApp).
84 0x10, 0x00, 0x00, 0x03, // Size = 3.
85 0x62, 0x61, 0x72, // Body (value = "bar").
86
87 0x57, 0x41, // ID = 0x5741 (WritingApp).
88 0x10, 0x00, 0x00, 0x03, // Size = 3.
89 0x62, 0x61, 0x7A, // Body (value = "baz").
90 });
91
92 Info info;
93 info.timecode_scale.Set(1, true);
94 info.duration.Set(299792448.0f, true);
95 info.date_utc.Set(-1, true);
96 info.title.Set("foo", true);
97 info.muxing_app.Set("bar", true);
98 info.writing_app.Set("baz", true);
99
100 EXPECT_CALL(callback_, OnInfo(metadata_, info)).Times(1);
101
102 ParseAndVerify();
103 }
104
105 } // namespace
106