• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 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_callback_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 HdiCallbackTest::SetUpTestCase(void) {}
TearDownTestCase(void)24 void HdiCallbackTest::TearDownTestCase(void) {}
SetUp(void)25 void HdiCallbackTest::SetUp(void)
26 {
27     Test_ = std::make_shared<OHOS::Camera::Test>();
28     Test_->Init();
29 }
TearDown(void)30 void HdiCallbackTest::TearDown(void)
31 {
32     Test_->Close();
33 }
34 
35 /**
36   * @tc.name: OnCameraStatus
37   * @tc.desc: CameraHostCallback, OnCameraStatus
38   * @tc.size: MediumTest
39   * @tc.type: Function
40   */
41 HWTEST_F(HdiCallbackTest, Camera_Hdi_1001, TestSize.Level0)
42 {
43     Test_->Open();
44     Test_->onCameraStatusFlag = false;
45     std::cout << "==========[test log]Preview stream, 640*480, expected success." << std::endl;
46     // Start stream
47     Test_->intents = {Camera::PREVIEW};
48     Test_->StartStream(Test_->intents);
49     // Get preview
50     Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
51     // release stream
52     Test_->captureIds = {Test_->captureId_preview};
53     Test_->streamIds = {Test_->streamId_preview};
54     Test_->StopStream(Test_->captureIds, Test_->streamIds);
55     Test_->StopConsumer(Test_->intents);
56     if (Test_->onCameraStatusFlag) {
57         std::cout << "==========[test log]OnCameraStatus" << std::endl;
58     }
59     EXPECT_EQ(Test_->onCameraStatusFlag, false);
60 }
61 
62 /**
63   * @tc.name: OnFlashlightStatus
64   * @tc.desc: CameraHostCallback, OnFlashlightStatus
65   * @tc.size: MediumTest
66   * @tc.type: Function
67   */
68 HWTEST_F(HdiCallbackTest, Camera_Hdi_1002, TestSize.Level0)
69 {
70     Test_->GetCameraAbility();
71     Test_->onFlashlightStatusFlag = false;
72     std::cout << "==========[test log]Turn on the flashlight, not the camera, success." << std::endl;
73     Test_->status = true;
74     Test_->rc = Test_->service->SetFlashlight(Test_->cameraIds.front(), Test_->status);
75     EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
76     Test_->status = false;
77     Test_->rc = Test_->service->SetFlashlight(Test_->cameraIds.front(), Test_->status);
78     sleep(3); // sleep for 3 seconds
79     if (Test_->onFlashlightStatusFlag) {
80         std::cout << "==========[test log]OnFlashlightStatus" << std::endl;
81     }
82     EXPECT_EQ(Test_->onFlashlightStatusFlag, true);
83 }
84 
85 /**
86   * @tc.name: OnError
87   * @tc.desc: CameraDeviceCallback, OnError.
88   * @tc.size: MediumTest
89   * @tc.type: Function
90   */
91 HWTEST_F(HdiCallbackTest, Camera_Hdi_1010, TestSize.Level0)
92 {
93     Test_->Open();
94     Test_->onErrorFlag = false;
95     std::cout << "==========[test log]Preview stream, 640*480, expected success." << std::endl;
96     // Start stream
97     Test_->intents = {Camera::PREVIEW};
98     Test_->StartStream(Test_->intents);
99     // Get preview
100     Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
101     // release stream
102     Test_->captureIds = {Test_->captureId_preview};
103     Test_->streamIds = {Test_->streamId_preview};
104     Test_->StopStream(Test_->captureIds, Test_->streamIds);
105     Test_->StopConsumer(Test_->intents);
106     if (Test_->onErrorFlag) {
107         std::cout << "==========[test log]OnError" << std::endl;
108     }
109     EXPECT_EQ(Test_->onErrorFlag, false);
110 }
111 
112 /**
113   * @tc.name: OnResult
114   * @tc.desc: CameraDeviceCallback, OnResult.
115   * @tc.size: MediumTest
116   * @tc.type: Function
117   */
118 HWTEST_F(HdiCallbackTest, Camera_Hdi_1011, TestSize.Level0)
119 {
120     Test_->onResultFlag = false;
121     Test_->Open();
122     EXPECT_EQ(true, Test_->cameraDevice != nullptr);
123     std::cout << "==========[test log]Check hdi_device: SetResultMode is PER_FRAME." << std::endl;
124     std::vector<Camera::MetaType> results;
125     results.push_back(OHOS_SENSOR_EXPOSURE_TIME);
126     results.push_back(OHOS_SENSOR_COLOR_CORRECTION_GAINS);
127     Test_->rc = Test_->cameraDevice->EnableResult(results);
128     EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
129     Test_->rc = Test_->cameraDevice->SetResultMode(Camera::PER_FRAME);
130     EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
131     // Start stream
132     Test_->intents = {Camera::PREVIEW};
133     Test_->StartStream(Test_->intents);
134     // Get preview
135     Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
136     // release stream
137     Test_->captureIds = {Test_->captureId_preview};
138     Test_->streamIds.push_back(Test_->streamId_preview);
139     Test_->StopStream(Test_->captureIds, Test_->streamIds);
140     Test_->StopConsumer(Test_->intents);
141     if (Test_->onResultFlag) {
142         std::cout << "==========[test log]OnResult" << std::endl;
143     }
144     EXPECT_EQ(Test_->onResultFlag, true);
145 }
146 
147 /**
148   * @tc.name: OnCaptureStarted
149   * @tc.desc: IStreamOpereatorCallback, OnCaptureStarted
150   * @tc.size: MediumTest
151   * @tc.type: Function
152   */
153 HWTEST_F(HdiCallbackTest, Camera_Hdi_1020, TestSize.Level0)
154 {
155     Test_->Open();
156     Test_->captureStartFlag = false;
157     std::cout << "==========[test log]Preview stream, 640*480, expected success." << std::endl;
158     // Start stream
159     Test_->intents = {Camera::PREVIEW};
160     Test_->StartStream(Test_->intents);
161     // Get preview
162     Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
163     // release stream
164     Test_->captureIds = {Test_->captureId_preview};
165     Test_->streamIds.push_back(Test_->streamId_preview);
166     Test_->StopStream(Test_->captureIds, Test_->streamIds);
167     Test_->StopConsumer(Test_->intents);
168     if (Test_->captureStartFlag) {
169         std::cout << "==========[test log]OnCaptureStarted" << std::endl;
170     }
171     EXPECT_EQ(Test_->captureStartFlag, true);
172 }
173 
174 /**
175   * @tc.name: OnCaptureEnded
176   * @tc.desc: IStreamOpereatorCallback, OnCaptureEnded
177   * @tc.size: MediumTest
178   * @tc.type: Function
179   */
180 HWTEST_F(HdiCallbackTest, Camera_Hdi_1021, TestSize.Level0)
181 {
182     Test_->Open();
183     Test_->captureEndFlag = false;
184     std::cout << "==========[test log]Preview stream, 640*480, expected success." << std::endl;
185     // Start stream
186     Test_->intents = {Camera::PREVIEW};
187     Test_->StartStream(Test_->intents);
188     // Get preview
189     Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
190     // release stream
191     Test_->captureIds = {Test_->captureId_preview};
192     Test_->streamIds.push_back(Test_->streamId_preview);
193     Test_->StopStream(Test_->captureIds, Test_->streamIds);
194     Test_->StopConsumer(Test_->intents);
195     if (Test_->captureEndFlag) {
196         std::cout << "==========[test log]OnCaptureEnded" << std::endl;
197     }
198     EXPECT_EQ(Test_->captureEndFlag, true);
199 }
200 
201 /**
202   * @tc.name: OnFrameShutter
203   * @tc.desc: IStreamOpereatorCallback, OnFrameShutter
204   * @tc.size: MediumTest
205   * @tc.type: Function
206   */
207 HWTEST_F(HdiCallbackTest, Camera_Hdi_1023, TestSize.Level0)
208 {
209     Test_->Open();
210     Test_->frameShutterFlag = false;
211     std::cout << "==========[test log]Preview stream, 640*480, expected success." << std::endl;
212     // Start stream
213     Test_->intents = {Camera::PREVIEW};
214     Test_->StartStream(Test_->intents);
215     // Get preview
216     Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, true, true);
217     // release stream
218     Test_->captureIds = {Test_->captureId_preview};
219     Test_->streamIds.push_back(Test_->streamId_preview);
220     Test_->StopStream(Test_->captureIds, Test_->streamIds);
221     Test_->StopConsumer(Test_->intents);
222     if (Test_->frameShutterFlag) {
223         std::cout << "==========[test log]OnFrameShutter" << std::endl;
224     }
225     EXPECT_EQ(Test_->frameShutterFlag, true);
226 }