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 #ifndef HISTREAMER_DATA_STREAM_SOURCE_PLUGIN_UNIT_TEST_H 16 #define HISTREAMER_DATA_STREAM_SOURCE_PLUGIN_UNIT_TEST_H 17 18 #include "gtest/gtest.h" 19 #include <gmock/gmock.h> 20 #include "data_stream_source_plugin.h" 21 22 namespace OHOS { 23 namespace Media { 24 namespace Plugin { 25 namespace DataStreamSource { 26 class TestCallback : public Plugins::Callback { OnEvent(const Plugins::PluginEvent & event)27 void OnEvent(const Plugins::PluginEvent &event) override 28 { 29 (void) event; 30 } 31 }; 32 33 class MockMediaDataSource : public IMediaDataSource { 34 public: 35 MockMediaDataSource() = default; 36 ~MockMediaDataSource() override = default; 37 38 MOCK_METHOD(int32_t, ReadAt, 39 (const std::shared_ptr<AVSharedMemory> &mem, uint32_t length, int64_t pos), (override)); 40 MOCK_METHOD(int32_t, GetSize, (int64_t &size), (override)); 41 // Deprecated methods 42 MOCK_METHOD(int32_t, ReadAt, 43 (int64_t pos, uint32_t length, const std::shared_ptr<AVSharedMemory> &mem), (override)); 44 MOCK_METHOD(int32_t, ReadAt, 45 (uint32_t length, const std::shared_ptr<AVSharedMemory> &mem), (override)); 46 }; 47 48 class DataStreamSourceUnitTest : public testing::Test { 49 public: 50 // SetUpTestCase: Called before all test cases 51 static void SetUpTestCase(void); 52 // TearDownTestCase: Called after all test case 53 static void TearDownTestCase(void); 54 // SetUp: Called before each test cases 55 void SetUp(void); 56 // TearDown: Called after each test cases 57 void TearDown(void); 58 59 protected: 60 std::shared_ptr<DataStreamSourcePlugin> plugin_{nullptr}; 61 std::shared_ptr<MockMediaDataSource> mockDataSrc_{nullptr}; 62 }; 63 } // namespace FileSource 64 } // namespace Plugins 65 } // namespace Media 66 } // namespace OHOS 67 #endif // HISTREAMER_DATA_STREAM_SOURCE_PLUGIN_UNIT_TEST_H