diff --git a/test/fuzztest/advancednotificationservice/servicecancelasbundlewithagent_fuzzer/service_cancelasbundlewithagent_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicecancelasbundlewithagent_fuzzer/service_cancelasbundlewithagent_fuzzer.cpp index 6e1dab8d7686cba5050b72baf4e38317e352b482..fb6911a843cdf3398c7269df29cd64dfe97a6e63 100644 --- a/test/fuzztest/advancednotificationservice/servicecancelasbundlewithagent_fuzzer/service_cancelasbundlewithagent_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicecancelasbundlewithagent_fuzzer/service_cancelasbundlewithagent_fuzzer.cpp @@ -18,11 +18,18 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_bundle_option.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + sptr bundleOption = ObjectBuilder::Build(fuzzData); + int32_t intData = fuzzData->ConsumeIntegral(); + service->CancelAsBundleWithAgent(bundleOption, intData); 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; -} +} \ No newline at end of file diff --git a/test/fuzztest/advancednotificationservice/servicegetalldistribuedenabledbundles_fuzzer/service_getalldistribuedenabledbundles_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetalldistribuedenabledbundles_fuzzer/service_getalldistribuedenabledbundles_fuzzer.cpp index effe2d0445fd862468edb2990a74d59cc8c46459..ae2d3e67a051054f7c9bd1b33e376da7b1b83030 100644 --- a/test/fuzztest/advancednotificationservice/servicegetalldistribuedenabledbundles_fuzzer/service_getalldistribuedenabledbundles_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetalldistribuedenabledbundles_fuzzer/service_getalldistribuedenabledbundles_fuzzer.cpp @@ -18,11 +18,23 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_bundle_option.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + std::string stringData = fuzzData->ConsumeRandomLengthString(); + std::vector bundelOptions; + int32_t bundleNum = fuzzData->ConsumeIntegral(); + for (int i = 0; i < bundleNum; i++) { + NotificationBundleOption bundleOption = *(ObjectBuilder::Build(fuzzData)); + bundelOptions.emplace_back(bundleOption); + } + service->GetAllDistribuedEnabledBundles(stringData, bundelOptions); return true; } } @@ -33,6 +45,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; -} +} \ No newline at end of file diff --git a/test/fuzztest/advancednotificationservice/servicegetdonotdisturbprofile_fuzzer/service_getdonotdisturbprofile_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetdonotdisturbprofile_fuzzer/service_getdonotdisturbprofile_fuzzer.cpp index 589fe2098adf1a52c1a2a669a16e927e8585fd50..dcdedbddc69840e193f90c2bcd6d1e389d37b683 100644 --- a/test/fuzztest/advancednotificationservice/servicegetdonotdisturbprofile_fuzzer/service_getdonotdisturbprofile_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetdonotdisturbprofile_fuzzer/service_getdonotdisturbprofile_fuzzer.cpp @@ -16,13 +16,21 @@ #include #include "advanced_notification_service.h" +#include "mock_notification_donotdisturb_profile.h" #include "ans_permission_def.h" -#include "mock_notification_request.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + int64_t intData = fuzzData->ConsumeIntegral(); + sptr profile = ObjectBuilder::Build(fuzzData); + service->GetDoNotDisturbProfile(intData, profile); + 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; -} +} \ No newline at end of file diff --git a/test/fuzztest/advancednotificationservice/servicegetslotbybundle_fuzzer/service_getslotbybundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetslotbybundle_fuzzer/service_getslotbybundle_fuzzer.cpp index a3c1b6d230828d8d6dfb9948c6392c3d5630a330..cf381c8dc41e07695e6b9d990157a72464c70dac 100644 --- a/test/fuzztest/advancednotificationservice/servicegetslotbybundle_fuzzer/service_getslotbybundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetslotbybundle_fuzzer/service_getslotbybundle_fuzzer.cpp @@ -18,15 +18,19 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_bundle_option.h" +#include "mock_notification_slot.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { - auto service = AdvancedNotificationService::GetInstance(); + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); sptr bundleOption = ObjectBuilder::Build(fuzzData); - std::vector> slots; - service->GetSlotsByBundle(bundleOption, slots); + sptr slot = ObjectBuilder::Build(fuzzData); + int32_t intData = fuzzData->ConsumeIntegral(); + service->GetSlotByBundle(bundleOption, intData, slot); return true; } } @@ -46,3 +50,4 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } + diff --git a/test/fuzztest/advancednotificationservice/serviceisneedsilentindonotdisturbmode_fuzzer/service_isneedsilentindonotdisturbmode_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceisneedsilentindonotdisturbmode_fuzzer/service_isneedsilentindonotdisturbmode_fuzzer.cpp index 7dc3a1027674429f2e36c6c935be958e8abcf75b..919803bb26b5998a19cb52ad2bb6de267f27f67d 100644 --- a/test/fuzztest/advancednotificationservice/serviceisneedsilentindonotdisturbmode_fuzzer/service_isneedsilentindonotdisturbmode_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceisneedsilentindonotdisturbmode_fuzzer/service_isneedsilentindonotdisturbmode_fuzzer.cpp @@ -23,6 +23,12 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + std::string stringData = fuzzData->ConsumeRandomLengthString(); + int32_t intData = fuzzData->ConsumeIntegral(); + service->IsNeedSilentInDoNotDisturbMode(stringData, intData); 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; -} +} \ No newline at end of file diff --git a/test/fuzztest/advancednotificationservice/servicesetnotificationsenabledforspecialbundle_fuzzer/service_setnotificationsenabledforspecialbundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesetnotificationsenabledforspecialbundle_fuzzer/service_setnotificationsenabledforspecialbundle_fuzzer.cpp index cd56aa1b509c36e9a98e2c139569ecc502957203..6a1597a2e4b2bad70338d51dd11e714e8265b724 100644 --- a/test/fuzztest/advancednotificationservice/servicesetnotificationsenabledforspecialbundle_fuzzer/service_setnotificationsenabledforspecialbundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesetnotificationsenabledforspecialbundle_fuzzer/service_setnotificationsenabledforspecialbundle_fuzzer.cpp @@ -18,11 +18,20 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_bundle_option.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + std::string stringData = fuzzData->ConsumeRandomLengthString(); + sptr bundleOption = ObjectBuilder::Build(fuzzData); + bool enabled = fuzzData->ConsumeBool(); + bool updateUnEnableTime = fuzzData->ConsumeBool(); + service->SetNotificationsEnabledForSpecialBundle(stringData, bundleOption, enabled, updateUnEnableTime); 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; -} +} \ No newline at end of file diff --git a/test/fuzztest/advancednotificationservice/servicesetsmartreminderenabled_fuzzer/service_setsmartreminderenabled_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesetsmartreminderenabled_fuzzer/service_setsmartreminderenabled_fuzzer.cpp index 84d14dac41d4f4eddca8e4711685534bc61777a5..a2c718f49c3ff0c78d4afd800eb05cec0bcd052c 100644 --- a/test/fuzztest/advancednotificationservice/servicesetsmartreminderenabled_fuzzer/service_setsmartreminderenabled_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesetsmartreminderenabled_fuzzer/service_setsmartreminderenabled_fuzzer.cpp @@ -23,6 +23,12 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + std::string stringData = fuzzData->ConsumeRandomLengthString(); + bool enabled = fuzzData->ConsumeBool(); + service->SetSmartReminderEnabled(stringData, enabled); 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; -} +} \ No newline at end of file diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturb_profile.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturb_profile.h index c79f2b1df0fdb78da8c6ffeef17df48da900c676..5d211b8def21a8077bb0a5b0f080ad1885874101 100644 --- a/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturb_profile.h +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturb_profile.h @@ -17,7 +17,7 @@ #define MOCK_NOTIFICATION_DONOT_DISTURB_PROFILE_BUILDER_H #include "mock_fuzz_object.h" -#include "notification_bundle_option.h" +#include "mock_notification_bundle_option.h" #include "notification_do_not_disturb_profile.h" namespace OHOS { diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_slot.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_slot.h index 73bde459aa347e85ee5f90f3be722104d337ace8..c9ea81046e4a663eac525fd6e603cc2c68fa18a3 100644 --- a/test/fuzztest/fuzz_common_base/mock/mock_notification_slot.h +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_slot.h @@ -24,7 +24,6 @@ namespace Notification { constexpr uint32_t MAX_SLOT_TYPE = 5; constexpr uint32_t MAX_STR_LENGTH = 20; constexpr uint32_t MAX_FLAGS = 63; -constexpr uint32_t MAX_VISIBLENESS_STATUS = 2; template <> NotificationSlot* ObjectBuilder::Build(FuzzedDataProvider *fdp) @@ -36,17 +35,15 @@ NotificationSlot* ObjectBuilder::Build(FuzzedDataProvider *fdp slot->SetDescription(fdp->ConsumeRandomLengthString(MAX_STR_LENGTH)); slot->SetLedLightColor(fdp->ConsumeIntegral()); slot->SetLevel(static_cast( - dp->ConsumeIntegralInRange(0, MAX_SLOT_TYPE))); - slot->SetSlotFlags(dp->ConsumeIntegralInRange(0, MAX_FLAGS)); - slot->SetVisibleness(static_cast( - fdp->ConsumeIntegralInRange(0, VISIBLENESS_STATUS))); + fdp->ConsumeIntegralInRange(0, MAX_SLOT_TYPE))); + slot->SetSlotFlags(fdp->ConsumeIntegralInRange(0, MAX_FLAGS)); slot->EnableBypassDnd(fdp->ConsumeBool()); slot->EnableBadge(fdp->ConsumeBool()); slot->SetEnable(fdp->ConsumeBool()); slot->SetForceControl(fdp->ConsumeBool()); - slot->SetAuthorizedStatus(dp->ConsumeIntegralInRange(0, 1)); - slot->SetAuthHintCnt(dp->ConsumeIntegralInRange(0, 1)); - slot->SetReminderMode(dp->ConsumeIntegralInRange(0, MAX_FLAGS)); + slot->SetAuthorizedStatus(fdp->ConsumeIntegralInRange(0, 1)); + slot->SetAuthHintCnt(fdp->ConsumeIntegralInRange(0, 1)); + slot->SetReminderMode(fdp->ConsumeIntegralInRange(0, MAX_FLAGS)); ANS_LOGE("Build mock veriables"); return slot;