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 #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) {}
TearDownTestCase(void)23 void OpenCameraTest::TearDownTestCase(void) {}
SetUp(void)24 void OpenCameraTest::SetUp(void)
25 {
26     Test_ = std::make_shared<OHOS::Camera::Test>();
27     Test_->Init();
28 }
TearDown(void)29 void OpenCameraTest::TearDown(void)
30 {
31     ;
32 }
33 
34 /**
35   * @tc.name: OpenCamera
36   * @tc.desc: OpenCamera, success.
37   * @tc.size: MediumTest
38   * @tc.type: Function
39   */
40 HWTEST_F(OpenCameraTest, Camera_Open_0001, TestSize.Level0)
41 {
42     std::cout << "==========[test log]OpenCamera, success."<< std::endl;
43     Test_->service->GetCameraIds(Test_->cameraIds);
44     std::cout << "==========[test log]cameraIds size = "<< Test_->cameraIds.size() << std::endl;
45     for (const auto &cameraId : Test_->cameraIds) {
46         std::cout << "==========[test log]cameraId = " << cameraId << std::endl;
47     }
48     std::string cameraId = Test_->cameraIds.front();
49     Test_->CreateDeviceCallback();
50     Test_->rc = Test_->service->OpenCamera(cameraId, Test_->deviceCallback, Test_->cameraDevice);
51     EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
52     if (Test_->rc== Camera::NO_ERROR) {
53         std::cout << "==========[test log]OpenCamera success." << std::endl;
54     } else {
55         std::cout << "==========[test log]OpenCamera fail, rc = " << Test_->rc << std::endl;
56     }
57     if (Test_->cameraDevice != nullptr) {
58         Test_->cameraDevice->Close();
59         std::cout << "==========[test log]Test_->cameraDevice->Close()." << std::endl;
60     }
61 }
62 
63 /**
64   * @tc.name: Open all Cameras
65   * @tc.desc: Open every Cameras what the getCameraId get.
66   * @tc.size: MediumTest
67   * @tc.type: Function
68   */
69 HWTEST_F(OpenCameraTest, Camera_Open_0010, TestSize.Level2)
70 {
71     std::cout << "==========[test log]Open all Cameras."<< std::endl;
72     Test_->service->GetCameraIds(Test_->cameraIds);
73     for (auto &cameraId : Test_->cameraIds) {
74         std::cout << "cameraId = " << cameraId << std::endl;
75         Test_->CreateDeviceCallback();
76         Test_->rc = Test_->service->OpenCamera(cameraId, Test_->deviceCallback, Test_->cameraDevice);
77         EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
78         if (Test_->rc== Camera::NO_ERROR) {
79         std::cout << "==========[test log]OpenCamera success, cameraId = " << cameraId << std::endl;
80         } else {
81             std::cout << "==========[test log]OpenCamera fail, Test_->rc = ";
82             std::cout << Test_->rc << ", cameraId = " << cameraId << std::endl;
83         }
84 
85         if (Test_->cameraDevice != nullptr) {
86             Test_->cameraDevice->Close();
87         }
88     }
89 }
90 
main(int argc,char * argv[])91 int main(int argc, char *argv[])
92 {
93     // start test
94     testing::InitGoogleTest(&argc, argv);
95     return RUN_ALL_TESTS();
96 }
97