mirror of
https://gitee.com/openharmony/deviceprofile_device_info_manager
synced 2024-11-27 01:31:01 +00:00
add dp ut
Signed-off-by: william <william.ligang@huawei.com>
This commit is contained in:
parent
461abbf62c
commit
9adaee0b31
@ -19,8 +19,8 @@ import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni")
|
||||
module_output_path = "device_info_manager/deviceprofiletest"
|
||||
|
||||
device_profile_deps = [
|
||||
"${old_device_profile_path}/radar:deviceprofileradar",
|
||||
"${old_device_profile_innerkits}/core:distributed_device_profile_client",
|
||||
"${old_device_profile_path}/radar:deviceprofileradar",
|
||||
"${old_device_profile_service}/core:distributed_device_profile",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
@ -39,8 +39,9 @@ ohos_executable("dp") {
|
||||
"src/shell_command.cpp",
|
||||
]
|
||||
|
||||
deps =
|
||||
[ "${old_device_profile_innerkits}/core:distributed_device_profile_client" ]
|
||||
deps = [
|
||||
"${old_device_profile_innerkits}/core:distributed_device_profile_client",
|
||||
]
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"dsoftbus:softbus_client",
|
||||
|
@ -310,6 +310,16 @@ ohos_unittest("dp_profile_service_new_test") {
|
||||
subsystem_name = "deviceprofile"
|
||||
}
|
||||
|
||||
ohos_unittest("dp_dm_adapter_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "unittest/dm_adapter_test.cpp" ]
|
||||
configs = device_profile_configs
|
||||
deps = device_profile_deps
|
||||
external_deps = device_profile_external_deps
|
||||
part_name = "device_info_manager"
|
||||
subsystem_name = "deviceprofile"
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = [
|
||||
@ -325,6 +335,7 @@ group("unittest") {
|
||||
":device_profile_manager_new_test",
|
||||
":distributed_device_profile_client_kv_new_test",
|
||||
":dp_content_sensor_test",
|
||||
":dp_dm_adapter_test",
|
||||
":dp_dumper_new_test",
|
||||
":dp_profile_service_new_test",
|
||||
":event_handler_factory_new_test",
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "distributed_device_profile_enums.h"
|
||||
#include "device_profile.h"
|
||||
#include "service_profile.h"
|
||||
#include "content_sensor_manager_utils.h"
|
||||
#include "characteristic_profile.h"
|
||||
#include "i_sync_completed_callback.h"
|
||||
#include "sync_completed_callback_stub.h"
|
||||
@ -1333,6 +1334,109 @@ HWTEST_F(DeviceProfileManagerTest, RunloadedFunction001, TestSize.Level1)
|
||||
ret = DeviceProfileManager::GetInstance().RunloadedFunction(deviceId, syncCb);
|
||||
EXPECT_EQ(ret, DP_LOAD_SYNC_ADAPTER_FAILED);
|
||||
}
|
||||
/**
|
||||
* @tc.name: RunloadedFunction002
|
||||
* @tc.desc: RunloadedFunction002
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DeviceProfileManagerTest, RunloadedFunction002, TestSize.Level1)
|
||||
{
|
||||
OHOS::sptr<OHOS::IRemoteObject> syncCb = new(nothrow) SyncCallback();
|
||||
string deviceId = ProfileUtils::GetLocalUdidFromDM();
|
||||
int32_t ret = DeviceProfileManager::GetInstance().RunloadedFunction(deviceId, syncCb);
|
||||
EXPECT_EQ(ret, DP_LOAD_SYNC_ADAPTER_FAILED);
|
||||
|
||||
DeviceProfileManager::GetInstance().isAdapterSoLoaded_ = true;
|
||||
ret = DeviceProfileManager::GetInstance().RunloadedFunction(deviceId, syncCb);
|
||||
EXPECT_EQ(ret, DP_LOAD_SYNC_ADAPTER_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DeviceOnlineAutoSync001
|
||||
* @tc.desc: DeviceOnlineAutoSync001
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DeviceProfileManagerTest, DeviceOnlineAutoSync001, TestSize.Level1)
|
||||
{
|
||||
std::string peerNetworkId = "";
|
||||
int32_t ret = DeviceProfileManager::GetInstance().DeviceOnlineAutoSync(peerNetworkId);
|
||||
EXPECT_EQ(ret, DP_INVALID_PARAMS);
|
||||
|
||||
peerNetworkId = ProfileUtils::GetLocalUdidFromDM();
|
||||
ret = DeviceProfileManager::GetInstance().DeviceOnlineAutoSync(peerNetworkId);
|
||||
EXPECT_EQ(ret, DP_INVALID_PARAMS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnNodeOnline001
|
||||
* @tc.desc: OnNodeOnline001
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DeviceProfileManagerTest, OnNodeOnline001, TestSize.Level1)
|
||||
{
|
||||
std::string peerNetworkId = "";
|
||||
DeviceProfileManager::GetInstance().OnNodeOnline(peerNetworkId);
|
||||
|
||||
peerNetworkId = ProfileUtils::GetLocalUdidFromDM();
|
||||
DeviceProfileManager::GetInstance().OnNodeOnline(peerNetworkId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnNodeOffline001
|
||||
* @tc.desc: OnNodeOffline001
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DeviceProfileManagerTest, OnNodeOffline001, TestSize.Level1)
|
||||
{
|
||||
std::string peerNetworkId = "";
|
||||
DeviceProfileManager::GetInstance().OnNodeOffline(peerNetworkId);
|
||||
|
||||
peerNetworkId = ProfileUtils::GetLocalUdidFromDM();
|
||||
DeviceProfileManager::GetInstance().OnNodeOffline(peerNetworkId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IsLocalOrOnlineDevice001
|
||||
* @tc.desc: IsLocalOrOnlineDevice001
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DeviceProfileManagerTest, IsLocalOrOnlineDevice001, TestSize.Level1)
|
||||
{
|
||||
std::string deviceId = "";
|
||||
bool ret = DeviceProfileManager::GetInstance().IsLocalOrOnlineDevice(deviceId);
|
||||
EXPECT_EQ(ret, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IsLocalOrOnlineDevice002
|
||||
* @tc.desc: IsLocalOrOnlineDevice002
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DeviceProfileManagerTest, IsLocalOrOnlineDevice002, TestSize.Level1)
|
||||
{
|
||||
std::string deviceId = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid();
|
||||
bool ret = DeviceProfileManager::GetInstance().IsLocalOrOnlineDevice(deviceId);
|
||||
EXPECT_EQ(ret, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IsLocalOrOnlineDevice003
|
||||
* @tc.desc: IsLocalOrOnlineDevice003
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DeviceProfileManagerTest, IsLocalOrOnlineDevice0013, TestSize.Level1)
|
||||
{
|
||||
std::string deviceId = "deviceId";
|
||||
DeviceProfileManager::GetInstance().onlineDevUdidSet_.insert("deviceId");
|
||||
bool ret = DeviceProfileManager::GetInstance().IsLocalOrOnlineDevice(deviceId);
|
||||
EXPECT_EQ(ret, true);
|
||||
}
|
||||
} // namespace DistributedDeviceProfile
|
||||
} // namespace OHOS
|
||||
|
222
services/core/test/unittest/dm_adapter_test.cpp
Normal file
222
services/core/test/unittest/dm_adapter_test.cpp
Normal file
@ -0,0 +1,222 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "distributed_device_profile_constants.h"
|
||||
#include "distributed_device_profile_errors.h"
|
||||
#include "distributed_device_profile_log.h"
|
||||
#include "event_handler_factory.h"
|
||||
#define private public
|
||||
#define protected public
|
||||
|
||||
#include "dm_adapter.h"
|
||||
|
||||
#undef private
|
||||
#undef protected
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace DistributedDeviceProfile {
|
||||
using namespace std;
|
||||
namespace {
|
||||
const std::string TAG = "DMAdapterTest";
|
||||
}
|
||||
class DMAdapterTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void DMAdapterTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DMAdapterTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DMAdapterTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void DMAdapterTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: Init001
|
||||
* @tc.desc: Init
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DMAdapterTest, Init001, TestSize.Level1)
|
||||
{
|
||||
DMAdapter::GetInstance().autoSyncHandler_ = nullptr;
|
||||
int32_t ret = DMAdapter::GetInstance().Init();
|
||||
EXPECT_EQ(0, ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: Init002
|
||||
* @tc.desc: Init
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DMAdapterTest, Init002, TestSize.Level1)
|
||||
{
|
||||
DMAdapter::GetInstance().deviceStateCallback_ = nullptr;
|
||||
int32_t ret = DMAdapter::GetInstance().Init();
|
||||
EXPECT_EQ(0, ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: Init003
|
||||
* @tc.desc: Init
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DMAdapterTest, Init003, TestSize.Level1)
|
||||
{
|
||||
DMAdapter::GetInstance().autoSyncHandler_ = EventHandlerFactory::
|
||||
GetInstance().CreateEventHandler(AUTO_SYNC_HANDLER);
|
||||
int32_t ret = DMAdapter::GetInstance().Init();
|
||||
EXPECT_EQ(0, ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: Init004
|
||||
* @tc.desc: Init
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DMAdapterTest, Init004, TestSize.Level1)
|
||||
{
|
||||
DMAdapter::GetInstance().deviceStateCallback_ = std::make_shared<DMAdapter::DpDeviceStateCallback>();
|
||||
int32_t ret = DMAdapter::GetInstance().Init();
|
||||
EXPECT_EQ(0, ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: UnInit001
|
||||
* @tc.desc: UnInit
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DMAdapterTest, UnInit001, TestSize.Level1)
|
||||
{
|
||||
DMAdapter::GetInstance().autoSyncHandler_ = nullptr;
|
||||
int32_t ret = DMAdapter::GetInstance().UnInit();
|
||||
EXPECT_EQ(0, ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: UnInit002
|
||||
* @tc.desc: UnInit
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DMAdapterTest, UnInit002, TestSize.Level1)
|
||||
{
|
||||
DMAdapter::GetInstance().deviceStateCallback_ = nullptr;
|
||||
int32_t ret = DMAdapter::GetInstance().UnInit();
|
||||
EXPECT_EQ(0, ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: UnInit003
|
||||
* @tc.desc: UnInit
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DMAdapterTest, UnInit003, TestSize.Level1)
|
||||
{
|
||||
DMAdapter::GetInstance().autoSyncHandler_ = EventHandlerFactory::
|
||||
GetInstance().CreateEventHandler(AUTO_SYNC_HANDLER);
|
||||
int32_t ret = DMAdapter::GetInstance().UnInit();
|
||||
EXPECT_EQ(0, ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: UnInit004
|
||||
* @tc.desc: UnInit
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DMAdapterTest, UnInit004, TestSize.Level1)
|
||||
{
|
||||
DMAdapter::GetInstance().deviceStateCallback_ = std::make_shared<DMAdapter::DpDeviceStateCallback>();
|
||||
int32_t ret = DMAdapter::GetInstance().Init();
|
||||
EXPECT_EQ(0, ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: ReInit001
|
||||
* @tc.desc: ReInit
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DMAdapterTest, ReInit001, TestSize.Level1)
|
||||
{
|
||||
int32_t ret = DMAdapter::GetInstance().ReInit();
|
||||
EXPECT_EQ(0, ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: AutoSync001
|
||||
* @tc.desc: AutoSync
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DMAdapterTest, AutoSync001, TestSize.Level1)
|
||||
{
|
||||
DistributedHardware::DmDeviceInfo deviceInfo;
|
||||
DMAdapter::GetInstance().AutoSync(deviceInfo);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: AutoSync003
|
||||
* @tc.desc: AutoSync
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DMAdapterTest, AutoSync002, TestSize.Level1)
|
||||
{
|
||||
DMAdapter::GetInstance().Init();
|
||||
DistributedHardware::DmDeviceInfo deviceInfo;
|
||||
DMAdapter::GetInstance().AutoSync(deviceInfo);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: AutoSync003
|
||||
* @tc.desc: AutoSync
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(DMAdapterTest, AutoSync003, TestSize.Level1)
|
||||
{
|
||||
DMAdapter::GetInstance().Init();
|
||||
DMAdapter::GetInstance().autoSyncHandler_ = nullptr;
|
||||
DistributedHardware::DmDeviceInfo deviceInfo;
|
||||
DMAdapter::GetInstance().AutoSync(deviceInfo);
|
||||
}
|
||||
} // namespace DistributedDeviceProfile
|
||||
} // namespace OHOS
|
@ -71,5 +71,16 @@ HWTEST_F(PermissionManagerTest, IsCallerTrust_001, TestSize.Level1)
|
||||
bool ret = PermissionManager::GetInstance().IsCallerTrust(PUT_ACCESS_CONTROL_PROFILE);
|
||||
EXPECT_EQ(ret, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: GetCallerProcName_001
|
||||
* @tc.desc: Normal testCase of PermissionManagerTest for CRUD
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(PermissionManagerTest, GetCallerProcName_001, TestSize.Level1)
|
||||
{
|
||||
std::string ret = PermissionManager::GetInstance().GetCallerProcName();
|
||||
EXPECT_EQ(ret, "");
|
||||
}
|
||||
} // namespace DistributedDeviceProfile
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user