• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #include "open_camera_test.h"
16 
17 using namespace OHOS;
18 using namespace std;
19 using namespace testing::ext;
20 using namespace OHOS::Camera;
21 
SetUpTestCase(void)22 void OpenCameraTest::SetUpTestCase(void)
23 {}
TearDownTestCase(void)24 void OpenCameraTest::TearDownTestCase(void)
25 {}
SetUp(void)26 void OpenCameraTest::SetUp(void)
27 {
28     if (display_ == nullptr) {
29         display_ = std::make_shared<TestDisplay>();
30         display_->Init();
31     }
32 }
TearDown(void)33 void OpenCameraTest::TearDown(void)
34 {
35     display_->Close();
36 }
37 
38 /**
39   * @tc.name: OpenCamera
40   * @tc.desc: OpenCamera, success.
41   * @tc.level: Level0
42   * @tc.size: MediumTest
43   * @tc.type: Function
44   */
45 HWTEST_F(OpenCameraTest, SUB_DriverSystem_CameraHdi_0010, TestSize.Level0)
46 {
47     std::vector<std::string> cameraIds;
48     display_->cameraHost->GetCameraIds(cameraIds);
49     for (auto &cameraId : cameraIds) {
50         std::cout << "cameraId = " << cameraId << std::endl;
51     }
52     std::string cameraId = cameraIds.front();
53     const OHOS::sptr<ICameraDeviceCallback> callback = new DemoCameraDeviceCallback();
54     OHOS::sptr<ICameraDevice> cameraDevice;
55     display_->rc = (CamRetCode)display_->cameraHost->OpenCamera(cameraId, callback, cameraDevice);
56     EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
57 }
58 
59 /**
60   * @tc.name: OpenCamera cameraID input error
61   * @tc.desc: OpenCamera, cameraID is not found.
62   * @tc.level: Level2
63   * @tc.size: MediumTest
64   * @tc.type: Function
65   */
66 HWTEST_F(OpenCameraTest, SUB_DriverSystem_CameraHdi_0670, TestSize.Level0)
67 {
68     CAMERA_LOGD("OpenCamera, cameraID is not found.");
69     std::string cameraId = "qwerty";
70     OHOS::sptr<ICameraDeviceCallback> callback = new DemoCameraDeviceCallback();
71     CAMERA_LOGD("opencamera begin");
72     display_->rc = (CamRetCode)display_->cameraHost->OpenCamera(cameraId, callback, display_->cameraDevice);
73     CAMERA_LOGD("opencamera end");
74     EXPECT_EQ(INVALID_ARGUMENT, display_->rc);
75 }
76 
77 /**
78   * @tc.name: OpenCamera cameraID input error
79   * @tc.desc: OpenCamera, cameraID is illegal.
80   * @tc.level: Level2
81   * @tc.size: MediumTest
82   * @tc.type: Function
83   */
84 HWTEST_F(OpenCameraTest, SUB_DriverSystem_CameraHdi_0680, TestSize.Level0)
85 {
86     CAMERA_LOGD("OpenCamera, cameraID is illegal.");
87     std::string cameraId = "1";
88     OHOS::sptr<ICameraDeviceCallback> callback = new DemoCameraDeviceCallback();
89     display_->rc = (CamRetCode)display_->cameraHost->OpenCamera(cameraId, callback, display_->cameraDevice);
90     EXPECT_EQ(INVALID_ARGUMENT, display_->rc);
91 }
92 
93 /**
94   * @tc.name: OpenCamera cameraID input error
95   * @tc.desc: OpenCamera, cameraID is Empty.
96   * @tc.level: Level2
97   * @tc.size: MediumTest
98   * @tc.type: Function
99   */
100 HWTEST_F(OpenCameraTest, SUB_DriverSystem_CameraHdi_0690, TestSize.Level0)
101 {
102     std::cout << "==========[test log] OpenCamera, cameraID is Empty."<< std::endl;
103     std::string cameraId;
104     OHOS::sptr<ICameraDeviceCallback> callback = new DemoCameraDeviceCallback();
105     display_->rc = (CamRetCode)display_->cameraHost->OpenCamera(cameraId, callback, display_->cameraDevice);
106     EXPECT_EQ(INVALID_ARGUMENT, display_->rc);
107 }
108 
109 /**
110   * @tc.name: OpenCamera Callback input error
111   * @tc.desc: OpenCamera, Callback is Null.
112   * @tc.level: Level2
113   * @tc.size: MediumTest
114   * @tc.type: Function
115   */
116 HWTEST_F(OpenCameraTest, SUB_DriverSystem_CameraHdi_0700, TestSize.Level0)
117 {
118     std::cout << "==========[test log] OpenCamera, Callback is Null."<< std::endl;
119     std::string cameraId = "CAMERA_FIRST";
120     OHOS::sptr<ICameraDeviceCallback> callback = nullptr;
121     display_->rc = (CamRetCode)display_->cameraHost->OpenCamera(cameraId, callback, display_->cameraDevice);
122     EXPECT_EQ(INVALID_ARGUMENT, display_->rc);
123 }
124 
125 /**
126   * @tc.name: OpenCamera cameraID & Callback input error
127   * @tc.desc: OpenCamera, cameraID is not found, callback is null.
128   * @tc.level: Level1
129   * @tc.size: MediumTest
130   * @tc.type: Function
131   */
132 HWTEST_F(OpenCameraTest, SUB_DriverSystem_CameraHdi_0710, TestSize.Level0)
133 {
134     std::cout << "==========[test log] OpenCamera, cameraID is not found, callback is null."<< std::endl;
135     std::string cameraId = "qwerty";
136     OHOS::sptr<ICameraDeviceCallback> callback = nullptr;
137     std::cout << "opencamera begin" << std::endl;
138     display_->rc = (CamRetCode)display_->cameraHost->OpenCamera(cameraId, callback, display_->cameraDevice);
139     std::cout << "opencamera end" << std::endl;
140     EXPECT_EQ(INVALID_ARGUMENT, display_-> rc);
141 }
142 
143 /**
144   * @tc.name: OpenCamera cameraID & Callback input error
145   * @tc.desc: OpenCamera, cameraID is illegal, callback is null.
146   * @tc.level: Level1
147   * @tc.size: MediumTest
148   * @tc.type: Function
149   */
150 HWTEST_F(OpenCameraTest, camera_open_0031, TestSize.Level0)
151 {
152     std::cout << "==========[test log] OpenCamera, cameraID is illegal, callback is null."<< std::endl;
153     std::string cameraId = "1";
154     OHOS::sptr<ICameraDeviceCallback> callback = nullptr;
155     display_->rc = (CamRetCode)display_->cameraHost->OpenCamera(cameraId, callback, display_->cameraDevice);
156     EXPECT_EQ(INVALID_ARGUMENT, display_-> rc);
157 }
158 
159 /**
160   * @tc.name: OpenCamera cameraID & Callback input error
161   * @tc.desc: OpenCamera, cameraID is Empty, callback is null.
162   * @tc.level: Level1
163   * @tc.size: MediumTest
164   * @tc.type: Function
165   */
166 HWTEST_F(OpenCameraTest, camera_open_0032, TestSize.Level0)
167 {
168     std::cout << "==========[test log] OpenCamera, cameraID is Empty, callback is null."<< std::endl;
169     std::string cameraId;
170     OHOS::sptr<ICameraDeviceCallback> callback = nullptr;
171     display_->rc = (CamRetCode)display_->cameraHost->OpenCamera(cameraId, callback, display_->cameraDevice);
172     EXPECT_EQ(INVALID_ARGUMENT, display_->rc);
173 }
174 
175 /**
176   * @tc.name: Open all Cameras
177   * @tc.desc: Open every Cameras what the getCameraId get.
178   * @tc.level: Level2
179   * @tc.size: MediumTest
180   * @tc.type: Function
181   */
182 HWTEST_F(OpenCameraTest, SUB_DriverSystem_CameraHdi_0020, TestSize.Level0)
183 {
184     std::cout << "==========[test log] Open all Cameras."<< std::endl;
185     std::vector<std::string> cameraIds;
186     display_->cameraHost->GetCameraIds(cameraIds);
187     for (auto &cameraId : cameraIds) {
188         std::cout << "cameraId = " << cameraId << std::endl;
189         const OHOS::sptr<ICameraDeviceCallback> callback = new DemoCameraDeviceCallback();
190         display_->rc = (CamRetCode)display_->cameraHost->OpenCamera(cameraId, callback, display_->cameraDevice);
191         EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
192         if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
193             std::cout << "==========[test log] OpenCamera success, cameraId = " << cameraId << std::endl;
194             } else {
195                 std::cout << "==========[test log] OpenCamera fail, rc = ";
196                 std::cout << display_->rc << ", cameraId = " << cameraId << std::endl;
197             }
198         }
199 }