!786 [新需求]: 新增UT,添加权限

Merge pull request !786 from 师皓杰/master
This commit is contained in:
openharmony_ci 2024-01-26 07:05:40 +00:00 committed by Gitee
commit 7ce757521b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
10 changed files with 231 additions and 0 deletions

View File

@ -104,6 +104,23 @@ HWTEST_F(DistributedAbilityManagerStubTest, RegisterInner_001, TestSize.Level3)
DTEST_LOG << "DistributedAbilityManagerStubTest RegisterInner_001 end" << std::endl;
}
/**
* @tc.name: RegisterInner_002
* @tc.desc: test RegisterInner
* @tc.type: FUNC
* @tc.require: I64FU7
*/
HWTEST_F(DistributedAbilityManagerStubTest, RegisterInner_002, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerStubTest RegisterInner_002 start" << std::endl;
MessageParcel data;
MessageParcel reply;
data.WriteInt32(VALUE_NULL);
int32_t result = dtbabilitymgrStub_->RegisterInner(data, reply);
EXPECT_EQ(result, ERR_NONE);
DTEST_LOG << "DistributedAbilityManagerStubTest RegisterInner_002 end" << std::endl;
}
/**
* @tc.name: RegisterDeviceSelectionCallbackInner_001
* @tc.desc: test RegisterDeviceSelectionCallbackInner with cbType is empty
@ -223,5 +240,41 @@ HWTEST_F(DistributedAbilityManagerStubTest, StartDeviceManagerInner_002, TestSiz
EXPECT_EQ(result, ERR_NONE);
DTEST_LOG << "DistributedAbilityManagerStubTest StartDeviceManagerInner_002 end" << std::endl;
}
/**
* @tc.name: UnregisterInner_001
* @tc.desc: test UnregisterInner
* @tc.type: FUNC
* @tc.require: I64FU7
*/
HWTEST_F(DistributedAbilityManagerStubTest, UnregisterInner_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterInner_001 start" << std::endl;
MessageParcel data;
MessageParcel reply;
data.WriteInt32(VALUE_OBJECT);
int32_t result = dtbabilitymgrStub_->UnregisterInner(data, reply);
EXPECT_EQ(result, ERR_NONE);
DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterInner_001 end" << std::endl;
}
/**
* @tc.name: UpdateConnectStatusInner_001
* @tc.desc: test UpdateConnectStatusInner
* @tc.type: FUNC
* @tc.require: I64FU7
*/
HWTEST_F(DistributedAbilityManagerStubTest, UpdateConnectStatusInner_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerStubTest UpdateConnectStatusInner_001 start" << std::endl;
MessageParcel data;
MessageParcel reply;
std::string deviceId = "12345";
data.WriteInt32(VALUE_OBJECT);
data.WriteString(deviceId);
int32_t result = dtbabilitymgrStub_->UpdateConnectStatusInner(data, reply);
EXPECT_EQ(result, ERR_NONE);
DTEST_LOG << "DistributedAbilityManagerStubTest UpdateConnectStatusInner_001 end" << std::endl;
}
}
}

View File

@ -102,5 +102,20 @@ HWTEST_F(DmsHandlerTest, UnRegisterDSchedEventListener_001, TestSize.Level3)
EXPECT_EQ(result, GET_REMOTE_DMS_FAIL);
DTEST_LOG << "DmsHandlerTest UnRegisterDSchedEventListener_001 end" << std::endl;
}
/**
* @tc.name: UnRegisterDSchedEventListener_002
* @tc.desc: UnRegisterDSchedEventListener listener not is null
* @tc.type: FUNC
* @tc.require: I64FU7s
*/
HWTEST_F(DmsHandlerTest, UnRegisterDSchedEventListener_002, TestSize.Level3)
{
DTEST_LOG << "DmsHandlerTest UnRegisterDSchedEventListener_002 start" << std::endl;
sptr<IDSchedEventListener> listener = sptr<IDSchedEventListener>(new BusinessTest());
int32_t result = dmsHandler_.UnRegisterDSchedEventListener(TYPE, listener);
EXPECT_EQ(result, 0);
DTEST_LOG << "DmsHandlerTest UnRegisterDSchedEventListener_002 end" << std::endl;
}
}
}

View File

@ -68,6 +68,15 @@ HWTEST_F(DmsSaClientTest, AddDSchedEventListener_001, TestSize.Level3)
DTEST_LOG << "dmssaClient_ is nullptr" << std::endl;
return;
}
DTEST_LOG << "DmsSaClientTest OnAddSystemAbility_002 start" << std::endl;
int32_t systemAbilityId = 1;
dmssaClient_->OnAddSystemAbility(systemAbilityId, DEVICE_ID);
systemAbilityId = DISTRIBUTED_SCHED_SA_ID;
dmssaClient_->OnAddSystemAbility(systemAbilityId, DEVICE_ID);
DTEST_LOG << "DmsSaClientTest OnAddSystemAbility_002 end" << std::endl;
sptr<IDSchedEventListenerTest> listener = new IDSchedEventListenerTest();
dmssaClient_->hasSubscribeDmsSA_ = true;
int32_t result = dmssaClient_->AddDSchedEventListener(TYPE, listener);
@ -88,6 +97,15 @@ HWTEST_F(DmsSaClientTest, AddDSchedEventListener_002, TestSize.Level3)
DTEST_LOG << "dmssaClient_ is nullptr" << std::endl;
return;
}
DTEST_LOG << "DmsSaClientTest OnRemoveSystemAbility_001 start" << std::endl;
int32_t systemAbilityId = 1;
dmssaClient_->OnAddSystemAbility(systemAbilityId, DEVICE_ID);
systemAbilityId = DISTRIBUTED_SCHED_SA_ID;
dmssaClient_->OnRemoveSystemAbility(systemAbilityId, DEVICE_ID);
DTEST_LOG << "DmsSaClientTest OnRemoveSystemAbility_001 end" << std::endl;
sptr<IDSchedEventListenerTest> listener = new IDSchedEventListenerTest();
int32_t result = dmssaClient_->AddDSchedEventListener(TYPE, listener);
EXPECT_EQ(result, NO_ERROR);

View File

@ -187,6 +187,23 @@ HWTEST_F(DistributedSchedServiceSecondTest, StartRemoteShareForm_002, TestSize.L
DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteShareForm_002 end" << std::endl;
}
/**
* @tc.name: StartRemoteShareForm_003
* @tc.desc: call StartRemoteShareForm with dms
* @tc.type: StartRemoteShareForm
* @tc.require: issueI5M62D
*/
HWTEST_F(DistributedSchedServiceSecondTest, StartRemoteShareForm_003, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteShareForm_003 start" << std::endl;
sptr<IDistributedSched> proxy = GetDms();
const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
auto result = proxy->StartRemoteShareForm(REMOTE_DEVICEID, formShareInfo);
DTEST_LOG << "result:" << result << std::endl;
EXPECT_NE(ERR_OK, result);
DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteShareForm_003 end" << std::endl;
}
/**
* @tc.name: StartShareFormFromRemote_001
* @tc.desc: call StartAbilityFromRemote with dms

View File

@ -1272,6 +1272,7 @@ HWTEST_F(DistributedSchedStubTest, StartSyncMissionsFromRemoteInner_001, TestSiz
HWTEST_F(DistributedSchedStubTest, StartSyncMissionsFromRemoteInner_002, TestSize.Level3)
{
DTEST_LOG << "DistributedSchedStubTest StartSyncMissionsFromRemoteInner_002 begin" << std::endl;
DistributedSchedUtil::MockManageMissions();
MessageParcel data;
MessageParcel reply;
CallerInfo callerInfo;

View File

@ -102,6 +102,14 @@ void DistributedSchedUtil::MockBundlePermission()
MockProcessAndPermission("DistributedSchedPermissionTest", PERMS, sizeof(PERMS) / sizeof(PERMS[0]));
}
void DistributedSchedUtil::MockManageMissions()
{
static const char *perms[] = {
"ohos.permission.MANAGE_MISSIONS"
};
MockProcessAndPermission("DistributedSchedPermissionTest", perms, sizeof(perms) / sizeof(perms[0]));
}
void DistributedSchedUtil::MockProcess(const char* processName)
{
MockProcessAndPermission(processName);

View File

@ -29,6 +29,7 @@ class DistributedSchedUtil {
public:
static void MockPermission();
static void MockBundlePermission();
static void MockManageMissions();
static void MockProcess(const char* processName);
static void MockProcessAndPermission(const char* processName,
const char *perms[] = nullptr, int32_t permsNum = 0);

View File

@ -117,6 +117,42 @@ HWTEST_F(DistributedDataStorageTest, InsertTest_001, TestSize.Level1)
DTEST_LOG << "DistributedDataStorageTest InsertTest_001 end" << std::endl;
}
/**
* @tc.name: InsertTest_002
* @tc.desc: test insert DistributedDataStorage
* @tc.type: FUNC
*/
HWTEST_F(DistributedDataStorageTest, InsertTest_002, TestSize.Level1)
{
DTEST_LOG << "DistributedDataStorageTest InsertTest_002 start" << std::endl;
distributedDataStorage_->Init();
this_thread::sleep_for(1s);
std::string deviceId;
uint8_t* byteStream = InitByteStream();
bool ret = distributedDataStorage_->Insert(deviceId, TASK_ID_1, byteStream, BYTESTREAM_LENGTH);
EXPECT_EQ(false, ret);
distributedDataStorage_->Stop();
DTEST_LOG << "DistributedDataStorageTest InsertTest_002 end" << std::endl;
}
/**
* @tc.name: InsertTest_003
* @tc.desc: test insert DistributedDataStorage
* @tc.type: FUNC
*/
HWTEST_F(DistributedDataStorageTest, InsertTest_003, TestSize.Level1)
{
DTEST_LOG << "DistributedDataStorageTest InsertTest_003 start" << std::endl;
distributedDataStorage_->Init();
this_thread::sleep_for(1s);
std::string deviceId = GetLocalDeviceId();
uint8_t* byteStream = InitByteStream();
bool ret = distributedDataStorage_->Insert(deviceId, -1, byteStream, BYTESTREAM_LENGTH);
EXPECT_EQ(false, ret);
distributedDataStorage_->Stop();
DTEST_LOG << "DistributedDataStorageTest InsertTest_003 end" << std::endl;
}
/**
* @tc.name: DeleteTest_001
* @tc.desc: test delete DistributedDataStorage
@ -153,6 +189,42 @@ HWTEST_F(DistributedDataStorageTest, DeleteTest_002, TestSize.Level1)
DTEST_LOG << "DistributedDataStorageTest DeleteTest_002 end" << std::endl;
}
/**
* @tc.name: DeleteTest_003
* @tc.desc: test delete DistributedDataStorage
* @tc.type: FUNC
*/
HWTEST_F(DistributedDataStorageTest, DeleteTest_003, TestSize.Level1)
{
DTEST_LOG << "DistributedDataStorageTest DeleteTest_003 start" << std::endl;
distributedDataStorage_->Init();
this_thread::sleep_for(1s);
std::string networkId;
int32_t missionId = 0;
bool ret = distributedDataStorage_->Delete(networkId, missionId);
EXPECT_EQ(false, ret);
distributedDataStorage_->Stop();
DTEST_LOG << "DistributedDataStorageTest DeleteTest_003 end" << std::endl;
}
/**
* @tc.name: DeleteTest_004
* @tc.desc: test delete DistributedDataStorage
* @tc.type: FUNC
*/
HWTEST_F(DistributedDataStorageTest, DeleteTest_004, TestSize.Level1)
{
DTEST_LOG << "DistributedDataStorageTest DeleteTest_004 start" << std::endl;
distributedDataStorage_->Init();
this_thread::sleep_for(1s);
std::string networkId = GetLocalDeviceId();
int32_t missionId = -1;
bool ret = distributedDataStorage_->Delete(networkId, missionId);
EXPECT_EQ(false, ret);
distributedDataStorage_->Stop();
DTEST_LOG << "DistributedDataStorageTest DeleteTest_004 end" << std::endl;
}
/**
* @tc.name: QueryTest_001
* @tc.desc: test query DistributedDataStorage
@ -259,5 +331,41 @@ HWTEST_F(DistributedDataStorageTest, QueryTest_005, TestSize.Level1)
distributedDataStorage_->Stop();
DTEST_LOG << "DistributedDataStorageTest QueryTest_005 end" << std::endl;
}
/**
* @tc.name: QueryTest_006
* @tc.desc: test query DistributedDataStorage
* @tc.type: FUNC
*/
HWTEST_F(DistributedDataStorageTest, QueryTest_006, TestSize.Level1)
{
DTEST_LOG << "DistributedDataStorageTest QueryTest_006 start" << std::endl;
distributedDataStorage_->Init();
this_thread::sleep_for(1s);
std::string deviceId;
Value value;
bool ret = distributedDataStorage_->Query(deviceId, TASK_ID_1, value);
EXPECT_EQ(false, ret);
distributedDataStorage_->Stop();
DTEST_LOG << "DistributedDataStorageTest QueryTest_006 end" << std::endl;
}
/**
* @tc.name: QueryTest_007
* @tc.desc: test query DistributedDataStorage
* @tc.type: FUNC
*/
HWTEST_F(DistributedDataStorageTest, QueryTest_007, TestSize.Level1)
{
DTEST_LOG << "DistributedDataStorageTest QueryTest_007 start" << std::endl;
distributedDataStorage_->Init();
this_thread::sleep_for(1s);
std::string deviceId = GetLocalDeviceId();
Value value;
bool ret = distributedDataStorage_->Query(deviceId, -1, value);
EXPECT_EQ(false, ret);
distributedDataStorage_->Stop();
DTEST_LOG << "DistributedDataStorageTest QueryTest_007 end" << std::endl;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -16,6 +16,7 @@
#include "dms_continue_manager_test.h"
#include "datetime_ex.h"
#include "distributed_sched_util.h"
#include "dtbschedmgr_log.h"
#define private public
#include "mission/distributed_sched_continue_manager.h"
@ -75,6 +76,7 @@ HWTEST_F(DMSContinueManagerTest, testUnInit001, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testUnInit001 begin" << std::endl;
DistributedSchedUtil::MockManageMissions();
DistributedSchedContinueManager::GetInstance().Init();
EXPECT_NE(DistributedSchedContinueManager::GetInstance().eventHandler_, nullptr);
@ -102,6 +104,7 @@ HWTEST_F(DMSContinueManagerTest, testAddCancelMissionFocusedTimer001, TestSize.L
{
DTEST_LOG << "DMSContinueManagerTest testAddCancelMissionFocusedTimer001 begin" << std::endl;
DistributedSchedUtil::MockManageMissions();
DistributedSchedContinueManager::GetInstance().Init();
/**
@ -131,6 +134,7 @@ HWTEST_F(DMSContinueManagerTest, testNotifyMissionFocused001, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testNotifyMissionFocused001 begin" << std::endl;
DistributedSchedUtil::MockManageMissions();
DistributedSchedContinueManager::GetInstance().Init();
/**
@ -159,6 +163,7 @@ HWTEST_F(DMSContinueManagerTest, testNotifyMissionUnfocused001, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testNotifyMissionUnfocused001 begin" << std::endl;
DistributedSchedUtil::MockManageMissions();
DistributedSchedContinueManager::GetInstance().Init();
/**
* @tc.steps: step1. test NotifyMissionUnfocused when eventHandler is not nullptr;
@ -489,6 +494,7 @@ HWTEST_F(DMSContinueManagerTest, testNotifyDeid001, TestSize.Level1)
HWTEST_F(DMSContinueManagerTest, testSetMissionContinueState001, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testSetMissionContinueState001 start" << std::endl;
DistributedSchedUtil::MockManageMissions();
DistributedSchedContinueManager::GetInstance().Init();
OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_ACTIVE;
@ -545,6 +551,7 @@ HWTEST_F(DMSContinueManagerTest, testNotifyScreenOff001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest testNotifyScreenOff001 start" << std::endl;
DistributedSchedUtil::MockManageMissions();
/**
* @tc.steps: step1. test NotifyScreenOff when eventHandler is not nullptr;
*/

View File

@ -1230,6 +1230,7 @@ HWTEST_F(DMSMissionManagerTest, testOnRemoteDied002, TestSize.Level3)
HWTEST_F(DMSMissionManagerTest, testStartSyncMissionsFromRemote001, TestSize.Level3)
{
DTEST_LOG << "testStartSyncMissionsFromRemote001 begin" << std::endl;
DistributedSchedUtil::MockManageMissions();
std::vector<DstbMissionInfo> missionInfos;
CallerInfo callerInfo;
DistributedSchedMissionManager::GetInstance().Init();
@ -2457,6 +2458,7 @@ HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions013, TestSize.Level3)
HWTEST_F(DMSMissionManagerTest, testStartSyncMissionsFromRemote002, TestSize.Level3)
{
DTEST_LOG << "testStartSyncMissionsFromRemote002 begin" << std::endl;
DistributedSchedUtil::MockManageMissions();
/**
* @tc.steps: step1. test GetRemoteDms
*/
@ -2493,6 +2495,7 @@ HWTEST_F(DMSMissionManagerTest, testStartSyncMissionsFromRemote002, TestSize.Lev
HWTEST_F(DMSMissionManagerTest, testStartSyncMissionsFromRemote003, TestSize.Level3)
{
DTEST_LOG << "testStartSyncMissionsFromRemote003 begin" << std::endl;
DistributedSchedUtil::MockManageMissions();
/**
* @tc.steps: step1. test notify remote died
*/