From 85eba4b11d2af8ee491338a950abbe49c49d5b8d Mon Sep 17 00:00:00 2001 From: 18734571586 Date: Tue, 25 Oct 2022 10:45:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E8=AF=81=E7=BB=84=E7=BD=91=E5=89=8D?= =?UTF-8?q?=E5=90=8E=E8=AE=BE=E5=A4=87=E5=90=8D=E7=A7=B0=E4=B8=BA=E7=9C=9F?= =?UTF-8?q?=E5=AE=9E=E5=90=8D=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 18734571586 --- adapter/BUILD.gn | 4 - .../include/lnn_settingdata_event_monitor.h | 1 + .../src/.vscode/c_cpp_properties.json | 18 +++ .../bus_center/src/.vscode/launch.json | 24 ++++ .../bus_center/src/.vscode/settings.json | 31 +++++ .../bus_center/src}/bus_center_adapter.c | 12 +- .../bus_center/src}/bus_center_adapter_weak.c | 0 .../src/lnn_settingdata_event_monitor.cpp | 23 +++- .../lnn_settingdata_event_monitor_virtual.cpp | 4 + core/adapter/core_adapter.gni | 28 ++-- .../lnn/net_builder/src/lnn_devicename_info.c | 25 +++- .../adapter/unittest/dsoftbus_other_test.cpp | 71 ---------- tests/core/adapter/bus_center_adapter.cpp | 129 ++++++++++++++++++ 13 files changed, 276 insertions(+), 94 deletions(-) create mode 100644 core/adapter/bus_center/src/.vscode/c_cpp_properties.json create mode 100644 core/adapter/bus_center/src/.vscode/launch.json create mode 100644 core/adapter/bus_center/src/.vscode/settings.json rename {adapter/common/bus_center/platform => core/adapter/bus_center/src}/bus_center_adapter.c (78%) rename {adapter/common/bus_center/platform => core/adapter/bus_center/src}/bus_center_adapter_weak.c (100%) create mode 100644 tests/core/adapter/bus_center_adapter.cpp diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn index a309171d29..7a59e0c88f 100644 --- a/adapter/BUILD.gn +++ b/adapter/BUILD.gn @@ -65,7 +65,6 @@ if (defined(ohos_lite)) { cflags = [ "-Wall" ] } sources = [ - "$softbus_adapter_common/bus_center/platform/bus_center_adapter.c", "$softbus_adapter_common/dfx/softbus_adapter_hisysevent_mini.c", "$softbus_adapter_common/kernel/liteos_m/lnn_ip_utils_adapter.c", "$softbus_adapter_common/kernel/liteos_m/softbus_adapter_file.c", @@ -80,7 +79,6 @@ if (defined(ohos_lite)) { if (board_name == "v200zr") { sources = [] sources = [ - "$softbus_adapter_common/bus_center/platform/bus_center_adapter.c", "$softbus_adapter_common/dfx/softbus_adapter_hisysevent_mini.c", "$softbus_adapter_common/kernel/liteos_m/lnn_ip_utils_adapter.c", "$softbus_adapter_common/kernel/liteos_m/softbus_adapter_mem.c", @@ -119,7 +117,6 @@ if (defined(ohos_lite)) { ] cflags_cc = [ "-fPIC" ] sources = [ - "$softbus_adapter_common/bus_center/platform/bus_center_adapter.c", "$softbus_adapter_common/dfx/softbus_adapter_hisysevent_mini.c", "$softbus_adapter_common/kernel/posix/lnn_ip_utils_adapter.c", "$softbus_adapter_common/kernel/posix/softbus_adapter_file.c", @@ -169,7 +166,6 @@ if (defined(ohos_lite)) { ] sources = [ "$dsoftbus_feature_product_config_path/spec_config/softbus_config_adapter.c", - "$softbus_adapter_common/bus_center/platform/bus_center_adapter.c", "$softbus_adapter_common/dfx/softbus_adapter_hisysevent.cpp", "$softbus_adapter_common/kernel/posix/lnn_ip_utils_adapter.c", "$softbus_adapter_common/kernel/posix/softbus_adapter_file.c", diff --git a/core/adapter/bus_center/include/lnn_settingdata_event_monitor.h b/core/adapter/bus_center/include/lnn_settingdata_event_monitor.h index 9b97fcce37..220748996a 100644 --- a/core/adapter/bus_center/include/lnn_settingdata_event_monitor.h +++ b/core/adapter/bus_center/include/lnn_settingdata_event_monitor.h @@ -26,6 +26,7 @@ typedef void (*LnnDeviceNameHandler)(void); int32_t LnnGetSettingDeviceName(char *deviceName, uint32_t len); int32_t LnnInitGetDeviceName(LnnDeviceNameHandler handler); int32_t LnnInitDeviceNameMonitorImpl(void); +void RegisterNameMonitor(void); #ifdef __cplusplus } diff --git a/core/adapter/bus_center/src/.vscode/c_cpp_properties.json b/core/adapter/bus_center/src/.vscode/c_cpp_properties.json new file mode 100644 index 0000000000..cea4d3f4e0 --- /dev/null +++ b/core/adapter/bus_center/src/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/core/adapter/bus_center/src/.vscode/launch.json b/core/adapter/bus_center/src/.vscode/launch.json new file mode 100644 index 0000000000..7316f54313 --- /dev/null +++ b/core/adapter/bus_center/src/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "y:/home/wxh/dscang/master/ds1025/communication_dsoftbus_1025/core/adapter/bus_center/src", + "program": "y:/home/wxh/dscang/master/ds1025/communication_dsoftbus_1025/core/adapter/bus_center/src/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/core/adapter/bus_center/src/.vscode/settings.json b/core/adapter/bus_center/src/.vscode/settings.json new file mode 100644 index 0000000000..52d4f4b48e --- /dev/null +++ b/core/adapter/bus_center/src/.vscode/settings.json @@ -0,0 +1,31 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ] +} \ No newline at end of file diff --git a/adapter/common/bus_center/platform/bus_center_adapter.c b/core/adapter/bus_center/src/bus_center_adapter.c similarity index 78% rename from adapter/common/bus_center/platform/bus_center_adapter.c rename to core/adapter/bus_center/src/bus_center_adapter.c index 61222d3630..7dbba77875 100644 --- a/adapter/common/bus_center/platform/bus_center_adapter.c +++ b/core/adapter/bus_center/src/bus_center_adapter.c @@ -20,10 +20,12 @@ #include #include "bus_center_adapter.h" +#include "lnn_settingdata_event_monitor.h" #include "parameter.h" #include "softbus_adapter_log.h" #include "softbus_common.h" #include "softbus_errcode.h" +#include "softbus_log.h" #define DEFAULT_DEVICE_NAME "OpenHarmony" @@ -37,8 +39,14 @@ int32_t GetCommonDevInfo(const CommonDeviceKey key, char *value, uint32_t len) const char *devType = NULL; switch (key) { case COMM_DEVICE_KEY_DEVNAME: - if (strncpy_s(value, len, DEFAULT_DEVICE_NAME, strlen(DEFAULT_DEVICE_NAME)) != EOK) { - return SOFTBUS_ERR; + if (LnnGetSettingDeviceName(value, len) == SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "LnnGetSettingDeviceName success"); + return SOFTBUS_OK; + } else { + if (strncpy_s(value, len, DEFAULT_DEVICE_NAME, strlen(DEFAULT_DEVICE_NAME)) != EOK) { + return SOFTBUS_ERR; + } + return SOFTBUS_OK; } break; case COMM_DEVICE_KEY_UDID: diff --git a/adapter/common/bus_center/platform/bus_center_adapter_weak.c b/core/adapter/bus_center/src/bus_center_adapter_weak.c similarity index 100% rename from adapter/common/bus_center/platform/bus_center_adapter_weak.c rename to core/adapter/bus_center/src/bus_center_adapter_weak.c diff --git a/core/adapter/bus_center/src/lnn_settingdata_event_monitor.cpp b/core/adapter/bus_center/src/lnn_settingdata_event_monitor.cpp index 2ab37c411d..7111f5e2d6 100644 --- a/core/adapter/bus_center/src/lnn_settingdata_event_monitor.cpp +++ b/core/adapter/bus_center/src/lnn_settingdata_event_monitor.cpp @@ -29,7 +29,7 @@ #include "softbus_log.h" #include "system_ability_definition.h" -static const int32_t DELAY_LEN = 100000; +static const int32_t DELAY_LEN = 7000; static LnnDeviceNameHandler g_eventHandler = nullptr; namespace OHOS { @@ -62,7 +62,6 @@ static void CreateDataAbilityHelperInstance(void) return; } - auto uri = std::make_shared(SETTINGS_DATA_DEVICE_NAME_URI); sptr saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (saManager == nullptr) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "CreateDataAbilityHelperInstance saManager NULL"); @@ -79,9 +78,6 @@ static void CreateDataAbilityHelperInstance(void) SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "CreateDataAbilityHelperInstance create fail."); return; } - - sptr settingDataObserver = std::make_unique().release(); - g_dataAbilityHelper->RegisterObserver(*uri, settingDataObserver); SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "CreateDataAbilityHelperInstance exit success."); } @@ -126,6 +122,18 @@ static int32_t GetDeviceNameFromDataAbilityHelper(char *deviceName, uint32_t len SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "GetDeviceNameFromDataAbilityHelper, deviceName=%s.", deviceName); return SOFTBUS_OK; } + +static void RegisterNameMonitorHelper(void) +{ + if (g_dataAbilityHelper == nullptr) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "RegisterNameMonitorHelper g_dataAbilityHelper == NULL."); + return; + } + auto uri = std::make_shared(SETTINGS_DATA_DEVICE_NAME_URI); + sptr settingDataObserver = std::make_unique().release(); + g_dataAbilityHelper->RegisterObserver(*uri, settingDataObserver); + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "RegisterNameMonitorHelper success"); +} } } @@ -161,4 +169,9 @@ int32_t LnnInitDeviceNameMonitorImpl(void) SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init DeviceName LnnAsyncCallbackDelayHelper fail"); } return ret; +} + +void RegisterNameMonitor(void) +{ + OHOS::BusCenter::RegisterNameMonitorHelper(); } \ No newline at end of file diff --git a/core/adapter/bus_center/src/lnn_settingdata_event_monitor_virtual.cpp b/core/adapter/bus_center/src/lnn_settingdata_event_monitor_virtual.cpp index b177e62698..65e1e2b824 100644 --- a/core/adapter/bus_center/src/lnn_settingdata_event_monitor_virtual.cpp +++ b/core/adapter/bus_center/src/lnn_settingdata_event_monitor_virtual.cpp @@ -54,4 +54,8 @@ bool LnnIsDefaultOhosAccount(void) int32_t LnnInitDeviceNameMonitorImpl(void) { return SOFTBUS_OK; +} + +void RegisterNameMonitor(void) +{ } \ No newline at end of file diff --git a/core/adapter/core_adapter.gni b/core/adapter/core_adapter.gni index 7994ef9a7a..0c04f8409a 100644 --- a/core/adapter/core_adapter.gni +++ b/core/adapter/core_adapter.gni @@ -26,30 +26,40 @@ declare_args() { dsoftbus_get_devicename = true } +bus_center_core_adapter_src = + [ "$dsoftbus_root_path/core/adapter/bus_center/src/bus_center_adapter.c" ] +bus_center_core_adapter_inc = [ + "$dsoftbus_root_path/adapter/common/include", + "//base/startup/init/interfaces/innerkits/include/syspara", +] +bus_center_core_adapter_deps = + [ "//base/startup/init/interfaces/innerkits:libbegetutil" ] + if (defined(ohos_lite)) { - bus_center_core_adapter_src = [ "$dsoftbus_root_path/core/adapter/bus_center/src/lnn_settingdata_event_monitor_virtual.cpp" ] + bus_center_core_adapter_src += [ "$dsoftbus_root_path/core/adapter/bus_center/src/lnn_settingdata_event_monitor_virtual.cpp" ] - bus_center_core_adapter_inc = [ + bus_center_core_adapter_inc += [ "$dsoftbus_root_path/core/adapter/bus_center/include", "$dsoftbus_root_path/core/bus_center/utils/include", ] - bus_center_core_adapter_deps = [] + bus_center_core_adapter_deps += [] } else { if (dsoftbus_get_devicename == false) { - bus_center_core_adapter_src = [ "$dsoftbus_root_path/core/adapter/bus_center/src/lnn_settingdata_event_monitor_virtual.cpp" ] + bus_center_core_adapter_src += [ "$dsoftbus_root_path/core/adapter/bus_center/src/lnn_settingdata_event_monitor_virtual.cpp" ] - bus_center_core_adapter_inc = + bus_center_core_adapter_inc += [ "$dsoftbus_root_path/core/adapter/bus_center/include" ] - bus_center_core_adapter_deps = [] + bus_center_core_adapter_deps += [] } else { - bus_center_core_adapter_src = [ + bus_center_core_adapter_src += [ "$dsoftbus_root_path/core/adapter/bus_center/src/lnn_settingdata_event_monitor.cpp", "$dsoftbus_root_path/core/adapter/bus_center/src/lnn_ohos_account.cpp", + "$dsoftbus_root_path/core/adapter/bus_center/src/bus_center_adapter.c", ] - bus_center_core_adapter_inc = [ + bus_center_core_adapter_inc += [ "$dsoftbus_root_path/adapter/common/bus_center/include", "$dsoftbus_root_path/adapter/common/include", "$dsoftbus_root_path/core/adapter/bus_center/include", @@ -58,7 +68,7 @@ if (defined(ohos_lite)) { "//base/account/os_account/interfaces/innerkits/ohosaccount/native/include/", ] - bus_center_core_adapter_deps = [ + bus_center_core_adapter_deps += [ "${ability_base_path}:want", "${ability_base_path}:zuri", "${ability_runtime_inner_api_path}/dataobs_manager:dataobs_manager", diff --git a/core/bus_center/lnn/net_builder/src/lnn_devicename_info.c b/core/bus_center/lnn/net_builder/src/lnn_devicename_info.c index e2cccc28a1..a4ab41581d 100644 --- a/core/bus_center/lnn/net_builder/src/lnn_devicename_info.c +++ b/core/bus_center/lnn/net_builder/src/lnn_devicename_info.c @@ -31,6 +31,11 @@ #include "softbus_errcode.h" #include "softbus_wifi_api_adapter.h" #include "softbus_json_utils.h" +#include "message_handler.h" + +#define DELAY_LEN 1000 +#define MAX_TRY 10 +static int32_t g_tryGetDevnameNums = 0; int32_t LnnSyncDeviceName(const char *networkId) { @@ -101,17 +106,31 @@ static void HandlerGetDeviceName(void) } } -static void UpdataLocalFromSetting(void) +static void UpdataLocalFromSetting(void *p) { char name[DEVICE_NAME_BUF_LEN] = {0}; SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "UpdataLocalFromSetting enter"); if (LnnGetSettingDeviceName(name, DEVICE_NAME_BUF_LEN) != SOFTBUS_OK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HandlerGetDeviceName fail"); + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "UpdataLocalFromSetting fail"); + g_tryGetDevnameNums++; + if (g_tryGetDevnameNums < MAX_TRY) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "g_tryGetDevnameNums: %d", g_tryGetDevnameNums); + SoftBusLooper *looper = GetLooper(LOOP_TYPE_DEFAULT); + if (looper == NULL) { + return; + } + int ret = LnnAsyncCallbackDelayHelper(looper, UpdataLocalFromSetting, NULL, DELAY_LEN); + if (ret != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init UpdataLocalFromSetting fail"); + } + } return; } if (LnnSetLocalStrInfo(STRING_KEY_DEV_NAME, name) != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "UpdataLocalFromSetting set device name fail"); } + RegisterNameMonitor(); + return; } void UpdateDeviceNameFromSetting(void) @@ -122,7 +141,7 @@ void UpdateDeviceNameFromSetting(void) void UpdateDeviceName(void *p) { UpdateDeviceNameFromSetting(); - UpdataLocalFromSetting(); + UpdataLocalFromSetting(p); } int32_t LnnInitDevicename(void) diff --git a/tests/adapter/unittest/dsoftbus_other_test.cpp b/tests/adapter/unittest/dsoftbus_other_test.cpp index 7da3c80560..cd77e74249 100644 --- a/tests/adapter/unittest/dsoftbus_other_test.cpp +++ b/tests/adapter/unittest/dsoftbus_other_test.cpp @@ -60,78 +60,7 @@ void DsoftbusOtherTest::TearDown(void) * @tc.type: FUNC * @tc.require: 1 */ -HWTEST_F(DsoftbusOtherTest, GetCommonDevInfo001, TestSize.Level0) -{ - char value[] = "abcdefg"; - int32_t len = 10; - int32_t ret = GetCommonDevInfo(COMM_DEVICE_KEY_DEVTYPE, value, len); - EXPECT_EQ(SOFTBUS_OK, ret); - - ret = GetCommonDevInfo(COMM_DEVICE_KEY_BT_MAC, value, len); - EXPECT_EQ(SOFTBUS_OK, ret); - - ret = GetCommonDevInfo(COMM_DEVICE_KEY_BUTT, value, len); - EXPECT_EQ(SOFTBUS_OK, ret); -} - -/* -* @tc.name: GetCommonDevInfoTest002 -* @tc.desc: value is nullptr -* @tc.type: FUNC -* @tc.require: 1 -*/ -HWTEST_F(DsoftbusOtherTest, GetCommonDevInfo002, TestSize.Level0) -{ - int32_t len = 10; - int32_t ret = GetCommonDevInfo(COMM_DEVICE_KEY_DEVNAME, NULL, len); - EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); - - ret = GetCommonDevInfo(COMM_DEVICE_KEY_UDID, NULL, len); - EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); - - ret = GetCommonDevInfo(COMM_DEVICE_KEY_DEVTYPE, NULL, len); - EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); - - ret = GetCommonDevInfo(COMM_DEVICE_KEY_BT_MAC, NULL, len); - EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); - - ret = GetCommonDevInfo(COMM_DEVICE_KEY_BUTT, NULL, len); - EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); -} - -/* -* @tc.name: GetCommonDevInfoTest003 -* @tc.desc: len is illegal -* @tc.type: FUNC -* @tc.require: 1 -*/ -HWTEST_F(DsoftbusOtherTest, GetCommonDevInfo003, TestSize.Level0) -{ - char value[] = "abcdefg"; - int32_t len = 0; - int32_t ret = GetCommonDevInfo(COMM_DEVICE_KEY_DEVNAME, value, len); - EXPECT_EQ(SOFTBUS_ERR, ret); - ret = GetCommonDevInfo(COMM_DEVICE_KEY_UDID, value, len); - EXPECT_EQ(SOFTBUS_ERR, ret); -} - -/* -* @tc.name: GetCommonDevInfoTest004 -* @tc.desc: value is illegal -* @tc.type: FUNC -* @tc.require: 1 -*/ -HWTEST_F(DsoftbusOtherTest, GetCommonDevInfo004, TestSize.Level0) -{ - char value[] = "abcdefg"; - int32_t len = 10; - int32_t ret = GetCommonDevInfo(COMM_DEVICE_KEY_DEVNAME, value, len); - EXPECT_EQ(SOFTBUS_ERR, ret); - - ret = GetCommonDevInfo(COMM_DEVICE_KEY_UDID, value, len); - EXPECT_EQ(SOFTBUS_ERR, ret); -} /* * @tc.name: GetNetworkIpByIfName001 diff --git a/tests/core/adapter/bus_center_adapter.cpp b/tests/core/adapter/bus_center_adapter.cpp new file mode 100644 index 0000000000..cc69d5a44d --- /dev/null +++ b/tests/core/adapter/bus_center_adapter.cpp @@ -0,0 +1,129 @@ +/* + * 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 +#include + +#include "gtest/gtest.h" +#include "lnn_ip_utils_adapter.h" +#include "bus_center_adapter.h" +#include "softbus_adapter_file.h" +#include "softbus_adapter_mem.h" +#include "softbus_errcode.h" +#include "softbus_adapter_log.h" + +using namespace std; +using namespace testing::ext; + +namespace OHOS { +const char *g_FileName = "example.txt"; + +class DsoftbusOtherTest : public testing::Test { +protected: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; +void DsoftbusOtherTest::SetUpTestCase(void) +{ +} +void DsoftbusOtherTest::TearDownTestCase(void) +{ + int32_t ret = remove(g_FileName); + if (ret == 0) { + return; + } +} +void DsoftbusOtherTest::SetUp(void) +{ +} +void DsoftbusOtherTest::TearDown(void) +{ +} + +HWTEST_F(DsoftbusOtherTest, GetCommonDevInfo001, TestSize.Level0) +{ + char value[] = "abcdefg"; + int32_t len = 10; + int32_t ret = GetCommonDevInfo(COMM_DEVICE_KEY_DEVTYPE, value, len); + EXPECT_EQ(SOFTBUS_OK, ret); + + ret = GetCommonDevInfo(COMM_DEVICE_KEY_BT_MAC, value, len); + EXPECT_EQ(SOFTBUS_OK, ret); + + ret = GetCommonDevInfo(COMM_DEVICE_KEY_BUTT, value, len); + EXPECT_EQ(SOFTBUS_OK, ret); +} + +/* +* @tc.name: GetCommonDevInfoTest002 +* @tc.desc: value is nullptr +* @tc.type: FUNC +* @tc.require: 1 +*/ +HWTEST_F(DsoftbusOtherTest, GetCommonDevInfo002, TestSize.Level0) +{ + int32_t len = 10; + int32_t ret = GetCommonDevInfo(COMM_DEVICE_KEY_DEVNAME, NULL, len); + EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); + + ret = GetCommonDevInfo(COMM_DEVICE_KEY_UDID, NULL, len); + EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); + + ret = GetCommonDevInfo(COMM_DEVICE_KEY_DEVTYPE, NULL, len); + EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); + + ret = GetCommonDevInfo(COMM_DEVICE_KEY_BT_MAC, NULL, len); + EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); + + ret = GetCommonDevInfo(COMM_DEVICE_KEY_BUTT, NULL, len); + EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); +} + +/* +* @tc.name: GetCommonDevInfoTest003 +* @tc.desc: len is illegal +* @tc.type: FUNC +* @tc.require: 1 +*/ +HWTEST_F(DsoftbusOtherTest, GetCommonDevInfo003, TestSize.Level0) +{ + char value[] = "abcdefg"; + int32_t len = 0; + int32_t ret = GetCommonDevInfo(COMM_DEVICE_KEY_DEVNAME, value, len); + EXPECT_EQ(SOFTBUS_ERR, ret); + + ret = GetCommonDevInfo(COMM_DEVICE_KEY_UDID, value, len); + EXPECT_EQ(SOFTBUS_ERR, ret); +} + +/* +* @tc.name: GetCommonDevInfoTest004 +* @tc.desc: value is illegal +* @tc.type: FUNC +* @tc.require: 1 +*/ +HWTEST_F(DsoftbusOtherTest, GetCommonDevInfo004, TestSize.Level0) +{ + char value[] = "abcdefg"; + int32_t len = 10; + int32_t ret = GetCommonDevInfo(COMM_DEVICE_KEY_DEVNAME, value, len); + EXPECT_EQ(SOFTBUS_ERR, ret); + + ret = GetCommonDevInfo(COMM_DEVICE_KEY_UDID, value, len); + EXPECT_EQ(SOFTBUS_ERR, ret); +} +} \ No newline at end of file -- Gitee