• 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_alarm.h"
17 #include "reminderrequestalarm_fuzzer.h"
18 #include <fuzzer/FuzzedDataProvider.h>
19 
20 namespace OHOS {
21     namespace {
22         constexpr uint8_t HOUR = 24;
23         constexpr uint8_t MINUTE = 60;
24         constexpr uint8_t WEEK = 7;
25         constexpr uint8_t ENABLE = 2;
26     }
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)27     bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider* fdp)
28     {
29         uint8_t hour = fdp->ConsumeIntegral<uint8_t>() % HOUR;
30         uint8_t minute = fdp->ConsumeIntegral<uint8_t>() % MINUTE;
31         uint8_t week = fdp->ConsumeIntegral<uint8_t>() % WEEK;
32         std::vector<uint8_t> daysOfWeek;
33         daysOfWeek.push_back(week);
34         auto rrc = std::make_shared<Notification::ReminderRequestAlarm>(hour, minute, daysOfWeek);
35         // test SetRepeatDaysOfWeek function
36         bool enabled = fdp->ConsumeBool();
37         rrc->SetRepeatDaysOfWeek(enabled, daysOfWeek);
38         // test GetDaysOfWeek function
39         rrc->GetDaysOfWeek();
40         // test CheckParamValid function
41         rrc->CheckParamValid();
42         // test IsRepeatReminder function
43         rrc->IsRepeatReminder();
44         // test PreGetNextTriggerTimeIgnoreSnooze function
45         rrc->PreGetNextTriggerTimeIgnoreSnooze(enabled, enabled);
46         // test GetNextTriggerTime function
47         rrc->GetNextTriggerTime(enabled);
48         // test GetNextDaysOfWeek function
49         time_t now;
50         (void)time(&now);  // unit is seconds.
51         time_t target = static_cast<time_t>(fdp->ConsumeIntegral<uint8_t>() % ENABLE);
52         rrc->GetNextDaysOfWeek(now, target);
53         // test GetHour function
54         rrc->GetHour();
55         // test GetMinute function
56         rrc->GetMinute();
57         // test GetRepeatDaysOfWeek function
58         rrc->GetRepeatDaysOfWeek();
59         // test OnDateTimeChange function
60         rrc->OnDateTimeChange();
61         // test OnTimeZoneChange function
62         rrc->OnTimeZoneChange();
63         // test UpdateNextReminder function
64         rrc->UpdateNextReminder();
65         // test Unmarshalling function
66         Parcel parcel;
67         rrc->Unmarshalling(parcel);
68         rrc->ReadFromParcel(parcel);
69         return rrc->Marshalling(parcel);
70     }
71 }
72 
73 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)74 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
75 {
76     /* Run your code on data */
77     FuzzedDataProvider fdp(data, size);
78     OHOS::DoSomethingInterestingWithMyAPI(&fdp);
79     return 0;
80 }
81