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 "arkuiformrenderproxy_fuzzer.h"
17
18 #define private public
19 #define protected public
20 #include "interfaces/inner_api/form_render/include/form_renderer_delegate_proxy.h"
21 #include "interfaces/inner_api/form_render/include/form_renderer_dispatcher_proxy.h"
22 #include "test/mock/interfaces/mock_i_remote_object.h"
23 #undef private
24 #undef protected
25
26 namespace OHOS::Ace {
27 const uint32_t u16m = 65535;
DelegateProxyAPI(const std::string data,size_t size)28 bool DelegateProxyAPI(const std::string data, size_t size)
29 {
30 sptr<IRemoteObject> impl = new MockIRemoteObject();
31 FormRendererDelegateProxy delegateProxy(impl);
32 std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode;
33 OHOS::AppExecFwk::FormJsInfo formJsInfo;
34 AAFwk::Want want;
35 delegateProxy.OnSurfaceCreate(surfaceNode, formJsInfo, want);
36 delegateProxy.OnActionEvent(data);
37 delegateProxy.OnError(data, data);
38 return true;
39 }
40
DispatcherProxyAPI(const std::string data,size_t size)41 bool DispatcherProxyAPI(const std::string data, size_t size)
42 {
43 sptr<IRemoteObject> impl = new MockIRemoteObject();
44 FormRendererDispatcherProxy dispatcherProxy(impl);
45 std::shared_ptr<OHOS::MMI::PointerEvent> pointEvent;
46 SerializedGesture serializedGesture;
47 dispatcherProxy.DispatchPointerEvent(pointEvent, serializedGesture);
48 dispatcherProxy.SetAllowUpdate(true);
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 DelegateProxyAPI(str, size);
62 DispatcherProxyAPI(str, size);
63 return 0;
64 }
65