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 HandleOnConsumedMap function
39 ansSubscriberStub.HandleOnConsumedMap(datas, reply);
40 // test HandleOnCanceledMap function
41 ansSubscriberStub.HandleOnCanceledMap(datas, reply);
42 // test HandleOnUpdated function
43 ansSubscriberStub.HandleOnUpdated(datas, reply);
44 // test HandleOnDoNotDisturbDateChange function
45 ansSubscriberStub.HandleOnDoNotDisturbDateChange(datas, reply);
46 // test HandleOnEnabledNotificationChanged function
47 ansSubscriberStub.HandleOnEnabledNotificationChanged(datas, reply);
48 // test OnConnected function
49 ansSubscriberStub.OnConnected();
50 // test OnDisconnected function
51 ansSubscriberStub.OnDisconnected();
52 // test OnConsumed function
53 sptr<Notification::Notification> notification = new Notification::Notification();
54 sptr<Notification::NotificationSortingMap> notificationMap = new Notification::NotificationSortingMap();
55 ansSubscriberStub.OnConsumed(notification, notificationMap);
56 // test OnCanceled function
57 int32_t deleteReason = 1;
58 ansSubscriberStub.OnCanceled(notification, notificationMap, deleteReason);
59 // test OnUpdated function
60 ansSubscriberStub.OnUpdated(notificationMap);
61 // test OnDoNotDisturbDateChange function
62 sptr<Notification::NotificationDoNotDisturbDate> date = new Notification::NotificationDoNotDisturbDate();
63 ansSubscriberStub.OnDoNotDisturbDateChange(date);
64 // test OnEnabledNotificationChanged function
65 sptr<Notification::EnabledNotificationCallbackData> callbackData = new Notification::EnabledNotificationCallbackData();
66 return true;
67 }
68 }
69
70 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)71 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
72 {
73 /* Run your code on data */
74 char *ch = ParseData(data, size);
75 if (ch != nullptr && size >= GetU32Size()) {
76 OHOS::DoSomethingInterestingWithMyAPI(ch, size);
77 free(ch);
78 ch = nullptr;
79 }
80 return 0;
81 }
82