1 /*
2 * Copyright (c) 2022-2024 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 <cstddef>
17 #include <cstdint>
18 #include "holiday_manager.h"
19 #include "holidaymanager_fuzzer.h"
20
21 namespace OHOS {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)22 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
23 {
24 using namespace Global::I18n;
25 if (size < 1) {
26 return false;
27 }
28 std::string input(reinterpret_cast<const char*>(data), size);
29 HolidayManager* holidayManager = new HolidayManager(input.c_str());
30
31 std::map<std::string, std::vector<HolidayInfoItem>> holidayDataMap;
32 std::vector<HolidayInfoItem> infoList;
33 std::vector<HolidayLocalName> localNameList1;
34 localNameList1.push_back({input, input});
35 HolidayInfoItem item1 = {input, size, size, size, localNameList1};
36 infoList.push_back(item1);
37 holidayDataMap.insert({input, infoList});
38 holidayManager->SetHolidayData(holidayDataMap);
39
40 holidayManager->IsHoliday();
41 holidayManager->IsHoliday(size, size, size);
42 holidayManager->GetHolidayInfoItemArray();
43 holidayManager->GetHolidayInfoItemArray(size);
44 delete holidayManager;
45 return true;
46 }
47 }
48
49 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)50 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
51 {
52 /* Run your code on data */
53 OHOS::DoSomethingInterestingWithMyAPI(data, size);
54 return 0;
55 }
56
57