mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 14:30:21 +00:00
commit
3f197826f9
@ -147,6 +147,10 @@ bool DtbschedmgrDeviceInfoStorage::WaitForDnetworkReady()
|
||||
void DtbschedmgrDeviceInfoStorage::RegisterUuidNetworkIdMap(const std::string& networkId)
|
||||
{
|
||||
std::string uuid = DnetworkAdapter::GetInstance()->GetUuidByNetworkId(networkId);
|
||||
if (uuid.empty()) {
|
||||
HILOGE("GetUuidByNetworkId return an empty uuid!");
|
||||
return;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> autoLock(uuidNetworkIdLock_);
|
||||
uuidNetworkIdMap_[uuid] = networkId;
|
||||
@ -156,6 +160,10 @@ void DtbschedmgrDeviceInfoStorage::RegisterUuidNetworkIdMap(const std::string& n
|
||||
void DtbschedmgrDeviceInfoStorage::UnregisterUuidNetworkIdMap(const std::string& networkId)
|
||||
{
|
||||
std::string uuid = DnetworkAdapter::GetInstance()->GetUuidByNetworkId(networkId);
|
||||
if (uuid.empty()) {
|
||||
HILOGE("GetUuidByNetworkId return an empty uuid");
|
||||
return;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> autoLock(uuidNetworkIdLock_);
|
||||
uuidNetworkIdMap_.erase(uuid);
|
||||
|
@ -20,9 +20,7 @@ module_output_path = "dmsfwk/distributed_base_svr_test"
|
||||
|
||||
distributed_service = "//foundation/ability/dmsfwk/services"
|
||||
|
||||
base_configs = [
|
||||
"${distributed_service}/dtbabilitymgr:distributed_ability_manager_config",
|
||||
]
|
||||
base_configs = [ "${distributed_service}/base:distributed_sched_config" ]
|
||||
|
||||
config("test_config") {
|
||||
visibility = [ ":*" ]
|
||||
@ -49,14 +47,20 @@ base_public_deps = [
|
||||
|
||||
ohos_unittest("dmsbasetest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "unittest/dms_network_adapter_test.cpp" ]
|
||||
sources = [
|
||||
"${distributed_service}/base/src/adapter/dnetwork_adapter.cpp",
|
||||
"${distributed_service}/base/src/deviceManager/dms_device_info.cpp",
|
||||
"${distributed_service}/base/src/distributed_device_node_listener.cpp",
|
||||
"${distributed_service}/base/src/dtbschedmgr_device_info_storage.cpp",
|
||||
"unittest/deviceManager/dms_device_info_test.cpp",
|
||||
"unittest/dms_network_adapter_test.cpp",
|
||||
"unittest/dtbschedmgr_device_info_storage_test.cpp",
|
||||
]
|
||||
configs = [
|
||||
":test_config",
|
||||
"//foundation/ability/dmsfwk/services/dtbschedmgr/test/resource:coverage_flags",
|
||||
]
|
||||
configs += base_configs
|
||||
deps =
|
||||
[ "${distributed_service}/dtbabilitymgr:distributed_ability_manager_svr" ]
|
||||
external_deps = base_external_deps
|
||||
public_deps = base_public_deps
|
||||
part_name = "dmsfwk"
|
||||
|
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "dms_device_info_test.h"
|
||||
|
||||
#include "deviceManager/dms_device_info.h"
|
||||
#include "parcel_helper.h"
|
||||
#include "test_log.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TAG = "DmsDeviceInfo";
|
||||
}
|
||||
void DmsDeviceInfoTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DmsDeviceInfoTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DmsDeviceInfoTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void DmsDeviceInfoTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testGet_001
|
||||
* @tc.desc: test Get functions.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DmsDeviceInfoTest, testGet_001, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DmsDeviceInfoTest testGet_001 begin" << std::endl;
|
||||
DmsDeviceInfo dmsDeviceInfo("invalid deviceName", 1, "invalid deivceId");
|
||||
/**
|
||||
* @tc.steps: step1. test GetDeviceName;
|
||||
*/
|
||||
EXPECT_EQ("invalid deviceName", dmsDeviceInfo.GetDeviceName());
|
||||
/**
|
||||
* @tc.steps: step2. test GetDeviceId;
|
||||
*/
|
||||
EXPECT_EQ("invalid deivceId", dmsDeviceInfo.GetDeviceId());
|
||||
/**
|
||||
* @tc.steps: step3. test GetDeviceType;
|
||||
*/
|
||||
EXPECT_EQ(1, dmsDeviceInfo.GetDeviceType());
|
||||
/**
|
||||
* @tc.steps: step4. test GetDeviceState;
|
||||
*/
|
||||
EXPECT_EQ(1, dmsDeviceInfo.GetDeviceState());
|
||||
/**
|
||||
* @tc.steps: step5. test Marshalling;
|
||||
*/
|
||||
Parcel parcel;
|
||||
std::u16string deviceId;
|
||||
std::u16string deviceName;
|
||||
int32_t deviceType;
|
||||
int32_t deviceState;
|
||||
EXPECT_TRUE(dmsDeviceInfo.Marshalling(parcel));
|
||||
PARCEL_READ_HELPER_NORET(parcel, String16, deviceId);
|
||||
PARCEL_READ_HELPER_NORET(parcel, String16, deviceName);
|
||||
PARCEL_READ_HELPER_NORET(parcel, Int32, deviceType);
|
||||
PARCEL_READ_HELPER_NORET(parcel, Int32, deviceState);
|
||||
EXPECT_FALSE(deviceId.empty());
|
||||
EXPECT_FALSE(deviceName.empty());
|
||||
EXPECT_EQ(1, deviceType);
|
||||
EXPECT_EQ(1, deviceState);
|
||||
DTEST_LOG << "DmsDeviceInfoTest testGet_001 end" << std::endl;
|
||||
}
|
||||
} // DistributedSchedule
|
||||
} // namespace OHOS
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef DMS_DEVICE_INFO_TEST_H
|
||||
#define DMS_DEVICE_INFO_TEST_H
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class DmsDeviceInfoTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif /* DMS_DEVICE_INFO_TEST_H */
|
||||
|
@ -15,8 +15,12 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <condition_variable>
|
||||
#include <shared_mutex>
|
||||
#include <thread>
|
||||
|
||||
#define private public
|
||||
#include "adapter/dnetwork_adapter.h"
|
||||
#undef private
|
||||
#include "dtbschedmgr_device_info_storage.h"
|
||||
|
||||
using namespace std;
|
||||
@ -26,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()
|
||||
@ -132,5 +167,157 @@ HWTEST_F(DMSNetworkAdapterTest, testGetUuidByNetworkId003, TestSize.Level3)
|
||||
std::string res = DnetworkAdapter::GetInstance()->GetUuidByNetworkId(NETWORKID);
|
||||
EXPECT_EQ(res, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnDeviceOnline_001
|
||||
* @tc.desc: listenerSet_ is empty
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, OnDeviceOnline_001, TestSize.Level3)
|
||||
{
|
||||
DistributedHardware::DmDeviceInfo deviceInfo;
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceOnline(deviceInfo);
|
||||
EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnDeviceOnline_002
|
||||
* @tc.desc: listenerSet_ is not empty
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, OnDeviceOnline_002, TestSize.Level3)
|
||||
{
|
||||
DistributedHardware::DmDeviceInfo deviceInfo;
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
DnetworkAdapter::listenerSet_.insert(deviceNodeListener);
|
||||
DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceOnline(deviceInfo);
|
||||
EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnDeviceOffline_001
|
||||
* @tc.desc: listenerSet_ is empty
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, OnDeviceOffline_001, TestSize.Level3)
|
||||
{
|
||||
DistributedHardware::DmDeviceInfo deviceInfo;
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceOffline(deviceInfo);
|
||||
EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnDeviceOffline_002
|
||||
* @tc.desc: listenerSet_ is not empty
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, OnDeviceOffline_002, TestSize.Level3)
|
||||
{
|
||||
DistributedHardware::DmDeviceInfo deviceInfo;
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
DnetworkAdapter::listenerSet_.insert(deviceNodeListener);
|
||||
DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceOffline(deviceInfo);
|
||||
EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddDeviceChangeListener_001
|
||||
* @tc.desc: dnetworkHandler_ is nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_001, TestSize.Level3)
|
||||
{
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
std::shared_ptr<AppExecFwk::EventHandler> dnetworkHandler = DnetworkAdapter::GetInstance()->dnetworkHandler_;
|
||||
DnetworkAdapter::GetInstance()->dnetworkHandler_ = nullptr;
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
bool res = DnetworkAdapter::GetInstance()->AddDeviceChangeListener(deviceNodeListener);
|
||||
DnetworkAdapter::GetInstance()->dnetworkHandler_ = dnetworkHandler;
|
||||
EXPECT_EQ(res, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddDeviceChangeListener_002
|
||||
* @tc.desc: deviceNodeListener is not exist
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_002, TestSize.Level3)
|
||||
{
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
std::shared_ptr<DeviceListener> oldDeviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
DnetworkAdapter::listenerSet_.insert(oldDeviceNodeListener);
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
bool res = DnetworkAdapter::GetInstance()->AddDeviceChangeListener(deviceNodeListener);
|
||||
EXPECT_EQ(res, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddDeviceChangeListener_003
|
||||
* @tc.desc: deviceNodeListener is not exist
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_003, TestSize.Level3)
|
||||
{
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
bool res = DnetworkAdapter::GetInstance()->AddDeviceChangeListener(deviceNodeListener);
|
||||
EXPECT_EQ(res, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddDeviceChangeListener_004
|
||||
* @tc.desc: deviceNodeListener is exist
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_004, TestSize.Level3)
|
||||
{
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
DnetworkAdapter::listenerSet_.insert(deviceNodeListener);
|
||||
bool res = DnetworkAdapter::GetInstance()->AddDeviceChangeListener(deviceNodeListener);
|
||||
EXPECT_EQ(res, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RemoveDeviceChangeListener_001
|
||||
* @tc.desc: listenerSet_ size is 0
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, RemoveDeviceChangeListener_001, TestSize.Level3)
|
||||
{
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
DnetworkAdapter::GetInstance()->RemoveDeviceChangeListener(deviceNodeListener);
|
||||
EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RemoveDeviceChangeListener_002
|
||||
* @tc.desc: listenerSet_ size is 1
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, RemoveDeviceChangeListener_002, TestSize.Level3)
|
||||
{
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
std::shared_ptr<DeviceListener> oldDeviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
DnetworkAdapter::listenerSet_.insert(oldDeviceNodeListener);
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
DnetworkAdapter::GetInstance()->RemoveDeviceChangeListener(deviceNodeListener);
|
||||
EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 1);
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -0,0 +1,432 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "dtbschedmgr_device_info_storage_test.h"
|
||||
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "test_log.h"
|
||||
#include <cstddef>
|
||||
|
||||
namespace OHOS {
|
||||
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:
|
||||
MockDmsNotifier() = default;
|
||||
~MockDmsNotifier() = default;
|
||||
|
||||
void DeviceOnlineNotify(const std::string& deviceId) override;
|
||||
void DeviceOfflineNotify(const std::string& deviceId) override;
|
||||
void ProcessNotifierDied(const sptr<IRemoteObject>& notifier) override;
|
||||
void ScheduleStartDeviceManager(const sptr<IRemoteObject>& appProxy, int32_t token,
|
||||
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr) override;
|
||||
int32_t OnDeviceConnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) override;
|
||||
int32_t OnDeviceDisconnect(int32_t token, const std::vector<std::string>& deviceIds) override;
|
||||
int32_t OnDeviceCancel() override;
|
||||
};
|
||||
|
||||
void MockDmsNotifier::DeviceOnlineNotify(const std::string& deviceId)
|
||||
{
|
||||
}
|
||||
|
||||
void MockDmsNotifier::DeviceOfflineNotify(const std::string& deviceId)
|
||||
{
|
||||
}
|
||||
|
||||
void MockDmsNotifier::ProcessNotifierDied(const sptr<IRemoteObject>& notifier)
|
||||
{
|
||||
}
|
||||
|
||||
void MockDmsNotifier::ScheduleStartDeviceManager(const sptr<IRemoteObject>& appProxy, int32_t token,
|
||||
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t MockDmsNotifier::OnDeviceConnect(int32_t token, const std::vector<ContinuationResult>& continuationResults)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t MockDmsNotifier::OnDeviceDisconnect(int32_t token, const std::vector<std::string>& deviceIds)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t MockDmsNotifier::OnDeviceCancel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void DtbschedmgrDeviceInfoStorageTest::SetUp()
|
||||
{
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest::SetUp" << std::endl;
|
||||
}
|
||||
|
||||
void DtbschedmgrDeviceInfoStorageTest::TearDown()
|
||||
{
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest::TearDown" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: InitTest_001
|
||||
* @tc.desc: test Init
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DtbschedmgrDeviceInfoStorageTest, InitTest_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest InitTest_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test Init with listener when initHandler_ is nullptr;
|
||||
*/
|
||||
sptr<DmsNotifier> listener = nullptr;
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().initHandler_ = nullptr;
|
||||
bool result = DtbschedmgrDeviceInfoStorage::GetInstance().Init(listener);
|
||||
EXPECT_TRUE(result);
|
||||
/**
|
||||
* @tc.steps: step2. test Init when initHandler_ is not nullptr;
|
||||
*/
|
||||
result = DtbschedmgrDeviceInfoStorage::GetInstance().Init();
|
||||
EXPECT_TRUE(result);
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest InitTest_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ConnectSoftbusTest_001
|
||||
* @tc.desc: test ConnectSoftbus
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DtbschedmgrDeviceInfoStorageTest, ConnectSoftbusTest_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest ConnectSoftbusTest_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test ConnectSoftbus;
|
||||
*/
|
||||
bool result = DtbschedmgrDeviceInfoStorage::GetInstance().ConnectSoftbus();
|
||||
EXPECT_TRUE(result);
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest ConnectSoftbusTest_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: InitNetworkIdManagerTest_001
|
||||
* @tc.desc: test InitNetworkIdManager
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DtbschedmgrDeviceInfoStorageTest, InitNetworkIdManagerTest_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest InitNetworkIdManagerTest_001 start" << std::endl;
|
||||
std::shared_ptr<DnetworkAdapter> dnetworkAdapter = DnetworkAdapter::GetInstance();
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().networkIdMgrHandler_ = nullptr;
|
||||
/**
|
||||
* @tc.steps: step1. test InitNetworkIdManager when networkIdMgrHandler_ is nullptr;
|
||||
*/
|
||||
bool result = DtbschedmgrDeviceInfoStorage::GetInstance().InitNetworkIdManager(dnetworkAdapter);
|
||||
EXPECT_TRUE(result);
|
||||
/**
|
||||
* @tc.steps: step2. test InitNetworkIdManager when networkIdMgrHandler_ is not nullptr;
|
||||
*/
|
||||
auto runner = AppExecFwk::EventRunner::Create("DmsNetworkIdManager");
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().networkIdMgrHandler_ =
|
||||
std::make_shared<AppExecFwk::EventHandler>(runner);
|
||||
result = DtbschedmgrDeviceInfoStorage::GetInstance().InitNetworkIdManager(dnetworkAdapter);
|
||||
EXPECT_TRUE(result);
|
||||
/**
|
||||
* @tc.steps: step3. test Stop when deviceNodeListener_ is nullptr;
|
||||
*/
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().deviceNodeListener_ = nullptr;
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().Stop();
|
||||
/**
|
||||
* @tc.steps: step4. test Stop when deviceNodeListener_ is not nullptr;
|
||||
*/
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().deviceNodeListener_ = std::make_shared<DistributedDeviceNodeListener>();
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().Stop();
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest InitNetworkIdManagerTest_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: WaitForDnetworkReadyTest_001
|
||||
* @tc.desc: test WaitForDnetworkReady
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DtbschedmgrDeviceInfoStorageTest, WaitForDnetworkReadyTest_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest WaitForDnetworkReadyTest_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test WaitForDnetworkReady;
|
||||
*/
|
||||
bool result = DtbschedmgrDeviceInfoStorage::GetInstance().WaitForDnetworkReady();
|
||||
EXPECT_TRUE(result);
|
||||
/**
|
||||
* @tc.steps: step2. test RegisterUuidNetworkIdMap;
|
||||
*/
|
||||
std::string networkId = "";
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().RegisterUuidNetworkIdMap(networkId);
|
||||
/**
|
||||
* @tc.steps: step3. test UnregisterUuidNetworkIdMap;
|
||||
*/
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().UnregisterUuidNetworkIdMap(networkId);
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest WaitForDnetworkReadyTest_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetDeviceIdSetTest_001
|
||||
* @tc.desc: test GetDeviceIdSet
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DtbschedmgrDeviceInfoStorageTest, GetDeviceIdSetTest_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetDeviceIdSetTest_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test GetDeviceIdSet;
|
||||
*/
|
||||
set<std::string> deviceIdSet;
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().GetDeviceIdSet(deviceIdSet);
|
||||
EXPECT_TRUE(deviceIdSet.empty());
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetDeviceIdSetTest_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetLocalDeviceFromDnetTest_001
|
||||
* @tc.desc: test GetLocalDeviceFromDnet
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DtbschedmgrDeviceInfoStorageTest, GetLocalDeviceFromDnetTest_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetLocalDeviceFromDnetTest_001 start" << std::endl;
|
||||
std::string deviceId;
|
||||
/**
|
||||
* @tc.steps: step1. test GetLocalDeviceFromDnet;
|
||||
*/
|
||||
bool result = DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
|
||||
EXPECT_TRUE(result);
|
||||
/**
|
||||
* @tc.steps: step2. test DeviceOnlineNotify when devInfo is nullptr;
|
||||
*/
|
||||
std::shared_ptr<DmsDeviceInfo> devInfo = nullptr;
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOnlineNotify(devInfo);
|
||||
/**
|
||||
* @tc.steps: step3. test DeviceOnlineNotify when networkIdMgrHandler_ is nullptr;
|
||||
*/
|
||||
deviceId = "invalid deviceId for DeviceOnlineNotify";
|
||||
std::string deviceName = "invalid deviceName for DeviceOnlineNotify";
|
||||
int32_t deviceType = 0;
|
||||
devInfo = make_shared<DmsDeviceInfo>(deviceName, deviceType, deviceId);
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().networkIdMgrHandler_ = nullptr;
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOnlineNotify(devInfo);
|
||||
/**
|
||||
* @tc.steps: step4. test DeviceOnlineNotify when listener_ is nullptr;
|
||||
*/
|
||||
auto runner = AppExecFwk::EventRunner::Create("DmsNetworkIdManager");
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().networkIdMgrHandler_ =
|
||||
std::make_shared<AppExecFwk::EventHandler>(runner);
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().listener_ = nullptr;
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOnlineNotify(devInfo);
|
||||
/**
|
||||
* @tc.steps: step5. test DeviceOnlineNotify when listener_ is not nullptr;
|
||||
*/
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().listener_ = new MockDmsNotifier();
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOnlineNotify(devInfo);
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetLocalDeviceFromDnetTest_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ClearAllDevicesTest_001
|
||||
* @tc.desc: test ClearAllDevices
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DtbschedmgrDeviceInfoStorageTest, ClearAllDevicesTest_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest ClearAllDevicesTest_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test ClearAllDevices;
|
||||
*/
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().ClearAllDevices();
|
||||
{
|
||||
lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
|
||||
EXPECT_TRUE(DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.empty());
|
||||
}
|
||||
/**
|
||||
* @tc.steps: step2. test DeviceOfflineNotify when deviceId is empty;
|
||||
*/
|
||||
std::string deviceId;
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOfflineNotify(deviceId);
|
||||
/**
|
||||
* @tc.steps: step3. test DeviceOfflineNotify when networkIdMgrHandler_ is nullptr;
|
||||
*/
|
||||
deviceId = "invalid deviceId for DeviceOnlineNotify";
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().networkIdMgrHandler_ = nullptr;
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOfflineNotify(deviceId);
|
||||
/**
|
||||
* @tc.steps: step4. test DeviceOfflineNotify when listener_ is nullptr;
|
||||
*/
|
||||
auto runner = AppExecFwk::EventRunner::Create("DmsNetworkIdManager");
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().networkIdMgrHandler_ =
|
||||
std::make_shared<AppExecFwk::EventHandler>(runner);
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().listener_ = nullptr;
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOfflineNotify(deviceId);
|
||||
/**
|
||||
* @tc.steps: step5. test DeviceOfflineNotify when listener_ is not nullptr;
|
||||
*/
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().listener_ = new MockDmsNotifier();
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOfflineNotify(deviceId);
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest ClearAllDevicesTest_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetDeviceInfoByIdTest_001
|
||||
* @tc.desc: test GetDeviceInfoById
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DtbschedmgrDeviceInfoStorageTest, GetDeviceInfoByIdTest_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetDeviceInfoByIdTest_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test GetDeviceInfoById when deviceId is not in map;
|
||||
*/
|
||||
std::string deviceId = "invalid deviceId for GetDeviceInfoById";
|
||||
{
|
||||
lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
|
||||
}
|
||||
std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().GetDeviceInfoById(deviceId);
|
||||
EXPECT_EQ(dmsDeviceInfo, nullptr);
|
||||
/**
|
||||
* @tc.steps: step2. test GetDeviceInfoById when deviceId is in map;
|
||||
*/
|
||||
{
|
||||
lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
|
||||
std::string deviceName = "invalid deviceName for GetDeviceInfoById";
|
||||
int32_t deviceType = 0;
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[deviceId] =
|
||||
make_shared<DmsDeviceInfo>(deviceName, deviceType, deviceId);
|
||||
}
|
||||
dmsDeviceInfo = DtbschedmgrDeviceInfoStorage::GetInstance().GetDeviceInfoById(deviceId);
|
||||
EXPECT_NE(dmsDeviceInfo, nullptr);
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetDeviceInfoByIdTest_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetUuidByNetworkIdTest_001
|
||||
* @tc.desc: test GetUuidByNetworkId
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DtbschedmgrDeviceInfoStorageTest, GetUuidByNetworkIdTest_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetUuidByNetworkIdTest_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test GetUuidByNetworkId when networkId is empty;
|
||||
*/
|
||||
std::string networkId;
|
||||
std::string result = DtbschedmgrDeviceInfoStorage::GetInstance().GetUuidByNetworkId(networkId);
|
||||
EXPECT_TRUE(result.empty());
|
||||
/**
|
||||
* @tc.steps: step2. test GetUuidByNetworkId when networkId is not in map;
|
||||
*/
|
||||
networkId = "invalid networkId for GetUuidByNetworkId";
|
||||
result = DtbschedmgrDeviceInfoStorage::GetInstance().GetUuidByNetworkId(networkId);
|
||||
EXPECT_TRUE(result.empty());
|
||||
/**
|
||||
* @tc.steps: step3. test GetUuidByNetworkId when networkId is in map;
|
||||
*/
|
||||
std::string uuid = "invalid uuid for GetUuidByNetworkId";
|
||||
{
|
||||
lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = networkId;
|
||||
}
|
||||
result = DtbschedmgrDeviceInfoStorage::GetInstance().GetUuidByNetworkId(networkId);
|
||||
EXPECT_EQ(result, uuid);
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetUuidByNetworkIdTest_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetNetworkIdByUuidTest_001
|
||||
* @tc.desc: test GetNetworkIdByUuid
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DtbschedmgrDeviceInfoStorageTest, GetNetworkIdByUuidTest_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetNetworkIdByUuidTest_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test GetNetworkIdByUuid when uuid is null;
|
||||
*/
|
||||
std::string uuid;
|
||||
std::string result = DtbschedmgrDeviceInfoStorage::GetInstance().GetNetworkIdByUuid(uuid);
|
||||
EXPECT_TRUE(result.empty());
|
||||
/**
|
||||
* @tc.steps: step2. test GetNetworkIdByUuid when uuid is invalid;
|
||||
*/
|
||||
uuid = "invalid uuid for GetNetworkIdByUuid";
|
||||
result = DtbschedmgrDeviceInfoStorage::GetInstance().GetNetworkIdByUuid(uuid);
|
||||
EXPECT_TRUE(result.empty());
|
||||
/**
|
||||
* @tc.steps: step3. test GetNetworkIdByUuid;
|
||||
*/
|
||||
std::string networkId = "invalid networkId for GetNetworkIdByUuid";
|
||||
{
|
||||
std::lock_guard<std::mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = networkId;
|
||||
}
|
||||
result = DtbschedmgrDeviceInfoStorage::GetInstance().GetNetworkIdByUuid(uuid);
|
||||
EXPECT_EQ(result, networkId);
|
||||
/**
|
||||
* @tc.steps: step4. test OnDeviceInfoChanged;
|
||||
*/
|
||||
std::string deviceId = "invalid deviceId for OnDeviceInfoChanged";
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().OnDeviceInfoChanged(deviceId);
|
||||
|
||||
/**
|
||||
* @tc.steps: step5. test OnRemoteDied;
|
||||
*/
|
||||
wptr<IRemoteObject> remote = nullptr;
|
||||
sptr<DnetServiceDeathRecipient> dnetServiceDeathRecipient = new DnetServiceDeathRecipient();
|
||||
dnetServiceDeathRecipient->OnRemoteDied(remote);
|
||||
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetNetworkIdByUuidTest_001 end" << std::endl;
|
||||
}
|
||||
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef 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
|
||||
#include "dtbschedmgr_device_info_storage.h"
|
||||
#undef private
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class DtbschedmgrDeviceInfoStorageTest : 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_;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DMSFWK_BASE_DTBSCHEDMGR_DEVICE_INFO_STORAGE_TEST_H
|
@ -26,25 +26,34 @@ dtbabilitymgr_configs = [
|
||||
|
||||
config("test_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [ "//foundation/ability/dmsfwk/utils/native/include" ]
|
||||
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",
|
||||
@ -104,6 +113,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
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "distributed_ability_manager_client.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "mock_remote_stub.h"
|
||||
#include "test_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -55,6 +56,7 @@ const std::string TEST_FILTER = "test filter";
|
||||
const std::string TEST_AUTHINFO = "test authInfo";
|
||||
const std::u16string TEST_INPUT1 = u"test input1";
|
||||
const std::u16string TEST_INPUT2 = u"test input2";
|
||||
const std::u16string TEST_INVALID_REMOTEDESCRIPTOR = u"invalid remoteDescriptor";
|
||||
const std::string TEST_INPUT3 = "test input1";
|
||||
const std::string TEST_INPUT4 = "test input2";
|
||||
const std::uint32_t INVALID_EVENT_DEVICE_CODE = 0;
|
||||
@ -79,7 +81,39 @@ void DeviceSelectionNotifierTest::OnDeviceDisconnect(const std::vector<std::stri
|
||||
for (size_t i = 0; i < deviceIds.size(); ++i) {
|
||||
DTEST_LOG << "DeviceSelectionNotifierTest::OnDeviceDisconnect unselected deviceId:"<<
|
||||
deviceIds[i] << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MockDmsNotifier::DeviceOnlineNotify(const std::string& deviceId)
|
||||
{
|
||||
}
|
||||
|
||||
void MockDmsNotifier::DeviceOfflineNotify(const std::string& deviceId)
|
||||
{
|
||||
}
|
||||
|
||||
void MockDmsNotifier::ProcessNotifierDied(const sptr<IRemoteObject>& notifier)
|
||||
{
|
||||
}
|
||||
|
||||
void MockDmsNotifier::ScheduleStartDeviceManager(const sptr<IRemoteObject>& appProxy, int32_t token,
|
||||
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t MockDmsNotifier::OnDeviceConnect(int32_t token, const std::vector<ContinuationResult>& continuationResults)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t MockDmsNotifier::OnDeviceDisconnect(int32_t token, const std::vector<std::string>& deviceIds)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t MockDmsNotifier::OnDeviceCancel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ContinuationManagerTest::SetUpTestCase()
|
||||
@ -1255,6 +1289,108 @@ HWTEST_F(ContinuationManagerTest, Write_Read_ContinuationResultsFromParcel_001,
|
||||
DTEST_LOG << "ContinuationManagerTest WriteContinuationResultsFromParcel_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ReadContinuationResultsFromParcel_001
|
||||
* @tc.desc: test ReadContinuationResultsFromParcel when len is less than 0.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_001 start" << std::endl;
|
||||
Parcel parcel;
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
parcel.WriteInt32(VALUE_OBJECT);
|
||||
parcel.WriteInt32(-1);
|
||||
bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
|
||||
EXPECT_FALSE(result);
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ReadContinuationResultsFromParcel_002
|
||||
* @tc.desc: test ReadContinuationResultsFromParcel when size > parcel.GetReadableBytes().
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_002 start" << std::endl;
|
||||
Parcel parcel;
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
parcel.WriteInt32(VALUE_OBJECT);
|
||||
parcel.WriteInt32(parcel.GetReadableBytes() + 1);
|
||||
bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
|
||||
EXPECT_FALSE(result);
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ReadContinuationResultsFromParcel_003
|
||||
* @tc.desc: test ReadContinuationResultsFromParcel when continuationResults.max_size() < size.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_003 start" << std::endl;
|
||||
Parcel parcel;
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
parcel.WriteInt32(VALUE_OBJECT);
|
||||
parcel.WriteInt32(continuationResults.max_size() + 1);
|
||||
bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
|
||||
EXPECT_FALSE(result);
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ReadContinuationResultsFromParcel_004
|
||||
* @tc.desc: test ReadContinuationResultsFromParcel when continuationResults.max_size() > size.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_004, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_004 start" << std::endl;
|
||||
Parcel parcel;
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
parcel.WriteInt32(VALUE_OBJECT);
|
||||
parcel.WriteInt32(continuationResults.max_size() - 1);
|
||||
bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
|
||||
EXPECT_FALSE(result);
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_004 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ReadContinuationResultsFromParcel_005
|
||||
* @tc.desc: test ReadContinuationResultsFromParcel when continuationResult is nullptr.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_005, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_005 start" << std::endl;
|
||||
Parcel parcel;
|
||||
ContinuationResult *continuationResult = nullptr;
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
parcel.WriteInt32(VALUE_OBJECT);
|
||||
parcel.WriteInt32(1);
|
||||
parcel.WriteParcelable(continuationResult);
|
||||
bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
|
||||
EXPECT_FALSE(result);
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_005 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: WriteContinuationResultsToParcel_001
|
||||
* @tc.desc: test WriteContinuationResultsToParcel when size == 0.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, WriteContinuationResultsToParcel_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "ContinuationManagerTest WriteContinuationResultsToParcel_001 start" << std::endl;
|
||||
Parcel parcel;
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
bool result = ContinuationResult::WriteContinuationResultsToParcel(parcel, continuationResults);
|
||||
EXPECT_TRUE(result);
|
||||
DTEST_LOG << "ContinuationManagerTest WriteContinuationResultsToParcel_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Str16VecToStr8Vec_001
|
||||
* @tc.desc: test Str16VecToStr8Vec function.
|
||||
@ -1557,5 +1693,60 @@ HWTEST_F(ContinuationManagerTest, OnRemoteRequest_005, TestSize.Level3)
|
||||
|
||||
EXPECT_EQ(ERR_OK, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnRemoteRequest_006
|
||||
* @tc.desc: test OnRemoteRequest when descriptor != remoteDescriptor.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5M4CD
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_006, TestSize.Level3)
|
||||
{
|
||||
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
|
||||
AppDeviceCallbackStub appDeviceCallbackStub(dmsNotifier);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(TEST_INVALID_REMOTEDESCRIPTOR);
|
||||
/**
|
||||
* @tc.steps: step1. AppDeviceCallbackStub::OnRemoteRequest
|
||||
*/
|
||||
int32_t ret = appDeviceCallbackStub.OnRemoteRequest(1, data, reply, option);
|
||||
EXPECT_EQ(ERR_INVALID_STATE, ret);
|
||||
/**
|
||||
* @tc.steps: step2. DeviceSelectionNotifierProxy::OnDeviceConnect when continuationResults is nullptr.
|
||||
*/
|
||||
sptr<IRemoteObject> impl = new MockRemoteStub();
|
||||
DeviceSelectionNotifierProxy deviceSelectionNotifierProxy(impl);
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
deviceSelectionNotifierProxy.OnDeviceConnect(continuationResults);
|
||||
/**
|
||||
* @tc.steps: step3. DeviceSelectionNotifierProxy::OnDeviceDisconnect when continuationResults is nullptr.
|
||||
*/
|
||||
std::vector<std::string> deviceIds;
|
||||
deviceSelectionNotifierProxy.OnDeviceDisconnect(deviceIds);
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. DeviceSelectionNotifierProxy::OnDeviceConnect.
|
||||
*/
|
||||
ContinuationResult continuationResult1;
|
||||
continuationResult1.SetDeviceId(SELECTED_DEVICE_ID1);
|
||||
continuationResult1.SetDeviceType(SELECTED_DEVICE_TYPE1);
|
||||
continuationResult1.SetDeviceName(SELECTED_DEVICE_NAME1);
|
||||
ContinuationResult continuationResult2;
|
||||
continuationResult2.SetDeviceId(SELECTED_DEVICE_ID2);
|
||||
continuationResult2.SetDeviceType(SELECTED_DEVICE_TYPE2);
|
||||
continuationResult2.SetDeviceName(SELECTED_DEVICE_NAME2);
|
||||
continuationResults.emplace_back(continuationResult1);
|
||||
continuationResults.emplace_back(continuationResult2);
|
||||
deviceSelectionNotifierProxy.OnDeviceConnect(continuationResults);
|
||||
/**
|
||||
* @tc.steps: step5. DeviceSelectionNotifierProxy::OnDeviceDisconnect.
|
||||
*/
|
||||
deviceIds.emplace_back(SELECTED_DEVICE_ID1);
|
||||
deviceIds.emplace_back(SELECTED_DEVICE_ID2);
|
||||
deviceIds.emplace_back(SELECTED_DEVICE_ID3);
|
||||
deviceSelectionNotifierProxy.OnDeviceDisconnect(deviceIds);
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include "device_selection_notifier_stub.h"
|
||||
#define private public
|
||||
#include "continuation_manager/app_device_callback_stub.h"
|
||||
#include "continuation_manager/device_selection_notifier_proxy.h"
|
||||
#include "distributed_ability_manager_service.h"
|
||||
#undef private
|
||||
|
||||
@ -43,6 +45,21 @@ public:
|
||||
void OnDeviceConnect(const std::vector<ContinuationResult>& continuationResults) override;
|
||||
void OnDeviceDisconnect(const std::vector<std::string>& deviceIds) override;
|
||||
};
|
||||
|
||||
class MockDmsNotifier : public DmsNotifier {
|
||||
public:
|
||||
MockDmsNotifier() = default;
|
||||
~MockDmsNotifier() = default;
|
||||
|
||||
void DeviceOnlineNotify(const std::string& deviceId) override;
|
||||
void DeviceOfflineNotify(const std::string& deviceId) override;
|
||||
void ProcessNotifierDied(const sptr<IRemoteObject>& notifier) override;
|
||||
void ScheduleStartDeviceManager(const sptr<IRemoteObject>& appProxy, int32_t token,
|
||||
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr) override;
|
||||
int32_t OnDeviceConnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) override;
|
||||
int32_t OnDeviceDisconnect(int32_t token, const std::vector<std::string>& deviceIds) override;
|
||||
int32_t OnDeviceCancel() override;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_ABILITY_MANAGER_CONTINUATION_MANAGER_TEST_H
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MOCK_REMOTE_STUB_H
|
||||
#define MOCK_REMOTE_STUB_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class MockRemoteInterface : public OHOS::IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.test.mock");
|
||||
};
|
||||
|
||||
class MockRemoteStub : public IRemoteStub<MockRemoteInterface> {
|
||||
public:
|
||||
~MockRemoteStub() = default;
|
||||
virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
|
||||
MessageOption& option) override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
@ -29,7 +29,7 @@ namespace {
|
||||
constexpr int32_t DISTRIBUTED_SCHED_SA_ID = 1401;
|
||||
const char* HIDUMPER_PROCESS_NAME = "hidumper_service";
|
||||
const char* DISTSCHED_PROCESS_NAME = "distributedsched";
|
||||
const char* INVAILD_PROCESS_NAME = "invaild_process";
|
||||
const char* INVALID_PROCESS_NAME = "invalid_process";
|
||||
bool g_mockResult = false;
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ void DistributedAbilityManagerDumperTest::TearDown()
|
||||
|
||||
/**
|
||||
* @tc.name: Dump_001
|
||||
* @tc.desc: call dump with invaild fd.
|
||||
* @tc.desc: call dump with invalid fd.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5PUBK
|
||||
*/
|
||||
@ -298,7 +298,7 @@ HWTEST_F(DistributedAbilityManagerDumperTest, Dumper_Dump_004, TestSize.Level3)
|
||||
|
||||
/**
|
||||
* @tc.name: Dumper_Dump_005
|
||||
* @tc.desc: call DistributedAbilityManagerDumper::Dump with invaild args.
|
||||
* @tc.desc: call DistributedAbilityManagerDumper::Dump with invalid args.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5PUBK
|
||||
*/
|
||||
@ -341,7 +341,7 @@ HWTEST_F(DistributedAbilityManagerDumperTest, Dumper_Dump_006, TestSize.Level4)
|
||||
|
||||
/**
|
||||
* @tc.name: Dumper_Dump_007
|
||||
* @tc.desc: call DistributedAbilityManagerDumper::Dump from invaild process.
|
||||
* @tc.desc: call DistributedAbilityManagerDumper::Dump from invalid process.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5PUBK
|
||||
*/
|
||||
@ -352,7 +352,7 @@ HWTEST_F(DistributedAbilityManagerDumperTest, Dumper_Dump_007, TestSize.Level4)
|
||||
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
|
||||
return;
|
||||
}
|
||||
MockProcess(INVAILD_PROCESS_NAME);
|
||||
MockProcess(INVALID_PROCESS_NAME);
|
||||
const std::vector<std::string> args;
|
||||
std::string dumpResult;
|
||||
bool result = DistributedAbilityManagerDumper::Dump(dtbabilitymgrService_, args, dumpResult);
|
||||
|
@ -14,10 +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;
|
||||
@ -26,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;
|
||||
}
|
||||
|
||||
@ -62,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;
|
||||
}
|
||||
@ -77,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);
|
||||
@ -102,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);
|
||||
@ -129,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;
|
||||
}
|
||||
@ -148,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;
|
||||
@ -162,59 +197,65 @@ HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_001, TestSize.Lev
|
||||
|
||||
/**
|
||||
* @tc.name: OnRemoteRequest_002
|
||||
* @tc.desc: test OnRemoteRequest to start funcsMap_
|
||||
* @tc.desc: test OnRemoteRequest with invalid code
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5NOA1
|
||||
*/
|
||||
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(UPDATE_CONNECT_STATUS, 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnRemoteRequest_003
|
||||
* @tc.desc: test OnRemoteRequest to start funcsMap_ with invalid token
|
||||
* @tc.desc: test OnRemoteRequest to start funcsMap_ without token
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5NOA1
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnRemoteRequest_004
|
||||
* @tc.desc: test OnRemoteRequest with invalid code
|
||||
* @tc.desc: test OnRemoteRequest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5NOA1
|
||||
*/
|
||||
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);
|
||||
MessageParcel data;
|
||||
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(UPDATE_CONNECT_STATUS, data, reply, option);
|
||||
EXPECT_NE(ERR_NONE, result);
|
||||
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_004 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
|
||||
|
@ -23,8 +23,9 @@ group("unittest") {
|
||||
config("distributed_sched_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [ "include" ]
|
||||
defines = []
|
||||
if (dmsfwk_mission_manager) {
|
||||
defines = [ "SUPPORT_DISTRIBUTED_MISSION_MANAGER" ]
|
||||
defines += [ "SUPPORT_DISTRIBUTED_MISSION_MANAGER" ]
|
||||
}
|
||||
if (dmsfwk_report_memmgr || dmsfwk_report_memmgr_plugins) {
|
||||
defines += [ "SUPPORT_DISTRIBUTEDCOMPONENT_TO_MEMMGR" ]
|
||||
|
@ -40,7 +40,7 @@ public:
|
||||
bool PushCallback(int32_t missionId, const sptr<IRemoteObject>& callback,
|
||||
std::string deviceId, bool isFreeInstall);
|
||||
sptr<IRemoteObject> PopCallback(int32_t missionId);
|
||||
int32_t NotifyMissionCenterResult(int32_t missionId, int32_t isSuccess);
|
||||
int32_t NotifyMissionCenterResult(int32_t missionId, int32_t resultCode);
|
||||
bool IsFreeInstall(int32_t missionId);
|
||||
std::string GetTargetDevice(int32_t missionId);
|
||||
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
int32_t status, uint32_t accessToken) override;
|
||||
void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) override;
|
||||
int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) override;
|
||||
void NotifyContinuationCallbackResult(int32_t missionId, int32_t isSuccess);
|
||||
void NotifyContinuationCallbackResult(int32_t missionId, int32_t resultCode);
|
||||
int32_t NotifyFreeInstallResult(const CallbackTaskItem item, int32_t resultCode);
|
||||
int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,
|
||||
int32_t callerUid, int32_t callerPid, uint32_t accessToken) override;
|
||||
|
@ -203,7 +203,7 @@ sptr<IRemoteObject> DSchedContinuation::PopCallback(int32_t missionId)
|
||||
return callback;
|
||||
}
|
||||
|
||||
int32_t DSchedContinuation::NotifyMissionCenterResult(int32_t missionId, int32_t isSuccess)
|
||||
int32_t DSchedContinuation::NotifyMissionCenterResult(int32_t missionId, int32_t resultCode)
|
||||
{
|
||||
sptr<IRemoteObject> callback = PopCallback(missionId);
|
||||
RemoveTimeOut(missionId);
|
||||
@ -217,7 +217,7 @@ int32_t DSchedContinuation::NotifyMissionCenterResult(int32_t missionId, int32_t
|
||||
HILOGE("NotifyMissionCenterResult write token failed");
|
||||
return INVALID_PARAMETERS_ERR;
|
||||
}
|
||||
PARCEL_WRITE_HELPER_RET(data, Int32, isSuccess, INVALID_PARAMETERS_ERR);
|
||||
PARCEL_WRITE_HELPER_RET(data, Int32, resultCode, INVALID_PARAMETERS_ERR);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
int32_t error = callback->SendRequest(NOTIFY_MISSION_CENTER_RESULT, data, reply, option);
|
||||
|
@ -567,9 +567,9 @@ void DistributedSchedService::ProcessFormMgrDied(const wptr<IRemoteObject>& remo
|
||||
}
|
||||
#endif
|
||||
|
||||
void DistributedSchedService::NotifyContinuationCallbackResult(int32_t missionId, int32_t isSuccess)
|
||||
void DistributedSchedService::NotifyContinuationCallbackResult(int32_t missionId, int32_t resultCode)
|
||||
{
|
||||
HILOGD("Continuation result is: %{public}d", isSuccess);
|
||||
HILOGD("Continuation result is: %{public}d", resultCode);
|
||||
|
||||
if (dschedContinuation_ == nullptr) {
|
||||
HILOGE("continuation object null!");
|
||||
@ -578,13 +578,13 @@ void DistributedSchedService::NotifyContinuationCallbackResult(int32_t missionId
|
||||
|
||||
int32_t result = 0;
|
||||
if (dschedContinuation_->IsInContinuationProgress(missionId)) {
|
||||
if (!isSuccess) {
|
||||
if (resultCode == ERR_OK) {
|
||||
result = AbilityManagerClient::GetInstance()->CleanMission(missionId);
|
||||
HILOGD("clean mission result:%{public}d", result);
|
||||
}
|
||||
result = dschedContinuation_->NotifyMissionCenterResult(missionId, isSuccess);
|
||||
result = dschedContinuation_->NotifyMissionCenterResult(missionId, resultCode);
|
||||
} else {
|
||||
result = AbilityManagerClient::GetInstance()->NotifyContinuationResult(missionId, isSuccess);
|
||||
result = AbilityManagerClient::GetInstance()->NotifyContinuationResult(missionId, resultCode);
|
||||
dschedContinuation_->RemoveTimeOut(missionId);
|
||||
}
|
||||
HILOGD("NotifyContinuationCallbackResult result:%{public}d", result);
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "mission/distributed_mission_info.h"
|
||||
|
||||
#include "adapter/adapter_constant.h"
|
||||
#include "mission/mission_constant.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "parcel_helper.h"
|
||||
#include "string_ex.h"
|
||||
@ -111,7 +112,7 @@ bool DstbMissionInfo::ReadDstbMissionInfosFromParcel(Parcel& parcel,
|
||||
return false;
|
||||
}
|
||||
size_t size = static_cast<size_t>(len);
|
||||
if ((size > parcel.GetReadableBytes()) || (missionInfos.max_size() < size)) {
|
||||
if ((size > parcel.GetReadableBytes()) || (size > Constants::Mission::GET_MAX_MISSIONS)) {
|
||||
HILOGE("Failed to read DstbMissionInfo vector, size = %{public}zu", size);
|
||||
return false;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "mission/mission_info_converter.h"
|
||||
|
||||
#include "adapter/adapter_constant.h"
|
||||
#include "mission/mission_constant.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "parcel_helper.h"
|
||||
|
||||
@ -78,7 +79,7 @@ bool MissionInfoConverter::ReadMissionInfosFromParcel(Parcel& parcel,
|
||||
return false;
|
||||
}
|
||||
size_t size = static_cast<size_t>(len);
|
||||
if ((size > parcel.GetReadableBytes()) || (missionInfos.max_size() < size)) {
|
||||
if ((size > parcel.GetReadableBytes()) || (size > Constants::Mission::GET_MAX_MISSIONS)) {
|
||||
HILOGE("Failed to read MissionInfo vector, size = %{public}zu", size);
|
||||
return false;
|
||||
}
|
||||
|
@ -129,7 +129,10 @@ ohos_unittest("distributedschedsvrtest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"unittest/distributed_sched_adapter_test.cpp",
|
||||
"unittest/distributed_sched_dumper_test.cpp",
|
||||
"unittest/distributed_sched_service_test.cpp",
|
||||
"unittest/distributed_sched_stub_test.cpp",
|
||||
"unittest/dms_callback_task_test.cpp",
|
||||
"unittest/dms_token_callback_test.cpp",
|
||||
"unittest/mock_distributed_sched.cpp",
|
||||
@ -268,6 +271,7 @@ ohos_unittest("dschedmissionmanagertest") {
|
||||
"unittest/mission/distributed_data_storage_test.cpp",
|
||||
"unittest/mission/distributed_mission_info_test.cpp",
|
||||
"unittest/mission/dms_mission_manager_test.cpp",
|
||||
"unittest/mission/mission_info_converter_test.cpp",
|
||||
"unittest/mission/snapshot_test.cpp",
|
||||
]
|
||||
sources += dtbschedmgr_sources
|
||||
|
@ -0,0 +1,453 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "distributed_sched_adapter_test.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "mock_remote_stub.h"
|
||||
#include "snapshot.h"
|
||||
#include "test_log.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
void DistributedSchedAdapterTest::SetUpTestCase()
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest::SetUpTestCase" << std::endl;
|
||||
}
|
||||
|
||||
void DistributedSchedAdapterTest::TearDownTestCase()
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest::TearDownTestCase" << std::endl;
|
||||
}
|
||||
|
||||
void DistributedSchedAdapterTest::TearDown()
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest::TearDown" << std::endl;
|
||||
}
|
||||
|
||||
void DistributedSchedAdapterTest::SetUp()
|
||||
{
|
||||
distributedSchedAdapter_ = std::make_shared<DistributedSchedAdapter>();
|
||||
distributedSchedAdapter_->Init();
|
||||
DTEST_LOG << "DistributedSchedAdapterTest::SetUp" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Init_001
|
||||
* @tc.desc: dmsAdapterHandler_ is not nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, Init_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest Init_001 begin" << std::endl;
|
||||
distributedSchedAdapter_->Init();
|
||||
EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest Init_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ConnectAbility_001
|
||||
* @tc.desc: invalid params
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, ConnectAbility_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ConnectAbility_001 begin" << std::endl;
|
||||
const OHOS::AAFwk::Want want;
|
||||
const sptr<IRemoteObject> connect;
|
||||
const sptr<IRemoteObject> callerToken;
|
||||
int32_t result = distributedSchedAdapter_->ConnectAbility(want, connect, callerToken);
|
||||
EXPECT_NE(result, ERR_OK);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ConnectAbility_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DisconnectAbility_001
|
||||
* @tc.desc: invalid params
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, DisconnectAbility_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest DisconnectAbility_001 begin" << std::endl;
|
||||
const sptr<IRemoteObject> connect;
|
||||
int32_t result = distributedSchedAdapter_->DisconnectAbility(connect);
|
||||
EXPECT_NE(result, ERR_OK);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest DisconnectAbility_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DeviceOnline_001
|
||||
* @tc.desc: dmsAdapterHandler_ is nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, DeviceOnline_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest DeviceOnline_001 begin" << std::endl;
|
||||
const std::string deviceId = "";
|
||||
distributedSchedAdapter_->dmsAdapterHandler_ = nullptr;
|
||||
distributedSchedAdapter_->DeviceOnline(deviceId);
|
||||
EXPECT_EQ(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest DeviceOnline_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DeviceOnline_002
|
||||
* @tc.desc: deviceId is empty
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, DeviceOnline_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest DeviceOnline_002 begin" << std::endl;
|
||||
const std::string deviceId = "";
|
||||
distributedSchedAdapter_->DeviceOnline(deviceId);
|
||||
EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest DeviceOnline_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DeviceOnline_003
|
||||
* @tc.desc: deviceId is not empty
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, DeviceOnline_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest DeviceOnline_003 begin" << std::endl;
|
||||
const std::string deviceId = "mockDeviceId";
|
||||
distributedSchedAdapter_->DeviceOnline(deviceId);
|
||||
EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest DeviceOnline_003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DeviceOffline_001
|
||||
* @tc.desc: dmsAdapterHandler_ is nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, DeviceOffline_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest DeviceOffline_001 begin" << std::endl;
|
||||
const std::string deviceId = "";
|
||||
distributedSchedAdapter_->dmsAdapterHandler_ = nullptr;
|
||||
distributedSchedAdapter_->DeviceOffline(deviceId);
|
||||
EXPECT_EQ(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest DeviceOffline_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DeviceOffline_002
|
||||
* @tc.desc: deviceId is empty
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, DeviceOffline_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest DeviceOffline_002 begin" << std::endl;
|
||||
const std::string deviceId = "";
|
||||
distributedSchedAdapter_->DeviceOffline(deviceId);
|
||||
EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest DeviceOffline_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DeviceOffline_003
|
||||
* @tc.desc: deviceId is not empty
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, DeviceOffline_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest DeviceOffline_003 begin" << std::endl;
|
||||
const std::string deviceId = "mockDeviceId";
|
||||
distributedSchedAdapter_->DeviceOffline(deviceId);
|
||||
EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest DeviceOffline_003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProcessConnectDied_001
|
||||
* @tc.desc: dmsAdapterHandler_ is nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, ProcessConnectDied_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessConnectDied_001 begin" << std::endl;
|
||||
const sptr<IRemoteObject> connect;
|
||||
distributedSchedAdapter_->dmsAdapterHandler_ = nullptr;
|
||||
distributedSchedAdapter_->ProcessConnectDied(connect);
|
||||
EXPECT_EQ(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessConnectDied_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProcessConnectDied_002
|
||||
* @tc.desc: connect is nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, ProcessConnectDied_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessConnectDied_002 begin" << std::endl;
|
||||
const sptr<IRemoteObject> connect = nullptr;
|
||||
distributedSchedAdapter_->ProcessConnectDied(connect);
|
||||
EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessConnectDied_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProcessConnectDied_003
|
||||
* @tc.desc: process connect died
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, ProcessConnectDied_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessConnectDied_003 begin" << std::endl;
|
||||
const sptr<IRemoteObject> connect = new MockRemoteStub();
|
||||
distributedSchedAdapter_->ProcessConnectDied(connect);
|
||||
EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessConnectDied_003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProcessCalleeDied_001
|
||||
* @tc.desc: dmsAdapterHandler_ is nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, ProcessCalleeDied_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessCalleeDied_001 begin" << std::endl;
|
||||
const sptr<IRemoteObject> connect;
|
||||
distributedSchedAdapter_->dmsAdapterHandler_ = nullptr;
|
||||
distributedSchedAdapter_->ProcessCalleeDied(connect);
|
||||
EXPECT_EQ(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessCalleeDied_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProcessCalleeDied_002
|
||||
* @tc.desc: connect is nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, ProcessCalleeDied_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessCalleeDied_002 begin" << std::endl;
|
||||
const sptr<IRemoteObject> connect = nullptr;
|
||||
distributedSchedAdapter_->ProcessCalleeDied(connect);
|
||||
EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessCalleeDied_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProcessCalleeDied_003
|
||||
* @tc.desc: processs callee died
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, ProcessCalleeDied_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessCalleeDied_003 begin" << std::endl;
|
||||
const sptr<IRemoteObject> connect = new MockRemoteStub();
|
||||
distributedSchedAdapter_->ProcessCalleeDied(connect);
|
||||
EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessCalleeDied_003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProcessCallerDied_001
|
||||
* @tc.desc: dmsAdapterHandler_ is nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, ProcessCallerDied_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessCallerDied_001 begin" << std::endl;
|
||||
const sptr<IRemoteObject> connect;
|
||||
int32_t deviceType = 0;
|
||||
distributedSchedAdapter_->dmsAdapterHandler_ = nullptr;
|
||||
distributedSchedAdapter_->ProcessCallerDied(connect, deviceType);
|
||||
EXPECT_EQ(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessCallerDied_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProcessCallerDied_002
|
||||
* @tc.desc: connect is nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, ProcessCallerDied_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessCallerDied_002 begin" << std::endl;
|
||||
const sptr<IRemoteObject> connect = nullptr;
|
||||
int32_t deviceType = 0;
|
||||
distributedSchedAdapter_->ProcessCallerDied(connect, deviceType);
|
||||
EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessCallerDied_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProcessCallerDied_003
|
||||
* @tc.desc: process caller died
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, ProcessCallerDied_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessCallerDied_003 begin" << std::endl;
|
||||
const sptr<IRemoteObject> connect = new MockRemoteStub();
|
||||
int32_t deviceType = 0;
|
||||
distributedSchedAdapter_->ProcessCallerDied(connect, deviceType);
|
||||
EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest ProcessCallerDied_003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetLocalMissionInfos_001
|
||||
* @tc.desc: numMissions is invalid
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, GetLocalMissionInfos_001, TestSize.Level4)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest GetLocalMissionInfos_001 begin" << std::endl;
|
||||
int32_t numMissions = -1;
|
||||
std::vector<DstbMissionInfo> missionInfos;
|
||||
int32_t result = distributedSchedAdapter_->GetLocalMissionInfos(numMissions, missionInfos);
|
||||
EXPECT_NE(result, ERR_OK);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest GetLocalMissionInfos_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetLocalMissionInfos_002
|
||||
* @tc.desc: numMissions is zero
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, GetLocalMissionInfos_002, TestSize.Level4)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest GetLocalMissionInfos_002 begin" << std::endl;
|
||||
int32_t numMissions = 0;
|
||||
std::vector<DstbMissionInfo> missionInfos;
|
||||
int32_t result = distributedSchedAdapter_->GetLocalMissionInfos(numMissions, missionInfos);
|
||||
EXPECT_NE(result, ERR_OK);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest GetLocalMissionInfos_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetLocalMissionInfos_003
|
||||
* @tc.desc: numMissions is not zero
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, GetLocalMissionInfos_003, TestSize.Level4)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest GetLocalMissionInfos_003 begin" << std::endl;
|
||||
int32_t numMissions = 10;
|
||||
std::vector<DstbMissionInfo> missionInfos;
|
||||
int32_t result = distributedSchedAdapter_->GetLocalMissionInfos(numMissions, missionInfos);
|
||||
EXPECT_NE(result, ERR_OK);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest GetLocalMissionInfos_003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RegisterMissionListener_001
|
||||
* @tc.desc: listener is nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, RegisterMissionListener_001, TestSize.Level4)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest RegisterMissionListener_001 begin" << std::endl;
|
||||
const sptr<DistributedMissionChangeListener> listener = nullptr;
|
||||
int32_t result = distributedSchedAdapter_->RegisterMissionListener(listener);
|
||||
EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest RegisterMissionListener_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RegisterMissionListener_002
|
||||
* @tc.desc: listener is not nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, RegisterMissionListener_002, TestSize.Level4)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest RegisterMissionListener_002 begin" << std::endl;
|
||||
const sptr<DistributedMissionChangeListener> listener = new DistributedMissionChangeListener();
|
||||
int32_t result = distributedSchedAdapter_->RegisterMissionListener(listener);
|
||||
EXPECT_NE(result, ERR_OK);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest RegisterMissionListener_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UnRegisterMissionListener_001
|
||||
* @tc.desc: listener is nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, UnRegisterMissionListener_001, TestSize.Level4)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest UnRegisterMissionListener_001 begin" << std::endl;
|
||||
const sptr<DistributedMissionChangeListener> listener = nullptr;
|
||||
int32_t result = distributedSchedAdapter_->UnRegisterMissionListener(listener);
|
||||
EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest UnRegisterMissionListener_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UnRegisterMissionListener_002
|
||||
* @tc.desc: listener is nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, UnRegisterMissionListener_002, TestSize.Level4)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest UnRegisterMissionListener_002 begin" << std::endl;
|
||||
const sptr<DistributedMissionChangeListener> listener = new DistributedMissionChangeListener();
|
||||
int32_t result = distributedSchedAdapter_->UnRegisterMissionListener(listener);
|
||||
EXPECT_NE(result, INVALID_PARAMETERS_ERR);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest UnRegisterMissionListener_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetLocalMissionSnapshotInfo_001
|
||||
* @tc.desc: networkId is invalid
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedAdapterTest, GetLocalMissionSnapshotInfo_001, TestSize.Level4)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedAdapterTest GetLocalMissionSnapshotInfo_001 begin" << std::endl;
|
||||
const std::string networkId = "invalidNetworkId";
|
||||
int32_t missionId = 0;
|
||||
AAFwk::MissionSnapshot missionSnapshot;
|
||||
int32_t result = distributedSchedAdapter_->GetLocalMissionSnapshotInfo(networkId, missionId, missionSnapshot);
|
||||
EXPECT_NE(result, ERR_OK);
|
||||
DTEST_LOG << "DistributedSchedAdapterTest GetLocalMissionSnapshotInfo_001 end" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef DISTRIBUTED_SCHED_ADAPTER_TEST_H
|
||||
#define DISTRIBUTED_SCHED_ADAPTER_TEST_H
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#define private public
|
||||
#include "distributed_sched_adapter.h"
|
||||
#undef private
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class DistributedSchedAdapterTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
std::shared_ptr<DistributedSchedAdapter> distributedSchedAdapter_;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // DISTRIBUTED_SCHED_ADAPTER_TEST_H
|
@ -21,6 +21,7 @@
|
||||
#include "distributed_sched_service.h"
|
||||
#include "distributed_sched_util.h"
|
||||
#include "dtbschedmgr_device_info_storage.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
@ -37,6 +38,7 @@ using namespace OHOS::DistributedHardware;
|
||||
|
||||
namespace {
|
||||
constexpr int32_t STDOUT_FD = 1;
|
||||
constexpr int32_t REQUEST_CODE_ERR = 305;
|
||||
}
|
||||
|
||||
class AbilityConnectCallbackTest : public AAFwk::AbilityConnectionStub {
|
||||
@ -81,6 +83,7 @@ public:
|
||||
|
||||
void AddConnectCount(int32_t uid) const;
|
||||
void DecreaseConnectCount(int32_t uid) const;
|
||||
sptr<IDistributedSched> GetDms();
|
||||
|
||||
class DeviceInitCallBack : public DmInitCallback {
|
||||
void OnRemoteDied() override;
|
||||
@ -206,6 +209,22 @@ void DistributedSchedConnectTest::DecreaseConnectCount(int32_t uid) const
|
||||
DistributedSchedService::GetInstance().DecreaseConnectLocked(uid);
|
||||
}
|
||||
|
||||
sptr<IDistributedSched> DistributedSchedConnectTest::GetDms()
|
||||
{
|
||||
auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sm == nullptr) {
|
||||
DTEST_LOG << "DistributedSchedConnectTest sm is nullptr" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
|
||||
if (distributedObject == nullptr) {
|
||||
DTEST_LOG << "distributedObject sm is nullptr" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
EXPECT_TRUE(distributedObject != nullptr);
|
||||
return iface_cast<IDistributedSched>(distributedObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DumpConnectInfo_001
|
||||
* @tc.desc: dump connect ability info by call Dump
|
||||
@ -1033,5 +1052,169 @@ HWTEST_F(DistributedSchedConnectTest, NotifyProcessDied001, TestSize.Level4)
|
||||
DistributedSchedService::GetInstance().NotifyProcessDied("123_remote_device_id", callerInfo, targetComponent);
|
||||
DTEST_LOG << "DistributedSchedConnectTest NotifyProcessDied001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProxyCallDisconnectRemoteAbility001
|
||||
* @tc.desc: call dms proxy DisconnectRemoteAbility
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5OOKG
|
||||
*/
|
||||
HWTEST_F(DistributedSchedConnectTest, ProxyCallDisconnectRemoteAbility001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectRemoteAbility001 start" << std::endl;
|
||||
sptr<IDistributedSched> proxy = GetDms();
|
||||
if (proxy == nullptr) {
|
||||
return;
|
||||
}
|
||||
int32_t ret = proxy->DisconnectRemoteAbility(nullptr, 0, 0);
|
||||
EXPECT_EQ(ret, ERR_NULL_OBJECT);
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectRemoteAbility001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProxyCallDisconnectRemoteAbility002
|
||||
* @tc.desc: call dms proxy DisconnectRemoteAbility
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5OOKG
|
||||
*/
|
||||
HWTEST_F(DistributedSchedConnectTest, ProxyCallDisconnectRemoteAbility002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectRemoteAbility002 start" << std::endl;
|
||||
sptr<IDistributedSched> proxy = GetDms();
|
||||
if (proxy == nullptr) {
|
||||
return;
|
||||
}
|
||||
sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
|
||||
int32_t ret = proxy->DisconnectRemoteAbility(connect, 0, 0);
|
||||
EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectRemoteAbility002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProxyCallConnectRemoteAbility001
|
||||
* @tc.desc: call dms proxy ConnectRemoteAbility
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5OOKG
|
||||
*/
|
||||
HWTEST_F(DistributedSchedConnectTest, ProxyCallConnectRemoteAbility001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectRemoteAbility001 start" << std::endl;
|
||||
sptr<IDistributedSched> proxy = GetDms();
|
||||
if (proxy == nullptr) {
|
||||
return;
|
||||
}
|
||||
OHOS::AAFwk::Want want;
|
||||
want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
|
||||
sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
|
||||
int32_t ret = proxy->ConnectRemoteAbility(want, connect, 0, 0, 0);
|
||||
EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectRemoteAbility001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProxyCallConnectRemoteAbility002
|
||||
* @tc.desc: call dms proxy ConnectRemoteAbility
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5OOKG
|
||||
*/
|
||||
HWTEST_F(DistributedSchedConnectTest, ProxyCallConnectRemoteAbility002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectRemoteAbility002 start" << std::endl;
|
||||
sptr<IDistributedSched> proxy = GetDms();
|
||||
if (proxy == nullptr) {
|
||||
return;
|
||||
}
|
||||
OHOS::AAFwk::Want want;
|
||||
want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
|
||||
int32_t ret = proxy->ConnectRemoteAbility(want, nullptr, 0, 0, 0);
|
||||
EXPECT_EQ(ret, ERR_NULL_OBJECT);
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectRemoteAbility002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProxyCallConnectAbilityFromRemote001
|
||||
* @tc.desc: call dms proxy ConnectAbilityFromRemote
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5OOKG
|
||||
*/
|
||||
HWTEST_F(DistributedSchedConnectTest, ProxyCallConnectAbilityFromRemote001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectAbilityFromRemote001 start" << std::endl;
|
||||
sptr<IDistributedSched> proxy = GetDms();
|
||||
if (proxy == nullptr) {
|
||||
return;
|
||||
}
|
||||
OHOS::AAFwk::Want want;
|
||||
want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
|
||||
AppExecFwk::AbilityInfo abilityInfo;
|
||||
sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
|
||||
CallerInfo callerInfo;
|
||||
IDistributedSched::AccountInfo accountInfo;
|
||||
int32_t ret = proxy->ConnectAbilityFromRemote(want, abilityInfo,
|
||||
connect, callerInfo, accountInfo);
|
||||
EXPECT_EQ(ret, REQUEST_CODE_ERR);
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectAbilityFromRemote001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProxyCallConnectAbilityFromRemote002
|
||||
* @tc.desc: call dms proxy ConnectAbilityFromRemote
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5OOKG
|
||||
*/
|
||||
HWTEST_F(DistributedSchedConnectTest, ProxyCallConnectAbilityFromRemote002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectAbilityFromRemote002 start" << std::endl;
|
||||
sptr<IDistributedSched> proxy = GetDms();
|
||||
if (proxy == nullptr) {
|
||||
return;
|
||||
}
|
||||
OHOS::AAFwk::Want want;
|
||||
want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
|
||||
AppExecFwk::AbilityInfo abilityInfo;
|
||||
CallerInfo callerInfo;
|
||||
IDistributedSched::AccountInfo accountInfo;
|
||||
int32_t ret = proxy->ConnectAbilityFromRemote(want, abilityInfo,
|
||||
nullptr, callerInfo, accountInfo);
|
||||
EXPECT_EQ(ret, ERR_NULL_OBJECT);
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectAbilityFromRemote002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProxyCallDisconnectAbilityFromRemote001
|
||||
* @tc.desc: call dms proxy DisconnectAbilityFromRemote
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5OOKG
|
||||
*/
|
||||
HWTEST_F(DistributedSchedConnectTest, ProxyCallDisconnectAbilityFromRemote001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectAbilityFromRemote001 start" << std::endl;
|
||||
sptr<IDistributedSched> proxy = GetDms();
|
||||
if (proxy == nullptr) {
|
||||
return;
|
||||
}
|
||||
sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
|
||||
int32_t ret = proxy->DisconnectAbilityFromRemote(connect, 0, "");
|
||||
EXPECT_EQ(ret, REQUEST_CODE_ERR);
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectAbilityFromRemote001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProxyCallDisconnectAbilityFromRemote002
|
||||
* @tc.desc: call dms proxy DisconnectAbilityFromRemote
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5OOKG
|
||||
*/
|
||||
HWTEST_F(DistributedSchedConnectTest, ProxyCallDisconnectAbilityFromRemote002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectAbilityFromRemote002 start" << std::endl;
|
||||
sptr<IDistributedSched> proxy = GetDms();
|
||||
if (proxy == nullptr) {
|
||||
return;
|
||||
}
|
||||
int32_t ret = proxy->DisconnectAbilityFromRemote(nullptr, 0, "");
|
||||
EXPECT_EQ(ret, ERR_NULL_OBJECT);
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectAbilityFromRemote002 end" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "distributed_sched_util.h"
|
||||
#include "dtbschedmgr_device_info_storage.h"
|
||||
#include "mock_distributed_sched.h"
|
||||
#include "mock_remote_stub.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
@ -32,6 +33,7 @@ const std::u16string MOCK_DEVICE_ID = u"MOCK_DEVICE_ID";
|
||||
constexpr int32_t MOCK_SESSION_ID = 123;
|
||||
constexpr int32_t MOCK_TASK_ID = 456;
|
||||
const string LOCAL_DEVICE_ID = "192.168.43.100";
|
||||
constexpr int32_t REQUEST_CODE_ERR = 305;
|
||||
}
|
||||
|
||||
void DSchedContinuationTest::SetUpTestCase()
|
||||
@ -480,6 +482,23 @@ HWTEST_F(DSchedContinuationTest, PushAbilityToken_004, TestSize.Level1)
|
||||
DTEST_LOG << "DSchedContinuationTest PushAbilityToken_004 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PushAbilityToken_005
|
||||
* @tc.desc: AbilityToken is exist.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, PushAbilityToken_005, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest PushAbilityToken_005 start" << std::endl;
|
||||
dschedContinuation_->Init(nullptr);
|
||||
auto sessionId = 1;
|
||||
bool ret = dschedContinuation_->PushAbilityToken(sessionId, GetDSchedService());
|
||||
ret = dschedContinuation_->PushAbilityToken(sessionId, GetDSchedService());
|
||||
EXPECT_EQ(ret, false);
|
||||
DTEST_LOG << "DSchedContinuationTest PushAbilityToken_005 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PopAbilityToken_001
|
||||
* @tc.desc: input invalid params.
|
||||
@ -540,6 +559,157 @@ HWTEST_F(DSchedContinuationTest, PopAbilityToken_003, TestSize.Level1)
|
||||
DTEST_LOG << "DSchedContinuationTest PopAbilityToken_003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PopAbilityToken_004
|
||||
* @tc.desc: pop abilityToken success.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, PopAbilityToken_004, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest PopAbilityToken_004 start" << std::endl;
|
||||
dschedContinuation_->continuationHandler_ = nullptr;
|
||||
|
||||
int32_t sessionId = PushAbilityToken();
|
||||
sptr<IRemoteObject> abilityToken = dschedContinuation_->PopAbilityToken(sessionId);
|
||||
EXPECT_TRUE(abilityToken != nullptr);
|
||||
DTEST_LOG << "DSchedContinuationTest PopAbilityToken_004 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GenerateSessionId_001
|
||||
* @tc.desc: test GenerateSessionId when currSessionId is less than zero.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, GenerateSessionId_001, TestSize.Level4)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest GenerateSessionId_001 start" << std::endl;
|
||||
int32_t sessionId = dschedContinuation_->currSessionId_;
|
||||
dschedContinuation_->currSessionId_ = -100;
|
||||
dschedContinuation_->GenerateSessionId();
|
||||
EXPECT_EQ(dschedContinuation_->currSessionId_, 1);
|
||||
dschedContinuation_->currSessionId_ = sessionId;
|
||||
DTEST_LOG << "DSchedContinuationTest GenerateSessionId_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetTimeOut_001
|
||||
* @tc.desc: test SetTimeOut.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, SetTimeOut_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest SetTimeOut_001 start" << std::endl;
|
||||
dschedContinuation_->Init(nullptr);
|
||||
|
||||
int32_t missionId = 0;
|
||||
int32_t timeout = 1000;
|
||||
dschedContinuation_->SetTimeOut(missionId, timeout);
|
||||
EXPECT_NE(dschedContinuation_->continuationHandler_, nullptr);
|
||||
DTEST_LOG << "DSchedContinuationTest SetTimeOut_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RemoveTimeOut_001
|
||||
* @tc.desc: test RemoveTimeOut.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, RemoveTimeOut_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest RemoveTimeOut_001 start" << std::endl;
|
||||
dschedContinuation_->Init(nullptr);
|
||||
|
||||
int32_t missionId = 0;
|
||||
int32_t timeout = 1000;
|
||||
dschedContinuation_->SetTimeOut(missionId, timeout);
|
||||
EXPECT_NE(dschedContinuation_->continuationHandler_, nullptr);
|
||||
DTEST_LOG << "DSchedContinuationTest RemoveTimeOut_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetTargetDevice_001
|
||||
* @tc.desc: test GetTargetDevice.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, GetTargetDevice_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest GetTargetDevice_001 start" << std::endl;
|
||||
dschedContinuation_->Init(nullptr);
|
||||
|
||||
int32_t missionId = 0;
|
||||
std::string mockDevice = "mockDevice";
|
||||
dschedContinuation_->continuationDevices_[missionId] = mockDevice;
|
||||
std::string result = dschedContinuation_->GetTargetDevice(missionId);
|
||||
EXPECT_EQ(result, mockDevice);
|
||||
DTEST_LOG << "DSchedContinuationTest GetTargetDevice_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PushCallback_001
|
||||
* @tc.desc: test PushCallback when callback is nullptr.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, PushCallback_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest PushCallback_001 start" << std::endl;
|
||||
dschedContinuation_->Init(nullptr);
|
||||
|
||||
int32_t missionId = 0;
|
||||
const sptr<IRemoteObject> callback = nullptr;
|
||||
std::string deviceId = "";
|
||||
bool isFreeInstall = true;
|
||||
bool result = dschedContinuation_->PushCallback(missionId, callback, deviceId, isFreeInstall);
|
||||
EXPECT_EQ(result, false);
|
||||
DTEST_LOG << "DSchedContinuationTest PushCallback_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PushCallback_002
|
||||
* @tc.desc: test PushCallback when callback is exist.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, PushCallback_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest PushCallback_002 start" << std::endl;
|
||||
dschedContinuation_->Init(nullptr);
|
||||
|
||||
int32_t missionId = 0;
|
||||
const sptr<IRemoteObject> callback = new MockRemoteStub();
|
||||
std::string deviceId = "";
|
||||
bool isFreeInstall = true;
|
||||
dschedContinuation_->callbackMap_[missionId] = callback;
|
||||
bool result = dschedContinuation_->PushCallback(missionId, callback, deviceId, isFreeInstall);
|
||||
EXPECT_EQ(result, false);
|
||||
DTEST_LOG << "DSchedContinuationTest PushCallback_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PushCallback_003
|
||||
* @tc.desc: test PushCallback when isFreeInstall is true.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, PushCallback_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest PushCallback_003 start" << std::endl;
|
||||
dschedContinuation_->Init(nullptr);
|
||||
|
||||
int32_t missionId = 0;
|
||||
const sptr<IRemoteObject> callback = new MockRemoteStub();
|
||||
std::string deviceId = "";
|
||||
bool isFreeInstall = true;
|
||||
dschedContinuation_->callbackMap_.clear();
|
||||
bool result = dschedContinuation_->PushCallback(missionId, callback, deviceId, isFreeInstall);
|
||||
EXPECT_EQ(result, true);
|
||||
DTEST_LOG << "DSchedContinuationTest PushCallback_003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ContinueMission_001
|
||||
* @tc.desc: test ContinueMission when srcDeviceId is empty.
|
||||
@ -896,5 +1066,238 @@ HWTEST_F(DSchedContinuationTest, NotifyCompleteFreeInstallFromRemote_002, TestSi
|
||||
EXPECT_TRUE(!freeInstallTimeoutFlag_);
|
||||
DTEST_LOG << "DSchedContinuationTest NotifyCompleteFreeInstallFromRemote_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IsFreeInstall_001
|
||||
* @tc.desc: missionId is not exist.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, IsFreeInstall_001, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest IsFreeInstall_001 start" << std::endl;
|
||||
int32_t missionId = -1;
|
||||
bool result = dschedContinuation_->IsFreeInstall(missionId);
|
||||
EXPECT_EQ(result, false);
|
||||
DTEST_LOG << "DSchedContinuationTest IsFreeInstall_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IsFreeInstall_002
|
||||
* @tc.desc: missionId is exist.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, IsFreeInstall_002, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest IsFreeInstall_002 start" << std::endl;
|
||||
int32_t missionId = 1;
|
||||
dschedContinuation_->freeInstall_[missionId] = true;
|
||||
bool result = dschedContinuation_->IsFreeInstall(missionId);
|
||||
EXPECT_EQ(result, true);
|
||||
DTEST_LOG << "DSchedContinuationTest IsFreeInstall_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IsFreeInstall_003
|
||||
* @tc.desc: missionId is exist.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, IsFreeInstall_003, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest IsFreeInstall_003 start" << std::endl;
|
||||
int32_t missionId = 1;
|
||||
dschedContinuation_->freeInstall_[missionId] = false;
|
||||
bool result = dschedContinuation_->IsFreeInstall(missionId);
|
||||
EXPECT_EQ(result, false);
|
||||
DTEST_LOG << "DSchedContinuationTest IsFreeInstall_003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PopCallback_001
|
||||
* @tc.desc: missionId is not exist in callbackMap_.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, PopCallback_001, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest PopCallback_001 start" << std::endl;
|
||||
int32_t missionId = -1;
|
||||
dschedContinuation_->callbackMap_.erase(missionId);
|
||||
sptr<IRemoteObject> result = dschedContinuation_->PopCallback(missionId);
|
||||
EXPECT_EQ(result, nullptr);
|
||||
DTEST_LOG << "DSchedContinuationTest PopCallback_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PopCallback_002
|
||||
* @tc.desc: missionId is not exist in continuationDevices_.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, PopCallback_002, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest PopCallback_002 start" << std::endl;
|
||||
int32_t missionId = -1;
|
||||
dschedContinuation_->callbackMap_[missionId] = GetDSchedService();
|
||||
dschedContinuation_->continuationDevices_.erase(missionId);
|
||||
sptr<IRemoteObject> result = dschedContinuation_->PopCallback(missionId);
|
||||
EXPECT_NE(result, nullptr);
|
||||
DTEST_LOG << "DSchedContinuationTest PopCallback_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PopCallback_003
|
||||
* @tc.desc: missionId is not exist in freeInstall_.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, PopCallback_003, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest PopCallback_003 start" << std::endl;
|
||||
int32_t missionId = -1;
|
||||
dschedContinuation_->callbackMap_[missionId] = GetDSchedService();
|
||||
dschedContinuation_->continuationDevices_[missionId] = "mockDevices";
|
||||
dschedContinuation_->freeInstall_.erase(missionId);
|
||||
sptr<IRemoteObject> result = dschedContinuation_->PopCallback(missionId);
|
||||
EXPECT_NE(result, nullptr);
|
||||
DTEST_LOG << "DSchedContinuationTest PopCallback_003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PopCallback_004
|
||||
* @tc.desc: missionId is exist.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, PopCallback_004, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest PopCallback_004 start" << std::endl;
|
||||
int32_t missionId = -1;
|
||||
dschedContinuation_->callbackMap_[missionId] = GetDSchedService();
|
||||
dschedContinuation_->continuationDevices_[missionId] = "mockDevices";
|
||||
dschedContinuation_->freeInstall_[missionId] = true;
|
||||
sptr<IRemoteObject> result = dschedContinuation_->PopCallback(missionId);
|
||||
EXPECT_NE(result, nullptr);
|
||||
DTEST_LOG << "DSchedContinuationTest PopCallback_004 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: NotifyMissionCenterResult_001
|
||||
* @tc.desc: missionId is not exist in callbackMap_.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, NotifyMissionCenterResult_001, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest NotifyMissionCenterResult_001 start" << std::endl;
|
||||
int32_t missionId = -1;
|
||||
int32_t resultCode = 0;
|
||||
dschedContinuation_->callbackMap_[missionId] = nullptr;
|
||||
int32_t result = dschedContinuation_->NotifyMissionCenterResult(missionId, resultCode);
|
||||
EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
|
||||
DTEST_LOG << "DSchedContinuationTest NotifyMissionCenterResult_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: NotifyMissionCenterResult_002
|
||||
* @tc.desc: missionId is exist.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, NotifyMissionCenterResult_002, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinuationTest NotifyMissionCenterResult_002 start" << std::endl;
|
||||
int32_t missionId = -1;
|
||||
int32_t resultCode = 0;
|
||||
dschedContinuation_->callbackMap_[missionId] = GetDSchedService();
|
||||
dschedContinuation_->NotifyMissionCenterResult(missionId, resultCode);
|
||||
EXPECT_EQ(dschedContinuation_->callbackMap_.size(), 0);
|
||||
DTEST_LOG << "DSchedContinuationTest NotifyMissionCenterResult_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProxyCallContinueMission001
|
||||
* @tc.desc: call dms proxy ContinueMission
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5X9O4
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, ProxyCallContinueMission001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallContinueMission001 start" << std::endl;
|
||||
sptr<IDistributedSched> proxy = GetDms();
|
||||
if (proxy == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::string srcDeviceId;
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(srcDeviceId);
|
||||
WantParams wantParams;
|
||||
int32_t ret = proxy->ContinueMission(srcDeviceId, "MockdevId", 0, GetDSchedService(), wantParams);
|
||||
EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallContinueMission001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProxyCallContinueMission002
|
||||
* @tc.desc: call dms proxy ContinueMission
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5X9O4
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, ProxyCallContinueMission002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallContinueMission002 start" << std::endl;
|
||||
sptr<IDistributedSched> proxy = GetDms();
|
||||
if (proxy == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::string srcDeviceId;
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(srcDeviceId);
|
||||
WantParams wantParams;
|
||||
int32_t ret = proxy->ContinueMission(srcDeviceId, "MockdevId", 0, nullptr, wantParams);
|
||||
EXPECT_EQ(ret, ERR_NULL_OBJECT);
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallContinueMission002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProxyCallStartContinuation001
|
||||
* @tc.desc: call dms proxy StartContinuation
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5X9O4
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, ProxyCallStartContinuation001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartContinuation001 start" << std::endl;
|
||||
sptr<IDistributedSched> proxy = GetDms();
|
||||
if (proxy == nullptr) {
|
||||
return;
|
||||
}
|
||||
OHOS::AAFwk::Want want;
|
||||
want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
|
||||
int32_t ret = proxy->StartContinuation(want, 0, 0, 0, 0);
|
||||
EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartContinuation001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProxyCallNotifyContinuationResultFromRemote001
|
||||
* @tc.desc: call dms proxy NotifyContinuationResultFromRemote
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5X9O4
|
||||
*/
|
||||
HWTEST_F(DSchedContinuationTest, ProxyCallNotifyContinuationResultFromRemote001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallNotifyContinuationResultFromRemote001 start" << std::endl;
|
||||
sptr<IDistributedSched> proxy = GetDms();
|
||||
if (proxy == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::string srcDeviceId;
|
||||
DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(srcDeviceId);
|
||||
proxy->NotifyCompleteContinuation(Str8ToStr16(srcDeviceId), 0, true);
|
||||
int32_t ret = proxy->NotifyContinuationResultFromRemote(0, true);
|
||||
EXPECT_EQ(ret, REQUEST_CODE_ERR);
|
||||
DTEST_LOG << "DistributedSchedServiceTest ProxyCallNotifyContinuationResultFromRemote001 end" << std::endl;
|
||||
}
|
||||
} // DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -16,9 +16,9 @@
|
||||
#ifndef DISTRIBUTED_SCHED_CONTINUATION_TEST_H
|
||||
#define DISTRIBUTED_SCHED_CONTINUATION_TEST_H
|
||||
|
||||
#include "distributed_sched_continuation.h"
|
||||
#include "distributed_sched_proxy.h"
|
||||
#define private public
|
||||
#include "distributed_sched_continuation.h"
|
||||
#include "distributed_sched_service.h"
|
||||
#undef private
|
||||
#include "gtest/gtest.h"
|
||||
|
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "distributed_sched_dumper_test.h"
|
||||
#include "test_log.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
void DistributedSchedDumperTest::SetUpTestCase()
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedDumperTest::SetUpTestCase" << std::endl;
|
||||
}
|
||||
|
||||
void DistributedSchedDumperTest::TearDownTestCase()
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedDumperTest::TearDownTestCase" << std::endl;
|
||||
}
|
||||
|
||||
void DistributedSchedDumperTest::TearDown()
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedDumperTest::TearDown" << std::endl;
|
||||
}
|
||||
|
||||
void DistributedSchedDumperTest::SetUp()
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedDumperTest::SetUp" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DumpDefault_001
|
||||
* @tc.desc: dump default info
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedDumperTest, DumpDefault_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedDumperTest DumpDefault_001 begin" << std::endl;
|
||||
std::string result = "";
|
||||
bool res = DistributedSchedDumper::DumpDefault(result);
|
||||
EXPECT_EQ(res, true);
|
||||
DTEST_LOG << "DistributedSchedDumperTest DumpDefault_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Dump_001
|
||||
* @tc.desc: dump info with null arg
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedDumperTest, Dump_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedDumperTest Dump_001 begin" << std::endl;
|
||||
const std::vector<std::string> args = {};
|
||||
std::string result = "";
|
||||
bool res = DistributedSchedDumper::Dump(args, result);
|
||||
EXPECT_EQ(res, true);
|
||||
DTEST_LOG << "DistributedSchedDumperTest Dump_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Dump_002
|
||||
* @tc.desc: dump info with a correct arg
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedDumperTest, Dump_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedDumperTest Dump_002 begin" << std::endl;
|
||||
const std::vector<std::string> args = {"-connect"};
|
||||
std::string result = "";
|
||||
bool res = DistributedSchedDumper::Dump(args, result);
|
||||
EXPECT_EQ(res, true);
|
||||
DTEST_LOG << "DistributedSchedDumperTest Dump_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Dump_003
|
||||
* @tc.desc: dump info with a invalid arg
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedDumperTest, Dump_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedDumperTest Dump_003 begin" << std::endl;
|
||||
const std::vector<std::string> args = {"-invalid"};
|
||||
std::string result = "";
|
||||
bool res = DistributedSchedDumper::Dump(args, result);
|
||||
EXPECT_EQ(res, false);
|
||||
DTEST_LOG << "DistributedSchedDumperTest Dump_003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Dump_004
|
||||
* @tc.desc: dump info with two args
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I60TOK
|
||||
*/
|
||||
HWTEST_F(DistributedSchedDumperTest, Dump_004, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedSchedDumperTest Dump_004 begin" << std::endl;
|
||||
const std::vector<std::string> args = {"-invalid1", "-invalid2"};
|
||||
std::string result = "";
|
||||
bool res = DistributedSchedDumper::Dump(args, result);
|
||||
EXPECT_EQ(res, false);
|
||||
DTEST_LOG << "DistributedSchedDumperTest Dump_004 end" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef DISTRIBUTED_SCHED_DUMPER_TEST_H
|
||||
#define DISTRIBUTED_SCHED_DUMPER_TEST_H
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#define private public
|
||||
#include "distributed_sched_dumper.h"
|
||||
#undef private
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class DistributedSchedDumperTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // DISTRIBUTED_SCHED_DUMPER_TEST_H
|
1729
services/dtbschedmgr/test/unittest/distributed_sched_stub_test.cpp
Normal file
1729
services/dtbschedmgr/test/unittest/distributed_sched_stub_test.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef DISTRIBUTED_SCHED_STUB_TEST_H
|
||||
#define DISTRIBUTED_SCHED_STUB_TEST_H
|
||||
|
||||
#include "distributed_sched_interface.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "gtest/gtest.h"
|
||||
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
|
||||
#include "mission/snapshot.h"
|
||||
#endif
|
||||
|
||||
#define private public
|
||||
#include "distributed_sched_stub.h"
|
||||
#undef private
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class DistributedSchedStubTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
sptr<DistributedSchedStub> distributedSchedStub_;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // DISTRIBUTED_SCHED_STUB_TEST_H
|
@ -89,6 +89,29 @@ HWTEST_F(DmsTokenCallbackTest, SendResultTest_002, TestSize.Level3)
|
||||
DTEST_LOG << "DmsTokenCallbackTest SendResultTest_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SendResultTest_003
|
||||
* @tc.desc: call SendResult with local device id
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5WKCK
|
||||
*/
|
||||
HWTEST_F(DmsTokenCallbackTest, SendResultTest_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsTokenCallbackTest SendResultTest_003 begin" << std::endl;
|
||||
AAFwk::Want want;
|
||||
string localDeviceId;
|
||||
dmsTokenCallback_->GetLocalDeviceId(localDeviceId);
|
||||
want.SetParam("dmsSrcNetworkId", localDeviceId);
|
||||
int32_t callerUid = 0;
|
||||
int32_t requestCode = 0;
|
||||
uint32_t accessToken = 0;
|
||||
int32_t resultCode = 0;
|
||||
DistributedSchedUtil::MockProcess(FOUNDATION_PROCESS_NAME);
|
||||
int32_t result = dmsTokenCallback_->SendResult(want, callerUid, requestCode, accessToken, resultCode);
|
||||
EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
|
||||
DTEST_LOG << "DmsTokenCallbackTest SendResultTest_003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CheckDeviceIdTest_001
|
||||
* @tc.desc: call CheckDeviceId with empty deviceId
|
||||
|
@ -27,10 +27,6 @@ using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
|
||||
}
|
||||
|
||||
void DmsVersionManagerTest::SetUpTestCase()
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest::SetUpTestCase" << std::endl;
|
||||
@ -133,14 +129,14 @@ HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_001, TestSize.Level3)
|
||||
|
||||
/**
|
||||
* @tc.name: ParseDmsVersionTest_002
|
||||
* @tc.desc: test call ParseDmsVersion with invaild dmsVersionData
|
||||
* @tc.desc: test call ParseDmsVersion with invalid dmsVersionData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_002 begin" << std::endl;
|
||||
std::string dmsVersionData = "invaild.2.1";
|
||||
std::string dmsVersionData = "invalid.2.1";
|
||||
DmsVersion dmsVersion;
|
||||
bool result = DmsVersionManager::ParseDmsVersion(dmsVersionData, dmsVersion);
|
||||
EXPECT_EQ(result, false);
|
||||
@ -149,7 +145,7 @@ HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_002, TestSize.Level3)
|
||||
|
||||
/**
|
||||
* @tc.name: ParseDmsVersionTest_003
|
||||
* @tc.desc: test call ParseDmsVersion with invaild dmsVersionData
|
||||
* @tc.desc: test call ParseDmsVersion with invalid dmsVersionData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
@ -165,14 +161,14 @@ HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_003, TestSize.Level3)
|
||||
|
||||
/**
|
||||
* @tc.name: ParseDmsVersionTest_004
|
||||
* @tc.desc: test call ParseDmsVersion with invaild dmsVersionData
|
||||
* @tc.desc: test call ParseDmsVersion with invalid dmsVersionData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_004, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_004 begin" << std::endl;
|
||||
std::string dmsVersionData = "3.invaild.1";
|
||||
std::string dmsVersionData = "3.invalid.1";
|
||||
DmsVersion dmsVersion;
|
||||
bool result = DmsVersionManager::ParseDmsVersion(dmsVersionData, dmsVersion);
|
||||
EXPECT_EQ(result, false);
|
||||
@ -181,7 +177,7 @@ HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_004, TestSize.Level3)
|
||||
|
||||
/**
|
||||
* @tc.name: ParseDmsVersionTest_005
|
||||
* @tc.desc: test call ParseDmsVersion with invaild dmsVersionData
|
||||
* @tc.desc: test call ParseDmsVersion with invalid dmsVersionData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
@ -197,14 +193,14 @@ HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_005, TestSize.Level3)
|
||||
|
||||
/**
|
||||
* @tc.name: ParseDmsVersionTest_006
|
||||
* @tc.desc: test call ParseDmsVersion with invaild dmsVersionData
|
||||
* @tc.desc: test call ParseDmsVersion with invalid dmsVersionData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_006, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsVersionManagerTest ParseDmsVersionTest_006 begin" << std::endl;
|
||||
std::string dmsVersionData = "3.2.invaild";
|
||||
std::string dmsVersionData = "3.2.invalid";
|
||||
DmsVersion dmsVersion;
|
||||
bool result = DmsVersionManager::ParseDmsVersion(dmsVersionData, dmsVersion);
|
||||
EXPECT_EQ(result, false);
|
||||
@ -213,7 +209,7 @@ HWTEST_F(DmsVersionManagerTest, ParseDmsVersionTest_006, TestSize.Level3)
|
||||
|
||||
/**
|
||||
* @tc.name: ParseDmsVersionTest_007
|
||||
* @tc.desc: test call ParseDmsVersion with invaild dmsVersionData
|
||||
* @tc.desc: test call ParseDmsVersion with invalid dmsVersionData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
@ -281,7 +277,7 @@ HWTEST_F(DmsVersionManagerTest, GetDmsVersionDataFromAppInfo_002, TestSize.Level
|
||||
|
||||
/**
|
||||
* @tc.name: GetDmsVersionDataFromAppInfo_003
|
||||
* @tc.desc: test call GetDmsVersionDataFromAppInfo with invaild data
|
||||
* @tc.desc: test call GetDmsVersionDataFromAppInfo with invalid data
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
@ -299,7 +295,7 @@ HWTEST_F(DmsVersionManagerTest, GetDmsVersionDataFromAppInfo_003, TestSize.Level
|
||||
|
||||
/**
|
||||
* @tc.name: GetDmsVersionDataFromAppInfo_004
|
||||
* @tc.desc: test call GetDmsVersionDataFromAppInfo with invaild data
|
||||
* @tc.desc: test call GetDmsVersionDataFromAppInfo with invalid data
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
@ -335,7 +331,7 @@ HWTEST_F(DmsVersionManagerTest, GetDmsVersionDataFromAppInfo_005, TestSize.Level
|
||||
|
||||
/**
|
||||
* @tc.name: GetAppInfoFromDP_001
|
||||
* @tc.desc: test call GetAppInfoFromDP with invaild device id
|
||||
* @tc.desc: test call GetAppInfoFromDP with invalid device id
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
@ -403,7 +399,7 @@ HWTEST_F(DmsVersionManagerTest, ParseAppInfo_002, TestSize.Level3)
|
||||
|
||||
/**
|
||||
* @tc.name: ParseAppInfo_003
|
||||
* @tc.desc: test call ParseAppInfo with invaild packageNamesData
|
||||
* @tc.desc: test call ParseAppInfo with invalid packageNamesData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
@ -439,7 +435,7 @@ HWTEST_F(DmsVersionManagerTest, ParseAppInfo_004, TestSize.Level3)
|
||||
|
||||
/**
|
||||
* @tc.name: ParseAppInfo_005
|
||||
* @tc.desc: test call ParseAppInfo with invaild versionsData
|
||||
* @tc.desc: test call ParseAppInfo with invalid versionsData
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
@ -475,7 +471,7 @@ HWTEST_F(DmsVersionManagerTest, ParseAppInfo_006, TestSize.Level3)
|
||||
|
||||
/**
|
||||
* @tc.name: GetRemoteDmsVersion_001
|
||||
* @tc.desc: test call GetRemoteDmsVersion with invaild deviceId
|
||||
* @tc.desc: test call GetRemoteDmsVersion with invalid deviceId
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
@ -507,7 +503,7 @@ HWTEST_F(DmsVersionManagerTest, GetRemoteDmsVersion_002, TestSize.Level3)
|
||||
|
||||
/**
|
||||
* @tc.name: IsRemoteDmsVersionLower_001
|
||||
* @tc.desc: test call IsRemoteDmsVersionLower with invaild deviceId
|
||||
* @tc.desc: test call IsRemoteDmsVersionLower with invalid deviceId
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5RWKZ
|
||||
*/
|
||||
|
@ -14,14 +14,24 @@
|
||||
*/
|
||||
|
||||
#include "distributed_mission_info_test.h"
|
||||
#include <memory>
|
||||
#define private public
|
||||
#include "mission/distributed_mission_info.h"
|
||||
#undef private
|
||||
#include "mission/mission_constant.h"
|
||||
#include "parcel_helper.h"
|
||||
#include "test_log.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
constexpr int32_t TEST_INVALID_VALUE = -1;
|
||||
constexpr int32_t TEST_PARCEL_WRITE_VALUE = 1;
|
||||
constexpr size_t TEST_PARCEL_WRITE_LEN = 5;
|
||||
}
|
||||
void DistributedMissionInfoTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
@ -38,13 +48,87 @@ void DistributedMissionInfoTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReadFromParcel001
|
||||
* @tc.desc: test ReadFromParcel
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5O2P9
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testReadFromParcel001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadFromParcel001 start" << std::endl;
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
Parcel parcel;
|
||||
bool ret = dstbMissionInfo.Marshalling(parcel);
|
||||
EXPECT_TRUE(ret);
|
||||
ret = dstbMissionInfo.ReadFromParcel(parcel);
|
||||
EXPECT_TRUE(ret);
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadFromParcel001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReadFromParcel002
|
||||
* @tc.desc: test ReadFromParcel when combinedMissionIds read failed
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5O2P9
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testReadFromParcel002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadFromParcel002 start" << std::endl;
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
Parcel parcel;
|
||||
for (size_t i = 0; i < TEST_PARCEL_WRITE_LEN; i++) {
|
||||
parcel.WriteInt32(TEST_PARCEL_WRITE_VALUE);
|
||||
}
|
||||
bool ret = dstbMissionInfo.ReadFromParcel(parcel);
|
||||
EXPECT_FALSE(ret);
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadFromParcel002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testUnmarshalling001
|
||||
* @tc.desc: test Unmarshalling
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5O2P9
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testUnmarshalling001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testUnmarshalling001 start" << std::endl;
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
Parcel parcel;
|
||||
bool ret = dstbMissionInfo.Marshalling(parcel);
|
||||
EXPECT_TRUE(ret);
|
||||
DstbMissionInfo* dstbMissionInfoReturn = dstbMissionInfo.Unmarshalling(parcel);
|
||||
EXPECT_NE(nullptr, dstbMissionInfoReturn);
|
||||
DTEST_LOG << "DistributedMissionInfoTest testUnmarshalling001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testUnmarshalling002
|
||||
* @tc.desc: test Unmarshalling when combinedMissionIds read failed
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5O2P9
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testUnmarshalling002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testUnmarshalling002 start" << std::endl;
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
Parcel parcel;
|
||||
for (size_t i = 0; i < TEST_PARCEL_WRITE_LEN; i++) {
|
||||
parcel.WriteInt32(TEST_PARCEL_WRITE_VALUE);
|
||||
}
|
||||
DstbMissionInfo* dstbMissionInfoReturn = dstbMissionInfo.Unmarshalling(parcel);
|
||||
EXPECT_EQ(nullptr, dstbMissionInfoReturn);
|
||||
DTEST_LOG << "DistributedMissionInfoTest testUnmarshalling002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testMarshalling001
|
||||
* @tc.desc: write data to parcel
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5O2P9
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testMarshalling001, TestSize.Level1)
|
||||
HWTEST_F(DistributedMissionInfoTest, testMarshalling001, TestSize.Level3)
|
||||
{
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
Parcel data;
|
||||
@ -52,17 +136,206 @@ HWTEST_F(DistributedMissionInfoTest, testMarshalling001, TestSize.Level1)
|
||||
EXPECT_EQ(ret, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReadDstbMissionInfosFromParcel001
|
||||
* @tc.desc: test ReadDstbMissionInfosFromParcel
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5O2P9
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testReadDstbMissionInfosFromParcel001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadDstbMissionInfosFromParcel001 start" << std::endl;
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
Parcel parcel;
|
||||
std::vector<DstbMissionInfo> missionInfos;
|
||||
bool ret = dstbMissionInfo.ReadDstbMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_EQ(0, missionInfos.size());
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadDstbMissionInfosFromParcel001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReadDstbMissionInfosFromParcel002
|
||||
* @tc.desc: test ReadDstbMissionInfosFromParcel when len < 0
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5O2P9
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testReadDstbMissionInfosFromParcel002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadDstbMissionInfosFromParcel002 start" << std::endl;
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
Parcel parcel;
|
||||
std::vector<DstbMissionInfo> missionInfos;
|
||||
parcel.WriteInt32(TEST_PARCEL_WRITE_VALUE);
|
||||
parcel.WriteInt32(TEST_INVALID_VALUE);
|
||||
bool ret = dstbMissionInfo.ReadDstbMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_FALSE(ret);
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadDstbMissionInfosFromParcel002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReadDstbMissionInfosFromParcel003
|
||||
* @tc.desc: test ReadDstbMissionInfosFromParcel when size > parcel.GetReadableBytes()
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5O2P9
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testReadDstbMissionInfosFromParcel003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadDstbMissionInfosFromParcel003 start" << std::endl;
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
Parcel parcel;
|
||||
std::vector<DstbMissionInfo> missionInfos;
|
||||
parcel.WriteInt32(TEST_PARCEL_WRITE_VALUE);
|
||||
parcel.WriteInt32(parcel.GetReadableBytes() + 1);
|
||||
bool ret = dstbMissionInfo.ReadDstbMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_FALSE(ret);
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadDstbMissionInfosFromParcel003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReadDstbMissionInfosFromParcel004
|
||||
* @tc.desc: test ReadDstbMissionInfosFromParcel when size > GET_MAX_MISSIONS
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5O2P9
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testReadDstbMissionInfosFromParcel004, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadDstbMissionInfosFromParcel004 start" << std::endl;
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
Parcel parcel;
|
||||
std::vector<DstbMissionInfo> missionInfos;
|
||||
parcel.WriteInt32(TEST_PARCEL_WRITE_VALUE);
|
||||
parcel.WriteInt32(Constants::Mission::GET_MAX_MISSIONS + 1);
|
||||
bool ret = dstbMissionInfo.ReadDstbMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_FALSE(ret);
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadDstbMissionInfosFromParcel004 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReadDstbMissionInfosFromParcel005
|
||||
* @tc.desc: test ReadDstbMissionInfosFromParcel when size = GET_MAX_MISSIONS - 1
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5O2P9
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testReadDstbMissionInfosFromParcel005, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadDstbMissionInfosFromParcel005 start" << std::endl;
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
Parcel parcel;
|
||||
std::vector<DstbMissionInfo> missionInfos;
|
||||
parcel.WriteInt32(TEST_PARCEL_WRITE_VALUE);
|
||||
parcel.WriteInt32(Constants::Mission::GET_MAX_MISSIONS - 1);
|
||||
bool ret = dstbMissionInfo.ReadDstbMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_FALSE(ret);
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadDstbMissionInfosFromParcel005 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReadDstbMissionInfosFromParcel006
|
||||
* @tc.desc: test ReadDstbMissionInfosFromParcel when ptr is nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5O2P9
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testReadDstbMissionInfosFromParcel006, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadDstbMissionInfosFromParcel006 start" << std::endl;
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
Parcel parcel;
|
||||
std::vector<DstbMissionInfo> missionInfos;
|
||||
parcel.WriteInt32(TEST_PARCEL_WRITE_VALUE);
|
||||
parcel.WriteInt32(TEST_PARCEL_WRITE_VALUE);
|
||||
parcel.WriteParcelable(nullptr);
|
||||
bool ret = dstbMissionInfo.ReadDstbMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_FALSE(ret);
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadDstbMissionInfosFromParcel006 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReadDstbMissionInfosFromParcel007
|
||||
* @tc.desc: test ReadDstbMissionInfosFromParcel when ptr is not nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5O2P9
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testReadDstbMissionInfosFromParcel007, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadDstbMissionInfosFromParcel007 start" << std::endl;
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
Parcel parcel;
|
||||
std::vector<DstbMissionInfo> missionInfos;
|
||||
parcel.WriteInt32(TEST_PARCEL_WRITE_VALUE);
|
||||
parcel.WriteInt32(TEST_PARCEL_WRITE_VALUE);
|
||||
parcel.WriteParcelable(&dstbMissionInfo);
|
||||
bool ret = dstbMissionInfo.ReadDstbMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_EQ(1, missionInfos.size());
|
||||
DTEST_LOG << "DistributedMissionInfoTest testReadDstbMissionInfosFromParcel007 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testWriteDstbMissionInfosToParcel001
|
||||
* @tc.desc: test WriteDstbMissionInfosToParcel when missionInfos is empty
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5O2P9
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testWriteDstbMissionInfosToParcel001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testWriteDstbMissionInfosToParcel001 start" << std::endl;
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
Parcel parcel;
|
||||
std::vector<DstbMissionInfo> missionInfos;
|
||||
bool ret = dstbMissionInfo.WriteDstbMissionInfosToParcel(parcel, missionInfos);
|
||||
EXPECT_TRUE(ret);
|
||||
DTEST_LOG << "DistributedMissionInfoTest testWriteDstbMissionInfosToParcel001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testWriteDstbMissionInfosToParcel002
|
||||
* @tc.desc: test WriteDstbMissionInfosToParcel
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5O2P9
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testWriteDstbMissionInfosToParcel002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testWriteDstbMissionInfosToParcel002 start" << std::endl;
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
Parcel parcel;
|
||||
std::vector<DstbMissionInfo> missionInfos;
|
||||
missionInfos.emplace_back(dstbMissionInfo);
|
||||
bool ret = dstbMissionInfo.WriteDstbMissionInfosToParcel(parcel, missionInfos);
|
||||
EXPECT_TRUE(ret);
|
||||
DTEST_LOG << "DistributedMissionInfoTest testWriteDstbMissionInfosToParcel002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testToString001
|
||||
* @tc.desc: print a missionInfo
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5O2P9
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testToString001, TestSize.Level1)
|
||||
HWTEST_F(DistributedMissionInfoTest, testToString001, TestSize.Level3)
|
||||
{
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
auto ret = dstbMissionInfo.ToString();
|
||||
EXPECT_NE(ret, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testToString002
|
||||
* @tc.desc: test ToString
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5O2P9
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testToString002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testToString002 start" << std::endl;
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
dstbMissionInfo.baseWant = std::make_shared<AAFwk::Want>();
|
||||
dstbMissionInfo.topAbility = std::make_shared<AppExecFwk::ElementName>();
|
||||
dstbMissionInfo.baseAbility = std::make_shared<AppExecFwk::ElementName>();
|
||||
dstbMissionInfo.reservedAbility = std::make_shared<AppExecFwk::ElementName>();
|
||||
std::string ret = dstbMissionInfo.ToString();
|
||||
EXPECT_FALSE(ret.empty());
|
||||
DTEST_LOG << "DistributedMissionInfoTest testToString002 end" << std::endl;
|
||||
}
|
||||
} // DistributedSchedule
|
||||
} // namespace OHOS
|
File diff suppressed because it is too large
Load Diff
@ -34,6 +34,7 @@ protected:
|
||||
std::string localDeviceId_;
|
||||
std::u16string u16localDeviceId_;
|
||||
sptr<IDistributedSched> proxy_;
|
||||
std::set<std::string> remoteSyncDeviceSet_;
|
||||
sptr<IDistributedSched> GetDms();
|
||||
|
||||
class DeviceInitCallBack : public OHOS::DistributedHardware::DmInitCallback {
|
||||
|
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mission_info_converter_test.h"
|
||||
|
||||
#include "mission/distributed_mission_info.h"
|
||||
#include "mission/mission_constant.h"
|
||||
#include "mission/mission_info_converter.h"
|
||||
#include "parcel_helper.h"
|
||||
#include "test_log.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TAG = "MissionInfoConverter";
|
||||
}
|
||||
|
||||
void MissionInfoConverterTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void MissionInfoConverterTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void MissionInfoConverterTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void MissionInfoConverterTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testConvertToDstbMissionInfos_001
|
||||
* @tc.desc: test ConvertToDstbMissionInfos when missionInfos is empty
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MissionInfoConverterTest, testConvertToDstbMissionInfos_001, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "MissionInfoConverterTest testConvertToDstbMissionInfos_001 begin" << std::endl;
|
||||
std::vector<AAFwk::MissionInfo> missionInfos;
|
||||
std::vector<DstbMissionInfo> dstbMissionInfos;
|
||||
int32_t result = MissionInfoConverter::ConvertToDstbMissionInfos(missionInfos, dstbMissionInfos);
|
||||
EXPECT_EQ(ERR_OK, result);
|
||||
DTEST_LOG << "MissionInfoConverterTest testConvertToDstbMissionInfos_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testConvertToMissionInfos_001
|
||||
* @tc.desc: test ConvertToMissionInfos when missionInfos is empty
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MissionInfoConverterTest, testConvertToMissionInfos_001, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "MissionInfoConverterTest testConvertToMissionInfos_001 begin" << std::endl;
|
||||
std::vector<AAFwk::MissionInfo> missionInfos;
|
||||
std::vector<DstbMissionInfo> dstbMissionInfos;
|
||||
int32_t result = MissionInfoConverter::ConvertToMissionInfos(dstbMissionInfos, missionInfos);
|
||||
EXPECT_EQ(ERR_OK, result);
|
||||
DTEST_LOG << "MissionInfoConverterTest testConvertToMissionInfos_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testWriteMissionInfosToParcel_001
|
||||
* @tc.desc: test WriteMissionInfosToParcel when missionInfos is empty
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MissionInfoConverterTest, testWriteMissionInfosToParcel_001, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "MissionInfoConverterTest testWriteMissionInfosToParcel_001 begin" << std::endl;
|
||||
Parcel parcel;
|
||||
std::vector<AAFwk::MissionInfo> missionInfos;
|
||||
/**
|
||||
* @tc.steps: step1. test WriteMissionInfosToParcel when missionInfos.size is 0;
|
||||
*/
|
||||
bool result = MissionInfoConverter::WriteMissionInfosToParcel(parcel, missionInfos);
|
||||
EXPECT_TRUE(result);
|
||||
/**
|
||||
* @tc.steps: step2. test ReadMissionInfosFromParcel when empty is not VALUE_OBJECT;
|
||||
*/
|
||||
result = MissionInfoConverter::ReadMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ReadMissionInfosFromParcel_001
|
||||
* @tc.desc: test ReadMissionInfosFromParcel when missionInfos is empty
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MissionInfoConverterTest, ReadMissionInfosFromParcel_001, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "MissionInfoConverterTest ReadMissionInfosFromParcel_001 begin" << std::endl;
|
||||
MessageParcel parcel;
|
||||
std::vector<AAFwk::MissionInfo> missionInfos;
|
||||
/**
|
||||
* @tc.steps: step1. test ReadMissionInfosFromParcel when len is less than 0;
|
||||
*/
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, 1);
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, -1);
|
||||
bool result = MissionInfoConverter::ReadMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_TRUE(missionInfos.empty());
|
||||
/**
|
||||
* @tc.steps: step2. test ReadMissionInfosFromParcel when len = parcel.GetReadableBytes() + 1;
|
||||
*/
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, 1);
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, parcel.GetReadableBytes() + 1);
|
||||
result = MissionInfoConverter::ReadMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_TRUE(missionInfos.empty());
|
||||
/**
|
||||
* @tc.steps: step3. test ReadMissionInfosFromParcel when len = GET_MAX_MISSIONS + 1;
|
||||
*/
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, 1);
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, Constants::Mission::GET_MAX_MISSIONS + 1);
|
||||
result = MissionInfoConverter::ReadMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_TRUE(missionInfos.empty());
|
||||
/**
|
||||
* @tc.steps: step4. test ReadMissionInfosFromParcel when len = GET_MAX_MISSIONS - 1;
|
||||
*/
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, 1);
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, Constants::Mission::GET_MAX_MISSIONS - 1);
|
||||
result = MissionInfoConverter::ReadMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_TRUE(missionInfos.empty());
|
||||
DTEST_LOG << "MissionInfoConverterTest ReadMissionInfosFromParcel_001 end" << std::endl;
|
||||
}
|
||||
} // DistributedSchedule
|
||||
} // namespace OHOS
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MISSION_INFO_CONVERTER_TEST_H
|
||||
#define MISSION_INFO_CONVERTER_TEST_H
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class MissionInfoConverterTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif /* MISSION_INFO_CONVERTER_TEST_H */
|
||||
|
@ -16,12 +16,19 @@
|
||||
#include "snapshot_test.h"
|
||||
#define private public
|
||||
#include "mission/snapshot.h"
|
||||
#undef private
|
||||
#include "parcel_helper.h"
|
||||
#include "test_log.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TAG = "Snapshot";
|
||||
constexpr size_t TEST_PARCEL_WRITE_VALUE = 1;
|
||||
}
|
||||
void SnapshotTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
@ -52,6 +59,69 @@ HWTEST_F(SnapshotTest, testWriteToParcel001, TestSize.Level1)
|
||||
EXPECT_EQ(ret, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testWriteToParcel002
|
||||
* @tc.desc: test WriteToParcel when rect_ is not nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5Y2VH
|
||||
*/
|
||||
HWTEST_F(SnapshotTest, testWriteToParcel002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "SnapshotTest testWriteToParcel002 start" << std::endl;
|
||||
Snapshot snapshot;
|
||||
MessageParcel data;
|
||||
snapshot.rect_ = std::make_unique<Rect>(0, 0, 0, 0);
|
||||
bool ret = snapshot.WriteToParcel(data);
|
||||
EXPECT_TRUE(ret);
|
||||
DTEST_LOG << "SnapshotTest testWriteToParcel002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testWriteToParcel003
|
||||
* @tc.desc: test WriteToParcel when windowBounds_ is not nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5Y2VH
|
||||
*/
|
||||
HWTEST_F(SnapshotTest, testWriteToParcel003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "SnapshotTest testWriteToParcel003 start" << std::endl;
|
||||
Snapshot snapshot;
|
||||
MessageParcel data;
|
||||
snapshot.rect_ = std::make_unique<Rect>(0, 0, 0, 0);
|
||||
snapshot.windowBounds_ = std::make_unique<Rect>(0, 0, 0, 0);
|
||||
bool ret = snapshot.WriteToParcel(data);
|
||||
EXPECT_TRUE(ret);
|
||||
DTEST_LOG << "SnapshotTest testWriteToParcel003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testWriteToParcel004
|
||||
* @tc.desc: test WriteToParcel when pixelMap_ is not nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5Y2VH
|
||||
*/
|
||||
HWTEST_F(SnapshotTest, testWriteToParcel004, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "SnapshotTest testWriteToParcel004 start" << std::endl;
|
||||
Snapshot snapshot;
|
||||
MessageParcel data;
|
||||
snapshot.rect_ = std::make_unique<Rect>(0, 0, 0, 0);
|
||||
snapshot.windowBounds_ = std::make_unique<Rect>(0, 0, 0, 0);
|
||||
uint8_t buffer = (uint8_t)TEST_PARCEL_WRITE_VALUE;
|
||||
snapshot.pixelMap_ = snapshot.CreatePixelMap(&buffer, TEST_PARCEL_WRITE_VALUE);
|
||||
/**
|
||||
* @tc.steps: step1. WriteToParcel when pixelMap_ is not nullptr
|
||||
*/
|
||||
bool ret = snapshot.WriteToParcel(data);
|
||||
EXPECT_TRUE(ret);
|
||||
/**
|
||||
* @tc.steps: step2. FillSnapShot
|
||||
*/
|
||||
std::unique_ptr<Snapshot> snapShotReturn = snapshot.FillSnapShot(data);
|
||||
EXPECT_NE(nullptr, snapShotReturn);
|
||||
DTEST_LOG << "SnapshotTest testWriteToParcel004 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testFillSnapShot001
|
||||
* @tc.desc: fill up a snapshot
|
||||
@ -79,5 +149,74 @@ HWTEST_F(SnapshotTest, testWriteSnapshotInfo001, TestSize.Level1)
|
||||
auto ret = snapshot.WriteSnapshotInfo(data);
|
||||
EXPECT_EQ(ret, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testCreate001
|
||||
* @tc.desc: test Create when buffer is nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5Y2VH
|
||||
*/
|
||||
HWTEST_F(SnapshotTest, testCreate001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "SnapshotTest testCreate001 start" << std::endl;
|
||||
Snapshot snapshot;
|
||||
std::vector<uint8_t> data;
|
||||
/**
|
||||
* @tc.steps: step1. Create when data is empty;
|
||||
*/
|
||||
std::unique_ptr<Snapshot> ret = snapshot.Create(data);
|
||||
EXPECT_EQ(nullptr, ret);
|
||||
/**
|
||||
* @tc.steps: step2. Create when data is not empty;
|
||||
*/
|
||||
data.emplace_back(1);
|
||||
EXPECT_EQ(nullptr, ret);
|
||||
DTEST_LOG << "SnapshotTest testCreate001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testGetCreatedTime001
|
||||
* @tc.desc: test GetCreatedTime
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5Y2VH
|
||||
*/
|
||||
HWTEST_F(SnapshotTest, testGetCreatedTime001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "SnapshotTest testGetCreatedTime001 start" << std::endl;
|
||||
Snapshot snapshot;
|
||||
int64_t ret = snapshot.GetCreatedTime();
|
||||
EXPECT_EQ(0, ret);
|
||||
DTEST_LOG << "SnapshotTest testGetCreatedTime001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testGetLastAccessTime001
|
||||
* @tc.desc: test GetLastAccessTime
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5Y2VH
|
||||
*/
|
||||
HWTEST_F(SnapshotTest, testGetLastAccessTime001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "SnapshotTest testGetCreatedTime001 start" << std::endl;
|
||||
Snapshot snapshot;
|
||||
int64_t ret = snapshot.GetLastAccessTime();
|
||||
EXPECT_EQ(0, ret);
|
||||
DTEST_LOG << "SnapshotTest testGetLastAccessTime001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testUpdateLastAccessTime001
|
||||
* @tc.desc: test UpdateLastAccessTime
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5Y2VH
|
||||
*/
|
||||
HWTEST_F(SnapshotTest, testUpdateLastAccessTime001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "SnapshotTest testUpdateLastAccessTime001 start" << std::endl;
|
||||
Snapshot snapshot;
|
||||
snapshot.UpdateLastAccessTime(TEST_PARCEL_WRITE_VALUE);
|
||||
EXPECT_EQ((int64_t)TEST_PARCEL_WRITE_VALUE, snapshot.lastAccessTime_);
|
||||
DTEST_LOG << "SnapshotTest testUpdateLastAccessTime001 end" << std::endl;
|
||||
}
|
||||
} // DistributedSchedule
|
||||
} // namespace OHOS
|
@ -75,7 +75,7 @@ ohos_fuzztest("ContinuationManagerFuzzTest") {
|
||||
|
||||
sources = [
|
||||
"continuationmanager_fuzzer.cpp",
|
||||
"mock_permission.cpp",
|
||||
"fuzz_util.cpp",
|
||||
]
|
||||
|
||||
sources += dtbabilitymgr_sources
|
||||
|
@ -18,10 +18,11 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "distributed_ability_manager_interface.h"
|
||||
#include "distributed_ability_manager_stub.h"
|
||||
#include "distributed_ability_manager_service.h"
|
||||
#include "mock_permission.h"
|
||||
#include "fuzz_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
@ -31,6 +32,8 @@ namespace {
|
||||
constexpr uint16_t MAX_CALL_TRANSACTION = 510;
|
||||
constexpr int32_t OFFSET = 4;
|
||||
const std::u16string DMS_INTERFACE_TOKEN = u"OHOS.DistributedSchedule.IDistributedAbilityManager";
|
||||
const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
|
||||
const std::string TAG = "ContinuationFuzz";
|
||||
}
|
||||
|
||||
uint32_t Convert2Uint32(const uint8_t* ptr)
|
||||
@ -43,19 +46,27 @@ uint32_t Convert2Uint32(const uint8_t* ptr)
|
||||
|
||||
void FuzzUnregister(const uint8_t* rawData, size_t size)
|
||||
{
|
||||
DmsMockPermission::MockPermission();
|
||||
FuzzUtil::MockPermission();
|
||||
uint32_t code = Convert2Uint32(rawData);
|
||||
rawData = rawData + OFFSET;
|
||||
size = size - OFFSET;
|
||||
MessageParcel data;
|
||||
data.WriteInterfaceToken(DMS_INTERFACE_TOKEN);
|
||||
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
|
||||
data.WriteBuffer(rawData, size);
|
||||
data.RewindRead(0);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
std::shared_ptr<DistributedAbilityManagerService> dtbAbilityMgr(
|
||||
new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true));
|
||||
dtbAbilityMgr->OnRemoteRequest(code % MAX_CALL_TRANSACTION, data, reply, option);
|
||||
auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (systemAbilityMgr == nullptr) {
|
||||
HILOGE("system ability manager is nullptr.");
|
||||
return;
|
||||
}
|
||||
auto remoteObj = systemAbilityMgr->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
|
||||
if (remoteObj == nullptr) {
|
||||
HILOGE("failed to get form manager service");
|
||||
return;
|
||||
}
|
||||
remoteObj->SendRequest(code % MAX_CALL_TRANSACTION, data, reply, option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,29 +13,42 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mock_permission.h"
|
||||
#include "fuzz_util.h"
|
||||
|
||||
#include "accesstoken_kit.h"
|
||||
#include "nativetoken_kit.h"
|
||||
#include "token_setproc.h"
|
||||
|
||||
namespace OHOS {
|
||||
void DmsMockPermission::MockPermission()
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const char* DISTSCHED_PROCESS_NAME = "foundation";
|
||||
}
|
||||
|
||||
void FuzzUtil::MockPermission()
|
||||
{
|
||||
static const char *PERMS[] = {
|
||||
"ohos.permission.DISTRIBUTED_DATASYNC"
|
||||
};
|
||||
MockProcessAndPermission(DISTSCHED_PROCESS_NAME, PERMS, 1);
|
||||
}
|
||||
|
||||
void FuzzUtil::MockProcessAndPermission(const char* processName, const char *perms[], int32_t permsNum)
|
||||
{
|
||||
uint64_t tokenId;
|
||||
NativeTokenInfoParams infoInstance = {
|
||||
.dcapsNum = 0,
|
||||
.permsNum = 1,
|
||||
.permsNum = permsNum,
|
||||
.aclsNum = 0,
|
||||
.dcaps = nullptr,
|
||||
.perms = PERMS,
|
||||
.perms = perms,
|
||||
.acls = nullptr,
|
||||
.processName = "foundation",
|
||||
.processName = processName,
|
||||
.aplStr = "system_core",
|
||||
};
|
||||
tokenId = GetAccessTokenId(&infoInstance);
|
||||
SetSelfTokenID(tokenId);
|
||||
OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
|
||||
}
|
||||
}
|
||||
}
|
@ -16,10 +16,16 @@
|
||||
#ifndef MOCK_PERMISSION_H
|
||||
#define MOCK_PERMISSION_H
|
||||
|
||||
#include "iservice_registry.h"
|
||||
|
||||
namespace OHOS {
|
||||
class DmsMockPermission {
|
||||
namespace DistributedSchedule {
|
||||
class FuzzUtil {
|
||||
public:
|
||||
static void MockPermission();
|
||||
static void MockProcessAndPermission(const char* processName,
|
||||
const char *perms[], int32_t permsNum);
|
||||
};
|
||||
}
|
||||
} // namespace OHOS
|
||||
#endif // SAMGR_SERVICES_SAMGR_MOCK_PERMISSION_H
|
Loading…
Reference in New Issue
Block a user