• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "hdi_host_test.h"
17 
18 using namespace OHOS;
19 using namespace std;
20 using namespace testing::ext;
21 using namespace OHOS::Camera;
22 
SetUpTestCase(void)23 void HdiHostTest::SetUpTestCase(void) {}
TearDownTestCase(void)24 void HdiHostTest::TearDownTestCase(void) {}
SetUp(void)25 void HdiHostTest::SetUp(void)
26 {
27     Test_ = std::make_shared<OHOS::Camera::Test>();
28     Test_->Init();
29 }
TearDown(void)30 void HdiHostTest::TearDown(void)
31 {
32     Test_->Close();
33 }
34 
35 /**
36   * @tc.name: SetCallback
37   * @tc.desc: CamRetCode SetCallback([in] ICameraHostCallback callback);
38   * @tc.size: MediumTest
39   * @tc.type: Function
40   */
41 HWTEST_F(HdiHostTest, Camera_Hdi_0001, TestSize.Level0)
42 {
43     std::cout << "==========[test log]Check hdi_host: init setcallback success." << std::endl;
44 }
45 
46 /**
47   * @tc.name: GetCameraIds
48   * @tc.desc: CamRetCode GetCameraIds([out] String[] ids);
49   * @tc.size: MediumTest
50   * @tc.type: Function
51   */
52 HWTEST_F(HdiHostTest, Camera_Hdi_0010, TestSize.Level0)
53 {
54     std::cout << "==========[test log]Check hdi_host: GetCameraIds([out] String[] ids)." << std::endl;
55     if (Test_->cameraDevice == nullptr) {
56         Test_->rc = Test_->service->GetCameraIds(Test_->cameraIds);
57         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
58         EXPECT_LT(0, Test_->cameraIds.size());
59         std::cout << "==========[test log]Check hdi_host:cameraIds.size()= ."<< Test_->cameraIds.size() << std::endl;
60     }
61 }
62 
63 /**
64   * @tc.name: GetCameraAbility
65   * @tc.desc: GetCameraAbility, normal cameraId.
66   * @tc.size: MediumTest
67   * @tc.type: Function
68   */
69 HWTEST_F(HdiHostTest, Camera_Hdi_0020, TestSize.Level0)
70 {
71     std::cout << "==========[test log]Check hdi_host: GetCameraAbility, normal cameraId." << std::endl;
72     if (Test_->cameraDevice == nullptr) {
73         Test_->rc = Test_->service->GetCameraIds(Test_->cameraIds);
74         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
75         for (int i=0; i<Test_->cameraIds.size(); i++) {
76             Test_->rc = Test_->service->GetCameraAbility(Test_->cameraIds[i], Test_->ability);
77             std::cout << "==========[test log]Check hdi_host: cameraid = " << Test_->cameraIds[i] << std::endl;
78             EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
79         }
80     }
81 }
82 
83 /**
84   * @tc.name: GetCameraAbility
85   * @tc.desc: GetCameraAbility, abnormal cameraId = 'abc'.
86   * @tc.size: MediumTest
87   * @tc.type: Function
88   */
89 HWTEST_F(HdiHostTest, Camera_Hdi_0021, TestSize.Level2)
90 {
91     std::cout << "==========[test log]Check hdi_host: GetCameraAbility, abnormal cameraId = 'abc'." << std::endl;
92     if (Test_->cameraDevice == nullptr) {
93         std::string cameraId = "abc";
94         Test_->rc = Test_->service->GetCameraAbility(cameraId, Test_->ability);
95         std::cout << "==========[test log]Check hdi_host: Test_->rc ="<< Test_->rc << std::endl;
96         EXPECT_EQ(true, Test_->rc == Camera::CamRetCode::INVALID_ARGUMENT);
97     }
98 }
99 
100 /**
101   * @tc.name: GetCameraAbility
102   * @tc.desc: GetCameraAbility, abnormal cameraId = ''
103   * @tc.size: MediumTest
104   * @tc.type: Function
105   */
106 HWTEST_F(HdiHostTest, Camera_Hdi_0022, TestSize.Level2)
107 {
108     std::cout << "==========[test log]Check hdi_host: GetCameraAbility, abnormal cameraId = ''." << std::endl;
109     if (Test_->cameraDevice == nullptr) {
110         std::string cameraId = "";
111         Test_->rc = Test_->service->GetCameraAbility(cameraId, Test_->ability);
112         std::cout << "==========[test log]Check hdi_host: Test_->rc ="<< Test_->rc << std::endl;
113         EXPECT_EQ(true, Test_->rc == Camera::CamRetCode::INVALID_ARGUMENT);
114     }
115 }
116 
117 /**
118   * @tc.name: OpenCamera
119   * @tc.desc: OpenCamera, normal cameraId.
120   * @tc.size: MediumTest
121   * @tc.type: Function
122   */
123 HWTEST_F(HdiHostTest, Camera_Hdi_0030, TestSize.Level0)
124 {
125     std::cout << "==========[test log]Check hdi_host: OpenCamera, normal cameraId."<< std::endl;
126     if (Test_->cameraDevice == nullptr) {
127         Test_->service->GetCameraIds(Test_->cameraIds);
128         Test_->CreateDeviceCallback();
129         Test_->rc = Test_->service->OpenCamera(Test_->cameraIds.front(), Test_->deviceCallback, Test_->cameraDevice);
130         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
131         if (Test_->rc != Camera::NO_ERROR || Test_->cameraDevice == nullptr) {
132             std::cout << "==========[test log]Check hdi_host: OpenCamera failed." << std::endl;
133             return;
134         }
135         std::cout << "==========[test log]Check hdi_host: OpenCamera success." << std::endl;
136     }
137 }
138 
139 /**
140   * @tc.name: OpenCamera
141   * @tc.desc: OpenCamera, cameraID is not found.
142   * @tc.size: MediumTest
143   * @tc.type: Function
144   */
145 HWTEST_F(HdiHostTest, Camera_Hdi_0031, TestSize.Level2)
146 {
147     std::cout << "==========[test log]Check hdi_host: OpenCamera, cameraID is not found."<< std::endl;
148     if (Test_->cameraDevice == nullptr) {
149         std::string cameraId = "qwerty";
150         Test_->CreateDeviceCallback();
151         Test_->rc = Test_->service->OpenCamera(cameraId, Test_->deviceCallback, Test_->cameraDevice);
152         EXPECT_EQ(true, Test_->rc == Camera::INVALID_ARGUMENT);
153     }
154 }
155 
156 /**
157   * @tc.name: OpenCamera
158   * @tc.desc: OpenCamera, cameraID is illegal.
159   * @tc.size: MediumTest
160   * @tc.type: Function
161   */
162 HWTEST_F(HdiHostTest, Camera_Hdi_0032, TestSize.Level2)
163 {
164     std::cout << "==========[test log]Check hdi_host: OpenCamera, cameraID is illegal."<< std::endl;
165     if (Test_->cameraDevice == nullptr) {
166         std::string cameraId = "1";
167         Test_->CreateDeviceCallback();
168         Test_->rc = Test_->service->OpenCamera(cameraId, Test_->deviceCallback, Test_->cameraDevice);
169         EXPECT_EQ(true, Test_->rc == Camera::INVALID_ARGUMENT);
170     }
171 }
172 
173 /**
174   * @tc.name: OpenCamera
175   * @tc.desc: OpenCamera, cameraID is Empty.
176   * @tc.size: MediumTest
177   * @tc.type: Function
178   */
179 HWTEST_F(HdiHostTest, Camera_Hdi_0033, TestSize.Level2)
180 {
181     std::cout << "==========[test log]Check hdi_host: OpenCamera, cameraID is Empty."<< std::endl;
182     if (Test_->cameraDevice == nullptr) {
183         std::string cameraId = "";
184         Test_->CreateDeviceCallback();
185         Test_->rc = Test_->service->OpenCamera(cameraId, Test_->deviceCallback, Test_->cameraDevice);
186         EXPECT_EQ(true, Test_->rc == Camera::INVALID_ARGUMENT);
187     }
188 }
189 
190 /**
191   * @tc.name: OpenCamera
192   * @tc.desc: OpenCamera, Callback is Null.
193   * @tc.size: MediumTest
194   * @tc.type: Function
195   */
196 HWTEST_F(HdiHostTest, Camera_Hdi_0034, TestSize.Level2)
197 {
198     std::cout << "==========[test log]Check hdi_host: OpenCamera, Callback is Null."<< std::endl;
199     if (Test_->cameraDevice == nullptr) {
200         Test_->service->GetCameraIds(Test_->cameraIds);
201         Test_->deviceCallback = nullptr;
202         Test_->rc = Test_->service->OpenCamera(Test_->cameraIds.front(), Test_->deviceCallback, Test_->cameraDevice);
203         EXPECT_EQ(true, Test_->rc == Camera::INVALID_ARGUMENT);
204     }
205 }
206 
207 /**
208   * @tc.name: OpenCamera
209   * @tc.desc: cameraID is not found, callback is null.
210   * @tc.size: MediumTest
211   * @tc.type: Function
212   */
213 HWTEST_F(HdiHostTest, Camera_Hdi_0035, TestSize.Level2)
214 {
215     std::cout << "==========[test log]Check hdi_host: OpenCamera, cameraID is not found, callback is null."<< std::endl;
216     if (Test_->cameraDevice == nullptr) {
217         std::string cameraId = "abc";
218         Test_->CreateDeviceCallback();
219         Test_->rc = Test_->service->OpenCamera(cameraId, Test_->deviceCallback, Test_->cameraDevice);
220         EXPECT_EQ(true, Test_->rc == Camera::INVALID_ARGUMENT);
221     }
222 }
223 
224 /**
225   * @tc.name: SetFlashlight
226   * @tc.desc: SetFlashlight, normal cameraId.
227   * @tc.size: MediumTest
228   * @tc.type: Function
229   */
230 HWTEST_F(HdiHostTest, Camera_Hdi_0040, TestSize.Level0)
231 {
232     std::cout << "==========[test log]Check hdi_host: SetFlashlight, normal cameraId." << std::endl;
233     if (Test_->cameraDevice == nullptr) {
234         Test_->service->GetCameraIds(Test_->cameraIds);
235         Test_->status = true;
236         Test_->rc = Test_->service->SetFlashlight(Test_->cameraIds.front(), Test_->status);
237         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
238     }
239 }
240 
241 /**
242   * @tc.name: SetFlashlight
243   * @tc.desc: SetFlashlight, cameraId is not found.
244   * @tc.size: MediumTest
245   * @tc.type: Function
246   */
247 HWTEST_F(HdiHostTest, Camera_Hdi_0041, TestSize.Level2)
248 {
249     std::cout << "==========[test log]Check hdi_host: SetFlashlight, cameraId is not found." << std::endl;
250     if (Test_->cameraDevice == nullptr) {
251         std::string cameraId = "abc";
252         Test_->status = true;
253         Test_->rc = Test_->service->SetFlashlight(cameraId, Test_->status);
254         EXPECT_EQ(true, Test_->rc == Camera::INVALID_ARGUMENT);
255     }
256 }
257 
258 /**
259   * @tc.name: SetFlashlight
260   * @tc.desc: SetFlashlight, cameraId is empty.
261   * @tc.size: MediumTest
262   * @tc.type: Function
263   */
264 HWTEST_F(HdiHostTest, Camera_Hdi_0042, TestSize.Level2)
265 {
266     std::cout << "==========[test log]Check hdi_host: SetFlashlight, cameraId is empty." << std::endl;
267     if (Test_->cameraDevice == nullptr) {
268         std::string cameraId = "";
269         Test_->status = true;
270         Test_->rc = Test_->service->SetFlashlight(cameraId, Test_->status);
271         EXPECT_EQ(true, Test_->rc == Camera::INVALID_ARGUMENT);
272     }
273 }
274 
275 /**
276   * @tc.name: SetFlashlight
277   * @tc.desc: SetFlashlight, status is true.
278   * @tc.size: MediumTest
279   * @tc.type: Function
280   */
281 HWTEST_F(HdiHostTest, Camera_Hdi_0043, TestSize.Level2)
282 {
283     std::cout << "==========[test log]Check hdi_host: SetFlashlight, normal cameraId." << std::endl;
284     if (Test_->cameraDevice == nullptr) {
285         Test_->service->GetCameraIds(Test_->cameraIds);
286         Test_->status = true;
287         Test_->rc = Test_->service->SetFlashlight(Test_->cameraIds.front(), Test_->status);
288         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
289     }
290 }
291 
292 /**
293   * @tc.name: SetFlashlight
294   * @tc.desc: SetFlashlight, status is false.
295   * @tc.size: MediumTest
296   * @tc.type: Function
297   */
298 HWTEST_F(HdiHostTest, Camera_Hdi_0044, TestSize.Level2)
299 {
300     std::cout << "==========[test log]Check hdi_host: SetFlashlight, normal cameraId." << std::endl;
301     if (Test_->cameraDevice == nullptr) {
302         Test_->service->GetCameraIds(Test_->cameraIds);
303         Test_->status = false;
304         Test_->rc = Test_->service->SetFlashlight(Test_->cameraIds.front(), Test_->status);
305         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
306     }
307 }
308