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..de791c288 --- /dev/null +++ b/test/unittest/services/src/keygurad_status_listener_test.cpp @@ -0,0 +1,75 @@ +/* + * 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, 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, 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 +} // 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)