1+ /*
2+ * If not stated otherwise in this file or this component's license file the
3+ * following copyright and licenses apply:
4+ *
5+ * Copyright 2025 RDK Management
6+ *
7+ * Licensed under the Apache License, Version 2.0 (the "License");
8+ * you may not use this file except in compliance with the License.
9+ * You may obtain a copy of the License at
10+ *
11+ * http://www.apache.org/licenses/LICENSE-2.0
12+ *
13+ * Unless required by applicable law or agreed to in writing, software
14+ * distributed under the License is distributed on an "AS IS" BASIS,
15+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+ * See the License for the specific language governing permissions and
17+ * limitations under the License.
18+ */
19+
20+ /* *
21+ * @file MockAampMp4Demuxer.h
22+ * @brief Mock implementation of AampMp4Demuxer for testing
23+ */
24+
25+ #ifndef __MOCK_AAMP_MP4_DEMUXER_H__
26+ #define __MOCK_AAMP_MP4_DEMUXER_H__
27+
28+ #include < gmock/gmock.h>
29+ #include " mediaprocessor.h"
30+ #include " AampMediaType.h"
31+ #include " AampGrowableBuffer.h"
32+
33+ /* *
34+ * @class MockAampMp4Demuxer
35+ * @brief Mock implementation of AampMp4Demuxer using Google Mock
36+ */
37+ class MockAampMp4Demuxer : public MediaProcessor
38+ {
39+ public:
40+ MockAampMp4Demuxer () = default ;
41+ virtual ~MockAampMp4Demuxer () = default ;
42+
43+ // Prevent copy construction and assignment
44+ MockAampMp4Demuxer (const MockAampMp4Demuxer&) = delete ;
45+ MockAampMp4Demuxer& operator =(const MockAampMp4Demuxer&) = delete ;
46+
47+ // Mock all pure virtual methods from MediaProcessor
48+ MOCK_METHOD (double , getFirstPts, (AampGrowableBuffer* pBuffer), (override ));
49+ MOCK_METHOD (void , setPtsOffset, (double ptsOffset), (override ));
50+ MOCK_METHOD (bool , sendSegment, (AampGrowableBuffer* pBuffer, double position, double duration,
51+ double fragmentPTSoffset, bool discontinuous, bool isInit,
52+ process_fcn_t processor, bool & ptsError), (override ));
53+ MOCK_METHOD (void , setRate, (double rate, PlayMode mode), (override ));
54+ MOCK_METHOD (void , setThrottleEnable, (bool enable), (override ));
55+ MOCK_METHOD (void , setFrameRateForTM, (int frameRate), (override ));
56+ MOCK_METHOD (void , abort, (), (override ));
57+ MOCK_METHOD (void , reset, (), (override ));
58+ MOCK_METHOD (void , abortInjectionWait, (), (override ));
59+ MOCK_METHOD (void , enable, (bool enable), (override ));
60+ MOCK_METHOD (void , setTrackOffset, (double offset), (override ));
61+
62+ // Mock virtual methods that have default implementations
63+ MOCK_METHOD (void , resetPTSOnSubtitleSwitch, (AampGrowableBuffer* pBuffer, double position), (override ));
64+ MOCK_METHOD (void , resetPTSOnAudioSwitch, (AampGrowableBuffer* pBuffer, double position), (override ));
65+ MOCK_METHOD (void , ChangeMuxedAudioTrack, (unsigned char index), (override ));
66+ MOCK_METHOD (void , SetAudioGroupId, (std::string& id), (override ));
67+ MOCK_METHOD (void , setApplyOffsetFlag, (bool enable), (override ));
68+ MOCK_METHOD (void , updateSkipPoint, (double skipPoint, double skipDuration), (override ));
69+ MOCK_METHOD (void , setDiscontinuityState, (bool isDiscontinuity), (override ));
70+ MOCK_METHOD (void , abortWaitForVideoPTS, (), (override ));
71+
72+ // Helper methods for test setup
73+ void SetupDefaultBehavior () {
74+ // Set up default return values
75+ ON_CALL (*this , getFirstPts (::testing::_))
76+ .WillByDefault (::testing::Return (0.0 ));
77+
78+ ON_CALL (*this , sendSegment (::testing::_, ::testing::_, ::testing::_,
79+ ::testing::_, ::testing::_, ::testing::_,
80+ ::testing::_, ::testing::_))
81+ .WillByDefault (::testing::DoAll (
82+ ::testing::SetArgReferee<7 >(false ), // Set ptsError to false
83+ ::testing::Return (true )
84+ ));
85+
86+ // Set up void methods to do nothing by default
87+ ON_CALL (*this , setPtsOffset (::testing::_))
88+ .WillByDefault (::testing::Return ());
89+
90+ ON_CALL (*this , setRate (::testing::_, ::testing::_))
91+ .WillByDefault (::testing::Return ());
92+
93+ ON_CALL (*this , setThrottleEnable (::testing::_))
94+ .WillByDefault (::testing::Return ());
95+
96+ ON_CALL (*this , setFrameRateForTM (::testing::_))
97+ .WillByDefault (::testing::Return ());
98+
99+ ON_CALL (*this , abort ())
100+ .WillByDefault (::testing::Return ());
101+
102+ ON_CALL (*this , reset ())
103+ .WillByDefault (::testing::Return ());
104+
105+ ON_CALL (*this , abortInjectionWait ())
106+ .WillByDefault (::testing::Return ());
107+
108+ ON_CALL (*this , enable (::testing::_))
109+ .WillByDefault (::testing::Return ());
110+
111+ ON_CALL (*this , setTrackOffset (::testing::_))
112+ .WillByDefault (::testing::Return ());
113+ }
114+
115+ // Test utilities for creating mock buffers
116+ static AampGrowableBuffer* CreateMockBuffer (const std::string& data) {
117+ AampGrowableBuffer* buffer = new AampGrowableBuffer (" MockBuffer" );
118+ buffer->AppendBytes (data.c_str (), data.length ());
119+ return buffer;
120+ }
121+
122+ static AampGrowableBuffer* CreateMockMp4Buffer () {
123+ // Create a minimal MP4 buffer with ftyp box
124+ const uint8_t mp4Data[] = {
125+ 0x00 , 0x00 , 0x00 , 0x20 , // size = 32
126+ 0x66 , 0x74 , 0x79 , 0x70 , // 'ftyp'
127+ 0x69 , 0x73 , 0x6f , 0x6d , // major_brand = 'isom'
128+ 0x00 , 0x00 , 0x02 , 0x00 , // minor_version = 512
129+ 0x69 , 0x73 , 0x6f , 0x6d , // compatible_brands[0] = 'isom'
130+ 0x69 , 0x73 , 0x6f , 0x32 , // compatible_brands[1] = 'iso2'
131+ 0x61 , 0x76 , 0x63 , 0x31 , // compatible_brands[2] = 'avc1'
132+ 0x6d , 0x70 , 0x34 , 0x31 // compatible_brands[3] = 'mp41'
133+ };
134+
135+ AampGrowableBuffer* buffer = new AampGrowableBuffer (" MockMp4Buffer" );
136+ buffer->AppendBytes ((const char *)mp4Data, sizeof (mp4Data));
137+ return buffer;
138+ }
139+
140+ static AampGrowableBuffer* CreateMockInitSegment () {
141+ return CreateMockMp4Buffer ();
142+ }
143+
144+ static AampGrowableBuffer* CreateMockDataSegment () {
145+ // Create a minimal MP4 fragment with moof and mdat
146+ const uint8_t fragmentData[] = {
147+ // moof box header
148+ 0x00 , 0x00 , 0x00 , 0x10 , // size = 16
149+ 0x6d , 0x6f , 0x6f , 0x66 , // 'moof'
150+ // mfhd box
151+ 0x00 , 0x00 , 0x00 , 0x08 , // size = 8
152+ 0x6d , 0x66 , 0x68 , 0x64 , // 'mfhd'
153+ // mdat box header
154+ 0x00 , 0x00 , 0x00 , 0x08 , // size = 8
155+ 0x6d , 0x64 , 0x61 , 0x74 // 'mdat'
156+ };
157+
158+ AampGrowableBuffer* buffer = new AampGrowableBuffer (" MockFragmentBuffer" );
159+ buffer->AppendBytes ((const char *)fragmentData, sizeof (fragmentData));
160+ return buffer;
161+ }
162+ };
163+
164+ #endif /* __MOCK_AAMP_MP4_DEMUXER_H__ */
0 commit comments