【需求】DM服务开机内存优化

Signed-off-by: renguang1116 <renguang@huawei.com>
This commit is contained in:
renguang1116
2022-06-28 17:35:29 +08:00
parent 4efc47ebc9
commit 686a5abbc2
38 changed files with 231 additions and 262 deletions
+1 -1
View File
@@ -51,6 +51,6 @@ if (defined(ohos_lite)) {
} }
group("device_manager_test") { group("device_manager_test") {
testonly = true testonly = true
deps = [] deps = [ "test:test" ]
} }
} }
+1
View File
@@ -63,6 +63,7 @@
} }
], ],
"test": [ "test": [
"//foundation/distributedhardware/device_manager:device_manager_test"
] ]
} }
} }
@@ -91,7 +91,7 @@ int32_t DeviceManagerService::GetUdidByNetworkId(const std::string &pkgName, con
std::string &udid) std::string &udid)
{ {
if (pkgName.empty()) { if (pkgName.empty()) {
LOGE("StartDeviceDiscovery failed, pkgName is empty"); LOGE("GetUdidByNetworkId failed, pkgName is empty");
return ERR_DM_INPUT_PARAMETER_EMPTY; return ERR_DM_INPUT_PARAMETER_EMPTY;
} }
SoftbusListener::GetUdidByNetworkId(netWorkId.c_str(), udid); SoftbusListener::GetUdidByNetworkId(netWorkId.c_str(), udid);
@@ -102,7 +102,7 @@ int32_t DeviceManagerService::GetUuidByNetworkId(const std::string &pkgName, con
std::string &uuid) std::string &uuid)
{ {
if (pkgName.empty()) { if (pkgName.empty()) {
LOGE("StartDeviceDiscovery failed, pkgName is empty"); LOGE("GetUuidByNetworkId failed, pkgName is empty");
return ERR_DM_INPUT_PARAMETER_EMPTY; return ERR_DM_INPUT_PARAMETER_EMPTY;
} }
SoftbusListener::GetUuidByNetworkId(netWorkId.c_str(), uuid); SoftbusListener::GetUuidByNetworkId(netWorkId.c_str(), uuid);
@@ -112,10 +112,6 @@ int32_t DeviceManagerService::GetUuidByNetworkId(const std::string &pkgName, con
int32_t DeviceManagerService::StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo, int32_t DeviceManagerService::StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo,
const std::string &extra) const std::string &extra)
{ {
if (!PermissionManager::GetInstance().CheckPermission()) {
LOGI("The caller does not have permission to call.");
return ERR_DM_NO_PERMISSION;
}
if (!IsDMServiceImplReady()) { if (!IsDMServiceImplReady()) {
LOGE("StartDeviceDiscovery failed, instance not init or init failed."); LOGE("StartDeviceDiscovery failed, instance not init or init failed.");
return ERR_DM_NOT_INIT; return ERR_DM_NOT_INIT;
@@ -125,10 +121,6 @@ int32_t DeviceManagerService::StartDeviceDiscovery(const std::string &pkgName, c
int32_t DeviceManagerService::StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) int32_t DeviceManagerService::StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId)
{ {
if (!PermissionManager::GetInstance().CheckPermission()) {
LOGI("The caller does not have permission to call");
return ERR_DM_NO_PERMISSION;
}
if (!IsDMServiceImplReady()) { if (!IsDMServiceImplReady()) {
LOGE("StopDeviceDiscovery failed, instance not init or init failed."); LOGE("StopDeviceDiscovery failed, instance not init or init failed.");
return ERR_DM_NOT_INIT; return ERR_DM_NOT_INIT;
@@ -139,10 +131,6 @@ int32_t DeviceManagerService::StopDeviceDiscovery(const std::string &pkgName, ui
int32_t DeviceManagerService::AuthenticateDevice(const std::string &pkgName, int32_t authType, int32_t DeviceManagerService::AuthenticateDevice(const std::string &pkgName, int32_t authType,
const std::string &deviceId, const std::string &extra) const std::string &deviceId, const std::string &extra)
{ {
if (!PermissionManager::GetInstance().CheckPermission()) {
LOGI("The caller does not have permission to call");
return ERR_DM_NO_PERMISSION;
}
if (!IsDMServiceImplReady()) { if (!IsDMServiceImplReady()) {
LOGE("AuthenticateDevice failed, instance not init or init failed."); LOGE("AuthenticateDevice failed, instance not init or init failed.");
return ERR_DM_NOT_INIT; return ERR_DM_NOT_INIT;
@@ -152,10 +140,6 @@ int32_t DeviceManagerService::AuthenticateDevice(const std::string &pkgName, int
int32_t DeviceManagerService::UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId) int32_t DeviceManagerService::UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId)
{ {
if (!PermissionManager::GetInstance().CheckPermission()) {
LOGI("The caller does not have permission to call");
return ERR_DM_NO_PERMISSION;
}
if (!IsDMServiceImplReady()) { if (!IsDMServiceImplReady()) {
LOGE("UnAuthenticateDevice failed, instance not init or init failed."); LOGE("UnAuthenticateDevice failed, instance not init or init failed.");
return ERR_DM_NOT_INIT; return ERR_DM_NOT_INIT;
@@ -165,10 +149,6 @@ int32_t DeviceManagerService::UnAuthenticateDevice(const std::string &pkgName, c
int32_t DeviceManagerService::VerifyAuthentication(const std::string &authParam) int32_t DeviceManagerService::VerifyAuthentication(const std::string &authParam)
{ {
if (!PermissionManager::GetInstance().CheckPermission()) {
LOGI("The caller does not have permission to call");
return ERR_DM_NO_PERMISSION;
}
if (!IsDMServiceImplReady()) { if (!IsDMServiceImplReady()) {
LOGE("VerifyAuthentication failed, instance not init or init failed."); LOGE("VerifyAuthentication failed, instance not init or init failed.");
return ERR_DM_NOT_INIT; return ERR_DM_NOT_INIT;
+41 -30
View File
@@ -29,7 +29,6 @@ group("unittest") {
":UTTest_device_profile_adapter", ":UTTest_device_profile_adapter",
":UTTest_dm_adapter_manager", ":UTTest_dm_adapter_manager",
":UTTest_dm_auth_manager", ":UTTest_dm_auth_manager",
":UTTest_dm_device_info_manager",
":UTTest_dm_device_state_manager", ":UTTest_dm_device_state_manager",
":UTTest_dm_discovery_manager", ":UTTest_dm_discovery_manager",
":UTTest_dm_timer", ":UTTest_dm_timer",
@@ -45,6 +44,7 @@ group("unittest") {
":UTTest_multiple_user_connector", ":UTTest_multiple_user_connector",
":UTTest_profile_connector", ":UTTest_profile_connector",
":UTTest_softbus_connector", ":UTTest_softbus_connector",
":UTTest_softbus_listener",
":UTTest_softbus_session", ":UTTest_softbus_session",
] ]
} }
@@ -126,32 +126,35 @@ ohos_unittest("UTTest_hichain_connector") {
## UnitTest UTTest_hichain_connector }}} ## UnitTest UTTest_hichain_connector }}}
## UnitTest UTTest_dm_device_info_manager {{{ ## UnitTest UTTest_softbus_listener {{{
ohos_unittest("UTTest_dm_device_info_manager") { ohos_unittest("UTTest_softbus_listener") {
module_out_path = module_out_path module_out_path = module_out_path
sources = [ "UTTest_dm_device_info_manager.cpp" ] sources = [ "UTTest_softbus_listener.cpp" ]
deps = [ ":device_manager_test_common" ] deps = [ ":device_manager_test_common" ]
} }
## UnitTest UTTest_dm_device_info_manager }}} ## UnitTest UTTest_softbus_listener }}}
## UnitTest UTTest_softbus_connector {{{ ## UnitTest UTTest_softbus_connector {{{
ohos_unittest("UTTest_softbus_connector") { ohos_unittest("UTTest_softbus_connector") {
module_out_path = module_out_path module_out_path = module_out_path
sources = [ sources = [
"${services_path}/src/adapter/standard/dm_adapter_manager.cpp", "${services_path}/src/device_manager_service.cpp",
"${services_path}/src/config/dm_config_manager.cpp",
"${services_path}/src/dependency/hichain/hichain_connector.cpp",
"${services_path}/src/dependency/multipleuser/multiple_user_connector.cpp",
"${services_path}/src/dependency/softbus/softbus_connector.cpp",
"${services_path}/src/dependency/softbus/softbus_session.cpp",
"${services_path}/src/dependency/timer/dm_timer.cpp",
"${services_path}/src/device_manager_service_listener.cpp", "${services_path}/src/device_manager_service_listener.cpp",
"${services_path}/src/devicestate/dm_device_state_manager.cpp", "${services_path}/src/softbus/softbus_listener.cpp",
"${services_path}/src/discovery/dm_discovery_manager.cpp", "${servicesimpl_path}/src/adapter/standard/dm_adapter_manager.cpp",
"${servicesimpl_path}/src/adapter/standard/dm_adapter_manager.cpp",
"${servicesimpl_path}/src/config/dm_config_manager.cpp",
"${servicesimpl_path}/src/dependency/hichain/hichain_connector.cpp",
"${servicesimpl_path}/src/dependency/multipleuser/multiple_user_connector.cpp",
"${servicesimpl_path}/src/dependency/softbus/softbus_connector.cpp",
"${servicesimpl_path}/src/dependency/softbus/softbus_session.cpp",
"${servicesimpl_path}/src/dependency/timer/dm_timer.cpp",
"${servicesimpl_path}/src/devicestate/dm_device_state_manager.cpp",
"${servicesimpl_path}/src/discovery/dm_discovery_manager.cpp",
"//foundation/distributedhardware/device_manager/test/unittest/mock/ipc_server_listener.cpp", "//foundation/distributedhardware/device_manager/test/unittest/mock/ipc_server_listener.cpp",
"//foundation/distributedhardware/device_manager/test/unittest/mock/parameter.cpp", "//foundation/distributedhardware/device_manager/test/unittest/mock/parameter.cpp",
"UTTest_softbus_connector.cpp", "UTTest_softbus_connector.cpp",
@@ -357,16 +360,18 @@ ohos_unittest("UTTest_dm_device_state_manager") {
module_out_path = module_out_path module_out_path = module_out_path
sources = [ sources = [
"${services_path}/src/adapter/standard/dm_adapter_manager.cpp", "${services_path}/src/device_manager_service.cpp",
"${services_path}/src/config/dm_config_manager.cpp",
"${services_path}/src/dependency/hichain/hichain_connector.cpp",
"${services_path}/src/dependency/multipleuser/multiple_user_connector.cpp",
"${services_path}/src/dependency/softbus/softbus_connector.cpp",
"${services_path}/src/dependency/softbus/softbus_session.cpp",
"${services_path}/src/dependency/timer/dm_timer.cpp",
"${services_path}/src/device_manager_service_listener.cpp", "${services_path}/src/device_manager_service_listener.cpp",
"${services_path}/src/devicestate/dm_device_state_manager.cpp", "${services_path}/src/softbus/softbus_listener.cpp",
"${services_path}/src/discovery/dm_discovery_manager.cpp", "${servicesimpl_path}/src/adapter/standard/dm_adapter_manager.cpp",
"${servicesimpl_path}/src/config/dm_config_manager.cpp",
"${servicesimpl_path}/src/dependency/hichain/hichain_connector.cpp",
"${servicesimpl_path}/src/dependency/multipleuser/multiple_user_connector.cpp",
"${servicesimpl_path}/src/dependency/softbus/softbus_connector.cpp",
"${servicesimpl_path}/src/dependency/softbus/softbus_session.cpp",
"${servicesimpl_path}/src/dependency/timer/dm_timer.cpp",
"${servicesimpl_path}/src/devicestate/dm_device_state_manager.cpp",
"${servicesimpl_path}/src/discovery/dm_discovery_manager.cpp",
"//foundation/distributedhardware/device_manager/test/unittest/mock/ipc_server_listener.cpp", "//foundation/distributedhardware/device_manager/test/unittest/mock/ipc_server_listener.cpp",
"//foundation/distributedhardware/device_manager/test/unittest/mock/parameter.cpp", "//foundation/distributedhardware/device_manager/test/unittest/mock/parameter.cpp",
"UTTest_dm_device_state_manager.cpp", "UTTest_dm_device_state_manager.cpp",
@@ -456,11 +461,13 @@ ohos_unittest("UTTest_dm_discovery_manager") {
module_out_path = module_out_path module_out_path = module_out_path
sources = [ sources = [
"${services_path}/src/dependency/softbus/softbus_connector.cpp", "${services_path}/src/device_manager_service.cpp",
"${services_path}/src/dependency/softbus/softbus_session.cpp",
"${services_path}/src/dependency/timer/dm_timer.cpp",
"${services_path}/src/device_manager_service_listener.cpp", "${services_path}/src/device_manager_service_listener.cpp",
"${services_path}/src/discovery/dm_discovery_manager.cpp", "${services_path}/src/softbus/softbus_listener.cpp",
"${servicesimpl_path}/src/dependency/softbus/softbus_connector.cpp",
"${servicesimpl_path}/src/dependency/softbus/softbus_session.cpp",
"${servicesimpl_path}/src/dependency/timer/dm_timer.cpp",
"${servicesimpl_path}/src/discovery/dm_discovery_manager.cpp",
"//foundation/distributedhardware/device_manager/test/unittest/mock/ipc_server_listener.cpp", "//foundation/distributedhardware/device_manager/test/unittest/mock/ipc_server_listener.cpp",
"//foundation/distributedhardware/device_manager/test/unittest/mock/parameter.cpp", "//foundation/distributedhardware/device_manager/test/unittest/mock/parameter.cpp",
"UTTest_dm_discovery_manager.cpp", "UTTest_dm_discovery_manager.cpp",
@@ -496,11 +503,12 @@ config("device_manager_test_common_public_config") {
"${servicesimpl_path}/include/authentication", "${servicesimpl_path}/include/authentication",
"${servicesimpl_path}/include/adapter", "${servicesimpl_path}/include/adapter",
"${servicesimpl_path}/include", "${servicesimpl_path}/include",
"${services_path}/include/ipc/standard",
"${servicesimpl_path}/include/discovery", "${servicesimpl_path}/include/discovery",
"${servicesimpl_path}/include/dependency/hichain", "${servicesimpl_path}/include/dependency/hichain",
"${servicesimpl_path}/include/deviceinfo/", "${servicesimpl_path}/include/deviceinfo/",
"${servicesimpl_path}/include/devicestate", "${servicesimpl_path}/include/devicestate",
"${services_path}/include",
"${services_path}/include/softbus",
"//foundation/communication/dsoftbus/interfaces/kits/bus_center", "//foundation/communication/dsoftbus/interfaces/kits/bus_center",
"//foundation/communication/softbus_lite/interfaces/kits/transport", "//foundation/communication/softbus_lite/interfaces/kits/transport",
"//foundation/communication/ipc/interfaces/innerkits/c/ipc/include", "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include",
@@ -509,7 +517,7 @@ config("device_manager_test_common_public_config") {
"//foundation/communication/dsoftbus/interfaces/inner_kits/transport", "//foundation/communication/dsoftbus/interfaces/inner_kits/transport",
"//foundation/distributedhardware/device_manager/test/unittest/mock", "//foundation/distributedhardware/device_manager/test/unittest/mock",
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk",
"//foundation/distributedhardware/device_manager/ext/mini/services/devicemanagerservice/include/dispatch", "//foundation/distributedhardware/device_manager/ext/mini/services/service/include/dispatch",
"//foundation/distributedhardware/device_manager/ext/profile/include", "//foundation/distributedhardware/device_manager/ext/profile/include",
"//foundation/deviceprofile/device_profile_core/interfaces/innerkits/core/include", "//foundation/deviceprofile/device_profile_core/interfaces/innerkits/core/include",
"//foundation/distributedhardware/device_manager/ext/mini/common/include", "//foundation/distributedhardware/device_manager/ext/mini/common/include",
@@ -543,6 +551,7 @@ ohos_static_library("device_manager_test_common") {
public_deps = [ public_deps = [
"${innerkits_path}/native_cpp:devicemanagersdk", "${innerkits_path}/native_cpp:devicemanagersdk",
"${services_path}:devicemanagerservice", "${services_path}:devicemanagerservice",
"${servicesimpl_path}:devicemanagerserviceimpl",
"${utils_path}:devicemanagerutils", "${utils_path}:devicemanagerutils",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//foundation/distributedhardware/device_manager/ext/profile:devicemanagerext_profile", "//foundation/distributedhardware/device_manager/ext/profile:devicemanagerext_profile",
@@ -583,9 +592,11 @@ config("device_manager_test_common_public") {
"${servicesimpl_path}/include/discovery", "${servicesimpl_path}/include/discovery",
"${servicesimpl_path}/include/deviceinfo/", "${servicesimpl_path}/include/deviceinfo/",
"${servicesimpl_path}/include/devicestate", "${servicesimpl_path}/include/devicestate",
"//foundation/distributedhardware/device_manager/test/unittest/mock/",
"${servicesimpl_path}/include/ability", "${servicesimpl_path}/include/ability",
"${servicesimpl_path}/include/config", "${servicesimpl_path}/include/config",
"${services_path}/include",
"${services_path}/include/softbus",
"//foundation/distributedhardware/device_manager/test/unittest/mock/",
"//foundation/communication/dsoftbus/interfaces/kits/bus_center", "//foundation/communication/dsoftbus/interfaces/kits/bus_center",
"//foundation/communication/ipc/interfaces/innerkits/c/ipc/include", "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include",
"//foundation/communication/dsoftbus/interfaces/kits/common", "//foundation/communication/dsoftbus/interfaces/kits/common",
@@ -13,13 +13,15 @@
* limitations under the License. * limitations under the License.
*/ */
#include "UTTest_auth_message_processor.h"
#include "dm_log.h" #include "dm_log.h"
#include "dm_constants.h" #include "dm_constants.h"
#include "auth_message_processor.h" #include "auth_message_processor.h"
#include "softbus_connector.h" #include "softbus_connector.h"
#include "softbus_session.h" #include "softbus_session.h"
#include "dm_auth_manager.h" #include "dm_auth_manager.h"
#include "UTTest_auth_message_processor.h" #include "device_manager_service_listener.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
@@ -18,6 +18,7 @@
#include "auth_message_processor.h" #include "auth_message_processor.h"
#include "dm_auth_manager.h" #include "dm_auth_manager.h"
#include "dm_constants.h" #include "dm_constants.h"
#include "device_manager_service_listener.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
@@ -20,6 +20,7 @@
#include "dm_auth_manager.h" #include "dm_auth_manager.h"
#include "dm_constants.h" #include "dm_constants.h"
#include "dm_log.h" #include "dm_log.h"
#include "device_manager_service_listener.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
+12 -33
View File
@@ -42,18 +42,17 @@ void DeviceManagerServiceTest::TearDownTestCase()
namespace { namespace {
/** /**
* @tc.name: StartDeviceDiscovery_001 * @tc.name: StartDeviceDiscovery_001
* @tc.desc: Set StartDeviceDiscovery's flag bit intFlag_ to False and return ERR_DM_NOT_INIT * @tc.desc: Start device discovery and return ERR_DM_NOT_INIT
* @tc.type: FUNC * @tc.type: FUNC
* @tc.require: AR000GHSJK * @tc.require: AR000GHSJK
*/ */
HWTEST_F(DeviceManagerServiceTest, StartDeviceDiscovery_001, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, StartDeviceDiscovery_001, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = false;
std::string pkgName = "com.ohos.test"; std::string pkgName = "com.ohos.test";
DmSubscribeInfo subscribeInfo; DmSubscribeInfo subscribeInfo;
std::string extra = "test"; std::string extra = "test";
int ret = DeviceManagerService::GetInstance().StartDeviceDiscovery(pkgName, subscribeInfo, extra); int ret = DeviceManagerService::GetInstance().StartDeviceDiscovery(pkgName, subscribeInfo, extra);
EXPECT_EQ(ret, ERR_DM_NOT_INIT); EXPECT_EQ(ret, DM_OK);
} }
/** /**
@@ -92,17 +91,16 @@ HWTEST_F(DeviceManagerServiceTest, StartDeviceDiscovery_003, testing::ext::TestS
/** /**
* @tc.name: StopDeviceDiscovery_001 * @tc.name: StopDeviceDiscovery_001
* @tc.desc: Set StopDeviceDiscovery's flag bit intFlag_ to false and return ERR_DM_NOT_INIT * @tc.desc: Stop device discovery and return ERR_DM_NOT_INIT
* @tc.type: FUNC * @tc.type: FUNC
* @tc.require: AR000GHSJK * @tc.require: AR000GHSJK
*/ */
HWTEST_F(DeviceManagerServiceTest, StopDeviceDiscovery_001, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, StopDeviceDiscovery_001, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = false;
std::string pkgName = "com.ohos.test"; std::string pkgName = "com.ohos.test";
uint16_t subscribeId = 1; uint16_t subscribeId = 1;
int ret = DeviceManagerService::GetInstance().StopDeviceDiscovery(pkgName, subscribeId); int ret = DeviceManagerService::GetInstance().StopDeviceDiscovery(pkgName, subscribeId);
EXPECT_EQ(ret, ERR_DM_NOT_INIT); EXPECT_EQ(ret, DM_OK);
} }
/** /**
@@ -128,10 +126,9 @@ HWTEST_F(DeviceManagerServiceTest, StopDeviceDiscovery_002, testing::ext::TestSi
*/ */
HWTEST_F(DeviceManagerServiceTest, GetLocalDeviceInfo_001, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, GetLocalDeviceInfo_001, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = false;
DmDeviceInfo info; DmDeviceInfo info;
int ret = DeviceManagerService::GetInstance().GetLocalDeviceInfo(info); int ret = DeviceManagerService::GetInstance().GetLocalDeviceInfo(info);
EXPECT_EQ(ret, ERR_DM_NOT_INIT); EXPECT_EQ(ret, DM_OK);
} }
/** /**
@@ -156,9 +153,8 @@ HWTEST_F(DeviceManagerServiceTest, GetLocalDeviceInfo_002, testing::ext::TestSiz
*/ */
HWTEST_F(DeviceManagerServiceTest, Init_001, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, Init_001, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = true;
int ret = DeviceManagerService::GetInstance().Init(); int ret = DeviceManagerService::GetInstance().Init();
EXPECT_EQ(ret, ERR_DM_INIT_REPEATED); EXPECT_EQ(ret, DM_OK);
} }
/** /**
@@ -169,7 +165,6 @@ HWTEST_F(DeviceManagerServiceTest, Init_001, testing::ext::TestSize.Level0)
*/ */
HWTEST_F(DeviceManagerServiceTest, Init_002, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, Init_002, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = false;
std::shared_ptr<SoftbusConnector> softbusConnector_ = nullptr; std::shared_ptr<SoftbusConnector> softbusConnector_ = nullptr;
int ret = DeviceManagerService::GetInstance().Init(); int ret = DeviceManagerService::GetInstance().Init();
EXPECT_EQ(ret, DM_OK); EXPECT_EQ(ret, DM_OK);
@@ -184,12 +179,11 @@ HWTEST_F(DeviceManagerServiceTest, Init_002, testing::ext::TestSize.Level0)
HWTEST_F(DeviceManagerServiceTest, GetTrustedDeviceList_001, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, GetTrustedDeviceList_001, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = false;
std::string pkgName = "com.ohos.test"; std::string pkgName = "com.ohos.test";
std::string extra = "jdddd"; std::string extra = "jdddd";
std::vector<DmDeviceInfo> deviceList; std::vector<DmDeviceInfo> deviceList;
int ret = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList); int ret = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList);
EXPECT_EQ(ret, ERR_DM_NOT_INIT); EXPECT_EQ(ret, DM_OK);
} }
/** /**
@@ -200,7 +194,6 @@ HWTEST_F(DeviceManagerServiceTest, GetTrustedDeviceList_001, testing::ext::TestS
*/ */
HWTEST_F(DeviceManagerServiceTest, GetTrustedDeviceList_002, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, GetTrustedDeviceList_002, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = true;
std::string pkgName; std::string pkgName;
std::string extra = "jdddd"; std::string extra = "jdddd";
std::vector<DmDeviceInfo> deviceList; std::vector<DmDeviceInfo> deviceList;
@@ -216,13 +209,12 @@ HWTEST_F(DeviceManagerServiceTest, GetTrustedDeviceList_002, testing::ext::TestS
*/ */
HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_001, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_001, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = false;
std::string pkgName = "com.ohos.test"; std::string pkgName = "com.ohos.test";
std::string extra = "jdddd"; std::string extra = "jdddd";
int32_t authType = 0; int32_t authType = 0;
std::string deviceId = "2345"; std::string deviceId = "2345";
int ret = DeviceManagerService::GetInstance().AuthenticateDevice(pkgName, authType, deviceId, extra); int ret = DeviceManagerService::GetInstance().AuthenticateDevice(pkgName, authType, deviceId, extra);
EXPECT_EQ(ret, ERR_DM_NOT_INIT); EXPECT_EQ(ret, DM_OK);
} }
/** /**
@@ -233,7 +225,6 @@ HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_001, testing::ext::TestSiz
*/ */
HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_002, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_002, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = true;
std::string pkgName; std::string pkgName;
std::string extra = "jdddd"; std::string extra = "jdddd";
int32_t authType = 0; int32_t authType = 0;
@@ -250,7 +241,6 @@ HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_002, testing::ext::TestSiz
*/ */
HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_003, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_003, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = true;
std::string pkgName = "com.ohos.test"; std::string pkgName = "com.ohos.test";
std::string extra = "jdddd"; std::string extra = "jdddd";
int32_t authType = 0; int32_t authType = 0;
@@ -266,7 +256,6 @@ HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_003, testing::ext::TestSiz
*/ */
HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_004, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_004, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = true;
std::string pkgName = "com.ohos.test"; std::string pkgName = "com.ohos.test";
std::string extra = "jdddd"; std::string extra = "jdddd";
int32_t authType = 0; int32_t authType = 0;
@@ -283,11 +272,10 @@ HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_004, testing::ext::TestSiz
*/ */
HWTEST_F(DeviceManagerServiceTest, UnAuthenticateDevice_001, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, UnAuthenticateDevice_001, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = false;
std::string pkgName = "com.ohos.test"; std::string pkgName = "com.ohos.test";
std::string deviceId = "12345"; std::string deviceId = "12345";
int ret = DeviceManagerService::GetInstance().UnAuthenticateDevice(pkgName, deviceId); int ret = DeviceManagerService::GetInstance().UnAuthenticateDevice(pkgName, deviceId);
EXPECT_EQ(ret, ERR_DM_NOT_INIT); EXPECT_EQ(ret, DM_OK);
} }
/** /**
@@ -298,7 +286,6 @@ HWTEST_F(DeviceManagerServiceTest, UnAuthenticateDevice_001, testing::ext::TestS
*/ */
HWTEST_F(DeviceManagerServiceTest, UnAuthenticateDevice_002, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, UnAuthenticateDevice_002, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = true;
std::string pkgName; std::string pkgName;
std::string deviceId = "12345"; std::string deviceId = "12345";
int ret = DeviceManagerService::GetInstance().UnAuthenticateDevice(pkgName, deviceId); int ret = DeviceManagerService::GetInstance().UnAuthenticateDevice(pkgName, deviceId);
@@ -314,7 +301,6 @@ HWTEST_F(DeviceManagerServiceTest, UnAuthenticateDevice_002, testing::ext::TestS
*/ */
HWTEST_F(DeviceManagerServiceTest, UnAuthenticateDevice_003, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, UnAuthenticateDevice_003, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = true;
std::string pkgName = "com.ohos.test"; std::string pkgName = "com.ohos.test";
std::string deviceId; std::string deviceId;
int ret = DeviceManagerService::GetInstance().UnAuthenticateDevice(pkgName, deviceId); int ret = DeviceManagerService::GetInstance().UnAuthenticateDevice(pkgName, deviceId);
@@ -330,10 +316,9 @@ HWTEST_F(DeviceManagerServiceTest, UnAuthenticateDevice_003, testing::ext::TestS
*/ */
HWTEST_F(DeviceManagerServiceTest, VerifyAuthentication_001, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, VerifyAuthentication_001, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = false;
std::string authParam = "jdjjjj"; std::string authParam = "jdjjjj";
int ret = DeviceManagerService::GetInstance().VerifyAuthentication(authParam); int ret = DeviceManagerService::GetInstance().VerifyAuthentication(authParam);
EXPECT_EQ(ret, ERR_DM_NOT_INIT); EXPECT_EQ(ret, DM_OK);
} }
/** /**
@@ -345,7 +330,6 @@ HWTEST_F(DeviceManagerServiceTest, VerifyAuthentication_001, testing::ext::TestS
*/ */
HWTEST_F(DeviceManagerServiceTest, GetUdidByNetworkId_001, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, GetUdidByNetworkId_001, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = true;
std::string pkgName = "com.ohos.test"; std::string pkgName = "com.ohos.test";
std::string netWorkId = ""; std::string netWorkId = "";
std::string udid = ""; std::string udid = "";
@@ -362,12 +346,11 @@ HWTEST_F(DeviceManagerServiceTest, GetUdidByNetworkId_001, testing::ext::TestSiz
*/ */
HWTEST_F(DeviceManagerServiceTest, GetUdidByNetworkId_002, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, GetUdidByNetworkId_002, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = false;
std::string pkgName = "com.ohos.test"; std::string pkgName = "com.ohos.test";
std::string netWorkId = ""; std::string netWorkId = "";
std::string udid = ""; std::string udid = "";
int ret = DeviceManagerService::GetInstance().GetUdidByNetworkId(pkgName, netWorkId, udid); int ret = DeviceManagerService::GetInstance().GetUdidByNetworkId(pkgName, netWorkId, udid);
EXPECT_EQ(ret, ERR_DM_NOT_INIT); EXPECT_EQ(ret, DM_OK);
} }
/** /**
@@ -379,7 +362,6 @@ HWTEST_F(DeviceManagerServiceTest, GetUdidByNetworkId_002, testing::ext::TestSiz
*/ */
HWTEST_F(DeviceManagerServiceTest, GetUdidByNetworkId_003, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, GetUdidByNetworkId_003, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = true;
std::string pkgName = ""; std::string pkgName = "";
std::string netWorkId = ""; std::string netWorkId = "";
std::string udid = ""; std::string udid = "";
@@ -396,7 +378,6 @@ HWTEST_F(DeviceManagerServiceTest, GetUdidByNetworkId_003, testing::ext::TestSiz
*/ */
HWTEST_F(DeviceManagerServiceTest, GetUuidByNetworkId_001, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, GetUuidByNetworkId_001, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = true;
std::string pkgName = "com.ohos.test"; std::string pkgName = "com.ohos.test";
std::string netWorkId = ""; std::string netWorkId = "";
std::string uuid = ""; std::string uuid = "";
@@ -413,12 +394,11 @@ HWTEST_F(DeviceManagerServiceTest, GetUuidByNetworkId_001, testing::ext::TestSiz
*/ */
HWTEST_F(DeviceManagerServiceTest, GetUuidByNetworkId_002, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, GetUuidByNetworkId_002, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = false;
std::string pkgName = "com.ohos.test"; std::string pkgName = "com.ohos.test";
std::string netWorkId = ""; std::string netWorkId = "";
std::string uuid = ""; std::string uuid = "";
int ret = DeviceManagerService::GetInstance().GetUuidByNetworkId(pkgName, netWorkId, uuid); int ret = DeviceManagerService::GetInstance().GetUuidByNetworkId(pkgName, netWorkId, uuid);
EXPECT_EQ(ret, ERR_DM_NOT_INIT); EXPECT_EQ(ret, DM_OK);
} }
/** /**
@@ -430,7 +410,6 @@ HWTEST_F(DeviceManagerServiceTest, GetUuidByNetworkId_002, testing::ext::TestSiz
*/ */
HWTEST_F(DeviceManagerServiceTest, GetUuidByNetworkId_003, testing::ext::TestSize.Level0) HWTEST_F(DeviceManagerServiceTest, GetUuidByNetworkId_003, testing::ext::TestSize.Level0)
{ {
DeviceManagerService::GetInstance().intFlag_ = true;
std::string pkgName = ""; std::string pkgName = "";
std::string netWorkId = ""; std::string netWorkId = "";
std::string uuid = ""; std::string uuid = "";
@@ -24,7 +24,6 @@
#include "device_manager_service.h" #include "device_manager_service.h"
#include "device_manager_service_listener.h" #include "device_manager_service_listener.h"
#include "dm_auth_manager.h" #include "dm_auth_manager.h"
#include "dm_device_info_manager.h"
#include "dm_device_state_manager.h" #include "dm_device_state_manager.h"
#include "dm_discovery_manager.h" #include "dm_discovery_manager.h"
#include "single_instance.h" #include "single_instance.h"
@@ -13,6 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#include "UTTest_device_profile_adapter.h"
#include "dm_constants.h" #include "dm_constants.h"
#include "dm_device_state_manager.h" #include "dm_device_state_manager.h"
#include "profile_adapter.h" #include "profile_adapter.h"
@@ -20,7 +22,7 @@
#include "profile_connector.h" #include "profile_connector.h"
#include "device_profile_adapter.h" #include "device_profile_adapter.h"
#include "distributed_device_profile_client.h" #include "distributed_device_profile_client.h"
#include "UTTest_device_profile_adapter.h" #include "device_manager_service_listener.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
@@ -46,7 +48,7 @@ std::shared_ptr<DmDeviceStateManager> deviceStateMgr = std::make_shared<DmDevice
hiChainConnector); hiChainConnector);
/** /**
* @tc.name: RegisterProfileListener_001 * @tc.name: RegisterProfileListener_001
* @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new * @tc.desc: Returns a new pointer to the constructor
* to construct an environment where the device has been discovered, and stop discovering * to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY * the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC * @tc.type: FUNC
@@ -65,7 +67,7 @@ HWTEST_F(DeviceProfileAdapterTest, RegisterProfileListener_001, testing::ext::Te
/** /**
* @tc.name: UnRegisterProfileListener_001 * @tc.name: UnRegisterProfileListener_001
* @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new * @tc.desc: Returns a new pointer to the constructor
* to construct an environment where the device has been discovered, and stop discovering * to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY * the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC * @tc.type: FUNC
@@ -83,7 +85,7 @@ HWTEST_F(DeviceProfileAdapterTest, UnRegisterProfileListener_001, testing::ext::
/** /**
* @tc.name: OnProfileChanged_001 * @tc.name: OnProfileChanged_001
* @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new * @tc.desc: Returns a new pointer to the constructor
* to construct an environment where the device has been discovered, and stop discovering * to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY * the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC * @tc.type: FUNC
@@ -102,7 +104,7 @@ HWTEST_F(DeviceProfileAdapterTest, OnProfileChanged_001, testing::ext::TestSize.
/** /**
* @tc.name: OnProfileComplete_001 * @tc.name: OnProfileComplete_001
* @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new * @tc.desc: Returns a new pointer to the constructor
* to construct an environment where the device has been discovered, and stop discovering * to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY * the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC * @tc.type: FUNC
+3 -2
View File
@@ -13,14 +13,15 @@
* limitations under the License. * limitations under the License.
*/ */
#include "dm_auth_manager.h" #include "UTTest_dm_auth_manager.h"
#include "nlohmann/json.hpp" #include "nlohmann/json.hpp"
#include "dm_log.h" #include "dm_log.h"
#include "dm_constants.h" #include "dm_constants.h"
#include "dm_auth_manager.h"
#include "auth_message_processor.h" #include "auth_message_processor.h"
#include "UTTest_dm_auth_manager.h" #include "device_manager_service_listener.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
@@ -1,95 +0,0 @@
/*
* 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 "UTTest_dm_device_info_manager.h"
#include "dm_constants.h"
#include "dm_log.h"
namespace OHOS {
namespace DistributedHardware {
void DeviceManagerImplTest::SetUp()
{
}
void DeviceManagerImplTest::TearDown()
{
}
void DeviceManagerImplTest::SetUpTestCase()
{
}
void DeviceManagerImplTest::TearDownTestCase()
{
}
namespace {
std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
std::shared_ptr<DeviceManagerServiceListener> listener_ = std::make_shared<DeviceManagerServiceListener>();
std::shared_ptr<DmDeviceInfoManager> dmDeviceStateManager = std::make_shared<DmDeviceInfoManager>(softbusConnector);
/**
* @tc.name: DmDeviceInfoManager_001
* @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new
* to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC
* @tc.require: AR000GHSJK
*/
HWTEST_F(DeviceManagerImplTest, DmDeviceInfoManager_001, testing::ext::TestSize.Level0)
{
std::shared_ptr<DmDeviceInfoManager> deviceInfoManager = std::make_shared<DmDeviceInfoManager>(softbusConnector);
ASSERT_NE(deviceInfoManager, nullptr);
}
/**
* @tc.name: GetTrustedDeviceList_001
* @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new
* to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC
* @tc.require: AR000GHSJK
*/
HWTEST_F(DeviceManagerImplTest, GetTrustedDeviceList_001, testing::ext::TestSize.Level0)
{
int32_t ret = DM_OK;
std::string pkgName = "";
std::string extra = "";
std::vector<DmDeviceInfo> deviceList;
std::shared_ptr<DmDeviceInfoManager> deviceInfoManager = std::make_shared<DmDeviceInfoManager>(softbusConnector);
ret = deviceInfoManager->GetTrustedDeviceList(pkgName, extra, deviceList);
ASSERT_EQ(ret, DM_OK);
}
/**
* @tc.name: GetLocalDeviceInfo_001
* @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new
* to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC
* @tc.require: AR000GHSJK
*/
HWTEST_F(DeviceManagerImplTest, GetLocalDeviceInfo_001, testing::ext::TestSize.Level0)
{
DmDeviceInfo deviceInfo;
int32_t ret = DM_OK;
std::shared_ptr<DmDeviceInfoManager> deviceInfoManager = std::make_shared<DmDeviceInfoManager>(softbusConnector);
ret = deviceInfoManager->GetLocalDeviceInfo(deviceInfo);
ASSERT_EQ(ret, DM_OK);
}
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -12,6 +12,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "UTTest_dm_device_state_manager.h"
#include <iostream> #include <iostream>
#include "dm_log.h" #include "dm_log.h"
@@ -24,7 +27,7 @@
#include "ipc_notify_device_found_req.h" #include "ipc_notify_device_found_req.h"
#include "ipc_notify_discover_result_req.h" #include "ipc_notify_discover_result_req.h"
#include "hichain_connector.h" #include "hichain_connector.h"
#include "UTTest_dm_device_state_manager.h" #include "device_manager_service_listener.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
@@ -13,6 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#include "UTTest_dm_discovery_manager.h"
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <unistd.h> #include <unistd.h>
@@ -23,7 +25,7 @@
#include "ipc_server_listener.h" #include "ipc_server_listener.h"
#include "device_manager_service_listener.h" #include "device_manager_service_listener.h"
#include "discovery_service.h" #include "discovery_service.h"
#include "UTTest_dm_discovery_manager.h" #include "device_manager_service_listener.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
+3 -1
View File
@@ -13,6 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#include "UTTest_hichain_connector.h"
#include <cstdlib> #include <cstdlib>
#include <ctime> #include <ctime>
#include <functional> #include <functional>
@@ -24,7 +26,7 @@
#include "dm_constants.h" #include "dm_constants.h"
#include "dm_random.h" #include "dm_random.h"
#include "hichain_connector.h" #include "hichain_connector.h"
#include "UTTest_hichain_connector.h" #include "device_manager_service_listener.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
+1 -1
View File
@@ -13,8 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#include "UTTest_ipc_client_manager.h" #include "UTTest_ipc_client_manager.h"
#include "device_manager_notify.h" #include "device_manager_notify.h"
#include "dm_device_info.h" #include "dm_device_info.h"
#include "ipc_client_stub.h" #include "ipc_client_stub.h"
@@ -22,6 +22,7 @@
#include "mock/mock_ipc_client_manager.h" #include "mock/mock_ipc_client_manager.h"
#include "ipc_client_manager.h" #include "ipc_client_manager.h"
#include "device_manager_callback.h" #include "device_manager_callback.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
class IpcClientManagerTest : public testing::Test { class IpcClientManagerTest : public testing::Test {
+3 -2
View File
@@ -14,6 +14,9 @@
*/ */
#include "UTTest_ipc_client_proxy.h" #include "UTTest_ipc_client_proxy.h"
#include <unistd.h>
#include "dm_device_info.h" #include "dm_device_info.h"
#include "ipc_remote_broker.h" #include "ipc_remote_broker.h"
#include "iremote_object.h" #include "iremote_object.h"
@@ -22,8 +25,6 @@
#include "ipc_client_manager.h" #include "ipc_client_manager.h"
#include "dm_constants.h" #include "dm_constants.h"
#include <unistd.h>
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
void IpcClientProxyTest::SetUp() void IpcClientProxyTest::SetUp()
+1
View File
@@ -24,6 +24,7 @@
#include "ipc_client.h" #include "ipc_client.h"
#include "ipc_req.h" #include "ipc_req.h"
#include "ipc_rsp.h" #include "ipc_rsp.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
class IpcClientProxyTest : public testing::Test { class IpcClientProxyTest : public testing::Test {
@@ -14,7 +14,9 @@
*/ */
#include "UTTest_ipc_client_server_proxy.h" #include "UTTest_ipc_client_server_proxy.h"
#include <unistd.h> #include <unistd.h>
#include "dm_constants.h" #include "dm_constants.h"
#include "dm_log.h" #include "dm_log.h"
#include "ipc_cmd_register.h" #include "ipc_cmd_register.h"
@@ -24,7 +26,6 @@
#include "ipc_stop_discovery_req.h" #include "ipc_stop_discovery_req.h"
#include "ipc_start_discovery_req.h" #include "ipc_start_discovery_req.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
void IpcClientServerProxyTest::SetUp() void IpcClientServerProxyTest::SetUp()
@@ -22,6 +22,7 @@
#include "ipc_remote_broker.h" #include "ipc_remote_broker.h"
#include "ipc_client_server_proxy.h" #include "ipc_client_server_proxy.h"
#include "iremote_proxy.h" #include "iremote_proxy.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
class IpcClientServerProxyTest : public testing::Test { class IpcClientServerProxyTest : public testing::Test {
+3 -2
View File
@@ -14,6 +14,9 @@
*/ */
#include "UTTest_ipc_client_stub.h" #include "UTTest_ipc_client_stub.h"
#include <unistd.h>
#include "dm_device_info.h" #include "dm_device_info.h"
#include "ipc_remote_broker.h" #include "ipc_remote_broker.h"
#include "iremote_object.h" #include "iremote_object.h"
@@ -28,8 +31,6 @@
#include "ipc_def.h" #include "ipc_def.h"
#include "dm_constants.h" #include "dm_constants.h"
#include <unistd.h>
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
void IpcClientStubTest::SetUp() void IpcClientStubTest::SetUp()
+1
View File
@@ -20,6 +20,7 @@
#include <refbase.h> #include <refbase.h>
#include "ipc_client_stub.h" #include "ipc_client_stub.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
class IpcClientStubTest : public testing::Test { class IpcClientStubTest : public testing::Test {
@@ -14,7 +14,9 @@
*/ */
#include "UTTest_ipc_cmd_register.h" #include "UTTest_ipc_cmd_register.h"
#include <unistd.h> #include <unistd.h>
#include "ipc_client_manager.h" #include "ipc_client_manager.h"
#include "ipc_register_listener_req.h" #include "ipc_register_listener_req.h"
#include "ipc_get_trustdevice_rsp.h" #include "ipc_get_trustdevice_rsp.h"
+1
View File
@@ -30,6 +30,7 @@
#include "ipc_types.h" #include "ipc_types.h"
#include "ipc_req.h" #include "ipc_req.h"
#include "ipc_rsp.h" #include "ipc_rsp.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
class IpcCmdRegisterTest : public testing::Test { class IpcCmdRegisterTest : public testing::Test {
@@ -14,7 +14,9 @@
*/ */
#include "UTTest_ipc_server_client_proxy.h" #include "UTTest_ipc_server_client_proxy.h"
#include <unistd.h> #include <unistd.h>
#include "dm_device_info.h" #include "dm_device_info.h"
#include "ipc_remote_broker.h" #include "ipc_remote_broker.h"
#include "iremote_object.h" #include "iremote_object.h"
@@ -16,6 +16,7 @@
#include "UTTest_ipc_server_listener.h" #include "UTTest_ipc_server_listener.h"
#include <unistd.h> #include <unistd.h>
#include "dm_device_info.h" #include "dm_device_info.h"
#include "ipc_remote_broker.h" #include "ipc_remote_broker.h"
#include "iremote_object.h" #include "iremote_object.h"
@@ -21,6 +21,7 @@
#include "ipc_client_stub.h" #include "ipc_client_stub.h"
#include "ipc_server_stub.h" #include "ipc_server_stub.h"
#include "ipc_server_listener.h" #include "ipc_server_listener.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
class IpcServerListenerTest : public testing::Test { class IpcServerListenerTest : public testing::Test {
+5 -4
View File
@@ -14,6 +14,11 @@
*/ */
#include "UTTest_ipc_server_stub.h" #include "UTTest_ipc_server_stub.h"
#include <algorithm>
#include <thread>
#include <unistd.h>
#include "dm_device_info.h" #include "dm_device_info.h"
#include "ipc_server_stub.h" #include "ipc_server_stub.h"
#include "device_manager_impl.h" #include "device_manager_impl.h"
@@ -26,10 +31,6 @@
#include "string_ex.h" #include "string_ex.h"
#include "system_ability_definition.h" #include "system_ability_definition.h"
#include <algorithm>
#include <thread>
#include <unistd.h>
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
void IpcServerStubTest::SetUp() void IpcServerStubTest::SetUp()
+1
View File
@@ -21,6 +21,7 @@
#include "ipc_client_stub.h" #include "ipc_client_stub.h"
#include "ipc_server_stub.h" #include "ipc_server_stub.h"
#include "ipc_server_listener.h" #include "ipc_server_listener.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
class IpcServerStubTest : public testing::Test { class IpcServerStubTest : public testing::Test {
@@ -13,9 +13,10 @@
* limitations under the License. * limitations under the License.
*/ */
#include "UTTest_multiple_user_connector.h"
#include "dm_constants.h" #include "dm_constants.h"
#include "multiple_user_connector.h" #include "multiple_user_connector.h"
#include "UTTest_multiple_user_connector.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
@@ -35,7 +36,7 @@ void MultipleUserConnectorTest::TearDownTestCase()
namespace { namespace {
/** /**
* @tc.name: OnDecisionFilterResult_001 * @tc.name: OnDecisionFilterResult_001
* @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new * @tc.desc: Returns a new pointer to the constructor
* to construct an environment where the device has been discovered, and stop discovering * to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY * the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC * @tc.type: FUNC
@@ -50,7 +51,7 @@ HWTEST_F(MultipleUserConnectorTest, GetCurrentAccountUserID_001, testing::ext::T
/** /**
* @tc.name: SetSwitchOldUserId_001 * @tc.name: SetSwitchOldUserId_001
* @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new * @tc.desc: Returns a new pointer to the constructor
* to construct an environment where the device has been discovered, and stop discovering * to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY * the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC * @tc.type: FUNC
@@ -67,7 +68,7 @@ HWTEST_F(MultipleUserConnectorTest, SetSwitchOldUserId_001, testing::ext::TestSi
/** /**
* @tc.name: GetSwitchOldUserId_001 * @tc.name: GetSwitchOldUserId_001
* @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new * @tc.desc: Returns a new pointer to the constructor
* to construct an environment where the device has been discovered, and stop discovering * to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY * the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC * @tc.type: FUNC
+1 -1
View File
@@ -16,12 +16,12 @@
#include "UTTest_pin_auth.h" #include "UTTest_pin_auth.h"
#include <unistd.h> #include <unistd.h>
#include <memory> #include <memory>
#include "dm_constants.h" #include "dm_constants.h"
#include "dm_log.h" #include "dm_log.h"
#include "nlohmann/json.hpp" #include "nlohmann/json.hpp"
#include "device_manager_service_listener.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
+1 -1
View File
@@ -16,7 +16,6 @@
#include "UTTest_pin_auth_ui.h" #include "UTTest_pin_auth_ui.h"
#include <unistd.h> #include <unistd.h>
#include <memory> #include <memory>
#include "dm_ability_manager.h" #include "dm_ability_manager.h"
@@ -24,6 +23,7 @@
#include "dm_log.h" #include "dm_log.h"
#include "nlohmann/json.hpp" #include "nlohmann/json.hpp"
#include "ui_service_mgr_client.h" #include "ui_service_mgr_client.h"
#include "device_manager_service_listener.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
+12 -10
View File
@@ -13,6 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#include "UTTest_profile_connector.h"
#include "dm_constants.h" #include "dm_constants.h"
#include "dm_device_state_manager.h" #include "dm_device_state_manager.h"
#include "profile_adapter.h" #include "profile_adapter.h"
@@ -20,7 +22,7 @@
#include "profile_connector.h" #include "profile_connector.h"
#include "device_profile_adapter.h" #include "device_profile_adapter.h"
#include "distributed_device_profile_client.h" #include "distributed_device_profile_client.h"
#include "UTTest_profile_connector.h" #include "device_manager_service_listener.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
@@ -41,12 +43,12 @@ namespace {
std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>(); std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
std::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>(); std::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
std::shared_ptr<HiChainConnector> hiChainConnector = std::make_shared<HiChainConnector>(); std::shared_ptr<HiChainConnector> hiChainConnector = std::make_shared<HiChainConnector>();
std::shared_ptr<DmDeviceStateManager> deviceStateMgr = std::make_shared<DmDeviceStateManager>(softbusConnector, std::shared_ptr<DmDeviceStateManager> deviceStateMgr =
listener, std::make_shared<DmDeviceStateManager>(softbusConnector, listener, hiChainConnector);
hiChainConnector);
/** /**
* @tc.name: OnDecisionFilterResult_001 * @tc.name: OnDecisionFilterResult_001
* @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new * @tc.desc: Returns a new pointer to the constructor
* to construct an environment where the device has been discovered, and stop discovering * to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY * the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC * @tc.type: FUNC
@@ -69,7 +71,7 @@ HWTEST_F(ProfileConnectorTest, RegisterProfileCallback_001, testing::ext::TestSi
/** /**
* @tc.name: OnDecisionFilterResult_001 * @tc.name: OnDecisionFilterResult_001
* @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new * @tc.desc: Returns a new pointer to the constructor
* to construct an environment where the device has been discovered, and stop discovering * to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY * the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC * @tc.type: FUNC
@@ -87,7 +89,7 @@ HWTEST_F(ProfileConnectorTest, UnRegisterProfileCallback_001, testing::ext::Test
/** /**
* @tc.name: OnDecisionFilterResult_001 * @tc.name: OnDecisionFilterResult_001
* @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new * @tc.desc: Returns a new pointer to the constructor
* to construct an environment where the device has been discovered, and stop discovering * to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY * the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC * @tc.type: FUNC
@@ -106,7 +108,7 @@ HWTEST_F(ProfileConnectorTest, SubscribeProfileEvents_001, testing::ext::TestSiz
/** /**
* @tc.name: OnDecisionFilterResult_001 * @tc.name: OnDecisionFilterResult_001
* @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new * @tc.desc: Returns a new pointer to the constructor
* to construct an environment where the device has been discovered, and stop discovering * to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY * the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC * @tc.type: FUNC
@@ -126,7 +128,7 @@ HWTEST_F(ProfileConnectorTest, UnSubscribeProfileEvents_001, testing::ext::TestS
/** /**
* @tc.name: OnDecisionFilterResult_002 * @tc.name: OnDecisionFilterResult_002
* @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new * @tc.desc: Returns a new pointer to the constructor
* to construct an environment where the device has been discovered, and stop discovering * to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY * the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC * @tc.type: FUNC
@@ -143,7 +145,7 @@ HWTEST_F(ProfileConnectorTest, UnSubscribeProfileEvents_002, testing::ext::TestS
/** /**
* @tc.name: OnDecisionFilterResult_001 * @tc.name: OnDecisionFilterResult_001
* @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new * @tc.desc: Returns a new pointer to the constructor
* to construct an environment where the device has been discovered, and stop discovering * to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY * the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC * @tc.type: FUNC
+14 -38
View File
@@ -16,7 +16,6 @@
#include <securec.h> #include <securec.h>
#include <unistd.h> #include <unistd.h>
#include <cstdlib> #include <cstdlib>
#include <string> #include <string>
#include <thread> #include <thread>
@@ -31,7 +30,6 @@
#include "ipc_notify_discover_result_req.h" #include "ipc_notify_discover_result_req.h"
#include "ipc_notify_verify_auth_result_req.h" #include "ipc_notify_verify_auth_result_req.h"
#include "parameter.h" #include "parameter.h"
#include "softbus_connector.h"
#include "system_ability_definition.h" #include "system_ability_definition.h"
namespace OHOS { namespace OHOS {
@@ -53,6 +51,7 @@ namespace {
std::shared_ptr<HiChainConnector> hiChainConnector = std::make_shared<HiChainConnector>(); std::shared_ptr<HiChainConnector> hiChainConnector = std::make_shared<HiChainConnector>();
std::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>(); std::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>(); std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
std::shared_ptr<SoftbusListener> softbusListener = std::make_shared<SoftbusListener>();
std::shared_ptr<DmDeviceStateManager> deviceStateMgr = std::shared_ptr<DmDeviceStateManager> deviceStateMgr =
std::make_shared<DmDeviceStateManager>(softbusConnector, listener, hiChainConnector); std::make_shared<DmDeviceStateManager>(softbusConnector, listener, hiChainConnector);
std::shared_ptr<DmDiscoveryManager> discoveryMgr = std::make_shared<DmDiscoveryManager>(softbusConnector, listener); std::shared_ptr<DmDiscoveryManager> discoveryMgr = std::make_shared<DmDiscoveryManager>(softbusConnector, listener);
@@ -68,7 +67,7 @@ HWTEST_F(SoftbusConnectorTest, DeviceOnLine_001, testing::ext::TestSize.Level0)
DmDeviceInfo info; DmDeviceInfo info;
strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123");
deviceStateMgr->RegisterSoftbusStateCallback(); deviceStateMgr->RegisterSoftbusStateCallback();
DeviceOnLine(SoftbusConnector::stateCallbackMap_, info); DeviceOnLine(info);
bool ret = false; bool ret = false;
if (listener->ipcServerListener_.req_ != nullptr) { if (listener->ipcServerListener_.req_ != nullptr) {
ret = true; ret = true;
@@ -89,7 +88,7 @@ HWTEST_F(SoftbusConnectorTest, DeviceOnLine_002, testing::ext::TestSize.Level0)
std::string pkgName = "123"; std::string pkgName = "123";
DmDeviceInfo info; DmDeviceInfo info;
strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123");
DeviceOnLine(SoftbusConnector::stateCallbackMap_, info); DeviceOnLine(info);
bool ret = false; bool ret = false;
if (listener->ipcServerListener_.req_ != nullptr) { if (listener->ipcServerListener_.req_ != nullptr) {
ret = true; ret = true;
@@ -111,7 +110,7 @@ HWTEST_F(SoftbusConnectorTest, DeviceOffLine_001, testing::ext::TestSize.Level0)
DmDeviceInfo info; DmDeviceInfo info;
strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123");
deviceStateMgr->RegisterSoftbusStateCallback(); deviceStateMgr->RegisterSoftbusStateCallback();
DeviceOffLine(SoftbusConnector::stateCallbackMap_, info); DeviceOffLine(info);
bool ret = false; bool ret = false;
if (listener->ipcServerListener_.req_ != nullptr) { if (listener->ipcServerListener_.req_ != nullptr) {
ret = true; ret = true;
@@ -132,7 +131,7 @@ HWTEST_F(SoftbusConnectorTest, DeviceOffLine_002, testing::ext::TestSize.Level0)
std::string pkgName = "123"; std::string pkgName = "123";
DmDeviceInfo info; DmDeviceInfo info;
strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123");
DeviceOffLine(SoftbusConnector::stateCallbackMap_, info); DeviceOffLine(info);
bool ret = false; bool ret = false;
if (listener->ipcServerListener_.req_ != nullptr) { if (listener->ipcServerListener_.req_ != nullptr) {
ret = true; ret = true;
@@ -167,18 +166,6 @@ HWTEST_F(SoftbusConnectorTest, SoftbusConnector_002, testing::ext::TestSize.Leve
EXPECT_EQ(m_SoftbusConnector, nullptr); EXPECT_EQ(m_SoftbusConnector, nullptr);
} }
/**
* @tc.name: Init_001
* @tc.desc: go to the corrort case and return DM_OK
* @tc.type: FUNC
* @tc.require: AR000GHSJK
*/
HWTEST_F(SoftbusConnectorTest, Init_001, testing::ext::TestSize.Level0)
{
int ret = softbusConnector->Init();
EXPECT_EQ(ret, DM_OK);
}
/** /**
* @tc.name: RegisterSoftbusDiscoveryCallback_001 * @tc.name: RegisterSoftbusDiscoveryCallback_001
* @tc.desc: set pkgName = "com.ohos.helloworld";call RegisterSoftbusDiscoveryCallback function to corrort ,return DM_OK * @tc.desc: set pkgName = "com.ohos.helloworld";call RegisterSoftbusDiscoveryCallback function to corrort ,return DM_OK
@@ -252,7 +239,7 @@ HWTEST_F(SoftbusConnectorTest, UnRegisterSoftbusStateCallback_001, testing::ext:
HWTEST_F(SoftbusConnectorTest, GetTrustedDeviceList_001, testing::ext::TestSize.Level0) HWTEST_F(SoftbusConnectorTest, GetTrustedDeviceList_001, testing::ext::TestSize.Level0)
{ {
std::vector<DmDeviceInfo> deviceInfoList; std::vector<DmDeviceInfo> deviceInfoList;
int ret = softbusConnector->GetTrustedDeviceList(deviceInfoList); int ret = softbusListener->GetTrustedDeviceList(deviceInfoList);
EXPECT_EQ(ret, DM_OK); EXPECT_EQ(ret, DM_OK);
} }
@@ -266,7 +253,7 @@ HWTEST_F(SoftbusConnectorTest, GetLocalDeviceInfo_001, testing::ext::TestSize.Le
{ {
std::string pkgName = "com.softbus.test"; std::string pkgName = "com.softbus.test";
DmDeviceInfo deviceInfo; DmDeviceInfo deviceInfo;
int ret = softbusConnector->GetLocalDeviceInfo(deviceInfo); int ret = softbusListener->GetLocalDeviceInfo(deviceInfo);
EXPECT_EQ(ret, DM_OK); EXPECT_EQ(ret, DM_OK);
} }
@@ -507,7 +494,7 @@ HWTEST_F(SoftbusConnectorTest, CovertNodeBasicInfoToDmDevice_001, testing::ext::
{ {
NodeBasicInfo nodeBasicInfo; NodeBasicInfo nodeBasicInfo;
DmDeviceInfo dmDeviceInfo; DmDeviceInfo dmDeviceInfo;
int ret = softbusConnector->CovertNodeBasicInfoToDmDevice(nodeBasicInfo, dmDeviceInfo); int ret = softbusListener->CovertNodeBasicInfoToDmDevice(nodeBasicInfo, dmDeviceInfo);
EXPECT_EQ(ret, DM_OK); EXPECT_EQ(ret, DM_OK);
} }
@@ -549,7 +536,7 @@ HWTEST_F(SoftbusConnectorTest, OnSoftBusDeviceOnline_001, testing::ext::TestSize
std::string deviceId = "123456"; std::string deviceId = "123456";
SoftbusConnector::discoveryDeviceInfoMap_[deviceId]; SoftbusConnector::discoveryDeviceInfoMap_[deviceId];
NodeBasicInfo *info = nullptr; NodeBasicInfo *info = nullptr;
softbusConnector->OnSoftBusDeviceOnline(info); softbusListener->OnSoftBusDeviceOnline(info);
bool ret = false; bool ret = false;
if (listener->ipcServerListener_.req_ != nullptr) { if (listener->ipcServerListener_.req_ != nullptr) {
listener->ipcServerListener_.req_ = nullptr; listener->ipcServerListener_.req_ = nullptr;
@@ -575,7 +562,7 @@ HWTEST_F(SoftbusConnectorTest, OnSoftBusDeviceOnline_002, testing::ext::TestSize
std::string pkgName = "com.ohos.helloworld"; std::string pkgName = "com.ohos.helloworld";
softbusConnector->RegisterSoftbusStateCallback( softbusConnector->RegisterSoftbusStateCallback(
pkgName, std::shared_ptr<ISoftbusStateCallback>(deviceStateMgr)); pkgName, std::shared_ptr<ISoftbusStateCallback>(deviceStateMgr));
softbusConnector->OnSoftBusDeviceOnline(&info); softbusListener->OnSoftBusDeviceOnline(&info);
sleep(1); sleep(1);
bool ret = false; bool ret = false;
if (listener->ipcServerListener_.req_ != nullptr) { if (listener->ipcServerListener_.req_ != nullptr) {
@@ -602,7 +589,7 @@ HWTEST_F(SoftbusConnectorTest, OnSoftBusDeviceOnline_003, testing::ext::TestSize
}; };
std::string oldName = DM_PKG_NAME; std::string oldName = DM_PKG_NAME;
std::string DM_PKG_NAME = "com.ohos.test"; std::string DM_PKG_NAME = "com.ohos.test";
softbusConnector->OnSoftBusDeviceOnline(&info); softbusListener->OnSoftBusDeviceOnline(&info);
bool ret = false; bool ret = false;
if (listener->ipcServerListener_.req_ != nullptr) { if (listener->ipcServerListener_.req_ != nullptr) {
listener->ipcServerListener_.req_ = nullptr; listener->ipcServerListener_.req_ = nullptr;
@@ -621,7 +608,7 @@ HWTEST_F(SoftbusConnectorTest, OnSoftBusDeviceOnline_003, testing::ext::TestSize
HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceOffline_001, testing::ext::TestSize.Level0) HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceOffline_001, testing::ext::TestSize.Level0)
{ {
NodeBasicInfo *info = nullptr; NodeBasicInfo *info = nullptr;
softbusConnector->OnSoftbusDeviceOffline(info); softbusListener->OnSoftbusDeviceOffline(info);
bool ret = false; bool ret = false;
if (listener->ipcServerListener_.req_ != nullptr) { if (listener->ipcServerListener_.req_ != nullptr) {
ret = true; ret = true;
@@ -645,7 +632,7 @@ HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceOffline_002, testing::ext::TestSiz
std::string pkgName = "com.ohos.helloworld"; std::string pkgName = "com.ohos.helloworld";
softbusConnector->RegisterSoftbusStateCallback( softbusConnector->RegisterSoftbusStateCallback(
pkgName, std::shared_ptr<ISoftbusStateCallback>(deviceStateMgr)); pkgName, std::shared_ptr<ISoftbusStateCallback>(deviceStateMgr));
softbusConnector->OnSoftbusDeviceOffline(&info); softbusListener->OnSoftbusDeviceOffline(&info);
sleep(1); sleep(1);
bool ret = false; bool ret = false;
if (listener->ipcServerListener_.req_ != nullptr) { if (listener->ipcServerListener_.req_ != nullptr) {
@@ -718,17 +705,6 @@ HWTEST_F(SoftbusConnectorTest, OnSoftbusDiscoverySuccess_001, testing::ext::Test
EXPECT_EQ(ret, true); EXPECT_EQ(ret, true);
softbusConnector->UnRegisterSoftbusDiscoveryCallback(pkgName); softbusConnector->UnRegisterSoftbusDiscoveryCallback(pkgName);
} }
/**
* @tc.name: OnParameterChgCallback_001
* @tc.desc: set some corrort para and return DM_OK
* @tc.type: FUNC
* @tc.require: AR000GHSJK
*/
HWTEST_F(SoftbusConnectorTest, OnParameterChgCallback_001, testing::ext::TestSize.Level0)
{
EXPECT_EQ(DM_OK, DM_OK);
}
} // namespace } // namespace
} // namespace DistributedHardware } // namespace DistributedHardware
} // namespace OHOS } // namespace OHOS-
+1 -1
View File
@@ -17,7 +17,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <refbase.h> #include <refbase.h>
#include <map> #include <map>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
@@ -32,6 +31,7 @@
#include "dm_subscribe_info.h" #include "dm_subscribe_info.h"
#include "softbus_bus_center.h" #include "softbus_bus_center.h"
#include "softbus_connector.h" #include "softbus_connector.h"
#include "softbus_listener.h"
#include "softbus_discovery_callback.h" #include "softbus_discovery_callback.h"
#include "softbus_session.h" #include "softbus_session.h"
#include "softbus_state_callback.h" #include "softbus_state_callback.h"
+86
View File
@@ -0,0 +1,86 @@
/*
* 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 "UTTest_softbus_listener.h"
#include "dm_constants.h"
#include "dm_log.h"
#include "softbus_listener.h"
namespace OHOS {
namespace DistributedHardware {
void SoftbusListenerTest::SetUp()
{
}
void SoftbusListenerTest::TearDown()
{
}
void SoftbusListenerTest::SetUpTestCase()
{
}
void SoftbusListenerTest::TearDownTestCase()
{
}
namespace {
std::shared_ptr<SoftbusListener> softbusListener = std::make_shared<SoftbusListener>();
/**
* @tc.name: Init_001
* @tc.desc: go to the corrort case and return DM_OK
* @tc.type: FUNC
* @tc.require: AR000GHSJK
*/
HWTEST_F(SoftbusListenerTest, Init_001, testing::ext::TestSize.Level0)
{
int ret = softbusListener->Init();
EXPECT_EQ(ret, DM_OK);
}
/**
* @tc.name: GetTrustedDeviceList_001
* @tc.desc: Returns a new pointer to the constructor
* to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC
* @tc.require: AR000GHSJK
*/
HWTEST_F(SoftbusListenerTest, GetTrustedDeviceList_001, testing::ext::TestSize.Level0)
{
std::vector<DmDeviceInfo> deviceList;
int32_t ret = softbusListener->GetTrustedDeviceList(deviceList);
ASSERT_EQ(ret, DM_OK);
}
/**
* @tc.name: GetLocalDeviceInfo_001
* @tc.desc: Returns a new pointer to the constructor
* to construct an environment where the device has been discovered, and stop discovering
* the device. Its return value is ERR_DM_INPUT_PARAMETER_EMPTY
* @tc.type: FUNC
* @tc.require: AR000GHSJK
*/
HWTEST_F(SoftbusListenerTest, GetLocalDeviceInfo_001, testing::ext::TestSize.Level0)
{
DmDeviceInfo deviceInfo;
int32_t ret = softbusListener->GetLocalDeviceInfo(deviceInfo);
ASSERT_EQ(ret, DM_OK);
}
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -12,8 +12,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#ifndef OHOS_UTTEST_DM_DEVICEINFO_MANAGER_H #ifndef OHOS_UTTEST_DM_SOFTBUS_LISTENER_H
#define OHOS_UTTEST_DM_DEVICEINFO_MANAGER_H #define OHOS_UTTEST_DM_SOFTBUS_LISTENER_H
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <refbase.h> #include <refbase.h>
@@ -24,13 +24,12 @@
#include "device_manager_service_listener.h" #include "device_manager_service_listener.h"
#include "dm_adapter_manager.h" #include "dm_adapter_manager.h"
#include "dm_device_info.h" #include "dm_device_info.h"
#include "dm_device_info_manager.h"
#include "softbus_connector.h" #include "softbus_connector.h"
#include "softbus_session_callback.h" #include "softbus_session_callback.h"
namespace OHOS { namespace OHOS {
namespace DistributedHardware { namespace DistributedHardware {
class DeviceManagerImplTest : public testing::Test { class SoftbusListenerTest : public testing::Test {
public: public:
static void SetUpTestCase(); static void SetUpTestCase();
static void TearDownTestCase(); static void TearDownTestCase();