• 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 "setnotificationsenabledforallbundles_fuzzer.h"
17 
18 #include "notification_helper.h"
19 #include <fuzzer/FuzzedDataProvider.h>
20 
21 namespace OHOS {
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)22     bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fdp)
23     {
24         // test SetNotificationsEnabledForAllBundles function
25         std::string stringData = fdp->ConsumeRandomLengthString();
26         bool enabled = fdp->ConsumeBool();
27         Notification::NotificationHelper::SetNotificationsEnabledForAllBundles(stringData, enabled);
28         // test SetNotificationsEnabledForDefaultBundle function
29         Notification::NotificationHelper::SetNotificationsEnabledForDefaultBundle(stringData, enabled);
30         // test SetNotificationsEnabledForSpecifiedBundle function
31         int32_t usingData = fdp->ConsumeIntegral<int32_t>();
32         Notification::NotificationBundleOption bundleOption;
33         bundleOption.SetBundleName(stringData);
34         bundleOption.SetUid(usingData);
35         Notification::NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(bundleOption, stringData, enabled);
36         // test SetShowBadgeEnabledForBundle function
37         Notification::NotificationHelper::SetShowBadgeEnabledForBundle(bundleOption, enabled);
38         // test GetShowBadgeEnabledForBundle function
39         return Notification::NotificationHelper::GetShowBadgeEnabledForBundle(bundleOption, enabled);
40     }
41 }
42 
43 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)44 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
45 {
46     /* Run your code on data */
47     FuzzedDataProvider fdp(data, size);
48     OHOS::DoSomethingInterestingWithMyAPI(&fdp);
49     return 0;
50 }
51