mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-27 08:30:38 +00:00
add ut testcase
Signed-off-by: m00579239 <majiajun@huawei.com> Change-Id: I8732d6fed7e0e765ae017e3e381f72ab4d08b2d6
This commit is contained in:
parent
b3bea393c7
commit
72114737d0
@ -277,8 +277,16 @@ HWTEST_F(ContinuationManagerTest, RegisterDeviceSelectionCallbackTest_003, TestS
|
||||
int32_t result2 = DistributedAbilityManagerClient::GetInstance().RegisterDeviceSelectionCallback(
|
||||
token, INVALID_CALLBACK_TYPE, notifier);
|
||||
DTEST_LOG << "result2:" << result2 << std::endl;
|
||||
int32_t result3 = DistributedAbilityManagerClient::GetInstance().RegisterDeviceSelectionCallback(
|
||||
token, "", notifier);
|
||||
DTEST_LOG << "result3:" << result3 << std::endl;
|
||||
int32_t result4 = DistributedAbilityManagerClient::GetInstance().RegisterDeviceSelectionCallback(
|
||||
token, INVALID_CALLBACK_TYPE, nullptr);
|
||||
DTEST_LOG << "result4:" << result4 << std::endl;
|
||||
EXPECT_EQ(ERR_OK, result1);
|
||||
EXPECT_EQ(UNKNOWN_CALLBACK_TYPE, result2);
|
||||
EXPECT_EQ(ERR_NULL_OBJECT, result3);
|
||||
EXPECT_EQ(ERR_NULL_OBJECT, result4);
|
||||
DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_003 end" << std::endl;
|
||||
}
|
||||
|
||||
@ -638,6 +646,26 @@ HWTEST_F(ContinuationManagerTest, UnregisterDeviceSelectionCallbackTest_004, Tes
|
||||
DTEST_LOG << "ContinuationManagerTest UnregisterDeviceSelectionCallbackTest_004 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UnregisterDeviceSelectionCallbackTest_005
|
||||
* @tc.desc: test register device selection callback with invalid param
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, UnregisterDeviceSelectionCallbackTest_005, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "ContinuationManagerTest UnregisterDeviceSelectionCallbackTest_005 start" << std::endl;
|
||||
int32_t token = -1;
|
||||
int32_t result1 = DistributedAbilityManagerClient::GetInstance().Register(nullptr, token);
|
||||
DTEST_LOG << "result1:" << result1 << std::endl;
|
||||
int32_t result2 = DistributedAbilityManagerClient::GetInstance().UnregisterDeviceSelectionCallback(
|
||||
token, "");
|
||||
DTEST_LOG << "result2:" << result2 << std::endl;
|
||||
EXPECT_EQ(ERR_OK, result1);
|
||||
EXPECT_EQ(ERR_NULL_OBJECT, result2);
|
||||
DTEST_LOG << "ContinuationManagerTest UnregisterDeviceSelectionCallbackTest_005 end" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @tc.name: StartDeviceManagerTest_001
|
||||
* @tc.desc: test start device manager
|
||||
|
@ -39,7 +39,7 @@ const std::string DEVICE_ID = "testDeviceId";
|
||||
}
|
||||
|
||||
sptr<DistributedAbilityManagerService> DistributedAbilityManagerServiceTest::dtbabilitymgrService_;
|
||||
bool DistributedAbilityManagerServiceTest::isCaseDone_ = false;
|
||||
int32_t DistributedAbilityManagerServiceTest::startTaskNum_ = 2;
|
||||
std::mutex DistributedAbilityManagerServiceTest::caseDoneLock_;
|
||||
std::condition_variable DistributedAbilityManagerServiceTest::caseDoneCondition_;
|
||||
|
||||
@ -103,8 +103,8 @@ void DistributedAbilityManagerServiceTest::TearDownTestCase()
|
||||
// Wait until all asyn tasks are completed before exiting the test suite
|
||||
auto caseDoneNotifyTask = []() {
|
||||
std::lock_guard<std::mutex> autoLock(caseDoneLock_);
|
||||
isCaseDone_ = true;
|
||||
caseDoneCondition_.notify_all();
|
||||
--startTaskNum_;
|
||||
caseDoneCondition_.notify_one();
|
||||
};
|
||||
if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ != nullptr) {
|
||||
std::shared_ptr<AppExecFwk::EventHandler> dmsDataStorageHandler =
|
||||
@ -113,9 +113,12 @@ void DistributedAbilityManagerServiceTest::TearDownTestCase()
|
||||
dmsDataStorageHandler->PostTask(caseDoneNotifyTask);
|
||||
}
|
||||
}
|
||||
if (dtbabilitymgrService_->continuationHandler_ != nullptr) {
|
||||
dtbabilitymgrService_->continuationHandler_->PostTask(caseDoneNotifyTask);
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(caseDoneLock_);
|
||||
caseDoneCondition_.wait_for(lock, std::chrono::milliseconds(MAX_WAIT_TIME),
|
||||
[&] () { return isCaseDone_; });
|
||||
[&] () { return startTaskNum_ == 0; });
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest::TearDownTestCase" << std::endl;
|
||||
}
|
||||
|
||||
@ -341,11 +344,13 @@ HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_005, TestSize.Lev
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, DeviceOnlineNotify_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest DeviceOnlineNotify_001 start" << std::endl;
|
||||
sptr<DistributedAbilityManagerService> dtbabilitymgrService =
|
||||
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
|
||||
dtbabilitymgrService->InitDmsImplFunc();
|
||||
EXPECT_EQ(dtbabilitymgrService->isLoaded_, true);
|
||||
dtbabilitymgrService->DeviceOnlineNotify(DEVICE_ID);
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
dtbabilitymgrService_->InitDmsImplFunc();
|
||||
EXPECT_EQ(dtbabilitymgrService_->isLoaded_, true);
|
||||
dtbabilitymgrService_->DeviceOnlineNotify(DEVICE_ID);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest DeviceOnlineNotify_001 end" << std::endl;
|
||||
}
|
||||
|
||||
@ -357,11 +362,11 @@ HWTEST_F(DistributedAbilityManagerServiceTest, DeviceOnlineNotify_001, TestSize.
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, DeviceOfflineNotify_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest DeviceOfflineNotify_001 start" << std::endl;
|
||||
sptr<DistributedAbilityManagerService> dtbabilitymgrService =
|
||||
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
|
||||
dtbabilitymgrService->InitDmsImplFunc();
|
||||
EXPECT_EQ(dtbabilitymgrService->isLoaded_, true);
|
||||
dtbabilitymgrService->DeviceOfflineNotify(DEVICE_ID);
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
dtbabilitymgrService_->DeviceOfflineNotify(DEVICE_ID);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest DeviceOfflineNotify_001 end" << std::endl;
|
||||
}
|
||||
|
||||
@ -373,17 +378,51 @@ HWTEST_F(DistributedAbilityManagerServiceTest, DeviceOfflineNotify_001, TestSize
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, ConnectAbility_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest ConnectAbility_001 start" << std::endl;
|
||||
sptr<DistributedAbilityManagerService> dtbabilitymgrService =
|
||||
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
|
||||
dtbabilitymgrService->InitDmsImplFunc();
|
||||
EXPECT_EQ(dtbabilitymgrService->isLoaded_, true);
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ(dtbabilitymgrService_->isLoaded_, true);
|
||||
sptr<DmsNotifier> dmsNotifier(new MockDmsNotifier());
|
||||
std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
|
||||
int32_t ret = dtbabilitymgrService->ConnectAbility(dmsNotifier, 1, continuationExtraParams);
|
||||
int32_t ret = dtbabilitymgrService_->ConnectAbility(dmsNotifier, 1, continuationExtraParams);
|
||||
EXPECT_NE(ret, true);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest ConnectAbility_001 end" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @tc.name: HandleDeviceDisconnect
|
||||
* @tc.desc: test HandleDeviceDisconnect
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, HandleDeviceDisconnect_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceDisconnect_001 start" << std::endl;
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
bool ret = dtbabilitymgrService_->HandleDeviceDisconnect(dtbabilitymgrService_, continuationResults);
|
||||
EXPECT_NE(ret, true);
|
||||
std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
|
||||
dtbabilitymgrService_->ScheduleStartDeviceManager(nullptr, 1, continuationExtraParams);
|
||||
dtbabilitymgrService_->ScheduleStartDeviceManager(dtbabilitymgrService_, 1, continuationExtraParams);
|
||||
dtbabilitymgrService_->HandleStartDeviceManager(1, continuationExtraParams);
|
||||
dtbabilitymgrService_->HandleStartDeviceManager(1, nullptr);
|
||||
if (dtbabilitymgrService_->continuationHandler_ == nullptr) {
|
||||
auto runner = AppExecFwk::EventRunner::Create("continuation_manager");
|
||||
dtbabilitymgrService_->continuationHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
|
||||
}
|
||||
bool result = dtbabilitymgrService_->HandleDeviceConnect(dtbabilitymgrService_, continuationResults);
|
||||
dtbabilitymgrService_->HandleStartDeviceManager(1, continuationExtraParams);
|
||||
dtbabilitymgrService_->HandleStartDeviceManager(1, nullptr);
|
||||
EXPECT_EQ(result, true);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceDisconnect_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HandleDeviceConnect
|
||||
* @tc.desc: test HandleDeviceConnect
|
||||
@ -392,20 +431,50 @@ HWTEST_F(DistributedAbilityManagerServiceTest, ConnectAbility_001, TestSize.Leve
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, HandleDeviceConnect_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceConnect_001 start" << std::endl;
|
||||
sptr<DistributedAbilityManagerService> dtbabilitymgrService =
|
||||
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
int32_t ret = dtbabilitymgrService->HandleDeviceConnect(dtbabilitymgrService, continuationResults);
|
||||
EXPECT_NE(ret, true);
|
||||
if (dtbabilitymgrService->continuationHandler_ == nullptr) {
|
||||
auto runner = AppExecFwk::EventRunner::Create("continuation_manager");
|
||||
dtbabilitymgrService->continuationHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
ret = dtbabilitymgrService->HandleDeviceConnect(dtbabilitymgrService, continuationResults);
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
int32_t ret = dtbabilitymgrService_->HandleDeviceConnect(dtbabilitymgrService_, continuationResults);
|
||||
EXPECT_EQ(ret, true);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceConnect_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HandleNotifierDied
|
||||
* @tc.desc: test HandleNotifierDied
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, HandleNotifierDied_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest HandleNotifierDied_001 start" << std::endl;
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
dtbabilitymgrService_->HandleNotifierDied(dtbabilitymgrService_);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest HandleNotifierDied_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HandleNotifierDied
|
||||
* @tc.desc: test HandleNotifierDied
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, OnDeviceCancel_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest OnDeviceCancel_001 start" << std::endl;
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
int32_t ret = dtbabilitymgrService_->OnDeviceCancel();
|
||||
EXPECT_NE(ret, true);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest OnDeviceCancel_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HandleUpdateConnectStatus
|
||||
* @tc.desc: test HandleUpdateConnectStatus
|
||||
@ -414,15 +483,17 @@ HWTEST_F(DistributedAbilityManagerServiceTest, HandleDeviceConnect_001, TestSize
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, HandleUpdateConnectStatus_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest HandleUpdateConnectStatus_001 start" << std::endl;
|
||||
sptr<DistributedAbilityManagerService> dtbabilitymgrService =
|
||||
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
|
||||
DeviceConnectStatus deviceConnectStatus = DeviceConnectStatus::CONNECTING;
|
||||
dtbabilitymgrService->HandleUpdateConnectStatus(1, DEVICE_ID, deviceConnectStatus);
|
||||
if (dtbabilitymgrService->continuationHandler_ == nullptr) {
|
||||
auto runner = AppExecFwk::EventRunner::Create("continuation_manager");
|
||||
dtbabilitymgrService->continuationHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
dtbabilitymgrService->HandleUpdateConnectStatus(1, DEVICE_ID, deviceConnectStatus);
|
||||
DeviceConnectStatus deviceConnectStatus = DeviceConnectStatus::CONNECTING;
|
||||
dtbabilitymgrService_->HandleUpdateConnectStatus(1, DEVICE_ID, deviceConnectStatus);
|
||||
if (dtbabilitymgrService_->continuationHandler_ == nullptr) {
|
||||
auto runner = AppExecFwk::EventRunner::Create("continuation_manager");
|
||||
dtbabilitymgrService_->continuationHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
|
||||
}
|
||||
dtbabilitymgrService_->HandleUpdateConnectStatus(1, DEVICE_ID, deviceConnectStatus);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest HandleUpdateConnectStatus_001 end" << std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
static bool isCaseDone_;
|
||||
static int32_t startTaskNum_;
|
||||
static std::mutex caseDoneLock_;
|
||||
static std::condition_variable caseDoneCondition_;
|
||||
static sptr<DistributedAbilityManagerService> dtbabilitymgrService_;
|
||||
|
@ -331,6 +331,23 @@ HWTEST_F(BundleManagerInternalTest, BundleManagerCallBackTest_002, TestSize.Leve
|
||||
DTEST_LOG << "BundleManagerCallBackTest BundleManagerCallBackTest_002 end "<< std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: BundleManagerCallBackTest_003
|
||||
* @tc.desc: test OnRemoteRequest
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(BundleManagerInternalTest, BundleManagerCallBackTest_003, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "BundleManagerCallBackTest BundleManagerCallBackTest_003 begin" << std::endl;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
auto callback = new DmsBundleManagerCallbackStub();
|
||||
int32_t ret = callback->OnRemoteRequest(-1, data, reply, option);
|
||||
EXPECT_TRUE(ERR_OK != ret);
|
||||
DTEST_LOG << "BundleManagerCallBackTest BundleManagerCallBackTest_003 end "<< std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetBundleNameListFromBms_001
|
||||
* @tc.desc: test GetBundleNameListFromBms
|
||||
@ -352,5 +369,39 @@ HWTEST_F(BundleManagerInternalTest, GetBundleNameListFromBms_001, TestSize.Level
|
||||
EXPECT_TRUE(u16BundleNameList.empty());
|
||||
DTEST_LOG << "BundleManagerCallBackTest GetBundleNameListFromBms_001 end "<< std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetCallerAppIdFromBms_001
|
||||
* @tc.desc: test get callerappId from bms
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(BundleManagerInternalTest, GetCallerAppIdFromBms_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "BundleManagerInternalTest GetCallerAppIdFromBms_001 begin" << std::endl;
|
||||
const std::string bundleName = "com.ohos.launcher";
|
||||
int32_t uid = BundleManagerInternal::GetUidFromBms(bundleName);
|
||||
if (uid <= 0) {
|
||||
return;
|
||||
}
|
||||
string appId;
|
||||
bool ret = BundleManagerInternal::GetCallerAppIdFromBms(uid, appId);
|
||||
EXPECT_EQ(ret, true);
|
||||
DTEST_LOG << "BundleManagerInternalTest GetCallerAppIdFromBms_001 end "<< std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IsSameAppId_001
|
||||
* @tc.desc: test IsSameAppId with invalid param
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(BundleManagerInternalTest, IsSameAppId_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "BundleManagerInternalTest IsSameAppId_001 begin" << std::endl;
|
||||
string appId = "1001";
|
||||
string targetBundleName = "ohos.samples.dms.testApp";
|
||||
bool ret = BundleManagerInternal::IsSameAppId(appId, targetBundleName);
|
||||
EXPECT_EQ(ret, false);
|
||||
DTEST_LOG << "BundleManagerInternalTest IsSameAppId_001 end "<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user