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