From f7699533fa0c1453d7d860abd4d9f0e3ccc2344d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=85=E5=87=AF?= Date: Fri, 15 Nov 2024 15:30:33 +0800 Subject: [PATCH 1/3] fix: ut coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 居凯 Change-Id: Ie40a6b769c3c94a53ef28275cff992697ad558d8 --- test/unittest/services/BUILD.gn | 1 + .../inc/keyguard_status_listener_test.h | 37 +++++++++++++ .../src/keygurad_status_listener_test.cpp | 54 +++++++++++++++++++ .../services/src/soft_bus_manager_test.cpp | 7 ++- 4 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 test/unittest/services/inc/keyguard_status_listener_test.h create mode 100644 test/unittest/services/src/keygurad_status_listener_test.cpp diff --git a/test/unittest/services/BUILD.gn b/test/unittest/services/BUILD.gn index e1f0cbb1c..2a509a5a8 100644 --- a/test/unittest/services/BUILD.gn +++ b/test/unittest/services/BUILD.gn @@ -137,6 +137,7 @@ ohos_unittest("iam_services_test") { "src/identification_impl_test.cpp", "src/identify_context_test.cpp", "src/ipc_common_test.cpp", + "src/keygurad_status_listener_test.cpp", "src/relative_timer_test.cpp", "src/resource_node_pool_test.cpp", "src/resource_node_test.cpp", diff --git a/test/unittest/services/inc/keyguard_status_listener_test.h b/test/unittest/services/inc/keyguard_status_listener_test.h new file mode 100644 index 000000000..f688ffbb5 --- /dev/null +++ b/test/unittest/services/inc/keyguard_status_listener_test.h @@ -0,0 +1,37 @@ +/* + * 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. + */ +#ifndef KEYGUARD_STATUS_LISTENER_TEST +#define KEYGUARD_STATUS_LISTENER_TEST + +#include + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +class KeyguardStatusListenerTest : public testing::Test { +public: + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp() override; + + void TearDown() override; +}; +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS + +#endif // KEYGUARD_STATUS_LISTENER_TEST \ No newline at end of file diff --git a/test/unittest/services/src/keygurad_status_listener_test.cpp b/test/unittest/services/src/keygurad_status_listener_test.cpp new file mode 100644 index 000000000..c117371fa --- /dev/null +++ b/test/unittest/services/src/keygurad_status_listener_test.cpp @@ -0,0 +1,54 @@ +/* + * 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 "keyguard_status_listener_test.h" +#include "keyguard_status_listener.h" + +#include "gtest/gtest.h" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +using namespace testing; +using namespace testing::ext; + +void KeyguardStatusListenerTest::SetUpTestCase() +{ +} + +void KeyguardStatusListenerTest::TearDownTestCase() +{ +} + +void KeyguardStatusListenerTest::SetUp() +{ +} + +void KeyguardStatusListenerTest::TearDown() +{ +} + +HWTEST_F(KeyguardStatusListenerTest, KeyguardStatusListenerTestRegisterListener, TestSize.Level0) +{ + ResultCode result = KeyguardStatusListenerManager::GetInstance().RegisterCommonEventListener(); + EXPECT_EQ(result, GENERAL_ERROR); + EXPECT_NO_THROW(KeyguardStatusListenerManager::GetInstance().RegisterKeyguardStatusSwitchCallback()); + EXPECT_NO_THROW(KeyguardStatusListenerManager::GetInstance().UnRegisterKeyguardStatusSwitchCallback()); + ResultCode result = KeyguardStatusListenerManager::GetInstance().UnRegisterCommonEventListener(); + EXPECT_EQ(result, GENERAL_ERROR); +} +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/services/src/soft_bus_manager_test.cpp b/test/unittest/services/src/soft_bus_manager_test.cpp index 69c47ef2f..78a3e9d3b 100644 --- a/test/unittest/services/src/soft_bus_manager_test.cpp +++ b/test/unittest/services/src/soft_bus_manager_test.cpp @@ -199,8 +199,13 @@ HWTEST_F(SoftBusManagerTest, SoftBusManagerTestOnShutdown_001, TestSize.Level0) { ShutdownReason reason = SHUTDOWN_REASON_UNKNOWN; EXPECT_NO_THROW(SoftBusManager::GetInstance().OnShutdown(-2, reason)); - SoftBusManager::GetInstance().ClearServerSocket(); + int32_t socketId = 100; + std::shared_ptr serverSocket = SocketFactory::CreateServerSocket(socketId); + SoftBusManager::GetInstance().AddSocket(socketId, serverSocket); + SoftBusManager::GetInstance().SetServerSocket(serverSocket); EXPECT_NO_THROW(SoftBusManager::GetInstance().OnShutdown(600, reason)); + SoftBusManager::GetInstance().ServiceSocketUnInit(); + SoftBusManager::GetInstance().DeleteSocket(socketId); } HWTEST_F(SoftBusManagerTest, SoftBusManagerTestOnServerBytes_002, TestSize.Level0) From 87d2df1ca76c0d69da0f29a2ecc9c37d3fffe4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=85=E5=87=AF?= Date: Fri, 15 Nov 2024 15:34:43 +0800 Subject: [PATCH 2/3] fix: ut coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 居凯 Change-Id: I028b2756e26795f5b76d5085b7cf9885ae66e889 --- test/unittest/services/src/keygurad_status_listener_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/services/src/keygurad_status_listener_test.cpp b/test/unittest/services/src/keygurad_status_listener_test.cpp index c117371fa..6f098bacd 100644 --- a/test/unittest/services/src/keygurad_status_listener_test.cpp +++ b/test/unittest/services/src/keygurad_status_listener_test.cpp @@ -46,7 +46,7 @@ HWTEST_F(KeyguardStatusListenerTest, KeyguardStatusListenerTestRegisterListener, EXPECT_EQ(result, GENERAL_ERROR); EXPECT_NO_THROW(KeyguardStatusListenerManager::GetInstance().RegisterKeyguardStatusSwitchCallback()); EXPECT_NO_THROW(KeyguardStatusListenerManager::GetInstance().UnRegisterKeyguardStatusSwitchCallback()); - ResultCode result = KeyguardStatusListenerManager::GetInstance().UnRegisterCommonEventListener(); + result = KeyguardStatusListenerManager::GetInstance().UnRegisterCommonEventListener(); EXPECT_EQ(result, GENERAL_ERROR); } } // namespace UserAuth From 2b1b57c6bce79a9e237799d51738298d6955406e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=85=E5=87=AF?= Date: Fri, 15 Nov 2024 16:13:16 +0800 Subject: [PATCH 3/3] fix: ut coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 居凯 Change-Id: Ia4dc3850294adf384aee97cb8f0d0d7b61c770c1 --- .../src/keygurad_status_listener_test.cpp | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/test/unittest/services/src/keygurad_status_listener_test.cpp b/test/unittest/services/src/keygurad_status_listener_test.cpp index 6f098bacd..de791c288 100644 --- a/test/unittest/services/src/keygurad_status_listener_test.cpp +++ b/test/unittest/services/src/keygurad_status_listener_test.cpp @@ -43,11 +43,32 @@ void KeyguardStatusListenerTest::TearDown() HWTEST_F(KeyguardStatusListenerTest, KeyguardStatusListenerTestRegisterListener, TestSize.Level0) { ResultCode result = KeyguardStatusListenerManager::GetInstance().RegisterCommonEventListener(); - EXPECT_EQ(result, GENERAL_ERROR); + EXPECT_EQ(result, SUCCESS); + result = KeyguardStatusListenerManager::GetInstance().RegisterCommonEventListener(); + EXPECT_NO_THROW(KeyguardStatusListenerManager::GetInstance().RegisterKeyguardStatusSwitchCallback()); EXPECT_NO_THROW(KeyguardStatusListenerManager::GetInstance().RegisterKeyguardStatusSwitchCallback()); EXPECT_NO_THROW(KeyguardStatusListenerManager::GetInstance().UnRegisterKeyguardStatusSwitchCallback()); + EXPECT_NO_THROW(KeyguardStatusListenerManager::GetInstance().UnRegisterKeyguardStatusSwitchCallback()); result = KeyguardStatusListenerManager::GetInstance().UnRegisterCommonEventListener(); - EXPECT_EQ(result, GENERAL_ERROR); + EXPECT_EQ(result, SUCCESS); + result = KeyguardStatusListenerManager::GetInstance().UnRegisterCommonEventListener(); +} + +HWTEST_F(KeyguardStatusListenerTest, KeyguardStatusListenerTestOnReceiveEvent, TestSize.Level0) +{ + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED); + + EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); + auto subscriber = std::make_shared(subscribeInfo); + EventFwk::Want want; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED); + EventFwk::CommonEventData data(want); + EXPECT_NO_THROW(subscriber->OnReceiveEvent(data)); + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED); + EventFwk::CommonEventData data1(want); + EXPECT_NO_THROW(subscriber->OnReceiveEvent(data1)); } } // namespace UserAuth } // namespace UserIam