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 DEMUXER_PLUGIN_MANAGER_UNITTEST_H 17 #define DEMUXER_PLUGIN_MANAGER_UNITTEST_H 18 #include "gtest/gtest.h" 19 #include "gmock/gmock.h" 20 21 #include <atomic> 22 #include <limits> 23 #include <string> 24 #include <shared_mutex> 25 #include "base_stream_demuxer.h" 26 #include "avcodec_common.h" 27 #include "demuxer_plugin_manager.h" 28 29 namespace OHOS { 30 namespace Media { 31 class MockBaseStreamDemuxer; 32 class DemuxerPluginManagerUnittest : public testing::Test { 33 public: 34 // SetUpTestCase: Called before all test cases 35 static void SetUpTestCase(void); 36 // TearDownTestCase: Called after all test case 37 static void TearDownTestCase(void); 38 // SetUp: Called before each test cases 39 void SetUp(void); 40 // TearDown: Called after each test cases 41 void TearDown(void); 42 43 protected: 44 std::shared_ptr<DemuxerPluginManager> demuxerPluginManager_{ nullptr }; 45 std::shared_ptr<DataSourceImpl> dataSourceImpl_{ nullptr }; 46 std::shared_ptr<MockBaseStreamDemuxer> streamDemuxer_{ nullptr }; 47 }; 48 class MockBaseStreamDemuxer : public BaseStreamDemuxer { 49 public: 50 MockBaseStreamDemuxer() = default; 51 ~MockBaseStreamDemuxer() = default; 52 53 MOCK_METHOD(Status, Pause, (), ()); 54 MOCK_METHOD(Status, Resume, (), ()); 55 MOCK_METHOD(Status, Start, (), ()); 56 MOCK_METHOD(Status, Stop, (), ()); 57 MOCK_METHOD(Status, Flush, (), ()); 58 MOCK_METHOD(Status, ResetAllCache, (), ()); 59 MOCK_METHOD(Status, CallbackReadAt, (int32_t streamID, int64_t offset, std::shared_ptr<Buffer>& buffer, 60 size_t expectedLen), ()); 61 MOCK_METHOD(Status, Init, (const std::string& uri), ()); 62 MOCK_METHOD(Status, ResetCache, (int32_t streamId), ()); 63 MOCK_METHOD(void, SetDemuxerState, (int32_t streamId, DemuxerState state), ()); 64 MOCK_METHOD(int32_t, GetNewAudioStreamID, (), ()); 65 MOCK_METHOD(int32_t, GetNewSubtitleStreamID, (), ()); 66 MOCK_METHOD(int32_t, GetNewVideoStreamID, (), ()); 67 MOCK_METHOD(std::string, SnifferMediaType, (int32_t streamID), ()); 68 MOCK_METHOD(bool, SetSourceInitialBufferSize, (int32_t offset, int32_t size), (override)); 69 }; 70 } // namespace Media 71 } // namespace OHOS 72 #endif