• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Android Open Source Project
2 //
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 #ifndef EVS_MANAGER_1_1_TEST_FUZZER_MOCKHWCAMERA_H_
16 #define EVS_MANAGER_1_1_TEST_FUZZER_MOCKHWCAMERA_H_
17 
18 #include <gmock/gmock.h>
19 #include <gtest/gtest.h>
20 
21 namespace android {
22 namespace automotive {
23 namespace evs {
24 namespace V1_1 {
25 namespace implementation {
26 
27 class MockHWCamera : public IEvsCamera_1_1 {
28 public:
29     MockHWCamera() = default;
30 
31     // v1.0 methods
getCameraInfo(getCameraInfo_cb _hidl_cb)32     Return<void> getCameraInfo(getCameraInfo_cb _hidl_cb) override { return {}; }
setMaxFramesInFlight(uint32_t bufferCount)33     Return<EvsResult> setMaxFramesInFlight(uint32_t bufferCount) override {
34         if (bufferCount > 1024) {
35             return EvsResult::INVALID_ARG;
36         }
37         return EvsResult::OK;
38     }
startVideoStream(const::android::sp<IEvsCameraStream_1_0> & stream)39     Return<EvsResult> startVideoStream(const ::android::sp<IEvsCameraStream_1_0>& stream) override {
40         return EvsResult::OK;
41     }
doneWithFrame(const BufferDesc_1_0 & buffer)42     Return<void> doneWithFrame(const BufferDesc_1_0& buffer) override { return {}; }
stopVideoStream()43     Return<void> stopVideoStream() override { return {}; }
getExtendedInfo(uint32_t opaqueIdentifier)44     Return<int32_t> getExtendedInfo(uint32_t opaqueIdentifier) override {
45         if (mExtendedInfo.find(opaqueIdentifier) != mExtendedInfo.end()) {
46             return mExtendedInfo[opaqueIdentifier];
47         }
48         return 0;
49     }
setExtendedInfo(uint32_t opaqueIdentifier,int32_t opaqueValue)50     Return<EvsResult> setExtendedInfo(uint32_t opaqueIdentifier, int32_t opaqueValue) override {
51         mExtendedInfo[opaqueIdentifier] = opaqueValue;
52         return EvsResult::OK;
53     }
54 
55     // v1.1 methods
getCameraInfo_1_1(getCameraInfo_1_1_cb _hidl_cb)56     Return<void> getCameraInfo_1_1(getCameraInfo_1_1_cb _hidl_cb) override { return {}; }
57     MOCK_METHOD(Return<void>, getPhysicalCameraInfo,
58                 (const hidl_string& deviceId, getPhysicalCameraInfo_cb _hidl_cb), (override));
59     MOCK_METHOD(Return<EvsResult>, pauseVideoStream, (), (override));
60     MOCK_METHOD(Return<EvsResult>, resumeVideoStream, (), (override));
doneWithFrame_1_1(const hardware::hidl_vec<BufferDesc_1_1> & buffer)61     Return<EvsResult> doneWithFrame_1_1(const hardware::hidl_vec<BufferDesc_1_1>& buffer) override {
62         return EvsResult::OK;
63     }
64     MOCK_METHOD(Return<EvsResult>, setMaster, (), (override));
65     MOCK_METHOD(Return<EvsResult>, forceMaster, (const sp<IEvsDisplay_1_0>& display), (override));
66     MOCK_METHOD(Return<EvsResult>, unsetMaster, (), (override));
getParameterList(getParameterList_cb _hidl_cb)67     Return<void> getParameterList(getParameterList_cb _hidl_cb) override { return {}; }
getIntParameterRange(CameraParam id,getIntParameterRange_cb _hidl_cb)68     Return<void> getIntParameterRange(CameraParam id, getIntParameterRange_cb _hidl_cb) override {
69         return {};
70     }
setIntParameter(CameraParam id,int32_t value,setIntParameter_cb _hidl_cb)71     Return<void> setIntParameter(CameraParam id, int32_t value,
72                                  setIntParameter_cb _hidl_cb) override {
73         // FIXME in default implementation, it's _hidl_cb(EvsResult::INVALID_ARG, 0); which will
74         // always cause a segfault what's the predefined behavior of _hidl_cb?
75         std::vector<int32_t> vec;
76         vec.push_back(0);
77         _hidl_cb(EvsResult::INVALID_ARG, vec);
78         return {};
79     }
80 
getIntParameter(CameraParam id,getIntParameter_cb _hidl_cb)81     Return<void> getIntParameter(CameraParam id, getIntParameter_cb _hidl_cb) {
82         _hidl_cb(EvsResult::INVALID_ARG, 0);
83         return {};
84     }
85 
getExtendedInfo_1_1(uint32_t opaqueIdentifier,getExtendedInfo_1_1_cb _hidl_cb)86     Return<void> getExtendedInfo_1_1(uint32_t opaqueIdentifier,
87                                      getExtendedInfo_1_1_cb _hidl_cb) override {
88         return {};
89     }
setExtendedInfo_1_1(uint32_t opaqueIdentifier,const hidl_vec<uint8_t> & opaqueValue)90     Return<EvsResult> setExtendedInfo_1_1(uint32_t opaqueIdentifier,
91                                           const hidl_vec<uint8_t>& opaqueValue) override {
92         return EvsResult::OK;
93     }
importExternalBuffers(const hidl_vec<BufferDesc_1_1> & buffers,importExternalBuffers_cb _hidl_cb)94     Return<void> importExternalBuffers(const hidl_vec<BufferDesc_1_1>& buffers,
95                                        importExternalBuffers_cb _hidl_cb) override {
96         return {};
97     }
98 
99 private:
100     std::map<uint32_t, int32_t> mExtendedInfo;
101     std::map<uint32_t, int32_t> mExtendedInfo_1_1;
102 };
103 
104 }  // namespace implementation
105 }  // namespace V1_1
106 }  // namespace evs
107 }  // namespace automotive
108 }  // namespace android
109 
110 #endif  // EVS_MANAGER_1_1_TEST_FUZZER_MOCKHWCAMERA_H_
111