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/cue_track_positions_parser.h"
9 
10 #include "gtest/gtest.h"
11 
12 #include "test_utils/element_parser_test.h"
13 #include "webm/id.h"
14 
15 using webm::CueTrackPositions;
16 using webm::CueTrackPositionsParser;
17 using webm::ElementParserTest;
18 using webm::Id;
19 
20 namespace {
21 
22 class CueTrackPositionsParserTest
23     : public ElementParserTest<CueTrackPositionsParser,
24                                Id::kCueTrackPositions> {};
25 
TEST_F(CueTrackPositionsParserTest,DefaultParse)26 TEST_F(CueTrackPositionsParserTest, DefaultParse) {
27   ParseAndVerify();
28 
29   const CueTrackPositions cue_track_positions = parser_.value();
30 
31   EXPECT_FALSE(cue_track_positions.track.is_present());
32   EXPECT_EQ(static_cast<std::uint64_t>(0), cue_track_positions.track.value());
33 
34   EXPECT_FALSE(cue_track_positions.cluster_position.is_present());
35   EXPECT_EQ(static_cast<std::uint64_t>(0),
36             cue_track_positions.cluster_position.value());
37 
38   EXPECT_FALSE(cue_track_positions.relative_position.is_present());
39   EXPECT_EQ(static_cast<std::uint64_t>(0),
40             cue_track_positions.relative_position.value());
41 
42   EXPECT_FALSE(cue_track_positions.duration.is_present());
43   EXPECT_EQ(static_cast<std::uint64_t>(0),
44             cue_track_positions.duration.value());
45 
46   EXPECT_FALSE(cue_track_positions.block_number.is_present());
47   EXPECT_EQ(static_cast<std::uint64_t>(1),
48             cue_track_positions.block_number.value());
49 }
50 
TEST_F(CueTrackPositionsParserTest,DefaultValues)51 TEST_F(CueTrackPositionsParserTest, DefaultValues) {
52   SetReaderData({
53       0xF7,  // ID = 0xF7 (CueTrack).
54       0x40, 0x00,  // Size = 0.
55 
56       0xF1,  // ID = 0xF1 (CueClusterPosition).
57       0x40, 0x00,  // Size = 0.
58 
59       0xF0,  // ID = 0xF0 (CueRelativePosition).
60       0x40, 0x00,  // Size = 0.
61 
62       0xB2,  // ID = 0xB2 (CueDuration).
63       0x40, 0x00,  // Size = 0.
64 
65       0x53, 0x78,  // ID = 0x5378 (CueBlockNumber).
66       0x80,  // Size = 0.
67   });
68 
69   ParseAndVerify();
70 
71   const CueTrackPositions cue_track_positions = parser_.value();
72 
73   EXPECT_TRUE(cue_track_positions.track.is_present());
74   EXPECT_EQ(static_cast<std::uint64_t>(0), cue_track_positions.track.value());
75 
76   EXPECT_TRUE(cue_track_positions.cluster_position.is_present());
77   EXPECT_EQ(static_cast<std::uint64_t>(0),
78             cue_track_positions.cluster_position.value());
79 
80   EXPECT_TRUE(cue_track_positions.relative_position.is_present());
81   EXPECT_EQ(static_cast<std::uint64_t>(0),
82             cue_track_positions.relative_position.value());
83 
84   EXPECT_TRUE(cue_track_positions.duration.is_present());
85   EXPECT_EQ(static_cast<std::uint64_t>(0),
86             cue_track_positions.duration.value());
87 
88   EXPECT_TRUE(cue_track_positions.block_number.is_present());
89   EXPECT_EQ(static_cast<std::uint64_t>(1),
90             cue_track_positions.block_number.value());
91 }
92 
TEST_F(CueTrackPositionsParserTest,CustomValues)93 TEST_F(CueTrackPositionsParserTest, CustomValues) {
94   SetReaderData({
95       0xF7,  // ID = 0xF7 (CueTrack).
96       0x40, 0x01,  // Size = 1.
97       0x01,  // Body (value = 1).
98 
99       0xF1,  // ID = 0xF1 (CueClusterPosition).
100       0x40, 0x01,  // Size = 1.
101       0x02,  // Body (value = 2).
102 
103       0xF0,  // ID = 0xF0 (CueRelativePosition).
104       0x40, 0x01,  // Size = 1.
105       0x03,  // Body (value = 3).
106 
107       0xB2,  // ID = 0xB2 (CueDuration).
108       0x40, 0x01,  // Size = 1.
109       0x04,  // Body (value = 4).
110 
111       0x53, 0x78,  // ID = 0x5378 (CueBlockNumber).
112       0x81,  // Size = 1.
113       0x05,  // Body (value = 5).
114   });
115 
116   ParseAndVerify();
117 
118   const CueTrackPositions cue_track_positions = parser_.value();
119 
120   EXPECT_TRUE(cue_track_positions.track.is_present());
121   EXPECT_EQ(static_cast<std::uint64_t>(1), cue_track_positions.track.value());
122 
123   EXPECT_TRUE(cue_track_positions.cluster_position.is_present());
124   EXPECT_EQ(static_cast<std::uint64_t>(2),
125             cue_track_positions.cluster_position.value());
126 
127   EXPECT_TRUE(cue_track_positions.relative_position.is_present());
128   EXPECT_EQ(static_cast<std::uint64_t>(3),
129             cue_track_positions.relative_position.value());
130 
131   EXPECT_TRUE(cue_track_positions.duration.is_present());
132   EXPECT_EQ(static_cast<std::uint64_t>(4),
133             cue_track_positions.duration.value());
134 
135   EXPECT_TRUE(cue_track_positions.block_number.is_present());
136   EXPECT_EQ(static_cast<std::uint64_t>(5),
137             cue_track_positions.block_number.value());
138 }
139 
140 }  // namespace
141