• 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 "reminder_request_calendar.h"
19 #undef private
20 #undef protected
21 #include "reminderrequestcalendar_fuzzer.h"
22 
23 namespace OHOS {
24     namespace {
25         constexpr uint8_t MONTHS = 12;
26         constexpr uint8_t DAYS = 31;
27         constexpr uint16_t YEAR = 365;
28         constexpr uint16_t HOURS = 24;
29         constexpr uint16_t MINUTES = 60;
30         constexpr uint16_t SECONDS = 60;
31         constexpr uint8_t ENABLE = 2;
32     }
DoSomethingInterestingWithMyAPI(const char * data,size_t size)33     bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
34     {
35         struct tm nowTime;
36         uint8_t months = *data % MONTHS;
37         uint8_t days = *data % DAYS;
38         std::vector<uint8_t> repeatMonths;
39         std::vector<uint8_t> repeatDays;
40         repeatMonths.push_back(months);
41         repeatDays.push_back(days);
42         Notification::ReminderRequestCalendar reminderRequestCalendar(nowTime, repeatMonths, repeatDays);
43         // test SetNextTriggerTime function
44         reminderRequestCalendar.SetNextTriggerTime();
45         // test InitDateTime function
46         reminderRequestCalendar.InitDateTime();
47         // test InitDateTime function
48         reminderRequestCalendar.InitDateTime(nowTime);
49         // test SetDay function
50         bool enabled = *data % ENABLE;
51         reminderRequestCalendar.SetDay(days, enabled);
52         // test SetMonth function
53         reminderRequestCalendar.SetMonth(months, enabled);
54         // test SetRepeatMonths function
55         reminderRequestCalendar.SetRepeatMonths(repeatMonths);
56         // test SetRepeatDaysOfMonth function
57         reminderRequestCalendar.SetRepeatDaysOfMonth(repeatDays);
58         // test GetRepeatMonths function
59         reminderRequestCalendar.GetRepeatMonths();
60         // test GetRepeatDays function
61         reminderRequestCalendar.GetRepeatDays();
62         // test GetDaysOfMonth function
63         uint16_t year = *data % YEAR;
64         reminderRequestCalendar.GetDaysOfMonth(year, months);
65         // test GetNextDay function
66         struct tm target;
67         reminderRequestCalendar.GetNextDay(year, months, nowTime, target);
68         // test GetNextTriggerTime function
69         reminderRequestCalendar.GetNextTriggerTime();
70         // test GetNextTriggerTimeAsRepeatReminder function
71         struct tm tarTime;
72         reminderRequestCalendar.GetNextTriggerTimeAsRepeatReminder(nowTime, tarTime);
73         // test GetTimeInstantMilli function
74         uint8_t hour = *data % HOURS;
75         uint8_t minute = *data % MINUTES;
76         uint8_t second = *data % SECONDS;
77         reminderRequestCalendar.GetTimeInstantMilli(year, months, days, hour, minute, second);
78         // test IsRepeatReminder function
79         reminderRequestCalendar.IsRepeatReminder();
80         // test IsRepeatMonth function
81         reminderRequestCalendar.IsRepeatMonth(months);
82         // test IsRepeatDay function
83         reminderRequestCalendar.IsRepeatDay(days);
84         // test OnDateTimeChange function
85         reminderRequestCalendar.OnDateTimeChange();
86         // test OnTimeZoneChange function
87         reminderRequestCalendar.OnTimeZoneChange();
88         // test UpdateNextReminder function
89         reminderRequestCalendar.UpdateNextReminder();
90         // test PreGetNextTriggerTimeIgnoreSnooze function
91         reminderRequestCalendar.PreGetNextTriggerTimeIgnoreSnooze(enabled, enabled);
92         // test RecoverFromDb function
93         std::shared_ptr<NativeRdb::AbsSharedResultSet> resultSet =
94         std::make_shared<NativeRdb::AbsSharedResultSet>();
95         reminderRequestCalendar.RecoverFromDb(resultSet);
96         // test Unmarshalling function
97         Parcel parcel;
98         reminderRequestCalendar.Unmarshalling(parcel);
99         reminderRequestCalendar.ReadFromParcel(parcel);
100         return reminderRequestCalendar.Marshalling(parcel);
101     }
102 }
103 
104 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)105 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
106 {
107     /* Run your code on data */
108     char *ch = ParseData(data, size);
109     if (ch != nullptr && size >= GetU32Size()) {
110         OHOS::DoSomethingInterestingWithMyAPI(ch, size);
111         free(ch);
112         ch = nullptr;
113     }
114     return 0;
115 }
116