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