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 "hcamera_host_manager.h" 21 #include "hcamera_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 class IStreamOperatorCallbackMock : public IStreamOperatorCallback { 67 public: OnCaptureReady(int32_t captureId,const std::vector<int32_t> & streamIds,uint64_t timestamp)68 inline int32_t OnCaptureReady(int32_t captureId, 69 const std::vector<int32_t>& streamIds, uint64_t timestamp) override 70 { 71 return 0; 72 } 73 OnFrameShutterEnd(int32_t captureId,const std::vector<int32_t> & streamIds,uint64_t timestamp)74 inline int32_t OnFrameShutterEnd(int32_t captureId, 75 const std::vector<int32_t>& streamIds, uint64_t timestamp) override 76 { 77 return 0; 78 } 79 OnCaptureEndedExt(int32_t captureId,const std::vector<OHOS::HDI::Camera::V1_3::CaptureEndedInfoExt> & infos)80 inline int32_t OnCaptureEndedExt(int32_t captureId, 81 const std::vector<OHOS::HDI::Camera::V1_3::CaptureEndedInfoExt>& infos) override 82 { 83 return 0; 84 } OnCaptureStarted(int32_t captureId,const std::vector<int32_t> & streamIds)85 inline int32_t OnCaptureStarted(int32_t captureId, const std::vector<int32_t>& streamIds) override 86 { 87 return 0; 88 } 89 OnCaptureEnded(int32_t captureId,const std::vector<OHOS::HDI::Camera::V1_0::CaptureEndedInfo> & infos)90 inline int32_t OnCaptureEnded(int32_t captureId, 91 const std::vector<OHOS::HDI::Camera::V1_0::CaptureEndedInfo>& infos) override 92 { 93 return 0; 94 } 95 OnCaptureError(int32_t captureId,const std::vector<OHOS::HDI::Camera::V1_0::CaptureErrorInfo> & infos)96 inline int32_t OnCaptureError(int32_t captureId, 97 const std::vector<OHOS::HDI::Camera::V1_0::CaptureErrorInfo>& infos) override 98 { 99 return 0; 100 } 101 OnFrameShutter(int32_t captureId,const std::vector<int32_t> & streamIds,uint64_t timestamp)102 inline int32_t OnFrameShutter(int32_t captureId, 103 const std::vector<int32_t>& streamIds, uint64_t timestamp) override 104 { 105 return 0; 106 } OnCaptureStarted_V1_2(int32_t captureId,const std::vector<OHOS::HDI::Camera::V1_2::CaptureStartedInfo> & infos)107 inline int32_t OnCaptureStarted_V1_2(int32_t captureId, 108 const std::vector<OHOS::HDI::Camera::V1_2::CaptureStartedInfo>& infos) override 109 { 110 return 0; 111 } OnResult(int32_t streamId,const std::vector<uint8_t> & result)112 inline int32_t OnResult(int32_t streamId, const std::vector<uint8_t>& result) override 113 { 114 return 0; 115 } 116 }; 117 118 void CameraDeviceFuzzTest(uint8_t *rawData, size_t size); 119 void CameraDeviceFuzzTestGetPermission(); 120 void CameraDeviceFuzzTest2(uint8_t *rawData, size_t size); 121 void Test3(uint8_t *rawData, size_t size); 122 void TestXCollie(uint8_t *rawData, size_t size); 123 } 124 } 125 #endif 126 127