diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 3b674d09c85ce4d23d4bd4ae23dad237a0f439ee..68e8077f325f93b27f7d215b5300019b7a9dedb8 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -33,13 +33,19 @@ group("fuzztest") { "getnotificationslot_fuzzer:GetNotificationSlotFuzzTest", "getnotificationslotnumasbundle_fuzzer:GetNotificationSlotNumAsBundleFuzzTest", "getnotificationslotsforbundle_fuzzer:GetNotificationSlotsForBundleFuzzTest", + "messageuser_fuzzer:MessageUserFuzzTest", "notification_fuzzer:NotificationFuzzTest", + "notificationactionbutton_fuzzer:NotificationActionButtonFuzzTest", + "notificationcontent_fuzzer:NotificationContentFuzzTest", "notificationconversationalcontent_fuzzer:NotificationConversationalContentFuzzTest", "notificationconversationalmessage_fuzzer:NotificationConversationalMessageFuzzTest", + "notificationdistributedoptions_fuzzer:NotificationDistributedOptionsFuzzTest", "notificationdonotdisturbdate_fuzzer:NotificationDoNotDisturbDateFuzzTest", + "notificationflags_fuzzer:NotificationFlagsFuzzTest", "notificationlongtextcontent_fuzzer:NotificationLongTextContentFuzzTest", "notificationmediacontent_fuzzer:NotificationMediaContentFuzzTest", "notificationmultilinecontent_fuzzer:NotificationMultiLineContentFuzzTest", + "notificationnormalcontent_fuzzer:NotificationNormalContentFuzzTest", "notificationpicturecontent_fuzzer:NotificationPictureContentFuzzTest", "notificationrequest_fuzzer:NotificationRequestFuzzTest", "notificationsorting_fuzzer:NotificationSortingFuzzTest", @@ -58,6 +64,7 @@ group("fuzztest") { "reminderrequestcontinuate_fuzzer:ReminderRequestContinuateFuzzTest", "reminderrequesttimer_fuzzer:ReminderRequestTimerFuzzTest", "reminderstore_fuzzer:ReminderStoreFuzzTest", + "reminderstoreannex_fuzzer:ReminderStoreAnnexFuzzTest", "removenotification_fuzzer:RemoveNotificationFuzzTest", "removenotificationsbybundle_fuzzer:RemoveNotificationsByBundleFuzzTest", "removenotificationslot_fuzzer:RemoveNotificationSlotFuzzTest", diff --git a/test/fuzztest/messageuser_fuzzer/BUILD.gn b/test/fuzztest/messageuser_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..743510799d46c0bd82f32d3b451534a4c2ea8cec --- /dev/null +++ b/test/fuzztest/messageuser_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("MessageUserFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/messageuser_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "messageuser_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":MessageUserFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/messageuser_fuzzer/corpus/init b/test/fuzztest/messageuser_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/messageuser_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.cpp b/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..47210c4a270c45fd7f877fe4473f22e059b3d0b5 --- /dev/null +++ b/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 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. + */ + +#define private public +#define protected public +#include "message_user.h" +#undef private +#undef protected +#include "messageuser_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string key(data); + Notification::MessageUser messageUser; + // test SetKey function + messageUser.SetKey(key); + // test SetName function + std::string name(data); + messageUser.SetName(name); + // test SetPixelMap function + std::shared_ptr pixelMap = std::make_shared(); + messageUser.SetPixelMap(pixelMap); + // test SetUri function + Uri uri(key); + messageUser.SetUri(uri); + // test SetMachine function + bool enabled = *data % ENABLE; + messageUser.SetMachine(enabled); + // test SetUserAsImportant function + messageUser.SetUserAsImportant(enabled); + // test GetKey function + messageUser.GetKey(); + // test GetName function + messageUser.GetName(); + // test GetPixelMap function + messageUser.GetPixelMap(); + // test GetUri function + messageUser.GetUri(); + // test IsMachine function + messageUser.IsMachine(); + // test IsUserImportant function + messageUser.IsUserImportant(); + // test ToJson function + nlohmann::json jsonObject; + messageUser.ToJson(jsonObject); + messageUser.FromJson(jsonObject); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.h b/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..8e6a27836e7fc3fa8a797debe2389e9f3c9b07ef --- /dev/null +++ b/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_MESSAGEUSER_FUZZER_MESSAGEUSER_FUZZER_H +#define TEST_FUZZTEST_MESSAGEUSER_FUZZER_MESSAGEUSER_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "messageuser_fuzzer" + +#endif // TEST_FUZZTEST_MESSAGEUSER_FUZZER_MESSAGEUSER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/messageuser_fuzzer/project.xml b/test/fuzztest/messageuser_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/messageuser_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationactionbutton_fuzzer/BUILD.gn b/test/fuzztest/notificationactionbutton_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..990c9dba24aa350c27cb2e4f3cce8e6dbcdd78f8 --- /dev/null +++ b/test/fuzztest/notificationactionbutton_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationActionButtonFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationactionbutton_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationactionbutton_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationActionButtonFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationactionbutton_fuzzer/corpus/init b/test/fuzztest/notificationactionbutton_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationactionbutton_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.cpp b/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..10982a6b7f16af3231c44740612ba8dbcc619707 --- /dev/null +++ b/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2022 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. + */ + +#define private public +#define protected public +#include "notification_action_button.h" +#undef private +#undef protected +#include "notificationactionbutton_fuzzer.h" +#include "want_agent_info.h" +#include "want_agent_helper.h" +#include "want_params.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + AbilityRuntime::WantAgent::WantAgentInfo paramsInfo; + std::shared_ptr wantAgent = + AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(paramsInfo); + std::string title(data); + std::shared_ptr actionButton = + Notification::NotificationActionButton::Create(nullptr, title, wantAgent); + if (actionButton == nullptr) { + return false; + } + // test AddAdditionalData function + AAFwk::WantParams extras; + actionButton->AddAdditionalData(extras); + // test AddMimeTypeOnlyUserInput function + std::shared_ptr userInput = + std::make_shared(); + actionButton->AddMimeTypeOnlyUserInput(userInput); + actionButton->AddNotificationUserInput(userInput); + // test GetMimeTypeOnlyUserInputs function + actionButton->GetMimeTypeOnlyUserInputs(); + // test GetUserInput function + actionButton->GetUserInput(); + // test IsAutoCreatedReplies function + actionButton->IsAutoCreatedReplies(); + // test IsContextDependent function + actionButton->IsContextDependent(); + // test GetSemanticActionButton function + actionButton->GetSemanticActionButton(); + // test GetIcon function + actionButton->GetIcon(); + // test GetTitle function + actionButton->GetTitle(); + // test GetWantAgent function + actionButton->GetWantAgent(); + // test Dump function + actionButton->Dump(); + // test ToJson function + nlohmann::json jsonObject; + actionButton->ToJson(jsonObject); + actionButton->FromJson(jsonObject); + // test Unmarshalling function + Parcel parcel; + actionButton->Marshalling(parcel); + actionButton->Unmarshalling(parcel); + actionButton->ReadFromParcel(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.h b/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..32b8806cc4cd8bf3a4b6b7aeff2575187b05b925 --- /dev/null +++ b/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_NOTIFICATIONACTIONBUTTON_FUZZER_NOTIFICATIONACTIONBUTTON_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONACTIONBUTTON_FUZZER_NOTIFICATIONACTIONBUTTON_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationactionbutton_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONACTIONBUTTON_FUZZER_NOTIFICATIONACTIONBUTTON_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationactionbutton_fuzzer/project.xml b/test/fuzztest/notificationactionbutton_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationactionbutton_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationcontent_fuzzer/BUILD.gn b/test/fuzztest/notificationcontent_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f093ca3f17af0a4ab90cf60e7c55296c214099f0 --- /dev/null +++ b/test/fuzztest/notificationcontent_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationContentFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationcontent_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationcontent_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationContentFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationcontent_fuzzer/corpus/init b/test/fuzztest/notificationcontent_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationcontent_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.cpp b/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2b913e0a6e3c3fd8eafbb7910dad03242cd81ecf --- /dev/null +++ b/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 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. + */ + +#define private public +#define protected public +#include "notification_content.h" +#undef private +#undef protected +#include "notificationcontent_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::shared_ptr normalContent = + std::make_shared(); + std::shared_ptr longTextContent = + std::make_shared(); + std::shared_ptr pictureContent = + std::make_shared(); + std::shared_ptr conversationContent = + std::make_shared(); + std::shared_ptr multiLineContent = + std::make_shared(); + std::shared_ptr mediaContent = + std::make_shared(); + if ((normalContent == nullptr) || (longTextContent == nullptr) || (pictureContent == nullptr) || + (conversationContent == nullptr) || (multiLineContent == nullptr) || (mediaContent == nullptr)) { + return false; + } + Notification::NotificationContent notificationContent(normalContent); + Notification::NotificationContent notificationLongTextContent(longTextContent); + Notification::NotificationContent notificationPictureContent(pictureContent); + Notification::NotificationContent notificationConversationContent(conversationContent); + Notification::NotificationContent notificationMultiLineContent(multiLineContent); + Notification::NotificationContent notificationMediaContent(mediaContent); + // test Dump function + notificationContent.GetContentType(); + // test Dump function + notificationContent.GetNotificationContent(); + // test Dump function + notificationContent.Dump(); + // test ToJson function + nlohmann::json jsonObject; + notificationContent.ToJson(jsonObject); + notificationContent.FromJson(jsonObject); + // test Unmarshalling function + Parcel parcel; + notificationContent.Unmarshalling(parcel); + notificationContent.ReadFromParcel(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.h b/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..f38e46696eac200c1119a9f3444886fcf5ddc7ec --- /dev/null +++ b/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_NOTIFICATIONCONTENT_FUZZER_NOTIFICATIONCONTENT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONCONTENT_FUZZER_NOTIFICATIONCONTENT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationcontent_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONCONTENT_FUZZER_NOTIFICATIONCONTENT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationcontent_fuzzer/project.xml b/test/fuzztest/notificationcontent_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationcontent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationdistributedoptions_fuzzer/BUILD.gn b/test/fuzztest/notificationdistributedoptions_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..559ffbc70d293d28442a9c0a2cd02489d8262b24 --- /dev/null +++ b/test/fuzztest/notificationdistributedoptions_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationDistributedOptionsFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationdistributedoptions_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationdistributedoptions_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationDistributedOptionsFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationdistributedoptions_fuzzer/corpus/init b/test/fuzztest/notificationdistributedoptions_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationdistributedoptions_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.cpp b/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0750e4835a67e7db8a77a092995ec9d67bda0fb1 --- /dev/null +++ b/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 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 "notification_distributed_options.h" +#include "notificationdistributedoptions_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + bool distribute = *data % ENABLE; + std::vector dvsDisplay; + std::vector dvsOperate; + dvsDisplay.emplace_back(stringData); + dvsOperate.emplace_back(stringData); + Notification::NotificationDistributedOptions notificationDistributedOptions(distribute, dvsDisplay, dvsOperate); + // test IsDistributed function + notificationDistributedOptions.IsDistributed(); + // test GetDevicesSupportDisplay function + notificationDistributedOptions.GetDevicesSupportDisplay(); + // test GetDevicesSupportOperate function + notificationDistributedOptions.GetDevicesSupportOperate(); + // test GetDevicesSupportOperate function + notificationDistributedOptions.GetDevicesSupportOperate(); + // test Dump function + notificationDistributedOptions.Dump(); + // test ToJson function + nlohmann::json jsonObject; + notificationDistributedOptions.ToJson(jsonObject); + notificationDistributedOptions.FromJson(jsonObject); + // test Unmarshalling function + Parcel parcel; + return notificationDistributedOptions.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.h b/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..083e196698ba04d56c9a1c12c27222651e1d3c69 --- /dev/null +++ b/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationdistributedoptions_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationdistributedoptions_fuzzer/project.xml b/test/fuzztest/notificationdistributedoptions_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationdistributedoptions_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationflags_fuzzer/BUILD.gn b/test/fuzztest/notificationflags_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..447895fb78f92cc5b42d9b4bc0be46895da09ac3 --- /dev/null +++ b/test/fuzztest/notificationflags_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationFlagsFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/notificationflags_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationflags_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationFlagsFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationflags_fuzzer/corpus/init b/test/fuzztest/notificationflags_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationflags_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.cpp b/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..40ddcc291fe3d9bfc8cf2114f46f1de89b37987a --- /dev/null +++ b/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 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. + */ + +#define private public +#define protected public +#include "notification_flags.h" +#undef private +#undef protected +#include "notificationflags_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationFlags notificationFlags; + // test IsSoundEnabled function + notificationFlags.IsSoundEnabled(); + // test IsVibrationEnabled function + notificationFlags.IsVibrationEnabled(); + // test Dump function + notificationFlags.Dump(); + // test ToJson function + nlohmann::json jsonObject; + if (jsonObject.is_null() or !jsonObject.is_object()) { + return false; + } + notificationFlags.ToJson(jsonObject); + notificationFlags.FromJson(jsonObject); + // test Unmarshalling function + Parcel parcel; + notificationFlags.Unmarshalling(parcel); + notificationFlags.ReadFromParcel(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.h b/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..9c68c8131bd2c14d66f655d4b6e599b7377d2801 --- /dev/null +++ b/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_NOTIFICATIONFLAGS_FUZZER_NOTIFICATIONFLAGS_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONFLAGS_FUZZER_NOTIFICATIONFLAGS_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationflags_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONFLAGS_FUZZER_NOTIFICATIONFLAGS_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationflags_fuzzer/project.xml b/test/fuzztest/notificationflags_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationflags_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationnormalcontent_fuzzer/BUILD.gn b/test/fuzztest/notificationnormalcontent_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..dab3a817d475d948ade3b8908731079a108ac5b0 --- /dev/null +++ b/test/fuzztest/notificationnormalcontent_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationNormalContentFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationnormalcontent_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationnormalcontent_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationNormalContentFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationnormalcontent_fuzzer/corpus/init b/test/fuzztest/notificationnormalcontent_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationnormalcontent_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.cpp b/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5a81c96f872bc007cdb92d3ca5d283a52414af6e --- /dev/null +++ b/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 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. + */ + +#define private public +#define protected public +#include "notification_normal_content.h" +#undef private +#undef protected +#include "notificationnormalcontent_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationNormalContent notificationNormalContent; + // test Dump function + notificationNormalContent.Dump(); + // test ToJson function + nlohmann::json jsonObject; + notificationNormalContent.ToJson(jsonObject); + notificationNormalContent.FromJson(jsonObject); + // test Unmarshalling function + Parcel parcel; + notificationNormalContent.Unmarshalling(parcel); + notificationNormalContent.ReadFromParcel(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.h b/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..8033ab597fcf05e75d8a25c91a0d447a1a1cf062 --- /dev/null +++ b/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_NOTIFICATIONNORMALCONTENT_FUZZER_NOTIFICATIONNORMALCONTENT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONNORMALCONTENT_FUZZER_NOTIFICATIONNORMALCONTENT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationnormalcontent_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONNORMALCONTENT_FUZZER_NOTIFICATIONNORMALCONTENT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationnormalcontent_fuzzer/project.xml b/test/fuzztest/notificationnormalcontent_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationnormalcontent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderstoreannex_fuzzer/BUILD.gn b/test/fuzztest/reminderstoreannex_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..edfc9cfd48a137c368d269c134e59e76860763c6 --- /dev/null +++ b/test/fuzztest/reminderstoreannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderStoreAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/reminderstoreannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderstoreannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderStoreAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderstoreannex_fuzzer/corpus/init b/test/fuzztest/reminderstoreannex_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/reminderstoreannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderstoreannex_fuzzer/project.xml b/test/fuzztest/reminderstoreannex_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/reminderstoreannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.cpp b/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..99e1ef7c0ca4c8415c27febb18b23549e23892b0 --- /dev/null +++ b/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 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. + */ + +#define private public +#define protected public +#include "reminder_store.h" +#undef private +#undef protected +#include "reminderstoreannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::ReminderStore reminderStore; + // test GetReminders function + std::string queryCondition(data); + reminderStore.GetReminders(queryCondition); + // test GetAllValidReminders function + reminderStore.GetAllValidReminders(); + // test Query function + reminderStore.Query(queryCondition); + // test GetBundleOption function + sptr bundleOption; + int32_t reminderId = static_cast(GetU32Data(data)); + reminderStore.GetBundleOption(reminderId, bundleOption); + // test GetInt32Val function + std::shared_ptr resultSet = std::make_shared(); + std::string name(data); + int32_t value = static_cast(GetU32Data(data)); + reminderStore.GetInt32Val(resultSet, name, value); + std::string value1(data); + reminderStore.GetStringVal(resultSet, name, value1); + // test BuildReminder function + reminderStore.BuildReminder(resultSet); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.h b/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..590bc3f13a328bef7fab98df62736c25fb6fc7e1 --- /dev/null +++ b/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_REMINDERSTOREANNEX_FUZZER_REMINDERSTOREANNEX_FUZZER_H +#define TEST_FUZZTEST_REMINDERSTOREANNEX_FUZZER_REMINDERSTOREANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderstoreannex_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERSTOREANNEX_FUZZER_REMINDERSTOREANNEX_FUZZER_H \ No newline at end of file