修复测试用例crash问题

Signed-off-by: wangyang2022 <wangyang412@huawei.com>
Change-Id: Ic47f67eb3e58055d2d16de6b3515423f28fdde9f
This commit is contained in:
wangyang2022 2022-11-10 09:57:57 +08:00
parent 008976d73f
commit dc74f99533
6 changed files with 164 additions and 56 deletions

View File

@ -15,6 +15,8 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include <condition_variable>
#include <shared_mutex>
#include <thread> #include <thread>
#define private public #define private public
#include "adapter/dnetwork_adapter.h" #include "adapter/dnetwork_adapter.h"
@ -28,24 +30,55 @@ using namespace testing::ext;
namespace { namespace {
const std::string NETWORKID = "1234567"; const std::string NETWORKID = "1234567";
constexpr int32_t SLEEP_TIME = 2000; constexpr int32_t SLEEP_TIME = 2000;
constexpr int32_t MAX_WAIT_TIME = 10000;
} }
namespace OHOS { namespace OHOS {
namespace DistributedSchedule { 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 { class DMSNetworkAdapterTest : public testing::Test {
public: public:
static void SetUpTestCase(); static void SetUpTestCase();
static void TearDownTestCase(); static void TearDownTestCase();
void SetUp(); void SetUp();
void TearDown(); 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::SetUpTestCase()
{ {
} }
void DMSNetworkAdapterTest::TearDownTestCase() 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() void DMSNetworkAdapterTest::SetUp()
@ -143,7 +176,6 @@ HWTEST_F(DMSNetworkAdapterTest, testGetUuidByNetworkId003, TestSize.Level3)
*/ */
HWTEST_F(DMSNetworkAdapterTest, OnDeviceOnline_001, TestSize.Level3) HWTEST_F(DMSNetworkAdapterTest, OnDeviceOnline_001, TestSize.Level3)
{ {
DnetworkAdapter::GetInstance()->Init();
DistributedHardware::DmDeviceInfo deviceInfo; DistributedHardware::DmDeviceInfo deviceInfo;
DnetworkAdapter::listenerSet_.clear(); DnetworkAdapter::listenerSet_.clear();
DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceOnline(deviceInfo); DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceOnline(deviceInfo);
@ -158,10 +190,9 @@ HWTEST_F(DMSNetworkAdapterTest, OnDeviceOnline_001, TestSize.Level3)
*/ */
HWTEST_F(DMSNetworkAdapterTest, OnDeviceOnline_002, TestSize.Level3) HWTEST_F(DMSNetworkAdapterTest, OnDeviceOnline_002, TestSize.Level3)
{ {
DnetworkAdapter::GetInstance()->Init();
DistributedHardware::DmDeviceInfo deviceInfo; DistributedHardware::DmDeviceInfo deviceInfo;
DnetworkAdapter::listenerSet_.clear(); 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::listenerSet_.insert(deviceNodeListener);
DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceOnline(deviceInfo); DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceOnline(deviceInfo);
EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 1); EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 1);
@ -175,7 +206,6 @@ HWTEST_F(DMSNetworkAdapterTest, OnDeviceOnline_002, TestSize.Level3)
*/ */
HWTEST_F(DMSNetworkAdapterTest, OnDeviceOffline_001, TestSize.Level3) HWTEST_F(DMSNetworkAdapterTest, OnDeviceOffline_001, TestSize.Level3)
{ {
DnetworkAdapter::GetInstance()->Init();
DistributedHardware::DmDeviceInfo deviceInfo; DistributedHardware::DmDeviceInfo deviceInfo;
DnetworkAdapter::listenerSet_.clear(); DnetworkAdapter::listenerSet_.clear();
DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceOffline(deviceInfo); DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceOffline(deviceInfo);
@ -190,10 +220,9 @@ HWTEST_F(DMSNetworkAdapterTest, OnDeviceOffline_001, TestSize.Level3)
*/ */
HWTEST_F(DMSNetworkAdapterTest, OnDeviceOffline_002, TestSize.Level3) HWTEST_F(DMSNetworkAdapterTest, OnDeviceOffline_002, TestSize.Level3)
{ {
DnetworkAdapter::GetInstance()->Init();
DistributedHardware::DmDeviceInfo deviceInfo; DistributedHardware::DmDeviceInfo deviceInfo;
DnetworkAdapter::listenerSet_.clear(); 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::listenerSet_.insert(deviceNodeListener);
DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceOffline(deviceInfo); DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceOffline(deviceInfo);
EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 1); EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 1);
@ -207,11 +236,12 @@ HWTEST_F(DMSNetworkAdapterTest, OnDeviceOffline_002, TestSize.Level3)
*/ */
HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_001, TestSize.Level3) HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_001, TestSize.Level3)
{ {
DnetworkAdapter::GetInstance()->Init();
DnetworkAdapter::listenerSet_.clear(); DnetworkAdapter::listenerSet_.clear();
std::shared_ptr<AppExecFwk::EventHandler> dnetworkHandler = DnetworkAdapter::GetInstance()->dnetworkHandler_;
DnetworkAdapter::GetInstance()->dnetworkHandler_ = nullptr; 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); bool res = DnetworkAdapter::GetInstance()->AddDeviceChangeListener(deviceNodeListener);
DnetworkAdapter::GetInstance()->dnetworkHandler_ = dnetworkHandler;
EXPECT_EQ(res, false); EXPECT_EQ(res, false);
} }
@ -223,11 +253,10 @@ HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_001, TestSize.Level3)
*/ */
HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_002, TestSize.Level3) HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_002, TestSize.Level3)
{ {
DnetworkAdapter::GetInstance()->Init();
DnetworkAdapter::listenerSet_.clear(); 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); 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); bool res = DnetworkAdapter::GetInstance()->AddDeviceChangeListener(deviceNodeListener);
EXPECT_EQ(res, true); EXPECT_EQ(res, true);
} }
@ -240,9 +269,8 @@ HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_002, TestSize.Level3)
*/ */
HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_003, TestSize.Level3) HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_003, TestSize.Level3)
{ {
DnetworkAdapter::GetInstance()->Init();
DnetworkAdapter::listenerSet_.clear(); 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); bool res = DnetworkAdapter::GetInstance()->AddDeviceChangeListener(deviceNodeListener);
EXPECT_EQ(res, true); EXPECT_EQ(res, true);
} }
@ -255,9 +283,8 @@ HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_003, TestSize.Level3)
*/ */
HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_004, TestSize.Level3) HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_004, TestSize.Level3)
{ {
DnetworkAdapter::GetInstance()->Init();
DnetworkAdapter::listenerSet_.clear(); 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::listenerSet_.insert(deviceNodeListener);
bool res = DnetworkAdapter::GetInstance()->AddDeviceChangeListener(deviceNodeListener); bool res = DnetworkAdapter::GetInstance()->AddDeviceChangeListener(deviceNodeListener);
EXPECT_EQ(res, true); EXPECT_EQ(res, true);
@ -271,9 +298,8 @@ HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_004, TestSize.Level3)
*/ */
HWTEST_F(DMSNetworkAdapterTest, RemoveDeviceChangeListener_001, TestSize.Level3) HWTEST_F(DMSNetworkAdapterTest, RemoveDeviceChangeListener_001, TestSize.Level3)
{ {
DnetworkAdapter::GetInstance()->Init();
DnetworkAdapter::listenerSet_.clear(); 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); DnetworkAdapter::GetInstance()->RemoveDeviceChangeListener(deviceNodeListener);
EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 0); EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 0);
} }
@ -286,11 +312,10 @@ HWTEST_F(DMSNetworkAdapterTest, RemoveDeviceChangeListener_001, TestSize.Level3)
*/ */
HWTEST_F(DMSNetworkAdapterTest, RemoveDeviceChangeListener_002, TestSize.Level3) HWTEST_F(DMSNetworkAdapterTest, RemoveDeviceChangeListener_002, TestSize.Level3)
{ {
DnetworkAdapter::GetInstance()->Init();
DnetworkAdapter::listenerSet_.clear(); 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); 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); DnetworkAdapter::GetInstance()->RemoveDeviceChangeListener(deviceNodeListener);
EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 1); EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 1);
} }

View File

@ -24,6 +24,9 @@ namespace DistributedSchedule {
using namespace std; using namespace std;
using namespace testing; using namespace testing;
using namespace testing::ext; using namespace testing::ext;
namespace {
constexpr int32_t MAX_WAIT_TIME = 10000;
}
class MockDmsNotifier : public DmsNotifier { class MockDmsNotifier : public DmsNotifier {
public: public:
@ -77,8 +80,25 @@ void DtbschedmgrDeviceInfoStorageTest::SetUpTestCase()
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest::SetUpTestCase" << std::endl; DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest::SetUpTestCase" << std::endl;
} }
bool DtbschedmgrDeviceInfoStorageTest::isCaseDone_ = false;
std::mutex DtbschedmgrDeviceInfoStorageTest::caseDoneLock_;
std::condition_variable DtbschedmgrDeviceInfoStorageTest::caseDoneCondition_;
void DtbschedmgrDeviceInfoStorageTest::TearDownTestCase() 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; DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest::TearDownTestCase" << std::endl;
} }

View File

@ -16,6 +16,8 @@
#ifndef OHOS_DMSFWK_BASE_DTBSCHEDMGR_DEVICE_INFO_STORAGE_TEST_H #ifndef OHOS_DMSFWK_BASE_DTBSCHEDMGR_DEVICE_INFO_STORAGE_TEST_H
#define 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" #include "gtest/gtest.h"
#define private public #define private public
@ -30,6 +32,9 @@ public:
static void TearDownTestCase(); static void TearDownTestCase();
void SetUp(); void SetUp();
void TearDown(); void TearDown();
static bool isCaseDone_;
static std::mutex caseDoneLock_;
static std::condition_variable caseDoneCondition_;
}; };
} // namespace DistributedSchedule } // namespace DistributedSchedule
} // namespace OHOS } // namespace OHOS

View File

@ -28,26 +28,32 @@ config("test_config") {
visibility = [ ":*" ] visibility = [ ":*" ]
include_dirs = [ include_dirs = [
"//foundation/ability/dmsfwk/utils/native/include", "//foundation/ability/dmsfwk/utils/native/include",
"//foundation/ability/dmsfwk/services/dtbschedmgr/include",
"//foundation/ability/dmsfwk/services/dtbschedmgr/test/unittest", "//foundation/ability/dmsfwk/services/dtbschedmgr/test/unittest",
] ]
} }
dtbabilitymgr_external_deps = [ dtbabilitymgr_external_deps = [
"ability_base:want",
"ability_runtime:ability_manager",
"access_token:libaccesstoken_sdk", "access_token:libaccesstoken_sdk",
"access_token:libnativetoken", "access_token:libnativetoken",
"access_token:libtoken_setproc", "access_token:libtoken_setproc",
"c_utils:utils", "c_utils:utils",
"device_auth:deviceauth_sdk",
"device_manager:devicemanagersdk", "device_manager:devicemanagersdk",
"eventhandler:libeventhandler", "eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog", "hiviewdfx_hilog_native:libhilog",
"init:libbegetutil", "init:libbegetutil",
"ipc:ipc_core", "ipc:ipc_core",
"kv_store:distributeddata_inner",
"safwk:system_ability_fwk", "safwk:system_ability_fwk",
"samgr:samgr_proxy", "samgr:samgr_proxy",
] ]
dtbabilitymgr_public_deps = [ dtbabilitymgr_public_deps = [
"//foundation/ability/dmsfwk/services/base:dmsbaseinner", "//foundation/ability/dmsfwk/services/base:dmsbaseinner",
"//foundation/ability/dmsfwk/services/dtbschedmgr:distributedschedsvr",
"//third_party/googletest:gmock_main", "//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main", "//third_party/googletest:gtest_main",
"//third_party/libxml2:libxml2", "//third_party/libxml2:libxml2",
@ -109,6 +115,7 @@ ohos_unittest("distributedabilitymanagerservicetest") {
":test_config", ":test_config",
"${distributed_service}/dtbschedmgr/test/resource:coverage_flags", "${distributed_service}/dtbschedmgr/test/resource:coverage_flags",
] ]
ldflags = [ "-rdynamic" ]
configs += dtbabilitymgr_configs configs += dtbabilitymgr_configs
if (is_standard_system) { if (is_standard_system) {
external_deps = dtbabilitymgr_external_deps external_deps = dtbabilitymgr_external_deps

View File

@ -14,11 +14,12 @@
*/ */
#include "distributed_ability_manager_service_test.h" #include "distributed_ability_manager_service_test.h"
#define private public #include <thread>
#include "distributed_ability_manager_service.h"
#undef private
#include "distributed_sched_util.h" #include "distributed_sched_util.h"
#include "dtbschedmgr_log.h" #include "dtbschedmgr_log.h"
#define private public
#include "mission/distributed_sched_mission_manager.h"
#undef private
#include "test_log.h" #include "test_log.h"
using namespace testing; using namespace testing;
@ -27,20 +28,43 @@ using namespace testing::ext;
namespace OHOS { namespace OHOS {
namespace DistributedSchedule { namespace DistributedSchedule {
namespace { namespace {
constexpr int32_t DISTRIBUTED_SCHED_SA_ID = 1401; constexpr int32_t DISTRIBUTED_SCHED_SA_ID = 1401;
constexpr int32_t GET_DISTRIBUTED_COMPONENT_LIST_REQUEST_CODE = 161; constexpr int32_t GET_DISTRIBUTED_COMPONENT_LIST_REQUEST_CODE = 161;
constexpr int32_t UPDATE_CONNECT_STATUS = 504; constexpr int32_t UPDATE_CONNECT_STATUS = 504;
constexpr int32_t INVALID_CODE = -1; constexpr int32_t INVALID_CODE = -1;
const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken"; 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() void DistributedAbilityManagerServiceTest::SetUpTestCase()
{ {
dtbabilitymgrService_ = new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
DTEST_LOG << "DistributedAbilityManagerServiceTest::SetUpTestCase" << std::endl; DTEST_LOG << "DistributedAbilityManagerServiceTest::SetUpTestCase" << std::endl;
} }
void DistributedAbilityManagerServiceTest::TearDownTestCase() 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; DTEST_LOG << "DistributedAbilityManagerServiceTest::TearDownTestCase" << std::endl;
} }
@ -63,9 +87,11 @@ void DistributedAbilityManagerServiceTest::TearDown()
HWTEST_F(DistributedAbilityManagerServiceTest, IsDistributedSchedLoaded_001, TestSize.Level3) HWTEST_F(DistributedAbilityManagerServiceTest, IsDistributedSchedLoaded_001, TestSize.Level3)
{ {
DTEST_LOG << "DistributedAbilityManagerServiceTest IsDistributedSchedLoaded_001 start" << std::endl; DTEST_LOG << "DistributedAbilityManagerServiceTest IsDistributedSchedLoaded_001 start" << std::endl;
sptr<DistributedAbilityManagerService> dtbabilitymgrService = if (dtbabilitymgrService_ == nullptr) {
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true); DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
int32_t result = dtbabilitymgrService->IsDistributedSchedLoaded(); return;
}
int32_t result = dtbabilitymgrService_->IsDistributedSchedLoaded();
EXPECT_EQ(false, result); EXPECT_EQ(false, result);
DTEST_LOG << "DistributedAbilityManagerServiceTest IsDistributedSchedLoaded_001 end" << std::endl; 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) HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_001, TestSize.Level3)
{ {
DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_001 start" << std::endl; DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_001 start" << std::endl;
sptr<DistributedAbilityManagerService> dtbabilitymgrService = if (dtbabilitymgrService_ == nullptr) {
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true); DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
MessageParcel data; MessageParcel data;
MessageParcel reply; MessageParcel reply;
MessageOption option; MessageOption option;
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN); 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); EXPECT_EQ(ERR_NONE, result);
result = reply.ReadInt32(); result = reply.ReadInt32();
EXPECT_EQ(ERR_NONE, result); EXPECT_EQ(ERR_NONE, result);
@ -103,15 +131,17 @@ HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_
HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_002, TestSize.Level3) HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_002, TestSize.Level3)
{ {
DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_002 start" << std::endl; DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_002 start" << std::endl;
sptr<DistributedAbilityManagerService> dtbabilitymgrService = if (dtbabilitymgrService_ == nullptr) {
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true); DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
MessageParcel data; MessageParcel data;
MessageParcel reply; MessageParcel reply;
MessageOption option; MessageOption option;
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN); data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
bool result1 = dtbabilitymgrService->InitDmsImplFunc(); bool result1 = dtbabilitymgrService_->InitDmsImplFunc();
EXPECT_EQ(true, result1); 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); EXPECT_EQ(ERR_NONE, result2);
result2 = reply.ReadInt32(); result2 = reply.ReadInt32();
EXPECT_EQ(ERR_NONE, result2); EXPECT_EQ(ERR_NONE, result2);
@ -130,12 +160,14 @@ HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_
HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_003, TestSize.Level3) HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_003, TestSize.Level3)
{ {
DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_003 start" << std::endl; DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_003 start" << std::endl;
sptr<DistributedAbilityManagerService> dtbabilitymgrService = if (dtbabilitymgrService_ == nullptr) {
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true); DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
MessageParcel data; MessageParcel data;
MessageParcel reply; MessageParcel reply;
MessageOption option; MessageOption option;
int32_t result = dtbabilitymgrService->GetDistributedComponentListInner(data, reply, option); int32_t result = dtbabilitymgrService_->GetDistributedComponentListInner(data, reply, option);
EXPECT_EQ(DMS_PERMISSION_DENIED, result); EXPECT_EQ(DMS_PERMISSION_DENIED, result);
DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_003 end" << std::endl; DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_003 end" << std::endl;
} }
@ -149,13 +181,15 @@ HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_
HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_001, TestSize.Level3) HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_001, TestSize.Level3)
{ {
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_001 start" << std::endl; DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_001 start" << std::endl;
sptr<DistributedAbilityManagerService> dtbabilitymgrService = if (dtbabilitymgrService_ == nullptr) {
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true); DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
MessageParcel data; MessageParcel data;
MessageParcel reply; MessageParcel reply;
MessageOption option; MessageOption option;
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN); 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); GET_DISTRIBUTED_COMPONENT_LIST_REQUEST_CODE, data, reply, option);
EXPECT_EQ(ERR_NONE, result); EXPECT_EQ(ERR_NONE, result);
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_001 end" << std::endl; 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) HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_002, TestSize.Level3)
{ {
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_002 start" << std::endl; DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_002 start" << std::endl;
sptr<DistributedAbilityManagerService> dtbabilitymgrService = if (dtbabilitymgrService_ == nullptr) {
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true); DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
MessageParcel data; MessageParcel data;
MessageParcel reply; MessageParcel reply;
MessageOption option; MessageOption option;
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN); 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); EXPECT_NE(ERR_NONE, result);
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_002 end" << std::endl; 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) HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_003, TestSize.Level3)
{ {
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_003 start" << std::endl; DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_003 start" << std::endl;
sptr<DistributedAbilityManagerService> dtbabilitymgrService = if (dtbabilitymgrService_ == nullptr) {
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true); DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
MessageParcel data; MessageParcel data;
MessageParcel reply; MessageParcel reply;
MessageOption option; 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); EXPECT_EQ(DMS_PERMISSION_DENIED, result);
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_003 end" << std::endl; 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) HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_004, TestSize.Level3)
{ {
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_004 start" << std::endl; DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_004 start" << std::endl;
sptr<DistributedAbilityManagerService> dtbabilitymgrService = if (dtbabilitymgrService_ == nullptr) {
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true); DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
MessageParcel data; MessageParcel data;
MessageParcel reply; MessageParcel reply;
MessageOption option; MessageOption option;
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN); 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); EXPECT_EQ(DMS_PERMISSION_DENIED, result);
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_004 end" << std::endl; 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) HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_005, TestSize.Level3)
{ {
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_005 start" << std::endl; DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_005 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
DistributedSchedUtil::MockPermission(); DistributedSchedUtil::MockPermission();
sptr<DistributedAbilityManagerService> dtbabilitymgrService =
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
MessageParcel data; MessageParcel data;
MessageParcel reply; MessageParcel reply;
MessageOption option; MessageOption option;
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN); 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); EXPECT_NE(ERR_NONE, result);
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_005 end" << std::endl; DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_005 end" << std::endl;
} }

View File

@ -16,6 +16,11 @@
#ifndef OHOS_DISTRIBUTED_ABILITY_MANAGER_SERVICE_TEST_H #ifndef OHOS_DISTRIBUTED_ABILITY_MANAGER_SERVICE_TEST_H
#define 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" #include "gtest/gtest.h"
namespace OHOS { namespace OHOS {
@ -26,6 +31,10 @@ public:
static void TearDownTestCase(); static void TearDownTestCase();
void SetUp(); void SetUp();
void TearDown(); void TearDown();
static bool isCaseDone_;
static std::mutex caseDoneLock_;
static std::condition_variable caseDoneCondition_;
static sptr<DistributedAbilityManagerService> dtbabilitymgrService_;
}; };
} // namespace DistributedSchedule } // namespace DistributedSchedule
} // namespace OHOS } // namespace OHOS