• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cstring>
17 #include "ge_visual_effect_fuzzer.h"
18 #include "get_object.h"
19 #include "ge_render.h"
20 #include <fuzzer/FuzzedDataProvider.h>
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace Drawing {
25 
26 namespace {
27 constexpr size_t STR_LEN = 10;
28 }
29 
GEVisualEffectFuzzTest001()30 std::shared_ptr<GEVisualEffectImpl> GEVisualEffectFuzzTest001()
31 {
32     int32_t nameLen = GETest::GetPlainData<int32_t>();
33     std::string name = GETest::GetStringFromData(nameLen);
34     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
35     auto geVisualEffect = std::make_shared<GEVisualEffect>(name, type);
36     geVisualEffect->GetName();
37     auto impl = geVisualEffect->GetImpl();
38     return impl;
39 }
40 
GEVisualEffectFuzzTest002()41 std::shared_ptr<GEVisualEffect> GEVisualEffectFuzzTest002()
42 {
43     int32_t nameLen = GETest::GetPlainData<int32_t>();
44     std::string name = GETest::GetStringFromData(nameLen);
45     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
46     auto geVisualEffect = std::make_shared<GEVisualEffect>(name, type);
47     return geVisualEffect;
48 }
49 
GEVisualEffectFuzzTest003(const uint8_t * data,size_t size)50 bool GEVisualEffectFuzzTest003(const uint8_t* data, size_t size)
51 {
52     FuzzedDataProvider fdp(data, size);
53     auto geVisualEffect = std::make_shared<GEVisualEffect>("test");
54     std::string tag = fdp.ConsumeRandomLengthString(STR_LEN);
55     int32_t param = fdp.ConsumeIntegral<int32_t>();
56     geVisualEffect->SetParam(tag, param);
57     return true;
58 }
59 
GEVisualEffectFuzzTest004()60 bool GEVisualEffectFuzzTest004()
61 {
62     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
63     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
64     std::string tag = GETest::GetStringFromData(STR_LEN);
65     int64_t param = GETest::GetPlainData<int64_t>();
66     geVisualEffect->SetParam(tag, param);
67     return true;
68 }
69 
GEVisualEffectFuzzTest005()70 bool GEVisualEffectFuzzTest005()
71 {
72     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
73     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
74     std::string tag = GETest::GetStringFromData(STR_LEN);
75     float param = GETest::GetPlainData<float>();
76     geVisualEffect->SetParam(tag, param);
77     return true;
78 }
79 
GEVisualEffectFuzzTest006()80 bool GEVisualEffectFuzzTest006()
81 {
82     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
83     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
84     std::string tag = GETest::GetStringFromData(STR_LEN);
85     double param = GETest::GetPlainData<double>();
86     geVisualEffect->SetParam(tag, param);
87     return true;
88 }
89 
GEVisualEffectFuzzTest007()90 bool GEVisualEffectFuzzTest007()
91 {
92     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
93     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
94     std::string tag = GETest::GetStringFromData(STR_LEN);
95     std::string param_str = GETest::GetStringFromData(STR_LEN);
96     geVisualEffect->SetParam(tag, param_str.c_str());
97     return true;
98 }
99 
GEVisualEffectFuzzTest008()100 bool GEVisualEffectFuzzTest008()
101 {
102     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
103     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
104     std::string tag = GETest::GetStringFromData(STR_LEN);
105     Matrix param;
106     geVisualEffect->SetParam(tag, param);
107     return true;
108 }
109 
GEVisualEffectFuzzTest009()110 bool GEVisualEffectFuzzTest009()
111 {
112     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
113     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
114     std::string tag = GETest::GetStringFromData(STR_LEN);
115     float f1 = GETest::GetPlainData<float>();
116     float f2 = GETest::GetPlainData<float>();
117     std::vector<std::pair<float, float>> param {{f1, f2}};
118     geVisualEffect->SetParam(tag, param);
119     return true;
120 }
121 
GEVisualEffectFuzzTest010()122 bool GEVisualEffectFuzzTest010()
123 {
124     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
125     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
126     std::string tag = GETest::GetStringFromData(STR_LEN);
127     bool param = GETest::GetPlainData<bool>();
128     geVisualEffect->SetParam(tag, param);
129     return true;
130 }
131 
GEVisualEffectFuzzTest011()132 bool GEVisualEffectFuzzTest011()
133 {
134     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
135     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
136     std::string tag = GETest::GetStringFromData(STR_LEN);
137     uint32_t param = GETest::GetPlainData<uint32_t>();
138     geVisualEffect->SetParam(tag, param);
139     return true;
140 }
141 
GEVisualEffectFuzzTest012()142 bool GEVisualEffectFuzzTest012()
143 {
144     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
145     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
146     std::string tag = GETest::GetStringFromData(STR_LEN);
147     std::shared_ptr<Drawing::Image> param;
148     geVisualEffect->SetParam(tag, param);
149     return true;
150 }
151 
GEVisualEffectFuzzTest013()152 bool GEVisualEffectFuzzTest013()
153 {
154     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
155     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
156     std::string tag = GETest::GetStringFromData(STR_LEN);
157     std::shared_ptr<Drawing::ColorFilter> param;
158     geVisualEffect->SetParam(tag, param);
159     return true;
160 }
161 
GEVisualEffectFuzzTest014()162 std::string GEVisualEffectFuzzTest014()
163 {
164     int32_t nameLen = GETest::GetPlainData<int32_t>();
165     std::string name = GETest::GetStringFromData(nameLen);
166     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
167     auto geVisualEffect = std::make_shared<GEVisualEffect>(name, type);
168     std::string res = geVisualEffect->GetName();
169     return res;
170 }
171 
172 } // namespace Drawing
173 } // namespace Rosen
174 } // namespace OHOS
175 
176 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)177 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
178 {
179     if (data == nullptr) {
180         return 0;
181     }
182     // initialize
183     OHOS::Rosen::GETest::g_data = data;
184     OHOS::Rosen::GETest::g_size = size;
185     OHOS::Rosen::GETest::g_pos = 0;
186     /* Run your code on data */
187     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest001();
188     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest002();
189     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest003(data, size);
190     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest004();
191     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest005();
192     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest006();
193     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest007();
194     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest008();
195     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest009();
196     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest010();
197     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest011();
198     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest012();
199     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest013();
200     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest014();
201     return 0;
202 }
203