diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn
index b6109218daa48c44cf52014f690deef8c488ad78..b5f84bce558a9df1e67fbf1b3cfa01ff984d4224 100644
--- a/test/fuzztest/BUILD.gn
+++ b/test/fuzztest/BUILD.gn
@@ -18,6 +18,7 @@ group("fuzztest") {
"addnotificationslot_fuzzer:AddNotificationSlotFuzzTest",
"addnotificationslots_fuzzer:AddNotificationSlotsFuzzTest",
"addslotbytype_fuzzer:AddSlotByTypeFuzzTest",
+ "advancednotificationservice:fuzztest",
"advancednotificationservice_fuzzer:AdvancedNotificationServiceFuzzTest",
"ansmanagerstub_fuzzer:AnsManagerStubFuzzTest",
"ansmanagerstubannex_fuzzer:AnsManagerStubAnnexFuzzTest",
diff --git a/test/fuzztest/advancednotificationservice/BUILD.gn b/test/fuzztest/advancednotificationservice/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..d2ce258a4a8ebd87462d755b4f0ab3ce015756d9
--- /dev/null
+++ b/test/fuzztest/advancednotificationservice/BUILD.gn
@@ -0,0 +1,22 @@
+# 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.
+
+import("//base/notification/distributed_notification_service/notification.gni")
+
+group("fuzztest") {
+ testonly = true
+
+ deps = [
+ "servicepublish_fuzzer:ServicePublishFuzzTest",
+ ]
+}
diff --git a/test/fuzztest/advancednotificationservice/servicepublish_fuzzer/BUILD.gn b/test/fuzztest/advancednotificationservice/servicepublish_fuzzer/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..48a44fc3f0f64819121511f3f83787f0c5748b99
--- /dev/null
+++ b/test/fuzztest/advancednotificationservice/servicepublish_fuzzer/BUILD.gn
@@ -0,0 +1,153 @@
+# 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.
+
+#####################hydra-fuzz###################
+import("//base/notification/distributed_notification_service/notification.gni")
+import("//build/config/features.gni")
+import("//build/test.gni")
+
+##############################fuzztest##########################################
+ohos_fuzztest("ServicePublishFuzzTest") {
+ module_out_path = service_fuzz_test_path
+ fuzz_config_file =
+ "${component_path}/test/fuzztest/advancednotificationservice/servicepublish_fuzzer"
+ include_dirs = [ "${services_path}/ans/include" ]
+ cflags = [
+ "-fno-math-errno",
+ "-fno-unroll-loops",
+ "-fmerge-all-constants",
+ "-fno-ident",
+ "-Oz",
+ "-flto",
+ "-ffunction-sections",
+ "-fdata-sections",
+ ]
+ sources = [ "service_publish_fuzzer.cpp" ]
+ defines = []
+ deps = [
+ "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base",
+ "${component_path}/test/fuzztest/fuzz_common_base:fuzz_mock_object",
+ "${frameworks_module_ans_path}:ans_innerkits",
+ "${services_path}/ans:ans_service_sources"
+ ]
+ if (is_double_framework) {
+ cflags += [ "-DCONFIG_DUAL_FRAMEWORK" ]
+ }
+
+ if (distributed_notification_supported) {
+ defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ]
+ deps += [ "${services_path}/distributed:libans_distributed" ]
+ include_dirs += [ "${services_path}/distributed/include" ]
+ }
+
+ if (notification_smart_reminder_supported) {
+ defines += [ "NOTIFICATION_SMART_REMINDER_SUPPORTED" ]
+ }
+
+ external_deps = [
+ "ability_base:configuration",
+ "ability_runtime:ability_manager",
+ "ability_runtime:app_manager",
+ "ability_runtime:appkit_native",
+ "ability_runtime:dataobs_manager",
+ "ability_runtime:extension_manager",
+ "ability_runtime:wantagent_innerkits",
+ "access_token:libaccesstoken_sdk",
+ "access_token:libtokenid_sdk",
+ "bundle_framework:appexecfwk_base",
+ "bundle_framework:appexecfwk_core",
+ "c_utils:utils",
+ "common_event_service:cesfwk_innerkits",
+ "config_policy:configpolicy_util",
+ "data_share:datashare_common",
+ "data_share:datashare_consumer",
+ "data_share:datashare_permission",
+ "device_manager:devicemanagersdk",
+ "ffrt:libffrt",
+ "hilog:libhilog",
+ "i18n:intl_util",
+ "image_framework:image_native",
+ "init:libbegetutil",
+ "kv_store:distributeddata_inner",
+ "openssl:libcrypto_shared",
+ "os_account:os_account_innerkits",
+ "relational_store:native_rdb",
+ "resource_management:global_resmgr",
+ "time_service:time_client",
+ ]
+ external_deps += component_external_deps
+
+ if (device_usage) {
+ external_deps += [ "device_usage_statistics:usagestatsinner" ]
+ defines += [ "DEVICE_USAGE_STATISTICS_ENABLE" ]
+ }
+
+ if (hisysevent_usage) {
+ cflags += [ "-DHAS_HISYSEVENT_PART" ]
+ external_deps += [ "hisysevent:libhisysevent" ]
+ }
+
+ if (standby_enable) {
+ external_deps += [ "device_standby:standby_innerkits" ]
+ defines += [ "DEVICE_STANDBY_ENABLE" ]
+ }
+
+ if (player_framework) {
+ external_deps += [ "player_framework:media_client" ]
+ defines += [ "PLAYER_FRAMEWORK_ENABLE" ]
+ }
+
+ if (ans_hitrace_usage) {
+ external_deps += [ "hitrace:hitrace_meter" ]
+ defines += [ "HITRACE_METER_ENABLE" ]
+ }
+
+ if (ans_config_policy_enable) {
+ external_deps += [ "config_policy:configpolicy_util" ]
+ defines += [ "CONFIG_POLICY_ENABLE" ]
+ }
+
+ if (screenlock_mgr_enable) {
+ external_deps += [ "screenlock_mgr:screenlock_client" ]
+ defines += [ "SCREENLOCK_MGR_ENABLE" ]
+ }
+
+ if (distributed_notification_service_feature_summary ||
+ distributed_notification_service_feature_additional_control ||
+ distributed_notification_service_feature_privileged_message) {
+ defines += [ "ENABLE_ANS_EXT_WRAPPER" ]
+ }
+
+ if (distributed_notification_service_feature_additional_control) {
+ defines += [ "ENABLE_ANS_ADDITIONAL_CONTROL" ]
+ }
+
+ if (distributed_notification_service_feature_summary) {
+ defines += [ "ENABLE_ANS_AGGREGATION" ]
+ }
+
+ if (telephony_cust) {
+ defines += [ "ENABLE_ANS_TELEPHONY_CUST_WRAPPER" ]
+ }
+
+ if (distributed_notification_service_feature_disable_fa_model) {
+ defines += [ "ANS_DISABLE_FA_MODEL" ]
+ }
+}
+
+###############################################################################
+group("fuzztest") {
+ testonly = true
+ deps = [ ":ServicePublishFuzzTest" ]
+}
+###############################################################################
diff --git a/test/fuzztest/advancednotificationservice/servicepublish_fuzzer/corpus/init b/test/fuzztest/advancednotificationservice/servicepublish_fuzzer/corpus/init
new file mode 100644
index 0000000000000000000000000000000000000000..d6a927d5409f58fd33b8e793135561bca72e8409
--- /dev/null
+++ b/test/fuzztest/advancednotificationservice/servicepublish_fuzzer/corpus/init
@@ -0,0 +1,13 @@
+# Copyright (c) 2023 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.
+100
\ No newline at end of file
diff --git a/test/fuzztest/advancednotificationservice/servicepublish_fuzzer/project.xml b/test/fuzztest/advancednotificationservice/servicepublish_fuzzer/project.xml
new file mode 100644
index 0000000000000000000000000000000000000000..226522bd2ad3eaf2db4f710f1924d82d2912c235
--- /dev/null
+++ b/test/fuzztest/advancednotificationservice/servicepublish_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 10000
+
+ 300
+
+ 4096
+
+
diff --git a/test/fuzztest/advancednotificationservice/servicepublish_fuzzer/service_publish_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicepublish_fuzzer/service_publish_fuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..27dbc66b64e0a3397d4b166afdb3b589254c64cb
--- /dev/null
+++ b/test/fuzztest/advancednotificationservice/servicepublish_fuzzer/service_publish_fuzzer.cpp
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+#include "service_publish_fuzzer.h"
+
+#include
+#include "advanced_notification_service.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();
+ std::string stringData = fuzzData->ConsumeRandomLengthString();
+ sptr request = ObjectBuilder::Build(fuzzData);
+ service->Publish(stringData, request);
+ return true;
+ }
+}
+}
+
+/* Fuzzer entry point */
+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/servicepublish_fuzzer/service_publish_fuzzer.h b/test/fuzztest/advancednotificationservice/servicepublish_fuzzer/service_publish_fuzzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..d6bd043726aa04d873b510d3666cc7cda25c1b63
--- /dev/null
+++ b/test/fuzztest/advancednotificationservice/servicepublish_fuzzer/service_publish_fuzzer.h
@@ -0,0 +1,24 @@
+/*
+ * 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 TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_ADVANCEDNOTIFICATIONSERVICE_FUZZER_H
+#define TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_ADVANCEDNOTIFICATIONSERVICE_FUZZER_H
+
+#include "fuzz_common_base.h"
+#include
+
+#define FUZZ_PROJECT_NAME "advancednotificationservice_fuzzer"
+
+#endif // TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_ADVANCEDNOTIFICATIONSERVICE_FUZZER_H
\ No newline at end of file
diff --git a/test/fuzztest/fuzz_common_base/BUILD.gn b/test/fuzztest/fuzz_common_base/BUILD.gn
index 778d1750239062be1560c9c26945e1a8f1ad2d4c..63b63ae495a09b0cdbd551bf263d1829c8cf7ce5 100644
--- a/test/fuzztest/fuzz_common_base/BUILD.gn
+++ b/test/fuzztest/fuzz_common_base/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright (c) 2022 Huawei Device Co., Ltd.
+# Copyright (c) 2024-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
@@ -31,8 +31,25 @@ static_library("fuzz_common_base") {
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
+ "c_utils:utils",
"selinux_adapter:librestorecon",
]
+}
+
+config("public_mock_config") {
+ include_dirs = [
+ "mock"
+ ]
+}
+
+static_library("fuzz_mock_object") {
+ public_configs = [ ":public_mock_config" ]
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
- public_external_deps = [ "c_utils:utils" ]
+ deps = [ "${frameworks_module_ans_path}:ans_innerkits" ]
}
diff --git a/test/fuzztest/fuzz_common_base/fuzz_common_base.cpp b/test/fuzztest/fuzz_common_base/fuzz_common_base.cpp
index f3e1b2649d1d4b7acb9a38e1aed7f2833052ce0e..e38c56a2c2158ec6a53c39acfa003f491f699deb 100644
--- a/test/fuzztest/fuzz_common_base/fuzz_common_base.cpp
+++ b/test/fuzztest/fuzz_common_base/fuzz_common_base.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2024-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
@@ -19,47 +19,26 @@
#include "nativetoken_kit.h"
#include "token_setproc.h"
#include "fuzz_common_base.h"
+#include
+#include
extern "C" {
-static constexpr uint32_t U32_AT_SIZE = 3;
-static constexpr uint32_t MAX_MEMORY_SIZE = 4 * 1024 * 1024;
-
using namespace OHOS::Security::AccessToken;
-uint32_t GetU32Size()
-{
- return U32_AT_SIZE;
-}
-
-uint32_t GetU32Data(const char* ptr)
+void MockRandomToken(FuzzedDataProvider *fdp, const std::vector &permissions)
{
- // convert fuzz input data to an integer
- return (ptr[0] << 16) | (ptr[1] << 8) | ptr[2];
-}
-
-char* ParseData(const uint8_t* data, size_t size)
-{
- if (data == nullptr) {
- return nullptr;
- }
-
- if (size > MAX_MEMORY_SIZE) {
- return nullptr;
- }
-
- char* ch = (char *)malloc(size + 1);
- if (ch == nullptr) {
- return nullptr;
- }
-
- (void)memset_s(ch, size + 1, 0x00, size + 1);
- if (memcpy_s(ch, size, data, size) != EOK) {
- free(ch);
- ch = nullptr;
- return nullptr;
+ int caseNum = fdp->ConsumeIntegralInRange(0, 3);
+ switch (caseNum) {
+ case 0:
+ NativeTokenGet(permissions);
+ break;
+ case 1:
+ SystemHapTokenGet(permissions);
+ break;
+ case 2:
+ default:
+ NormalHapTokenGet();
}
-
- return ch;
}
void NativeTokenGet(const std::vector &permissions)
@@ -90,10 +69,9 @@ void NativeTokenGet(const std::vector &permissions)
void SystemHapTokenGet(const std::vector &permissions)
{
-
HapPolicyParams hapPolicyPrams = {
.apl = APL_SYSTEM_CORE,
- .domain = "com.ohos.notificationdialog",
+ .domain = "test.fuzz.ans",
.permList = {},
.permStateList = {}
};
@@ -101,17 +79,17 @@ void SystemHapTokenGet(const std::vector &permissions)
for (auto permission : permissions) {
PermissionStateFull permStateFull = {
.permissionName = permission,
- .isGeneral = true,
- .resDeviceID = {"local"},
- .grantStatus = {PermissionState::PERMISSION_GRANTED},
- .grantFlags = {1}
+ .isGeneral = false,
+ .resDeviceID = {"device 1", "device 2"},
+ .grantStatus = {PermissionState::PERMISSION_GRANTED, PermissionState::PERMISSION_GRANTED},
+ .grantFlags = {1, 2}
};
PermissionDef permDef = {
.permissionName = permission,
- .bundleName = "com.ohos.notificationdialog",
+ .bundleName = "test.fuzz.ans",
.grantMode = 1,
- .availableLevel = APL_NORMAL,
- .label = "label",
+ .availableLevel = APL_SYSTEM_CORE,
+ .label = "label3",
.labelId = 1,
.description = "break the door",
.descriptionId = 1,
@@ -122,9 +100,9 @@ void SystemHapTokenGet(const std::vector &permissions)
HapInfoParams hapInfoParams = {
.userID = 100,
- .bundleName = "com.ohos.notificationdialog",
+ .bundleName = "test.fuzz.ans",
.instIndex = 0,
- .appIDDesc = "com.ohos.notificationdialog",
+ .appIDDesc = "test.fuzz.ans",
.apiVersion = 12,
.isSystemApp = true
};
@@ -133,4 +111,27 @@ void SystemHapTokenGet(const std::vector &permissions)
tokenIdEx = AccessTokenKit::AllocHapToken(hapInfoParams, hapPolicyPrams);
SetSelfTokenID(tokenIdEx.tokenIDEx);
}
+
+void NormalHapTokenGet()
+{
+ HapPolicyParams hapPolicyPrams = {
+ .apl = APL_NORMAL,
+ .domain = "test.fuzz.ans",
+ .permList = {},
+ .permStateList = {}
+ };
+
+ HapInfoParams hapInfoParams = {
+ .userID = 100,
+ .bundleName = "test.fuzz.ans",
+ .instIndex = 0,
+ .appIDDesc = "test.fuzz.ans",
+ .apiVersion = 12,
+ .isSystemApp = false
+ };
+
+ AccessTokenIDEx tokenIdEx = {0};
+ tokenIdEx = AccessTokenKit::AllocHapToken(hapInfoParams, hapPolicyPrams);
+ SetSelfTokenID(tokenIdEx.tokenIDEx);
+}
}
\ No newline at end of file
diff --git a/test/fuzztest/fuzz_common_base/fuzz_common_base.h b/test/fuzztest/fuzz_common_base/fuzz_common_base.h
index c84b5c5134f900ff9fe2a4c6f240f28f41be7a73..5c426a3bb13ce4e53b3ec313a19cedbc0ab26700 100644
--- a/test/fuzztest/fuzz_common_base/fuzz_common_base.h
+++ b/test/fuzztest/fuzz_common_base/fuzz_common_base.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Copyright (c) 2024-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
@@ -20,18 +20,16 @@
#include
#include
#include "securec.h"
-#include "fuzz_data.h"
+#include
extern "C" {
-uint32_t GetU32Size();
-
-uint32_t GetU32Data(const char* ptr);
-
-char* ParseData(const uint8_t* data, size_t size);
-
void NativeTokenGet(const std::vector &permissions);
+void NormalHapTokenGet();
+
void SystemHapTokenGet(const std::vector &permissions);
+
+void MockRandomToken(FuzzedDataProvider *fdp, const std::vector &permissions);
}
-#endif // FUZZ_COMMON_BASE_H
+#endif // FUZZ_COMMON_BASE_H
\ No newline at end of file
diff --git a/test/fuzztest/fuzz_common_base/fuzz_data.h b/test/fuzztest/fuzz_common_base/fuzz_data.h
deleted file mode 100644
index 87e6af604980a2961ddb004fb82add9563df0409..0000000000000000000000000000000000000000
--- a/test/fuzztest/fuzz_common_base/fuzz_data.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (c) 2024 Huawei Device Co., Ltd.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef FUZZ_DATA_H
-#define FUZZ_DATA_H
-#include
-#include
-#include "securec.h"
-
-namespace OHOS {
-
-constexpr uint32_t BOOL_MODULO_NUM = 2;
-
-using namespace std;
-class FuzzData {
-public:
- explicit FuzzData(const uint8_t *data, const size_t size) : pos_(0), data_(data), size_(size) {}
-
- template T GetData()
- {
- T object{};
- size_t objectSize = sizeof(object);
- if (data_ == nullptr || objectSize > size_ - pos_) {
- return object;
- }
- errno_t ret = memcpy_s(&object, objectSize, data_ + pos_, objectSize);
- if (ret != EOK) {
- return {};
- }
- pos_ += objectSize;
- return object;
- }
-
- std::string GetStringFromData(size_t pos, size_t strlen)
- {
- if (pos > size_) {
- return "test";
- }
- char cstr[strlen + 1];
- cstr[strlen] = '\0';
- pos_ = pos;
- for (size_t i = 0; i < strlen; i++) {
- char tmp = GetData();
- if (tmp == '\0') {
- tmp = '1';
- }
- cstr[i] = tmp;
- }
- std::string str(cstr);
- return str;
- }
-
- std::string GenerateRandomString()
- {
- return GetStringFromData(0, (GetData() % size_));
- }
-
- int32_t GenerateRandomInt32()
- {
- return GetData();
- }
-
- template T GenerateRandomEnmu(T enmuMax)
- {
- return static_cast(GetData() % (static_cast(enmuMax) + 1));
- }
-
- bool GenerateRandomBool()
- {
- return (GetData() % BOOL_MODULO_NUM) == 0;
- }
-
- size_t GetSize() const
- {
- return size_;
- }
-
-public:
- size_t pos_;
-
-private:
- const uint8_t *data_;
- const size_t size_;
-};
-} // namespace OHOS
-#endif // FUZZ_DATA_H
\ No newline at end of file
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_fuzz_object.h b/test/fuzztest/fuzz_common_base/mock/mock_fuzz_object.h
new file mode 100644
index 0000000000000000000000000000000000000000..f2b42549e71cd45d19d1177c1c2aa4e0a63a3cab
--- /dev/null
+++ b/test/fuzztest/fuzz_common_base/mock/mock_fuzz_object.h
@@ -0,0 +1,40 @@
+/*
+ * 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_OBJECT_BUILDER_H
+#define MOCK_OBJECT_BUILDER_H
+
+#include "ans_log_wrapper.h"
+#include
+
+namespace OHOS {
+namespace Notification {
+
+template
+struct ObjectBuilder {
+ static T* Build(FuzzedDataProvider *fdp)
+ {
+ return nullptr;
+ }
+
+ static std::shared_ptr BuildSharedPtr(FuzzedDataProvider *fdp)
+ {
+ return std::shared_ptr(Build(fdp));
+ }
+};
+} // namespace Notification
+} // namespace OHOS
+
+#endif // MOCK_OBJECT_BUILDER_H
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_action_button.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_action_button.h
new file mode 100644
index 0000000000000000000000000000000000000000..59126701068be5ecd7a2810cf599a7a54d5b741b
--- /dev/null
+++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_action_button.h
@@ -0,0 +1,52 @@
+/*
+ * 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_ACTION_BUTTON_BUILDER_H
+#define MOCK_NOTIFICATION_ACTION_BUTTON_BUILDER_H
+
+#include "mock_fuzz_object.h"
+#include "notification_action_button.h"
+#include "mock_notification_user_input.h"
+#include "mock_pixel_map.h"
+
+namespace OHOS {
+namespace Notification {
+
+template <>
+std::shared_ptr ObjectBuilder::BuildSharedPtr(
+ FuzzedDataProvider *fdp)
+{
+ std::string title = fdp->ConsumeRandomLengthString(50);
+ auto icon = fdp->ConsumeBool() ? ObjectBuilder::BuildSharedPtr(fdp) : nullptr;
+
+ auto semanticAction = static_cast(
+ fdp->ConsumeIntegralInRange(0, 3));
+ bool autoReplies = fdp->ConsumeBool();
+ std::vector> mimeInputs;
+ for (size_t i = 0; i < fdp->ConsumeIntegralInRange(0, 5); ++i) {
+ mimeInputs.push_back(ObjectBuilder::BuildSharedPtr(fdp));
+ }
+ auto userInput = fdp->ConsumeBool() ? ObjectBuilder::BuildSharedPtr(fdp) : nullptr;
+ bool isContextual = fdp->ConsumeBool();
+
+ ANS_LOGE("Build mock veriables");
+ return NotificationActionButton::Create(
+ icon, title, nullptr, nullptr, semanticAction, autoReplies, mimeInputs, userInput, isContextual);
+}
+
+} // namespace Notification
+} // namespace OHOS
+
+#endif // MOCK_NOTIFICATION_ACTION_BUTTON_BUILDER_H
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_bundle_option.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_bundle_option.h
new file mode 100644
index 0000000000000000000000000000000000000000..9c134bef68d16befdf2f8c91c913d03557fa96a0
--- /dev/null
+++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_bundle_option.h
@@ -0,0 +1,40 @@
+/*
+ * 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_BUNDLE_OPTION_BUILDER_H
+#define MOCK_NOTIFICATION_BUNDLE_OPTION_BUILDER_H
+
+#include "mock_fuzz_object.h"
+#include "notification_bundle_option.h"
+
+namespace OHOS {
+namespace Notification {
+
+template <>
+NotificationBundleOption* ObjectBuilder::Build(FuzzedDataProvider *fdp)
+{
+ std::string bundleName = fdp->ConsumeRandomLengthString(32);
+ int32_t uid = fdp->ConsumeIntegral();
+ auto bundleOption = new NotificationBundleOption(bundleName, uid);
+ bundleOption->SetInstanceKey(fdp->ConsumeIntegral());
+ bundleOption->SetAppInstanceKey(fdp->ConsumeRandomLengthString(16));
+ bundleOption->SetAppIndex(fdp->ConsumeIntegral());
+ ANS_LOGE("Build mock veriables");
+ return bundleOption;
+}
+} // namespace Notification
+} // namespace OHOS
+
+#endif // MOCK_NOTIFICATION_BUNDLE_OPTION_BUILDER_H
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_content.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_content.h
new file mode 100644
index 0000000000000000000000000000000000000000..2dbe094d2706a7348fced99a506e9a06abd27ab2
--- /dev/null
+++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_content.h
@@ -0,0 +1,54 @@
+/*
+ * 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_CONTENT_BUILDER_H
+#define MOCK_NOTIFICATION_CONTENT_BUILDER_H
+
+#include "mock_fuzz_object.h"
+#include "notification_content.h"
+#include "mock_notification_conversational_content.h"
+#include "mock_notification_media_content.h"
+#include "mock_notification_live_view_content.h"
+#include "mock_notification_multiline_content.h"
+#include "mock_notification_normal_content.h"
+
+namespace OHOS {
+namespace Notification {
+
+template <>
+NotificationContent* ObjectBuilder::Build(FuzzedDataProvider *fdp)
+{
+ int caseNum = fdp->ConsumeIntegralInRange(0, 5);
+ ANS_LOGE("Build mock veriables");
+ switch (caseNum) {
+ case 0:
+ return reinterpret_cast(ObjectBuilder::Build(fdp));
+ case 1:
+ return reinterpret_cast(ObjectBuilder::Build(fdp));
+ case 2:
+ return reinterpret_cast(ObjectBuilder::Build(fdp));
+ case 3:
+ return reinterpret_cast(ObjectBuilder::Build(fdp));
+ case 4:
+ return reinterpret_cast(ObjectBuilder::Build(fdp));
+ default:
+ return reinterpret_cast(ObjectBuilder::Build(fdp));
+ }
+}
+
+} // namespace Notification
+} // namespace OHOS
+
+#endif // MOCK_NOTIFICATION_CONTENT_BUILDER_H
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_conversational_content.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_conversational_content.h
new file mode 100644
index 0000000000000000000000000000000000000000..9052fd2f3cd085765cc3217eed98a8245bb10548
--- /dev/null
+++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_conversational_content.h
@@ -0,0 +1,47 @@
+/*
+ * 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_CONVERSATIONAL_CONTENT_BUILDER_H
+#define MOCK_NOTIFICATION_CONVERSATIONAL_CONTENT_BUILDER_H
+
+#include "mock_fuzz_object.h"
+#include "notification_conversational_content.h"
+
+namespace OHOS {
+namespace Notification {
+
+template <>
+NotificationConversationalContent* ObjectBuilder::Build(FuzzedDataProvider *fdp)
+{
+ MessageUser user;
+ user.SetKey(fdp->ConsumeRandomLengthString());
+ user.SetName(fdp->ConsumeRandomLengthString());
+ user.SetMachine(fdp->ConsumeBool());
+ user.SetUserAsImportant(fdp->ConsumeBool());
+ auto content = new NotificationConversationalContent(user);
+ content->SetText(fdp->ConsumeRandomLengthString());
+ content->SetTitle(fdp->ConsumeRandomLengthString());
+ content->SetAdditionalText(fdp->ConsumeRandomLengthString());
+ content->SetConversationTitle(fdp->ConsumeRandomLengthString(32));
+ content->SetConversationGroup(fdp->ConsumeBool());
+ content->AddConversationalMessage(fdp->ConsumeRandomLengthString(), fdp->ConsumeIntegral(), user);
+ ANS_LOGE("Build mock veriables");
+ return content;
+}
+
+} // namespace Notification
+} // namespace OHOS
+
+#endif // MOCK_NOTIFICATION_CONVERSATIONAL_CONTENT_BUILDER_H
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_distributed_options.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_distributed_options.h
new file mode 100644
index 0000000000000000000000000000000000000000..2d2abe789ef50f8fd4ee34aeb2108b542850fcd4
--- /dev/null
+++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_distributed_options.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_DISTRIBUTED_OPTIONS_BUILDER_H
+#define MOCK_NOTIFICATION_DISTRIBUTED_OPTIONS_BUILDER_H
+
+#include "mock_fuzz_object.h"
+#include "notification_distributed_options.h"
+
+namespace OHOS {
+namespace Notification {
+template<>
+NotificationDistributedOptions* ObjectBuilder::Build(FuzzedDataProvider *fdp)
+{
+ bool distribute = fdp->ConsumeBool();
+ std::vector devicesSupportDisplay;
+ for (int i = 0; i < fdp->ConsumeIntegralInRange(0, 10); ++i) {
+ devicesSupportDisplay.push_back(fdp->ConsumeRandomLengthString());
+ }
+ std::vector devicesSupportOperate;
+ for (int i = 0; i < fdp->ConsumeIntegralInRange(0, 10); ++i) {
+ devicesSupportOperate.push_back(fdp->ConsumeRandomLengthString());
+ }
+ ANS_LOGE("Build mock veriables");
+
+ return new NotificationDistributedOptions(distribute, devicesSupportDisplay, devicesSupportOperate);
+}
+} // namespace Notification
+} // namespace OHOS
+
+#endif // MOCK_NOTIFICATION_DISTRIBUTED_OPTIONS_BUILDER_H
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_flags.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_flags.h
new file mode 100644
index 0000000000000000000000000000000000000000..a4079a28db3e9e6a4c91547ff1dbdd73af2a752f
--- /dev/null
+++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_flags.h
@@ -0,0 +1,42 @@
+/*
+ * 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_FLAGS_BUILDER_H
+#define MOCK_NOTIFICATION_FLAGS_BUILDER_H
+
+#include "mock_fuzz_object.h"
+#include "notification_flags.h"
+
+namespace OHOS {
+namespace Notification {
+
+template <>
+NotificationFlags* ObjectBuilder::Build(FuzzedDataProvider *fdp)
+{
+ auto flags = new NotificationFlags();
+ flags->SetSoundEnabled(static_cast(fdp->ConsumeIntegral()));
+ flags->SetVibrationEnabled(static_cast(fdp->ConsumeIntegral()));
+ flags->SetReminderFlags(fdp->ConsumeIntegral());
+ flags->SetLockScreenVisblenessEnabled(fdp->ConsumeBool());
+ flags->SetBannerEnabled(fdp->ConsumeBool());
+ flags->SetLightScreenEnabled(fdp->ConsumeBool());
+ flags->SetStatusIconEnabled(fdp->ConsumeBool());
+ ANS_LOGE("Build mock veriables");
+ return flags;
+}
+} // namespace Notification
+} // namespace OHOS
+
+#endif // MOCK_NOTIFICATION_FLAGS_BUILDER_H
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_live_view_content.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_live_view_content.h
new file mode 100644
index 0000000000000000000000000000000000000000..4e575b8144d61898c44ef86de6a02d035b656e07
--- /dev/null
+++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_live_view_content.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_LIVE_VIEW_CONTENT_BUILDER_H
+#define MOCK_NOTIFICATION_LIVE_VIEW_CONTENT_BUILDER_H
+
+#include "mock_fuzz_object.h"
+#include "notification_live_view_content.h"
+
+namespace OHOS {
+namespace Notification {
+
+template <>
+NotificationLiveViewContent* ObjectBuilder::Build(FuzzedDataProvider *fdp)
+{
+ auto content = new NotificationLiveViewContent();
+ content->SetText(fdp->ConsumeRandomLengthString());
+ content->SetTitle(fdp->ConsumeRandomLengthString());
+ content->SetAdditionalText(fdp->ConsumeRandomLengthString());
+ auto status = static_cast(fdp->ConsumeIntegralInRange(0, 4));
+ content->SetLiveViewStatus(status);
+ content->SetVersion(fdp->ConsumeIntegral());
+ content->SetIsOnlyLocalUpdate(fdp->ConsumeBool());
+ ANS_LOGE("Build mock veriables");
+ return content;
+}
+
+} // namespace Notification
+} // namespace OHOS
+
+#endif // MOCK_NOTIFICATION_LIVE_VIEW_CONTENT_BUILDER_H
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_media_content.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_media_content.h
new file mode 100644
index 0000000000000000000000000000000000000000..ea91ef1ecb235e23ac0dbfaae72e65125f9922e2
--- /dev/null
+++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_media_content.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_MEDIA_CONTENT_BUILDER_H
+#define MOCK_NOTIFICATION_MEDIA_CONTENT_BUILDER_H
+
+#include "mock_fuzz_object.h"
+#include "notification_media_content.h"
+
+namespace OHOS {
+namespace Notification {
+
+template<>
+NotificationMediaContent* ObjectBuilder::Build(FuzzedDataProvider *fdp)
+{
+ std::vector actions;
+ for (int i = 0; i < fdp->ConsumeIntegralInRange(0, 10); i++) {
+ actions.push_back(fdp->ConsumeIntegral());
+ }
+
+ auto mediaContent = new NotificationMediaContent();
+ mediaContent->SetText(fdp->ConsumeRandomLengthString());
+ mediaContent->SetTitle(fdp->ConsumeRandomLengthString());
+ mediaContent->SetAdditionalText(fdp->ConsumeRandomLengthString());
+ mediaContent->SetShownActions(actions);
+ ANS_LOGE("Build mock veriables");
+ return mediaContent;
+}
+} // namespace Notification
+} // namespace OHOS
+
+#endif // MOCK_NOTIFICATION_MEDIA_CONTENT_BUILDER_H
\ No newline at end of file
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_multiline_content.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_multiline_content.h
new file mode 100644
index 0000000000000000000000000000000000000000..07cbd608377d45788d0591177f99cb6816450aa4
--- /dev/null
+++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_multiline_content.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_MULTILINE_CONTENT_BUILDER_H
+#define MOCK_NOTIFICATION_MULTILINE_CONTENT_BUILDER_H
+
+#include "mock_fuzz_object.h"
+#include "notification_multiline_content.h"
+
+namespace OHOS {
+namespace Notification {
+
+template <>
+NotificationMultiLineContent* ObjectBuilder::Build(FuzzedDataProvider *fdp)
+{
+ NotificationMultiLineContent* multiLineContent = new NotificationMultiLineContent();
+ multiLineContent->SetText(fdp->ConsumeRandomLengthString());
+ multiLineContent->SetTitle(fdp->ConsumeRandomLengthString());
+ multiLineContent->SetAdditionalText(fdp->ConsumeRandomLengthString());
+ multiLineContent->SetExpandedTitle(fdp->ConsumeRandomLengthString());
+ multiLineContent->SetBriefText(fdp->ConsumeRandomLengthString());
+ for (int i = 0; i < fdp->ConsumeIntegralInRange(0, 10); i++) {
+ multiLineContent->AddSingleLine(fdp->ConsumeRandomLengthString());
+ }
+ ANS_LOGE("Build mock veriables");
+ return multiLineContent;
+}
+
+} // namespace Notification
+} // namespace OHOS
+
+#endif // MOCK_NOTIFICATION_MULTILINE_CONTENT_H
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_normal_content.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_normal_content.h
new file mode 100644
index 0000000000000000000000000000000000000000..5ac42a17d7d65bfb096692f5f581aa73ce6de5ac
--- /dev/null
+++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_normal_content.h
@@ -0,0 +1,39 @@
+/*
+ * 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_NORMAL_CONTENT_BUILDER_H
+#define MOCK_NOTIFICATION_NORMAL_CONTENT_BUILDER_H
+
+#include "mock_fuzz_object.h"
+#include "notification_normal_content.h"
+
+namespace OHOS {
+namespace Notification {
+
+template <>
+NotificationNormalContent* ObjectBuilder::Build(FuzzedDataProvider *fdp)
+{
+ auto normalContent = new NotificationNormalContent();
+ normalContent->SetText(fdp->ConsumeRandomLengthString());
+ normalContent->SetTitle(fdp->ConsumeRandomLengthString());
+ normalContent->SetAdditionalText(fdp->ConsumeRandomLengthString());
+ ANS_LOGE("Build mock veriables");
+ return normalContent;
+}
+
+} // namespace Notification
+} // namespace OHOS
+
+#endif // MOCK_NOTIFICATION_NORMAL_CONTENT_BUILDER_H
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_request.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_request.h
new file mode 100644
index 0000000000000000000000000000000000000000..206a6a62d1cea14a3a744684fdbc46d9966909bb
--- /dev/null
+++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_request.h
@@ -0,0 +1,177 @@
+/*
+ * 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_REQUEST_BUILDER_H
+#define MOCK_NOTIFICATION_REQUEST_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 "mock_pixel_map.h"
+#include "mock_want_params.h"
+#include "notification_request.h"
+
+
+namespace OHOS {
+namespace Notification {
+void GenerateBooleanTypeVeriables(FuzzedDataProvider* fdp, NotificationRequest* request)
+{
+ request->SetColorEnabled(fdp->ConsumeBool());
+ request->SetAlertOneTime(fdp->ConsumeBool());
+ request->SetShowStopwatch(fdp->ConsumeBool());
+ request->SetCountdownTimer(fdp->ConsumeBool());
+ request->SetInProgress(fdp->ConsumeBool());
+ request->SetGroupOverview(fdp->ConsumeBool());
+ request->SetUnremovable(fdp->ConsumeBool());
+ request->SetFloatingIcon(fdp->ConsumeBool());
+ request->SetOnlyLocal(fdp->ConsumeBool());
+ request->SetPermitSystemGeneratedContextualActionButtons(fdp->ConsumeBool());
+ request->SetIsAgentNotification(fdp->ConsumeBool());
+ request->SetRemoveAllowed(fdp->ConsumeBool());
+ request->SetIsCoverActionButtons(fdp->ConsumeBool());
+ request->SetUpdateByOwnerAllowed(fdp->ConsumeBool());
+ request->SetUpdateOnly(fdp->ConsumeBool());
+ request->SetForceDistributed(fdp->ConsumeBool());
+ request->SetNotDistributed(fdp->ConsumeBool());
+ request->SetInProgress(fdp->ConsumeBool());
+ request->SetIsSystemApp(fdp->ConsumeBool());
+ request->SetIsDoNotDisturbByPassed(fdp->ConsumeBool());
+ request->SetDistributedCollaborate(fdp->ConsumeBool());
+ ANS_LOGE("Build mock veriables");
+}
+
+void GenerateIntegerTypeVeriables(FuzzedDataProvider* fdp, NotificationRequest* request)
+{
+ request->SetPublishDelayTime(fdp->ConsumeIntegral());
+ request->SetNotificationId(fdp->ConsumeIntegral());
+ request->SetColor(fdp->ConsumeIntegral());
+ request->SetBadgeNumber(fdp->ConsumeIntegral());
+ request->SetNotificationControlFlags(fdp->ConsumeIntegral());
+ request->SetCreateTime(fdp->ConsumeIntegral());
+ request->SetDeliveryTime(fdp->ConsumeIntegral());
+ request->SetAutoDeletedTime(fdp->ConsumeIntegral());
+ request->SetUpdateDeadLine(fdp->ConsumeIntegral());
+ request->SetFinishDeadLine(fdp->ConsumeIntegral());
+ request->SetArchiveDeadLine(fdp->ConsumeIntegral());
+ if (fdp->ConsumeIntegral() % 3 == 0) {
+ request->SetCreatorPid(fdp->ConsumeIntegral());
+ }
+ if (fdp->ConsumeIntegral() % 3 == 0) {
+ request->SetCreatorUid(fdp->ConsumeIntegralInRange(0, 10000));
+ }
+ if (fdp->ConsumeIntegral() % 3 == 0) {
+ request->SetOwnerUid(fdp->ConsumeIntegralInRange(0, 10000));
+ }
+ if (fdp->ConsumeIntegral() % 3 == 0) {
+ request->SetCreatorUserId(fdp->ConsumeIntegralInRange(0, 105));
+ }
+ if (fdp->ConsumeIntegral() % 3 == 0) {
+ request->SetOwnerUserId(fdp->ConsumeIntegralInRange(0, 105));
+ }
+ if (fdp->ConsumeIntegral() % 3 == 0) {
+ request->SetReceiverUserId(fdp->ConsumeIntegralInRange(0, 105));
+ }
+ request->SetCreatorInstanceKey(fdp->ConsumeIntegral());
+ request->SetHashCodeGenerateType(fdp->ConsumeIntegral());
+ request->SetCollaboratedReminderFlag(fdp->ConsumeIntegral());
+ ANS_LOGE("Build mock veriables");
+}
+
+void GenerateStringTypeVeriables(FuzzedDataProvider* fdp, NotificationRequest* request)
+{
+ request->SetAppInstanceKey(fdp->ConsumeRandomLengthString(20));
+ request->SetSettingsText(fdp->ConsumeRandomLengthString(20));
+ if (fdp->ConsumeIntegral() % 3 == 0) {
+ request->SetCreatorBundleName(fdp->ConsumeRandomLengthString(20));
+ }
+ if (fdp->ConsumeIntegral() % 3 == 0) {
+ request->SetOwnerBundleName(fdp->ConsumeRandomLengthString(20));
+ }
+ request->SetGroupName(fdp->ConsumeRandomLengthString(20));
+ request->SetStatusBarText(fdp->ConsumeRandomLengthString(20));
+ request->SetLabel(fdp->ConsumeRandomLengthString(20));
+ request->SetShortcutId(fdp->ConsumeRandomLengthString(20));
+ request->SetSortingKey(fdp->ConsumeRandomLengthString(20));
+ request->SetClassification(fdp->ConsumeRandomLengthString(20));
+ request->SetAppMessageId(fdp->ConsumeRandomLengthString(20));
+ request->SetSound(fdp->ConsumeRandomLengthString(20));
+ request->SetDistributedHashCode(fdp->ConsumeRandomLengthString(20));
+ ANS_LOGE("Build mock veriables");
+}
+
+void GenerateEnumTypeVeriables(FuzzedDataProvider* fdp, NotificationRequest* request)
+{
+ request->SetBadgeIconStyle(static_cast(
+ fdp->ConsumeIntegralInRange(0, 3)));
+ request->SetGroupAlertType(static_cast(
+ fdp->ConsumeIntegralInRange(0, 3)));
+ request->SetSlotType(static_cast(
+ fdp->ConsumeIntegralInRange(0, 5)));
+ request->SetVisibleness(static_cast(
+ fdp->ConsumeIntegralInRange(0, 2)));
+ ANS_LOGE("Build mock veriables");
+}
+
+template <>
+NotificationRequest* ObjectBuilder::Build(FuzzedDataProvider *fdp)
+{
+ auto request = new NotificationRequest();
+ GenerateIntegerTypeVeriables(fdp, request);
+ GenerateBooleanTypeVeriables(fdp, request);
+ GenerateStringTypeVeriables(fdp, request);
+ GenerateEnumTypeVeriables(fdp, request);
+
+ request->SetContent(ObjectBuilder::BuildSharedPtr(fdp));
+ request->SetTemplate(ObjectBuilder::BuildSharedPtr(fdp));
+ request->SetBundleOption(ObjectBuilder::BuildSharedPtr(fdp));
+ request->SetAgentBundle(ObjectBuilder::BuildSharedPtr(fdp));
+ request->SetAdditionalData(ObjectBuilder::BuildSharedPtr(fdp));
+ request->SetLittleIcon(ObjectBuilder::BuildSharedPtr(fdp));
+ request->SetBigIcon(ObjectBuilder::BuildSharedPtr(fdp));
+ request->SetOverlayIcon(ObjectBuilder::BuildSharedPtr(fdp));
+
+ size_t actionCount = fdp->ConsumeIntegralInRange(0, 3);
+ for (size_t i = 0; i < actionCount; ++i) {
+ request->AddActionButton(ObjectBuilder::BuildSharedPtr(fdp));
+ }
+ std::vector devicesSupportDisplay;
+ for(int i = 0; i < fdp->ConsumeIntegralInRange(0, 10); i++) {
+ devicesSupportDisplay.push_back(fdp->ConsumeRandomLengthString());
+ }
+ request->SetDevicesSupportDisplay(devicesSupportDisplay);
+ std::vector devicesSupportOperate;
+ for(int i = 0; i < fdp->ConsumeIntegralInRange(0, 10); i++) {
+ devicesSupportOperate.push_back(fdp->ConsumeRandomLengthString());
+ }
+ request->SetDevicesSupportOperate(devicesSupportOperate);
+ std::vector userInputHistory;
+ for(int i = 0; i < fdp->ConsumeIntegralInRange(0, 10); i++) {
+ userInputHistory.push_back(fdp->ConsumeRandomLengthString());
+ }
+ request->SetNotificationUserInputHistory(userInputHistory);
+ ANS_LOGE("Build mock veriables");
+ return request;
+}
+
+
+
+} // namespace Notification
+} // namespace OHOS
+
+#endif // MOCK_NOTIFICATION_REQUEST_BUILDER_H
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_template.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_template.h
new file mode 100644
index 0000000000000000000000000000000000000000..7040fa11ad71be162a22eee38e6fa37c2cba5631
--- /dev/null
+++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_template.h
@@ -0,0 +1,39 @@
+/*
+ * 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_TEMPLATE_BUILDER_H
+#define MOCK_NOTIFICATION_TEMPLATE_BUILDER_H
+
+#include "mock_fuzz_object.h"
+#include "mock_want_params.h"
+#include "notification_template.h"
+
+namespace OHOS {
+namespace Notification {
+
+template <>
+NotificationTemplate* ObjectBuilder::Build(FuzzedDataProvider *fdp)
+{
+ NotificationTemplate* templateObject = new NotificationTemplate();
+ templateObject->SetTemplateName(fdp->ConsumeRandomLengthString());
+ templateObject->SetTemplateData(ObjectBuilder::BuildSharedPtr(fdp));
+ ANS_LOGE("Build mock veriables");
+ return templateObject;
+}
+
+} // namespace Notification
+} // namespace OHOS
+
+#endif // MOCK_NOTIFICATION_TEMPLATE_BUILDER_H
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_user_input.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_user_input.h
new file mode 100644
index 0000000000000000000000000000000000000000..1ac5c8da0f679629aa9511ee54ee244f0e4541e0
--- /dev/null
+++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_user_input.h
@@ -0,0 +1,51 @@
+/*
+ * 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_USER_INPUT_BUILDER_H
+#define MOCK_NOTIFICATION_USER_INPUT_BUILDER_H
+
+#include "mock_fuzz_object.h"
+#include "notification_user_input.h"
+#include "mock_want_params.h"
+
+namespace OHOS {
+namespace Notification {
+
+template <>
+std::shared_ptr ObjectBuilder::BuildSharedPtr(FuzzedDataProvider *fdp)
+{
+ std::string inputKey = fdp->ConsumeRandomLengthString(20);
+ std::string tag = fdp->ConsumeRandomLengthString(10);
+ std::vector options;
+ for (size_t i = 0; i < fdp->ConsumeIntegralInRange(0, 5); ++i) {
+ options.push_back(fdp->ConsumeRandomLengthString(15));
+ }
+ bool permitFreeFormInput = fdp->ConsumeBool();
+ std::set permitMimeTypes;
+ for (size_t i = 0; i < fdp->ConsumeIntegralInRange(0, 3); ++i) {
+ permitMimeTypes.insert(fdp->ConsumeRandomLengthString(10));
+ }
+ auto additional = ObjectBuilder::BuildSharedPtr(fdp);
+ NotificationConstant::InputEditType editType = static_cast(
+ fdp->ConsumeIntegralInRange(0, 2));
+
+ ANS_LOGE("Build mock veriables");
+ return NotificationUserInput::Create(inputKey, tag, options, permitFreeFormInput,
+ permitMimeTypes, additional, editType);
+}
+} // namespace Notification
+} // namespace OHOS
+
+#endif // MOCK_NOTIFICATION_USER_INPUT_BUILDER_H
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_pixel_map.h b/test/fuzztest/fuzz_common_base/mock/mock_pixel_map.h
new file mode 100644
index 0000000000000000000000000000000000000000..38b707ae063b79b655da98b1855a95666399e53d
--- /dev/null
+++ b/test/fuzztest/fuzz_common_base/mock/mock_pixel_map.h
@@ -0,0 +1,65 @@
+/*
+ * 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_PIXEL_MAP_BUILDER_H
+#define MOCK_NOTIFICATION_PIXEL_MAP_BUILDER_H
+
+#include "mock_fuzz_object.h"
+
+#include "pixel_map.h"
+#include
+
+namespace OHOS {
+namespace Notification {
+
+constexpr uint32_t MAX_LENGTH_MODULO = 1024;
+constexpr uint32_t PIXELFORMAT_MODULO = 8;
+constexpr uint32_t ALPHATYPE_MODULO = 4;
+constexpr uint32_t SCALEMODE_MODULO = 2;
+
+std::unique_ptr GetPixelMapFromOpts(FuzzedDataProvider *fdp,
+ Media::PixelFormat pixelFormat = Media::PixelFormat::UNKNOWN)
+{
+ int32_t width = fdp->ConsumeIntegralInRange(0, MAX_LENGTH_MODULO);
+ int32_t height = fdp->ConsumeIntegralInRange(0, MAX_LENGTH_MODULO);
+ Media::InitializationOptions opts;
+ opts.size.width = width;
+ opts.size.height = height;
+ opts.srcPixelFormat = pixelFormat == Media::PixelFormat::UNKNOWN ?
+ static_cast(fdp->ConsumeIntegralInRange(0, PIXELFORMAT_MODULO)) : pixelFormat;
+ opts.pixelFormat = pixelFormat == Media::PixelFormat::UNKNOWN ?
+ static_cast(fdp->ConsumeIntegralInRange(0, PIXELFORMAT_MODULO)) : pixelFormat;
+ opts.alphaType = static_cast(fdp->ConsumeIntegralInRange(0, ALPHATYPE_MODULO));
+ opts.scaleMode = static_cast(fdp->ConsumeIntegralInRange(0, SCALEMODE_MODULO));
+ opts.editable = fdp->ConsumeBool();
+ opts.useSourceIfMatch = fdp->ConsumeBool();
+ return Media::PixelMap::Create(opts);
+}
+
+template <>
+std::shared_ptr ObjectBuilder::BuildSharedPtr(FuzzedDataProvider *fdp)
+{
+ auto pixelMap = GetPixelMapFromOpts(fdp);
+ if (pixelMap == nullptr) {
+ return nullptr;
+ }
+ ANS_LOGE("Build mock veriables");
+ return std::shared_ptr(std::move(pixelMap.release()));
+}
+
+} // namespace Notification
+} // namespace OHOS
+
+#endif // MOCK_NOTIFICATION_PIXEL_MAP_BUILDER_H
diff --git a/test/fuzztest/fuzz_common_base/mock/mock_want_params.h b/test/fuzztest/fuzz_common_base/mock/mock_want_params.h
new file mode 100644
index 0000000000000000000000000000000000000000..839cd7dc98ac7f88d096dde2b3b7be25631a9876
--- /dev/null
+++ b/test/fuzztest/fuzz_common_base/mock/mock_want_params.h
@@ -0,0 +1,41 @@
+/*
+ * 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_WANT_PARAMS_BUILDER_H
+#define MOCK_NOTIFICATION_WANT_PARAMS_BUILDER_H
+
+#include "mock_fuzz_object.h"
+#include "want.h"
+#include "want_params.h"
+
+namespace OHOS {
+namespace Notification {
+
+template <>
+AAFwk::WantParams* ObjectBuilder::Build(FuzzedDataProvider *fdp)
+{
+ AAFwk::Want want;
+ for (size_t i = 0; i < fdp->ConsumeIntegralInRange(0, 10); i++) {
+ want.SetParam(fdp->ConsumeRandomLengthString(10), fdp->ConsumeRandomLengthString(10));
+ want.SetParam(fdp->ConsumeRandomLengthString(10), fdp->ConsumeIntegral());
+ }
+ ANS_LOGE("Build mock veriables");
+ return new AAFwk::WantParams(want.GetParams());
+}
+
+} // namespace Notification
+} // namespace OHOS
+
+#endif // MOCK_NOTIFICATION_WANT_PARAMS_BUILDER_H