!573 添加状态感知测试用例

Merge pull request !573 from ql/0413
This commit is contained in:
openharmony_ci 2023-04-13 08:24:02 +00:00 committed by Gitee
commit 9fe9e2c411
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 241 additions and 2 deletions

View File

@ -2178,7 +2178,6 @@ int32_t DistributedSchedService::NotifyStateChanged(int32_t abilityState, AppExe
break;
}
}
HILOGE("observer not exits");
}
HILOGD("Get missionId = %{public}d", missionId);

View File

@ -968,7 +968,8 @@ int32_t DistributedSchedStub::NotifyStateChangedFromRemoteInner(MessageParcel& d
}
int32_t result = NotifyStateChangedFromRemote(abilityState, missionId, *element);
HILOGI("result = %{public}d", result);
PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
PARCEL_WRITE_HELPER(reply, Int32, result);
return ERR_NONE;
}
int32_t DistributedSchedStub::StartRemoteFreeInstallInner(MessageParcel& data, MessageParcel& reply)

View File

@ -1571,6 +1571,201 @@ HWTEST_F(DistributedSchedServiceTest, NotifyStateChangedFromRemote_003, TestSize
DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_003 end" << std::endl;
}
/**
* @tc.name: RegisterAppStateObserver_001
* @tc.desc: test RegisterAppStateObserver
* @tc.type: FUNC
* @tc.require: I6VDBO
*/
HWTEST_F(DistributedSchedServiceTest, RegisterAppStateObserver_001, TestSize.Level3)
{
DTEST_LOG << "DistributedSchedServiceTest RegisterAppStateObserver_001 start" << std::endl;
AAFwk::Want want;
std::string localDeviceId;
DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
want.SetElement(element);
want.SetParam(DMS_MISSION_ID, 0);
sptr<IRemoteObject> connect = new MockDistributedSched();
CallerInfo callerInfo;
callerInfo.uid = 0;
callerInfo.sourceDeviceId = localDeviceId;
bool ret = DistributedSchedService::GetInstance().RegisterAppStateObserver(want, callerInfo, connect);
DistributedSchedService::GetInstance().UnregisterAppStateObserver(connect);
EXPECT_TRUE(ret);
DTEST_LOG << "DistributedSchedServiceTest RegisterAppStateObserver_001 end" << std::endl;
}
/**
* @tc.name: UnregisterAppStateObserver_001
* @tc.desc: test UnregisterAppStateObserver
* @tc.type: FUNC
* @tc.require: I6VDBO
*/
HWTEST_F(DistributedSchedServiceTest, UnregisterAppStateObserver_001, TestSize.Level3)
{
DTEST_LOG << "DistributedSchedServiceTest UnregisterAppStateObserver_001 start" << std::endl;
sptr<IRemoteObject> connect;
DistributedSchedService::GetInstance().UnregisterAppStateObserver(connect);
EXPECT_EQ(connect, nullptr);
DTEST_LOG << "DistributedSchedServiceTest UnregisterAppStateObserver_001 end" << std::endl;
}
/**
* @tc.name: UnregisterAppStateObserver_002
* @tc.desc: test UnregisterAppStateObserver
* @tc.type: FUNC
* @tc.require: I6VDBO
*/
HWTEST_F(DistributedSchedServiceTest, UnregisterAppStateObserver_002, TestSize.Level3)
{
DTEST_LOG << "DistributedSchedServiceTest UnregisterAppStateObserver_002 start" << std::endl;
AAFwk::Want want;
std::string localDeviceId;
DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
want.SetElement(element);
want.SetParam(DMS_MISSION_ID, 0);
sptr<IRemoteObject> connect = new MockDistributedSched();
CallerInfo callerInfo;
callerInfo.uid = 0;
callerInfo.sourceDeviceId = localDeviceId;
bool ret = DistributedSchedService::GetInstance().RegisterAppStateObserver(want, callerInfo, connect);
EXPECT_TRUE(ret);
sptr<IRemoteObject> connect1 = new MockDistributedSched();
DistributedSchedService::GetInstance().UnregisterAppStateObserver(connect1);
EXPECT_NE(connect, connect1);
DTEST_LOG << "DistributedSchedServiceTest UnregisterAppStateObserver_002 end" << std::endl;
}
/**
* @tc.name: GetAppManager_001
* @tc.desc: test GetAppManager
* @tc.type: FUNC
* @tc.require: I6VDBO
*/
HWTEST_F(DistributedSchedServiceTest, GetAppManager_001, TestSize.Level3)
{
DTEST_LOG << "DistributedSchedServiceTest GetAppManager_001 start" << std::endl;
auto ret = DistributedSchedService::GetInstance().GetAppManager();
EXPECT_NE(ret, nullptr);
DTEST_LOG << "DistributedSchedServiceTest GetAppManager_001 end" << std::endl;
}
/**
* @tc.name: NotifyStateChanged_002
* @tc.desc: test NotifyStateChanged
* @tc.type: FUNC
* @tc.require: I6VDBO
*/
HWTEST_F(DistributedSchedServiceTest, NotifyStateChanged_002, TestSize.Level3)
{
DTEST_LOG << "DistributedSchedServiceTest NotifyStateChanged_002 start" << std::endl;
sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
int32_t abilityState = FOREGROUND;
std::string localDeviceId;
DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
sptr<IRemoteObject> connect = new MockDistributedSched();
DistributedSchedService::GetInstance().observerMap_[connect] = {appStateObserver, localDeviceId, 0, BUNDLE_NAME,
ABILITY_NAME};
AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
int32_t ret = DistributedSchedService::GetInstance().NotifyStateChanged(abilityState, element);
DTEST_LOG << "ret:" << ret << std::endl;
DistributedSchedService::GetInstance().observerMap_.clear();
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
DTEST_LOG << "DistributedSchedServiceTest NotifyStateChanged_002 end" << std::endl;
}
/**
* @tc.name: NotifyStateChanged_003
* @tc.desc: test NotifyStateChanged
* @tc.type: FUNC
* @tc.require: I6VDBO
*/
HWTEST_F(DistributedSchedServiceTest, NotifyStateChanged_003, TestSize.Level3)
{
DTEST_LOG << "DistributedSchedServiceTest NotifyStateChanged_003 start" << std::endl;
sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
int32_t abilityState = FOREGROUND;
std::string localDeviceId;
DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
sptr<IRemoteObject> connect = new MockDistributedSched();
DistributedSchedService::GetInstance().observerMap_[connect] = {appStateObserver, REMOTE_DEVICEID, 0, BUNDLE_NAME,
ABILITY_NAME};
AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
int32_t ret = DistributedSchedService::GetInstance().NotifyStateChanged(abilityState, element);
DTEST_LOG << "ret:" << ret << std::endl;
DistributedSchedService::GetInstance().observerMap_.clear();
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
DTEST_LOG << "DistributedSchedServiceTest NotifyStateChanged_003 end" << std::endl;
}
/**
* @tc.name: NotifyStateChangedFromRemote_004
* @tc.desc: test NotifyStateChangedFromRemote
* @tc.type: FUNC
* @tc.require: I6VDBO
*/
HWTEST_F(DistributedSchedServiceTest, NotifyStateChangedFromRemote_004, TestSize.Level3)
{
DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_004 start" << std::endl;
sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
int32_t abilityState = FOREGROUND;
std::string localDeviceId;
DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
int32_t ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(abilityState, 0, element);
DTEST_LOG << "ret:" << ret << std::endl;
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_004 end" << std::endl;
}
/**
* @tc.name: NotifyStateChangedFromRemote_005
* @tc.desc: test NotifyStateChangedFromRemote
* @tc.type: FUNC
* @tc.require: I6VDBO
*/
HWTEST_F(DistributedSchedServiceTest, NotifyStateChangedFromRemote_005, TestSize.Level3)
{
DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_005 start" << std::endl;
sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
int32_t abilityState = FOREGROUND;
std::string localDeviceId;
DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
sptr<IRemoteObject> connect = nullptr;
DistributedSchedService::GetInstance().callMap_[0] = {connect, localDeviceId};
AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
int32_t ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(abilityState, 0, element);
DTEST_LOG << "ret:" << ret << std::endl;
DistributedSchedService::GetInstance().callMap_.clear();
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_005 end" << std::endl;
}
/**
* @tc.name: NotifyStateChangedFromRemote_006
* @tc.desc: test NotifyStateChangedFromRemote
* @tc.type: FUNC
* @tc.require: I6VDBO
*/
HWTEST_F(DistributedSchedServiceTest, NotifyStateChangedFromRemote_006, TestSize.Level3)
{
DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_006 start" << std::endl;
sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
int32_t abilityState = FOREGROUND;
std::string localDeviceId;
DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
sptr<IRemoteObject> connect = new MockDistributedSched();
DistributedSchedService::GetInstance().callMap_[0] = {connect, localDeviceId};
AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
int32_t ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(abilityState, 0, element);
DTEST_LOG << "ret:" << ret << std::endl;
DistributedSchedService::GetInstance().callMap_.clear();
EXPECT_EQ(ret, ERR_OK);
DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_006 end" << std::endl;
}
/**
* @tc.name: ConnectAbilityFromRemote_001
* @tc.desc: test ConnectAbilityFromRemote

View File

@ -2012,5 +2012,49 @@ HWTEST_F(DistributedSchedStubTest, StopExtensionAbilityFromRemoteInner_001, Test
EXPECT_EQ(result, ERR_NONE);
DTEST_LOG << "DistributedSchedStubTest StopExtensionAbilityFromRemoteInner_001 end" << std::endl;
}
/**
* @tc.name: NotifyStateChangedFromRemoteInner_001
* @tc.desc: check NotifyStateChangedFromRemoteInner
* @tc.type: FUNC
* @tc.require: I6VDBO
*/
HWTEST_F(DistributedSchedStubTest, NotifyStateChangedFromRemoteInner_001, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedStubTest NotifyStateChangedFromRemoteInner_001 begin" << std::endl;
MessageParcel data;
MessageParcel reply;
int32_t abilityState = 0;
data.WriteInt32(abilityState);
int32_t missionId = 0;
data.WriteInt32(missionId);
ElementName element;
data.WriteParcelable(&element);
int32_t result = distributedSchedStub_->NotifyStateChangedFromRemoteInner(data, reply);
EXPECT_EQ(result, ERR_NONE);
DTEST_LOG << "DistributedSchedStubTest NotifyStateChangedFromRemoteInner_001 end" << std::endl;
}
/**
* @tc.name: NotifyStateChangedFromRemoteInner_002
* @tc.desc: check NotifyStateChangedFromRemoteInner
* @tc.type: FUNC
* @tc.require: I6VDBO
*/
HWTEST_F(DistributedSchedStubTest, NotifyStateChangedFromRemoteInner_002, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedStubTest NotifyStateChangedFromRemoteInner_002 begin" << std::endl;
MessageParcel data;
MessageParcel reply;
int32_t abilityState = 0;
data.WriteInt32(abilityState);
int32_t missionId = 0;
data.WriteInt32(missionId);
int32_t result = distributedSchedStub_->NotifyStateChangedFromRemoteInner(data, reply);
EXPECT_EQ(result, ERR_INVALID_VALUE);
DTEST_LOG << "DistributedSchedStubTest NotifyStateChangedFromRemoteInner_002 end" << std::endl;
}
}
}