• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <string>
19 #include "date_time_format.h"
20 #include "datetimeformat_fuzzer.h"
21 
22 namespace OHOS {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)23     void DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
24     {
25         using namespace Global::I18n;
26 
27         std::string input(reinterpret_cast<const char*>(data), size);
28 
29         std::vector<std::string> localeTags;
30         localeTags.push_back(input);
31         std::map<std::string, std::string> configs;
32         configs[input] = input;
33         DateTimeFormat dateTimeFormat(localeTags, configs);
34         dateTimeFormat.Format(size);
35         dateTimeFormat.FormatRange(size, size);
36         dateTimeFormat.GetResolvedOptions(configs);
37         dateTimeFormat.GetDateStyle();
38         dateTimeFormat.GetTimeStyle();
39         dateTimeFormat.GetHourCycle();
40         dateTimeFormat.GetTimeZone();
41         dateTimeFormat.GetTimeZoneName();
42         dateTimeFormat.GetNumberingSystem();
43         dateTimeFormat.GetHour12();
44         dateTimeFormat.GetWeekday();
45         dateTimeFormat.GetEra();
46         dateTimeFormat.GetYear();
47         dateTimeFormat.GetMonth();
48         dateTimeFormat.GetDay();
49         dateTimeFormat.GetHour();
50         dateTimeFormat.GetMinute();
51         dateTimeFormat.GetSecond();
52         std::unique_ptr<DateTimeFormat> dtFormat =
53                 DateTimeFormat::CreateInstance(localeTags, configs);
54         if (dtFormat != nullptr) {
55             dtFormat->Format(size);
56         }
57     }
58 }
59 
60 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)61 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
62 {
63     /* Run your code on data */
64     OHOS::DoSomethingInterestingWithMyAPI(data, size);
65     return 0;
66 }
67 
68