!1022 新增ut,提升覆盖率

Merge pull request !1022 from 师皓杰/master
This commit is contained in:
openharmony_ci 2024-07-30 06:26:26 +00:00 committed by Gitee
commit efd44053df
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 365 additions and 2 deletions

View File

@ -138,8 +138,6 @@ ohos_unittest("distributedschedsvrtest") {
sources = [
"unittest/continue_scene_session_handler_test.cpp",
"unittest/dfx/distributed_radar_test.cpp",
"unittest/dfx/distributed_sched_dumper_test.cpp",
"unittest/distributed_sched_adapter_test.cpp",
"unittest/distributed_sched_service_first_test.cpp",
"unittest/distributed_sched_service_second_test.cpp",
@ -499,6 +497,9 @@ ohos_unittest("dmsbasetest") {
sources = [
"unittest/collaborate/dsched_collaborate_callback_mgr_test.cpp",
"unittest/deviceManager/dms_device_info_test.cpp",
"unittest/dfx/distributed_radar_test.cpp",
"unittest/dfx/distributed_sched_dumper_test.cpp",
"unittest/dfx/distributed_ue_test.cpp",
"unittest/dfx/dms_continue_time_dumper_test.cpp",
"unittest/dfx/dms_hisysevent_report_test.cpp",
"unittest/dms_network_adapter_test.cpp",

View File

@ -0,0 +1,134 @@
/*
* Copyright (c) 2024 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 "distributed_ue_test.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::string NO_FAILED_EXTRAINFO = "NULL";
constexpr int32_t ONE = 1;
}
void DmsUETest::SetUpTestCase()
{
DTEST_LOG << "DmsUETest::SetUpTestCase" << std::endl;
}
void DmsUETest::TearDownTestCase()
{
DTEST_LOG << "DmsUETest::TearDownTestCase" << std::endl;
}
void DmsUETest::TearDown()
{
DTEST_LOG << "DmsUETest::TearDown" << std::endl;
}
void DmsUETest::SetUp()
{
DTEST_LOG << "DmsUETest::SetUp" << std::endl;
}
/**
* @tc.name: TriggerDmsContinue_001
* @tc.desc: check TriggerDmsContinue
* @tc.type: FUNC
*/
HWTEST_F(DmsUETest, TriggerDmsContinue_001, TestSize.Level3)
{
DTEST_LOG << "DmsUETest TriggerDmsContinue_001 begin" << std::endl;
std::string bundleName;
std::string abilityName;
std::string networkId;
bool ret = DmsUE::GetInstance().TriggerDmsContinue(bundleName, abilityName, networkId, ONE);
ret = DmsUE::GetInstance().DmsContinueComplete(bundleName, abilityName, networkId, ONE);
ret = DmsUE::GetInstance().OriginalSwitchState(true, ONE);
EXPECT_EQ(ret, true);
DTEST_LOG << "DmsUETest TriggerDmsContinue_001 end" << std::endl;
}
/**
* @tc.name: ChangedSwitchState_001
* @tc.desc: check ChangedSwitchState
* @tc.type: FUNC
*/
HWTEST_F(DmsUETest, ChangedSwitchState_001, TestSize.Level3)
{
DTEST_LOG << "DmsUETest ChangedSwitchState_001 begin" << std::endl;
bool ret = DmsUE::GetInstance().ChangedSwitchState(true, ONE);
ret = DmsUE::GetInstance().ChangedSwitchState(true, ERR_OK);
EXPECT_EQ(ret, true);
DTEST_LOG << "DmsUETest ChangedSwitchState_001 end" << std::endl;
}
/**
* @tc.name: ConvertErrCodeToStr_001
* @tc.desc: check ConvertErrCodeToStr
* @tc.type: FUNC
*/
HWTEST_F(DmsUETest, ConvertErrCodeToStr_001, TestSize.Level3)
{
DTEST_LOG << "DmsUETest ConvertErrCodeToStr_001 begin" << std::endl;
std::string ret = DmsUE::GetInstance().ConvertErrCodeToStr(ERR_OK);
EXPECT_EQ(ret, NO_FAILED_EXTRAINFO);
ret = DmsUE::GetInstance().ConvertErrCodeToStr(INVALID_PARAMETERS_ERR);
EXPECT_NE(ret, "");
ret = DmsUE::GetInstance().ConvertErrCodeToStr(INVALID_REMOTE_PARAMETERS_ERR);
EXPECT_NE(ret, "");
ret = DmsUE::GetInstance().ConvertErrCodeToStr(DMS_START_CONTROL_PERMISSION_DENIED);
EXPECT_NE(ret, "");
ret = DmsUE::GetInstance().ConvertErrCodeToStr(NO_MISSION_INFO_FOR_MISSION_ID);
EXPECT_NE(ret, "");
ret = DmsUE::GetInstance().ConvertErrCodeToStr(OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET);
EXPECT_NE(ret, "");
ret = DmsUE::GetInstance().ConvertErrCodeToStr(CONTINUE_ALREADY_IN_PROGRESS);
EXPECT_NE(ret, "");
DTEST_LOG << "DmsUETest ConvertErrCodeToStr_001 end" << std::endl;
}
/**
* @tc.name: ConvertErrCodeToStr_002
* @tc.desc: check ConvertErrCodeToStr
* @tc.type: FUNC
*/
HWTEST_F(DmsUETest, ConvertErrCodeToStr_002, TestSize.Level3)
{
DTEST_LOG << "DmsUETest ConvertErrCodeToStr_002 begin" << std::endl;
std::string ret = DmsUE::GetInstance().ConvertErrCodeToStr(MISSION_FOR_CONTINUING_IS_NOT_ALIVE);
EXPECT_NE(ret, "");
ret = DmsUE::GetInstance().ConvertErrCodeToStr(CONTINUE_SEND_EVENT_FAILED);
EXPECT_NE(ret, "");
ret = DmsUE::GetInstance().ConvertErrCodeToStr(CONTINUE_STATE_MACHINE_INVALID_STATE);
EXPECT_NE(ret, "");
ret = DmsUE::GetInstance().ConvertErrCodeToStr(CONTINUE_SESSION_SHUTDOWN);
EXPECT_NE(ret, "");
ret = DmsUE::GetInstance().ConvertErrCodeToStr(CONTINUE_CALL_CONTINUE_ABILITY_FAILED);
EXPECT_NE(ret, "");
ret = DmsUE::GetInstance().ConvertErrCodeToStr(CONTINUE_CALL_START_ABILITY_FAILED);
EXPECT_NE(ret, "");
ret = DmsUE::GetInstance().ConvertErrCodeToStr(CONTINUE_SINK_ABILITY_TERMINATED);
EXPECT_NE(ret, "");
ret = DmsUE::GetInstance().ConvertErrCodeToStr(DMS_CONNECT_APPLY_REJECT_FAILED);
EXPECT_NE(ret, "");
DTEST_LOG << "DmsUETest ConvertErrCodeToStr_002 end" << std::endl;
}
}
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2024 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 DISTRIBUTED_UE_TEST_H
#define DISTRIBUTED_UE_TEST_H
#include "gtest/gtest.h"
#include "test_log.h"
#include "dfx/distributed_ue.h"
namespace OHOS {
namespace DistributedSchedule {
class DmsUETest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // DISTRIBUTED_UE_TEST_H

View File

@ -886,6 +886,126 @@ HWTEST_F(DSchedContinuationTest, PushCallback_003, TestSize.Level3)
DTEST_LOG << "DSchedContinuationTest PushCallback_003 end" << std::endl;
}
/**
* @tc.name: PushCallback_004
* @tc.desc: test PushCallback
* @tc.type: FUNC
* @tc.require: I60TOK
*/
HWTEST_F(DSchedContinuationTest, PushCallback_004, TestSize.Level3)
{
DTEST_LOG << "DSchedContinuationTest PushCallback_004 start" << std::endl;
ASSERT_NE(dschedContinuation_, nullptr);
const sptr<IRemoteObject> callback = nullptr;
dschedContinuation_->PushCallback(callback);
dschedContinuation_->Init(nullptr);
bool result = dschedContinuation_->PushCallback(callback);
EXPECT_EQ(result, false);
DTEST_LOG << "DSchedContinuationTest PushCallback_004 end" << std::endl;
}
/**
* @tc.name: PushCallback_005
* @tc.desc: test PushCallback
* @tc.type: FUNC
* @tc.require: I60TOK
*/
HWTEST_F(DSchedContinuationTest, PushCallback_005, TestSize.Level3)
{
DTEST_LOG << "DSchedContinuationTest PushCallback_005 start" << std::endl;
ASSERT_NE(dschedContinuation_, nullptr);
const sptr<IRemoteObject> callback(new MockRemoteStub());
dschedContinuation_->Init(nullptr);
dschedContinuation_->continuationCallbackArr_.clear();
dschedContinuation_->PushCallback(callback);
dschedContinuation_->continuationCallbackArr_.push_back(callback);
bool result = dschedContinuation_->PushCallback(callback);
EXPECT_EQ(result, false);
DTEST_LOG << "DSchedContinuationTest PushCallback_005 end" << std::endl;
}
/**
* @tc.name: CleanupCallback_001
* @tc.desc: test CleanupCallback
* @tc.type: FUNC
* @tc.require: I60TOK
*/
HWTEST_F(DSchedContinuationTest, CleanupCallback_001, TestSize.Level3)
{
DTEST_LOG << "DSchedContinuationTest CleanupCallback_001 start" << std::endl;
ASSERT_NE(dschedContinuation_, nullptr);
const sptr<IRemoteObject> callback(new MockRemoteStub());
dschedContinuation_->continuationCallbackArr_.push_back(callback);
dschedContinuation_->CleanupCallback(callback);
dschedContinuation_->continuationCallbackArr_.clear();
bool result = dschedContinuation_->CleanupCallback(callback);
EXPECT_EQ(result, false);
DTEST_LOG << "DSchedContinuationTest CleanupCallback_001 end" << std::endl;
}
/**
* @tc.name: NotifyDSchedEventForOneCB_001
* @tc.desc: test NotifyDSchedEventForOneCB
* @tc.type: FUNC
* @tc.require: I60TOK
*/
HWTEST_F(DSchedContinuationTest, NotifyDSchedEventForOneCB_001, TestSize.Level3)
{
DTEST_LOG << "DSchedContinuationTest NotifyDSchedEventForOneCB_001 start" << std::endl;
ASSERT_NE(dschedContinuation_, nullptr);
const sptr<IRemoteObject> cb(new MockRemoteStub());
int32_t resultCode = 0;
dschedContinuation_->NotifyDSchedEventForOneCB(cb, resultCode);
int32_t result = dschedContinuation_->NotifyDSchedEventForOneCB(nullptr, resultCode);
EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
DTEST_LOG << "DSchedContinuationTest NotifyDSchedEventForOneCB_001 end" << std::endl;
}
/**
* @tc.name: NotifyDSchedEventResult_001
* @tc.desc: test NotifyDSchedEventResult
* @tc.type: FUNC
* @tc.require: I60TOK
*/
HWTEST_F(DSchedContinuationTest, NotifyDSchedEventResult_001, TestSize.Level3)
{
DTEST_LOG << "DSchedContinuationTest NotifyDSchedEventResult_001 start" << std::endl;
ASSERT_NE(dschedContinuation_, nullptr);
const sptr<IRemoteObject> callback(new MockRemoteStub());
int32_t resultCode = 0;
dschedContinuation_->continuationCallbackArr_.push_back(callback);
dschedContinuation_->NotifyDSchedEventResult(resultCode);
dschedContinuation_->continuationCallbackArr_.clear();
int32_t result = dschedContinuation_->NotifyDSchedEventResult(resultCode);
EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
DTEST_LOG << "DSchedContinuationTest NotifyDSchedEventResult_001 end" << std::endl;
}
/**
* @tc.name: IsCleanMission_001
* @tc.desc: test IsCleanMission
* @tc.type: FUNC
* @tc.require: I60TOK
*/
HWTEST_F(DSchedContinuationTest, IsCleanMission_001, TestSize.Level3)
{
DTEST_LOG << "DSchedContinuationTest IsCleanMission_001 start" << std::endl;
ASSERT_NE(dschedContinuation_, nullptr);
int32_t missionId = 0;
dschedContinuation_->SetCleanMissionFlag(1, true);
dschedContinuation_->IsCleanMission(missionId);
dschedContinuation_->SetCleanMissionFlag(missionId, false);
bool result = dschedContinuation_->IsCleanMission(missionId);
EXPECT_EQ(result, false);
DTEST_LOG << "DSchedContinuationTest IsCleanMission_001 end" << std::endl;
}
/**
* @tc.name: ContinueMission_001
* @tc.desc: test ContinueMission when srcDeviceId is empty.

View File

@ -1769,5 +1769,24 @@ HWTEST_F(DistributedSchedPermissionTest, GetDeviceSecurityLevel_001, TestSize.Le
EXPECT_NE(ret, 0);
DTEST_LOG << "DistributedSchedPermissionTest GetDeviceSecurityLevel_001 end " << std::endl;
}
/**
* @tc.name: CheckAclList_001
* @tc.desc: call CheckAclList
* @tc.type: FUNC
* @tc.require: I5RWIV
*/
HWTEST_F(DistributedSchedPermissionTest, CheckAclList_001, TestSize.Level3)
{
DTEST_LOG << "DistributedSchedPermissionTest CheckAclList_001 begin" << std::endl;
std::string dstNetworkId;
IDistributedSched::AccountInfo dmsAccountInfo;
CallerInfo callerInfo;
DistributedSchedPermission::GetInstance().GetOsAccountData(dmsAccountInfo);
DistributedSchedPermission::GetInstance().CheckDstSameAccount(dstNetworkId, dmsAccountInfo, callerInfo);
bool ret = DistributedSchedPermission::GetInstance().CheckAclList(dstNetworkId, dmsAccountInfo, callerInfo);
EXPECT_EQ(ret, false);
DTEST_LOG << "DistributedSchedPermissionTest CheckAclList_001 end result:" << ret << std::endl;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1145,6 +1145,7 @@ HWTEST_F(DistributedSchedServiceSecondTest, RemoveCallerComponent_001, TestSize.
DistributedSchedService::GetInstance().callerMap_[connect] = sessionsList;
DistributedSchedService::GetInstance().callMap_[connect] = {5, localDeviceId};
DistributedSchedService::GetInstance().RemoveCallerComponent(connect);
DistributedSchedService::GetInstance().RemoveCallerComponent(nullptr);
DistributedSchedService::GetInstance().callerMap_.clear();
EXPECT_TRUE(DistributedSchedService::GetInstance().callerMap_.empty());
DistributedSchedService::GetInstance().callMap_.clear();
@ -1341,6 +1342,7 @@ HWTEST_F(DistributedSchedServiceSecondTest, UnregisterAppStateObserver_002, Test
sptr<IRemoteObject> connect1(new MockDistributedSched());
DistributedSchedService::GetInstance().UnregisterAppStateObserver(connect1);
EXPECT_NE(connect, connect1);
DistributedSchedService::GetInstance().SaveCallerComponent(want, nullptr, callerInfo);
DTEST_LOG << "DistributedSchedServiceSecondTest UnregisterAppStateObserver_002 end" << std::endl;
}
@ -1412,6 +1414,8 @@ HWTEST_F(DistributedSchedServiceSecondTest, ContinueMissionBundleName_001, TestS
int32_t result = DistributedSchedService::GetInstance().ContinueMission(
"string", localDeviceId, "bundleName", callback, wantParams);
EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
DistributedSchedService::GetInstance().ContinueMission(
localDeviceId, "string", "bundleName", callback, wantParams);
DTEST_LOG << "DSchedContinuationTest ContinueMissionBundleName_001 end" << std::endl;
}
@ -1430,5 +1434,54 @@ HWTEST_F(DistributedSchedServiceSecondTest, ContinueMissionBundleName_002, TestS
EXPECT_EQ(static_cast<int>(OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET), result);
DTEST_LOG << "DSchedContinuationTest ContinueMissionBundleName_002 end" << std::endl;
}
/**
* @tc.name: GetCallerInfo_001
* @tc.desc: GetCallerInfo
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedServiceSecondTest, GetCallerInfo_001, TestSize.Level3)
{
DTEST_LOG << "DistributedSchedServiceSecondTest GetCallerInfo_001 start" << std::endl;
int32_t callerUid = 0;
uint32_t accessToken = 0;
CallerInfo callerInfo;
int32_t result = DistributedSchedService::GetInstance().GetCallerInfo(
LOCAL_DEVICEID, callerUid, accessToken, callerInfo);
EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
DTEST_LOG << "DistributedSchedServiceSecondTest GetCallerInfo_001 end" << std::endl;
}
/**
* @tc.name: ProcessContinueLocalMission_001
* @tc.desc: ProcessContinueLocalMission
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedServiceSecondTest, ProcessContinueLocalMission_001, TestSize.Level3)
{
DTEST_LOG << "DistributedSchedServiceSecondTest ProcessContinueLocalMission_001 start" << std::endl;
WantParams wantParams;
int32_t result = DistributedSchedService::GetInstance().ProcessContinueLocalMission(
LOCAL_DEVICEID, REMOTE_DEVICEID, BUNDLE_NAME, nullptr, wantParams);
bool ret = DistributedSchedService::GetInstance().GetIsFreeInstall(0);
EXPECT_EQ(ret, false);
DTEST_LOG << "DistributedSchedServiceSecondTest ProcessContinueLocalMission_001 end" << std::endl;
}
/**
* @tc.name: StartAbility_001
* @tc.desc: StartAbility
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedServiceSecondTest, StartAbility_001, TestSize.Level3)
{
DTEST_LOG << "DistributedSchedServiceSecondTest StartAbility_001 start" << std::endl;
Want want;
int32_t requestCode = 0;
int32_t ret = DistributedSchedService::GetInstance().StartAbility(want, requestCode);
EXPECT_NE(ret, ERR_OK);
DTEST_LOG << "DistributedSchedServiceSecondTest StartAbility_001 end" << std::endl;
}
}
}