From 541a37824e84412b4a4cad9d9b4da2da8072a9c3 Mon Sep 17 00:00:00 2001 From: wangsen1994 Date: Tue, 1 Jul 2025 10:53:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EFuzz=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangsen1994 --- .../service_cancel_fuzzer.cpp | 12 +++++ ...vice_disablenotificationfeature_fuzzer.cpp | 10 +++++ ...ce_getallliveviewenabledbundles_fuzzer.cpp | 10 +++++ .../service_getbundleimportance_fuzzer.cpp | 10 +++++ .../service_getdonotdisturbdate_fuzzer.cpp | 10 +++++ ...e_getspecialactivenotifications_fuzzer.cpp | 14 ++++++ ...vice_removedonotdisturbprofiles_fuzzer.cpp | 16 +++++++ ...ervice_replydistributeoperation_fuzzer.cpp | 11 +++++ ...service_setenabledforbundleslot_fuzzer.cpp | 13 ++++++ ...ce_setshowbadgeenabledforbundle_fuzzer.cpp | 11 +++++ .../service_settargetdevicestatus_fuzzer.cpp | 14 ++++++ .../service_shelldump_fuzzer.cpp | 15 +++++++ .../mock/mock_notification_disable.h | 44 +++++++++++++++++++ .../mock/mock_notification_donotdisturbdate.h | 43 ++++++++++++++++++ 14 files changed, 233 insertions(+) create mode 100644 test/fuzztest/fuzz_common_base/mock/mock_notification_disable.h create mode 100644 test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturbdate.h diff --git a/test/fuzztest/advancednotificationservice/servicecancel_fuzzer/service_cancel_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicecancel_fuzzer/service_cancel_fuzzer.cpp index 3dace1401..41ce3f2db 100644 --- a/test/fuzztest/advancednotificationservice/servicecancel_fuzzer/service_cancel_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicecancel_fuzzer/service_cancel_fuzzer.cpp @@ -23,6 +23,12 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + + int32_t notificationId = fuzzData->ConsumeIntegral(); + std::string label = fuzzData->ConsumeRandomLengthString(); + std::string instanceKey = fuzzData->ConsumeRandomLengthString(); + service->Cancel(notificationId, label, instanceKey); return true; } } @@ -33,6 +39,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicedisablenotificationfeature_fuzzer/service_disablenotificationfeature_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicedisablenotificationfeature_fuzzer/service_disablenotificationfeature_fuzzer.cpp index b3c136406..37a8ee071 100644 --- a/test/fuzztest/advancednotificationservice/servicedisablenotificationfeature_fuzzer/service_disablenotificationfeature_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicedisablenotificationfeature_fuzzer/service_disablenotificationfeature_fuzzer.cpp @@ -23,6 +23,10 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + + sptr notificationDisable = ObjectBuilder::Build(fuzzData); + service->DisableNotificationFeature(notificationDisable); return true; } } @@ -33,6 +37,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicegetallliveviewenabledbundles_fuzzer/service_getallliveviewenabledbundles_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetallliveviewenabledbundles_fuzzer/service_getallliveviewenabledbundles_fuzzer.cpp index d3fd0620d..d1a1e0fd4 100644 --- a/test/fuzztest/advancednotificationservice/servicegetallliveviewenabledbundles_fuzzer/service_getallliveviewenabledbundles_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetallliveviewenabledbundles_fuzzer/service_getallliveviewenabledbundles_fuzzer.cpp @@ -23,6 +23,10 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + + std::vector bundleOption; + service->GetAllLiveViewEnabledBundles(bundleOption); return true; } } @@ -33,6 +37,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicegetbundleimportance_fuzzer/service_getbundleimportance_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetbundleimportance_fuzzer/service_getbundleimportance_fuzzer.cpp index 3718993e6..fed9e36b5 100644 --- a/test/fuzztest/advancednotificationservice/servicegetbundleimportance_fuzzer/service_getbundleimportance_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetbundleimportance_fuzzer/service_getbundleimportance_fuzzer.cpp @@ -23,6 +23,10 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + + int32_t importance = 0; + service->GetBundleImportance(importance); return true; } } @@ -33,6 +37,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicegetdonotdisturbdate_fuzzer/service_getdonotdisturbdate_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetdonotdisturbdate_fuzzer/service_getdonotdisturbdate_fuzzer.cpp index 275c98fc8..c8234283e 100644 --- a/test/fuzztest/advancednotificationservice/servicegetdonotdisturbdate_fuzzer/service_getdonotdisturbdate_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetdonotdisturbdate_fuzzer/service_getdonotdisturbdate_fuzzer.cpp @@ -23,6 +23,10 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + + sptr date; + service->GetDoNotDisturbDate(date); return true; } } @@ -33,6 +37,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicegetspecialactivenotifications_fuzzer/service_getspecialactivenotifications_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetspecialactivenotifications_fuzzer/service_getspecialactivenotifications_fuzzer.cpp index ff9661159..2f46a5c61 100644 --- a/test/fuzztest/advancednotificationservice/servicegetspecialactivenotifications_fuzzer/service_getspecialactivenotifications_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetspecialactivenotifications_fuzzer/service_getspecialactivenotifications_fuzzer.cpp @@ -23,6 +23,14 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + + std::vector key; + key.push_back(fuzzData->ConsumeRandomLengthString()); + key.push_back(fuzzData->ConsumeRandomLengthString()); + key.push_back(fuzzData->ConsumeRandomLengthString()); + std::vector> notifications; + service->GetSpecialActiveNotifications(key, notifications); return true; } } @@ -33,6 +41,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/serviceremovedonotdisturbprofiles_fuzzer/service_removedonotdisturbprofiles_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceremovedonotdisturbprofiles_fuzzer/service_removedonotdisturbprofiles_fuzzer.cpp index e8692ec11..a42ca49a4 100644 --- a/test/fuzztest/advancednotificationservice/serviceremovedonotdisturbprofiles_fuzzer/service_removedonotdisturbprofiles_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceremovedonotdisturbprofiles_fuzzer/service_removedonotdisturbprofiles_fuzzer.cpp @@ -23,6 +23,16 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + + std::vector> profiles; + sptr profile1 = + ObjectBuilder::Build(fuzzData); + profiles.push_back(profile1); + sptr profile2 = + ObjectBuilder::Build(fuzzData); + profiles.push_back(profile2); + service->RemoveDoNotDisturbProfiles(profiles); return true; } } @@ -33,6 +43,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicereplydistributeoperation_fuzzer/service_replydistributeoperation_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicereplydistributeoperation_fuzzer/service_replydistributeoperation_fuzzer.cpp index 63d4ccdf0..103a24590 100644 --- a/test/fuzztest/advancednotificationservice/servicereplydistributeoperation_fuzzer/service_replydistributeoperation_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicereplydistributeoperation_fuzzer/service_replydistributeoperation_fuzzer.cpp @@ -23,6 +23,11 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + + int32_t result = fuzzData->ConsumeIntegral(); + std::string hashCode = fuzzData->ConsumeRandomLengthString(); + service->ReplyDistributeOperation(hashCode, result); return true; } } @@ -33,6 +38,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicesetenabledforbundleslot_fuzzer/service_setenabledforbundleslot_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesetenabledforbundleslot_fuzzer/service_setenabledforbundleslot_fuzzer.cpp index 2d69fed75..f51efc5d9 100644 --- a/test/fuzztest/advancednotificationservice/servicesetenabledforbundleslot_fuzzer/service_setenabledforbundleslot_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesetenabledforbundleslot_fuzzer/service_setenabledforbundleslot_fuzzer.cpp @@ -23,6 +23,13 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + + bool enabled = fuzzData->ConsumeBool(); + bool isForceControl = fuzzData->ConsumeBool(); + int32_t slotTypeInt = fuzzData->ConsumeIntegral(); + sptr bundleOption = ObjectBuilder::Build(fuzzData); + service->SetEnabledForBundleSlot(bundleOption, slotTypeInt, enabled, isForceControl); return true; } } @@ -33,6 +40,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicesetshowbadgeenabledforbundle_fuzzer/service_setshowbadgeenabledforbundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesetshowbadgeenabledforbundle_fuzzer/service_setshowbadgeenabledforbundle_fuzzer.cpp index 3c1f6ccd6..74a547c07 100644 --- a/test/fuzztest/advancednotificationservice/servicesetshowbadgeenabledforbundle_fuzzer/service_setshowbadgeenabledforbundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesetshowbadgeenabledforbundle_fuzzer/service_setshowbadgeenabledforbundle_fuzzer.cpp @@ -23,6 +23,11 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + + bool enabled = fuzzData->ConsumeBool(); + sptr bundleOption = ObjectBuilder::Build(fuzzData); + service->SetShowBadgeEnabledForBundle(bundleOption, enabled); return true; } } @@ -33,6 +38,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicesettargetdevicestatus_fuzzer/service_settargetdevicestatus_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesettargetdevicestatus_fuzzer/service_settargetdevicestatus_fuzzer.cpp index 0fdfc728a..8ac418b9e 100644 --- a/test/fuzztest/advancednotificationservice/servicesettargetdevicestatus_fuzzer/service_settargetdevicestatus_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesettargetdevicestatus_fuzzer/service_settargetdevicestatus_fuzzer.cpp @@ -23,6 +23,14 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + + std::string deviceType = fuzzData->ConsumeRandomLengthString(); + std::string deviceId = fuzzData->ConsumeRandomLengthString(); + uint32_t status = fuzzData->ConsumeIntegral(); + uint32_t controlFlag = fuzzData->ConsumeIntegral(); + int32_t userId = fuzzData->ConsumeIntegral(); + service->SetTargetDeviceStatus(deviceType, status, controlFlag, deviceId, userId); return true; } } @@ -33,6 +41,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/serviceshelldump_fuzzer/service_shelldump_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceshelldump_fuzzer/service_shelldump_fuzzer.cpp index 02c33df27..39f49e9fe 100644 --- a/test/fuzztest/advancednotificationservice/serviceshelldump_fuzzer/service_shelldump_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceshelldump_fuzzer/service_shelldump_fuzzer.cpp @@ -23,6 +23,15 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + + std::string cmd = fuzzData->ConsumeRandomLengthString(); + std::string bundle = fuzzData->ConsumeRandomLengthString(); + int32_t userId = fuzzData->ConsumeIntegral(); + int32_t recvUserId = fuzzData->ConsumeIntegral(); + + std::vector dumpInfo; + service->ShellDump(cmd, bundle, userId, recvUserId, dumpInfo); return true; } } @@ -33,6 +42,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_disable.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_disable.h new file mode 100644 index 000000000..1a0ba5354 --- /dev/null +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_disable.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 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 MOCK_NOTIFICATION_DISABLE_BUILDER_H +#define MOCK_NOTIFICATION_DISABLE_BUILDER_H + +#include "mock_fuzz_object.h" +#include "mock_notification_content.h" +#include "mock_notification_distributed_options.h" +#include "mock_notification_template.h" +#include "mock_notification_flags.h" +#include "mock_notification_bundle_option.h" +#include "mock_notification_action_button.h" +#include "notification_request.h" + +namespace OHOS { +namespace Notification { +template <> +NotificationSlot* ObjectBuilder::Build(FuzzedDataProvider *fdp) +{ + auto disable = new NotificationDisable(); + slot->SetDisabled(fdp->ConsumeBool()); + std::vector bundleList; + bundleList.push_back(fdp->ConsumeRandomLengthString()); + bundleList.push_back(fdp->ConsumeRandomLengthString()); + bundleList.push_back(fdp->ConsumeRandomLengthString()); + slot->SetBundleList(bundleList); + return slot; +} +} // namespace Notification +} // namespace OHOS +#endif // MOCK_NOTIFICATION_DISABLE_BUILDER_H diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturbdate.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturbdate.h new file mode 100644 index 000000000..3a2e96b5b --- /dev/null +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturbdate.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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 MOCK_NOTIFICATION_DISABLE_BUILDER_H +#define MOCK_NOTIFICATION_DISABLE_BUILDER_H + +#include "mock_fuzz_object.h" +#include "mock_notification_content.h" +#include "mock_notification_distributed_options.h" +#include "mock_notification_template.h" +#include "mock_notification_flags.h" +#include "mock_notification_bundle_option.h" +#include "mock_notification_action_button.h" +#include "notification_request.h" + +namespace OHOS { +namespace Notification { +constexpr int32_t DONOTDISTURB_TYPE_LENGTH = 3; +template <> +NotificationSlot* ObjectBuilder::Build(FuzzedDataProvider *fdp) +{ + auto disturbDate = new NotificationDoNotDisturbDate(); + disturbDate->SetBeginDate(fdp->ConsumeIntegral()); + disturbDate->SetEndDate(fdp->ConsumeIntegral()); + disturbDate->SetDoNotDisturbType(static_cast( + fdp->ConsumeIntegralInRange(0, DONOTDISTURB_TYPE_LENGTH))); + return slot; +} +} // namespace Notification +} // namespace OHOS +#endif // MOCK_NOTIFICATION_DISABLE_BUILDER_H -- Gitee