!1130 fix:UT coverage

Merge pull request !1130 from 居凯/master
This commit is contained in:
openharmony_ci 2024-11-15 10:13:54 +00:00 committed by Gitee
commit c49873236c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 119 additions and 1 deletions

View File

@ -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",

View File

@ -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 <gtest/gtest.h>
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

View File

@ -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<KeyguardStatusListener>(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

View File

@ -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<BaseSocket> 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)