From ee3ef1d6a6bc2f70eb6fd27cfa7c92fc05c9577f Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Mon, 25 Jul 2022 18:07:19 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9ut=E5=92=8Ccodecheck=20Si?= =?UTF-8?q?gned-off-by:=20wangyb0625=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device_discovery_fuzzer.cpp | 3 +- .../UTTest_device_manager_service.cpp | 42 ------------------- test/unittest/UTTest_softbus_connector.cpp | 27 ------------ test/unittest/UTTest_softbus_listener.cpp | 30 ------------- 4 files changed, 2 insertions(+), 100 deletions(-) diff --git a/test/fuzztest/devicediscovery_fuzzer/device_discovery_fuzzer.cpp b/test/fuzztest/devicediscovery_fuzzer/device_discovery_fuzzer.cpp index 0551bde0f..d8d3721a5 100644 --- a/test/fuzztest/devicediscovery_fuzzer/device_discovery_fuzzer.cpp +++ b/test/fuzztest/devicediscovery_fuzzer/device_discovery_fuzzer.cpp @@ -47,7 +47,8 @@ void DeviceDiscoveryFuzzTest(const uint8_t* data, size_t size) subInfo.freq = *(reinterpret_cast(data)); subInfo.isSameAccount = *(reinterpret_cast(data)); subInfo.isWakeRemote = *(reinterpret_cast(data)); - strncpy_s(subInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, (char*)data, DM_MAX_DEVICE_CAPABILITY_LEN); + strncpy_s(std::string(subInfo.capability), DM_MAX_DEVICE_CAPABILITY_LEN, std::string((char*)data), + DM_MAX_DEVICE_CAPABILITY_LEN); std::string extra(reinterpret_cast(data), size); int16_t subscribeId = *(reinterpret_cast(data)); diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index d3d40c424..1e97a25b9 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -128,48 +128,6 @@ HWTEST_F(DeviceManagerServiceTest, StopDeviceDiscovery_002, testing::ext::TestSi EXPECT_EQ(ret, ERR_DM_INPUT_PARAMETER_EMPTY); } -/** - * @tc.name: GetLocalDeviceInfo_001 - * @tc.desc: Set the flag bit of GetLocalDeviceInfo to intFlag_ to false; The return value is ERR_DM_NOT_INIT - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DeviceManagerServiceTest, GetLocalDeviceInfo_001, testing::ext::TestSize.Level0) -{ - DmDeviceInfo info; - int ret = DeviceManagerService::GetInstance().GetLocalDeviceInfo(info); - EXPECT_EQ(ret, DM_OK); -} - -/** - * @tc.name:GetLocalDeviceInfo_002 - * @tc.desc: Initialize the GetLocalDeviceInfo function with the return value DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DeviceManagerServiceTest, GetLocalDeviceInfo_002, testing::ext::TestSize.Level0) -{ - DmDeviceInfo info; - int ret = DeviceManagerService::GetInstance().GetLocalDeviceInfo(info); - EXPECT_EQ(ret, DM_OK); -} - -/** - * @tc.name: GetTrustedDeviceList_001 - * @tc.desc: Set the intFlag of GetTrustedDeviceList to false. The return value is ERR_DM_NOT_INIT - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ - -HWTEST_F(DeviceManagerServiceTest, GetTrustedDeviceList_001, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.test"; - std::string extra = "jdddd"; - std::vector deviceList; - int ret = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList); - EXPECT_EQ(ret, DM_OK); -} - /** * @tc.name: GetTrustedDeviceList_002 * @tc.desc:Set the intFlag of GetTrustedDeviceList to true and pkgName = null; Return ERR_DM_INPUT_PARAMETER_EMPTY diff --git a/test/unittest/UTTest_softbus_connector.cpp b/test/unittest/UTTest_softbus_connector.cpp index 0188a30fd..e7f16c256 100644 --- a/test/unittest/UTTest_softbus_connector.cpp +++ b/test/unittest/UTTest_softbus_connector.cpp @@ -230,33 +230,6 @@ HWTEST_F(SoftbusConnectorTest, UnRegisterSoftbusStateCallback_001, testing::ext: EXPECT_EQ(ret, DM_OK); } -/** - * @tc.name: GetTrustedDeviceList_001 - * @tc.desc: create GetAllNodeDeviceInfo not equal 0, and return DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(SoftbusConnectorTest, GetTrustedDeviceList_001, testing::ext::TestSize.Level0) -{ - std::vector deviceInfoList; - int ret = softbusListener->GetTrustedDeviceList(deviceInfoList); - EXPECT_EQ(ret, DM_OK); -} - -/** - * @tc.name: GetLocalDeviceInfo_001 - * @tc.desc: set pkgName to com.softbus.test,define deviceInfo,and return DM_OK. - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(SoftbusConnectorTest, GetLocalDeviceInfo_001, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.softbus.test"; - DmDeviceInfo deviceInfo; - int ret = softbusListener->GetLocalDeviceInfo(deviceInfo); - EXPECT_EQ(ret, DM_OK); -} - /** * @tc.name: StartDiscovery_001 * @tc.desc: get StartDiscovery to wroing master and return ERR_DM_DISCOVERY_FAILED diff --git a/test/unittest/UTTest_softbus_listener.cpp b/test/unittest/UTTest_softbus_listener.cpp index 9f70b1dd8..88a276421 100644 --- a/test/unittest/UTTest_softbus_listener.cpp +++ b/test/unittest/UTTest_softbus_listener.cpp @@ -51,36 +51,6 @@ 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 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 -- Gitee From df8c20fcbfa095c7786632cbcfc9c82bfd6b6081 Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Mon, 25 Jul 2022 20:01:27 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- .../devicediscovery_fuzzer/device_discovery_fuzzer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/fuzztest/devicediscovery_fuzzer/device_discovery_fuzzer.cpp b/test/fuzztest/devicediscovery_fuzzer/device_discovery_fuzzer.cpp index d8d3721a5..a8ad83e5e 100644 --- a/test/fuzztest/devicediscovery_fuzzer/device_discovery_fuzzer.cpp +++ b/test/fuzztest/devicediscovery_fuzzer/device_discovery_fuzzer.cpp @@ -47,8 +47,11 @@ void DeviceDiscoveryFuzzTest(const uint8_t* data, size_t size) subInfo.freq = *(reinterpret_cast(data)); subInfo.isSameAccount = *(reinterpret_cast(data)); subInfo.isWakeRemote = *(reinterpret_cast(data)); - strncpy_s(std::string(subInfo.capability), DM_MAX_DEVICE_CAPABILITY_LEN, std::string((char*)data), + int32_t ret = strncpy_s(subInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, (char*)data, DM_MAX_DEVICE_CAPABILITY_LEN); + if (ret != 0) { + return; + } std::string extra(reinterpret_cast(data), size); int16_t subscribeId = *(reinterpret_cast(data)); -- Gitee From 8f581f7116c2ce9007a834433494e0615f294f5b Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Mon, 25 Jul 2022 20:29:03 +0800 Subject: [PATCH 3/3] 12 Signed-off-by: wangyb0625 --- .../devicediscovery_fuzzer/device_discovery_fuzzer.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/fuzztest/devicediscovery_fuzzer/device_discovery_fuzzer.cpp b/test/fuzztest/devicediscovery_fuzzer/device_discovery_fuzzer.cpp index a8ad83e5e..b9d78f841 100644 --- a/test/fuzztest/devicediscovery_fuzzer/device_discovery_fuzzer.cpp +++ b/test/fuzztest/devicediscovery_fuzzer/device_discovery_fuzzer.cpp @@ -47,9 +47,7 @@ void DeviceDiscoveryFuzzTest(const uint8_t* data, size_t size) subInfo.freq = *(reinterpret_cast(data)); subInfo.isSameAccount = *(reinterpret_cast(data)); subInfo.isWakeRemote = *(reinterpret_cast(data)); - int32_t ret = strncpy_s(subInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, (char*)data, - DM_MAX_DEVICE_CAPABILITY_LEN); - if (ret != 0) { + if (strncpy_s(subInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, (char*)data, DM_MAX_DEVICE_CAPABILITY_LEN) != 0) { return; } std::string extra(reinterpret_cast(data), size); -- Gitee