From d91ed7477b13e501fdd110d39094c81a18caf6da Mon Sep 17 00:00:00 2001 From: w30042960 Date: Tue, 26 Mar 2024 16:56:53 +0800 Subject: [PATCH] modify fuzz Signed-off-by: w30042960 --- .../BUILD.gn | 6 +-- .../BUILD.gn | 2 +- ...dlerregisterdistributedhardware_fuzzer.cpp | 4 +- .../BUILD.gn | 2 +- ...erunregisterdistributedhardware_fuzzer.cpp | 4 +- .../test/include/mock_component_disable.h | 48 +++++++++++++++++++ .../test/include/mock_component_enable.h | 48 +++++++++++++++++++ 7 files changed, 104 insertions(+), 10 deletions(-) create mode 100644 interfaces/inner_kits/native_cpp/test/include/mock_component_disable.h create mode 100644 interfaces/inner_kits/native_cpp/test/include/mock_component_enable.h diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/BUILD.gn index 7223f143..c3bda4c4 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/BUILD.gn @@ -46,10 +46,8 @@ ohos_fuzztest("SinkHandlerRegisterPrivacyResourcesFuzzTest") { "${fwk_services_path}/distributedhardwarefwkservice/include/componentmanager", ] - deps = [ - "${fwk_services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", - "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", - ] + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] external_deps = [ "c_utils:utils", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/BUILD.gn index b03bb35e..2b49400e 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/BUILD.gn @@ -41,12 +41,12 @@ ohos_fuzztest("SourceHandlerRegisterDistributedHardwareFuzzTest") { "include", "${common_path}/include", "${innerkits_path}/native_cpp/audio_source/include", + "${innerkits_path}/native_cpp/test/include", "${fwk_services_path}/distributedhardwarefwkservice/include", "${fwk_services_path}/distributedhardwarefwkservice/include/componentmanager", ] deps = [ - "${fwk_services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", "${innerkits_path}/native_cpp/audio_source:distributed_audio_source_sdk", ] diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/sourcehandlerregisterdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/sourcehandlerregisterdistributedhardware_fuzzer.cpp index 10871d97..bc7a5b74 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/sourcehandlerregisterdistributedhardware_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/sourcehandlerregisterdistributedhardware_fuzzer.cpp @@ -20,7 +20,7 @@ #include "daudio_source_handler.h" #include "daudio_constants.h" -#include "component_enable.h" +#include "mock_component_enable.h" namespace OHOS { namespace DistributedHardware { @@ -36,7 +36,7 @@ void SourceHandlerRegisterDistributedHardwareFuzzTest(const uint8_t* data, size_ EnableParam param; param.sinkVersion = version; param.sinkAttrs = attrs; - std::shared_ptr callback = std::make_shared(); + std::shared_ptr callback = std::make_shared(); DAudioSourceHandler::GetInstance().RegisterDistributedHardware(devId, dhId, param, callback); } diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/BUILD.gn index e03e9b14..8721723a 100755 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/BUILD.gn @@ -41,12 +41,12 @@ ohos_fuzztest("SourceHandlerUnregisterDistributedHardwareFuzzTest") { "include", "${common_path}/include", "${innerkits_path}/native_cpp/audio_source/include", + "${innerkits_path}/native_cpp/test/include", "${fwk_services_path}/distributedhardwarefwkservice/include", "${fwk_services_path}/distributedhardwarefwkservice/include/componentmanager", ] deps = [ - "${fwk_services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", "${innerkits_path}/native_cpp/audio_source:distributed_audio_source_sdk", ] diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/sourcehandlerunregisterdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/sourcehandlerunregisterdistributedhardware_fuzzer.cpp index 25493ddc..499fecdc 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/sourcehandlerunregisterdistributedhardware_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/sourcehandlerunregisterdistributedhardware_fuzzer.cpp @@ -20,7 +20,7 @@ #include "daudio_source_handler.h" #include "daudio_constants.h" -#include "component_disable.h" +#include "mock_component_disable.h" namespace OHOS { namespace DistributedHardware { @@ -31,7 +31,7 @@ void SourceHandlerUnregisterDistributedHardwareFuzzTest(const uint8_t* data, siz } std::string devId(reinterpret_cast(data), size); std::string dhId(reinterpret_cast(data), size); - std::shared_ptr callback = std::make_shared(); + std::shared_ptr callback = std::make_shared(); DAudioSourceHandler::GetInstance().UnregisterDistributedHardware(devId, dhId, callback); } diff --git a/interfaces/inner_kits/native_cpp/test/include/mock_component_disable.h b/interfaces/inner_kits/native_cpp/test/include/mock_component_disable.h new file mode 100644 index 00000000..0a21a846 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/include/mock_component_disable.h @@ -0,0 +1,48 @@ +/* + * 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. + */ + +#ifndef OHOS_DAUDIO_MOCK_COMPONENT_DISABLE_H +#define OHOS_DAUDIO_MOCK_COMPONENT_DISABLE_H + +#include "daudio_errorcode.h" +#include "idistributed_hardware_source.h" + +namespace OHOS { +namespace DistributedHardware { +class MockComponentDisable : public std::enable_shared_from_this, public UnregisterCallback { +public: + MockComponentDisable() + { + } + + virtual ~MockComponentDisable() + { + } + + int32_t Disable(const std::string &networkId, const std::string &dhId, + IDistributedHardwareSource *handler) + { + return DH_SUCCESS; + } + + int32_t OnUnregisterResult(const std::string &networkId, const std::string &dhId, int32_t status, + const std::string &data) override + { + return DH_SUCCESS; + } +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/interfaces/inner_kits/native_cpp/test/include/mock_component_enable.h b/interfaces/inner_kits/native_cpp/test/include/mock_component_enable.h new file mode 100644 index 00000000..a6349ba0 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/include/mock_component_enable.h @@ -0,0 +1,48 @@ +/* + * 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. + */ + +#ifndef OHOS_DAUDIO_MOCK_COMPONENT_ENABLE_H +#define OHOS_DAUDIO_MOCK_COMPONENT_ENABLE_H + +#include "daudio_errorcode.h" +#include "idistributed_hardware_source.h" + +namespace OHOS { +namespace DistributedHardware { +class MockComponentEnable : public std::enable_shared_from_this, public RegisterCallback { +public: + explicit MockComponentEnable() + { + } + + virtual ~MockComponentEnable() + { + } + + int32_t Enable(const std::string &uuid, const std::string &dhId, const EnableParam ¶m, + IDistributedHardwareSource *handler) + { + return DH_SUCCESS; + } + + int32_t OnRegisterResult(const std::string &uuid, const std::string &dhId, int32_t status, + const std::string &data) override + { + return DH_SUCCESS; + } +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif -- Gitee