mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 06:20:07 +00:00
修复测试用例crash问题
Signed-off-by: wangyang2022 <wangyang412@huawei.com> Change-Id: Ic47f67eb3e58055d2d16de6b3515423f28fdde9f
This commit is contained in:
parent
008976d73f
commit
dc74f99533
@ -15,6 +15,8 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <condition_variable>
|
||||
#include <shared_mutex>
|
||||
#include <thread>
|
||||
#define private public
|
||||
#include "adapter/dnetwork_adapter.h"
|
||||
@ -28,24 +30,55 @@ using namespace testing::ext;
|
||||
namespace {
|
||||
const std::string NETWORKID = "1234567";
|
||||
constexpr int32_t SLEEP_TIME = 2000;
|
||||
constexpr int32_t MAX_WAIT_TIME = 10000;
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class MockDeviceListener : public DeviceListener {
|
||||
public:
|
||||
MockDeviceListener() = default;
|
||||
~MockDeviceListener() = default;
|
||||
|
||||
void OnDeviceOnline(const DistributedHardware::DmDeviceInfo& deviceInfo) override {}
|
||||
void OnDeviceOffline(const DistributedHardware::DmDeviceInfo& deviceInfo) override {}
|
||||
void OnDeviceInfoChanged(const DistributedHardware::DmDeviceInfo& deviceInfo) override {}
|
||||
};
|
||||
|
||||
class DMSNetworkAdapterTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
static bool isCaseDone_;
|
||||
static std::mutex caseDoneLock_;
|
||||
static std::condition_variable caseDoneCondition_;
|
||||
};
|
||||
|
||||
bool DMSNetworkAdapterTest::isCaseDone_ = false;
|
||||
std::mutex DMSNetworkAdapterTest::caseDoneLock_;
|
||||
std::condition_variable DMSNetworkAdapterTest::caseDoneCondition_;
|
||||
|
||||
void DMSNetworkAdapterTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DMSNetworkAdapterTest::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();
|
||||
};
|
||||
if (DnetworkAdapter::GetInstance()->dnetworkHandler_ != nullptr) {
|
||||
DnetworkAdapter::GetInstance()->dnetworkHandler_->PostTask(caseDoneNotifyTask);
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock(caseDoneLock_);
|
||||
caseDoneCondition_.wait_for(lock, std::chrono::milliseconds(MAX_WAIT_TIME),
|
||||
[&] () { return isCaseDone_; });
|
||||
}
|
||||
|
||||
void DMSNetworkAdapterTest::SetUp()
|
||||
@ -143,7 +176,6 @@ HWTEST_F(DMSNetworkAdapterTest, testGetUuidByNetworkId003, TestSize.Level3)
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, OnDeviceOnline_001, TestSize.Level3)
|
||||
{
|
||||
DnetworkAdapter::GetInstance()->Init();
|
||||
DistributedHardware::DmDeviceInfo deviceInfo;
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceOnline(deviceInfo);
|
||||
@ -158,10 +190,9 @@ HWTEST_F(DMSNetworkAdapterTest, OnDeviceOnline_001, TestSize.Level3)
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, OnDeviceOnline_002, TestSize.Level3)
|
||||
{
|
||||
DnetworkAdapter::GetInstance()->Init();
|
||||
DistributedHardware::DmDeviceInfo deviceInfo;
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
DnetworkAdapter::listenerSet_.insert(deviceNodeListener);
|
||||
DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceOnline(deviceInfo);
|
||||
EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 1);
|
||||
@ -175,7 +206,6 @@ HWTEST_F(DMSNetworkAdapterTest, OnDeviceOnline_002, TestSize.Level3)
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, OnDeviceOffline_001, TestSize.Level3)
|
||||
{
|
||||
DnetworkAdapter::GetInstance()->Init();
|
||||
DistributedHardware::DmDeviceInfo deviceInfo;
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceOffline(deviceInfo);
|
||||
@ -190,10 +220,9 @@ HWTEST_F(DMSNetworkAdapterTest, OnDeviceOffline_001, TestSize.Level3)
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, OnDeviceOffline_002, TestSize.Level3)
|
||||
{
|
||||
DnetworkAdapter::GetInstance()->Init();
|
||||
DistributedHardware::DmDeviceInfo deviceInfo;
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
DnetworkAdapter::listenerSet_.insert(deviceNodeListener);
|
||||
DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceOffline(deviceInfo);
|
||||
EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 1);
|
||||
@ -207,11 +236,12 @@ HWTEST_F(DMSNetworkAdapterTest, OnDeviceOffline_002, TestSize.Level3)
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_001, TestSize.Level3)
|
||||
{
|
||||
DnetworkAdapter::GetInstance()->Init();
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
std::shared_ptr<AppExecFwk::EventHandler> dnetworkHandler = DnetworkAdapter::GetInstance()->dnetworkHandler_;
|
||||
DnetworkAdapter::GetInstance()->dnetworkHandler_ = nullptr;
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
bool res = DnetworkAdapter::GetInstance()->AddDeviceChangeListener(deviceNodeListener);
|
||||
DnetworkAdapter::GetInstance()->dnetworkHandler_ = dnetworkHandler;
|
||||
EXPECT_EQ(res, false);
|
||||
}
|
||||
|
||||
@ -223,11 +253,10 @@ HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_001, TestSize.Level3)
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_002, TestSize.Level3)
|
||||
{
|
||||
DnetworkAdapter::GetInstance()->Init();
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
std::shared_ptr<DeviceListener> oldDeviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
|
||||
std::shared_ptr<DeviceListener> oldDeviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
DnetworkAdapter::listenerSet_.insert(oldDeviceNodeListener);
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
bool res = DnetworkAdapter::GetInstance()->AddDeviceChangeListener(deviceNodeListener);
|
||||
EXPECT_EQ(res, true);
|
||||
}
|
||||
@ -240,9 +269,8 @@ HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_002, TestSize.Level3)
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_003, TestSize.Level3)
|
||||
{
|
||||
DnetworkAdapter::GetInstance()->Init();
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
bool res = DnetworkAdapter::GetInstance()->AddDeviceChangeListener(deviceNodeListener);
|
||||
EXPECT_EQ(res, true);
|
||||
}
|
||||
@ -255,9 +283,8 @@ HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_003, TestSize.Level3)
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_004, TestSize.Level3)
|
||||
{
|
||||
DnetworkAdapter::GetInstance()->Init();
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
DnetworkAdapter::listenerSet_.insert(deviceNodeListener);
|
||||
bool res = DnetworkAdapter::GetInstance()->AddDeviceChangeListener(deviceNodeListener);
|
||||
EXPECT_EQ(res, true);
|
||||
@ -271,9 +298,8 @@ HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_004, TestSize.Level3)
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, RemoveDeviceChangeListener_001, TestSize.Level3)
|
||||
{
|
||||
DnetworkAdapter::GetInstance()->Init();
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
DnetworkAdapter::GetInstance()->RemoveDeviceChangeListener(deviceNodeListener);
|
||||
EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 0);
|
||||
}
|
||||
@ -286,11 +312,10 @@ HWTEST_F(DMSNetworkAdapterTest, RemoveDeviceChangeListener_001, TestSize.Level3)
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, RemoveDeviceChangeListener_002, TestSize.Level3)
|
||||
{
|
||||
DnetworkAdapter::GetInstance()->Init();
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
std::shared_ptr<DeviceListener> oldDeviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
|
||||
std::shared_ptr<DeviceListener> oldDeviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
DnetworkAdapter::listenerSet_.insert(oldDeviceNodeListener);
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
DnetworkAdapter::GetInstance()->RemoveDeviceChangeListener(deviceNodeListener);
|
||||
EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 1);
|
||||
}
|
||||
|
@ -24,6 +24,9 @@ namespace DistributedSchedule {
|
||||
using namespace std;
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
namespace {
|
||||
constexpr int32_t MAX_WAIT_TIME = 10000;
|
||||
}
|
||||
|
||||
class MockDmsNotifier : public DmsNotifier {
|
||||
public:
|
||||
@ -77,8 +80,25 @@ void DtbschedmgrDeviceInfoStorageTest::SetUpTestCase()
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest::SetUpTestCase" << std::endl;
|
||||
}
|
||||
|
||||
bool DtbschedmgrDeviceInfoStorageTest::isCaseDone_ = false;
|
||||
std::mutex DtbschedmgrDeviceInfoStorageTest::caseDoneLock_;
|
||||
std::condition_variable DtbschedmgrDeviceInfoStorageTest::caseDoneCondition_;
|
||||
|
||||
void DtbschedmgrDeviceInfoStorageTest::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();
|
||||
};
|
||||
if (DtbschedmgrDeviceInfoStorage::GetInstance().networkIdMgrHandler_ != nullptr) {
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().networkIdMgrHandler_->PostTask(caseDoneNotifyTask);
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock(caseDoneLock_);
|
||||
caseDoneCondition_.wait_for(lock, std::chrono::milliseconds(MAX_WAIT_TIME),
|
||||
[&] () { return isCaseDone_; });
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest::TearDownTestCase" << std::endl;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,8 @@
|
||||
#ifndef OHOS_DMSFWK_BASE_DTBSCHEDMGR_DEVICE_INFO_STORAGE_TEST_H
|
||||
#define OHOS_DMSFWK_BASE_DTBSCHEDMGR_DEVICE_INFO_STORAGE_TEST_H
|
||||
|
||||
#include <condition_variable>
|
||||
#include <shared_mutex>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#define private public
|
||||
@ -30,6 +32,9 @@ public:
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
static bool isCaseDone_;
|
||||
static std::mutex caseDoneLock_;
|
||||
static std::condition_variable caseDoneCondition_;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -28,26 +28,32 @@ config("test_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"//foundation/ability/dmsfwk/utils/native/include",
|
||||
"//foundation/ability/dmsfwk/services/dtbschedmgr/include",
|
||||
"//foundation/ability/dmsfwk/services/dtbschedmgr/test/unittest",
|
||||
]
|
||||
}
|
||||
|
||||
dtbabilitymgr_external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_runtime:ability_manager",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libnativetoken",
|
||||
"access_token:libtoken_setproc",
|
||||
"c_utils:utils",
|
||||
"device_auth:deviceauth_sdk",
|
||||
"device_manager:devicemanagersdk",
|
||||
"eventhandler:libeventhandler",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"kv_store:distributeddata_inner",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
dtbabilitymgr_public_deps = [
|
||||
"//foundation/ability/dmsfwk/services/base:dmsbaseinner",
|
||||
"//foundation/ability/dmsfwk/services/dtbschedmgr:distributedschedsvr",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//third_party/libxml2:libxml2",
|
||||
@ -109,6 +115,7 @@ ohos_unittest("distributedabilitymanagerservicetest") {
|
||||
":test_config",
|
||||
"${distributed_service}/dtbschedmgr/test/resource:coverage_flags",
|
||||
]
|
||||
ldflags = [ "-rdynamic" ]
|
||||
configs += dtbabilitymgr_configs
|
||||
if (is_standard_system) {
|
||||
external_deps = dtbabilitymgr_external_deps
|
||||
|
@ -14,11 +14,12 @@
|
||||
*/
|
||||
#include "distributed_ability_manager_service_test.h"
|
||||
|
||||
#define private public
|
||||
#include "distributed_ability_manager_service.h"
|
||||
#undef private
|
||||
#include <thread>
|
||||
#include "distributed_sched_util.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#define private public
|
||||
#include "mission/distributed_sched_mission_manager.h"
|
||||
#undef private
|
||||
#include "test_log.h"
|
||||
|
||||
using namespace testing;
|
||||
@ -27,20 +28,43 @@ using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
constexpr int32_t DISTRIBUTED_SCHED_SA_ID = 1401;
|
||||
constexpr int32_t GET_DISTRIBUTED_COMPONENT_LIST_REQUEST_CODE = 161;
|
||||
constexpr int32_t UPDATE_CONNECT_STATUS = 504;
|
||||
constexpr int32_t INVALID_CODE = -1;
|
||||
const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
|
||||
constexpr int32_t DISTRIBUTED_SCHED_SA_ID = 1401;
|
||||
constexpr int32_t GET_DISTRIBUTED_COMPONENT_LIST_REQUEST_CODE = 161;
|
||||
constexpr int32_t UPDATE_CONNECT_STATUS = 504;
|
||||
constexpr int32_t INVALID_CODE = -1;
|
||||
constexpr int32_t MAX_WAIT_TIME = 10000;
|
||||
const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
|
||||
}
|
||||
|
||||
sptr<DistributedAbilityManagerService> DistributedAbilityManagerServiceTest::dtbabilitymgrService_;
|
||||
bool DistributedAbilityManagerServiceTest::isCaseDone_ = false;
|
||||
std::mutex DistributedAbilityManagerServiceTest::caseDoneLock_;
|
||||
std::condition_variable DistributedAbilityManagerServiceTest::caseDoneCondition_;
|
||||
|
||||
void DistributedAbilityManagerServiceTest::SetUpTestCase()
|
||||
{
|
||||
dtbabilitymgrService_ = new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest::SetUpTestCase" << std::endl;
|
||||
}
|
||||
|
||||
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();
|
||||
};
|
||||
if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ != nullptr) {
|
||||
std::shared_ptr<AppExecFwk::EventHandler> dmsDataStorageHandler =
|
||||
DistributedSchedMissionManager::GetInstance().distributedDataStorage_->dmsDataStorageHandler_;
|
||||
if (dmsDataStorageHandler != nullptr) {
|
||||
dmsDataStorageHandler->PostTask(caseDoneNotifyTask);
|
||||
}
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(caseDoneLock_);
|
||||
caseDoneCondition_.wait_for(lock, std::chrono::milliseconds(MAX_WAIT_TIME),
|
||||
[&] () { return isCaseDone_; });
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest::TearDownTestCase" << std::endl;
|
||||
}
|
||||
|
||||
@ -63,9 +87,11 @@ void DistributedAbilityManagerServiceTest::TearDown()
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, IsDistributedSchedLoaded_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest IsDistributedSchedLoaded_001 start" << std::endl;
|
||||
sptr<DistributedAbilityManagerService> dtbabilitymgrService =
|
||||
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
|
||||
int32_t result = dtbabilitymgrService->IsDistributedSchedLoaded();
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
int32_t result = dtbabilitymgrService_->IsDistributedSchedLoaded();
|
||||
EXPECT_EQ(false, result);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest IsDistributedSchedLoaded_001 end" << std::endl;
|
||||
}
|
||||
@ -78,13 +104,15 @@ HWTEST_F(DistributedAbilityManagerServiceTest, IsDistributedSchedLoaded_001, Tes
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_001 start" << std::endl;
|
||||
sptr<DistributedAbilityManagerService> dtbabilitymgrService =
|
||||
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
int32_t result = dtbabilitymgrService->GetDistributedComponentListInner(data, reply, option);
|
||||
int32_t result = dtbabilitymgrService_->GetDistributedComponentListInner(data, reply, option);
|
||||
EXPECT_EQ(ERR_NONE, result);
|
||||
result = reply.ReadInt32();
|
||||
EXPECT_EQ(ERR_NONE, result);
|
||||
@ -103,15 +131,17 @@ HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_002 start" << std::endl;
|
||||
sptr<DistributedAbilityManagerService> dtbabilitymgrService =
|
||||
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
bool result1 = dtbabilitymgrService->InitDmsImplFunc();
|
||||
bool result1 = dtbabilitymgrService_->InitDmsImplFunc();
|
||||
EXPECT_EQ(true, result1);
|
||||
int32_t result2 = dtbabilitymgrService->GetDistributedComponentListInner(data, reply, option);
|
||||
int32_t result2 = dtbabilitymgrService_->GetDistributedComponentListInner(data, reply, option);
|
||||
EXPECT_EQ(ERR_NONE, result2);
|
||||
result2 = reply.ReadInt32();
|
||||
EXPECT_EQ(ERR_NONE, result2);
|
||||
@ -130,12 +160,14 @@ HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_003 start" << std::endl;
|
||||
sptr<DistributedAbilityManagerService> dtbabilitymgrService =
|
||||
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int32_t result = dtbabilitymgrService->GetDistributedComponentListInner(data, reply, option);
|
||||
int32_t result = dtbabilitymgrService_->GetDistributedComponentListInner(data, reply, option);
|
||||
EXPECT_EQ(DMS_PERMISSION_DENIED, result);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_003 end" << std::endl;
|
||||
}
|
||||
@ -149,13 +181,15 @@ HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_001 start" << std::endl;
|
||||
sptr<DistributedAbilityManagerService> dtbabilitymgrService =
|
||||
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
int32_t result = dtbabilitymgrService->OnRemoteRequest(
|
||||
int32_t result = dtbabilitymgrService_->OnRemoteRequest(
|
||||
GET_DISTRIBUTED_COMPONENT_LIST_REQUEST_CODE, data, reply, option);
|
||||
EXPECT_EQ(ERR_NONE, result);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_001 end" << std::endl;
|
||||
@ -170,13 +204,15 @@ HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_001, TestSize.Lev
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_002 start" << std::endl;
|
||||
sptr<DistributedAbilityManagerService> dtbabilitymgrService =
|
||||
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
int32_t result = dtbabilitymgrService->OnRemoteRequest(INVALID_CODE, data, reply, option);
|
||||
int32_t result = dtbabilitymgrService_->OnRemoteRequest(INVALID_CODE, data, reply, option);
|
||||
EXPECT_NE(ERR_NONE, result);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_002 end" << std::endl;
|
||||
}
|
||||
@ -190,12 +226,14 @@ HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_002, TestSize.Lev
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_003 start" << std::endl;
|
||||
sptr<DistributedAbilityManagerService> dtbabilitymgrService =
|
||||
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int32_t result = dtbabilitymgrService->OnRemoteRequest(UPDATE_CONNECT_STATUS, data, reply, option);
|
||||
int32_t result = dtbabilitymgrService_->OnRemoteRequest(UPDATE_CONNECT_STATUS, data, reply, option);
|
||||
EXPECT_EQ(DMS_PERMISSION_DENIED, result);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_003 end" << std::endl;
|
||||
}
|
||||
@ -209,13 +247,15 @@ HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_003, TestSize.Lev
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_004, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_004 start" << std::endl;
|
||||
sptr<DistributedAbilityManagerService> dtbabilitymgrService =
|
||||
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
int32_t result = dtbabilitymgrService->OnRemoteRequest(UPDATE_CONNECT_STATUS, data, reply, option);
|
||||
int32_t result = dtbabilitymgrService_->OnRemoteRequest(UPDATE_CONNECT_STATUS, data, reply, option);
|
||||
EXPECT_EQ(DMS_PERMISSION_DENIED, result);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_004 end" << std::endl;
|
||||
}
|
||||
@ -228,14 +268,16 @@ HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_004, TestSize.Lev
|
||||
HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_005, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_005 start" << std::endl;
|
||||
if (dtbabilitymgrService_ == nullptr) {
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
DistributedSchedUtil::MockPermission();
|
||||
sptr<DistributedAbilityManagerService> dtbabilitymgrService =
|
||||
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
int32_t result = dtbabilitymgrService->OnRemoteRequest(UPDATE_CONNECT_STATUS, data, reply, option);
|
||||
int32_t result = dtbabilitymgrService_->OnRemoteRequest(UPDATE_CONNECT_STATUS, data, reply, option);
|
||||
EXPECT_NE(ERR_NONE, result);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_005 end" << std::endl;
|
||||
}
|
||||
|
@ -16,6 +16,11 @@
|
||||
#ifndef OHOS_DISTRIBUTED_ABILITY_MANAGER_SERVICE_TEST_H
|
||||
#define OHOS_DISTRIBUTED_ABILITY_MANAGER_SERVICE_TEST_H
|
||||
|
||||
#include <condition_variable>
|
||||
#include <shared_mutex>
|
||||
#define private public
|
||||
#include "distributed_ability_manager_service.h"
|
||||
#undef private
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -26,6 +31,10 @@ public:
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
static bool isCaseDone_;
|
||||
static std::mutex caseDoneLock_;
|
||||
static std::condition_variable caseDoneCondition_;
|
||||
static sptr<DistributedAbilityManagerService> dtbabilitymgrService_;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user