• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef CAMERADEVICE_FUZZER_H
17 #define CAMERADEVICE_FUZZER_H
18 #define FUZZ_PROJECT_NAME "cameradevice_fuzzer"
19 #include <iostream>
20 #include "icamera_device_service_callback.h"
21 #include "v1_3/icamera_device.h"
22 namespace OHOS {
23 namespace CameraStandard {
24 
25 class IRemoteObjectMock : public IRemoteObject {
26 public:
GetObjectRefCount()27     inline int32_t GetObjectRefCount() override
28     {
29         return 0;
30     }
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31     inline int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override
32     {
33         return 0;
34     }
AddDeathRecipient(const sptr<DeathRecipient> & recipient)35     inline bool AddDeathRecipient(const sptr<DeathRecipient> &recipient) override
36     {
37         return true;
38     }
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)39     inline bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient) override
40     {
41         return true;
42     }
Dump(int fd,const std::vector<std::u16string> & args)43     inline int Dump(int fd, const std::vector<std::u16string> &args) override
44     {
45         return 0;
46     }
47 };
48 
49 class ICameraDeviceServiceCallbackMock : public ICameraDeviceServiceCallback, public IRemoteObjectMock {
50 public:
OnError(const int32_t errorType,const int32_t errorMsg)51     inline int32_t OnError(const int32_t errorType, const int32_t errorMsg) override
52     {
53         return 0;
54     }
OnResult(const uint64_t timestamp,const std::shared_ptr<OHOS::Camera::CameraMetadata> & result)55     inline int32_t OnResult(const uint64_t timestamp,
56         const std::shared_ptr<OHOS::Camera::CameraMetadata> &result) override
57     {
58         return 0;
59     }
AsObject()60     sptr<IRemoteObject> AsObject() override
61     {
62         return this;
63     }
64 };
65 
66 using OHOS::HDI::Camera::V1_3::IStreamOperatorCallback;
67 class IStreamOperatorCallbackMock : public IStreamOperatorCallback {
68 public:
OnCaptureReady(int32_t captureId,const std::vector<int32_t> & streamIds,uint64_t timestamp)69     inline int32_t OnCaptureReady(int32_t captureId,
70         const std::vector<int32_t>& streamIds, uint64_t timestamp) override
71     {
72         return 0;
73     }
74 
OnFrameShutterEnd(int32_t captureId,const std::vector<int32_t> & streamIds,uint64_t timestamp)75     inline int32_t OnFrameShutterEnd(int32_t captureId,
76         const std::vector<int32_t>& streamIds, uint64_t timestamp) override
77     {
78         return 0;
79     }
80 
OnCaptureEndedExt(int32_t captureId,const std::vector<OHOS::HDI::Camera::V1_3::CaptureEndedInfoExt> & infos)81     inline int32_t OnCaptureEndedExt(int32_t captureId,
82          const std::vector<OHOS::HDI::Camera::V1_3::CaptureEndedInfoExt>& infos) override
83     {
84         return 0;
85     }
OnCaptureStarted(int32_t captureId,const std::vector<int32_t> & streamIds)86     inline int32_t OnCaptureStarted(int32_t captureId, const std::vector<int32_t>& streamIds) override
87     {
88         return 0;
89     }
90 
OnCaptureEnded(int32_t captureId,const std::vector<OHOS::HDI::Camera::V1_0::CaptureEndedInfo> & infos)91     inline int32_t OnCaptureEnded(int32_t captureId,
92          const std::vector<OHOS::HDI::Camera::V1_0::CaptureEndedInfo>& infos) override
93     {
94         return 0;
95     }
96 
OnCaptureError(int32_t captureId,const std::vector<OHOS::HDI::Camera::V1_0::CaptureErrorInfo> & infos)97     inline int32_t OnCaptureError(int32_t captureId,
98          const std::vector<OHOS::HDI::Camera::V1_0::CaptureErrorInfo>& infos) override
99     {
100         return 0;
101     }
102 
OnFrameShutter(int32_t captureId,const std::vector<int32_t> & streamIds,uint64_t timestamp)103     inline int32_t OnFrameShutter(int32_t captureId,
104         const std::vector<int32_t>& streamIds, uint64_t timestamp) override
105     {
106         return 0;
107     }
OnCaptureStarted_V1_2(int32_t captureId,const std::vector<OHOS::HDI::Camera::V1_2::CaptureStartedInfo> & infos)108     inline int32_t OnCaptureStarted_V1_2(int32_t captureId,
109          const std::vector<OHOS::HDI::Camera::V1_2::CaptureStartedInfo>& infos) override
110     {
111         return 0;
112     }
OnResult(int32_t streamId,const std::vector<uint8_t> & result)113     inline int32_t OnResult(int32_t streamId, const std::vector<uint8_t>& result) override
114     {
115         return 0;
116     }
117 };
118 
119 void CameraDeviceFuzzTest(uint8_t *rawData, size_t size);
120 void CameraDeviceFuzzTestGetPermission();
121 void CameraDeviceFuzzTest2(uint8_t *rawData, size_t size);
122 void Test3(uint8_t *rawData, size_t size);
123 void TestXCollie(uint8_t *rawData, size_t size);
124 void TestDynamicLoader(uint8_t *rawData, size_t size);
125 } //CameraStandard
126 } //OHOS
127 #endif //CAMERADEVICE_FUZZER_H
128 
129