!369 添加DMS单元测试用例

Merge pull request !369 from 王洋/master_ut
This commit is contained in:
openharmony_ci 2022-09-01 08:05:26 +00:00 committed by Gitee
commit 6adf31b9f0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
9 changed files with 469 additions and 276 deletions

View File

@ -125,24 +125,6 @@ if (dmsfwk_standard_form_share) {
[ "${distributed_service}/dtbschedmgr/src/form_mgr_death_recipient.cpp" ]
}
ohos_unittest("appconnectstubtest") {
module_out_path = module_output_path
sources = [ "unittest/app_connection_stub_test.cpp" ]
sources += dtbschedmgr_sources
configs = [
":test_config",
"//foundation/ability/dmsfwk/services/dtbschedmgr/test/resource:coverage_flags",
]
configs += dsched_configs
if (is_standard_system) {
external_deps = dsched_external_deps
public_deps = dsched_public_deps
}
part_name = "dmsfwk"
subsystem_name = "ability"
}
ohos_unittest("distributedschedsvrtest") {
module_out_path = module_output_path
@ -187,10 +169,10 @@ ohos_unittest("distributedcalltest") {
subsystem_name = "ability"
}
ohos_unittest("dmsfreeinstallcbstubtest") {
ohos_unittest("dmsfreeinstallcbtest") {
module_out_path = module_output_path
sources = [ "unittest/dms_free_install_callback_stub_test.cpp" ]
sources = [ "unittest/dms_free_install_callback_test.cpp" ]
sources += dtbschedmgr_sources
configs = [
":test_config",
@ -238,7 +220,10 @@ ohos_unittest("dschedcontinuetest") {
ohos_unittest("dschedconnecttest") {
module_out_path = module_output_path
sources = [ "unittest/distributed_sched_connect_test.cpp" ]
sources = [
"unittest/app_connection_stub_test.cpp",
"unittest/distributed_sched_connect_test.cpp",
]
sources += dtbschedmgr_sources
configs = [
":test_config",
@ -273,7 +258,12 @@ ohos_unittest("dschedpermissiontest") {
ohos_unittest("dschedmissionmanagertest") {
module_out_path = module_output_path
sources = [ "unittest/mission/dms_mission_manager_test.cpp" ]
sources = [
"unittest/mission/distributed_data_storage_test.cpp",
"unittest/mission/distributed_mission_info_test.cpp",
"unittest/mission/dms_mission_manager_test.cpp",
"unittest/mission/snapshot_test.cpp",
]
sources += dtbschedmgr_sources
configs = [
":test_config",
@ -289,57 +279,6 @@ ohos_unittest("dschedmissionmanagertest") {
subsystem_name = "ability"
}
ohos_unittest("dscheddatastoragetest") {
module_out_path = module_output_path
sources = [ "unittest/mission/distributed_data_storage_test.cpp" ]
sources += dtbschedmgr_sources
configs = [
":test_config",
"//foundation/ability/dmsfwk/services/dtbschedmgr/test/resource:coverage_flags",
]
configs += dsched_configs
deps = [ "${distributed_service}/dtbschedmgr:distributedschedsvr" ]
if (is_standard_system) {
external_deps = dsched_external_deps
public_deps = dsched_public_deps
}
part_name = "dmsfwk"
}
ohos_unittest("snapshottest") {
module_out_path = module_output_path
sources = [ "unittest/mission/snapshot_test.cpp" ]
sources += dtbschedmgr_sources
configs = [
":test_config",
"//foundation/ability/dmsfwk/services/dtbschedmgr/test/resource:coverage_flags",
]
configs += dsched_configs
deps = [ "${distributed_service}/dtbschedmgr:distributedschedsvr" ]
if (is_standard_system) {
external_deps = dsched_external_deps
public_deps = dsched_public_deps
}
part_name = "dmsfwk"
}
ohos_unittest("distributedmissioninfotest") {
module_out_path = module_output_path
sources = [ "unittest/mission/distributed_mission_info_test.cpp" ]
sources += dtbschedmgr_sources
configs = [
":test_config",
"//foundation/ability/dmsfwk/services/dtbschedmgr/test/resource:coverage_flags",
]
configs += dsched_configs
deps = [ "${distributed_service}/dtbschedmgr:distributedschedsvr" ]
if (is_standard_system) {
external_deps = dsched_external_deps
public_deps = dsched_public_deps
}
part_name = "dmsfwk"
}
ohos_unittest("bundlemanagerinternaltest") {
module_out_path = module_output_path
sources = [ "unittest/bundle_manager_internal_test.cpp" ]
@ -355,6 +294,7 @@ ohos_unittest("bundlemanagerinternaltest") {
public_deps = dsched_public_deps
}
part_name = "dmsfwk"
subsystem_name = "ability"
}
ohos_unittest("hisyseventreporttest") {
@ -372,26 +312,23 @@ ohos_unittest("hisyseventreporttest") {
public_deps = dsched_public_deps
}
part_name = "dmsfwk"
subsystem_name = "ability"
}
group("unittest") {
testonly = true
deps = [
":appconnectstubtest",
":bundlemanagerinternaltest",
":distributedcalltest",
":distributedschedsvrtest",
":dmsfreeinstallcbstubtest",
":dmsfreeinstallcbtest",
":dschedconnecttest",
":dschedcontinuetest",
]
if (dmsfwk_mission_manager) {
deps += [
":distributedmissioninfotest",
":dscheddatastoragetest",
":dschedmissionmanagertest",
":dschedpermissiontest",
":snapshottest",
]
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
@ -14,23 +14,63 @@
*/
#include "app_connection_stub_test.h"
#include "mock_remote_stub.h"
#include "test_log.h"
#define private public
#include "app_connection_stub.h"
#undef private
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace DistributedSchedule {
namespace {
AppConnectionStub* appConnectionStub;
const std::u16string MOCK_INVALID_DESCRIPTOR = u"invalid descriptor";
int32_t code = 0;
MessageParcel reply;
MessageOption option;
const std::u16string MOCK_INVALID_DESCRIPTOR = u"invalid descriptor";
}
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 AppConnectionStubTest::SetUpTestCase()
@ -50,107 +90,185 @@ void AppConnectionStubTest::TearDown()
void AppConnectionStubTest::SetUp()
{
sptr<DmsNotifier> dmsNotifier(new MockDmsNotifier());
int32_t token = 0;
std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
appConnectionStub_ = new AppConnectionStub(dmsNotifier, token, continuationExtraParams);
DTEST_LOG << "AppConnectionStubTest::SetUp" << std::endl;
}
/**
* @tc.name: AppConnectionStubTest_001
* @tc.desc: constructor
* @tc.desc: invalid descriptor
* @tc.type: FUNC
*/
HWTEST_F(AppConnectionStubTest, AppConnectionStubTest_001, TestSize.Level2)
HWTEST_F(AppConnectionStubTest, AppConnectionStubTest_001, TestSize.Level3)
{
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_001 begin" << std::endl;
const sptr<DmsNotifier> dmsNotifier;
int32_t token = 0;
const std::shared_ptr<ContinuationExtraParams> continuationExtraParams;
appConnectionStub = new AppConnectionStub(dmsNotifier, token, continuationExtraParams);
EXPECT_EQ(appConnectionStub->token_, 0);
int32_t code = 0;
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(MOCK_INVALID_DESCRIPTOR);
int32_t result = appConnectionStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_INVALID_STATE);
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_001 end" << std::endl;
}
/**
* @tc.name: AppConnectionStubTest_002
* @tc.desc: invalid descriptor
* @tc.desc: invalid element name
* @tc.type: FUNC
*/
HWTEST_F(AppConnectionStubTest, AppConnectionStubTest_002, TestSize.Level2)
HWTEST_F(AppConnectionStubTest, AppConnectionStubTest_002, TestSize.Level3)
{
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_002 begin" << std::endl;
int32_t code = 0;
MessageParcel data;
data.WriteInterfaceToken(MOCK_INVALID_DESCRIPTOR);
int32_t result = appConnectionStub->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_INVALID_STATE);
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(AppConnectionStub::GetDescriptor());
int32_t result = appConnectionStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_INVALID_VALUE);
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_002 end" << std::endl;
}
/**
* @tc.name: AppConnectionStubTest_003
* @tc.desc: invalid element name
* @tc.desc: test connect done
* @tc.type: FUNC
*/
HWTEST_F(AppConnectionStubTest, AppConnectionStubTest_003, TestSize.Level2)
HWTEST_F(AppConnectionStubTest, AppConnectionStubTest_003, TestSize.Level3)
{
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_003 begin" << std::endl;
int32_t code = 0;
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(AppConnectionStub::GetDescriptor());
int32_t result = appConnectionStub->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_INVALID_VALUE);
AppExecFwk::ElementName element;
data.WriteParcelable(&element);
code = AppConnectionStub::ON_ABILITY_CONNECT_DONE;
int32_t result = appConnectionStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_INVALID_DATA);
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_003 end" << std::endl;
}
/**
* @tc.name: AppConnectionStubTest_004
* @tc.desc: test connect done
* @tc.desc: test disconnect done
* @tc.type: FUNC
*/
HWTEST_F(AppConnectionStubTest, AppConnectionStubTest_004, TestSize.Level2)
HWTEST_F(AppConnectionStubTest, AppConnectionStubTest_004, TestSize.Level3)
{
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_004 begin" << std::endl;
int32_t code = 0;
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(AppConnectionStub::GetDescriptor());
AppExecFwk::ElementName element;
data.WriteParcelable(&element);
code = AppConnectionStub::ON_ABILITY_CONNECT_DONE;
int32_t result = appConnectionStub->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_INVALID_DATA);
code = AppConnectionStub::ON_ABILITY_DISCONNECT_DONE;
int32_t result = appConnectionStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_004 end" << std::endl;
}
/**
* @tc.name: AppConnectionStubTest_005
* @tc.desc: test disconnect done
* @tc.desc: invalid code
* @tc.type: FUNC
*/
HWTEST_F(AppConnectionStubTest, AppConnectionStubTest_005, TestSize.Level2)
HWTEST_F(AppConnectionStubTest, AppConnectionStubTest_005, TestSize.Level3)
{
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_005 begin" << std::endl;
int32_t code = 0;
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(AppConnectionStub::GetDescriptor());
AppExecFwk::ElementName element;
data.WriteParcelable(&element);
code = AppConnectionStub::ON_ABILITY_DISCONNECT_DONE;
int32_t result = appConnectionStub->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
code = -1;
int32_t result = appConnectionStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_NE(result, ERR_NONE);
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_005 end" << std::endl;
}
/**
* @tc.name: AppConnectionStubTest_006
* @tc.desc: invalid code
* @tc.desc: test connect done
* @tc.type: FUNC
*/
HWTEST_F(AppConnectionStubTest, AppConnectionStubTest_006, TestSize.Level2)
HWTEST_F(AppConnectionStubTest, AppConnectionStubTest_006, TestSize.Level3)
{
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_006 begin" << std::endl;
int32_t code = 0;
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(AppConnectionStub::GetDescriptor());
AppExecFwk::ElementName element;
data.WriteParcelable(&element);
code = -1;
int32_t result = appConnectionStub->OnRemoteRequest(code, data, reply, option);
EXPECT_NE(result, ERR_NONE);
data.WriteRemoteObject((new MockRemoteStub())->AsObject());
code = AppConnectionStub::ON_ABILITY_CONNECT_DONE;
int32_t result = appConnectionStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_006 end" << std::endl;
}
/**
* @tc.name: AppConnectionStubTest_007
* @tc.desc: nullptr
* @tc.type: FUNC
*/
HWTEST_F(AppConnectionStubTest, AppConnectionStubTest_007, TestSize.Level3)
{
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_007 begin" << std::endl;
int32_t code = 0;
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(AppConnectionStub::GetDescriptor());
AppExecFwk::ElementName element;
data.WriteParcelable(&element);
data.WriteRemoteObject((new MockRemoteStub())->AsObject());
code = AppConnectionStub::ON_ABILITY_CONNECT_DONE;
appConnectionStub_->dmsNotifier_ = nullptr;
int32_t result = appConnectionStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_007 end" << std::endl;
}
/**
* @tc.name: AppConnectionStubTest_008
* @tc.desc: nullptr
* @tc.type: FUNC
*/
HWTEST_F(AppConnectionStubTest, AppConnectionStubTest_008, TestSize.Level3)
{
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_008 begin" << std::endl;
int32_t code = 0;
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(AppConnectionStub::GetDescriptor());
AppExecFwk::ElementName element;
data.WriteParcelable(&element);
code = AppConnectionStub::ON_ABILITY_DISCONNECT_DONE;
appConnectionStub_->dmsNotifier_ = nullptr;
int32_t result = appConnectionStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_008 end" << std::endl;
}
}
}

View File

@ -18,6 +18,10 @@
#include "gtest/gtest.h"
#define private public
#include "app_connection_stub.h"
#undef private
namespace OHOS {
namespace DistributedSchedule {
class AppConnectionStubTest : public testing::Test {
@ -26,6 +30,7 @@ public:
static void TearDownTestCase();
void SetUp();
void TearDown();
sptr<AppConnectionStub> appConnectionStub_;
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -223,6 +223,80 @@ HWTEST_F(BundleManagerInternalTest, BundleManagerInternalTest_008, TestSize.Leve
DTEST_LOG << "BundleManagerInternalTest BundleManagerInternalTest_008 end "<< std::endl;
}
/**
* @tc.name: BundleManagerInternalTest_009
* @tc.desc: test get callerappId from bms with invalid param
* @tc.type: FUNC
*/
HWTEST_F(BundleManagerInternalTest, BundleManagerInternalTest_009, TestSize.Level4)
{
DTEST_LOG << "BundleManagerInternalTest BundleManagerInternalTest_009 begin" << std::endl;
int32_t callingUid = -1;
string appId;
bool ret = BundleManagerInternal::GetCallerAppIdFromBms(callingUid, appId);
EXPECT_EQ(ret, false);
DTEST_LOG << "BundleManagerInternalTest BundleManagerInternalTest_009 end "<< std::endl;
}
/**
* @tc.name: BundleManagerInternalTest_010
* @tc.desc: test get callerappId from bms with invalid param
* @tc.type: FUNC
*/
HWTEST_F(BundleManagerInternalTest, BundleManagerInternalTest_010, TestSize.Level3)
{
DTEST_LOG << "BundleManagerInternalTest BundleManagerInternalTest_010 begin" << std::endl;
int32_t callingUid = 5522;
string appId;
bool ret = BundleManagerInternal::GetCallerAppIdFromBms(callingUid, appId);
EXPECT_EQ(ret, false);
DTEST_LOG << "BundleManagerInternalTest BundleManagerInternalTest_010 end "<< std::endl;
}
/**
* @tc.name: BundleManagerInternalTest_011
* @tc.desc: test IsSameAppId with invalid param
* @tc.type: FUNC
*/
HWTEST_F(BundleManagerInternalTest, BundleManagerInternalTest_011, TestSize.Level3)
{
DTEST_LOG << "BundleManagerInternalTest BundleManagerInternalTest_011 begin" << std::endl;
string appId;
string targetBundleName;
bool ret = BundleManagerInternal::IsSameAppId(appId, targetBundleName);
EXPECT_EQ(ret, false);
DTEST_LOG << "BundleManagerInternalTest BundleManagerInternalTest_011 end "<< std::endl;
}
/**
* @tc.name: BundleManagerInternalTest_012
* @tc.desc: test IsSameAppId with invalid param
* @tc.type: FUNC
*/
HWTEST_F(BundleManagerInternalTest, BundleManagerInternalTest_012, TestSize.Level3)
{
DTEST_LOG << "BundleManagerInternalTest BundleManagerInternalTest_012 begin" << std::endl;
string appId = "1001";
string targetBundleName = "ohos.samples.testApp";
bool ret = BundleManagerInternal::IsSameAppId(appId, targetBundleName);
EXPECT_EQ(ret, false);
DTEST_LOG << "BundleManagerInternalTest BundleManagerInternalTest_012 end "<< std::endl;
}
/**
* @tc.name: BundleManagerInternalTest_013
* @tc.desc: test IsSameAppId with invalid param
* @tc.type: FUNC
*/
HWTEST_F(BundleManagerInternalTest, BundleManagerInternalTest_013, TestSize.Level3)
{
DTEST_LOG << "BundleManagerInternalTest BundleManagerInternalTest_013 begin" << std::endl;
string bundleName = "ohos.samples.testApp";
int32_t uid = BundleManagerInternal::GetUidFromBms(bundleName);
EXPECT_EQ(uid, -1);
DTEST_LOG << "BundleManagerInternalTest BundleManagerInternalTest_013 end "<< std::endl;
}
/**
* @tc.name: BundleManagerCallBackTest_001
* @tc.desc: test OnQueryInstallationFinished with failed result

View File

@ -1,136 +0,0 @@
/*
* Copyright (c) 2021 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_free_install_callback_stub_test.h"
#include "test_log.h"
#define private public
#include "dms_free_install_callback.h"
#undef private
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace DistributedSchedule {
namespace {
DmsFreeInstallCallbackStub* dmsFreeInstallCallbackStub;
const std::u16string MOCK_INVALID_DESCRIPTOR = u"invalid descriptor";
int32_t code = -1;
MessageParcel reply;
MessageOption option;
}
void DmsFreeInstallCallbackStubTest::SetUpTestCase()
{
DTEST_LOG << "DmsFreeInstallCallbackStubTest::SetUpTestCase" << std::endl;
}
void DmsFreeInstallCallbackStubTest::TearDownTestCase()
{
DTEST_LOG << "DmsFreeInstallCallbackStubTest::TearDownTestCase" << std::endl;
}
void DmsFreeInstallCallbackStubTest::TearDown()
{
DTEST_LOG << "DmsFreeInstallCallbackStubTest::TearDown" << std::endl;
}
void DmsFreeInstallCallbackStubTest::SetUp()
{
DTEST_LOG << "DmsFreeInstallCallbackStubTest::SetUp" << std::endl;
}
/**
* @tc.name: DmsFreeInstallCallbackStubTest_001
* @tc.desc: constructor
* @tc.type: FUNC
*/
HWTEST_F(DmsFreeInstallCallbackStubTest, DmsFreeInstallCallbackStubTest_001, TestSize.Level2)
{
DTEST_LOG << "DmsFreeInstallCallbackStubTest DmsFreeInstallCallbackStubTest_001 begin" << std::endl;
int64_t taskId = 0;
IDistributedSched::FreeInstallInfo info;
dmsFreeInstallCallbackStub = new DmsFreeInstallCallback(taskId, info);
EXPECT_EQ(dmsFreeInstallCallbackStub->memberFuncMap_.size(), 1);
DTEST_LOG << "DmsFreeInstallCallbackStubTest DmsFreeInstallCallbackStubTest_001 end" << std::endl;
}
/**
* @tc.name: DmsFreeInstallCallbackStubTest_002
* @tc.desc: invalid descriptor
* @tc.type: FUNC
*/
HWTEST_F(DmsFreeInstallCallbackStubTest, DmsFreeInstallCallbackStubTest_002, TestSize.Level2)
{
DTEST_LOG << "DmsFreeInstallCallbackStubTest DmsFreeInstallCallbackStubTest_002 begin" << std::endl;
MessageParcel data;
data.WriteInterfaceToken(MOCK_INVALID_DESCRIPTOR);
int32_t result = dmsFreeInstallCallbackStub->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_INVALID_STATE);
DTEST_LOG << "DmsFreeInstallCallbackStubTest DmsFreeInstallCallbackStubTest_002 end" << std::endl;
}
/**
* @tc.name: DmsFreeInstallCallbackStubTest_003
* @tc.desc: invalid code
* @tc.type: FUNC
*/
HWTEST_F(DmsFreeInstallCallbackStubTest, DmsFreeInstallCallbackStubTest_003, TestSize.Level2)
{
DTEST_LOG << "DmsFreeInstallCallbackStubTest DmsFreeInstallCallbackStubTest_003 begin" << std::endl;
MessageParcel data;
data.WriteInterfaceToken(DmsFreeInstallCallbackStub::GetDescriptor());
int32_t result = dmsFreeInstallCallbackStub->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_INVALID_STATE);
DTEST_LOG << "DmsFreeInstallCallbackStubTest DmsFreeInstallCallbackStubTest_003 end" << std::endl;
}
/**
* @tc.name: DmsFreeInstallCallbackStubTest_004
* @tc.desc: invalid param
* @tc.type: FUNC
*/
HWTEST_F(DmsFreeInstallCallbackStubTest, DmsFreeInstallCallbackStubTest_004, TestSize.Level2)
{
DTEST_LOG << "DmsFreeInstallCallbackStubTest DmsFreeInstallCallbackStubTest_004 begin" << std::endl;
MessageParcel data;
data.WriteInterfaceToken(DmsFreeInstallCallbackStub::GetDescriptor());
code = 0;
int32_t result = dmsFreeInstallCallbackStub->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_INVALID_VALUE);
DTEST_LOG << "DmsFreeInstallCallbackStubTest DmsFreeInstallCallbackStubTest_004 end" << std::endl;
}
/**
* @tc.name: DmsFreeInstallCallbackStubTest_005
* @tc.desc: test finish install
* @tc.type: FUNC
*/
HWTEST_F(DmsFreeInstallCallbackStubTest, DmsFreeInstallCallbackStubTest_005, TestSize.Level2)
{
DTEST_LOG << "DmsFreeInstallCallbackStubTest DmsFreeInstallCallbackStubTest_005 begin" << std::endl;
code = 0;
MessageParcel data;
data.WriteInterfaceToken(DmsFreeInstallCallbackStub::GetDescriptor());
data.WriteInt32(0);
AAFwk::Want want;
data.WriteParcelable(&want);
int32_t result = dmsFreeInstallCallbackStub->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, NO_ERROR);
DTEST_LOG << "DmsFreeInstallCallbackStubTest DmsFreeInstallCallbackStubTest_005 end" << std::endl;
}
}
}

View File

@ -0,0 +1,149 @@
/*
* 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_free_install_callback_test.h"
#include "mock_remote_stub.h"
#include "test_log.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::u16string MOCK_INVALID_DESCRIPTOR = u"invalid descriptor";
}
void DmsFreeInstallCallbackTest::SetUpTestCase()
{
DTEST_LOG << "DmsFreeInstallCallbackTest::SetUpTestCase" << std::endl;
}
void DmsFreeInstallCallbackTest::TearDownTestCase()
{
DTEST_LOG << "DmsFreeInstallCallbackTest::TearDownTestCase" << std::endl;
}
void DmsFreeInstallCallbackTest::TearDown()
{
DTEST_LOG << "DmsFreeInstallCallbackTest::TearDown" << std::endl;
}
void DmsFreeInstallCallbackTest::SetUp()
{
DTEST_LOG << "DmsFreeInstallCallbackTest::SetUp" << std::endl;
int64_t taskId = 0;
IDistributedSched::FreeInstallInfo info;
dmsFreeInstallCallbackStub_ = new DmsFreeInstallCallback(taskId, info);
dmsFreeInstallCallbackProxy_ = new DmsFreeInstallCallbackProxy((new MockRemoteStub())->AsObject());
}
/**
* @tc.name: DmsFreeInstallCallbackTest_001
* @tc.desc: invalid descriptor
* @tc.type: FUNC
*/
HWTEST_F(DmsFreeInstallCallbackTest, DmsFreeInstallCallbackTest_001, TestSize.Level3)
{
DTEST_LOG << "DmsFreeInstallCallbackTest DmsFreeInstallCallbackTest_001 begin" << std::endl;
int32_t code = 0;
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(MOCK_INVALID_DESCRIPTOR);
int32_t result = dmsFreeInstallCallbackStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_INVALID_STATE);
DTEST_LOG << "DmsFreeInstallCallbackTest DmsFreeInstallCallbackTest_001 end" << std::endl;
}
/**
* @tc.name: DmsFreeInstallCallbackTest_002
* @tc.desc: invalid code
* @tc.type: FUNC
*/
HWTEST_F(DmsFreeInstallCallbackTest, DmsFreeInstallCallbackTest_002, TestSize.Level4)
{
DTEST_LOG << "DmsFreeInstallCallbackTest DmsFreeInstallCallbackTest_002 begin" << std::endl;
int32_t code = -1;
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(DmsFreeInstallCallbackStub::GetDescriptor());
int32_t result = dmsFreeInstallCallbackStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_INVALID_STATE);
DTEST_LOG << "DmsFreeInstallCallbackTest DmsFreeInstallCallbackTest_002 end" << std::endl;
}
/**
* @tc.name: DmsFreeInstallCallbackTest_003
* @tc.desc: invalid param
* @tc.type: FUNC
*/
HWTEST_F(DmsFreeInstallCallbackTest, DmsFreeInstallCallbackTest_003, TestSize.Level3)
{
DTEST_LOG << "DmsFreeInstallCallbackTest DmsFreeInstallCallbackTest_003 begin" << std::endl;
int32_t code = 0;
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(DmsFreeInstallCallbackStub::GetDescriptor());
int32_t result = dmsFreeInstallCallbackStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_INVALID_VALUE);
DTEST_LOG << "DmsFreeInstallCallbackTest DmsFreeInstallCallbackTest_003 end" << std::endl;
}
/**
* @tc.name: DmsFreeInstallCallbackTest_004
* @tc.desc: test finish install
* @tc.type: FUNC
*/
HWTEST_F(DmsFreeInstallCallbackTest, DmsFreeInstallCallbackTest_004, TestSize.Level3)
{
DTEST_LOG << "DmsFreeInstallCallbackTest DmsFreeInstallCallbackTest_004 begin" << std::endl;
int32_t code = 0;
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(DmsFreeInstallCallbackStub::GetDescriptor());
data.WriteInt32(0);
AAFwk::Want want;
data.WriteParcelable(&want);
int32_t result = dmsFreeInstallCallbackStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, NO_ERROR);
DTEST_LOG << "DmsFreeInstallCallbackTest DmsFreeInstallCallbackTest_004 end" << std::endl;
}
/**
* @tc.name: DmsFreeInstallCallbackTest_005
* @tc.desc: test on install finished
* @tc.type: FUNC
*/
HWTEST_F(DmsFreeInstallCallbackTest, DmsFreeInstallCallbackTest_005, TestSize.Level3)
{
DTEST_LOG << "DmsFreeInstallCallbackTest DmsFreeInstallCallbackTest_005 begin" << std::endl;
AAFwk::Want want;
int32_t requestCode = -1;
int32_t resultCode = -1;
dmsFreeInstallCallbackProxy_->OnInstallFinished(want, requestCode, resultCode);
EXPECT_NE(dmsFreeInstallCallbackProxy_, nullptr);
DTEST_LOG << "DmsFreeInstallCallbackTest DmsFreeInstallCallbackTest_005 end" << std::endl;
}
}
}

View File

@ -13,20 +13,27 @@
* limitations under the License.
*/
#ifndef DMS_FREE_INSTALL_CB_STUB_TEST_H
#define DMS_FREE_INSTALL_CB_STUB_TEST_H
#ifndef DMS_FREE_INSTALL_CB_TEST_H
#define DMS_FREE_INSTALL_CB_TEST_H
#include "gtest/gtest.h"
#include "dms_free_install_callback_proxy.h"
#define private public
#include "dms_free_install_callback.h"
#undef private
namespace OHOS {
namespace DistributedSchedule {
class DmsFreeInstallCallbackStubTest : public testing::Test {
class DmsFreeInstallCallbackTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
sptr<DmsFreeInstallCallbackStub> dmsFreeInstallCallbackStub_;
sptr<DmsFreeInstallCallbackProxy> dmsFreeInstallCallbackProxy_;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // DMS_FREE_INSTALL_CB_STUB_TEST_H
#endif // DMS_FREE_INSTALL_CB_TEST_H

View File

@ -24,11 +24,10 @@ using namespace testing::ext;
namespace OHOS {
namespace DistributedSchedule {
namespace {
const string GROUP_ID = "TEST_GROUP_ID";
const string bundleName = "ohos.hisysevent.test";
const string abilityName = "testAbility";
const int32_t eventResult = 0;
const int32_t callingAppUid = 0;
const string bundleName = "ohos.hisysevent.test";
const string abilityName = "testAbility";
const int32_t eventResult = 0;
const int32_t callingAppUid = 0;
}
void DmsHiSysEventReportTest::SetUpTestCase()
@ -56,7 +55,7 @@ void DmsHiSysEventReportTest::SetUp()
* @tc.desc: report start remote ability
* @tc.type: FUNC
*/
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_001, TestSize.Level1)
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_001, TestSize.Level3)
{
DTEST_LOG << "DmsHiSysEventReportTest DmsHiSysEventReportTest_001 begin" << std::endl;
@ -73,7 +72,7 @@ HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_001, TestSize.Level1)
* @tc.desc: report connect remote ability
* @tc.type: FUNC
*/
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_002, TestSize.Level1)
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_002, TestSize.Level3)
{
DTEST_LOG << "DmsHiSysEventReportTest DmsHiSysEventReportTest_002 begin" << std::endl;
@ -90,7 +89,7 @@ HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_002, TestSize.Level1)
* @tc.desc: report continue remote ability
* @tc.type: FUNC
*/
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_003, TestSize.Level1)
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_003, TestSize.Level3)
{
DTEST_LOG << "DmsHiSysEventReportTest DmsHiSysEventReportTest_003 begin" << std::endl;
@ -107,7 +106,7 @@ HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_003, TestSize.Level1)
* @tc.desc: report start remote ability by call
* @tc.type: FUNC
*/
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_004, TestSize.Level1)
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_004, TestSize.Level3)
{
DTEST_LOG << "DmsHiSysEventReportTest DmsHiSysEventReportTest_004 begin" << std::endl;
@ -124,7 +123,7 @@ HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_004, TestSize.Level1)
* @tc.desc: report disconnect remote ability
* @tc.type: FUNC
*/
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_005, TestSize.Level1)
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_005, TestSize.Level3)
{
DTEST_LOG << "DmsHiSysEventReportTest DmsHiSysEventReportTest_005 begin" << std::endl;
@ -141,7 +140,7 @@ HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_005, TestSize.Level1)
* @tc.desc: report release remote ability
* @tc.type: FUNC
*/
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_006, TestSize.Level1)
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_006, TestSize.Level3)
{
DTEST_LOG << "DmsHiSysEventReportTest DmsHiSysEventReportTest_006 begin" << std::endl;
@ -158,7 +157,7 @@ HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_006, TestSize.Level1)
* @tc.desc: report start remote ability
* @tc.type: FUNC
*/
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_007, TestSize.Level1)
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_007, TestSize.Level3)
{
DTEST_LOG << "DmsHiSysEventReportTest DmsHiSysEventReportTest_007 begin" << std::endl;
@ -174,7 +173,7 @@ HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_007, TestSize.Level1)
* @tc.desc: report connect remote ability
* @tc.type: FUNC
*/
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_008, TestSize.Level1)
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_008, TestSize.Level3)
{
DTEST_LOG << "DmsHiSysEventReportTest DmsHiSysEventReportTest_008 begin" << std::endl;
@ -190,7 +189,7 @@ HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_008, TestSize.Level1)
* @tc.desc: report continue remote ability
* @tc.type: FUNC
*/
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_009, TestSize.Level1)
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_009, TestSize.Level3)
{
DTEST_LOG << "DmsHiSysEventReportTest DmsHiSysEventReportTest_009 begin" << std::endl;
@ -206,7 +205,7 @@ HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_009, TestSize.Level1)
* @tc.desc: report start remote ability by call
* @tc.type: FUNC
*/
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_010, TestSize.Level1)
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_010, TestSize.Level3)
{
DTEST_LOG << "DmsHiSysEventReportTest DmsHiSysEventReportTest_010 begin" << std::endl;
@ -222,7 +221,7 @@ HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_010, TestSize.Level1)
* @tc.desc: report disconnect remote ability
* @tc.type: FUNC
*/
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_011, TestSize.Level1)
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_011, TestSize.Level3)
{
DTEST_LOG << "DmsHiSysEventReportTest DmsHiSysEventReportTest_011 begin" << std::endl;
@ -238,7 +237,7 @@ HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_011, TestSize.Level1)
* @tc.desc: report release remote ability
* @tc.type: FUNC
*/
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_012, TestSize.Level1)
HWTEST_F(DmsHiSysEventReportTest, DmsHiSysEventReportTest_012, TestSize.Level3)
{
DTEST_LOG << "DmsHiSysEventReportTest DmsHiSysEventReportTest_012 begin" << std::endl;

View File

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