mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 14:30:21 +00:00
commit
5d230bf89a
@ -53,6 +53,7 @@ ohos_unittest("dmsbasetest") {
|
||||
"${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/dfx/dms_hisysevent_report_test.cpp",
|
||||
"unittest/dms_network_adapter_test.cpp",
|
||||
"unittest/dtbschedmgr_device_info_storage_test.cpp",
|
||||
]
|
||||
|
100
services/base/test/unittest/dfx/dms_hisysevent_report_test.cpp
Normal file
100
services/base/test/unittest/dfx/dms_hisysevent_report_test.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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_hisysevent_report_test.h"
|
||||
|
||||
#include "dfx/dms_hisysevent_report.h"
|
||||
#include "test_log.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string bundleName = "ohos.hisysevent.test";
|
||||
const std::string abilityName = "testAbility";
|
||||
const std::string TAG = "DmsHiSysEventReportTest";
|
||||
const int32_t eventResult = 0;
|
||||
const int32_t callingAppUid = 0;
|
||||
}
|
||||
|
||||
void DmsHiSysEventReportTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DmsHiSysEventReportTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DmsHiSysEventReportTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void DmsHiSysEventReportTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReportBehaviorEvent_001
|
||||
* @tc.desc: test ReportBehaviorEvent when HiSysEvent::Write success
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I621C1
|
||||
*/
|
||||
HWTEST_F(DmsHiSysEventReportTest, testReportBehaviorEvent_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsHiSysEventReportTest testReportBehaviorEvent_001 begin" << std::endl;
|
||||
BehaviorEventParam param;
|
||||
/**
|
||||
* @tc.steps: step1. test ReportBehaviorEvent with invalid eventName
|
||||
*/
|
||||
int32_t result = DmsHiSysEventReport::ReportBehaviorEvent(param);
|
||||
EXPECT_NE(0, result);
|
||||
/**
|
||||
* @tc.steps: step2. test ReportBehaviorEvent
|
||||
*/
|
||||
param = { EventCallingType::LOCAL, BehaviorEvent::START_REMOTE_ABILITY, eventResult,
|
||||
bundleName, abilityName, callingAppUid };
|
||||
result = DmsHiSysEventReport::ReportBehaviorEvent(param);
|
||||
EXPECT_EQ(0, result);
|
||||
DTEST_LOG << "DmsHiSysEventReportTest testReportBehaviorEvent_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReportFaultEvent_001
|
||||
* @tc.desc: test ReportFaultEvent when HiSysEvent::Write success
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I621C1
|
||||
*/
|
||||
HWTEST_F(DmsHiSysEventReportTest, testReportFaultEvent_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DmsHiSysEventReportTest testReportFaultEvent_001 begin" << std::endl;
|
||||
std::string eventName;
|
||||
std::string errorType;
|
||||
/**
|
||||
* @tc.steps: step1. test ReportFaultEvent with invalid error type
|
||||
*/
|
||||
int32_t result = DmsHiSysEventReport::ReportFaultEvent("", "");
|
||||
EXPECT_NE(0, result);
|
||||
/**
|
||||
* @tc.steps: step2. test ReportFaultEvent
|
||||
*/
|
||||
result = DmsHiSysEventReport::ReportFaultEvent(FaultEvent::START_REMOTE_ABILITY,
|
||||
EventErrorType::GET_ABILITY_MGR_FAILED);
|
||||
EXPECT_EQ(0, result);
|
||||
DTEST_LOG << "DmsHiSysEventReportTest testReportFaultEvent_001 end" << std::endl;
|
||||
}
|
||||
} // DistributedSchedule
|
||||
} // namespace OHOS
|
32
services/base/test/unittest/dfx/dms_hisysevent_report_test.h
Normal file
32
services/base/test/unittest/dfx/dms_hisysevent_report_test.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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_DMS_HISYSEVENT_REPORT_TEST_H
|
||||
#define OHOS_DMSFWK_BASE_DMS_HISYSEVENT_REPORT_TEST_H
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class DmsHiSysEventReportTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DMSFWK_BASE_DMS_HISYSEVENT_REPORT_TEST_H
|
@ -290,6 +290,53 @@ HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_004, TestSize.Level3)
|
||||
EXPECT_EQ(res, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddDeviceChangeListener_005
|
||||
* @tc.desc: test AddDeviceChangeListener when initCallback_ is nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I621C1
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_005, TestSize.Level3)
|
||||
{
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
DnetworkAdapter::listenerSet_.insert(deviceNodeListener);
|
||||
DnetworkAdapter::GetInstance()->initCallback_ = nullptr;
|
||||
bool ret = DnetworkAdapter::GetInstance()->AddDeviceChangeListener(deviceNodeListener);
|
||||
EXPECT_TRUE(ret);
|
||||
DnetworkAdapter::GetInstance()->initCallback_ = std::make_shared<DnetworkAdapter::DeviceInitCallBack>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddDeviceChangeListener_006
|
||||
* @tc.desc: test AddDeviceChangeListener when stateCallback_ is nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I621C1
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, AddDeviceChangeListener_006, TestSize.Level3)
|
||||
{
|
||||
DistributedHardware::DmDeviceInfo deviceInfo;
|
||||
/**
|
||||
* @tc.steps: step1. OnDeviceChanged
|
||||
*/
|
||||
DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceChanged(deviceInfo);
|
||||
/**
|
||||
* @tc.steps: step2. OnDeviceReady
|
||||
*/
|
||||
DnetworkAdapter::GetInstance()->stateCallback_->OnDeviceReady(deviceInfo);
|
||||
/**
|
||||
* @tc.steps: step3. AddDeviceChangeListener when stateCallback_ is nullptr
|
||||
*/
|
||||
std::shared_ptr<DeviceListener> deviceNodeListener = std::make_shared<MockDeviceListener>();
|
||||
DnetworkAdapter::listenerSet_.clear();
|
||||
DnetworkAdapter::listenerSet_.insert(deviceNodeListener);
|
||||
DnetworkAdapter::GetInstance()->stateCallback_ = nullptr;
|
||||
bool res = DnetworkAdapter::GetInstance()->AddDeviceChangeListener(deviceNodeListener);
|
||||
EXPECT_EQ(res, true);
|
||||
DnetworkAdapter::GetInstance()->stateCallback_ =
|
||||
std::make_shared<DnetworkAdapter::DmsDeviceStateCallback>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RemoveDeviceChangeListener_001
|
||||
* @tc.desc: listenerSet_ size is 0
|
||||
@ -312,12 +359,19 @@ HWTEST_F(DMSNetworkAdapterTest, RemoveDeviceChangeListener_001, TestSize.Level3)
|
||||
*/
|
||||
HWTEST_F(DMSNetworkAdapterTest, RemoveDeviceChangeListener_002, TestSize.Level3)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. test RemoveDeviceChangeListener when listenerSet_ size is 1
|
||||
*/
|
||||
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);
|
||||
/**
|
||||
* @tc.steps: step2. OnRemoteDied
|
||||
*/
|
||||
DnetworkAdapter::GetInstance()->initCallback_->OnRemoteDied();
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -27,6 +27,7 @@ using namespace testing;
|
||||
using namespace testing::ext;
|
||||
namespace {
|
||||
constexpr int32_t DISTRIBUTED_SCHED_SA_ID = 1401;
|
||||
constexpr int32_t INVALID_LEN = -1;
|
||||
constexpr int32_t UNREGISTER_TOKEN = 10000;
|
||||
constexpr int32_t TEST_TOKEN = 1000;
|
||||
constexpr int32_t TEST_ACCESS_TOKEN = 10000000;
|
||||
@ -1376,6 +1377,24 @@ HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_005, TestSiz
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_005 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ReadContinuationResultsFromParcel_006
|
||||
* @tc.desc: test ReadContinuationResultsFromParcel when size <= parcel.GetReadableBytes().
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I621C1
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_006, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_006 start" << std::endl;
|
||||
Parcel parcel;
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
parcel.WriteInt32(VALUE_OBJECT);
|
||||
parcel.WriteInt32(parcel.GetReadableBytes());
|
||||
bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
|
||||
EXPECT_FALSE(result);
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_006 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: WriteContinuationResultsToParcel_001
|
||||
* @tc.desc: test WriteContinuationResultsToParcel when size == 0.
|
||||
@ -1578,6 +1597,23 @@ HWTEST_F(ContinuationManagerTest, Unmarshalling_001, TestSize.Level3)
|
||||
DTEST_LOG << "ContinuationManagerTest Unmarshalling_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Unmarshalling_002
|
||||
* @tc.desc: test Unmarshalling_002 when ontinuationExtraParams->ReadFromParcel failed;
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I621C1
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, Unmarshalling_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "ContinuationManagerTest Unmarshalling_002 start" << std::endl;
|
||||
ContinuationExtraParams continuationExtraParams;
|
||||
Parcel parcel;
|
||||
parcel.WriteInt32(INVALID_LEN);
|
||||
ContinuationExtraParams* result = continuationExtraParams.Unmarshalling(parcel);
|
||||
EXPECT_EQ(nullptr, result);
|
||||
DTEST_LOG << "ContinuationManagerTest Unmarshalling_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnRemoteRequest_001
|
||||
* @tc.desc: test OnRemoteRequest, invalid interface token.
|
||||
@ -1659,14 +1695,24 @@ HWTEST_F(ContinuationManagerTest, OnRemoteRequest_003, TestSize.Level3)
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_004, TestSize.Level3)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. test OnRemoteRequest with invalid interface token.
|
||||
*/
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
DeviceSelectionNotifierTest deviceSelectionNotifierTest;
|
||||
int32_t result = deviceSelectionNotifierTest.OnRemoteRequest(IDeviceSelectionNotifier::EVENT_DEVICE_DISCONNECT,
|
||||
data, reply, option);
|
||||
|
||||
EXPECT_EQ(ERR_INVALID_VALUE, result);
|
||||
/**
|
||||
* @tc.steps: step2. test OnRemoteDied when dmsNotifier_ == nullptr.
|
||||
*/
|
||||
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
|
||||
NotifierDeathRecipient notifierDeathRecipient(dmsNotifier);
|
||||
notifierDeathRecipient.dmsNotifier_ = nullptr;
|
||||
wptr<IRemoteObject> remote = nullptr;
|
||||
notifierDeathRecipient.OnRemoteDied(remote);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1690,17 +1736,36 @@ HWTEST_F(ContinuationManagerTest, OnRemoteRequest_005, TestSize.Level3)
|
||||
DeviceSelectionNotifierTest deviceSelectionNotifierTest;
|
||||
int32_t result = deviceSelectionNotifierTest.OnRemoteRequest(IDeviceSelectionNotifier::EVENT_DEVICE_DISCONNECT,
|
||||
data, reply, option);
|
||||
|
||||
EXPECT_EQ(ERR_OK, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnRemoteRequest_006
|
||||
* @tc.desc: test OnRemoteRequest, code = EVENT_DEVICE_CONNECT but read from parcel failed
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I621C1
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_006, TestSize.Level3)
|
||||
{
|
||||
MessageParcel data;
|
||||
data.WriteInterfaceToken(IDeviceSelectionNotifier::GetDescriptor());
|
||||
data.WriteInt32(VALUE_OBJECT);
|
||||
data.WriteInt32(INVALID_LEN);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
DeviceSelectionNotifierTest deviceSelectionNotifierTest;
|
||||
int32_t result = deviceSelectionNotifierTest.OnRemoteRequest(IDeviceSelectionNotifier::EVENT_DEVICE_CONNECT,
|
||||
data, reply, option);
|
||||
EXPECT_EQ(ERR_FLATTEN_OBJECT, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnRemoteRequest_007
|
||||
* @tc.desc: test OnRemoteRequest when descriptor != remoteDescriptor.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5M4CD
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_006, TestSize.Level3)
|
||||
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_007, TestSize.Level3)
|
||||
{
|
||||
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
|
||||
AppDeviceCallbackStub appDeviceCallbackStub(dmsNotifier);
|
||||
@ -1748,5 +1813,160 @@ HWTEST_F(ContinuationManagerTest, OnRemoteRequest_006, TestSize.Level3)
|
||||
deviceIds.emplace_back(SELECTED_DEVICE_ID3);
|
||||
deviceSelectionNotifierProxy.OnDeviceDisconnect(deviceIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnRemoteRequest_008
|
||||
* @tc.desc: test OnRemoteRequest when code = AppDeviceCallbackInterface::EVENT_DEVICE_CONNECT.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I621C1
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_008, TestSize.Level3)
|
||||
{
|
||||
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
|
||||
AppDeviceCallbackStub appDeviceCallbackStub(dmsNotifier);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(AppDeviceCallbackInterface::GetDescriptor());
|
||||
data.WriteInt32(TEST_TOKEN);
|
||||
int32_t ret = appDeviceCallbackStub.OnRemoteRequest(
|
||||
AppDeviceCallbackInterface::EVENT_DEVICE_CONNECT, data, reply, option);
|
||||
EXPECT_EQ(ERR_NONE, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnRemoteRequest_009
|
||||
* @tc.desc: test OnRemoteRequest when ContinuationResult read from parcel failed.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I621C1
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_009, TestSize.Level3)
|
||||
{
|
||||
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
|
||||
AppDeviceCallbackStub appDeviceCallbackStub(dmsNotifier);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(AppDeviceCallbackInterface::GetDescriptor());
|
||||
data.WriteInt32(TEST_TOKEN);
|
||||
data.WriteInt32(VALUE_OBJECT);
|
||||
data.WriteInt32(INVALID_LEN);
|
||||
int32_t ret = appDeviceCallbackStub.OnRemoteRequest(
|
||||
AppDeviceCallbackInterface::EVENT_DEVICE_CONNECT, data, reply, option);
|
||||
EXPECT_EQ(ERR_FLATTEN_OBJECT, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnRemoteRequest_010
|
||||
* @tc.desc: test OnRemoteRequest when code = AppDeviceCallbackInterface::EVENT_DEVICE_DISCONNECT.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I621C1
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_010, TestSize.Level3)
|
||||
{
|
||||
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
|
||||
AppDeviceCallbackStub appDeviceCallbackStub(dmsNotifier);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(AppDeviceCallbackInterface::GetDescriptor());
|
||||
data.WriteInt32(TEST_TOKEN);
|
||||
int32_t ret = appDeviceCallbackStub.OnRemoteRequest(
|
||||
AppDeviceCallbackInterface::EVENT_DEVICE_DISCONNECT, data, reply, option);
|
||||
EXPECT_EQ(ERR_NONE, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnRemoteRequest_011
|
||||
* @tc.desc: test OnRemoteRequest when code = AppDeviceCallbackInterface::EVENT_DEVICE_CANCEL.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I621C1
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_011, TestSize.Level3)
|
||||
{
|
||||
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
|
||||
AppDeviceCallbackStub appDeviceCallbackStub(dmsNotifier);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(AppDeviceCallbackInterface::GetDescriptor());
|
||||
int32_t ret = appDeviceCallbackStub.OnRemoteRequest(
|
||||
AppDeviceCallbackInterface::EVENT_DEVICE_CANCEL, data, reply, option);
|
||||
EXPECT_EQ(ERR_NONE, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnRemoteRequest_012
|
||||
* @tc.desc: test OnRemoteRequest when code = INVALID_EVENT_DEVICE_CODE.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I621C1
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_012, TestSize.Level3)
|
||||
{
|
||||
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
|
||||
AppDeviceCallbackStub appDeviceCallbackStub(dmsNotifier);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(AppDeviceCallbackInterface::GetDescriptor());
|
||||
int32_t ret = appDeviceCallbackStub.OnRemoteRequest(INVALID_EVENT_DEVICE_CODE, data, reply, option);
|
||||
EXPECT_NE(ERR_NONE, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnDeviceEvent_001
|
||||
* @tc.desc: test OnDeviceConnect, OnDeviceDisconnect and OnDeviceCancel.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I621C1
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, OnDeviceEvent_001, TestSize.Level3)
|
||||
{
|
||||
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
|
||||
AppDeviceCallbackStub appDeviceCallbackStub(dmsNotifier);
|
||||
/**
|
||||
* @tc.steps: step1. test OnDeviceConnect
|
||||
*/
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
int32_t ret = appDeviceCallbackStub.OnDeviceConnect(TEST_TOKEN, continuationResults);
|
||||
EXPECT_EQ(ERR_NONE, ret);
|
||||
/**
|
||||
* @tc.steps: step2. test OnDeviceDisconnect
|
||||
*/
|
||||
std::vector<std::string> deviceIds;
|
||||
ret = appDeviceCallbackStub.OnDeviceDisconnect(TEST_TOKEN, deviceIds);
|
||||
EXPECT_EQ(ERR_NONE, ret);
|
||||
/**
|
||||
* @tc.steps: step3. test OnDeviceCancel
|
||||
*/
|
||||
ret = appDeviceCallbackStub.OnDeviceCancel();
|
||||
EXPECT_EQ(ERR_NONE, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetConnectStatusInfo_001
|
||||
* @tc.desc: test GetConnectStatusInfo
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I621C1
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, GetConnectStatusInfo_001, TestSize.Level3)
|
||||
{
|
||||
NotifierInfo notifierInfo;
|
||||
/**
|
||||
* @tc.steps: step1. test DeleteNotifier when cbType is not in notifierMap_
|
||||
*/
|
||||
notifierInfo.notifierMap_.clear();
|
||||
notifierInfo.DeleteNotifier(INVALID_CALLBACK_TYPE);
|
||||
/**
|
||||
* @tc.steps: step2. test RemoveDeathRecipient when cbType is not in notifierMap_
|
||||
*/
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient = nullptr;
|
||||
notifierInfo.RemoveDeathRecipient(deathRecipient, INVALID_CALLBACK_TYPE);
|
||||
/**
|
||||
* @tc.steps: step3. test GetConnectStatusInfo
|
||||
*/
|
||||
notifierInfo.connectStatusInfo_ = nullptr;
|
||||
std::shared_ptr<ConnectStatusInfo> result = notifierInfo.GetConnectStatusInfo();
|
||||
EXPECT_EQ(nullptr, result);
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -22,6 +22,8 @@
|
||||
#define private public
|
||||
#include "continuation_manager/app_device_callback_stub.h"
|
||||
#include "continuation_manager/device_selection_notifier_proxy.h"
|
||||
#include "continuation_manager/notifier_death_recipient.h"
|
||||
#include "continuation_manager/notifier_info.h"
|
||||
#include "distributed_ability_manager_service.h"
|
||||
#undef private
|
||||
|
||||
|
@ -136,6 +136,7 @@ ohos_unittest("distributedschedsvrtest") {
|
||||
"unittest/dms_callback_task_test.cpp",
|
||||
"unittest/dms_token_callback_test.cpp",
|
||||
"unittest/mock_distributed_sched.cpp",
|
||||
"unittest/mock_remote_stub.cpp",
|
||||
]
|
||||
sources += dtbschedmgr_sources
|
||||
configs = [
|
||||
@ -177,7 +178,10 @@ ohos_unittest("distributedcalltest") {
|
||||
ohos_unittest("dmsfreeinstallcbtest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [ "unittest/dms_free_install_callback_test.cpp" ]
|
||||
sources = [
|
||||
"unittest/dms_free_install_callback_test.cpp",
|
||||
"unittest/mock_remote_stub.cpp",
|
||||
]
|
||||
sources += dtbschedmgr_sources
|
||||
configs = [
|
||||
":test_config",
|
||||
@ -199,6 +203,7 @@ ohos_unittest("dschedcontinuetest") {
|
||||
"unittest/distributed_sched_continuation_test.cpp",
|
||||
"unittest/dms_version_manager_test.cpp",
|
||||
"unittest/mock_distributed_sched.cpp",
|
||||
"unittest/mock_remote_stub.cpp",
|
||||
]
|
||||
sources += dtbschedmgr_sources
|
||||
configs = [
|
||||
@ -229,6 +234,7 @@ ohos_unittest("dschedconnecttest") {
|
||||
sources = [
|
||||
"unittest/app_connection_stub_test.cpp",
|
||||
"unittest/distributed_sched_connect_test.cpp",
|
||||
"unittest/mock_remote_stub.cpp",
|
||||
]
|
||||
sources += dtbschedmgr_sources
|
||||
configs = [
|
||||
@ -273,6 +279,7 @@ ohos_unittest("dschedmissionmanagertest") {
|
||||
"unittest/mission/dms_mission_manager_test.cpp",
|
||||
"unittest/mission/mission_info_converter_test.cpp",
|
||||
"unittest/mission/snapshot_test.cpp",
|
||||
"unittest/mock_remote_stub.cpp",
|
||||
]
|
||||
sources += dtbschedmgr_sources
|
||||
configs = [
|
||||
|
@ -15,10 +15,14 @@
|
||||
|
||||
#include "distributed_mission_info_test.h"
|
||||
#include <memory>
|
||||
#include "change_notification.h"
|
||||
#define private public
|
||||
#include "mission/distributed_data_change_listener.h"
|
||||
#include "mission/distributed_mission_info.h"
|
||||
#include "mission/mission_changed_notify.h"
|
||||
#undef private
|
||||
#include "mission/mission_constant.h"
|
||||
#include "mock_remote_stub.h"
|
||||
#include "parcel_helper.h"
|
||||
#include "test_log.h"
|
||||
|
||||
@ -31,6 +35,9 @@ namespace {
|
||||
constexpr int32_t TEST_INVALID_VALUE = -1;
|
||||
constexpr int32_t TEST_PARCEL_WRITE_VALUE = 1;
|
||||
constexpr size_t TEST_PARCEL_WRITE_LEN = 5;
|
||||
const std::string TEST_DEVICE_ID = "test deviceId";
|
||||
const std::u16string TEST_DEVICEID = u"invalid deviceId";
|
||||
const std::u16string TEST_DEVICEID_TO_RETURN_FALSE = u"deviceId to return false";
|
||||
}
|
||||
void DistributedMissionInfoTest::SetUpTestCase()
|
||||
{
|
||||
@ -280,6 +287,23 @@ HWTEST_F(DistributedMissionInfoTest, testReadDstbMissionInfosFromParcel007, Test
|
||||
HWTEST_F(DistributedMissionInfoTest, testWriteDstbMissionInfosToParcel001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testWriteDstbMissionInfosToParcel001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test NotifyMissionsChanged when remoteObject is nullptr
|
||||
*/
|
||||
sptr<IRemoteObject> remoteObject = nullptr;
|
||||
MissionChangedNotify::NotifyMissionsChanged(remoteObject, TEST_DEVICEID);
|
||||
/**
|
||||
* @tc.steps: step2. test NotifyMissionsChanged when remoteObject is not nullptr
|
||||
*/
|
||||
remoteObject = new MockRemoteStub();
|
||||
MissionChangedNotify::NotifyMissionsChanged(remoteObject, TEST_DEVICEID);
|
||||
/**
|
||||
* @tc.steps: step3. test NotifyMissionsChanged when remoteObject return false
|
||||
*/
|
||||
MissionChangedNotify::NotifyMissionsChanged(remoteObject, TEST_DEVICEID_TO_RETURN_FALSE);
|
||||
/**
|
||||
* @tc.steps: step4. test WriteDstbMissionInfosToParcel when missionInfos is empty
|
||||
*/
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
Parcel parcel;
|
||||
std::vector<DstbMissionInfo> missionInfos;
|
||||
@ -297,6 +321,24 @@ HWTEST_F(DistributedMissionInfoTest, testWriteDstbMissionInfosToParcel001, TestS
|
||||
HWTEST_F(DistributedMissionInfoTest, testWriteDstbMissionInfosToParcel002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testWriteDstbMissionInfosToParcel002 start" << std::endl;
|
||||
int32_t missionId = 0;
|
||||
/**
|
||||
* @tc.steps: step1. test NotifySnapshot when remoteObject is nullptr
|
||||
*/
|
||||
sptr<IRemoteObject> remoteObject = nullptr;
|
||||
MissionChangedNotify::NotifySnapshot(remoteObject, TEST_DEVICEID, missionId);
|
||||
/**
|
||||
* @tc.steps: step2. test NotifySnapshot when remoteObject is not nullptr
|
||||
*/
|
||||
remoteObject = new MockRemoteStub();
|
||||
MissionChangedNotify::NotifySnapshot(remoteObject, TEST_DEVICEID, missionId);
|
||||
/**
|
||||
* @tc.steps: step3. test NotifySnapshot when remoteObject return false
|
||||
*/
|
||||
MissionChangedNotify::NotifySnapshot(remoteObject, TEST_DEVICEID_TO_RETURN_FALSE, missionId);
|
||||
/**
|
||||
* @tc.steps: step4. test WriteDstbMissionInfosToParcel
|
||||
*/
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
Parcel parcel;
|
||||
std::vector<DstbMissionInfo> missionInfos;
|
||||
@ -314,6 +356,24 @@ HWTEST_F(DistributedMissionInfoTest, testWriteDstbMissionInfosToParcel002, TestS
|
||||
*/
|
||||
HWTEST_F(DistributedMissionInfoTest, testToString001, TestSize.Level3)
|
||||
{
|
||||
int32_t state = 0;
|
||||
/**
|
||||
* @tc.steps: step1. test NotifyNetDisconnect when remoteObject is nullptr
|
||||
*/
|
||||
sptr<IRemoteObject> remoteObject = nullptr;
|
||||
MissionChangedNotify::NotifyNetDisconnect(remoteObject, TEST_DEVICEID, state);
|
||||
/**
|
||||
* @tc.steps: step2. test NotifyNetDisconnect when remoteObject is not nullptr
|
||||
*/
|
||||
remoteObject = new MockRemoteStub();
|
||||
MissionChangedNotify::NotifyNetDisconnect(remoteObject, TEST_DEVICEID, state);
|
||||
/**
|
||||
* @tc.steps: step3. test NotifyNetDisconnect when remoteObject return false
|
||||
*/
|
||||
MissionChangedNotify::NotifyNetDisconnect(remoteObject, TEST_DEVICEID_TO_RETURN_FALSE, state);
|
||||
/**
|
||||
* @tc.steps: step4. test ToString print a missionInfo.
|
||||
*/
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
auto ret = dstbMissionInfo.ToString();
|
||||
EXPECT_NE(ret, "");
|
||||
@ -328,6 +388,9 @@ HWTEST_F(DistributedMissionInfoTest, testToString001, TestSize.Level3)
|
||||
HWTEST_F(DistributedMissionInfoTest, testToString002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DistributedMissionInfoTest testToString002 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test ToString.
|
||||
*/
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
dstbMissionInfo.baseWant = std::make_shared<AAFwk::Want>();
|
||||
dstbMissionInfo.topAbility = std::make_shared<AppExecFwk::ElementName>();
|
||||
@ -335,6 +398,16 @@ HWTEST_F(DistributedMissionInfoTest, testToString002, TestSize.Level3)
|
||||
dstbMissionInfo.reservedAbility = std::make_shared<AppExecFwk::ElementName>();
|
||||
std::string ret = dstbMissionInfo.ToString();
|
||||
EXPECT_FALSE(ret.empty());
|
||||
/**
|
||||
* @tc.steps: step2. test OnChange when insertEntries is empty.
|
||||
*/
|
||||
DistributedDataChangeListener distributedDataChangeListener;
|
||||
std::vector<DistributedKv::Entry> insertEntries;
|
||||
std::vector<DistributedKv::Entry> updateEntries;
|
||||
std::vector<DistributedKv::Entry> deleteEntries;
|
||||
DistributedKv::ChangeNotification changeNotification(std::move(insertEntries),
|
||||
std::move(updateEntries), std::move(deleteEntries), TEST_DEVICE_ID, false);
|
||||
distributedDataChangeListener.OnChange(changeNotification);
|
||||
DTEST_LOG << "DistributedMissionInfoTest testToString002 end" << std::endl;
|
||||
}
|
||||
} // DistributedSchedule
|
||||
|
@ -61,6 +61,26 @@ HWTEST_F(MissionInfoConverterTest, testConvertToDstbMissionInfos_001, TestSize.L
|
||||
DTEST_LOG << "MissionInfoConverterTest testConvertToDstbMissionInfos_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testConvertToDstbMissionInfos_002
|
||||
* @tc.desc: test ConvertToDstbMissionInfos when missionInfos is not empty
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I621C1
|
||||
*/
|
||||
HWTEST_F(MissionInfoConverterTest, testConvertToDstbMissionInfos_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MissionInfoConverterTest testConvertToDstbMissionInfos_002 begin" << std::endl;
|
||||
std::vector<AAFwk::MissionInfo> missionInfos;
|
||||
std::vector<DstbMissionInfo> dstbMissionInfos;
|
||||
AAFwk::MissionInfo missionInfo;
|
||||
missionInfo.want = AAFwk::Want();
|
||||
missionInfos.emplace_back(missionInfo);
|
||||
int32_t result = MissionInfoConverter::ConvertToDstbMissionInfos(missionInfos, dstbMissionInfos);
|
||||
EXPECT_EQ(ERR_OK, result);
|
||||
EXPECT_FALSE(dstbMissionInfos.empty());
|
||||
DTEST_LOG << "MissionInfoConverterTest testConvertToDstbMissionInfos_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testConvertToMissionInfos_001
|
||||
* @tc.desc: test ConvertToMissionInfos when missionInfos is empty
|
||||
@ -76,6 +96,26 @@ HWTEST_F(MissionInfoConverterTest, testConvertToMissionInfos_001, TestSize.Level
|
||||
DTEST_LOG << "MissionInfoConverterTest testConvertToMissionInfos_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testConvertToMissionInfos_002
|
||||
* @tc.desc: test ConvertToMissionInfos when missionInfos is not empty
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I621C1
|
||||
*/
|
||||
HWTEST_F(MissionInfoConverterTest, testConvertToMissionInfos_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MissionInfoConverterTest testConvertToMissionInfos_002 begin" << std::endl;
|
||||
std::vector<AAFwk::MissionInfo> missionInfos;
|
||||
std::vector<DstbMissionInfo> dstbMissionInfos;
|
||||
DstbMissionInfo dstbMissionInfo;
|
||||
std::shared_ptr<AAFwk::Want> spWant = std::make_shared<AAFwk::Want>();
|
||||
dstbMissionInfo.baseWant = spWant;
|
||||
dstbMissionInfos.emplace_back(dstbMissionInfo);
|
||||
int32_t result = MissionInfoConverter::ConvertToMissionInfos(dstbMissionInfos, missionInfos);
|
||||
EXPECT_EQ(ERR_OK, result);
|
||||
DTEST_LOG << "MissionInfoConverterTest testConvertToMissionInfos_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testWriteMissionInfosToParcel_001
|
||||
* @tc.desc: test WriteMissionInfosToParcel when missionInfos is empty
|
||||
@ -96,6 +136,13 @@ HWTEST_F(MissionInfoConverterTest, testWriteMissionInfosToParcel_001, TestSize.L
|
||||
*/
|
||||
result = MissionInfoConverter::ReadMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_TRUE(result);
|
||||
/**
|
||||
* @tc.steps: step3. test ReadMissionInfosFromParcel when missionInfos is not empty;
|
||||
*/
|
||||
AAFwk::MissionInfo missionInfo;
|
||||
missionInfos.emplace_back(missionInfo);
|
||||
result = MissionInfoConverter::ReadMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,6 +187,16 @@ HWTEST_F(MissionInfoConverterTest, ReadMissionInfosFromParcel_001, TestSize.Leve
|
||||
result = MissionInfoConverter::ReadMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_TRUE(missionInfos.empty());
|
||||
/**
|
||||
* @tc.steps: step5. test ReadMissionInfosFromParcel when missionInfo is not nullptr;
|
||||
*/
|
||||
AAFwk::MissionInfo missionInfo;
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, 1);
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, 1);
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Parcelable, &missionInfo);
|
||||
result = MissionInfoConverter::ReadMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_TRUE(result);
|
||||
EXPECT_FALSE(missionInfos.empty());
|
||||
DTEST_LOG << "MissionInfoConverterTest ReadMissionInfosFromParcel_001 end" << std::endl;
|
||||
}
|
||||
} // DistributedSchedule
|
||||
|
40
services/dtbschedmgr/test/unittest/mock_remote_stub.cpp
Normal file
40
services/dtbschedmgr/test/unittest/mock_remote_stub.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2021-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 "mock_remote_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
constexpr int32_t CODE_NOTIFY_MISSION = 0;
|
||||
constexpr int32_t NOTIFY_SNAP_SHOT = 1;
|
||||
constexpr int32_t NOTIFY_NET_DISCONNECT = 2;
|
||||
const std::string MOCK_DEVICEID_TO_RETURN_FALSE = "deviceId to return false";
|
||||
}
|
||||
|
||||
int32_t MockRemoteStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
|
||||
MessageOption& option)
|
||||
{
|
||||
if (code == CODE_NOTIFY_MISSION || code == NOTIFY_SNAP_SHOT || code == NOTIFY_NET_DISCONNECT) {
|
||||
data.ReadInterfaceToken();
|
||||
std::string deviceId = data.ReadString();
|
||||
if (deviceId == MOCK_DEVICEID_TO_RETURN_FALSE) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -29,11 +29,8 @@ public:
|
||||
class MockRemoteStub : public IRemoteStub<MockRemoteInterface> {
|
||||
public:
|
||||
~MockRemoteStub() = default;
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
|
||||
MessageOption& option) override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
|
||||
MessageOption& option) override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user