• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace OHOS {
20     namespace {
21         constexpr uint8_t ENABLE = 2;
22         constexpr uint8_t SLOT_TYPE_NUM = 5;
23     }
DoSomethingInterestingWithMyAPI(const char * data,size_t size)24     bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
25     {
26         int32_t userId = static_cast<int32_t>(GetU32Data(data));
27         uint32_t type = GetU32Data(data);
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(data);
38         Notification::NotificationBundleOption bundleOption;
39         bundleOption.SetBundleName(stringData);
40         bundleOption.SetUid(userId);
41         uint8_t types = *data % SLOT_TYPE_NUM;
42         Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(types);
43         bool enabled = *data % ENABLE;
44         Notification::NotificationHelper::SetEnabledForBundleSlot(bundleOption, slotType, enabled);
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     char *ch = ParseData(data, size);
61     if (ch != nullptr && size >= GetU32Size()) {
62         OHOS::DoSomethingInterestingWithMyAPI(ch, size);
63         free(ch);
64         ch = nullptr;
65     }
66     return 0;
67 }
68