• 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_alarm.h"
19 #undef private
20 #undef protected
21 #include "reminderrequestalarm_fuzzer.h"
22 
23 namespace OHOS {
24     namespace {
25         constexpr uint8_t HOUR = 24;
26         constexpr uint8_t MINUTE = 60;
27         constexpr uint8_t WEEK = 7;
28         constexpr uint8_t ENABLE = 2;
29     }
DoSomethingInterestingWithMyAPI(const char * data,size_t size)30     bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
31     {
32         uint8_t hour = *data % HOUR;
33         uint8_t minute = *data % MINUTE;
34         uint8_t week = *data % WEEK;
35         std::vector<uint8_t> daysOfWeek;
36         daysOfWeek.push_back(week);
37         auto rrc = std::make_shared<Notification::ReminderRequestAlarm>(hour, minute, daysOfWeek);
38         // test SetDaysOfWeek function
39         bool enabled = *data % ENABLE;
40         rrc->SetDaysOfWeek(enabled, daysOfWeek);
41         // test GetDaysOfWeek function
42         rrc->GetDaysOfWeek();
43         // test CheckParamValid function
44         rrc->CheckParamValid();
45         // test IsRepeatReminder function
46         rrc->IsRepeatReminder();
47         // test PreGetNextTriggerTimeIgnoreSnooze function
48         rrc->PreGetNextTriggerTimeIgnoreSnooze(enabled, enabled);
49         // test GetNextTriggerTime function
50         rrc->GetNextTriggerTime(enabled);
51         // test GetNextAlarm function
52         time_t now;
53         (void)time(&now);  // unit is seconds.
54         time_t target = *data % ENABLE;
55         rrc->GetNextAlarm(now, target);
56         // test IsRepeatDay function
57         int32_t day = static_cast<int32_t>(GetU32Data(data));
58         rrc->IsRepeatDay(day);
59         // test GetHour function
60         rrc->GetHour();
61         // test GetMinute function
62         rrc->GetMinute();
63         // test GetRepeatDay function
64         rrc->GetRepeatDay();
65         // test OnDateTimeChange function
66         rrc->OnDateTimeChange();
67         // test OnTimeZoneChange function
68         rrc->OnTimeZoneChange();
69         // test UpdateNextReminder function
70         rrc->UpdateNextReminder();
71         // test Unmarshalling function
72         Parcel parcel;
73         rrc->Unmarshalling(parcel);
74         rrc->ReadFromParcel(parcel);
75         // test RecoverFromDb function
76         std::shared_ptr<NativeRdb::AbsSharedResultSet> resultSet =
77         std::make_shared<NativeRdb::AbsSharedResultSet>();
78         rrc->RecoverFromDb(resultSet);
79         return rrc->Marshalling(parcel);
80     }
81 }
82 
83 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)84 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
85 {
86     /* Run your code on data */
87     char *ch = ParseData(data, size);
88     if (ch != nullptr && size >= GetU32Size()) {
89         OHOS::DoSomethingInterestingWithMyAPI(ch, size);
90         free(ch);
91         ch = nullptr;
92     }
93     return 0;
94 }
95