• 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 #define private public
17 #define protected public
18 #include "ans_subscriber_stub.h"
19 #undef private
20 #undef protected
21 #include "anssubscriberstub_fuzzer.h"
22 #include "notification_request.h"
23 
24 namespace OHOS {
DoSomethingInterestingWithMyAPI(const char * data,size_t size)25     bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
26     {
27         Notification::AnsSubscriberStub ansSubscriberStub;
28         uint32_t code = GetU32Data(data);
29         MessageParcel datas;
30         MessageParcel reply;
31         MessageOption flags;
32         // test OnRemoteRequest function
33         ansSubscriberStub.OnRemoteRequest(code, datas, reply, flags);
34         // test HandleOnConnected function
35         ansSubscriberStub.HandleOnConnected(datas, reply);
36         // test HandleOnDisconnected function
37         ansSubscriberStub.HandleOnDisconnected(datas, reply);
38         // test HandleOnConsumed function
39         ansSubscriberStub.HandleOnConsumed(datas, reply);
40         // test HandleOnConsumedMap function
41         ansSubscriberStub.HandleOnConsumedMap(datas, reply);
42         // test HandleOnCanceledMap function
43         ansSubscriberStub.HandleOnCanceledMap(datas, reply);
44         // test HandleOnUpdated function
45         ansSubscriberStub.HandleOnUpdated(datas, reply);
46         // test HandleOnDoNotDisturbDateChange function
47         ansSubscriberStub.HandleOnDoNotDisturbDateChange(datas, reply);
48         // test HandleOnEnabledNotificationChanged function
49         ansSubscriberStub.HandleOnEnabledNotificationChanged(datas, reply);
50         // test OnConnected function
51         ansSubscriberStub.OnConnected();
52         // test OnDisconnected function
53         ansSubscriberStub.OnDisconnected();
54         // test OnConsumed function
55         sptr<Notification::Notification> notification = new Notification::Notification();
56         ansSubscriberStub.OnConsumed(notification);
57         // test OnConsumed function
58         sptr<Notification::NotificationSortingMap> notificationMap = new Notification::NotificationSortingMap();
59         ansSubscriberStub.OnConsumed(notification, notificationMap);
60         // test OnCanceled function
61         int32_t deleteReason = 1;
62         ansSubscriberStub.OnCanceled(notification, notificationMap, deleteReason);
63         // test OnUpdated function
64         ansSubscriberStub.OnUpdated(notificationMap);
65         // test OnDoNotDisturbDateChange function
66         sptr<Notification::NotificationDoNotDisturbDate> date = new Notification::NotificationDoNotDisturbDate();
67         ansSubscriberStub.OnDoNotDisturbDateChange(date);
68         // test OnEnabledNotificationChanged function
69         sptr<Notification::EnabledNotificationCallbackData> callbackData = new Notification::EnabledNotificationCallbackData();
70         return true;
71     }
72 }
73 
74 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)75 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
76 {
77     /* Run your code on data */
78     char *ch = ParseData(data, size);
79     if (ch != nullptr && size >= GetU32Size()) {
80         OHOS::DoSomethingInterestingWithMyAPI(ch, size);
81         free(ch);
82         ch = nullptr;
83     }
84     return 0;
85 }
86