diff --git a/window_scene/test/unittest/BUILD.gn b/window_scene/test/unittest/BUILD.gn index 66ba03acbe75aace59f2863c7fa5230ee463a539..335dc21fa31423923bf8b605ec8dbbd8199a8d6d 100644 --- a/window_scene/test/unittest/BUILD.gn +++ b/window_scene/test/unittest/BUILD.gn @@ -19,6 +19,7 @@ group("unittest") { testonly = true deps = [ + ":ws_distributed_client_test", ":ws_dual_display_device_policy_test", ":ws_event_stage_test", ":ws_extension_session_manager_test", @@ -289,6 +290,7 @@ ohos_unittest("ws_screen_session_manager_test") { deps = [ ":ws_unittest_common" ] external_deps = [ + "ability_runtime:runtime", "c_utils:utils", "hilog:libhilog", ] @@ -592,6 +594,19 @@ ohos_unittest("ws_session_stub_test") { ] } +ohos_unittest("ws_distributed_client_test") { + module_out_path = module_out_path + + sources = [ "distributed_client_test.cpp" ] + + deps = [ ":ws_unittest_common" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] +} + ## Build ws_unittest_common.a {{{ config("ws_unittest_common_public_config") { include_dirs = [ diff --git a/window_scene/test/unittest/distributed_client_test.cpp b/window_scene/test/unittest/distributed_client_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7628a38b7ef548358edd6ae3a0821cd071a32457 --- /dev/null +++ b/window_scene/test/unittest/distributed_client_test.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2023 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 "ability_manager_errors.h" +#include "distributed_client.h" +#include "distributed_parcel_helper.h" +#include "ipc_skeleton.h" +#include "iservice_registry.h" +#include "string_ex.h" +#include "system_ability_definition.h" +#include "window_manager_hilog.h" + +using namespace testing; +using namespace testing::ext; + +// using namespace FRAME_TRACE; +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +namespace { +const std::string UNDEFINED = "undefined"; +} + +class DistributedClientTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +private: + std::shared_ptr distributedClient_; +}; + +void DistributedClientTest::SetUpTestCase() +{ +} + +void DistributedClientTest::TearDownTestCase() +{ +} + +void DistributedClientTest::SetUp() +{ + distributedClient_ = std::make_shared(); + EXPECT_NE(nullptr, distributedClient_); +} + +void DistributedClientTest::TearDown() +{ + distributedClient_ = nullptr; +} + +namespace { +/** + * @tc.name: GetMissionInfos + * @tc.desc: GetMissionInfos test + * @tc.type: FUNC + * @tc.require: #I6JLSI + */ +HWTEST_F(DistributedClientTest, GetMissionInfos, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "DistributedClientTest GetMissionInfos start."; + const std::u16string DMS_PROXY_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken"; + MessageParcel data; + MessageParcel reply; + MessageOption option; + std::vector missionInfos; + if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) { + EXPECT_EQ(distributedClient_->GetMissionInfos("", 0, missionInfos), ERR_FLATTEN_OBJECT); + } + EXPECT_EQ(distributedClient_->GetMissionInfos("", 0, missionInfos), AAFwk::INVALID_PARAMETERS_ERR); + GTEST_LOG_(INFO) << "DistributedClientTest GetMissionInfos end."; +} +} + +/** + * @tc.name: GetRemoteMissionSnapshotInfo + * @tc.desc: GetRemoteMissionSnapshotInfo test + * @tc.type: FUNC + * @tc.require: #I6JLSI + */ +HWTEST_F(DistributedClientTest, GetRemoteMissionSnapshotInfo, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "DistributedClientTest GetRemoteMissionSnapshotInfo start."; + std::unique_ptr missionSnapshot; + EXPECT_EQ(distributedClient_->GetRemoteMissionSnapshotInfo("", 0, missionSnapshot), ERR_NULL_OBJECT); + GTEST_LOG_(INFO) << "DistributedClientTest GetRemoteMissionSnapshotInfo end."; +} + +/** + * @tc.name: SetMissionContinueState + * @tc.desc: SetMissionContinueState test + * @tc.type: FUNC + * @tc.require: #I6JLSI + */ +HWTEST_F(DistributedClientTest, SetMissionContinueState, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "DistributedClientTest SetMissionContinueState start."; + AAFwk::ContinueState state = AAFwk::ContinueState::CONTINUESTATE_ACTIVE; + EXPECT_NE(distributedClient_->SetMissionContinueState(0, state), 0); + GTEST_LOG_(INFO) << "DistributedClientTest ReadMissionInfosFromParcel end."; +} +} +} diff --git a/window_scene/test/unittest/screen_session_manager_test.cpp b/window_scene/test/unittest/screen_session_manager_test.cpp index d61797af7131799e76a635170b669a3edb4387f2..f776c861ea68496ce836fd68175f0edc53d9fba1 100644 --- a/window_scene/test/unittest/screen_session_manager_test.cpp +++ b/window_scene/test/unittest/screen_session_manager_test.cpp @@ -42,7 +42,7 @@ sptr ScreenSessionManagerTest::ssm_ = nullptr; void ScreenSessionManagerTest::SetUpTestCase() { - ssm_ = new ScreenSessionManager(); + ssm_ = &ScreenSessionManager::GetInstance(); } void ScreenSessionManagerTest::TearDownTestCase() @@ -59,23 +59,61 @@ void ScreenSessionManagerTest::TearDown() } namespace { +/** + * @tc.name: RegisterScreenConnectionListener + * @tc.desc: RegisterScreenConnectionListener test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, RegisterScreenConnectionListener, Function | SmallTest | Level3) +{ + sptr screenConnectionListener = nullptr; + ssm_->RegisterScreenConnectionListener(screenConnectionListener); + EXPECT_EQ(nullptr, screenConnectionListener); + + ssm_->UnregisterScreenConnectionListener(screenConnectionListener); + EXPECT_EQ(nullptr, screenConnectionListener); +} + /** * @tc.name: RegisterDisplayManagerAgent - * @tc.desc: ScreenSesionManager rigister display manager agent + * @tc.desc: RegisterDisplayManagerAgent test * @tc.type: FUNC */ HWTEST_F(ScreenSessionManagerTest, RegisterDisplayManagerAgent, Function | SmallTest | Level3) { sptr displayManagerAgent = new DisplayManagerAgentDefault(); - DisplayManagerAgentType type = DisplayManagerAgentType::DISPLAY_STATE_LISTENER; + DisplayManagerAgentType type = DisplayManagerAgentType::SCREEN_EVENT_LISTENER; + EXPECT_NE(DMError::DM_ERROR_NOT_SYSTEM_APP, ssm_->RegisterDisplayManagerAgent(displayManagerAgent, type)); + EXPECT_NE(DMError::DM_ERROR_NOT_SYSTEM_APP, ssm_->UnregisterDisplayManagerAgent(displayManagerAgent, type)); - ASSERT_EQ(DMError::DM_ERROR_NULLPTR, ssm_->RegisterDisplayManagerAgent(nullptr, type)); - ASSERT_EQ(DMError::DM_ERROR_NULLPTR, ssm_->UnregisterDisplayManagerAgent(nullptr, type)); + type = DisplayManagerAgentType::PRIVATE_WINDOW_LISTENER; + EXPECT_EQ(DMError::DM_ERROR_NULLPTR, ssm_->RegisterDisplayManagerAgent(nullptr, type)); + EXPECT_EQ(DMError::DM_ERROR_NULLPTR, ssm_->UnregisterDisplayManagerAgent(nullptr, type)); - ASSERT_EQ(DMError::DM_ERROR_NULLPTR, ssm_->UnregisterDisplayManagerAgent(displayManagerAgent, type)); + EXPECT_EQ(DMError::DM_OK, ssm_->RegisterDisplayManagerAgent(displayManagerAgent, type)); + EXPECT_EQ(DMError::DM_OK, ssm_->UnregisterDisplayManagerAgent(displayManagerAgent, type)); +} + +/** + * @tc.name: ScreenChange + * @tc.desc: ScreenChange test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, ScreenChange, Function | SmallTest | Level3) +{ + ScreenEvent screenEvent = ScreenEvent::CONNECTED; + ssm_->OnVirtualScreenChange(DEFAULT_SCREEN_ID, screenEvent); + ssm_->OnVirtualScreenChange(VIRTUAL_SCREEN_ID, screenEvent); + ssm_->OnScreenChange(DEFAULT_SCREEN_ID, screenEvent); + ssm_->OnScreenChange(VIRTUAL_SCREEN_ID, screenEvent); + EXPECT_TRUE(1); - ASSERT_EQ(DMError::DM_OK, ssm_->RegisterDisplayManagerAgent(displayManagerAgent, type)); - ASSERT_EQ(DMError::DM_OK, ssm_->UnregisterDisplayManagerAgent(displayManagerAgent, type)); + screenEvent = ScreenEvent::DISCONNECTED; + ssm_->OnVirtualScreenChange(DEFAULT_SCREEN_ID, screenEvent); + ssm_->OnVirtualScreenChange(VIRTUAL_SCREEN_ID, screenEvent); + ssm_->OnScreenChange(DEFAULT_SCREEN_ID, screenEvent); + ssm_->OnScreenChange(VIRTUAL_SCREEN_ID, screenEvent); + EXPECT_TRUE(1); } /** @@ -517,7 +555,7 @@ HWTEST_F(ScreenSessionManagerTest, InitAbstractScreenModesInfo, Function | Small ASSERT_TRUE(screenId != VIRTUAL_SCREEN_ID); } sptr screenSession =new (std::nothrow) ScreenSession(); - ASSERT_EQ(false, ssm_->InitAbstractScreenModesInfo(screenSession)); + ASSERT_EQ(true, ssm_->InitAbstractScreenModesInfo(screenSession)); } /**