• 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_store.h"
17 #include "reminderstore_fuzzer.h"
18 #include "abs_shared_result_set.h"
19 #include "reminder_request_alarm.h"
20 #include "reminder_request_timer.h"
21 #include "reminder_store_strategy.h"
22 #include "reminder_request_calendar.h"
23 #include <fuzzer/FuzzedDataProvider.h>
24 
25 namespace OHOS {
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)26     bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider* fdp)
27     {
28         std::string stringData = fdp->ConsumeRandomLengthString();
29         Notification::ReminderStore reminderStore;
30         int32_t oldVersion = fdp->ConsumeIntegral<int32_t>();
31         int32_t id = fdp->ConsumeIntegral<int32_t>();
32         bool value = fdp->ConsumeBool();
33         reminderStore.Init();
34         reminderStore.InitData();
35         reminderStore.Delete(oldVersion);
36         reminderStore.DeleteUser(oldVersion);
37         reminderStore.Delete(stringData, oldVersion, oldVersion);
38         reminderStore.DeleteBase(stringData);
39         sptr<Notification::ReminderRequest> timer = new Notification::ReminderRequestTimer(id);
40         sptr<Notification::ReminderRequest> alarm = new Notification::ReminderRequestAlarm(id);
41         sptr<Notification::ReminderRequest> calendar = new Notification::ReminderRequestCalendar(id);
42         NativeRdb::ValuesBucket bucket;
43         Notification::ReminderStrategy::AppendValuesBucket(timer, bucket, value);
44         std::shared_ptr<NativeRdb::ResultSet> result = std::make_shared<NativeRdb::AbsSharedResultSet>();
45         std::shared_ptr<NativeRdb::ResultSet> baseResult = std::make_shared<NativeRdb::AbsSharedResultSet>();
46         Notification::ReminderStrategy::RecoverFromOldVersion(timer, result);
47         Notification::ReminderStrategy::RecoverFromDb(timer, result);
48         Notification::ReminderStrategy::RecoverTimeFromOldVersion(timer, result);
49         Notification::ReminderStrategy::RecoverIdFromOldVersion(timer, result);
50         Notification::ReminderStrategy::RecoverContextFromOldVersion(timer, result);
51         Notification::ReminderStrategy::RecoverTimeFromDb(timer, result);
52         Notification::ReminderStrategy::RecoverIdFromDb(timer, result);
53         Notification::ReminderStrategy::RecoverContextFromDb(timer, result);
54         Notification::ReminderTimerStrategy::AppendValuesBucket(timer, bucket);
55         Notification::ReminderTimerStrategy::RecoverFromOldVersion(timer, result);
56         Notification::ReminderTimerStrategy::RecoverFromDb(timer, baseResult, result);
57         Notification::ReminderAlarmStrategy::AppendValuesBucket(alarm, bucket);
58         Notification::ReminderAlarmStrategy::RecoverFromOldVersion(alarm, result);
59         Notification::ReminderAlarmStrategy::RecoverFromDb(alarm, baseResult, result);
60         Notification::ReminderCalendarStrategy::AppendValuesBucket(calendar, bucket);
61         Notification::ReminderCalendarStrategy::RecoverFromOldVersion(calendar, result);
62         Notification::ReminderCalendarStrategy::RecoverFromDb(calendar, baseResult, result);
63         Notification::ReminderCalendarStrategy::RecoverTime(calendar, result);
64         return true;
65     }
66 }
67 
68 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)69 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
70 {
71     /* Run your code on data */
72     FuzzedDataProvider fdp(data, size);
73     OHOS::DoSomethingInterestingWithMyAPI(&fdp);
74     return 0;
75 }
76