xref: /aosp_15_r20/external/libwebm/webm_parser/tests/cue_point_parser_test.cc (revision 103e46e4cd4b6efcf6001f23fa8665fb110abf8d)
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_point_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::CuePoint;
17 using webm::CuePointParser;
18 using webm::CueTrackPositions;
19 using webm::ElementParserTest;
20 using webm::Id;
21 
22 namespace {
23 
24 class CuePointParserTest
25     : public ElementParserTest<CuePointParser, Id::kCuePoint> {};
26 
TEST_F(CuePointParserTest,DefaultParse)27 TEST_F(CuePointParserTest, DefaultParse) {
28   EXPECT_CALL(callback_, OnCuePoint(metadata_, CuePoint{})).Times(1);
29 
30   ParseAndVerify();
31 }
32 
TEST_F(CuePointParserTest,DefaultValues)33 TEST_F(CuePointParserTest, DefaultValues) {
34   SetReaderData({
35       0xB3,  // ID = 0xB3 (CueTime).
36       0x80,  // Size = 0.
37 
38       0xB7,  // ID = 0xB7 (CueTrackPositions).
39       0x80,  // Size = 0.
40   });
41 
42   CuePoint cue_point;
43   cue_point.time.Set(0, true);
44   cue_point.cue_track_positions.emplace_back();
45   cue_point.cue_track_positions[0].Set({}, true);
46 
47   EXPECT_CALL(callback_, OnCuePoint(metadata_, cue_point)).Times(1);
48 
49   ParseAndVerify();
50 }
51 
TEST_F(CuePointParserTest,CustomValues)52 TEST_F(CuePointParserTest, CustomValues) {
53   SetReaderData({
54       0xB3,  // ID = 0xB3 (CueTime).
55       0x81,  // Size = 1.
56       0x01,  // Body (value = 1).
57 
58       0xB7,  // ID = 0xB7 (CueTrackPositions).
59       0x83,  // Size = 3.
60 
61       0xF1,  //   ID = 0xF1 (CueClusterPosition).
62       0x81,  //   Size = 1.
63       0x02,  //   Body (value = 2).
64 
65       0xB7,  // ID = 0xB7 (CueTrackPositions).
66       0x83,  // Size = 3.
67 
68       0xF7,  //   ID = 0xF7 (CueTrack).
69       0x81,  //   Size = 1.
70       0x03,  //   Body (value = 3).
71   });
72 
73   CuePoint cue_point;
74   cue_point.time.Set(1, true);
75   CueTrackPositions cue_track_positions;
76   cue_track_positions.cluster_position.Set(2, true);
77   cue_point.cue_track_positions.emplace_back(cue_track_positions, true);
78   cue_track_positions = {};
79   cue_track_positions.track.Set(3, true);
80   cue_point.cue_track_positions.emplace_back(cue_track_positions, true);
81 
82   EXPECT_CALL(callback_, OnCuePoint(metadata_, cue_point)).Times(1);
83 
84   ParseAndVerify();
85 }
86 
87 }  // namespace
88