补齐dms单元测试用例

Signed-off-by: wangyang2022 <wangyang412@huawei.com>
Change-Id: I6dfc7c0fc2197241b71df7574a8ebd41332c7334
This commit is contained in:
wangyang2022 2022-10-24 16:13:31 +08:00
parent 706c801962
commit 6e6877399e
7 changed files with 767 additions and 2 deletions

View File

@ -16,7 +16,9 @@
#include "gtest/gtest.h"
#include <thread>
#define private public
#include "adapter/dnetwork_adapter.h"
#undef private
#include "dtbschedmgr_device_info_storage.h"
using namespace std;
@ -132,5 +134,165 @@ 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)
{
DnetworkAdapter::GetInstance()->Init();
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)
{
DnetworkAdapter::GetInstance()->Init();
DistributedHardware::DmDeviceInfo deviceInfo;
DnetworkAdapter::listenerSet_.clear();
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
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)
{
DnetworkAdapter::GetInstance()->Init();
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)
{
DnetworkAdapter::GetInstance()->Init();
DistributedHardware::DmDeviceInfo deviceInfo;
DnetworkAdapter::listenerSet_.clear();
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
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::GetInstance()->Init();
DnetworkAdapter::listenerSet_.clear();
DnetworkAdapter::GetInstance()->dnetworkHandler_ = nullptr;
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
bool res = DnetworkAdapter::GetInstance()->AddDeviceChangeListener(deviceNodeListener);
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::GetInstance()->Init();
DnetworkAdapter::listenerSet_.clear();
std::shared_ptr<DeviceListener> oldDeviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
DnetworkAdapter::listenerSet_.insert(oldDeviceNodeListener);
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
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::GetInstance()->Init();
DnetworkAdapter::listenerSet_.clear();
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
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::GetInstance()->Init();
DnetworkAdapter::listenerSet_.clear();
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
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::GetInstance()->Init();
DnetworkAdapter::listenerSet_.clear();
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
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::GetInstance()->Init();
DnetworkAdapter::listenerSet_.clear();
std::shared_ptr<DeviceListener> oldDeviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
DnetworkAdapter::listenerSet_.insert(oldDeviceNodeListener);
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<DistributedDeviceNodeListener>();
DnetworkAdapter::GetInstance()->RemoveDeviceChangeListener(deviceNodeListener);
EXPECT_EQ(DnetworkAdapter::listenerSet_.size(), 1);
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -128,6 +128,7 @@ ohos_unittest("distributedschedsvrtest") {
module_out_path = module_output_path
sources = [
"unittest/distributed_sched_adapter_test.cpp",
"unittest/distributed_sched_service_test.cpp",
"unittest/dms_callback_task_test.cpp",
"unittest/dms_token_callback_test.cpp",

View File

@ -0,0 +1,392 @@
/*
* 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 "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: 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: 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: 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: 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;
}
}
}

View File

@ -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

View File

@ -896,5 +896,155 @@ 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;
}
} // DistributedSchedule
} // namespace OHOS

View File

@ -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"

View File

@ -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