From 542b8c64e1208d6851d1315169d781b2cd9a5291 Mon Sep 17 00:00:00 2001 From: pwx1285814 Date: Wed, 28 Aug 2024 09:15:02 +0800 Subject: [PATCH] =?UTF-8?q?CleanCode=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: pwx1285814 Change-Id: Id3b8b699266e9b8111bf40ca8a2918141334110f Signed-off-by: pwx1285814 --- bundle.json | 6 +-- .../dscreenmanager_fuzzer.cpp | 1 - .../fuzztest/softbusadapter_fuzzer/BUILD.gn | 5 +-- .../softbusadapter_fuzzer/mock_socket.cpp | 45 ------------------- .../softbusadapter_fuzzer.cpp | 31 +++++++++++++ 5 files changed, 34 insertions(+), 54 deletions(-) delete mode 100644 services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/mock_socket.cpp diff --git a/bundle.json b/bundle.json index ede16417..6369a05f 100644 --- a/bundle.json +++ b/bundle.json @@ -49,9 +49,7 @@ "distributed_hardware_fwk", "libjpeg-turbo" ], - "third_party": [ - "googletest" - ] + "third_party": [] }, "build": { "sub_component": [ @@ -109,4 +107,4 @@ ] } } -} \ No newline at end of file +} diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.cpp b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.cpp index d7380b32..221aeab3 100644 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.cpp +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.cpp @@ -78,7 +78,6 @@ void DScreenCallbackOnRegResultFuzzTest(const uint8_t* data, size_t size) return; } - std::string reqId(reinterpret_cast(data), size); std::string screenId(reinterpret_cast(data), size); int32_t status = *(reinterpret_cast(data)); std::string dataStr(reinterpret_cast(data), size); diff --git a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/BUILD.gn index c1c6d526..1f4510b7 100644 --- a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/BUILD.gn +++ b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/BUILD.gn @@ -25,10 +25,7 @@ ohos_fuzztest("SoftbusAdapterFuzzTest") { configs = [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] - sources = [ - "mock_socket.cpp", - "softbusadapter_fuzzer.cpp", - ] + sources = [ "softbusadapter_fuzzer.cpp" ] include_dirs = [ "${common_path}/include", diff --git a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/mock_socket.cpp b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/mock_socket.cpp deleted file mode 100644 index 8b7de21f..00000000 --- a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/mock_socket.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "socket.h" - -constexpr int32_t DH_SUCCESS = 0; - -int Socket(SocketInfo info) -{ - return DH_SUCCESS; -} - -int Listen(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISocketListener *listener) -{ - return DH_SUCCESS; -} - -int Bind(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISocketListener *listener) -{ - return DH_SUCCESS; -} - -void Shutdown(int32_t socket) {} - -int SendBytes(int32_t socket, const void *data, uint32_t len) -{ - return DH_SUCCESS; -} - -int SendStream(int32_t socket, const StreamData *data, const StreamData *ext, const StreamFrameInfo *param) -{ - return DH_SUCCESS; -} diff --git a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp index 53a500bc..8b998311 100644 --- a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp +++ b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp @@ -19,6 +19,7 @@ #include "dscreen_errcode.h" #include "dscreen_util.h" #include "isoftbus_listener.h" +#include "socket.h" #include "softbus_adapter.h" #include "softbus_bus_center.h" #include "softbus_common.h" @@ -214,3 +215,33 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::DistributedHardware::SoftbusOpenSoftbusSessionFuzzTest(data, size); return 0; } + +extern "C" __attribute__((constructor)) int Socket(SocketInfo info) +{ + return 0; +} + +extern "C" __attribute__((constructor)) int Listen(int32_t socket, const QosTV qos[], uint32_t qosCount, + const ISocketListener *listener) +{ + return 0; +} + +extern "C" __attribute__((constructor)) int Bind(int32_t socket, const QosTV qos[], uint32_t qosCount, + const ISocketListener *listener) +{ + return 0; +} + +extern "C" __attribute__((constructor)) void Shutdown(int32_t socket) {} + +extern "C" __attribute__((constructor)) int SendBytes(int32_t socket, const void *data, uint32_t len) +{ + return 0; +} + +extern "C" __attribute__((constructor)) int SendStream(int32_t socket, const StreamData *data, const StreamData *ext, + const StreamFrameInfo *param) +{ + return 0; +} -- Gitee