1 /*
2  * Copyright (c) 2023-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 "locale_config.h"
19 #include "date_rule_init.h"
20 #include "date_time_rule.h"
21 
22 namespace OHOS {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)23     bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
24     {
25         using namespace Global::I18n;
26         if (size < 1) {
27             return false;
28         }
29         std::string input(reinterpret_cast<const char*>(data), size);
30 
31         DateRuleInit* dateRuleInit = new DateRuleInit(input);
32         icu::UnicodeString message(input.c_str());
33         dateRuleInit->Detect(message);
34 
35         DateTimeRule* dateTimeRule = new DateTimeRule(input);
36         dateTimeRule->GetUniverseRules();
37         dateTimeRule->GetLocalesRules();
38         dateTimeRule->GetLocalesRulesBackup();
39         dateTimeRule->GetSubRulesMap();
40         dateTimeRule->GetSubRules();
41         dateTimeRule->GetFilterRules();
42         dateTimeRule->GetPastRules();
43         dateTimeRule->GetParam();
44         dateTimeRule->GetParamBackup();
45         dateTimeRule->GetPatternsMap();
46         dateTimeRule->CompareLevel(input, input);
47         std::unordered_map<std::string, std::string> param = {
48             {input, input}
49         };
50         dateTimeRule->Get(param, input);
51         dateTimeRule->GetLocale();
52         icu::UnicodeString hyphen(input.c_str());
53         dateTimeRule->IsRelDates(hyphen, input);
54         DateTimeRule::trim(input);
55         DateTimeRule::CompareBeginEnd(input, input, false);
56         delete dateTimeRule;
57         delete dateRuleInit;
58         return true;
59     }
60 }
61 
62 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)63 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
64 {
65     /* Run your code on data */
66     OHOS::DoSomethingInterestingWithMyAPI(data, size);
67     return 0;
68 }
69 
70