From 7f586946edfd2a7a86d46659c21db1158084f368 Mon Sep 17 00:00:00 2001 From: qinlong Date: Wed, 23 Nov 2022 16:24:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EUT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qinlong --- bundle.json | 1 + services/screenclient/test/unittest/BUILD.gn | 63 ++++++ .../unittest/include/screen_client_test.h | 37 ++++ .../screen_client_window_adapter_test.h | 43 +++++ .../test/unittest/src/screen_client_test.cpp | 175 +++++++++++++++++ .../src/screen_client_window_adapter_test.cpp | 182 ++++++++++++++++++ 6 files changed, 501 insertions(+) create mode 100644 services/screenclient/test/unittest/BUILD.gn create mode 100644 services/screenclient/test/unittest/include/screen_client_test.h create mode 100644 services/screenclient/test/unittest/include/screen_client_window_adapter_test.h create mode 100644 services/screenclient/test/unittest/src/screen_client_test.cpp create mode 100644 services/screenclient/test/unittest/src/screen_client_window_adapter_test.cpp diff --git a/bundle.json b/bundle.json index 7c6eeb70..34fd19f0 100644 --- a/bundle.json +++ b/bundle.json @@ -84,6 +84,7 @@ "test":[ "//foundation/distributedhardware/distributed_screen/services/screendemo:distributedScreenTest", "//foundation/distributedhardware/distributed_screen/screenhandler/test/unittest/screenhandler:DscreenHandlerTest", + "//foundation/distributedhardware/distributed_screen/services/screenclient/test/unittest:ScreenClientTest", "//foundation/distributedhardware/distributed_screen/services/screenservice/test/unittest/sinkservice/screenregionmgr:DscreenSinkServiceTest", "//foundation/distributedhardware/distributed_screen/services/screentransport/test/unittest:screen_transport_test", "//foundation/distributedhardware/distributed_screen/services/softbusadapter/test/unittest:SoftBusAdapterTest", diff --git a/services/screenclient/test/unittest/BUILD.gn b/services/screenclient/test/unittest/BUILD.gn new file mode 100644 index 00000000..909f4248 --- /dev/null +++ b/services/screenclient/test/unittest/BUILD.gn @@ -0,0 +1,63 @@ +# Copyright (c) 2022 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/distributedhardware/distributed_screen/distributedscreen.gni") + +module_out_path = "distributed_screen/screen_client_test" + +config("module_private_config") { + include_dirs = [ + "${windowmanager_path}/interfaces/innerkits/wm", + "${graphicstandard_path}/interfaces/innerkits/surface", + "${graphicstandard_path}/rosen/modules/render_service_client/core/ui", + "${fwk_common_path}/utils/include", + "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include/", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${services_path}/screenclient/include", + "${services_path}/screenclient/test/unittest/include", + ] +} + +## UnitTest screen_client_test +ohos_unittest("ScreenClientTest") { + module_out_path = module_out_path + + sources = [ + "${services_path}/screenclient/test/unittest/src/screen_client_test.cpp", + "${services_path}/screenclient/test/unittest/src/screen_client_window_adapter_test.cpp", + ] + + configs = [ ":module_private_config" ] + + deps = [ + "${common_path}:distributed_screen_utils", + "${windowmanager_path}/wm:libwm", + "//foundation/distributedhardware/distributed_screen/services/screenclient:distributed_screen_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ "input:libmmi-client" ] +} + +group("screen_client_test") { + testonly = true + deps = [ ":ScreenClientTest" ] +} diff --git a/services/screenclient/test/unittest/include/screen_client_test.h b/services/screenclient/test/unittest/include/screen_client_test.h new file mode 100644 index 00000000..465c22db --- /dev/null +++ b/services/screenclient/test/unittest/include/screen_client_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 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 OHOS_SCREEN_CLIENT_TEST_H +#define OHOS_SCREEN_CLIENT_TEST_H + +#include + +#include "dscreen_errcode.h" +#include "dscreen_log.h" +#include "screen_client.h" +#include "screen_client_window_adapter.h" + +namespace OHOS { +namespace DistributedHardware { +class ScreenClientTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/screenclient/test/unittest/include/screen_client_window_adapter_test.h b/services/screenclient/test/unittest/include/screen_client_window_adapter_test.h new file mode 100644 index 00000000..2daca48f --- /dev/null +++ b/services/screenclient/test/unittest/include/screen_client_window_adapter_test.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 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 OHOS_SCREEN_CLIENT_WINDOW_ADAPTER_TEST_H +#define OHOS_SCREEN_CLIENT_WINDOW_ADAPTER_TEST_H + +#include + +#include "rs_surface_node.h" +#include "transaction/rs_interfaces.h" +#include "window_option.h" +#include "wm_common.h" + +#include "dscreen_constants.h" +#include "dscreen_errcode.h" +#include "dscreen_hisysevent.h" +#include "dscreen_log.h" +#include "screen_client_window_adapter.h" + +namespace OHOS { +namespace DistributedHardware { +class ScreenClientWindowAdapterTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/screenclient/test/unittest/src/screen_client_test.cpp b/services/screenclient/test/unittest/src/screen_client_test.cpp new file mode 100644 index 00000000..e217187a --- /dev/null +++ b/services/screenclient/test/unittest/src/screen_client_test.cpp @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2022 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. + */ + +#define private public +#include "screen_client_test.h" +#undef private + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +void ScreenClientTest::SetUpTestCase(void) {} + +void ScreenClientTest::TearDownTestCase(void) {} + +void ScreenClientTest::SetUp() {} + +void ScreenClientTest::TearDown() {} + +/** + * @tc.name: AddWindow_001 + * @tc.desc: Verify the AddWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientTest, AddWindow_001, TestSize.Level1) +{ + std::shared_ptr windowProperty = nullptr; + int32_t actual = ScreenClient::GetInstance().AddWindow(windowProperty); + EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_ADD_WINDOW_ERROR, actual); +} + +/** + * @tc.name: AddWindow_002 + * @tc.desc: Verify the AddWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientTest, AddWindow_002, TestSize.Level1) +{ + std::shared_ptr windowProperty = std::make_shared(); + int32_t windowId = 0; + int32_t actual = ScreenClient::GetInstance().AddWindow(windowProperty); + EXPECT_EQ(windowId, actual); + ScreenClient::GetInstance().RemoveWindow(actual); +} + +/** + * @tc.name: ShowWindow_001 + * @tc.desc: Verify the ShowWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientTest, ShowWindow_001, TestSize.Level1) +{ + int32_t windowId = 0; + int32_t actual = ScreenClient::GetInstance().ShowWindow(windowId); + EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR, actual); +} + +/** + * @tc.name: ShowWindow_002 + * @tc.desc: Verify the ShowWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientTest, ShowWindow_002, TestSize.Level1) +{ + std::shared_ptr windowProperty = std::make_shared(); + int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty); + int32_t actual = ScreenClient::GetInstance().ShowWindow(windowId); + EXPECT_EQ(DH_SUCCESS, actual); + ScreenClient::GetInstance().RemoveWindow(windowId); +} + +/** + * @tc.name: MoveWindow_001 + * @tc.desc: Verify the MoveWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientTest, MoveWindow_001, TestSize.Level1) +{ + int32_t windowId = 0; + int32_t startX = 0; + int32_t startY = 0; + int32_t actual = ScreenClient::GetInstance().MoveWindow(windowId, startX, startY); + EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR, actual); +} + +/** + * @tc.name: MoveWindow_002 + * @tc.desc: Verify the MoveWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientTest, MoveWindow_002, TestSize.Level1) +{ + std::shared_ptr windowProperty = std::make_shared(); + int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty); + int32_t startX = 0; + int32_t startY = 0; + int32_t actual = ScreenClient::GetInstance().MoveWindow(windowId, startX, startY); + EXPECT_EQ(DH_SUCCESS, actual); + ScreenClient::GetInstance().RemoveWindow(windowId); +} + +/** + * @tc.name: RemoveWindow_001 + * @tc.desc: Verify the RemoveWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientTest, RemoveWindow_001, TestSize.Level1) +{ + int32_t windowId = 0; + int32_t actual = ScreenClient::GetInstance().RemoveWindow(windowId); + EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, actual); +} + +/** + * @tc.name: RemoveWindow_002 + * @tc.desc: Verify the RemoveWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientTest, RemoveWindow_002, TestSize.Level1) +{ + std::shared_ptr windowProperty = std::make_shared(); + int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty); + int32_t actual = ScreenClient::GetInstance().RemoveWindow(windowId); + EXPECT_EQ(DH_SUCCESS, actual); +} + +/** + * @tc.name: GetSurface_001 + * @tc.desc: Verify the GetSurface function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientTest, GetSurface_001, TestSize.Level1) +{ + int32_t windowId = 0; + sptr actualSurface = ScreenClient::GetInstance().GetSurface(windowId); + EXPECT_EQ(nullptr, actualSurface); +} + +/** + * @tc.name: GetSurface_002 + * @tc.desc: Verify the GetSurface function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientTest, GetSurface_002, TestSize.Level1) +{ + std::shared_ptr windowProperty = std::make_shared(); + int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty); + sptr actualSurface = ScreenClient::GetInstance().GetSurface(windowId); + EXPECT_NE(nullptr, actualSurface); + ScreenClient::GetInstance().RemoveWindow(windowId); +} +} // DistributedHardware +} // OHOS \ No newline at end of file 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 new file mode 100644 index 00000000..fb67f5a1 --- /dev/null +++ b/services/screenclient/test/unittest/src/screen_client_window_adapter_test.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2022 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. + */ + +#define private public +#include "screen_client_window_adapter_test.h" +#undef private + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +void ScreenClientWindowAdapterTest::SetUpTestCase(void) {} + +void ScreenClientWindowAdapterTest::TearDownTestCase(void) {} + +void ScreenClientWindowAdapterTest::SetUp() {} + +void ScreenClientWindowAdapterTest::TearDown() {} + +/** + * @tc.name: CreateWindow_001 + * @tc.desc: Verify the CreateWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientWindowAdapterTest, CreateWindow_001, TestSize.Level1) +{ + std::shared_ptr windowProperty = nullptr; + int32_t windowId = 0; + sptr surface = nullptr; + sptr actualSurface = ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId); + EXPECT_EQ(surface, actualSurface); +} + +/** + * @tc.name: CreateWindow_002 + * @tc.desc: Verify the CreateWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientWindowAdapterTest, CreateWindow_002, TestSize.Level1) +{ + std::shared_ptr windowProperty = std::make_shared(); + int32_t windowId = 0; + sptr surface = nullptr; + sptr actualSurface = ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId); + EXPECT_NE(surface, actualSurface); + ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId); +} + +/** + * @tc.name: ShowWindow_001 + * @tc.desc: Verify the ShowWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientWindowAdapterTest, ShowWindow_001, TestSize.Level1) +{ + int32_t windowId = 0; + int32_t actual = ScreenClientWindowAdapter::GetInstance().ShowWindow(windowId); + EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR, actual); +} + +/** + * @tc.name: ShowWindow_002 + * @tc.desc: Verify the ShowWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientWindowAdapterTest, ShowWindow_002, TestSize.Level1) +{ + std::shared_ptr windowProperty = std::make_shared(); + int32_t windowId = 0; + ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId); + int32_t actual = ScreenClientWindowAdapter::GetInstance().ShowWindow(windowId); + EXPECT_EQ(DH_SUCCESS, actual); + ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId); +} + +/** + * @tc.name: HideWindow_001 + * @tc.desc: Verify the HideWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientWindowAdapterTest, HideWindow_001, TestSize.Level1) +{ + int32_t windowId = 0; + int32_t actual = ScreenClientWindowAdapter::GetInstance().HideWindow(windowId); + EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_HIDE_WINDOW_ERROR, actual); +} + +/** + * @tc.name: HideWindow_001 + * @tc.desc: Verify the HideWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientWindowAdapterTest, HideWindow_002, TestSize.Level1) +{ + std::shared_ptr windowProperty = std::make_shared(); + int32_t windowId = 0; + ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId); + int32_t actual = ScreenClientWindowAdapter::GetInstance().HideWindow(windowId); + EXPECT_EQ(DH_SUCCESS, actual); + ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId); +} + +/** + * @tc.name: MoveWindow_001 + * @tc.desc: Verify the MoveWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientWindowAdapterTest, MoveWindow_001, TestSize.Level1) +{ + int32_t windowId = 0; + int32_t startX = 0; + int32_t startY = 0; + int32_t actual = ScreenClientWindowAdapter::GetInstance().MoveWindow(windowId, startX, startY); + EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR, actual); +} + +/** + * @tc.name: MoveWindow_002 + * @tc.desc: Verify the MoveWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientWindowAdapterTest, MoveWindow_002, TestSize.Level1) +{ + std::shared_ptr windowProperty = std::make_shared(); + int32_t windowId = 0; + ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId); + int32_t startX = 0; + int32_t startY = 0; + int32_t actual = ScreenClientWindowAdapter::GetInstance().MoveWindow(windowId, startX, startY); + EXPECT_EQ(DH_SUCCESS, actual); + ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId); +} + +/** + * @tc.name: RemoveWindow_001 + * @tc.desc: Verify the RemoveWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientWindowAdapterTest, RemoveWindow_001, TestSize.Level1) +{ + int32_t windowId = 0; + int32_t actual = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId); + EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, actual); +} + +/** + * @tc.name: RemoveWindow_002 + * @tc.desc: Verify the RemoveWindow function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenClientWindowAdapterTest, RemoveWindow_002, TestSize.Level1) +{ + std::shared_ptr windowProperty = std::make_shared(); + int32_t windowId = 0; + ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId); + int32_t actual = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId); + EXPECT_EQ(DH_SUCCESS, actual); +} +} // DistributedHardware +} // OHOS \ No newline at end of file -- Gitee