mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 06:20:07 +00:00
commit
42cbdc4981
@ -444,16 +444,12 @@ ohos_unittest("dmscontinuemanagertest") {
|
||||
}
|
||||
|
||||
ohos_unittest("dmsmissionmanagertest") {
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
module_out_path = module_output_path
|
||||
cflags = [ "-Dprivate=public" ]
|
||||
sources = [
|
||||
"unittest/mission/distributed_data_storage_test.cpp",
|
||||
"unittest/mission/dms_mission_manager_test.cpp",
|
||||
"unittest/mission/mock_distributed_sched_adapter.cpp",
|
||||
"unittest/mission/mock_image_packer.cpp",
|
||||
]
|
||||
sources += dtbschedmgr_sources
|
||||
@ -469,6 +465,8 @@ ohos_unittest("dmsmissionmanagertest") {
|
||||
external_deps += [ "config_policy:configpolicy_util" ]
|
||||
public_deps = dsched_public_deps
|
||||
}
|
||||
|
||||
external_deps += [ "googletest:gmock" ]
|
||||
part_name = "dmsfwk"
|
||||
subsystem_name = "ability"
|
||||
}
|
||||
@ -656,11 +654,6 @@ ohos_unittest("dschedswitchstatustest") {
|
||||
}
|
||||
|
||||
ohos_unittest("dschedcontinuestatetest") {
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
module_out_path = module_output_path
|
||||
cflags = [ "-Dprivate=public" ]
|
||||
sources = [
|
||||
@ -668,6 +661,7 @@ ohos_unittest("dschedcontinuestatetest") {
|
||||
"unittest/continue/dsched_continue_manager_test.cpp",
|
||||
"unittest/continue/dsched_continue_state_test.cpp",
|
||||
"unittest/continue/dsched_continue_test.cpp",
|
||||
"unittest/continue/mock_dtbschedmgr_device_info.cpp",
|
||||
"unittest/mock_distributed_sched.cpp",
|
||||
]
|
||||
sources += dtbschedmgr_sources
|
||||
@ -681,6 +675,7 @@ ohos_unittest("dschedcontinuestatetest") {
|
||||
external_deps = dsched_external_deps
|
||||
public_deps = dsched_public_deps
|
||||
}
|
||||
external_deps += [ "googletest:gmock" ]
|
||||
part_name = "dmsfwk"
|
||||
subsystem_name = "ability"
|
||||
}
|
||||
|
@ -45,12 +45,16 @@ void DSchedContinueManagerTest::SetUpTestCase()
|
||||
const std::string pkgName = "DBinderBus_PermissionTest" + std::to_string(getprocpid());
|
||||
std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
|
||||
DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
|
||||
dmsStoreMock = std::make_shared<MockDmsMgrDeviceInfoStore>();
|
||||
DmsMgrDeviceInfoStore::dmsStore = dmsStoreMock;
|
||||
DTEST_LOG << "DSchedContinueManagerTest::SetUpTestCase" << std::endl;
|
||||
}
|
||||
|
||||
void DSchedContinueManagerTest::TearDownTestCase()
|
||||
{
|
||||
(void)remove(BASEDIR.c_str());
|
||||
DmsMgrDeviceInfoStore::dmsStore = nullptr;
|
||||
dmsStoreMock = nullptr;
|
||||
DTEST_LOG << "DSchedContinueManagerTest::TearDownTestCase" << std::endl;
|
||||
}
|
||||
|
||||
@ -113,6 +117,7 @@ HWTEST_F(DSchedContinueManagerTest, ContinueMission_001, TestSize.Level3)
|
||||
DTEST_LOG << "DSchedContinueManagerTest ContinueMission_001 begin" << std::endl;
|
||||
auto callback = GetDSchedService();
|
||||
OHOS::AAFwk::WantParams wantParams;
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
|
||||
int32_t ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
|
||||
callback, wantParams);
|
||||
EXPECT_EQ(ret, OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET);
|
||||
@ -133,10 +138,26 @@ HWTEST_F(DSchedContinueManagerTest, ContinueMission_002, TestSize.Level3)
|
||||
DSchedContinueManager::GetInstance().HandleContinueMission(LOCAL_DEVICEID, "", MISSION_ID, callback, wantParams);
|
||||
DSchedContinueManager::GetInstance().HandleContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
|
||||
nullptr, wantParams);
|
||||
|
||||
int32_t ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
|
||||
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true)).WillOnce(Return(true));
|
||||
DSchedContinueManager::GetInstance().HandleContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
|
||||
callback, wantParams);
|
||||
EXPECT_EQ(ret, OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET);
|
||||
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(false));
|
||||
DSchedContinueManager::GetInstance().HandleContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
|
||||
callback, wantParams);
|
||||
|
||||
int32_t ret = DSchedContinueManager::GetInstance().ContinueMission("", REMOTE_DEVICEID, MISSION_ID,
|
||||
callback, wantParams);
|
||||
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
|
||||
|
||||
ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, "", MISSION_ID,
|
||||
nullptr, wantParams);
|
||||
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
|
||||
|
||||
ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
|
||||
nullptr, wantParams);
|
||||
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
|
||||
DTEST_LOG << "DSchedContinueManagerTest ContinueMission_002 end" << std::endl;
|
||||
}
|
||||
|
||||
@ -166,20 +187,21 @@ HWTEST_F(DSchedContinueManagerTest, ContinueMission_003, TestSize.Level3)
|
||||
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
|
||||
|
||||
auto callback = GetDSchedService();
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
|
||||
ret = DSchedContinueManager::GetInstance().ContinueMission(
|
||||
DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE),
|
||||
callback, wantParams);
|
||||
EXPECT_EQ(ret, OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET);
|
||||
|
||||
std::string locDevId;
|
||||
EXPECT_EQ(true, DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(locDevId));
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(DoAll(SetArgReferee<0>(LOCAL_DEVICEID), Return(true)));
|
||||
ret = DSchedContinueManager::GetInstance().ContinueMission(
|
||||
DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, locDevId, BUNDLE_NAME, CONTINUETYPE),
|
||||
DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE),
|
||||
callback, wantParams);
|
||||
EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
|
||||
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(DoAll(SetArgReferee<0>(REMOTE_DEVICEID), Return(true)));
|
||||
ret = DSchedContinueManager::GetInstance().ContinueMission(
|
||||
DSchedContinueInfo(locDevId, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE),
|
||||
DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE),
|
||||
callback, wantParams);
|
||||
EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
|
||||
DTEST_LOG << "DSchedContinueManagerTest ContinueMission_003 end" << std::endl;
|
||||
@ -205,6 +227,7 @@ HWTEST_F(DSchedContinueManagerTest, HandleContinueMission_001, TestSize.Level3)
|
||||
DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE),
|
||||
nullptr, wantParams);
|
||||
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
|
||||
DSchedContinueManager::GetInstance().HandleContinueMission(
|
||||
DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE),
|
||||
callback, wantParams);
|
||||
@ -255,6 +278,7 @@ HWTEST_F(DSchedContinueManagerTest, CheckContinuationLimit_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest CheckContinuationLimit_001 begin" << std::endl;
|
||||
int32_t direction = 0;
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
|
||||
int32_t ret = DSchedContinueManager::GetInstance().CheckContinuationLimit(LOCAL_DEVICEID, REMOTE_DEVICEID,
|
||||
direction);
|
||||
EXPECT_EQ(ret, OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET);
|
||||
@ -297,6 +321,11 @@ HWTEST_F(DSchedContinueManagerTest, GetContinueInfo_002, TestSize.Level3)
|
||||
DSchedContinueManager::GetInstance().continues_[info] = dContinue;
|
||||
int32_t ret = DSchedContinueManager::GetInstance().GetContinueInfo(localDeviceId, remoteDeviceId);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
|
||||
DSchedContinueManager::GetInstance().continues_.clear();
|
||||
DSchedContinueManager::GetInstance().continues_[info] = nullptr;
|
||||
ret = DSchedContinueManager::GetInstance().GetContinueInfo(localDeviceId, remoteDeviceId);
|
||||
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
|
||||
DTEST_LOG << "DSchedContinueManagerTest GetContinueInfo_002 end" << std::endl;
|
||||
}
|
||||
|
||||
@ -384,6 +413,11 @@ HWTEST_F(DSchedContinueManagerTest, HandleContinueEnd_001, TestSize.Level3)
|
||||
|
||||
std::shared_ptr<DSchedContinue> ptr = nullptr;
|
||||
DSchedContinueManager::GetInstance().continues_[info] = ptr;
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(false));
|
||||
DSchedContinueManager::GetInstance().HandleContinueEnd(info);
|
||||
|
||||
DSchedContinueManager::GetInstance().continues_[info] = ptr;
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
|
||||
DSchedContinueManager::GetInstance().HandleContinueEnd(info);
|
||||
EXPECT_EQ(DSchedContinueManager::GetInstance().cntSource_, 0);
|
||||
DTEST_LOG << "DSchedContinueManagerTest HandleContinueEnd_001 end" << std::endl;
|
||||
@ -400,6 +434,7 @@ HWTEST_F(DSchedContinueManagerTest, GetDSchedContinueByWant_001, TestSize.Level3
|
||||
OHOS::AAFwk::Want want;
|
||||
int32_t missionId = 0;
|
||||
DSchedContinueManager::GetInstance().continues_.clear();
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
|
||||
auto ret = DSchedContinueManager::GetInstance().GetDSchedContinueByWant(want, missionId);
|
||||
EXPECT_EQ(ret, nullptr);
|
||||
DTEST_LOG << "DSchedContinueManagerTest GetDSchedContinueByWant_001 end" << std::endl;
|
||||
@ -421,5 +456,150 @@ HWTEST_F(DSchedContinueManagerTest, NotifyTerminateContinuation_001, TestSize.Le
|
||||
EXPECT_EQ(DSchedContinueManager::GetInstance().continues_.empty(), true);
|
||||
DTEST_LOG << "DSchedContinueManagerTest NotifyTerminateContinuation_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetFirstBundleName_001
|
||||
* @tc.desc: test GetFirstBundleName func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, GetFirstBundleName_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest GetFirstBundleName_001 begin" << std::endl;
|
||||
DSchedContinueInfo info;
|
||||
std::string firstBundleName;
|
||||
std::string bundleName;
|
||||
std::string deviceId;
|
||||
bool ret = DSchedContinueManager::GetInstance().GetFirstBundleName(info, firstBundleName, bundleName, deviceId);
|
||||
EXPECT_EQ(ret, false);
|
||||
DTEST_LOG << "DSchedContinueManagerTest GetFirstBundleName_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ContinueMission_004
|
||||
* @tc.desc: test ContinueMission func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, ContinueMission_004, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest ContinueMission_004 begin" << std::endl;
|
||||
auto callback = GetDSchedService();
|
||||
OHOS::AAFwk::WantParams wantParams;
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(false));
|
||||
int32_t ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
|
||||
callback, wantParams);
|
||||
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
|
||||
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(DoAll(SetArgReferee<0>(LOCAL_DEVICEID), Return(true)));
|
||||
ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
|
||||
callback, wantParams);
|
||||
EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
|
||||
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(DoAll(SetArgReferee<0>(REMOTE_DEVICEID), Return(true)));
|
||||
ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
|
||||
callback, wantParams);
|
||||
EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
|
||||
DTEST_LOG << "DSchedContinueManagerTest ContinueMission_004 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ContinueMission_005
|
||||
* @tc.desc: test ContinueMission func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, ContinueMission_005, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest ContinueMission_005 begin" << std::endl;
|
||||
auto callback = GetDSchedService();
|
||||
OHOS::AAFwk::WantParams wantParams;
|
||||
int32_t timeout = 0;
|
||||
DSchedContinueManager::GetInstance().WaitAllConnectDecision(CONTINUE_SOURCE,
|
||||
DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE), timeout);
|
||||
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(false));
|
||||
int32_t ret = DSchedContinueManager::GetInstance().ContinueMission(
|
||||
DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE),
|
||||
callback, wantParams);
|
||||
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
|
||||
DTEST_LOG << "DSchedContinueManagerTest ContinueMission_005 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetDSchedContinueByWant_002
|
||||
* @tc.desc: test GetDSchedContinueByWant func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, GetDSchedContinueByWant_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest GetDSchedContinueByWant_002 begin" << std::endl;
|
||||
OHOS::AAFwk::Want want;
|
||||
int32_t missionId = 0;
|
||||
int32_t callerUid = 0;
|
||||
int32_t status = 0;
|
||||
uint32_t accessToken = 0;
|
||||
DSchedContinueInfo info(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE);
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
|
||||
DSchedContinueManager::GetInstance().HandleStartContinuation(want, missionId, callerUid, status, accessToken);
|
||||
|
||||
DSchedContinueManager::GetInstance().continues_.clear();
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(false));
|
||||
auto ret = DSchedContinueManager::GetInstance().GetDSchedContinueByWant(want, missionId);
|
||||
EXPECT_EQ(ret, nullptr);
|
||||
|
||||
std::shared_ptr<DSchedContinue> dContinue = CreateObject();
|
||||
DSchedContinueManager::GetInstance().continues_[info] = nullptr;
|
||||
DSchedContinueManager::GetInstance().continues_[info] = dContinue;
|
||||
|
||||
DSchedContinueManager::GetInstance().NotifyTerminateContinuation(missionId);
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
|
||||
ret = DSchedContinueManager::GetInstance().GetDSchedContinueByWant(want, missionId);
|
||||
EXPECT_NE(ret, nullptr);
|
||||
DTEST_LOG << "DSchedContinueManagerTest GetDSchedContinueByWant_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CheckContinuationLimit_002
|
||||
* @tc.desc: test CheckContinuationLimit func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, CheckContinuationLimit_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest CheckContinuationLimit_002 begin" << std::endl;
|
||||
int32_t direction = 0;
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(false));
|
||||
int32_t ret = DSchedContinueManager::GetInstance().CheckContinuationLimit(LOCAL_DEVICEID, REMOTE_DEVICEID,
|
||||
direction);
|
||||
EXPECT_EQ(ret, GET_LOCAL_DEVICE_ERR);
|
||||
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(DoAll(SetArgReferee<0>(LOCAL_DEVICEID), Return(true)));
|
||||
DSchedContinueManager::GetInstance().cntSink_.store(MAX_CONCURRENT_SINK);
|
||||
ret = DSchedContinueManager::GetInstance().CheckContinuationLimit(LOCAL_DEVICEID, REMOTE_DEVICEID,
|
||||
direction);
|
||||
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
|
||||
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(DoAll(SetArgReferee<0>(REMOTE_DEVICEID), Return(true)));
|
||||
DSchedContinueManager::GetInstance().cntSink_.store(0);
|
||||
ret = DSchedContinueManager::GetInstance().CheckContinuationLimit(LOCAL_DEVICEID, REMOTE_DEVICEID,
|
||||
direction);
|
||||
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
|
||||
DTEST_LOG << "DSchedContinueManagerTest CheckContinuationLimit_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: NotifyContinueDataRecv_001
|
||||
* @tc.desc: test NotifyContinueDataRecv func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, NotifyContinueDataRecv_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest NotifyContinueDataRecv_001 begin" << std::endl;
|
||||
int32_t sessionId = 0;
|
||||
int32_t command = 0;
|
||||
std::string jsonStr = "jsonStr";
|
||||
std::shared_ptr<DSchedDataBuffer> dataBuffer = nullptr;
|
||||
DSchedContinueManager::GetInstance().continues_.clear();
|
||||
DSchedContinueManager::GetInstance().NotifyContinueDataRecv(sessionId, command, jsonStr, dataBuffer);
|
||||
EXPECT_EQ(DSchedContinueManager::GetInstance().continues_.empty(), true);
|
||||
DTEST_LOG << "DSchedContinueManagerTest NotifyContinueDataRecv_001 end" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "device_manager.h"
|
||||
#include "dsched_continue_manager.h"
|
||||
#include "mock_dtbschedmgr_device_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
@ -32,6 +33,7 @@ public:
|
||||
void TearDown();
|
||||
std::shared_ptr<DSchedContinue> CreateObject();
|
||||
sptr<IRemoteObject> GetDSchedService() const;
|
||||
static inline std::shared_ptr<MockDmsMgrDeviceInfoStore> dmsStoreMock = nullptr;
|
||||
protected:
|
||||
class DeviceInitCallBack : public OHOS::DistributedHardware::DmInitCallback {
|
||||
void OnRemoteDied() override;
|
||||
|
@ -36,6 +36,8 @@ namespace {
|
||||
void DSchedContinueTest::SetUpTestCase()
|
||||
{
|
||||
mkdir(BASEDIR.c_str(), (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH));
|
||||
dmsStoreMock = std::make_shared<MockDmsMgrDeviceInfoStore>();
|
||||
DmsMgrDeviceInfoStore::dmsStore = dmsStoreMock;
|
||||
DTEST_LOG << "DSchedContinueTest::SetUpTestCase" << std::endl;
|
||||
DistributedSchedService::GetInstance().Init();
|
||||
}
|
||||
@ -43,6 +45,8 @@ void DSchedContinueTest::SetUpTestCase()
|
||||
void DSchedContinueTest::TearDownTestCase()
|
||||
{
|
||||
(void)remove(BASEDIR.c_str());
|
||||
DmsMgrDeviceInfoStore::dmsStore = nullptr;
|
||||
dmsStoreMock = nullptr;
|
||||
DTEST_LOG << "DSchedContinueTest::TearDownTestCase" << std::endl;
|
||||
}
|
||||
|
||||
@ -587,6 +591,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0017_1, TestSize.Level0)
|
||||
|
||||
auto cmd = std::make_shared<DSchedContinueDataCmd>();
|
||||
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
|
||||
int32_t ret = conti->ExecuteContinueData(cmd);
|
||||
EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
|
||||
|
||||
@ -782,6 +787,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0024_1, TestSize.Level0)
|
||||
conti->Init();
|
||||
|
||||
std::string localDeviceId;
|
||||
EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
|
||||
bool ret = conti->GetLocalDeviceId(localDeviceId);
|
||||
EXPECT_EQ(ret, true);
|
||||
DTEST_LOG << "DSchedContinueTest DSchedContinueTest_0024_1 end ret:" << ret << std::endl;
|
||||
|
@ -17,6 +17,7 @@
|
||||
#define DSCHED_CONTINUE_TEST_H
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "mock_dtbschedmgr_device_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
@ -27,6 +28,7 @@ public:
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
static inline std::shared_ptr<MockDmsMgrDeviceInfoStore> dmsStoreMock = nullptr;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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 "mock_dtbschedmgr_device_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
bool DtbschedmgrDeviceInfoStorage::GetLocalDeviceId(std::string& networkId)
|
||||
{
|
||||
return OHOS::DistributedSchedule::DmsMgrDeviceInfoStore::dmsStore->GetLocalDeviceId(networkId);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 MOCK_DTBSCHEDMGR_DEVICE_INFO_H
|
||||
#define MOCK_DTBSCHEDMGR_DEVICE_INFO_H
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <string>
|
||||
|
||||
#include "dtbschedmgr_device_info_storage.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class DmsMgrDeviceInfoStore {
|
||||
public:
|
||||
virtual ~DmsMgrDeviceInfoStore() = default;
|
||||
public:
|
||||
virtual bool GetLocalDeviceId(std::string& networkId) = 0;
|
||||
public:
|
||||
static inline std::shared_ptr<DmsMgrDeviceInfoStore> dmsStore = nullptr;
|
||||
};
|
||||
|
||||
class MockDmsMgrDeviceInfoStore : public DmsMgrDeviceInfoStore {
|
||||
public:
|
||||
MOCK_METHOD(bool, GetLocalDeviceId, (std::string& networkId));
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif //MOCK_DTBSCHEDMGR_DEVICE_INFO_H
|
@ -71,11 +71,15 @@ void DMSMissionManagerTest::SetUpTestCase()
|
||||
}
|
||||
const std::string pkgName = "DBinderBus_" + std::to_string(getprocpid());
|
||||
std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
|
||||
mockDmsAdapter = std::make_shared<MockAdapter>();
|
||||
AdapterMock::dmsAdapter = mockDmsAdapter;
|
||||
DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
|
||||
}
|
||||
|
||||
void DMSMissionManagerTest::TearDownTestCase()
|
||||
{
|
||||
AdapterMock::dmsAdapter = nullptr;
|
||||
mockDmsAdapter = nullptr;
|
||||
}
|
||||
|
||||
void DMSMissionManagerTest::SetUp()
|
||||
@ -1379,6 +1383,7 @@ HWTEST_F(DMSMissionManagerTest, testMissionSnapshotChanged001, TestSize.Level3)
|
||||
DistributedSchedMissionManager::GetInstance().NotifyDmsProxyProcessDied();
|
||||
std::vector<DstbMissionInfo> missionInfos;
|
||||
DistributedSchedMissionManager::GetInstance().InitAllSnapshots(missionInfos);
|
||||
EXPECT_CALL(*mockDmsAdapter, GetLocalMissionSnapshotInfo(_, _, _)).WillOnce(Return(true));
|
||||
auto ret = DistributedSchedMissionManager::GetInstance().MissionSnapshotChanged(NUM_MISSIONS);
|
||||
EXPECT_NE(ret, ERR_NONE);
|
||||
DTEST_LOG << "testMissionSnapshotChanged001 end" << std::endl;
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "remote_mission_listener_stub.h"
|
||||
|
||||
#include "distributed_sched_interface.h"
|
||||
#include "mock_distributed_sched_adapter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
@ -40,6 +41,7 @@ protected:
|
||||
static bool isCaseDone_;
|
||||
static std::mutex caseDoneLock_;
|
||||
static std::condition_variable caseDoneCondition_;
|
||||
static inline std::shared_ptr<MockAdapter> mockDmsAdapter = nullptr;
|
||||
|
||||
class DeviceInitCallBack : public OHOS::DistributedHardware::DmInitCallback {
|
||||
void OnRemoteDied() override;
|
||||
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 "mock_distributed_sched_adapter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
int32_t DistributedSchedAdapter::GetLocalMissionSnapshotInfo(const std::string& networkId, int32_t missionId,
|
||||
AAFwk::MissionSnapshot& missionSnapshot)
|
||||
{
|
||||
return OHOS::DistributedSchedule::AdapterMock::dmsAdapter->GetLocalMissionSnapshotInfo(networkId, missionId,
|
||||
missionSnapshot);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 MOCK_DISTRIBUTED_SCHED_ADAPTER_H
|
||||
#define MOCK_DISTRIBUTED_SCHED_ADAPTER_H
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <string>
|
||||
|
||||
#include "distributed_sched_adapter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class AdapterMock {
|
||||
public:
|
||||
virtual ~AdapterMock() = default;
|
||||
public:
|
||||
virtual int32_t GetLocalMissionSnapshotInfo(const std::string& networkId, int32_t missionId,
|
||||
AAFwk::MissionSnapshot& missionSnapshot) = 0;
|
||||
public:
|
||||
static inline std::shared_ptr<AdapterMock> dmsAdapter = nullptr;
|
||||
};
|
||||
|
||||
class MockAdapter : public AdapterMock {
|
||||
public:
|
||||
MOCK_METHOD(int32_t, GetLocalMissionSnapshotInfo, (const std::string& networkId, int32_t missionId,
|
||||
AAFwk::MissionSnapshot& missionSnapshot));
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif //MOCK_DISTRIBUTED_SCHED_ADAPTER_H
|
Loading…
Reference in New Issue
Block a user