1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2020 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci#include "hdi_callback_test.h"
17094332d3Sopenharmony_ci
18094332d3Sopenharmony_ciusing namespace OHOS;
19094332d3Sopenharmony_ciusing namespace std;
20094332d3Sopenharmony_ciusing namespace testing::ext;
21094332d3Sopenharmony_ciusing namespace OHOS::Camera;
22094332d3Sopenharmony_ci
23094332d3Sopenharmony_civoid HdiCallbackTest::SetUpTestCase(void) {}
24094332d3Sopenharmony_civoid HdiCallbackTest::TearDownTestCase(void) {}
25094332d3Sopenharmony_civoid HdiCallbackTest::SetUp(void)
26094332d3Sopenharmony_ci{
27094332d3Sopenharmony_ci    Test_ = std::make_shared<OHOS::Camera::Test>();
28094332d3Sopenharmony_ci    Test_->Init();
29094332d3Sopenharmony_ci}
30094332d3Sopenharmony_civoid HdiCallbackTest::TearDown(void)
31094332d3Sopenharmony_ci{
32094332d3Sopenharmony_ci    Test_->Close();
33094332d3Sopenharmony_ci}
34094332d3Sopenharmony_ci
35094332d3Sopenharmony_ci/**
36094332d3Sopenharmony_ci  * @tc.name: OnCameraStatus
37094332d3Sopenharmony_ci  * @tc.desc: CameraHostCallback, OnCameraStatus
38094332d3Sopenharmony_ci  * @tc.size: MediumTest
39094332d3Sopenharmony_ci  * @tc.type: Function
40094332d3Sopenharmony_ci  */
41094332d3Sopenharmony_ciHWTEST_F(HdiCallbackTest, Camera_Hdi_1001, TestSize.Level0)
42094332d3Sopenharmony_ci{
43094332d3Sopenharmony_ci    Test_->Open();
44094332d3Sopenharmony_ci    Test_->onCameraStatusFlag = false;
45094332d3Sopenharmony_ci    std::cout << "==========[test log]Preview stream, 640*480, expected success." << std::endl;
46094332d3Sopenharmony_ci    // Start stream
47094332d3Sopenharmony_ci    Test_->intents = {Camera::PREVIEW};
48094332d3Sopenharmony_ci    Test_->StartStream(Test_->intents);
49094332d3Sopenharmony_ci    // Get preview
50094332d3Sopenharmony_ci    Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
51094332d3Sopenharmony_ci    // release stream
52094332d3Sopenharmony_ci    Test_->captureIds = {Test_->captureId_preview};
53094332d3Sopenharmony_ci    Test_->streamIds = {Test_->streamId_preview};
54094332d3Sopenharmony_ci    Test_->StopStream(Test_->captureIds, Test_->streamIds);
55094332d3Sopenharmony_ci    Test_->StopConsumer(Test_->intents);
56094332d3Sopenharmony_ci    if (Test_->onCameraStatusFlag) {
57094332d3Sopenharmony_ci        std::cout << "==========[test log]OnCameraStatus" << std::endl;
58094332d3Sopenharmony_ci    }
59094332d3Sopenharmony_ci    EXPECT_EQ(Test_->onCameraStatusFlag, false);
60094332d3Sopenharmony_ci}
61094332d3Sopenharmony_ci
62094332d3Sopenharmony_ci/**
63094332d3Sopenharmony_ci  * @tc.name: OnFlashlightStatus
64094332d3Sopenharmony_ci  * @tc.desc: CameraHostCallback, OnFlashlightStatus
65094332d3Sopenharmony_ci  * @tc.size: MediumTest
66094332d3Sopenharmony_ci  * @tc.type: Function
67094332d3Sopenharmony_ci  */
68094332d3Sopenharmony_ciHWTEST_F(HdiCallbackTest, Camera_Hdi_1002, TestSize.Level0)
69094332d3Sopenharmony_ci{
70094332d3Sopenharmony_ci    Test_->GetCameraAbility();
71094332d3Sopenharmony_ci    Test_->onFlashlightStatusFlag = false;
72094332d3Sopenharmony_ci    std::cout << "==========[test log]Turn on the flashlight, not the camera, success." << std::endl;
73094332d3Sopenharmony_ci    Test_->status = true;
74094332d3Sopenharmony_ci    Test_->rc = Test_->service->SetFlashlight(Test_->cameraIds.front(), Test_->status);
75094332d3Sopenharmony_ci    EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
76094332d3Sopenharmony_ci    Test_->status = false;
77094332d3Sopenharmony_ci    Test_->rc = Test_->service->SetFlashlight(Test_->cameraIds.front(), Test_->status);
78094332d3Sopenharmony_ci    sleep(3); // sleep for 3 seconds
79094332d3Sopenharmony_ci    if (Test_->onFlashlightStatusFlag) {
80094332d3Sopenharmony_ci        std::cout << "==========[test log]OnFlashlightStatus" << std::endl;
81094332d3Sopenharmony_ci    }
82094332d3Sopenharmony_ci    EXPECT_EQ(Test_->onFlashlightStatusFlag, true);
83094332d3Sopenharmony_ci}
84094332d3Sopenharmony_ci
85094332d3Sopenharmony_ci/**
86094332d3Sopenharmony_ci  * @tc.name: OnError
87094332d3Sopenharmony_ci  * @tc.desc: CameraDeviceCallback, OnError.
88094332d3Sopenharmony_ci  * @tc.size: MediumTest
89094332d3Sopenharmony_ci  * @tc.type: Function
90094332d3Sopenharmony_ci  */
91094332d3Sopenharmony_ciHWTEST_F(HdiCallbackTest, Camera_Hdi_1010, TestSize.Level0)
92094332d3Sopenharmony_ci{
93094332d3Sopenharmony_ci    Test_->Open();
94094332d3Sopenharmony_ci    Test_->onErrorFlag = false;
95094332d3Sopenharmony_ci    std::cout << "==========[test log]Preview stream, 640*480, expected success." << std::endl;
96094332d3Sopenharmony_ci    // Start stream
97094332d3Sopenharmony_ci    Test_->intents = {Camera::PREVIEW};
98094332d3Sopenharmony_ci    Test_->StartStream(Test_->intents);
99094332d3Sopenharmony_ci    // Get preview
100094332d3Sopenharmony_ci    Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
101094332d3Sopenharmony_ci    // release stream
102094332d3Sopenharmony_ci    Test_->captureIds = {Test_->captureId_preview};
103094332d3Sopenharmony_ci    Test_->streamIds = {Test_->streamId_preview};
104094332d3Sopenharmony_ci    Test_->StopStream(Test_->captureIds, Test_->streamIds);
105094332d3Sopenharmony_ci    Test_->StopConsumer(Test_->intents);
106094332d3Sopenharmony_ci    if (Test_->onErrorFlag) {
107094332d3Sopenharmony_ci        std::cout << "==========[test log]OnError" << std::endl;
108094332d3Sopenharmony_ci    }
109094332d3Sopenharmony_ci    EXPECT_EQ(Test_->onErrorFlag, false);
110094332d3Sopenharmony_ci}
111094332d3Sopenharmony_ci
112094332d3Sopenharmony_ci/**
113094332d3Sopenharmony_ci  * @tc.name: OnResult
114094332d3Sopenharmony_ci  * @tc.desc: CameraDeviceCallback, OnResult.
115094332d3Sopenharmony_ci  * @tc.size: MediumTest
116094332d3Sopenharmony_ci  * @tc.type: Function
117094332d3Sopenharmony_ci  */
118094332d3Sopenharmony_ciHWTEST_F(HdiCallbackTest, Camera_Hdi_1011, TestSize.Level0)
119094332d3Sopenharmony_ci{
120094332d3Sopenharmony_ci    Test_->onResultFlag = false;
121094332d3Sopenharmony_ci    Test_->Open();
122094332d3Sopenharmony_ci    EXPECT_EQ(true, Test_->cameraDevice != nullptr);
123094332d3Sopenharmony_ci    std::cout << "==========[test log]Check hdi_device: SetResultMode is PER_FRAME." << std::endl;
124094332d3Sopenharmony_ci    std::vector<Camera::MetaType> results;
125094332d3Sopenharmony_ci    results.push_back(OHOS_SENSOR_EXPOSURE_TIME);
126094332d3Sopenharmony_ci    results.push_back(OHOS_SENSOR_COLOR_CORRECTION_GAINS);
127094332d3Sopenharmony_ci    Test_->rc = Test_->cameraDevice->EnableResult(results);
128094332d3Sopenharmony_ci    EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
129094332d3Sopenharmony_ci    Test_->rc = Test_->cameraDevice->SetResultMode(Camera::PER_FRAME);
130094332d3Sopenharmony_ci    EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
131094332d3Sopenharmony_ci    // Start stream
132094332d3Sopenharmony_ci    Test_->intents = {Camera::PREVIEW};
133094332d3Sopenharmony_ci    Test_->StartStream(Test_->intents);
134094332d3Sopenharmony_ci    // Get preview
135094332d3Sopenharmony_ci    Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
136094332d3Sopenharmony_ci    // release stream
137094332d3Sopenharmony_ci    Test_->captureIds = {Test_->captureId_preview};
138094332d3Sopenharmony_ci    Test_->streamIds.push_back(Test_->streamId_preview);
139094332d3Sopenharmony_ci    Test_->StopStream(Test_->captureIds, Test_->streamIds);
140094332d3Sopenharmony_ci    Test_->StopConsumer(Test_->intents);
141094332d3Sopenharmony_ci    if (Test_->onResultFlag) {
142094332d3Sopenharmony_ci        std::cout << "==========[test log]OnResult" << std::endl;
143094332d3Sopenharmony_ci    }
144094332d3Sopenharmony_ci    EXPECT_EQ(Test_->onResultFlag, true);
145094332d3Sopenharmony_ci}
146094332d3Sopenharmony_ci
147094332d3Sopenharmony_ci/**
148094332d3Sopenharmony_ci  * @tc.name: OnCaptureStarted
149094332d3Sopenharmony_ci  * @tc.desc: IStreamOpereatorCallback, OnCaptureStarted
150094332d3Sopenharmony_ci  * @tc.size: MediumTest
151094332d3Sopenharmony_ci  * @tc.type: Function
152094332d3Sopenharmony_ci  */
153094332d3Sopenharmony_ciHWTEST_F(HdiCallbackTest, Camera_Hdi_1020, TestSize.Level0)
154094332d3Sopenharmony_ci{
155094332d3Sopenharmony_ci    Test_->Open();
156094332d3Sopenharmony_ci    Test_->captureStartFlag = false;
157094332d3Sopenharmony_ci    std::cout << "==========[test log]Preview stream, 640*480, expected success." << std::endl;
158094332d3Sopenharmony_ci    // Start stream
159094332d3Sopenharmony_ci    Test_->intents = {Camera::PREVIEW};
160094332d3Sopenharmony_ci    Test_->StartStream(Test_->intents);
161094332d3Sopenharmony_ci    // Get preview
162094332d3Sopenharmony_ci    Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
163094332d3Sopenharmony_ci    // release stream
164094332d3Sopenharmony_ci    Test_->captureIds = {Test_->captureId_preview};
165094332d3Sopenharmony_ci    Test_->streamIds.push_back(Test_->streamId_preview);
166094332d3Sopenharmony_ci    Test_->StopStream(Test_->captureIds, Test_->streamIds);
167094332d3Sopenharmony_ci    Test_->StopConsumer(Test_->intents);
168094332d3Sopenharmony_ci    if (Test_->captureStartFlag) {
169094332d3Sopenharmony_ci        std::cout << "==========[test log]OnCaptureStarted" << std::endl;
170094332d3Sopenharmony_ci    }
171094332d3Sopenharmony_ci    EXPECT_EQ(Test_->captureStartFlag, true);
172094332d3Sopenharmony_ci}
173094332d3Sopenharmony_ci
174094332d3Sopenharmony_ci/**
175094332d3Sopenharmony_ci  * @tc.name: OnCaptureEnded
176094332d3Sopenharmony_ci  * @tc.desc: IStreamOpereatorCallback, OnCaptureEnded
177094332d3Sopenharmony_ci  * @tc.size: MediumTest
178094332d3Sopenharmony_ci  * @tc.type: Function
179094332d3Sopenharmony_ci  */
180094332d3Sopenharmony_ciHWTEST_F(HdiCallbackTest, Camera_Hdi_1021, TestSize.Level0)
181094332d3Sopenharmony_ci{
182094332d3Sopenharmony_ci    Test_->Open();
183094332d3Sopenharmony_ci    Test_->captureEndFlag = false;
184094332d3Sopenharmony_ci    std::cout << "==========[test log]Preview stream, 640*480, expected success." << std::endl;
185094332d3Sopenharmony_ci    // Start stream
186094332d3Sopenharmony_ci    Test_->intents = {Camera::PREVIEW};
187094332d3Sopenharmony_ci    Test_->StartStream(Test_->intents);
188094332d3Sopenharmony_ci    // Get preview
189094332d3Sopenharmony_ci    Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
190094332d3Sopenharmony_ci    // release stream
191094332d3Sopenharmony_ci    Test_->captureIds = {Test_->captureId_preview};
192094332d3Sopenharmony_ci    Test_->streamIds.push_back(Test_->streamId_preview);
193094332d3Sopenharmony_ci    Test_->StopStream(Test_->captureIds, Test_->streamIds);
194094332d3Sopenharmony_ci    Test_->StopConsumer(Test_->intents);
195094332d3Sopenharmony_ci    if (Test_->captureEndFlag) {
196094332d3Sopenharmony_ci        std::cout << "==========[test log]OnCaptureEnded" << std::endl;
197094332d3Sopenharmony_ci    }
198094332d3Sopenharmony_ci    EXPECT_EQ(Test_->captureEndFlag, true);
199094332d3Sopenharmony_ci}
200094332d3Sopenharmony_ci
201094332d3Sopenharmony_ci/**
202094332d3Sopenharmony_ci  * @tc.name: OnFrameShutter
203094332d3Sopenharmony_ci  * @tc.desc: IStreamOpereatorCallback, OnFrameShutter
204094332d3Sopenharmony_ci  * @tc.size: MediumTest
205094332d3Sopenharmony_ci  * @tc.type: Function
206094332d3Sopenharmony_ci  */
207094332d3Sopenharmony_ciHWTEST_F(HdiCallbackTest, Camera_Hdi_1023, TestSize.Level0)
208094332d3Sopenharmony_ci{
209094332d3Sopenharmony_ci    Test_->Open();
210094332d3Sopenharmony_ci    Test_->frameShutterFlag = false;
211094332d3Sopenharmony_ci    std::cout << "==========[test log]Preview stream, 640*480, expected success." << std::endl;
212094332d3Sopenharmony_ci    // Start stream
213094332d3Sopenharmony_ci    Test_->intents = {Camera::PREVIEW};
214094332d3Sopenharmony_ci    Test_->StartStream(Test_->intents);
215094332d3Sopenharmony_ci    // Get preview
216094332d3Sopenharmony_ci    Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, true, true);
217094332d3Sopenharmony_ci    // release stream
218094332d3Sopenharmony_ci    Test_->captureIds = {Test_->captureId_preview};
219094332d3Sopenharmony_ci    Test_->streamIds.push_back(Test_->streamId_preview);
220094332d3Sopenharmony_ci    Test_->StopStream(Test_->captureIds, Test_->streamIds);
221094332d3Sopenharmony_ci    Test_->StopConsumer(Test_->intents);
222094332d3Sopenharmony_ci    if (Test_->frameShutterFlag) {
223094332d3Sopenharmony_ci        std::cout << "==========[test log]OnFrameShutter" << std::endl;
224094332d3Sopenharmony_ci    }
225094332d3Sopenharmony_ci    EXPECT_EQ(Test_->frameShutterFlag, true);
226094332d3Sopenharmony_ci}