• 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 <cstddef>
17 #include <cstdint>
18 #include <string>
19 #include <vector>
20 #include "locale_config.h"
21 #include "localeconfigget_fuzzer.h"
22 
23 namespace OHOS {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)24     bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
25     {
26         using namespace Global::I18n;
27         LocaleConfig::GetSystemLanguage();
28         LocaleConfig::GetSystemRegion();
29         LocaleConfig::GetSystemLocale();
30         LocaleConfig::GetSystemLanguages();
31         LocaleConfig::GetSystemCountries();
32 
33         std::string input(reinterpret_cast<const char*>(data), size);
34         LocaleConfig::IsSuggested(input);
35         const size_t minimalLocaleLength = 2;
36         if (input.length() > minimalLocaleLength) {
37             std::string firstInput(input, 0, minimalLocaleLength);
38             std::string secondInput(input, minimalLocaleLength);
39             LocaleConfig::IsSuggested(firstInput, secondInput);
40             LocaleConfig::GetDisplayLanguage(firstInput, secondInput, true);
41             LocaleConfig::GetDisplayLanguage(firstInput, secondInput, false);
42             LocaleConfig::GetDisplayRegion(firstInput, secondInput, true);
43             LocaleConfig::GetDisplayRegion(firstInput, secondInput, false);
44         }
45         LocaleConfig::IsRTL(input);
46         LocaleConfig::GetValidLocale(input);
47 
48         return true;
49     }
50 }
51 
52 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)53 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
54 {
55     /* Run your code on data */
56     OHOS::DoSomethingInterestingWithMyAPI(data, size);
57     return 0;
58 }
59 
60