diff --git a/test/BUILD.gn b/test/BUILD.gn index 127f7b8d0c046255bd6fe82c56bd1963beddcd06..19bdcb7b8b8d5a3779d63c4ce14267b9db0fa396 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -24,6 +24,7 @@ group("media_unit_test") { "../frameworks/native/recorder/test/unittest:recorder_unit_test", "../frameworks/native/recorder_profiles/test/unittest:recorder_profiles_unit_test", "unittest/audio_haptic_test:audio_haptic_unit_test", + "unittest/dfx_test:player_framework_dfx_test", "unittest/observer_test:incallobserver_unit_test", "unittest/screen_capture_test:screen_capture_capi_unit_test", "unittest/screen_capture_test:screen_capture_native_unit_test", diff --git a/test/unittest/dfx_test/BUILD.gn b/test/unittest/dfx_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8d5b849814935acd8f47f7ddaa8072f42996e734 --- /dev/null +++ b/test/unittest/dfx_test/BUILD.gn @@ -0,0 +1,33 @@ +# 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") + +ohos_unittest("player_framework_dfx_test") { + module_out_path = "player_framework/media_dfx" + + include_dirs = [ "$MEDIA_PLAYER_ROOT_DIR/services/utils/include" ] + + sources = [ "media_dfx_test.cpp" ] + + deps = [ "$MEDIA_PLAYER_ROOT_DIR/services/utils:media_service_utils" ] + + external_deps = [ + "c_utils:utils", + "media_foundation:media_foundation", + ] + + subsystem_name = "multimedia" + part_name = "player_framework" +} diff --git a/test/unittest/dfx_test/media_dfx_test.cpp b/test/unittest/dfx_test/media_dfx_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ecd03e7e67731ed611950b5f8e52da7865a4a70e --- /dev/null +++ b/test/unittest/dfx_test/media_dfx_test.cpp @@ -0,0 +1,128 @@ +/* + * 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. + */ + +#include +#include +#include "gtest/gtest.h" +#include "media_dfx.h" +#include "common/media_core.h" +#include "meta/meta.h" + +using namespace testing::ext; +using namespace OHOS::Media; + +namespace { + constexpr uint32_t TEST_UID_ID_1 = 1; + constexpr int32_t ERROR_CODE = 5; +} + +namespace OHOS { +namespace Media { +class MediaDfxTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase(void) {}; + void SetUp(void) {}; + void TearDown(void) {}; +}; + +HWTEST_F(MediaDfxTest, CREATE_MEDIA_INFO, TestSize.Level1) +{ + uint64_t instanceId = 1; + int32_t ret = CreateMediaInfo(CallType::AVPLAYER, TEST_UID_ID_1, instanceId); + ASSERT_EQ(ret, MSERR_OK); + + std::shared_ptr meta = std::make_shared(); + meta->SetData(Tag::SCREEN_CAPTURE_ERR_MSG, "SCREEN_CAPTURE_ERR_MSG"); + meta->SetData(Tag::SCREEN_CAPTURE_ERR_CODE, ERROR_CODE); + ret = AppendMediaInfo(meta, instanceId); + ASSERT_EQ(ret, MSERR_OK); + + ret = ReportMediaInfo(instanceId); + ASSERT_EQ(ret, MSERR_OK); +} + +HWTEST_F(MediaDfxTest, CREATE_MEDIA_INFO_1, TestSize.Level1) +{ + uint64_t instanceId = 1; + int32_t ret = CreateMediaInfo(CallType::AVPLAYER, TEST_UID_ID_1, instanceId); + ASSERT_EQ(ret, MSERR_OK); + + std::shared_ptr meta = std::make_shared(); + meta->SetData(Tag::SCREEN_CAPTURE_ERR_MSG, "SCREEN_CAPTURE_ERR_MSG"); + meta->SetData(Tag::SCREEN_CAPTURE_ERR_CODE, ERROR_CODE); + ret = AppendMediaInfo(meta, instanceId); + ASSERT_EQ(ret, MSERR_OK); + + std::shared_ptr meta1 = std::make_shared(); + ret = AppendMediaInfo(meta1, instanceId); + ASSERT_NE(ret, MSERR_OK); + ASSERT_EQ(ret, MSERR_INVALID_OPERATION); + + ret = ReportMediaInfo(instanceId); + ASSERT_EQ(ret, MSERR_OK); +} + +HWTEST_F(MediaDfxTest, CREATE_MEDIA_INFO_2, TestSize.Level1) +{ + uint64_t instanceId = 1; + int32_t ret = CreateMediaInfo(CallType::AVPLAYER, TEST_UID_ID_1, instanceId); + ASSERT_EQ(ret, MSERR_OK); + + std::shared_ptr meta = std::make_shared(); + meta->SetData(Tag::SCREEN_CAPTURE_ERR_MSG, "SCREEN_CAPTURE_ERR_MSG"); + meta->SetData(Tag::SCREEN_CAPTURE_ERR_CODE, ERROR_CODE); + ret = AppendMediaInfo(meta, instanceId); + ASSERT_EQ(ret, MSERR_OK); + + ret = ReportMediaInfo(instanceId); + ASSERT_EQ(ret, MSERR_OK); + ret = ReportMediaInfo(instanceId); + ASSERT_NE(ret, MSERR_OK); + ASSERT_EQ(ret, MSERR_INVALID_OPERATION); +} + +HWTEST_F(MediaDfxTest, FAULT_SOURCE_EVENT, TestSize.Level1) +{ + std::string appName = "appName"; + uint64_t instanceId = 1; + std::string callerType = "callerType"; + int8_t sourceType = 1; + std::string sourceUrl = "sourceUrl"; + std::string errorMessage = "errorMessage"; + FaultSourceEventWrite(appName, instanceId, callerType, sourceType, sourceUrl, errorMessage); +} + +HWTEST_F(MediaDfxTest, FAULT_RECORD_AUDIO_EVENT, TestSize.Level1) +{ + std::string appName = "appName"; + uint64_t instanceId = 1; + int8_t sourceType = 1; + std::string errorMessage = "errorMessage"; + FaultRecordAudioEventWrite(appName, instanceId, sourceType, errorMessage); +} + +HWTEST_F(MediaDfxTest, FAULT_SCREEN_CAPTURE_EVENT, TestSize.Level1) +{ + std::string appName = "appName"; + uint64_t instanceId = 1; + int8_t captureMode = 1; + int8_t dataMode = 1; + int32_t errorCode = 1; + std::string errorMessage = "errorMessage"; + FaultScreenCaptureEventWrite(appName, instanceId, captureMode, dataMode, errorCode, errorMessage); +} +} +} \ No newline at end of file