• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 OHOS_DISTRIBUTED_CAMERA_MOCKSOURCE_DEV_H
17 #define OHOS_DISTRIBUTED_CAMERA_MOCKSOURCE_DEV_H
18 
19 #include "dcamera_source_dev.h"
20 
21 #include "distributed_camera_errno.h"
22 #include "idistributed_camera_source.h"
23 
24 namespace OHOS {
25 namespace DistributedHardware {
26 extern std::string g_regisStateStr;
27 extern std::string g_openStateStr;
28 extern std::string g_captureStateStr;
29 class MockDCameraSourceDev : public DCameraSourceDev {
30 public:
MockDCameraSourceDev(std::string devId,std::string dhId,std::shared_ptr<ICameraStateListener> & stateLisener)31     MockDCameraSourceDev(std::string devId, std::string dhId, std::shared_ptr<ICameraStateListener>& stateLisener)
32         : DCameraSourceDev(devId, dhId, stateLisener) {};
33     ~MockDCameraSourceDev() = default;
34 
Register(std::shared_ptr<DCameraRegistParam> & param)35     int32_t Register(std::shared_ptr<DCameraRegistParam>& param)
36     {
37         if (g_regisStateStr == "test008") {
38             return DCAMERA_BAD_VALUE;
39         }
40         return DCAMERA_OK;
41     }
UnRegister(std::shared_ptr<DCameraRegistParam> & param)42     int32_t UnRegister(std::shared_ptr<DCameraRegistParam>& param)
43     {
44         if (g_regisStateStr == "test008" || g_openStateStr == "test010" || g_captureStateStr == "test014") {
45             return DCAMERA_BAD_VALUE;
46         }
47         return DCAMERA_OK;
48     }
OpenCamera()49     int32_t OpenCamera()
50     {
51         if (g_regisStateStr == "test008") {
52             return DCAMERA_BAD_VALUE;
53         }
54         return DCAMERA_OK;
55     }
CloseCamera()56     int32_t CloseCamera()
57     {
58         if (g_openStateStr == "test010" || g_openStateStr == "test012" || g_captureStateStr == "test014" ||
59             g_captureStateStr == "test017") {
60             return DCAMERA_BAD_VALUE;
61         }
62         return DCAMERA_OK;
63     }
ConfigStreams(std::vector<std::shared_ptr<DCStreamInfo>> & streamInfos)64     int32_t ConfigStreams(std::vector<std::shared_ptr<DCStreamInfo>>& streamInfos)
65     {
66         if (g_openStateStr == "test010") {
67             return DCAMERA_BAD_VALUE;
68         }
69         return DCAMERA_OK;
70     }
ReleaseStreams(std::vector<int> & streamIds,bool & isAllRelease)71     int32_t ReleaseStreams(std::vector<int>& streamIds, bool& isAllRelease)
72     {
73         isAllRelease = true;
74         return DCAMERA_OK;
75     }
ReleaseAllStreams()76     int32_t ReleaseAllStreams()
77     {
78         if (g_captureStateStr == "test018" || g_captureStateStr == "test020") {
79             return DCAMERA_BAD_VALUE;
80         }
81         return DCAMERA_OK;
82     }
StartCapture(std::vector<std::shared_ptr<DCCaptureInfo>> & captureInfos)83     int32_t StartCapture(std::vector<std::shared_ptr<DCCaptureInfo>>& captureInfos)
84     {
85         if (g_captureStateStr == "test014") {
86             return DCAMERA_BAD_VALUE;
87         }
88         return DCAMERA_OK;
89     }
StopCapture(std::vector<int> & streamIds,bool & isAllStop)90     int32_t StopCapture(std::vector<int>& streamIds, bool& isAllStop)
91     {
92         if (g_captureStateStr == "test014") {
93             return DCAMERA_BAD_VALUE;
94         }
95         isAllStop = true;
96         return DCAMERA_OK;
97     }
StopAllCapture()98     int32_t StopAllCapture()
99     {
100         if (g_captureStateStr == "test016" || g_captureStateStr == "test019") {
101             return DCAMERA_BAD_VALUE;
102         }
103         return DCAMERA_OK;
104     }
UpdateSettings(std::vector<std::shared_ptr<DCameraSettings>> & settings)105     int32_t UpdateSettings(std::vector<std::shared_ptr<DCameraSettings>>& settings)
106     {
107         if (g_openStateStr == "test010" || g_captureStateStr == "test014") {
108             return DCAMERA_BAD_VALUE;
109         }
110         return DCAMERA_OK;
111     }
CameraEventNotify(std::shared_ptr<DCameraEvent> & events)112     int32_t CameraEventNotify(std::shared_ptr<DCameraEvent>& events)
113     {
114         if (g_regisStateStr == "test008" || g_openStateStr == "test010" || g_openStateStr == "test011" ||
115             g_captureStateStr == "test014" || g_captureStateStr == "test015") {
116             return DCAMERA_BAD_VALUE;
117         }
118         return DCAMERA_OK;
119     }
120 
121 private:
122     std::string devId_;
123     std::string dhId_;
124     std::shared_ptr<ICameraStateListener> stateLisener_;
125 };
126 } // namespace DistributedHardware
127 } // namespace OHOS
128 #endif // OHOS_DISTRIBUTED_CAMERA_MOCKSOURCE_DEV_H
129