1 /*
2  * Copyright (c) 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 "sampling_options_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <securec.h>
21 
22 #include "get_object.h"
23 #include "utils/sampling_options.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 namespace Drawing {
28 namespace {
29     constexpr uint32_t MATH_TWO = 2;
30     constexpr uint32_t MATH_THREE = 3;
31 } // namespace
32 
SamplingOptionsFuzzTest000(const uint8_t * data,size_t size)33 void SamplingOptionsFuzzTest000(const uint8_t* data, size_t size)
34 {
35     // initialize
36     g_data = data;
37     g_size = size;
38     g_pos = 0;
39 
40     uint32_t mm = GetObject<uint32_t>();
41     uint32_t fm = GetObject<uint32_t>();
42 
43     SamplingOptions sam;
44     SamplingOptions sam1 = SamplingOptions(static_cast<FilterMode>(fm % MATH_TWO));
45     SamplingOptions sam2 = SamplingOptions(static_cast<FilterMode>(fm % MATH_TWO),
46         static_cast<MipmapMode>(mm % MATH_THREE));
47     CubicResampler c = CubicResampler::CatmullRom();
48     SamplingOptions sam3 = SamplingOptions(c);
49     sam.GetUseCubic();
50     sam.GetFilterMode();
51     sam.GetMipmapMode();
52     sam.GetCubicCoffB();
53     sam.GetCubicCoffC();
54 
55     if (sam1 == sam2) {}
56     if (sam1 != sam2) {}
57 }
58 } // namespace Drawing
59 } // namespace Rosen
60 } // namespace OHOS
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::Rosen::Drawing::SamplingOptionsFuzzTest000(data, size);
67 
68     return 0;
69 }