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 "acereskeyparser_fuzzer.h"
17 #include "base/resource/ace_res_key_parser.h"
18
19 namespace OHOS::Ace {
20 constexpr size_t enumNum = 10;
GetString(const uint8_t * data,size_t size)21 bool GetString(const uint8_t* data, size_t size)
22 {
23 std::string str = "";
24 str += AceResKeyParser::GetInstance().GetOrientationByType(DeviceOrientation(size % enumNum));
25 str += AceResKeyParser::GetInstance().GetColorModeByType(ColorMode(size % enumNum));
26 str += AceResKeyParser::GetInstance().GetDeviceByType(DeviceType(size % enumNum));
27 str += AceResKeyParser::GetInstance().GetResolutionByType(ResolutionType(size % enumNum));
28 str += AceResKeyParser::GetInstance().GetScreenShapeByType(ScreenShape(size % enumNum));
29 str += AceResKeyParser::GetInstance().GetScreenLongByType(LongScreenType(size % enumNum));
30 str += AceResKeyParser::GetInstance().GetDeclarativeColorModeByType(ColorMode(size % enumNum));
31 return str.empty();
32 }
33 }
34
35 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)36 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
37 {
38 /* Run your code on data */
39 OHOS::Ace::GetString(data, size);
40 return 0;
41 }
42
43