增加TDD

Signed-off-by: du-zhihai <duzhihai@huawei.com>
Change-Id: I5fb488c1518861a71390fd9689b9389423503fbd
This commit is contained in:
du-zhihai 2023-03-20 21:32:41 +08:00
parent e482c43898
commit 77c5c36035
5 changed files with 543 additions and 42 deletions

View File

@ -19,6 +19,7 @@
#include "dtbschedmgr_log.h"
#define private public
#include "mission/distributed_sched_mission_manager.h"
#include "continuation_extra_params.h"
#undef private
#include "test_log.h"
@ -31,8 +32,11 @@ namespace {
constexpr int32_t REGISTER = 500;
constexpr int32_t UPDATE_CONNECT_STATUS = 504;
constexpr int32_t INVALID_CODE = -1;
constexpr int32_t MAX_REGISTER_NUM = 600;
constexpr int32_t MAX_WAIT_TIME = 10000;
constexpr uint32_t TEST_UINT32_T = 0;
const std::u16string DMS_STUB_INTERFACE_TOKEN = u"OHOS.DistributedSchedule.IDistributedAbilityManager";
const std::u16string TEST_U16STRING = u"test u16string";
const std::string DEVICE_ID = "testDeviceId";
}
@ -41,6 +45,14 @@ int32_t DistributedAbilityManagerServiceTest::startTaskNum_ = 1;
std::mutex DistributedAbilityManagerServiceTest::caseDoneLock_;
std::condition_variable DistributedAbilityManagerServiceTest::caseDoneCondition_;
void DeviceSelectionNotifierTest::OnDeviceConnect(const std::vector<ContinuationResult>& continuationResults)
{
}
void DeviceSelectionNotifierTest::OnDeviceDisconnect(const std::vector<ContinuationResult>& continuationResults)
{
}
void DistributedAbilityManagerServiceTest::SetUpTestCase()
{
dtbabilitymgrService_ = new DistributedAbilityManagerService();
@ -74,6 +86,53 @@ void DistributedAbilityManagerServiceTest::TearDown()
DTEST_LOG << "DistributedAbilityManagerServiceTest::TearDown" << std::endl;
}
/**
* @tc.name: Dump_001
* @tc.desc: test Dump when args is not empty.
* @tc.type: FUNC
* @tc.require: I6NMR8
*/
HWTEST_F(DistributedAbilityManagerServiceTest, Dump_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest Dump_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
/**
* @tc.steps: step1. test OnStart.
*/
dtbabilitymgrService_->OnStart();
/**
* @tc.steps: step2. test OnStop.
*/
dtbabilitymgrService_->OnStop();
/**
* @tc.steps: step3. test Dump when args is not empty.
*/
std::vector<std::u16string> args;
args.push_back(TEST_U16STRING);
int32_t result = dtbabilitymgrService_->Dump(INVALID_CODE, args);
EXPECT_EQ(result, DMS_WRITE_FILE_FAILED_ERR);
/**
* @tc.steps: step4. test DumpAppRegisterInfo when tokenMap_ is not empty.
*/
std::string info;
std::vector<int32_t> tokenMapValue;
{
std::lock_guard<std::mutex> autoLock(dtbabilitymgrService_->tokenMapMutex_);
dtbabilitymgrService_->tokenMap_.clear();
tokenMapValue.push_back(INVALID_CODE);
dtbabilitymgrService_->tokenMap_[TEST_UINT32_T] = tokenMapValue;
}
dtbabilitymgrService_->DumpAppRegisterInfo(info);
{
std::lock_guard<std::mutex> autoLock(dtbabilitymgrService_->tokenMapMutex_);
dtbabilitymgrService_->tokenMap_.clear();
}
DTEST_LOG << "DistributedAbilityManagerServiceTest Dump_001 end" << std::endl;
}
/**
* @tc.name: OnRemoteRequest_001
* @tc.desc: test OnRemoteRequest to start Register
@ -183,6 +242,236 @@ HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_005, TestSize.Lev
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_005 end" << std::endl;
}
/**
* @tc.name: Register_001
* @tc.desc: test Register when continuationExtraParams != nullptr.
* @tc.type: FUNC
* @tc.require: I6NMR8
*/
HWTEST_F(DistributedAbilityManagerServiceTest, Register_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest Register_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
/**
* @tc.steps: step1. test DumpNotifierLocked when callbackMap_ is not empty.
*/
std::vector<int32_t> tokenVec;
std::string info;
std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
{
std::lock_guard<std::mutex> autoLock(dtbabilitymgrService_->callbackMapMutex_);
dtbabilitymgrService_->callbackMap_.clear();
dtbabilitymgrService_->callbackMap_[INVALID_CODE] = std::move(notifierInfo);;
}
tokenVec.push_back(INVALID_CODE);
dtbabilitymgrService_->DumpNotifierLocked(tokenVec, info);
/**
* @tc.steps: step2. test Register when register max num.
*/
int32_t token = 0;
std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
for (int32_t i = 0; i < MAX_REGISTER_NUM; i++) {
dtbabilitymgrService_->Register(continuationExtraParams, token);
}
int32_t ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
EXPECT_EQ(ret, REGISTER_EXCEED_MAX_TIMES);
{
std::lock_guard<std::mutex> tokenLock(dtbabilitymgrService_->tokenMutex_);
dtbabilitymgrService_->tokenMap_.clear();
}
DTEST_LOG << "DistributedAbilityManagerServiceTest Register_001 end" << std::endl;
}
/**
* @tc.name: Unregister_001
* @tc.desc: test Unregister
* @tc.type: FUNC
* @tc.require: I5NOA1
*/
HWTEST_F(DistributedAbilityManagerServiceTest, Unregister_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest Unregister_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
/**
* @tc.steps: step1. test Unregister when token is not registered.
*/
int32_t ret = dtbabilitymgrService_->Unregister(INVALID_CODE);
EXPECT_EQ(ret, TOKEN_HAS_NOT_REGISTERED);
/**
* @tc.steps: step2. test Unregister when notifier is not registered.
*/
{
std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
dtbabilitymgrService_->callbackMap_.clear();
}
int32_t token = 0;
std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
EXPECT_EQ(ret, ERR_OK);
ret = dtbabilitymgrService_->Unregister(token);
EXPECT_EQ(ret, ERR_OK);
/**
* @tc.steps: step3. test Unregister when notifier is registered.
*/
ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
EXPECT_EQ(ret, ERR_OK);
{
std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
dtbabilitymgrService_->callbackMap_[token] = std::move(notifierInfo);;
}
ret = dtbabilitymgrService_->Unregister(token);
EXPECT_EQ(ret, ERR_OK);
{
std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
dtbabilitymgrService_->callbackMap_.clear();
}
DTEST_LOG << "DistributedAbilityManagerServiceTest Unregister_001 end" << std::endl;
}
/**
* @tc.name: RegisterDeviceSelectionCallback_001
* @tc.desc: test RegisterDeviceSelectionCallback
* @tc.type: FUNC
* @tc.require: I5NOA1
*/
HWTEST_F(DistributedAbilityManagerServiceTest, RegisterDeviceSelectionCallback_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest RegisterDeviceSelectionCallback_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
/**
* @tc.steps: step1. test RegisterDeviceSelectionCallback when cbType is invalid.
*/
int32_t ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(INVALID_CODE, "", nullptr);
EXPECT_EQ(ret, UNKNOWN_CALLBACK_TYPE);
/**
* @tc.steps: step2. test RegisterDeviceSelectionCallback when cbType has registered.
*/
int32_t token = 0;
std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
EXPECT_EQ(ret, ERR_OK);
sptr<DeviceSelectionNotifierTest> notifier = new DeviceSelectionNotifierTest();
ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(token, EVENT_CONNECT, notifier);
EXPECT_EQ(ret, ERR_OK);
ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(token, EVENT_CONNECT, notifier);
EXPECT_EQ(ret, CALLBACK_HAS_REGISTERED);
ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(token, EVENT_CONNECT);
EXPECT_EQ(ret, ERR_OK);
ret = dtbabilitymgrService_->Unregister(token);
EXPECT_EQ(ret, ERR_OK);
DTEST_LOG << "DistributedAbilityManagerServiceTest RegisterDeviceSelectionCallback_001 end" << std::endl;
}
/**
* @tc.name: UnregisterDeviceSelectionCallback_001
* @tc.desc: test UnregisterDeviceSelectionCallback
* @tc.type: FUNC
* @tc.require: I5NOA1
*/
HWTEST_F(DistributedAbilityManagerServiceTest, UnregisterDeviceSelectionCallback_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest UnregisterDeviceSelectionCallback_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
/**
* @tc.steps: step1. test UnregisterDeviceSelectionCallback when cbType is invalid.
*/
int32_t ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(INVALID_CODE, "");
EXPECT_EQ(ret, UNKNOWN_CALLBACK_TYPE);
/**
* @tc.steps: step2. test UnregisterDeviceSelectionCallback when cbType == EVENT_CONNECT.
*/
ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(INVALID_CODE, EVENT_CONNECT);
EXPECT_EQ(ret, TOKEN_HAS_NOT_REGISTERED);
/**
* @tc.steps: step3. test UnregisterDeviceSelectionCallback when cbType == EVENT_DISCONNECT.
*/
ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(INVALID_CODE, EVENT_DISCONNECT);
EXPECT_EQ(ret, TOKEN_HAS_NOT_REGISTERED);
/**
* @tc.steps: step4. test UnregisterDeviceSelectionCallback when token is registered.
*/
int32_t token = 0;
std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
EXPECT_EQ(ret, ERR_OK);
ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(token, EVENT_CONNECT);
EXPECT_EQ(ret, CALLBACK_HAS_NOT_REGISTERED);
/**
* @tc.steps: step5. test UnregisterDeviceSelectionCallback when callback is registered.
*/
sptr<DeviceSelectionNotifierTest> notifier = new DeviceSelectionNotifierTest();
ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(token, EVENT_CONNECT, notifier);
EXPECT_EQ(ret, ERR_OK);
ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(token, EVENT_CONNECT);
EXPECT_EQ(ret, ERR_OK);
ret = dtbabilitymgrService_->Unregister(token);
EXPECT_EQ(ret, ERR_OK);
DTEST_LOG << "DistributedAbilityManagerServiceTest UnregisterDeviceSelectionCallback_001 end" << std::endl;
}
/**
* @tc.name: UpdateConnectStatus_001
* @tc.desc: test UpdateConnectStatus
* @tc.type: FUNC
* @tc.require: I5NOA1
*/
HWTEST_F(DistributedAbilityManagerServiceTest, UpdateConnectStatus_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest UpdateConnectStatus_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
/**
* @tc.steps: step1. test UpdateConnectStatus when deviceId is empty.
*/
int32_t ret = dtbabilitymgrService_->UpdateConnectStatus(INVALID_CODE, "", DeviceConnectStatus::IDLE);
EXPECT_EQ(ret, ERR_NULL_OBJECT);
/**
* @tc.steps: step2. test UpdateConnectStatus when token is not registered.
*/
ret = dtbabilitymgrService_->UpdateConnectStatus(INVALID_CODE, DEVICE_ID, DeviceConnectStatus::IDLE);
EXPECT_EQ(ret, TOKEN_HAS_NOT_REGISTERED);
/**
* @tc.steps: step3. test UpdateConnectStatus when callback is not registered.
*/
int32_t token = 0;
std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
EXPECT_EQ(ret, ERR_OK);
ret = dtbabilitymgrService_->UpdateConnectStatus(token, DEVICE_ID, DeviceConnectStatus::IDLE);
EXPECT_EQ(ret, CALLBACK_HAS_NOT_REGISTERED);
/**
* @tc.steps: step4. test UpdateConnectStatus when callback is registered.
*/
sptr<DeviceSelectionNotifierTest> notifier = new DeviceSelectionNotifierTest();
ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(token, EVENT_CONNECT, notifier);
EXPECT_EQ(ret, ERR_OK);
ret = dtbabilitymgrService_->UpdateConnectStatus(token, DEVICE_ID, DeviceConnectStatus::IDLE);
EXPECT_EQ(ret, ERR_OK);
ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(token, EVENT_CONNECT);
EXPECT_EQ(ret, ERR_OK);
ret = dtbabilitymgrService_->Unregister(token);
EXPECT_EQ(ret, ERR_OK);
DTEST_LOG << "DistributedAbilityManagerServiceTest UpdateConnectStatus_001 end" << std::endl;
}
/**
* @tc.name: ConnectAbility
* @tc.desc: test ConnectAbility
@ -201,6 +490,117 @@ HWTEST_F(DistributedAbilityManagerServiceTest, ConnectAbility_001, TestSize.Leve
DTEST_LOG << "DistributedAbilityManagerServiceTest ConnectAbility_001 end" << std::endl;
}
/**
* @tc.name: OnDeviceDisconnect_001
* @tc.desc: test OnDeviceDisconnect
* @tc.type: FUNC
* @tc.require: I5NOA1
*/
HWTEST_F(DistributedAbilityManagerServiceTest, OnDeviceDisconnect_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest OnDeviceDisconnect_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
/**
* @tc.steps: step1. test OnDeviceDisconnect when callback has not registered.
*/
if (dtbabilitymgrService_->continuationHandler_ == nullptr) {
auto runner = AppExecFwk::EventRunner::Create("continuation_manager");
dtbabilitymgrService_->continuationHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
}
std::vector<ContinuationResult> continuationResults;
int32_t ret = dtbabilitymgrService_->OnDeviceDisconnect(INVALID_CODE, continuationResults);
EXPECT_EQ(ret, CALLBACK_HAS_NOT_REGISTERED);
/**
* @tc.steps: step2. test OnDeviceDisconnect when callback has registered.
*/
int32_t token = 0;
std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
EXPECT_EQ(ret, ERR_OK);
sptr<DeviceSelectionNotifierTest> notifier = new DeviceSelectionNotifierTest();
ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(token, EVENT_DISCONNECT, notifier);
EXPECT_EQ(ret, ERR_OK);
ret = dtbabilitymgrService_->OnDeviceDisconnect(token, continuationResults);
EXPECT_EQ(ret, ERR_OK);
ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(token, EVENT_DISCONNECT);
EXPECT_EQ(ret, ERR_OK);
ret = dtbabilitymgrService_->Unregister(token);
EXPECT_EQ(ret, ERR_OK);
DTEST_LOG << "DistributedAbilityManagerServiceTest OnDeviceDisconnect_001 end" << std::endl;
}
/**
* @tc.name: IsExceededRegisterMaxNum_001
* @tc.desc: test IsExceededRegisterMaxNum when IsExceededRegisterMaxNum returns true.
* @tc.type: FUNC
* @tc.require: I5NOA1
*/
HWTEST_F(DistributedAbilityManagerServiceTest, IsExceededRegisterMaxNum_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest IsExceededRegisterMaxNum_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
{
std::lock_guard<std::mutex> tokenMapLock(dtbabilitymgrService_->tokenMapMutex_);
dtbabilitymgrService_->tokenMap_.clear();
std::vector<int32_t> vec;
for (int32_t i = 0; i < MAX_REGISTER_NUM; ++i) {
vec.push_back(INVALID_CODE);
}
dtbabilitymgrService_->tokenMap_[TEST_UINT32_T] = vec;
}
bool ret = dtbabilitymgrService_->IsExceededRegisterMaxNum(TEST_UINT32_T);
EXPECT_EQ(ret, true);
DTEST_LOG << "DistributedAbilityManagerServiceTest IsExceededRegisterMaxNum_001 end" << std::endl;
}
/**
* @tc.name: IsNotifierRegistered_001
* @tc.desc: test IsNotifierRegistered when callbackMap_[token] = nullptr.
* @tc.type: FUNC
* @tc.require: I5NOA1
*/
HWTEST_F(DistributedAbilityManagerServiceTest, IsNotifierRegistered_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest IsNotifierRegistered_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
{
std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
dtbabilitymgrService_->callbackMap_[INVALID_CODE] = nullptr;
}
bool ret = dtbabilitymgrService_->IsNotifierRegistered(INVALID_CODE);
EXPECT_EQ(ret, false);
DTEST_LOG << "DistributedAbilityManagerServiceTest IsNotifierRegistered_001 end" << std::endl;
}
/**
* @tc.name: HandleDeviceConnect_002
* @tc.desc: test HandleDeviceConnect when continuationHandler_ == nullptr.
* @tc.type: FUNC
* @tc.require: I5NOA1
*/
HWTEST_F(DistributedAbilityManagerServiceTest, HandleDeviceConnect_002, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceConnect_002 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
dtbabilitymgrService_->continuationHandler_ = nullptr;
std::vector<ContinuationResult> continuationResults;
bool ret = dtbabilitymgrService_->HandleDeviceConnect(nullptr, continuationResults);
EXPECT_EQ(ret, false);
DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceConnect_002 end" << std::endl;
}
/**
* @tc.name: HandleDeviceDisconnect
@ -214,7 +614,6 @@ HWTEST_F(DistributedAbilityManagerServiceTest, HandleDeviceDisconnect_001, TestS
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
std::vector<ContinuationResult> continuationResults;
bool ret = dtbabilitymgrService_->HandleDeviceDisconnect(dtbabilitymgrService_, continuationResults);
EXPECT_NE(ret, true);
@ -234,6 +633,36 @@ HWTEST_F(DistributedAbilityManagerServiceTest, HandleDeviceDisconnect_001, TestS
DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceDisconnect_001 end" << std::endl;
}
/**
* @tc.name: HandleDeviceDisconnect_002
* @tc.desc: test HandleDeviceDisconnect when continuationHandler_ != nullptr.
* @tc.type: FUNC
* @tc.require: I5NOA1
*/
HWTEST_F(DistributedAbilityManagerServiceTest, HandleDeviceDisconnect_002, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceDisconnect_002 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
/**
* @tc.steps: step1. test HandleUpdateConnectStatus when continuationHandler_ is nullptr.
*/
dtbabilitymgrService_->continuationHandler_ = nullptr;
dtbabilitymgrService_->HandleUpdateConnectStatus(INVALID_CODE, DEVICE_ID, DeviceConnectStatus::CONNECTED);
/**
* @tc.steps: step2. test HandleDeviceConnect when continuationHandler_ is not nullptr.
*/
auto runner = AppExecFwk::EventRunner::Create("continuation_manager");
dtbabilitymgrService_->continuationHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
sptr<DeviceSelectionNotifierTest> notifier = new DeviceSelectionNotifierTest();
std::vector<ContinuationResult> continuationResults;
bool ret = dtbabilitymgrService_->HandleDeviceDisconnect(notifier, continuationResults);
EXPECT_EQ(ret, true);
DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceDisconnect_002 end" << std::endl;
}
/**
* @tc.name: HandleDeviceConnect
* @tc.desc: test HandleDeviceConnect
@ -253,7 +682,60 @@ HWTEST_F(DistributedAbilityManagerServiceTest, HandleDeviceConnect_001, TestSize
}
/**
* @tc.name: HandleNotifierDied
* @tc.name: QueryTokenByNotifier_001
* @tc.desc: test QueryTokenByNotifier when iter->second == nullptr.
* @tc.type: FUNC
* @tc.require: I5NOA1
*/
HWTEST_F(DistributedAbilityManagerServiceTest, QueryTokenByNotifier_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest QueryTokenByNotifier_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
/**
* @tc.steps: step1. test QueryTokenByNotifier when iter->second == nullptr.
*/
{
std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
dtbabilitymgrService_->callbackMap_.clear();
dtbabilitymgrService_->callbackMap_[INVALID_CODE] = nullptr;
}
sptr<DeviceSelectionNotifierTest> notifier = new DeviceSelectionNotifierTest();
int32_t token;
bool ret = dtbabilitymgrService_->QueryTokenByNotifier(notifier, token);
EXPECT_FALSE(ret);
{
std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
dtbabilitymgrService_->callbackMap_.clear();
}
/**
* @tc.steps: step2. test ProcessNotifierDied when notifier != nullptr.
*/
dtbabilitymgrService_->ProcessNotifierDied(notifier);
/**
* @tc.steps: step3. test HandleNotifierDied when continuationHandler_ == nullptr.
*/
dtbabilitymgrService_->continuationHandler_ = nullptr;
dtbabilitymgrService_->HandleNotifierDied(nullptr);
/**
* @tc.steps: step4. test HandleNotifierDied when QueryTokenByNotifier returns true.
*/
auto runner = AppExecFwk::EventRunner::Create("continuation_manager");
dtbabilitymgrService_->continuationHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
notifierInfo->SetNotifier(EVENT_CONNECT, notifier);
{
std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
dtbabilitymgrService_->callbackMap_[INVALID_CODE] = std::move(notifierInfo);;
}
dtbabilitymgrService_->HandleNotifierDied(notifier);
DTEST_LOG << "DistributedAbilityManagerServiceTest QueryTokenByNotifier_001 end" << std::endl;
}
/**
* @tc.name: HandleNotifierDied_001
* @tc.desc: test HandleNotifierDied
* @tc.type: FUNC
*/
@ -264,8 +746,27 @@ HWTEST_F(DistributedAbilityManagerServiceTest, HandleNotifierDied_001, TestSize.
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
/**
* @tc.steps: step1. test HandleNotifierDied.
*/
std::vector<ContinuationResult> continuationResults;
dtbabilitymgrService_->HandleNotifierDied(dtbabilitymgrService_);
/**
* @tc.steps: step2. test HandleNotifierDied when IsNotifierRegistered returns true.
*/
int32_t token = 0;
std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
int32_t res = dtbabilitymgrService_->Register(continuationExtraParams, token);
EXPECT_EQ(res, ERR_OK);
sptr<DeviceSelectionNotifierTest> notifier = new DeviceSelectionNotifierTest();
std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
notifierInfo->SetNotifier(EVENT_CONNECT, notifier);
{
std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
dtbabilitymgrService_->callbackMap_.clear();
dtbabilitymgrService_->callbackMap_[token] = std::move(notifierInfo);;
}
dtbabilitymgrService_->HandleNotifierDied(notifier);
DTEST_LOG << "DistributedAbilityManagerServiceTest HandleNotifierDied_001 end" << std::endl;
}

View File

@ -18,6 +18,7 @@
#include <condition_variable>
#include <shared_mutex>
#include "device_selection_notifier_stub.h"
#define private public
#include "distributed_ability_manager_service.h"
#undef private
@ -36,6 +37,15 @@ public:
static std::condition_variable caseDoneCondition_;
static sptr<DistributedAbilityManagerService> dtbabilitymgrService_;
};
class DeviceSelectionNotifierTest : public DeviceSelectionNotifierStub {
public:
DeviceSelectionNotifierTest() = default;
~DeviceSelectionNotifierTest() = default;
void OnDeviceConnect(const std::vector<ContinuationResult>& continuationResults) override;
void OnDeviceDisconnect(const std::vector<ContinuationResult>& continuationResults) override;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DISTRIBUTED_ABILITY_MANAGER_SERVICE_TEST_H

View File

@ -338,29 +338,15 @@ HWTEST_F(DmsVersionManagerTest, GetDmsVersionDataFromAppInfo_005, TestSize.Level
HWTEST_F(DmsVersionManagerTest, GetAppInfoFromDP_001, TestSize.Level3)
{
DTEST_LOG << "DmsVersionManagerTest GetAppInfoFromDP_001 begin" << std::endl;
std::string deviceId = "1";
std::string deviceId;
std::string appInfoJson;
DmsVersionManager::GetAppInfoFromDP(deviceId, appInfoJson);
deviceId = "1";
int32_t result = DmsVersionManager::GetAppInfoFromDP(deviceId, appInfoJson);
EXPECT_NE(result, ERR_OK);
DTEST_LOG << "DmsVersionManagerTest GetAppInfoFromDP_001 end ret:" << result << std::endl;
}
/**
* @tc.name: GetAppInfoFromDP_002
* @tc.desc: test call GetAppInfoFromDP with local device id
* @tc.type: FUNC
* @tc.require: I5RWKZ
*/
HWTEST_F(DmsVersionManagerTest, GetAppInfoFromDP_002, TestSize.Level3)
{
DTEST_LOG << "DmsVersionManagerTest GetAppInfoFromDP_002 begin" << std::endl;
std::string deviceId;
std::string appInfoJson;
int32_t result = DmsVersionManager::GetAppInfoFromDP(deviceId, appInfoJson);
EXPECT_EQ(result, ERR_OK);
DTEST_LOG << "DmsVersionManagerTest GetAppInfoFromDP_002 end ret:" << result << std::endl;
}
/**
* @tc.name: ParseAppInfo_001
* @tc.desc: test call ParseAppInfo with appInfoJsonDatadata is empty
@ -451,6 +437,22 @@ HWTEST_F(DmsVersionManagerTest, ParseAppInfo_005, TestSize.Level3)
DTEST_LOG << "DmsVersionManagerTest ParseAppInfo_005 end ret:" << result << std::endl;
}
/**
* @tc.name: GetAppInfoFromDP_002
* @tc.desc: test call GetAppInfoFromDP with local device id
* @tc.type: FUNC
* @tc.require: I5RWKZ
*/
HWTEST_F(DmsVersionManagerTest, GetAppInfoFromDP_002, TestSize.Level3)
{
DTEST_LOG << "DmsVersionManagerTest GetAppInfoFromDP_002 begin" << std::endl;
std::string deviceId = "test";
std::string appInfoJson;
int32_t result = DmsVersionManager::GetAppInfoFromDP(deviceId, appInfoJson);
EXPECT_NE(result, ERR_OK);
DTEST_LOG << "DmsVersionManagerTest GetAppInfoFromDP_002 end ret:" << result << std::endl;
}
/**
* @tc.name: ParseAppInfo_006
* @tc.desc: test call ParseAppInfo
@ -478,8 +480,10 @@ HWTEST_F(DmsVersionManagerTest, ParseAppInfo_006, TestSize.Level3)
HWTEST_F(DmsVersionManagerTest, GetRemoteDmsVersion_001, TestSize.Level3)
{
DTEST_LOG << "DmsVersionManagerTest GetRemoteDmsVersion_001 begin" << std::endl;
std::string deviceId = "0";
std::string deviceId;
DmsVersion dmsVersion;
DmsVersionManager::GetRemoteDmsVersion(deviceId, dmsVersion);
deviceId = "0";
int32_t result = DmsVersionManager::GetRemoteDmsVersion(deviceId, dmsVersion);
EXPECT_NE(result, ERR_OK);
DTEST_LOG << "DmsVersionManagerTest GetRemoteDmsVersion_001 end ret:" << result << std::endl;
@ -494,10 +498,10 @@ HWTEST_F(DmsVersionManagerTest, GetRemoteDmsVersion_001, TestSize.Level3)
HWTEST_F(DmsVersionManagerTest, GetRemoteDmsVersion_002, TestSize.Level3)
{
DTEST_LOG << "DmsVersionManagerTest GetRemoteDmsVersion_002 begin" << std::endl;
std::string deviceId;
std::string deviceId = "test";
DmsVersion dmsVersion;
int32_t result = DmsVersionManager::GetRemoteDmsVersion(deviceId, dmsVersion);
EXPECT_EQ(result, ERR_OK);
EXPECT_NE(result, ERR_OK);
DTEST_LOG << "DmsVersionManagerTest GetRemoteDmsVersion_002 end ret:" << result << std::endl;
}
@ -510,27 +514,13 @@ HWTEST_F(DmsVersionManagerTest, GetRemoteDmsVersion_002, TestSize.Level3)
HWTEST_F(DmsVersionManagerTest, IsRemoteDmsVersionLower_001, TestSize.Level3)
{
DTEST_LOG << "DmsVersionManagerTest IsRemoteDmsVersionLower_001 begin" << std::endl;
std::string deviceId = "0";
std::string deviceId;
DmsVersion thresholdDmsVersion = {3, 2, 0};
DmsVersionManager::IsRemoteDmsVersionLower(deviceId, thresholdDmsVersion);
deviceId = "0";
bool result = DmsVersionManager::IsRemoteDmsVersionLower(deviceId, thresholdDmsVersion);
EXPECT_EQ(result, true);
DTEST_LOG << "DmsVersionManagerTest IsRemoteDmsVersionLower_001 end ret:" << result << std::endl;
}
/**
* @tc.name: IsRemoteDmsVersionLower_002
* @tc.desc: test call IsRemoteDmsVersionLower with local deviceId
* @tc.type: FUNC
* @tc.require: I5RWKZ
*/
HWTEST_F(DmsVersionManagerTest, IsRemoteDmsVersionLower_002, TestSize.Level3)
{
DTEST_LOG << "DmsVersionManagerTest IsRemoteDmsVersionLower_002 begin" << std::endl;
std::string deviceId;
DmsVersion thresholdDmsVersion = {3, 2, 0};
bool result = DmsVersionManager::IsRemoteDmsVersionLower(deviceId, thresholdDmsVersion);
EXPECT_EQ(result, false);
DTEST_LOG << "DmsVersionManagerTest IsRemoteDmsVersionLower_002 end ret:" << result << std::endl;
}
}
}

View File

@ -15,17 +15,17 @@
<configuration ver="2.0">
<target name="distributedschedsvrtest">
<preparer>
<option name="push" value="resource/bmsThirdBundle1.hap -> /data/test/resource/dmsfwk/resource/" src="res"/>
<option name="push" value="resource/bmsThirdBundle.hap -> /data/test/resource/dmsfwk/resource/" src="res"/>
</preparer>
</target>
<target name="bundlemanagerinternaltest">
<preparer>
<option name="push" value="resource/bmsThirdBundle1.hap -> /data/test/resource/dmsfwk/resource/" src="res"/>
<option name="push" value="resource/bmsThirdBundle.hap -> /data/test/resource/dmsfwk/resource/" src="res"/>
</preparer>
</target>
<target name="dschedcontinuetest">
<preparer>
<option name="push" value="resource/bmsThirdBundle1.hap -> /data/test/resource/dmsfwk/resource/" src="res"/>
<option name="push" value="resource/bmsThirdBundle.hap -> /data/test/resource/dmsfwk/resource/" src="res"/>
</preparer>
</target>
</configuration>