From 1f4ef3416ebc422de5740b48fe81d501db1c779e Mon Sep 17 00:00:00 2001 From: zhangwt3652 Date: Wed, 30 Apr 2025 15:11:39 +0800 Subject: [PATCH] =?UTF-8?q?tdd=E8=A6=86=E7=9B=96=E5=BA=A6=E6=8F=90?= =?UTF-8?q?=E5=8D=870430?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangwt3652 --- test/unittest/dfx_test/media_dfx_test.cpp | 99 +++ test/unittest/hiplayer_impl_unittest/BUILD.gn | 129 ++++ .../hiplayer_impl_unittest.cpp | 614 ++++++++++++++++++ .../hiplayer_impl_unittest.h | 191 ++++++ .../sa_media_client_unit_test/BUILD.gn | 135 ++++ .../media_client_unit_test.cpp | 100 +++ .../media_client_unit_test.h | 60 ++ 7 files changed, 1328 insertions(+) create mode 100644 test/unittest/hiplayer_impl_unittest/BUILD.gn create mode 100644 test/unittest/hiplayer_impl_unittest/hiplayer_impl_unittest.cpp create mode 100644 test/unittest/hiplayer_impl_unittest/hiplayer_impl_unittest.h create mode 100644 test/unittest/sa_media_client_unit_test/BUILD.gn create mode 100644 test/unittest/sa_media_client_unit_test/media_client_unit_test.cpp create mode 100644 test/unittest/sa_media_client_unit_test/media_client_unit_test.h diff --git a/test/unittest/dfx_test/media_dfx_test.cpp b/test/unittest/dfx_test/media_dfx_test.cpp index 2bde70596..faa66a694 100644 --- a/test/unittest/dfx_test/media_dfx_test.cpp +++ b/test/unittest/dfx_test/media_dfx_test.cpp @@ -219,6 +219,105 @@ HWTEST_F(MediaDfxTest, ParseOneEvent_ShouldParseBool_WhenBoolType, TestSize.Leve EXPECT_EQ(metaInfoJson[Tag::MEDIA_HAS_VIDEO], "true"); } + +// Scenario7: Test case for float type +HWTEST_F(MediaDfxTest, ParseOneEvent_ShouldParseFloat_WhenFloatType, TestSize.Level0) { + std::pair> listPair; + listPair.first = 1; + listPair.second = std::make_shared(); + float value = 0.5f; + listPair.second->SetData(Tag::MEDIA_LATITUDE, value); + json metaInfoJson; + + mediaEvent_->ParseOneEvent(listPair, metaInfoJson); + Any valueType = OHOS::Media::GetDefaultAnyValue(Tag::MEDIA_LATITUDE); + EXPECT_EQ(Any::IsSameTypeWith(valueType), true); + EXPECT_EQ(metaInfoJson[Tag::MEDIA_LATITUDE], "0.50"); +} + +// Scenario8: Test case for default type +HWTEST_F(MediaDfxTest, ParseOneEvent_ShouldParsedefault_WhendefaultType, TestSize.Level0) { + std::pair> listPair; + listPair.first = 1; + listPair.second = std::make_shared(); + float value = 0.5f; + listPair.second->SetData(Tag::VIDEO_BIT_STREAM_FORMAT, value); + json metaInfoJson; + + mediaEvent_->ParseOneEvent(listPair, metaInfoJson); + Any valueType = OHOS::Media::GetDefaultAnyValue(Tag::VIDEO_BIT_STREAM_FORMAT); + EXPECT_EQ(Any::IsSameTypeWith(valueType), false); +} + +// Scenario9: Test case for uint64_t type repeat +HWTEST_F(MediaDfxTest, ParseOneEvent_ShouldParseUint64_WhenUint64Type_002, TestSize.Level0) { + std::pair> listPair; + listPair.first = 1; + listPair.second = std::make_shared(); + listPair.second->SetData(Tag::MEDIA_FILE_SIZE, 123u); + listPair.second->SetData(Tag::MEDIA_POSITION, 123u); + listPair.second->SetData(Tag::AV_PLAYER_DOWNLOAD_TOTAL_BITS, 123u); + json metaInfoJson; + + mediaEvent_->ParseOneEvent(listPair, metaInfoJson); + Any valueType = OHOS::Media::GetDefaultAnyValue(Tag::MEDIA_FILE_SIZE); + EXPECT_EQ(Any::IsSameTypeWith(valueType), true); + valueType = OHOS::Media::GetDefaultAnyValue(Tag::AV_PLAYER_DOWNLOAD_TOTAL_BITS); + EXPECT_EQ(Any::IsSameTypeWith(valueType), true); + valueType = OHOS::Media::GetDefaultAnyValue(Tag::MEDIA_POSITION); + EXPECT_EQ(Any::IsSameTypeWith(valueType), true); +} #endif + +// Scenario10: Test case for BehaviorEventWrite +HWTEST_F(MediaDfxTest, ParseOneEvent_BehaviorEventWrite, TestSize.Level0) { + std::string status = "testMeg1"; + std::string module = "testmodule"; + BehaviorEventWrite(status, module); + bool ret = false; + std::string testvalue = "state change, current state is: testMeg1"; + ret = mediaEvent_->CreateMsg("state change, current state is: testMeg1"); + EXPECT_NE(ret, false); + EXPECT_EQ(mediaEvent_->msg_, testvalue); +} + +// Scenario11: Test case for BehaviorEventWriteForScreenCapture +HWTEST_F(MediaDfxTest, ParseOneEvent_BehaviorEventWriteForScreenCapture, TestSize.Level0) { + std::string status = "testMeg2"; + std::string module = "testmodule"; + int32_t appUid = 10; + int32_t appPid = 11; + BehaviorEventWriteForScreenCapture(status, module, appUid, appPid); + bool ret = false; + std::string testvalue = "state change, current state is: testMeg2"; + ret = mediaEvent_->CreateMsg("state change, current state is: testMeg2"); + EXPECT_NE(ret, false); + EXPECT_EQ(mediaEvent_->msg_, testvalue); +} + +// Scenario12: Test case for StatisticEventWriteBundleName +HWTEST_F(MediaDfxTest, ParseOneEvent_StatisticEventWriteBundleName, TestSize.Level0) { + std::string status = "testMeg3"; + std::string module = "testmodule"; + std::string bundleName = ""; + StatisticEventWriteBundleName(status, module, bundleName); + bool ret = false; + std::string testvalue = "state change, current state is: testMeg3"; + ret = mediaEvent_->CreateMsg("state change, current state is: testMeg3"); + EXPECT_NE(ret, false); + EXPECT_EQ(mediaEvent_->msg_, testvalue); +} + +// Scenario13: Test case for FaultEventWrite +HWTEST_F(MediaDfxTest, ParseOneEvent_FaultEventWrite, TestSize.Level0) { + std::string status = "testMeg4Fault"; + std::string module = "testmodule"; + FaultEventWrite(status, module); + bool ret = false; + std::string testvalue = "testMeg4_Fault"; + ret = mediaEvent_->CreateMsg("testMeg4Fault"); + EXPECT_NE(ret, false); + EXPECT_EQ(mediaEvent_->msg_, testvalue); +} } } \ No newline at end of file diff --git a/test/unittest/hiplayer_impl_unittest/BUILD.gn b/test/unittest/hiplayer_impl_unittest/BUILD.gn new file mode 100644 index 000000000..1b39e5b19 --- /dev/null +++ b/test/unittest/hiplayer_impl_unittest/BUILD.gn @@ -0,0 +1,129 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/multimedia/player_framework/config.gni") + +module_output_path = "player_framework/player_framework/player" + +config("hiplayer_impl_unittest_config") { + visibility = [ ":*" ] + + cflags = [ + "-O2", + "-fPIC", + "-Wall", + "-fexceptions", + "-fno-rtti", + "-Wno-unused-but-set-variable", + "-Wno-format", + "-Dprivate=public", + "-Dprotected=public", + ] + cflags_cc = cflags + include_dirs = [ + "./", + "$MEDIA_PLAYER_ROOT_DIR/interfaces/inner_api/native", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/player", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/utils", + "$MEDIA_PLAYER_ROOT_DIR/services/services/engine_intf", + "$MEDIA_PLAYER_ROOT_DIR/services/services/player/client", + "$MEDIA_PLAYER_ROOT_DIR/services/services/player/ipc", + "$MEDIA_PLAYER_ROOT_DIR/services/services/player/server/", + "$MEDIA_PLAYER_ROOT_DIR/services/utils/include", + ] + defines = [] + + if (target_cpu == "arm64" || is_emulator) { + dragging_player_path = "\"/system/lib64\"" + } else { + dragging_player_path = "\"/system/lib\"" + } + + defines += [ "DRAGGING_PLAYER_PATH=${dragging_player_path}" ] + + defines += player_framework_defines +} + +ohos_unittest("hiplayer_impl_unittest") { + module_out_path = module_output_path + stack_protector_ret = true + + sources = [ + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/player/dfx_agent.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/player/dragging_player_agent.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/player/hiplayer_callback_looper.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/player/hiplayer_impl.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/player/live_controller.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/player/seek_agent.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/utils/media_dfx.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/utils/media_utils.cpp", + "hiplayer_impl_unittest.cpp", + ] + + configs = [ + ":hiplayer_impl_unittest_config", + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx_public_config", + "$MEDIA_PLAYER_ROOT_DIR/services/utils:media_service_utils_public_config", + ] + + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libprivacy_sdk", + "audio_framework:audio_client", + "audio_framework:audio_renderer", + "av_codec:av_codec_client", + "av_codec:av_codec_media_engine_filters", + "av_codec:av_codec_media_engine_modules", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "googletest:gmock", + "graphic_surface:surface", + "graphic_surface:sync_fence", + "hicollie:libhicollie", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "init:libbegetutil", + "ipc:ipc_single", + "libxml2:libxml2", + "media_foundation:media_foundation", + "os_account:os_account_innerkits", + "qos_manager:qos", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if (player_framework_support_drm) { + external_deps += [ "drm_framework:drm_framework" ] + } + + deps = [ + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/player:media_engine_histreamer_player", + "$MEDIA_PLAYER_ROOT_DIR/services/utils:media_service_utils", + ] + + deps = [] +} diff --git a/test/unittest/hiplayer_impl_unittest/hiplayer_impl_unittest.cpp b/test/unittest/hiplayer_impl_unittest/hiplayer_impl_unittest.cpp new file mode 100644 index 000000000..7336da4e8 --- /dev/null +++ b/test/unittest/hiplayer_impl_unittest/hiplayer_impl_unittest.cpp @@ -0,0 +1,614 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "media_errors.h" +#include "hiplayer_impl_unittest.h" +#include "pipeline/pipeline.h" +#include "player.h" +#include "audio_device_descriptor.h" +#include "audio_capture_filter.h" + +namespace OHOS { +namespace Media { +using namespace std; +using namespace testing; +using namespace testing::ext; + +void PlayHiplayerImplUnitTest::SetUpTestCase(void) +{ +} + +void PlayHiplayerImplUnitTest::TearDownTestCase(void) +{ +} + +void PlayHiplayerImplUnitTest::SetUp(void) +{ + hiplayer_ = std::make_shared(0, 0, 0, 0); +} + +void PlayHiplayerImplUnitTest::TearDown(void) +{ + hiplayer_ = nullptr; +} + +// @tc.name Test SetDefaultAudioRenderInfo API +// @tc.number PHIUT_SetDefaultAudioRenderInfo_001 +// @tc.desc Test SetDefaultAudioRenderInfo interface, 1. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_SetDefaultAudioRenderInfo_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::vector> trackInfos; + std::shared_ptr testptr = nullptr; + trackInfos.push_back(testptr); + hiplayer_->SetDefaultAudioRenderInfo(trackInfos); + EXPECT_EQ(hiplayer_->isNetWorkPlay_, false); +} + +// @tc.name Test SetSource API +// @tc.number PHIUT_SetSource_001 +// @tc.desc Test SetSource interface, 2. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_SetSource_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::shared_ptr dataSrc; + int32_t ret = -10; + ret = hiplayer_->SetSource(dataSrc); + EXPECT_EQ(ret, 0); +} + +// @tc.name Test PrepareAsync API +// @tc.number PHIUT_PrepareAsync_001 +// @tc.desc Test PrepareAsync interface, 1. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_PrepareAsync_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + hiplayer_->pipelineStates_ = PlayerStates::PLAYER_STATE_ERROR; + int32_t ret = -10; + ret = hiplayer_->PrepareAsync(); + EXPECT_EQ(ret, 331350054); +} + +// @tc.name Test UpdatePlayerStateAndNotify API +// @tc.number PHIUT_UpdatePlayerStateAndNotify_001 +// @tc.desc Test UpdatePlayerStateAndNotify interface, 1. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_UpdatePlayerStateAndNotify_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + hiplayer_->durationMs_.store(0); + hiplayer_->UpdatePlayerStateAndNotify(); + EXPECT_EQ(hiplayer_->durationMs_.load(), 0); +} + +// @tc.name Test UpdateMediaFirstPts API +// @tc.number PHIUT_UpdateMediaFirstPts_001 +// @tc.desc Test UpdateMediaFirstPts interface, 2. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_UpdateMediaFirstPts_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + hiplayer_->demuxer_ = std::make_shared(name, type); + std::shared_ptr testptr = nullptr; + hiplayer_->demuxer_->demuxer_ = std::make_shared(); + hiplayer_->demuxer_->demuxer_->mediaMetaData_.trackMetas.push_back(testptr); + hiplayer_->UpdateMediaFirstPts(); + EXPECT_EQ(hiplayer_->demuxer_->GetStreamMetaInfo().empty(), false); +} + +// @tc.name Test SelectBitRate API +// @tc.number PHIUT_SelectBitRate_001 +// @tc.desc Test SelectBitRate interface, 1. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_SelectBitRate_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + uint32_t bitRate = 1212; + bool isAutoSelect = false; + int32_t ret = 0; + std::cout << "1111111" << std::endl; + ret = hiplayer_->SelectBitRate(bitRate, isAutoSelect); + std::cout << "2222222" << std::endl; + EXPECT_NE(ret, 0); +} + +// @tc.name Test DoInitializeForHttp API +// @tc.number PHIUT_DoInitializeForHttp_001 +// @tc.desc Test DoInitializeForHttp interface, 1. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_DoInitializeForHttp_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + hiplayer_->isNetWorkPlay_ = true; + string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + hiplayer_->demuxer_ = std::make_shared(name, type); + hiplayer_->demuxer_->demuxer_ = std::make_shared(); + hiplayer_->DoInitializeForHttp(); + EXPECT_NE(hiplayer_->isNetWorkPlay_, false); +} + +// @tc.name Test ReportAudioInterruptEvent API +// @tc.number PHIUT_ReportAudioInterruptEvent_001 +// @tc.desc Test ReportAudioInterruptEvent interface, 1. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_ReportAudioInterruptEvent_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + hiplayer_->interruptNotifyPlay_.store(true); + hiplayer_->ReportAudioInterruptEvent(); + EXPECT_EQ(hiplayer_->isNetWorkPlay_, false); +} + +// @tc.name Test Seek API +// @tc.number PHIUT_Seek_001 +// @tc.desc Test Seek interface, 2. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_Seek_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + int32_t mSeconds = 5; + PlayerSeekMode mode = PlayerSeekMode::SEEK_NEXT_SYNC; + int32_t ret = -10; + hiplayer_->endTimeWithMode_ = 0; + hiplayer_->startTimeWithMode_ = 10; + ret = hiplayer_->Seek(mSeconds, mode); + EXPECT_NE(ret, 0); +} + +// @tc.name Test NeedSeekClosest API +// @tc.number PHIUT_NeedSeekClosest_001 +// @tc.desc Test Seek NeedSeekClosest, 2. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_NeedSeekClosest_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + hiplayer_->demuxer_ = std::make_shared(name, type); + std::shared_ptr testptr = std::make_shared(); + hiplayer_->demuxer_->demuxer_ = std::make_shared(); + hiplayer_->demuxer_->demuxer_->mediaMetaData_.trackMetas.push_back(testptr); + bool ret = hiplayer_->NeedSeekClosest(); + EXPECT_NE(ret, false); +} + +// @tc.name Test SetVolumeMode API +// @tc.number PHIUT_SetVolumMode_001 +// @tc.desc Test SetVolumeMode interface, 1. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_SetVolumeMode_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + int32_t mode = 10; + std::string name = "testname"; + hiplayer_->audioSink_ = std::make_shared(name); + int32_t ret = hiplayer_->SetVolumeMode(mode); + EXPECT_EQ(ret, 0); +} + +// @tc.name Test SetVolume API +// @tc.number PHIUT_SetVolume_001 +// @tc.desc Test SetVolume interface, 1. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_SetVolume_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + float leftVolume = 0.5f; + float rightVolume = 0.5f; + std::string name = "testname"; + hiplayer_->audioSink_ = std::make_shared(name); + int32_t ret = hiplayer_->SetVolume(leftVolume, rightVolume); + EXPECT_NE(ret, -7); +} + +// @tc.name Test SetDecryptConfig API +// @tc.number PHIUT_SetDecryptConfig_001 +// @tc.desc Test SetDecryptConfig interface, 1. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_SetDecryptConfig_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + sptr keySessionProxy; + bool svp = false; + int32_t ret = hiplayer_->SetDecryptConfig(keySessionProxy, svp); + EXPECT_EQ(ret, -7); +} + +// @tc.name Test InitDuration API +// @tc.number PHIUT_InitDuration_001 +// @tc.desc Test InitDuration interface, 3. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_InitDuration_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::string name = "testname"; + hiplayer_->audioSink_ = std::make_shared(name); + hiplayer_->audioSink_->audioSink_ = std::make_shared(); + int32_t ret = hiplayer_->InitDuration(); + EXPECT_NE(ret, 0); +} + +// @tc.name Test OnEventContinue API +// @tc.number PHIUT_OnEventContinue_001 +// @tc.desc Test OnEventContinue interface, 3. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_OnEventContinue_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + Event event; + event.type = EventType::EVENT_RESOLUTION_CHANGE; + std::string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + hiplayer_->demuxer_ = std::make_shared(name, type); + std::shared_ptr testptr = std::make_shared(); + hiplayer_->demuxer_->demuxer_ = std::make_shared(); + hiplayer_->demuxer_->demuxer_->mediaMetaData_.trackMetas.push_back(testptr); + Format format; + format.meta_ = std::make_shared(); + event.param = format; + hiplayer_->OnEventContinue(event); + + event.type = EventType::EVENT_SEI_INFO; + hiplayer_->OnEventContinue(event); + + event.type = EventType::EVENT_FLV_AUTO_SELECT_BITRATE; + hiplayer_->OnEventContinue(event); + EXPECT_EQ(hiplayer_->audioSink_, nullptr); +} + +// @tc.name Test OnEventSub API +// @tc.number PHIUT_OnEventSub_001 +// @tc.desc Test OnEventSub interface, 4. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_OnEventSub_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + Event event; + event.type = EventType::EVENT_AUDIO_DEVICE_CHANGE; + AudioStandard::AudioDeviceDescriptor test1; + AudioStandard::AudioStreamDeviceChangeReason test2; + std::pair p1(test1, test2); + event.param = p1; + hiplayer_->OnEventSub(event); + + event.type = EventType::BUFFERING_END; + hiplayer_->isBufferingStartNotified_.store(true); + hiplayer_->isSeekClosest_.store(false); + int32_t test3 = 10; + event.param = test3; + hiplayer_->OnEventSub(event); + + event.type = EventType::BUFFERING_START; + hiplayer_->isBufferingStartNotified_.store(true); + hiplayer_->OnEventSub(event); + + event.type = EventType::EVENT_SOURCE_BITRATE_START; + uint32_t test4 = 10; + event.param = test4; + hiplayer_->OnEventSub(event); + EXPECT_EQ(hiplayer_->audioSink_, nullptr); +} + +// @tc.name Test OnEventSubTrackChange API +// @tc.number PHIUT_OnEventSubTrackChange_001 +// @tc.desc Test OnEventSubTrackChange interface, 2. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_OnEventSubTrackChange_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + Event event; + int32_t test1 = 10; + std::string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + hiplayer_->demuxer_ = std::make_shared(name, type); + std::shared_ptr testptr = std::make_shared(); + hiplayer_->demuxer_->demuxer_ = std::make_shared(); + hiplayer_->demuxer_->demuxer_->mediaMetaData_.trackMetas.push_back(testptr); + event.param = test1; + event.type = EventType::EVENT_VIDEO_TRACK_CHANGE; + hiplayer_->OnEventSubTrackChange(event); + + event.type = EventType::EVENT_SUBTITLE_TRACK_CHANGE; + hiplayer_->subtitleSink_ = std::make_shared("test"); + hiplayer_->OnEventSubTrackChange(event); + EXPECT_EQ(hiplayer_->audioSink_, nullptr); +} + +// @tc.name Test DoSetSource API +// @tc.number PHIUT_DoSetSource_001 +// @tc.desc Test DoSetSource interface, 2. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_DoSetSource_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::string url = ""; + hiplayer_->mimeType_ = "testtype"; + AVPlayMediaStream avplayMediaStream; + hiplayer_->playMediaStreamVec_.push_back(avplayMediaStream); + std::shared_ptr source = std::make_shared(url); + hiplayer_->DoSetSource(source); + EXPECT_EQ(hiplayer_->audioSink_, nullptr); +} + +// @tc.name Test Resume API +// @tc.number PHIUT_Resume_001 +// @tc.desc Test Resume interface, 1. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_Resume_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + hiplayer_->Resume(); + EXPECT_NE(hiplayer_->startTime_, 0); +} + +// @tc.name Test HandleDrmInfoUpdatedEvent API +// @tc.number PHIUT_HandleDrmInfoUpdatedEvent_001 +// @tc.desc Test HandleDrmInfoUpdatedEvent interface, 1. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_HandleDrmInfoUpdatedEvent_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + Event event; + std::multimap> test1; + event.param = test1; + hiplayer_->HandleDrmInfoUpdatedEvent(event); + EXPECT_EQ(hiplayer_->audioSink_, nullptr); +} + +// @tc.name Test HandleResolutionChangeEvent API +// @tc.number PHIUT_HandleResolutionChangeEvent_001 +// @tc.desc Test HandleResolutionChangeEvent interface, 4. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_HandleResolutionChangeEvent_001, TestSize.Level0) +{ +#ifdef SUPPORT_VIDEO +#undef SUPPORT_VIDEO +#endif +#define SUPPORT_VIDEO + ASSERT_NE(hiplayer_, nullptr); + Event event; + Format format; + format.meta_ = std::make_shared(); + event.param = format; + std::string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + hiplayer_->demuxer_ = std::make_shared(name, type); + std::shared_ptr testptr = std::make_shared(); + hiplayer_->demuxer_->demuxer_ = std::make_shared(); + hiplayer_->demuxer_->demuxer_->mediaMetaData_.trackMetas.push_back(testptr); + hiplayer_->currentVideoTrackId_ = 0; + hiplayer_->HandleResolutionChangeEvent(event); + EXPECT_EQ(hiplayer_->audioSink_, nullptr); +#undef SUPPORT_VIDEO +} + +// @tc.name Test NotifySeekDone API +// @tc.number PHIUT_NotifySeekDone_001 +// @tc.desc Test NotifySeekDone interface, 1. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_NotifySeekDone_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + hiplayer_->curState_ = PlayerStateId::INIT; + std::string name = "testname"; + int32_t test_value = 0; + FilterType type = FilterType::VIDEO_CAPTURE; + hiplayer_->demuxer_ = std::make_shared(name, type); + std::shared_ptr testptr = std::make_shared(); + hiplayer_->demuxer_->demuxer_ = std::make_shared(); + hiplayer_->demuxer_->demuxer_->mediaMetaData_.trackMetas.push_back(testptr); + hiplayer_->isSeekClosest_.store(true); + hiplayer_->isBufferingStartNotified_.store(true); + hiplayer_->NotifySeekDone(test_value); + EXPECT_NE(hiplayer_->isSeekClosest_.load(), true); +} + +// @tc.name Test HandleVideoTrackChangeEvent API +// @tc.number PHIUT_HandleVideoTrackChangeEvent_001 +// @tc.desc Test HandleVideoTrackChangeEvent interface, 2. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_HandleVideoTrackChangeEvent_001, TestSize.Level0) +{ +#define SUPPORT_VIDEO + ASSERT_NE(hiplayer_, nullptr); + std::string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + hiplayer_->demuxer_ = std::make_shared(name, type); + std::shared_ptr testptr = std::make_shared(); + hiplayer_->demuxer_->demuxer_ = std::make_shared(); + hiplayer_->demuxer_->demuxer_->mediaMetaData_.trackMetas.push_back(testptr); + Event event; + Format format; + format.meta_ = std::make_shared(); + event.param = format; + hiplayer_->HandleVideoTrackChangeEvent(event); + EXPECT_NE(hiplayer_->isSeekClosest_.load(), true); +#undef SUPPORT_VIDEO +} + +// @tc.name Test OnStateChanged API +// @tc.number PHIUT_OnStateChanged_001 +// @tc.desc Test OnStateChanged interface, 1. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_OnStateChanged_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + hiplayer_->isDoCompletedSeek_.store(false); + hiplayer_->curState_ = PlayerStateId::EOS; + PlayerStateId state = PlayerStateId::PAUSE; + bool isSystemOperation = false; + hiplayer_->OnStateChanged(state, isSystemOperation); + EXPECT_NE(hiplayer_->isSeekClosest_.load(), true); +} + +// @tc.name Test OnCallback API +// @tc.number PHIUT_OnCallback_001 +// @tc.desc Test OnCallback interface, 2. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_OnCallback_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::shared_ptr filter; + FilterCallBackCommand cmd = FilterCallBackCommand::NEXT_FILTER_NEEDED; + StreamType outType = StreamType::STREAMTYPE_RAW_VIDEO; + Status ret; + ret = hiplayer_->OnCallback(filter, cmd, outType); + EXPECT_EQ(ret, Status::OK); +} + +// @tc.name Test SetAudioRendererParameter API +// @tc.number PHIUT_SetAudioRendererParameter_001 +// @tc.desc Test SetAudioRendererParameter interface, 1. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_SetAudioRendererParameter_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + std::string name = "testname"; + hiplayer_->audioSink_ = std::make_shared(name); + hiplayer_->audioInterruptMode_ = std::make_shared();; + hiplayer_->SetAudioRendererParameter(); + EXPECT_NE(hiplayer_->isSeekClosest_.load(), true); +} + +// @tc.name Test StartSeekContinous API +// @tc.number PHIUT_StartSeekContinous_001 +// @tc.desc Test StartSeekContinous interface, 2. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_StartSeekContinous_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + Status ret; + hiplayer_->curState_ = PlayerStateId::PLAYING; + + auto videoDecoder = std::make_shared(); + hiplayer_->videoDecoder_ = videoDecoder; + EXPECT_CALL(*videoDecoder, DoInitAfterLink()).WillRepeatedly(Return(Status::OK)); + + ret = hiplayer_->StartSeekContinous(); + EXPECT_EQ(hiplayer_->draggingPlayerAgent_, nullptr); + EXPECT_EQ(ret, Status::OK); +} + +// @tc.name Test SetSeiMessageListener API +// @tc.number PHIUT_SetSeiMessageListener_001 +// @tc.desc Test SetSeiMessageListener interface, 2. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_SetSeiMessageListener_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + Status ret; + hiplayer_->seiDecoder_ = + FilterFactory::Instance().CreateFilter("player.sei", FilterType::FILTERTYPE_SEI); + ret = hiplayer_->SetSeiMessageListener(); + EXPECT_NE(ret, Status::OK); +} + +// @tc.name Test DoRestartLiveLink API +// @tc.number PHIUT_DoRestartLiveLink_001 +// @tc.desc Test DoRestartLiveLink interface, 6. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_DoRestartLiveLink_001, TestSize.Level0) +{ + ASSERT_NE(hiplayer_, nullptr); + hiplayer_->isFlvLive_ = true; + std::string name = "testname"; + FilterType type = FilterType::VIDEO_CAPTURE; + hiplayer_->demuxer_ = std::make_shared(name, type); + std::shared_ptr testptr = std::make_shared(); + hiplayer_->demuxer_->demuxer_ = std::make_shared(); + hiplayer_->demuxer_->demuxer_->mediaMetaData_.trackMetas.push_back(testptr); + hiplayer_->audioSink_ = std::make_shared(name); + + auto videoDecoder = std::make_shared(); + hiplayer_->videoDecoder_ = videoDecoder; + EXPECT_CALL(*videoDecoder, DoInitAfterLink()).WillRepeatedly(Return(Status::OK)); + + hiplayer_->DoRestartLiveLink(); + hiplayer_->demuxer_ = nullptr; + hiplayer_->playerEventReceiver_ = nullptr; + hiplayer_->playerFilterCallback_ = nullptr; + EXPECT_NE(hiplayer_->isSeekClosest_.load(), true); +} + +// @tc.name Test LinkAudioDecoderFilter API +// @tc.number PHIUT_LinkAudioDecoderFilter_001 +// @tc.desc Test LinkAudioDecoderFilter interface, 4. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_LinkAudioDecoderFilter_001, TestSize.Level0) +{ +#ifdef SUPPORT_AVPLAYER_DRM +#undef SUPPORT_AVPLAYER_DRM +#endif +#define SUPPORT_AVPLAYER_DRM +#define SUPPORT_START_STOP_ON_DEMAND + ASSERT_NE(hiplayer_, nullptr); + std::shared_ptr filter = std::make_shared(); + StreamType type = StreamType::STREAMTYPE_RAW_VIDEO; + Status ret; + hiplayer_->isDrmProtected_ = true; + hiplayer_->isDrmPrepared_ = true; + hiplayer_->interruptMonitor_ = std::make_shared(); + hiplayer_->Init(); + ret = hiplayer_->LinkAudioDecoderFilter(filter, type); + hiplayer_->dfxAgent_ = nullptr; + hiplayer_->playerEventReceiver_ = nullptr; + hiplayer_->playerFilterCallback_ = nullptr; + hiplayer_->demuxer_ = nullptr; + hiplayer_->playerId_ = "0"; + EXPECT_EQ(ret, Status::OK); +#undef SUPPORT_START_STOP_ON_DEMAND +#undef SUPPORT_AVPLAYER_DRM +} + +// @tc.name Test LinkAudioSinkFilter API +// @tc.number PHIUT_LinkAudioSinkFilter_001 +// @tc.desc Test LinkAudioSinkFilter interface, 1. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_LinkAudioSinkFilter_001, TestSize.Level0) +{ +#ifdef SUPPORT_START_STOP_ON_DEMAND +#undef SUPPORT_START_STOP_ON_DEMAND +#endif +#define SUPPORT_START_STOP_ON_DEMAND + ASSERT_NE(hiplayer_, nullptr); + std::shared_ptr filter = std::make_shared(); + StreamType outType = StreamType::STREAMTYPE_RAW_VIDEO; + Status ret; + hiplayer_->mutedMediaType_ = OHOS::Media::MediaType::MEDIA_TYPE_AUD; + ret = hiplayer_->LinkAudioSinkFilter(filter, outType); + EXPECT_EQ(ret, Status::OK); +#undef SUPPORT_START_STOP_ON_DEMAND +} + +// @tc.name Test LinkSeiDecoder API +// @tc.number PHIUT_LinkSeiDecoder_001 +// @tc.desc Test LinkSeiDecoder interface, 2. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_LinkSeiDecoder_001, TestSize.Level0) +{ +#ifdef SUPPORT_VIDEO +#undef SUPPORT_VIDEO +#endif +#define SUPPORT_VIDEO + ASSERT_NE(hiplayer_, nullptr); + std::shared_ptr preFilter = std::make_shared(); + StreamType type = StreamType::STREAMTYPE_RAW_VIDEO; + hiplayer_->interruptMonitor_ = std::make_shared(); + Status ret = hiplayer_->LinkSeiDecoder(preFilter, type); + EXPECT_EQ(ret, Status::OK); +#undef SUPPORT_VIDEO +} + +// @tc.name Test LinkVideoDecoderFilter API +// @tc.number PHIUT_LinkVideoDecoderFilter_001 +// @tc.desc Test LinkVideoDecoderFilter interface, 1. +HWTEST_F(PlayHiplayerImplUnitTest, PHIUT_LinkVideoDecoderFilter_001, TestSize.Level0) +{ +#ifdef SUPPORT_AVPLAYER_DRM +#undef SUPPORT_AVPLAYER_DRM +#endif +#define SUPPORT_AVPLAYER_DRM + ASSERT_NE(hiplayer_, nullptr); + std::shared_ptr preFilter = std::make_shared(); + std::shared_ptr filter = preFilter; + StreamType type = StreamType::STREAMTYPE_RAW_VIDEO; + hiplayer_->seiMessageCbStatus_ = true; + hiplayer_->isDrmProtected_ = true; + hiplayer_->isDrmPrepared_ = true; + auto videoDecoder = std::make_shared(); + hiplayer_->videoDecoder_ = videoDecoder; + EXPECT_CALL(*preFilter, DoInitAfterLink()).WillRepeatedly(Return(Status::OK)); + EXPECT_CALL(*videoDecoder, DoInitAfterLink()).WillRepeatedly(Return(Status::OK)); + hiplayer_->Init(); + Status ret = hiplayer_->LinkVideoDecoderFilter(filter, type); + EXPECT_EQ(ret, Status::OK); +#undef SUPPORT_AVPLAYER_DRM +} +} // namespace Media +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/hiplayer_impl_unittest/hiplayer_impl_unittest.h b/test/unittest/hiplayer_impl_unittest/hiplayer_impl_unittest.h new file mode 100644 index 000000000..8b712f63b --- /dev/null +++ b/test/unittest/hiplayer_impl_unittest/hiplayer_impl_unittest.h @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HIPLAYER_IMPL_UNITTEST_H +#define HIPLAYER_IMPL_UNITTEST_H + +#include "gtest/gtest.h" +#include + +#ifdef SUPPORT_VIDEO +#undef SUPPORT_VIDEO +#endif +#define SUPPORT_VIDEO +#include "hiplayer_impl.h" +#undef SUPPORT_VIDEO + +namespace OHOS { +namespace Media { +class PlayHiplayerImplUnitTest : public testing::Test { +public: + // SetUpTestCase: Called before all test cases + static void SetUpTestCase(void); + // TearDownTestCase: Called after all test case + static void TearDownTestCase(void); + // SetUp: Called before each test cases + void SetUp(void); + // TearDown: Called after each test cases + void TearDown(void); + + std::shared_ptr hiplayer_; +}; +class MockFilter : public Filter { +public: + MockFilter():Filter("TestFilter", FilterType::FILTERTYPE_ADEC) {} + ~MockFilter() = default; + + MOCK_METHOD(void, Init, (const std::shared_ptr& receiver, + const std::shared_ptr& callback), ()); + MOCK_METHOD(void, Init, (const std::shared_ptr& receiver, + const std::shared_ptr& callback, const std::shared_ptr& monitor), ()); + MOCK_METHOD(Status, DoSetPerfRecEnabled, (bool isPerfRecEnabled), ()); + MOCK_METHOD(Status, DoInitAfterLink, (), (override)); + MOCK_METHOD(Status, DoPrepare, (), ()); + MOCK_METHOD(Status, DoStart, (), ()); + MOCK_METHOD(Status, DoPause, (), ()); + MOCK_METHOD(Status, DoPauseDragging, (), ()); + MOCK_METHOD(Status, DoPauseAudioAlign, (), ()); + MOCK_METHOD(Status, DoResume, (), ()); + MOCK_METHOD(Status, DoResumeDragging, (), ()); + MOCK_METHOD(Status, DoResumeAudioAlign, (), ()); + MOCK_METHOD(Status, DoStop, (), ()); + MOCK_METHOD(Status, DoFlush, (), ()); + MOCK_METHOD(Status, DoRelease, (), ()); + MOCK_METHOD(Status, DoPreroll, (), ()); + MOCK_METHOD(Status, DoWaitPrerollDone, (bool render), ()); + MOCK_METHOD(Status, DoSetPlayRange, (int64_t start, int64_t end), ()); + MOCK_METHOD(Status, DoProcessInputBuffer, (int recvArg, bool dropFrame), ()); + MOCK_METHOD(Status, DoProcessOutputBuffer, + (int recvArg, bool dropFrame, bool byIdx, uint32_t idx, int64_t renderTime), ()); + MOCK_METHOD(void, SetParameter, (const std::shared_ptr& meta), ()); + MOCK_METHOD(void, GetParameter, (std::shared_ptr& meta), ()); + MOCK_METHOD(Status, LinkNext, (const std::shared_ptr& nextFilter, StreamType outType), ()); + MOCK_METHOD(Status, UpdateNext, (const std::shared_ptr& nextFilter, StreamType outType), ()); + MOCK_METHOD(Status, UnLinkNext, (const std::shared_ptr& nextFilter, StreamType outType), ()); + MOCK_METHOD(Status, OnLinked, (StreamType inType, const std::shared_ptr& meta, + const std::shared_ptr& callback), ()); + MOCK_METHOD(Status, OnUpdated, (StreamType inType, const std::shared_ptr& meta, + const std::shared_ptr& callback), ()); + MOCK_METHOD(Status, OnUnLinked, (StreamType inType, const std::shared_ptr& callback), ()); + MOCK_METHOD(Status, ClearAllNextFilters, (), ()); +}; +class MockDecoderSurfaceFilter : public DecoderSurfaceFilter { +public: + MockDecoderSurfaceFilter():DecoderSurfaceFilter("testname", FilterType::FILTERTYPE_ADEC){} + ~MockDecoderSurfaceFilter() = default; + MOCK_METHOD(Status, Configure, (const std::shared_ptr ¶meter), ()); + MOCK_METHOD(Status, DoInitAfterLink, (), ()); + MOCK_METHOD(Status, DoPrepare, (), ()); + MOCK_METHOD(Status, DoStart, (), ()); + MOCK_METHOD(Status, DoPause, (), ()); + MOCK_METHOD(Status, DoPauseDragging, (), ()); + MOCK_METHOD(Status, DoResume, (), ()); + MOCK_METHOD(Status, DoResumeDragging, (), ()); + MOCK_METHOD(Status, DoStop, (), ()); + MOCK_METHOD(Status, DoFlush, (), ()); + MOCK_METHOD(Status, DoRelease, (), ()); + MOCK_METHOD(Status, DoPreroll, (), ()); + MOCK_METHOD(Status, DoWaitPrerollDone, (bool render), ()); + MOCK_METHOD(Status, DoSetPlayRange, (int64_t start, int64_t end), ()); + MOCK_METHOD(Status, DoProcessInputBuffer, (int recvArg, bool dropFrame), ()); + MOCK_METHOD(Status, DoProcessOutputBuffer, + (int recvArg, bool dropFrame, bool byIdx, uint32_t idx, int64_t renderTime), ()); + MOCK_METHOD(Status, DoSetPerfRecEnabled, (bool isPerfRecEnabled), ()); + + MOCK_METHOD(void, SetParameter, (const std::shared_ptr& parameter), ()); + MOCK_METHOD(void, GetParameter, (std::shared_ptr& parameter), ()); + MOCK_METHOD(void, OnInterrupted, (bool isInterruptNeeded), ()); + + MOCK_METHOD(Status, LinkNext, (const std::shared_ptr &nextFilter, StreamType outType), ()); + MOCK_METHOD(Status, UpdateNext, (const std::shared_ptr &nextFilter, StreamType outType), ()); + MOCK_METHOD(Status, UnLinkNext, (const std::shared_ptr &nextFilter, StreamType outType), ()); + MOCK_METHOD(void, OnLinkedResult, + (const sptr &outputBufferQueue, std::shared_ptr &meta), ()); + MOCK_METHOD(void, OnUpdatedResult, (std::shared_ptr &meta), ()); + + MOCK_METHOD(void, OnUnlinkedResult, (std::shared_ptr &meta), ()); + MOCK_METHOD(FilterType, GetFilterType, (), ()); + MOCK_METHOD(void, DrainOutputBuffer, (uint32_t index, std::shared_ptr &outputBuffer), ()); + MOCK_METHOD(void, DecoderDrainOutputBuffer, (uint32_t index, std::shared_ptr &outputBuffer), ()); + MOCK_METHOD(Status, SetVideoSurface, (sptr videoSurface), ()); + + MOCK_METHOD(Status, SetDecryptConfig, + (const sptr &keySessionProxy, bool svp), ()); + + MOCK_METHOD(void, OnError, (MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode), ()); + MOCK_METHOD(void, PostProcessorOnError, (int32_t errorCode), ()); + + MOCK_METHOD(sptr, GetInputBufferQueue, (), ()); + MOCK_METHOD(void, SetSyncCenter, (std::shared_ptr syncCenter), ()); + MOCK_METHOD(void, SetSeekTime, (int64_t seekTimeUs), ()); + MOCK_METHOD(void, ResetSeekInfo, (), ()); + MOCK_METHOD(Status, HandleInputBuffer, (), ()); + MOCK_METHOD(void, OnDumpInfo, (int32_t fd), ()); + + MOCK_METHOD(void, SetCallingInfo, + (int32_t appUid, int32_t appPid, std::string bundleName, uint64_t instanceId), ()); + + MOCK_METHOD(Status, GetLagInfo, (int32_t& lagTimes, int32_t& maxLagDuration, int32_t& avgLagDuration), ()); + MOCK_METHOD(void, SetBitrateStart, (), ()); + MOCK_METHOD(void, OnOutputFormatChanged, (const MediaAVCodec::Format &format), ()); + MOCK_METHOD(Status, StartSeekContinous, (), ()); + MOCK_METHOD(Status, StopSeekContinous, (), ()); + MOCK_METHOD(void, RegisterVideoFrameReadyCallback, (std::shared_ptr &callback), ()); + MOCK_METHOD(void, DeregisterVideoFrameReadyCallback, (), ()); + MOCK_METHOD(int32_t, GetDecRateUpperLimit, (), ()); + MOCK_METHOD(bool, GetIsSupportSeekWithoutFlush, (), ()); + MOCK_METHOD(void, ConsumeVideoFrame, (uint32_t index, bool isRender, int64_t renderTimeNs), ()); + MOCK_METHOD(Status, SetSeiMessageCbStatus, (bool status, const std::vector &payloadTypes), ()); + + MOCK_METHOD(Status, InitPostProcessor, (), ()); + MOCK_METHOD(void, SetPostProcessorType, (VideoPostProcessorType type), ()); + MOCK_METHOD(Status, SetPostProcessorOn, (bool isSuperResolutionOn), ()); + MOCK_METHOD(Status, SetVideoWindowSize, (int32_t width, int32_t height), ()); + MOCK_METHOD(void, NotifyAudioComplete, (), ()); + MOCK_METHOD(Status, SetSpeed, (float speed), ()); + +protected: + MOCK_METHOD(Status, OnLinked,(StreamType inType, const std::shared_ptr &meta, + const std::shared_ptr &callback), ()); + MOCK_METHOD(Status, OnUpdated, (StreamType inType, const std::shared_ptr &meta, + const std::shared_ptr &callback), ()); + MOCK_METHOD(Status, OnUnLinked, + (StreamType inType, const std::shared_ptr& callback), ()); + +private: + MOCK_METHOD(void, RenderLoop, (), ()); + MOCK_METHOD(std::string, GetCodecName, (std::string mimeType), ()); + MOCK_METHOD(int64_t, CalculateNextRender, (uint32_t index, std::shared_ptr &outputBuffer), ()); + MOCK_METHOD(void, ParseDecodeRateLimit, (), ()); + MOCK_METHOD(void, RenderNextOutput, (uint32_t index, std::shared_ptr &outputBuffer), ()); + MOCK_METHOD(Status, ReleaseOutputBuffer, + (int index, bool render, const std::shared_ptr &outBuffer, int64_t renderTime), ()); + MOCK_METHOD(void, DoReleaseOutputBuffer, (uint32_t index, bool render, int64_t pts), ()); + MOCK_METHOD(void, DoRenderOutputBufferAtTime, (uint32_t index, int64_t renderTime, int64_t pts), ()); + MOCK_METHOD(bool, AcquireNextRenderBuffer, + (bool byIdx, uint32_t &index, std::shared_ptr &outBuffer, int64_t renderTime), ()); + MOCK_METHOD(bool, DrainSeekContinuous, (uint32_t index, std::shared_ptr &outputBuffer), ()); + MOCK_METHOD(bool, DrainPreroll, (uint32_t index, std::shared_ptr &outputBuffer), ()); + MOCK_METHOD(bool, DrainSeekClosest, (uint32_t index, std::shared_ptr &outputBuffer), ()); + MOCK_METHOD(void, HandleFirstOutput, (), ()); + MOCK_METHOD(void, HandleEosOutput, (int index), ()); + MOCK_METHOD(void, ReportEosEvent, (), ()); + MOCK_METHOD(void, RenderAtTimeDfx, (int64_t renderTimeNs, int64_t currentTimeNs, int64_t lastRenderTimeNs), ()); + MOCK_METHOD(int64_t, GetSystimeTimeNs, (), ()); + MOCK_METHOD(bool, IsPostProcessorSupported, (), ()); +}; +} // namespace Media +} // namespace OHOS +#endif // HIPLAYER_IMPL_UNIT_TEST_H \ No newline at end of file diff --git a/test/unittest/sa_media_client_unit_test/BUILD.gn b/test/unittest/sa_media_client_unit_test/BUILD.gn new file mode 100644 index 000000000..bd5740b47 --- /dev/null +++ b/test/unittest/sa_media_client_unit_test/BUILD.gn @@ -0,0 +1,135 @@ +# Copyright (C) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/multimedia/player_framework/config.gni") + +module_output_path = "player_framework/player_framework/sa_media" + +ohos_unittest("sa_media_client_unit_test") { + module_out_path = module_output_path +include_dirs = [ + "./", + "$MEDIA_PLAYER_ROOT_DIR/frameworks/js/avplayer", + "$MEDIA_PLAYER_ROOT_DIR/frameworks/js/common", + "$MEDIA_PLAYER_ROOT_DIR/frameworks/native/media_source_loading_request", + "$MEDIA_PLAYER_ROOT_DIR/interfaces/inner_api/native", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/player", + "$MEDIA_PLAYER_ROOT_DIR/services/include", + "$MEDIA_PLAYER_ROOT_DIR/services/services/avmetadatahelper/client", + "$MEDIA_PLAYER_ROOT_DIR/services/services/avmetadatahelper/ipc", + "$MEDIA_PLAYER_ROOT_DIR/services/services/common", + "$MEDIA_PLAYER_ROOT_DIR/services/services/engine_intf", + "$MEDIA_PLAYER_ROOT_DIR/services/services/media_data_source/ipc", + "$MEDIA_PLAYER_ROOT_DIR/services/services/media_source/ipc", + "$MEDIA_PLAYER_ROOT_DIR/services/services/monitor/client", + "$MEDIA_PLAYER_ROOT_DIR/services/services/monitor/ipc", + "$MEDIA_PLAYER_ROOT_DIR/services/services/player/client", + "$MEDIA_PLAYER_ROOT_DIR/services/services/player/ipc", + "$MEDIA_PLAYER_ROOT_DIR/services/services/player/player_mem_manage", + "$MEDIA_PLAYER_ROOT_DIR/services/services/player/server", + "$MEDIA_PLAYER_ROOT_DIR/services/services/player/subscriber", + "$MEDIA_PLAYER_ROOT_DIR/services/services/recorder/client", + "$MEDIA_PLAYER_ROOT_DIR/services/services/recorder/ipc", + "$MEDIA_PLAYER_ROOT_DIR/services/services/recorder_profiles/client", + "$MEDIA_PLAYER_ROOT_DIR/services/services/recorder_profiles/ipc", + "$MEDIA_PLAYER_ROOT_DIR/services/services/sa_media/client", + "$MEDIA_PLAYER_ROOT_DIR/services/services/sa_media/ipc", + "$MEDIA_PLAYER_ROOT_DIR/services/services/screen_capture/client", + "$MEDIA_PLAYER_ROOT_DIR/services/services/screen_capture/ipc", + "$MEDIA_PLAYER_ROOT_DIR/services/services/screen_capture_monitor/client", + "$MEDIA_PLAYER_ROOT_DIR/services/services/screen_capture_monitor/ipc", + "$MEDIA_PLAYER_ROOT_DIR/services/services/transcoder/client", + "$MEDIA_PLAYER_ROOT_DIR/services/services/transcoder/ipc", + ] + + cflags = [ + "-Wall", + "-Werror", + "-Dprivate=public", + "-Dprotected=public", + ] + sanitize = { + cfi = true + cfi_cross_dso = true + } + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken_shared", + "access_token:libprivacy_sdk", + "access_token:libtokensetproc_shared", + "audio_framework:audio_client", + "av_codec:av_codec_client", + "c_utils:utils", + "hdf_core:libhdi", + "hicollie:libhicollie", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "image_framework:image_native", + "init:libbegetutil", + "ipc:ipc_single", + "media_foundation:media_foundation", + "memmgr:memmgrclient", + "napi:ace_napi", + "os_account:os_account_innerkits", + "qos_manager:concurrent_task_client", + "qos_manager:qos", + "resource_schedule_service:ressched_client", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if (player_framework_support_drm) { + external_deps += [ "drm_framework:drm_framework" ] + } + + sources = [ + "$MEDIA_PLAYER_ROOT_DIR/frameworks/native/media_source_loading_request/loading_request_impl.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/avmetadatahelper/client/avmetadatahelper_client.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/avmetadatahelper/ipc/helper_listener_stub.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/media_data_source/ipc/media_data_source_stub.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/media_source/ipc/media_source_loader_stub.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/media_source/ipc/media_source_loading_request_proxy.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/monitor/client/monitor_client.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/monitor/client/monitor_client_object.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/player/client/player_client.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/player/ipc/player_listener_stub.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/player/player_mem_manage/player_server_mem.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/recorder/client/recorder_client.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/recorder/ipc/recorder_listener_stub.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/recorder_profiles/client/recorder_profiles_client.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/sa_media/client/media_client.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/sa_media/ipc/media_listener_stub.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/screen_capture/client/screen_capture_client.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/screen_capture/client/screen_capture_controller_client.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/screen_capture/ipc/screen_capture_listener_stub.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/screen_capture_monitor/client/screen_capture_monitor_client.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/screen_capture_monitor/ipc/screen_capture_monitor_listener_stub.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/transcoder/client/transcoder_client.cpp", + "$MEDIA_PLAYER_ROOT_DIR/services/services/transcoder/ipc/transcoder_listener_stub.cpp", + "media_client_unit_test.cpp", + ] + + deps = [ + "$MEDIA_PLAYER_ROOT_DIR/interfaces/inner_api/native:media_client", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/player:media_engine_histreamer_player", + "$MEDIA_PLAYER_ROOT_DIR/services/services:media_service", + "$MEDIA_PLAYER_ROOT_DIR/services/utils:media_service_utils", + ] + + resource_config_file = + "$MEDIA_PLAYER_ROOT_DIR/test/unittest/resources/ohos_test.xml" +} diff --git a/test/unittest/sa_media_client_unit_test/media_client_unit_test.cpp b/test/unittest/sa_media_client_unit_test/media_client_unit_test.cpp new file mode 100644 index 000000000..0cf059315 --- /dev/null +++ b/test/unittest/sa_media_client_unit_test/media_client_unit_test.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "media_client_unit_test.h" +#include "avmetadatahelper_client.h" +#include "i_standard_avmetadatahelper_service.h" +#include "player_client.h" +#include "i_avmetadatahelper_service.h" +#include "i_standard_recorder_profiles_service.h" + +namespace OHOS { +namespace Media { +using namespace std; +using namespace testing::ext; + + +void MediaClientUnitTest::SetUpTestCase(void) +{ +} + +void MediaClientUnitTest::TearDownTestCase(void) +{ +} + +void MediaClientUnitTest::SetUp(void) +{ +} + +void MediaClientUnitTest::TearDown(void) +{ +} + +/** + * @tc.name : Test PlayerMemManage AVPlayerServerDied API + * @tc.number: MediaClientUnitTest_AVPlayerServerDied_test_001 + * @tc.desc : Test PlayerMemManage AVPlayerServerDied interface + */ +HWTEST_F(MediaClientUnitTest, MediaClientUnitTest_AVPlayerServerDied_test_001, TestSize.Level0) +{ + std::shared_ptr testptr = std::make_shared(); + ASSERT_NE(testptr, nullptr); + sptr ipcProxy1; + std::shared_ptr ptr1 = std::make_shared(ipcProxy1); + sptr ipcProxy; + std::shared_ptr ptr2 = std::make_shared(ipcProxy); +#define SUPPORT_PLAYER +#define SUPPORT_METADATA + testptr->playerClientList_.push_back(ptr1); + testptr->avMetadataHelperClientList_.push_back(ptr2); + testptr->AVPlayerServerDied(); + EXPECT_EQ(testptr->playerClientList_.empty(), false); +#undef SUPPORT_PLAYER +#undef SUPPORT_METADATA +} + +/** + * @tc.name : Test PlayerMemManage DoMediaServerDied API + * @tc.number: MediaClientUnitTest_DoMediaServerDied_test_001 + * @tc.desc : Test PlayerMemManage DoMediaServerDied interface + */ +HWTEST_F(MediaClientUnitTest, MediaClientUnitTest_DoMediaServerDied_test_001, TestSize.Level0) +{ +#define SUPPORT_RECORDER +#define SUPPORT_SCREEN_CAPTURE + std::shared_ptr testptr = std::make_shared(); + ASSERT_NE(testptr, nullptr); + sptr sptrTest1; + sptr sptrTest2; + sptr sptrTest3; + sptr sptrTest4; + sptr sptrTest5; + std::shared_ptr ptr1 = std::make_shared(sptrTest1); + std::shared_ptr ptr2 = std::make_shared(sptrTest2); + std::shared_ptr ptr3 = std::make_shared(sptrTest3); + std::shared_ptr ptr4 = std::make_shared(sptrTest4); + std::shared_ptr ptr5 = std::make_shared(sptrTest5); + testptr->recorderClientList_.push_back(ptr1); + testptr->recorderProfilesClientList_.push_back(ptr2); + testptr->screenCaptureClientList_.push_back(ptr3); + testptr->screenCaptureMonitorClientList_.push_back(ptr4); + testptr->screenCaptureControllerList_.push_back(ptr5); + testptr->DoMediaServerDied(); + EXPECT_EQ(testptr->playerClientList_.empty(), false); +#undef SUPPORT_RECORDER +#undef SUPPORT_SCREEN_CAPTURE +} +} // namespace Media +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/sa_media_client_unit_test/media_client_unit_test.h b/test/unittest/sa_media_client_unit_test/media_client_unit_test.h new file mode 100644 index 000000000..043f936b7 --- /dev/null +++ b/test/unittest/sa_media_client_unit_test/media_client_unit_test.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MEDIA_CLIENT_UNIT_TEST_H +#define MEDIA_CLIENT_UNIT_TEST_H + +#include "gtest/gtest.h" +#include "i_standard_media_service.h" +#include "i_standard_recorder_service.h" + +#ifdef SUPPORT_PLAYER +#undef SUPPORT_PLAYER +#endif +#ifdef SUPPORT_METADATA +#undef SUPPORT_METADATA +#endif +#ifdef SUPPORT_RECORDER +#undef SUPPORT_RECORDER +#endif +#ifdef SUPPORT_SCREEN_CAPTURE +#undef SUPPORT_SCREEN_CAPTURE +#endif +#define SUPPORT_PLAYER +#define SUPPORT_METADATA +#define SUPPORT_SCREEN_CAPTURE +#define SUPPORT_RECORDER +#include "media_client.h" +#undef SUPPORT_RECORDER +#undef SUPPORT_METADATA +#undef SUPPORT_PLAYER +#undef SUPPORT_SCREEN_CAPTURE + +namespace OHOS { +namespace Media { +class MediaClientUnitTest : public testing::Test { +public: + // SetUpTestCase: Called before all test cases + static void SetUpTestCase(void); + // TearDownTestCase: Called after all test case + static void TearDownTestCase(void); + // SetUp: Called before each test cases + void SetUp(void); + // TearDown: Called after each test cases + void TearDown(void); +}; +} // namespace Media +} // namespace OHOS +#endif // MEDIA_CLIENT_UNIT_TEST_H \ No newline at end of file -- Gitee