• 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 "reminder_request_calendar.h"
17 #include "reminderrequestcalendar_fuzzer.h"
18 #include <fuzzer/FuzzedDataProvider.h>
19 
20 namespace OHOS {
21     namespace {
22         constexpr uint8_t MONTHS = 12;
23         constexpr uint8_t DAYS = 31;
24         constexpr uint16_t YEAR = 365;
25         constexpr uint16_t HOURS = 24;
26         constexpr uint16_t MINUTES = 60;
27         constexpr uint16_t SECONDS = 60;
28         constexpr uint8_t WEEK = 7;
29     }
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)30     bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider* fdp)
31     {
32         struct tm nowTime;
33         uint8_t months = fdp->ConsumeIntegral<uint8_t>() % MONTHS + 1;
34         uint8_t days = fdp->ConsumeIntegral<uint8_t>() % DAYS + 1;
35         uint8_t weeks = fdp->ConsumeIntegral<uint8_t>() % WEEK + 1;
36         std::vector<uint8_t> repeatMonths;
37         std::vector<uint8_t> repeatDays;
38         std::vector<uint8_t> daysOfWeek;
39         daysOfWeek.push_back(weeks);
40         repeatMonths.push_back(months);
41         repeatDays.push_back(days);
42         Notification::ReminderRequestCalendar reminderRequestCalendar(nowTime, repeatMonths, repeatDays, daysOfWeek);
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 = fdp->ConsumeBool();
51         reminderRequestCalendar.SetDay(days, enabled);
52         // test SetMonth function
53         reminderRequestCalendar.SetMonth(months, enabled);
54         // test SetRepeatDaysOfWeek function
55         reminderRequestCalendar.SetRepeatDaysOfWeek(enabled, daysOfWeek);
56         // test SetRepeatMonths function
57         reminderRequestCalendar.SetRepeatMonths(repeatMonths);
58         // test SetRepeatDaysOfMonth function
59         reminderRequestCalendar.SetRepeatDaysOfMonth(repeatDays);
60         // test GetRepeatMonths function
61         reminderRequestCalendar.GetRepeatMonths();
62         // test GetRepeatDays function
63         reminderRequestCalendar.GetRepeatDays();
64         // test GetDaysOfMonth function
65         uint16_t year = fdp->ConsumeIntegral<uint16_t>() % YEAR;
66         reminderRequestCalendar.GetDaysOfMonth(year, months);
67         // test GetNextDay function
68         struct tm target;
69         reminderRequestCalendar.GetNextDay(year, months, nowTime, target);
70         // test GetNextTriggerTime function
71         reminderRequestCalendar.GetNextTriggerTime();
72         // test GetNextTriggerTimeAsRepeatReminder function
73         struct tm tarTime;
74         reminderRequestCalendar.GetNextTriggerTimeAsRepeatReminder(nowTime, tarTime);
75         // test GetTimeInstantMilli function
76         uint8_t hour = fdp->ConsumeIntegral<uint8_t>() % HOURS;
77         uint8_t minute = fdp->ConsumeIntegral<uint8_t>() % MINUTES;
78         uint8_t second = fdp->ConsumeIntegral<uint8_t>() % SECONDS;
79         reminderRequestCalendar.GetTimeInstantMilli(year, months, days, hour, minute, second);
80         // test IsRepeatReminder function
81         reminderRequestCalendar.IsRepeatReminder();
82         // test IsRepeatMonth function
83         reminderRequestCalendar.IsRepeatMonth(months);
84         // test IsRepeatDay function
85         reminderRequestCalendar.IsRepeatDay(days);
86         // test OnDateTimeChange function
87         reminderRequestCalendar.OnDateTimeChange();
88         // test OnTimeZoneChange function
89         reminderRequestCalendar.OnTimeZoneChange();
90         // test UpdateNextReminder function
91         reminderRequestCalendar.UpdateNextReminder();
92         // test PreGetNextTriggerTimeIgnoreSnooze function
93         reminderRequestCalendar.PreGetNextTriggerTimeIgnoreSnooze(enabled, enabled);
94         // test Unmarshalling function
95         Parcel parcel;
96         reminderRequestCalendar.Unmarshalling(parcel);
97         reminderRequestCalendar.ReadFromParcel(parcel);
98         return reminderRequestCalendar.Marshalling(parcel);
99     }
100 }
101 
102 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)103 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
104 {
105     /* Run your code on data */
106     FuzzedDataProvider fdp(data, size);
107     OHOS::DoSomethingInterestingWithMyAPI(&fdp);
108     return 0;
109 }
110