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 "getbundleimportance_fuzzer.h"
17
18 #include "notification_helper.h"
19 namespace OHOS {
20 namespace {
21 constexpr uint8_t NOTIFICATION_LEVEL_NUM = 6;
22 }
DoSomethingInterestingWithMyAPI(const char * data,size_t size)23 bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
24 {
25 // test CanPublishNotificationAsBundle function
26 std::string representativeBundle(data);
27 bool canPublish = true;
28 Notification::NotificationHelper::CanPublishNotificationAsBundle(representativeBundle, canPublish);
29 // test SetNotificationBadgeNum function and no parameter
30 Notification::NotificationHelper::SetNotificationBadgeNum();
31 // test IsAllowedNotify function
32 bool allowed = true;
33 Notification::NotificationHelper::IsAllowedNotify(allowed);
34 // test IsAllowedNotifySelf function
35 Notification::NotificationHelper::IsAllowedNotifySelf(allowed);
36 // test GetBundleImportance function
37 uint8_t levels = *data % NOTIFICATION_LEVEL_NUM;
38 Notification::NotificationSlot::NotificationLevel level =
39 Notification::NotificationSlot::NotificationLevel(levels);
40 return Notification::NotificationHelper::GetBundleImportance(level) == ERR_OK;
41 }
42 }
43
44 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)45 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
46 {
47 /* Run your code on data */
48 char *ch = ParseData(data, size);
49 if (ch != nullptr && size >= GetU32Size()) {
50 OHOS::DoSomethingInterestingWithMyAPI(ch, size);
51 free(ch);
52 ch = nullptr;
53 }
54 return 0;
55 }
56