1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "setdonotdisturbdate_fuzzer.h"
17
18 #include "notification_helper.h"
19 #include <fuzzer/FuzzedDataProvider.h>
20 namespace OHOS {
21 namespace {
22 constexpr uint8_t SLOT_TYPE_NUM = 5;
23 }
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)24 bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fdp)
25 {
26 int32_t userId = fdp->ConsumeIntegral<int32_t>();
27 uint32_t type = fdp->ConsumeIntegral<uint32_t>();
28 Notification::NotificationDoNotDisturbDate disturb;
29 Notification::NotificationConstant::DoNotDisturbType disturbType =
30 Notification::NotificationConstant::DoNotDisturbType(type);
31 disturb.SetDoNotDisturbType(disturbType);
32 // test SetDoNotDisturbDate function
33 Notification::NotificationHelper::SetDoNotDisturbDate(userId, disturb);
34 // test GetDoNotDisturbDate function
35 Notification::NotificationHelper::GetDoNotDisturbDate(userId, disturb);
36 // test SetEnabledForBundleSlot function
37 std::string stringData = fdp->ConsumeRandomLengthString();
38 Notification::NotificationBundleOption bundleOption;
39 bundleOption.SetBundleName(stringData);
40 bundleOption.SetUid(userId);
41 uint8_t types = fdp->ConsumeIntegral<uint8_t>() % SLOT_TYPE_NUM;
42 Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(types);
43 bool enabled = fdp->ConsumeBool();
44 Notification::NotificationHelper::SetEnabledForBundleSlot(bundleOption, slotType, enabled, false);
45 // test GetEnabledForBundleSlot function
46 Notification::NotificationHelper::GetEnabledForBundleSlot(bundleOption, slotType, enabled);
47 // test SetSyncNotificationEnabledWithoutApp function
48 Notification::NotificationHelper::SetSyncNotificationEnabledWithoutApp(userId, enabled);
49 // test GetSyncNotificationEnabledWithoutApp function
50 Notification::NotificationHelper::GetSyncNotificationEnabledWithoutApp(userId, enabled);
51 // test RemoveNotifications function
52 return Notification::NotificationHelper::RemoveNotifications(userId);
53 }
54 }
55
56 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)57 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
58 {
59 /* Run your code on data */
60 FuzzedDataProvider fdp(data, size);
61 OHOS::DoSomethingInterestingWithMyAPI(&fdp);
62 return 0;
63 }
64