1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file expected 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 "camera_ability_test.h"
16
17 using namespace testing::ext;
18
SetUpTestCase(void)19 void CameraAbilityTest::SetUpTestCase(void) {}
20
TearDownTestCase(void)21 void CameraAbilityTest::TearDownTestCase(void) {}
22
SetUp(void)23 void CameraAbilityTest::SetUp(void)
24 {
25 if (display_ == nullptr) {
26 display_ = std::make_shared<TestDisplay>();
27 }
28 display_->Init();
29 }
30
GetSensorOrientation(std::shared_ptr<CameraAbility> & ability)31 OHOS::Camera::RetCode CameraAbilityTest::GetSensorOrientation(std::shared_ptr<CameraAbility> &ability)
32 {
33 common_metadata_header_t *data = display_->ability->get();
34 int32_t sensorOrientation;
35 camera_metadata_item_t entry;
36 int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_SENSOR_ORIENTATION, &entry);
37 if (ret != 0) {
38 std::cout << "==========[test log] get OHOS_SENSOR_ORIENTATION error." << std::endl;
39 return OHOS::Camera::RC_ERROR;
40 }
41 sensorOrientation = *(entry.data.i32);
42 std::cout << "==========[test log] get sensorOrientation =" << sensorOrientation << std::endl;
43 return OHOS::Camera::RC_OK;
44 }
45
GetFlashAvailable(std::shared_ptr<CameraAbility> & ability)46 OHOS::Camera::RetCode CameraAbilityTest::GetFlashAvailable(std::shared_ptr<CameraAbility> &ability)
47 {
48 common_metadata_header_t *data = display_->ability->get();
49 uint8_t flashAvailable;
50 camera_metadata_item_t entry;
51 int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_FLASH_AVAILABLE, &entry);
52 if (ret != 0) {
53 std::cout << "==========[test log] get OHOS_ABILITY_FLASH_AVAILABLE error." << std::endl;
54 return OHOS::Camera::RC_ERROR;
55 }
56 flashAvailable = *(entry.data.u8);
57 std::cout << "==========[test log] get flashAvailable =" << static_cast<int>(flashAvailable) << std::endl;
58 return OHOS::Camera::RC_OK;
59 }
60
GetAfAvailable(std::shared_ptr<CameraAbility> & ability)61 OHOS::Camera::RetCode CameraAbilityTest::GetAfAvailable(std::shared_ptr<CameraAbility> &ability)
62 {
63 common_metadata_header_t *data = display_->ability->get();
64 std::vector<uint8_t> afAvailable;
65 camera_metadata_item_t entry;
66 int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_CONTROL_AF_AVAILABLE_MODES, &entry);
67 if (ret != 0) {
68 std::cout << "==========[test log] get OHOS_CONTROL_AF_AVAILABLE_MODES error." << std::endl;
69 return OHOS::Camera::RC_ERROR;
70 }
71 uint32_t count = entry.count;
72 std::cout << "==========[test log] count =" << count << std::endl;
73
74 for (int i = 0; i < count; i++) {
75 afAvailable.push_back(*(entry.data.u8 + i));
76 }
77
78 for (auto it = afAvailable.begin(); it != afAvailable.end(); it++) {
79 std::cout << "==========[test log] afAvailable =" << static_cast<int>(*it) << std::endl;
80 }
81 return OHOS::Camera::RC_OK;
82 }
83
GetZoomRatioRange(std::shared_ptr<CameraAbility> & ability)84 OHOS::Camera::RetCode CameraAbilityTest::GetZoomRatioRange(std::shared_ptr<CameraAbility> &ability)
85 {
86 common_metadata_header_t *data = display_->ability->get();
87 std::vector<float> zoomRatioRange;
88 camera_metadata_item_t entry;
89 int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_ZOOM_RATIO_RANGE, &entry);
90 if (ret != 0) {
91 std::cout << "==========[test log] get OHOS_ABILITY_ZOOM_RATIO_RANGE error." << std::endl;
92 return OHOS::Camera::RC_ERROR;
93 }
94 uint32_t count = entry.count;
95 std::cout << "==========[test log] count =" << count << std::endl;
96
97 for (int i = 0; i < count; i++) {
98 zoomRatioRange.push_back(*(entry.data.f + i));
99 }
100
101 for (auto it = zoomRatioRange.begin(); it != zoomRatioRange.end(); it++) {
102 std::cout << "==========[test log] zoomRatioRange =" << *it << std::endl;
103 }
104 return OHOS::Camera::RC_OK;
105 }
106
GetJpegOrientation(std::shared_ptr<CameraAbility> & ability)107 OHOS::Camera::RetCode CameraAbilityTest::GetJpegOrientation(std::shared_ptr<CameraAbility> &ability)
108 {
109 common_metadata_header_t *data = display_->ability->get();
110 int32_t jpegOrientation;
111 camera_metadata_item_t entry;
112 int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_JPEG_ORIENTATION, &entry);
113 if (ret != 0) {
114 std::cout << "==========[test log] get OHOS_JPEG_ORIENTATION error." << std::endl;
115 return OHOS::Camera::RC_ERROR;
116 }
117 jpegOrientation = *(entry.data.i32);
118 std::cout << "==========[test log] get jpegOrientation =" << jpegOrientation << std::endl;
119 return OHOS::Camera::RC_OK;
120 }
121
TearDown(void)122 void CameraAbilityTest::TearDown(void)
123 {
124 display_->Close();
125 }
126
127 /**
128 * @tc.name: get camera ability
129 * @tc.desc: get camera ability
130 * @tc.level: Level1
131 * @tc.size: MediumTest
132 * @tc.type: Function
133 */
134 static HWTEST_F(CameraAbilityTest, camera_ability_001, TestSize.Level1)
135 {
136 if (display_->ability == nullptr) {
137 std::cout << "==========[test log] ability is null." << std::endl;
138 return;
139 }
140 GetSensorOrientation(display_->ability);
141 GetFlashAvailable(display_->ability);
142 GetAfAvailable(display_->ability);
143 GetZoomRatioRange(display_->ability);
144 GetJpegOrientation(display_->ability);
145 }
146