• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef STREAM_DEMUXER_UNITTEST_H
17 #define STREAM_DEMUXER_UNITTEST_H
18 
19 #include "mock/mock_plugin_buffer_memory.h"
20 #include "mock/source.h"
21 #include "gtest/gtest.h"
22 #include "stream_demuxer.h"
23 
24 namespace OHOS {
25 namespace Media {
26 class StreamDemuxerUnitTest : public testing::Test {
27 public:
28     static void SetUpTestCase(void);
29     static void TearDownTestCase(void);
30     void SetUp(void);
31     void TearDown(void);
32 protected:
33     std::shared_ptr<StreamDemuxer> streamDemuxer_ = nullptr;
34 };
35 class MockSource : public Source {
36 public:
37     MockSource() = default;
38     ~MockSource() override = default;
39 
40     MOCK_METHOD(void, OnEvent, (const Plugins::PluginEvent &event), (override));
41     MOCK_METHOD(void, OnDfxEvent, (const Plugins::PluginDfxEvent &event), (override));
42     MOCK_METHOD(void, SetSelectBitRateFlag, (bool flag, uint32_t desBitRate), (override));
43     MOCK_METHOD(bool, CanAutoSelectBitRate, (), (override));
44 
45     MOCK_METHOD(Status, SetSource, (const std::shared_ptr<MediaSource> &source), (override));
46     MOCK_METHOD(void, SetBundleName, (const std::string &bundleName), (override));
47     MOCK_METHOD(Status, Prepare, (), (override));
48     MOCK_METHOD(Status, Start, (), (override));
49     MOCK_METHOD(Status, Stop, (), (override));
50     MOCK_METHOD(Status, Pause, (), (override));
51     MOCK_METHOD(Status, Resume, (), (override));
52     MOCK_METHOD(Status, SetReadBlockingFlag, (bool isReadBlockingAllowed), (override));
53     MOCK_METHOD(Plugins::Seekable, GetSeekable, (), (override));
54     MOCK_METHOD(Status, GetSize, (uint64_t & fileSize), (override));
55     MOCK_METHOD(bool, IsSeekToTimeSupported, (), (override));
56     MOCK_METHOD(bool, IsLocalFd, (), (override));
57     MOCK_METHOD(int64_t, GetDuration, (), (override));
58     MOCK_METHOD(Status, SeekToTime, (int64_t seekTime, SeekMode mode), (override));
59     MOCK_METHOD(Status, SeekTo, (uint64_t offset), (override));
60     MOCK_METHOD(Status, GetBitRates, (std::vector<uint32_t> & bitRates), (override));
61     MOCK_METHOD(Status, SelectBitRate, (uint32_t bitRate), (override));
62     MOCK_METHOD(Status, AutoSelectBitRate, (uint32_t bitRate), (override));
63     MOCK_METHOD(Status, StopBufferring, (bool flag), (override));
64     MOCK_METHOD(Status, SetStartPts, (int64_t startPts), (override));
65     MOCK_METHOD(Status, SetExtraCache, (uint64_t cacheDuration), (override));
66     MOCK_METHOD(Status, SetCurrentBitRate, (int32_t bitRate, int32_t streamID), (override));
67     MOCK_METHOD(void, SetCallback, (Callback * callback), (override));
68     MOCK_METHOD(bool, IsNeedPreDownload, (), (override));
69     MOCK_METHOD(void, SetDemuxerState, (int32_t streamId), (override));
70     MOCK_METHOD(Status, GetStreamInfo, (std::vector<StreamInfo> & streams), (override));
71     MOCK_METHOD(Status, Read, (int32_t streamID, std::shared_ptr<Buffer> &buffer,
72         uint64_t offset, size_t expectedLen), (override));
73     MOCK_METHOD(void, SetInterruptState, (bool isInterruptNeeded), (override));
74     MOCK_METHOD(Status, GetDownloadInfo, (DownloadInfo & downloadInfo), (override));
75     MOCK_METHOD(Status, GetPlaybackInfo, (PlaybackInfo & playbackInfo), (override));
76     MOCK_METHOD(Status, SelectStream, (int32_t streamID), (override));
77     MOCK_METHOD(void, SetEnableOnlineFdCache, (bool isEnableFdCache), (override));
78     MOCK_METHOD(size_t, GetSegmentOffset, (), (override));
79     MOCK_METHOD(bool, GetHLSDiscontinuity, (), (override));
80     MOCK_METHOD(void, WaitForBufferingEnd, (), (override));
81     MOCK_METHOD(bool, SetInitialBufferSize, (int32_t offset, int32_t size), (override));
82     MOCK_METHOD(Status, SetPerfRecEnabled, (bool perfRecEnabled), (override));
83     MOCK_METHOD(void, NotifyInitSuccess, (), (override));
84     MOCK_METHOD(uint64_t, GetCachedDuration, (), (override));
85     MOCK_METHOD(void, RestartAndClearBuffer, (), (override));
86     MOCK_METHOD(bool, IsFlvLive, (), (override));
87     MOCK_METHOD(bool, IsFlvLiveStream, (), (override, const));
88     MOCK_METHOD(uint64_t, GetMemorySize, (), (override));
89     MOCK_METHOD(std::string, GetContentType, (), (override));
90     MOCK_METHOD(bool, IsHlsFmp4, (), (override));
91     MOCK_METHOD(Status, InitPlugin, (const std::shared_ptr<Plugins::MediaSource>& source), (override));
92     MOCK_METHOD(std::string, GetUriSuffix, (const std::string& uri), (override));
93     MOCK_METHOD(bool, GetProtocolByUri, (), (override));
94     MOCK_METHOD(bool, ParseProtocol, (const std::shared_ptr<Plugins::MediaSource>& source), (override));
95     MOCK_METHOD(Status, FindPlugin, (const std::shared_ptr<Plugins::MediaSource>& source), (override));
96     MOCK_METHOD(void, ClearData, (), (override));
97     MOCK_METHOD(Status, ReadWithPerfRecord, (int32_t streamID, std::shared_ptr<Plugins::Buffer>& buffer,
98         uint64_t offset, size_t expectedLen), (override));
99 };
100 }
101 }
102 
103 #endif