From af60eb5909f2a099df71a48f706ec4031783f8f3 Mon Sep 17 00:00:00 2001 From: pwx1285814 Date: Wed, 19 Jun 2024 10:07:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85UT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: pwx1285814 Change-Id: I49124094fd89566650ce39bbe591ebe7bdd98636 Signed-off-by: pwx1285814 --- .../test/unittest/src/screen_common_test.cpp | 40 +++++++ .../src/dscreen_source_handler_test.cpp | 23 ++++ .../test/unittest/utils/video_param_test.cpp | 14 +++ .../src/screen_client_window_adapter_test.cpp | 39 ++++++ .../src/dscreen_sink_stub_test.cpp | 111 ++++++++++++++++++ .../1.0/src/screenregionmgr_test.cpp | 84 ++++++++++++- .../src/av_receiver_engine_adapter_test.cpp | 28 ++++- .../2.0/src/screenregion_test.cpp | 22 +++- .../1.0/src/dscreen_manager_test.cpp | 34 +++++- .../dscreenmgr/1.0/src/dscreen_test.cpp | 51 +++++++- .../2.0/src/av_sender_engine_adapter_test.cpp | 35 +++++- 11 files changed, 471 insertions(+), 10 deletions(-) diff --git a/common/test/unittest/src/screen_common_test.cpp b/common/test/unittest/src/screen_common_test.cpp index 122550e6..148274b5 100644 --- a/common/test/unittest/src/screen_common_test.cpp +++ b/common/test/unittest/src/screen_common_test.cpp @@ -16,8 +16,10 @@ #include "dscreen_errcode.h" #include "dscreen_hisysevent.h" +#include "dscreen_json_util.h" #include "dscreen_log.h" #include "dscreen_util.h" + using namespace testing::ext; namespace OHOS { @@ -103,5 +105,43 @@ HWTEST_F(ScreenCommonTest, common_004, TestSize.Level1) std::string ret = GetInterruptString(value); EXPECT_EQ("Idva", ret); } + +/** + * @tc.name: IsInt64_001 + * @tc.desc: Verify the IsInt64 function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenCommonTest, IsInt64_001, TestSize.Level1) +{ + nlohmann::json testJson; + std::string key = "test"; + EXPECT_FALSE(IsInt64(testJson, key)); + + testJson[key] = "test"; + EXPECT_FALSE(IsInt64(testJson, key)); + + testJson[key] = 1; + EXPECT_TRUE(IsInt64(testJson, key)); +} + +/** + * @tc.name: IsArray_001 + * @tc.desc: Verify the IsArray function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenCommonTest, IsArray_001, TestSize.Level1) +{ + nlohmann::json testJson; + std::string key = "test"; + EXPECT_FALSE(IsArray(testJson, key)); + + testJson[key] = "test"; + EXPECT_FALSE(IsArray(testJson, key)); + + testJson[key] = {1, 2, 3}; + EXPECT_TRUE(IsArray(testJson, key)); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp index 38400d68..311fe29f 100644 --- a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp +++ b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp @@ -146,6 +146,10 @@ HWTEST_F(DScreenSourceHandlerTest, RegisterDistributedHardware_004, TestSize.Lev std::shared_ptr callback = std::make_shared(); int32_t ret = DScreenSourceHandler::GetInstance().RegisterDistributedHardware(devId, dhId, param, callback); EXPECT_EQ(ERR_DH_SCREEN_STRING_PARAM_EMPTY, ret); + + const std::string dhId1 = "test"; + ret = DScreenSourceHandler::GetInstance().RegisterDistributedHardware(dhId1, dhId, param, callback); + EXPECT_EQ(ERR_DH_SCREEN_STRING_PARAM_EMPTY, ret); } /** @@ -221,6 +225,10 @@ HWTEST_F(DScreenSourceHandlerTest, UnregisterDistributedHardware_002, TestSize.L std::shared_ptr callback = std::make_shared(); int32_t ret = DScreenSourceHandler::GetInstance().UnregisterDistributedHardware(devId, dhId, callback); EXPECT_EQ(ERR_DH_SCREEN_STRING_PARAM_EMPTY, ret); + + const std::string dhId1 = "test"; + ret = DScreenSourceHandler::GetInstance().UnregisterDistributedHardware(dhId1, dhId, callback); + EXPECT_EQ(ERR_DH_SCREEN_STRING_PARAM_EMPTY, ret); } /** @@ -340,5 +348,20 @@ HWTEST_F(DScreenSourceHandlerTest, OnRemoteDied_001, TestSize.Level1) DScreenSourceHandler::GetInstance().sourceSvrRecipient_->OnRemoteDied(remote); EXPECT_EQ(nullptr, DScreenSourceHandler::GetInstance().dScreenSourceProxy_); } + +/** + * @tc.name: OnRemoteDied_002 + * @tc.desc: Verify the OnRemoteDied function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenSourceHandlerTest, OnRemoteDied_002, TestSize.Level1) +{ + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr remoteObject = nullptr; + wptr remote(remoteObject); + DScreenSourceHandler::GetInstance().sourceSvrRecipient_->OnRemoteDied(remote); + EXPECT_EQ(remote, remote); +} } } \ No newline at end of file diff --git a/services/common/test/unittest/utils/video_param_test.cpp b/services/common/test/unittest/utils/video_param_test.cpp index 0aa27050..74625954 100644 --- a/services/common/test/unittest/utils/video_param_test.cpp +++ b/services/common/test/unittest/utils/video_param_test.cpp @@ -75,6 +75,20 @@ HWTEST_F(VideoParamTest, GetVideoWidth_001, TestSize.Level1) EXPECT_EQ(videoWidth, actual); } +/** + * @tc.name: SetPartialRefreshFlag_001 + * @tc.desc: Verify the SetPartialRefreshFlag function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(VideoParamTest, SetPartialRefreshFlag_001, TestSize.Level1) +{ + std::shared_ptr videoParam = std::make_shared(); + videoParam->isPartialRefresh_ = false; + videoParam->SetPartialRefreshFlag(true); + EXPECT_TRUE(videoParam->isPartialRefresh_); +} + /** * @tc.name: GetVideoHeight_001 * @tc.desc: Verify the GetVideoHeight function. diff --git a/services/screenclient/test/unittest/src/screen_client_window_adapter_test.cpp b/services/screenclient/test/unittest/src/screen_client_window_adapter_test.cpp index 0c09a7cd..1f24b82e 100644 --- a/services/screenclient/test/unittest/src/screen_client_window_adapter_test.cpp +++ b/services/screenclient/test/unittest/src/screen_client_window_adapter_test.cpp @@ -242,5 +242,44 @@ HWTEST_F(ScreenClientWindowAdapterTest, DestroyAllWindow_001, TestSize.Level1) int32_t ret = ScreenClientWindowAdapter::GetInstance().DestroyAllWindow(); EXPECT_EQ(DH_SUCCESS, ret); } + +/** + * @tc.name: ScreenClientInputEventListener_OnInputEvent_001 + * @tc.desc: Verify the OnInputEvent function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientWindowAdapterTest, ScreenClientInputEventListener_OnInputEvent_001, TestSize.Level1) +{ + std::shared_ptr pointerEvent = nullptr; + std::shared_ptr listener = std::make_shared(); + EXPECT_FALSE(listener->OnInputEvent(pointerEvent)); +} + +/** + * @tc.name: ScreenClientInputEventListener_OnInputEvent_002 + * @tc.desc: Verify the OnInputEvent function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientWindowAdapterTest, ScreenClientInputEventListener_OnInputEvent_002, TestSize.Level1) +{ + std::shared_ptr keyEvent = nullptr; + std::shared_ptr listener = std::make_shared(); + EXPECT_FALSE(listener->OnInputEvent(keyEvent)); +} + +/** + * @tc.name: ScreenClientInputEventListener_OnInputEvent_003 + * @tc.desc: Verify the OnInputEvent function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientWindowAdapterTest, ScreenClientInputEventListener_OnInputEvent_003, TestSize.Level1) +{ + std::shared_ptr axisEvent = nullptr; + std::shared_ptr listener = std::make_shared(); + EXPECT_FALSE(listener->OnInputEvent(axisEvent)); +} } // DistributedHardware } // OHOS \ No newline at end of file diff --git a/services/screenservice/test/unittest/sinkservice/dscreenservice/src/dscreen_sink_stub_test.cpp b/services/screenservice/test/unittest/sinkservice/dscreenservice/src/dscreen_sink_stub_test.cpp index dd4bdb5a..5cdd6df0 100644 --- a/services/screenservice/test/unittest/sinkservice/dscreenservice/src/dscreen_sink_stub_test.cpp +++ b/services/screenservice/test/unittest/sinkservice/dscreenservice/src/dscreen_sink_stub_test.cpp @@ -16,6 +16,7 @@ #include "dscreen_sink_stub_test.h" #include +#include "dscreen_constants.h" using namespace testing; using namespace testing::ext; @@ -183,5 +184,115 @@ HWTEST_F(DScreenSinkStubTest, DScreenNotify_001, TestSize.Level1) EXPECT_EQ(eventCode, ((sptr &)sinkStubPtr)->eventCode_); EXPECT_STREQ(eventContent.c_str(), ((sptr &)sinkStubPtr)->eventContent_.c_str()); } + +/** + * @tc.name: DScreenNotifyInner_001 + * @tc.desc: Verify the DScreenNotifyInner function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenSinkStubTest, DScreenNotifyInner_001, TestSize.Level1) +{ + sptr sinkStub = new TestDScreenSinkStub(); + MessageParcel data; + MessageParcel reply; + MessageOption option; + std::string devId = ""; + int32_t eventCode = -1; + std::string eventContent = ""; + data.WriteString(devId); + data.WriteInt32(eventCode); + data.WriteString(eventContent); + int32_t ret = sinkStub->DScreenNotifyInner(data, reply, option); + EXPECT_EQ(ret, ERR_DH_SCREEN_INPUT_PARAM_INVALID); +} + +/** + * @tc.name: DScreenNotifyInner_002 + * @tc.desc: Verify the DScreenNotifyInner function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenSinkStubTest, DScreenNotifyInner_002, TestSize.Level1) +{ + sptr sinkStub = new TestDScreenSinkStub(); + MessageParcel data; + MessageParcel reply; + MessageOption option; + std::string exceedDidMaxSizeStr(DID_MAX_SIZE + 1, 'a'); + int32_t eventCode = -1; + std::string eventContent = ""; + data.WriteString(exceedDidMaxSizeStr); + data.WriteInt32(eventCode); + data.WriteString(eventContent); + int32_t ret = sinkStub->DScreenNotifyInner(data, reply, option); + EXPECT_EQ(ret, ERR_DH_SCREEN_INPUT_PARAM_INVALID); +} + +/** + * @tc.name: DScreenNotifyInner_003 + * @tc.desc: Verify the DScreenNotifyInner function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenSinkStubTest, DScreenNotifyInner_003, TestSize.Level1) +{ + sptr sinkStub = new TestDScreenSinkStub(); + MessageParcel data; + MessageParcel reply; + MessageOption option; + std::string devId = "test"; + int32_t eventCode = -1; + std::string eventContent = ""; + data.WriteString(devId); + data.WriteInt32(eventCode); + data.WriteString(eventContent); + int32_t ret = sinkStub->DScreenNotifyInner(data, reply, option); + EXPECT_EQ(ret, ERR_DH_SCREEN_INPUT_PARAM_INVALID); +} + +/** + * @tc.name: DScreenNotifyInner_004 + * @tc.desc: Verify the DScreenNotifyInner function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenSinkStubTest, DScreenNotifyInner_004, TestSize.Level1) +{ + sptr sinkStub = new TestDScreenSinkStub(); + MessageParcel data; + MessageParcel reply; + MessageOption option; + std::string devId = "test"; + int32_t eventCode = -1; + std::string exceedParamMaxSizeStr(PARAM_MAX_SIZE + 1, 'a'); + data.WriteString(devId); + data.WriteInt32(eventCode); + data.WriteString(exceedParamMaxSizeStr); + int32_t ret = sinkStub->DScreenNotifyInner(data, reply, option); + EXPECT_EQ(ret, ERR_DH_SCREEN_INPUT_PARAM_INVALID); +} + +/** + * @tc.name: DScreenNotifyInner_005 + * @tc.desc: Verify the DScreenNotifyInner function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenSinkStubTest, DScreenNotifyInner_005, TestSize.Level1) +{ + sptr sinkStub = new TestDScreenSinkStub(); + MessageParcel data; + MessageParcel reply; + MessageOption option; + std::string devId = "test"; + int32_t eventCode = -1; + std::string eventContent = "test"; + data.WriteString(devId); + data.WriteInt32(eventCode); + data.WriteString(eventContent); + int32_t ret = sinkStub->DScreenNotifyInner(data, reply, option); + EXPECT_EQ(ret, DH_SUCCESS); +} } } \ No newline at end of file diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregionmgr_test.cpp b/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregionmgr_test.cpp index 40ae7720..3620f267 100644 --- a/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregionmgr_test.cpp +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregionmgr_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -186,6 +186,26 @@ HWTEST_F(ScreenRegionManagerTestV1, HandleNotifySetUp_003, TestSize.Level1) EXPECT_EQ(0, ScreenRegionManager::GetInstance().screenRegions_.size()); } +/** + * @tc.name: HandleNotifySetUp_004 + * @tc.desc: Verify the HandleNotifySetUp function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionManagerTestV1, HandleNotifySetUp_004, TestSize.Level1) +{ + ScreenRegionManager::GetInstance().screenRegions_.clear(); + const std::string remoteDevId = "sourceDevId"; + const std::string eventContent = "{\"dhId\":\"SCREEN#0\", \"mapRelation\":{\"displayId\":0, \ + \"displayRect\":{\"height\":1280, \"startX\":0, \"startY\":0, \"width\":720}, \"screenId\":2, \ + \"screenRect\":{\"height\":1280, \"startX\":0, \"startY\":0, \"width\":720}}, \"screenId\":2, \ + \"videoParam\":{\"codecType\":2, \"colorFormat\":3, \"fps\":30, \"screenHeight\":1280, \ + \"screenWidths\":720, \"videoHeights\":1280, \"videoWidths\":720}, \"screenVersion\":\"1.0\"}"; + ScreenRegionManager::GetInstance().HandleNotifySetUp(remoteDevId, eventContent); + + EXPECT_NE(0, ScreenRegionManager::GetInstance().screenRegions_.size()); + ScreenRegionManager::GetInstance().screenRegions_.clear(); +} /** * @tc.name: GetDScreenSourceSA_001 @@ -200,6 +220,68 @@ HWTEST_F(ScreenRegionManagerTestV1, GetDScreenSourceSA_001, TestSize.Level1) EXPECT_EQ(nullptr, ret); } + +/** + * @tc.name: CheckContentJson_001 + * @tc.desc: Verify the CheckContentJson function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionManagerTestV1, CheckContentJson_001, TestSize.Level1) +{ + nlohmann::json testJson; + testJson[KEY_SCREEN_ID] = "test"; + EXPECT_FALSE(ScreenRegionManager::GetInstance().CheckContentJson(testJson)); +} + +/** + * @tc.name: CheckContentJson_002 + * @tc.desc: Verify the CheckContentJson function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionManagerTestV1, CheckContentJson_002, TestSize.Level1) +{ + nlohmann::json testJson; + uint64_t screenId = 0; + testJson[KEY_SCREEN_ID] = screenId; + testJson[KEY_DH_ID] = screenId; + EXPECT_FALSE(ScreenRegionManager::GetInstance().CheckContentJson(testJson)); +} + +/** + * @tc.name: CheckContentJson_003 + * @tc.desc: Verify the CheckContentJson function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionManagerTestV1, CheckContentJson_003, TestSize.Level1) +{ + nlohmann::json testJson; + uint64_t screenId = 0; + testJson[KEY_SCREEN_ID] = screenId; + testJson[KEY_DH_ID] = "test"; + EXPECT_TRUE(ScreenRegionManager::GetInstance().CheckContentJson(testJson)); + + testJson[KEY_VERSION] = screenId; + EXPECT_FALSE(ScreenRegionManager::GetInstance().CheckContentJson(testJson)); +} + +/** + * @tc.name: CheckContentJson_004 + * @tc.desc: Verify the CheckContentJson function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionManagerTestV1, CheckContentJson_004, TestSize.Level1) +{ + nlohmann::json testJson; + uint64_t screenId = 0; + testJson[KEY_SCREEN_ID] = screenId; + testJson[KEY_DH_ID] = "test"; + testJson[KEY_VERSION] = "test"; + EXPECT_TRUE(ScreenRegionManager::GetInstance().CheckContentJson(testJson)); +} } } } \ No newline at end of file diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/av_receiver_engine_adapter_test.cpp b/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/av_receiver_engine_adapter_test.cpp index d1bd7fdb..cd82bd6d 100644 --- a/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/av_receiver_engine_adapter_test.cpp +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/av_receiver_engine_adapter_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 @@ -158,5 +158,31 @@ HWTEST_F(AVReceiverEngineAdapterTest, OnReceiverEvent_001, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, receiverAdapter_->OnDataAvailable(buffer)); EXPECT_EQ(DH_SUCCESS, receiverAdapter_->Release()); } + +/** + * @tc.name: OnReceiverEvent_002 + * @tc.desc: Verify the Start and OnReceiverEvent function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(AVReceiverEngineAdapterTest, OnReceiverEvent_002, TestSize.Level1) +{ + AVTransEvent event; + event.type = EventType::EVENT_START_SUCCESS; + receiverAdapter_->adapterCallback_ = std::make_shared(); + EXPECT_EQ(DH_AVT_SUCCESS, receiverAdapter_->OnReceiverEvent(event)); + + event.type = EventType::EVENT_CHANNEL_CLOSED; + EXPECT_EQ(DH_AVT_SUCCESS, receiverAdapter_->OnReceiverEvent(event)); + + event.type = EventType::EVENT_ENGINE_ERROR; + EXPECT_EQ(DH_AVT_SUCCESS, receiverAdapter_->OnReceiverEvent(event)); + + event.type = EventType::EVENT_REMOTE_ERROR; + EXPECT_EQ(DH_AVT_SUCCESS, receiverAdapter_->OnReceiverEvent(event)); + + event.type = EventType::EVENT_CHANNEL_OPENED; + EXPECT_EQ(DH_AVT_SUCCESS, receiverAdapter_->OnReceiverEvent(event)); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/screenregion_test.cpp b/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/screenregion_test.cpp index 65bb31ad..b63b7f1c 100644 --- a/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/screenregion_test.cpp +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/screenregion_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -59,7 +59,8 @@ HWTEST_F(ScreenRegionTestV2, OnEngineEvent_001, TestSize.Level1) */ HWTEST_F(ScreenRegionTestV2, OnEngineMessage_001, TestSize.Level1) { - std::shared_ptr message = std::make_shared(); + screenRegion_->OnEngineMessage(nullptr); + std::shared_ptr message = std::make_shared(); message->type_ = DScreenMsgType::START_MIRROR; message->content_ = "invaild_json_string"; screenRegion_->receiverAdapter_ = std::make_shared(); @@ -333,6 +334,23 @@ HWTEST_F(ScreenRegionTestV2, ConfigWindow_002, TestSize.Level1) ScreenClient::GetInstance().AddWindow(windowProperty); EXPECT_EQ(DH_SUCCESS, screenRegion_->ConfigWindow()); } + +/** + * @tc.name: CheckContentJson_001 + * @tc.desc: Verify the CheckContentJson function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionTestV2, CheckContentJson_001, TestSize.Level1) +{ + nlohmann::json testJson; + testJson[KEY_SCREEN_ID] = "test"; + EXPECT_FALSE(screenRegion_->CheckContentJson(testJson)); + + uint64_t screenId = 0; + testJson[KEY_SCREEN_ID] = screenId; + EXPECT_TRUE(screenRegion_->CheckContentJson(testJson)); +} } // namespace V2_0 } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/dscreen_manager_test.cpp b/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/dscreen_manager_test.cpp index 7288cd7a..274e2d91 100644 --- a/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/dscreen_manager_test.cpp +++ b/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/dscreen_manager_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -193,6 +193,36 @@ HWTEST_F(DScreenManagerTestV1, EnableDistributedScreen_001, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, ret); } +/** + * @tc.name: EnableDistributedScreen_002 + * @tc.desc: Verify the EnableDistributedScreen function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenManagerTestV1, EnableDistributedScreen_002, TestSize.Level1) +{ + std::string devId = "test"; + std::string dhId = ""; + EnableParam param; + param.sinkVersion = ""; + param.sinkAttrs = ""; + std::string reqId = ""; + int32_t ret = DScreenManager::GetInstance().EnableDistributedScreen(devId, dhId, param, reqId); + EXPECT_EQ(ERR_DH_SCREEN_SA_ENABLE_FAILED, ret); + + dhId = "test"; + ret = DScreenManager::GetInstance().EnableDistributedScreen(devId, dhId, param, reqId); + EXPECT_EQ(ERR_DH_SCREEN_SA_ENABLE_FAILED, ret); + + param.sinkVersion = "test"; + ret = DScreenManager::GetInstance().EnableDistributedScreen(devId, dhId, param, reqId); + EXPECT_EQ(ERR_DH_SCREEN_SA_ENABLE_FAILED, ret); + + param.sinkAttrs = "test"; + ret = DScreenManager::GetInstance().EnableDistributedScreen(devId, dhId, param, reqId); + EXPECT_EQ(ERR_DH_SCREEN_SA_ENABLE_FAILED, ret); +} + /** * @tc.name: FindDScreenByScreenId_001 * @tc.desc: Verify the FindDScreenByScreenId function failed. @@ -262,6 +292,8 @@ HWTEST_F(DScreenManagerTestV1, NotifyRemoteScreenService_001, TestSize.Level1) HWTEST_F(DScreenManagerTestV1, PublishMessage_001, TestSize.Level1) { std::shared_ptr dScreenCallback = std::make_shared(); + dScreenCallback->OnRegResult(nullptr, "", 0, ""); + dScreenCallback->OnUnregResult(nullptr, "", 0, ""); std::shared_ptr dScreen = std::make_shared("devId000", "dhId000", dScreenCallback); DScreenManager::GetInstance().PublishMessage(DHTopic::TOPIC_START_DSCREEN, dScreen); diff --git a/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/dscreen_test.cpp b/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/dscreen_test.cpp index bc5b6873..6189db86 100644 --- a/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/dscreen_test.cpp +++ b/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/dscreen_test.cpp @@ -234,6 +234,41 @@ HWTEST_F(DScreenTestV1, HandleEnable_005, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, ret); } +/** + * @tc.name: HandleEnable_006 + * @tc.desc: Verify the HandleEnable function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenTestV1, HandleEnable_006, TestSize.Level1) +{ + std::string reqId = "reqId"; + std::string attrs = "attrs"; + std::shared_ptr task = std::make_shared(TaskType::TASK_DISCONNECT, reqId, attrs); + dScreen_->curState_ = ENABLING; + dScreen_->videoParam_ = nullptr; + std::string param = "{\"codecType\":\"OMX_rk_video_encoder_avc\", \ + \"screenHeight\":1280, \"screenVersion\":\"1.0\", \"screenWidth\":720}"; + std::string taskId = "taskId"; + dScreen_->HandleEnable(param, taskId); + + dScreen_->curState_ = CONNECTING; + dScreen_->HandleEnable(param, taskId); + + dScreen_->curState_ = CONNECTED; + dScreen_->HandleEnable(param, taskId); + + dScreen_->curState_ = DISABLED; + dScreen_->videoParam_ = nullptr; + dScreen_->HandleEnable(param, taskId); + + dScreen_->dscreenCallback_ = nullptr; + dScreen_->HandleEnable(param, taskId); + + int32_t ret = dScreen_->AddTask(task); + EXPECT_EQ(DH_SUCCESS, ret); +} + /** * @tc.name: CheckJsonData_001 * @tc.desc: Verify the CheckJsonData function failed. @@ -242,8 +277,6 @@ HWTEST_F(DScreenTestV1, HandleEnable_005, TestSize.Level1) */ HWTEST_F(DScreenTestV1, CheckJsonData_001, TestSize.Level1) { - json attrJson; - std::string taskId = "taskId"; dScreen_->dscreenCallback_ = nullptr; dScreen_->HandleDisable(taskId); @@ -251,8 +284,16 @@ HWTEST_F(DScreenTestV1, CheckJsonData_001, TestSize.Level1) dScreen_->curState_ = CONNECTED; dScreen_->HandleDisconnect(); + json attrJson; + attrJson[KEY_SCREEN_WIDTH] = "test"; int32_t ret = dScreen_->CheckJsonData(attrJson); EXPECT_EQ(ERR_DH_SCREEN_SA_ENABLE_JSON_ERROR, ret); + + uint32_t data = 0; + attrJson[KEY_SCREEN_WIDTH] = data; + attrJson[KEY_SCREEN_HEIGHT] = "test"; + ret = dScreen_->CheckJsonData(attrJson); + EXPECT_EQ(ERR_DH_SCREEN_SA_ENABLE_JSON_ERROR, ret); } /** @@ -263,14 +304,16 @@ HWTEST_F(DScreenTestV1, CheckJsonData_001, TestSize.Level1) */ HWTEST_F(DScreenTestV1, CheckJsonData_002, TestSize.Level1) { - json attrJson; - attrJson["dhid"] = "dhid"; std::string taskId = "taskId"; dScreen_->screenId_ = 100; dScreen_->HandleDisable(taskId); dScreen_->curState_ = DISABLED; dScreen_->HandleDisconnect(); + json attrJson; + uint32_t data = 0; + attrJson[KEY_SCREEN_WIDTH] = data; + attrJson[KEY_SCREEN_HEIGHT] = data; int32_t ret = dScreen_->CheckJsonData(attrJson); EXPECT_EQ(ERR_DH_SCREEN_SA_ENABLE_JSON_ERROR, ret); } diff --git a/services/screenservice/test/unittest/sourceservice/dscreenmgr/2.0/src/av_sender_engine_adapter_test.cpp b/services/screenservice/test/unittest/sourceservice/dscreenmgr/2.0/src/av_sender_engine_adapter_test.cpp index f63f767e..4b95ed3b 100644 --- a/services/screenservice/test/unittest/sourceservice/dscreenmgr/2.0/src/av_sender_engine_adapter_test.cpp +++ b/services/screenservice/test/unittest/sourceservice/dscreenmgr/2.0/src/av_sender_engine_adapter_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -201,5 +201,38 @@ HWTEST_F(AVSenderEngineAdapterTest, OnSenderEvent_001, TestSize.Level1) EXPECT_EQ(DH_AVT_SUCCESS, senderAdapter_->OnSenderEvent(event)); EXPECT_EQ(DH_AVT_SUCCESS, senderAdapter_->OnMessageReceived(message)); } + +/** + * @tc.name: OnSenderEvent_002 + * @tc.desc: Verify the OnSenderEvent function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(AVSenderEngineAdapterTest, OnSenderEvent_002, TestSize.Level1) +{ + AVTransEvent event; + event.type = EventType::EVENT_CHANNEL_CLOSED; + senderAdapter_->adapterCallback_ = std::make_shared(); + EXPECT_EQ(DH_AVT_SUCCESS, senderAdapter_->OnSenderEvent(event)); + + event.type = EventType::EVENT_START_SUCCESS; + EXPECT_EQ(DH_AVT_SUCCESS, senderAdapter_->OnSenderEvent(event)); + + event.type = EventType::EVENT_REMOTE_ERROR; + EXPECT_EQ(DH_AVT_SUCCESS, senderAdapter_->OnSenderEvent(event)); + + event.type = EventType::EVENT_REMOVE_STREAM; + EXPECT_EQ(DH_AVT_SUCCESS, senderAdapter_->OnSenderEvent(event)); + + senderAdapter_->adapterCallback_ = nullptr; + event.type = EventType::EVENT_CHANNEL_CLOSED; + EXPECT_EQ(DH_AVT_SUCCESS, senderAdapter_->OnSenderEvent(event)); + + event.type = EventType::EVENT_START_SUCCESS; + EXPECT_EQ(DH_AVT_SUCCESS, senderAdapter_->OnSenderEvent(event)); + + event.type = EventType::EVENT_REMOTE_ERROR; + EXPECT_EQ(DH_AVT_SUCCESS, senderAdapter_->OnSenderEvent(event)); +} } // namespace DistributedHardware } // namespace OHOS -- Gitee