1 /*
2 * Copyright (c) 2023 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 "arkuiformrenderimpl_fuzzer.h"
17
18 #define private public
19 #define protected public
20 #include "interfaces/inner_api/form_render/include/form_renderer_delegate_impl.h"
21 #include "interfaces/inner_api/form_render/include/form_renderer_dispatcher_impl.h"
22 #undef private
23 #undef protected
24
25 namespace OHOS::Ace {
26 const uint32_t u16m = 65535;
DelegateImplAPI(const std::string data,size_t size)27 bool DelegateImplAPI(const std::string data, size_t size)
28 {
29 FormRendererDelegateImpl delegateImpl;
30 std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode;
31 OHOS::AppExecFwk::FormJsInfo formJsInfo;
32 AAFwk::Want want;
33 delegateImpl.OnSurfaceCreate(surfaceNode, formJsInfo, want);
34 delegateImpl.OnActionEvent(data);
35 delegateImpl.OnError(data, data);
36 return true;
37 }
38
DispatcherImplAPI(const std::string data,size_t size)39 bool DispatcherImplAPI(const std::string data, size_t size)
40 {
41 std::shared_ptr<UIContent> uiContent;
42 std::weak_ptr<OHOS::AppExecFwk::EventHandler> handler;
43 FormRendererDispatcherImpl dispatcherImpl(uiContent, nullptr, handler);
44 std::shared_ptr<OHOS::MMI::PointerEvent> pointEvent;
45 SerializedGesture serializedGesture;
46 dispatcherImpl.DispatchPointerEvent(pointEvent, serializedGesture);
47 dispatcherImpl.SetAllowUpdate(true);
48 dispatcherImpl.IsAllowUpdate();
49 return true;
50 }
51 }
52
53 using namespace OHOS;
54 using namespace OHOS::Ace;
55 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)56 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
57 {
58 auto ri = size % u16m;
59 std::string str(reinterpret_cast<const char*>(data), ri);
60 /* Run your code on data */
61 DelegateImplAPI(str, size);
62 DispatcherImplAPI(str, size);
63 return 0;
64 }
65