1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file expected 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#include "camera_ability_test.h"
16094332d3Sopenharmony_ci
17094332d3Sopenharmony_ciusing namespace testing::ext;
18094332d3Sopenharmony_ci
19094332d3Sopenharmony_civoid CameraAbilityTest::SetUpTestCase(void) {}
20094332d3Sopenharmony_ci
21094332d3Sopenharmony_civoid CameraAbilityTest::TearDownTestCase(void) {}
22094332d3Sopenharmony_ci
23094332d3Sopenharmony_civoid CameraAbilityTest::SetUp(void)
24094332d3Sopenharmony_ci{
25094332d3Sopenharmony_ci    if (cameraBase_ == nullptr) {
26094332d3Sopenharmony_ci        cameraBase_ = std::make_shared<TestCameraBase>();
27094332d3Sopenharmony_ci    }
28094332d3Sopenharmony_ci    cameraBase_->Init();
29094332d3Sopenharmony_ci}
30094332d3Sopenharmony_ci
31094332d3Sopenharmony_ciOHOS::Camera::RetCode CameraAbilityTest::GetSensorOrientation(std::shared_ptr<CameraAbility> &ability)
32094332d3Sopenharmony_ci{
33094332d3Sopenharmony_ci    common_metadata_header_t *data = cameraBase_->ability->get();
34094332d3Sopenharmony_ci    int32_t sensorOrientation;
35094332d3Sopenharmony_ci    camera_metadata_item_t entry;
36094332d3Sopenharmony_ci    int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_SENSOR_ORIENTATION, &entry);
37094332d3Sopenharmony_ci    if (ret != 0) {
38094332d3Sopenharmony_ci        CAMERA_LOGE("get OHOS_SENSOR_ORIENTATION error.");
39094332d3Sopenharmony_ci        return OHOS::Camera::RC_ERROR;
40094332d3Sopenharmony_ci    }
41094332d3Sopenharmony_ci    sensorOrientation = *(entry.data.i32);
42094332d3Sopenharmony_ci    CAMERA_LOGD("get sensorOrientation = %{public}d", sensorOrientation);
43094332d3Sopenharmony_ci    return OHOS::Camera::RC_OK;
44094332d3Sopenharmony_ci}
45094332d3Sopenharmony_ci
46094332d3Sopenharmony_ciOHOS::Camera::RetCode CameraAbilityTest::GetFlashAvailable(std::shared_ptr<CameraAbility> &ability)
47094332d3Sopenharmony_ci{
48094332d3Sopenharmony_ci    common_metadata_header_t *data = cameraBase_->ability->get();
49094332d3Sopenharmony_ci    uint8_t flashAvailable;
50094332d3Sopenharmony_ci    camera_metadata_item_t entry;
51094332d3Sopenharmony_ci    int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_FLASH_AVAILABLE, &entry);
52094332d3Sopenharmony_ci    if (ret != 0) {
53094332d3Sopenharmony_ci        CAMERA_LOGE("get OHOS_ABILITY_FLASH_AVAILABLE error.");
54094332d3Sopenharmony_ci        return OHOS::Camera::RC_ERROR;
55094332d3Sopenharmony_ci    }
56094332d3Sopenharmony_ci    flashAvailable = *(entry.data.u8);
57094332d3Sopenharmony_ci    CAMERA_LOGD("get flashAvailable = %{public}d", static_cast<int>(flashAvailable));
58094332d3Sopenharmony_ci    return OHOS::Camera::RC_OK;
59094332d3Sopenharmony_ci}
60094332d3Sopenharmony_ci
61094332d3Sopenharmony_ciOHOS::Camera::RetCode CameraAbilityTest::GetAfAvailable(std::shared_ptr<CameraAbility> &ability)
62094332d3Sopenharmony_ci{
63094332d3Sopenharmony_ci    common_metadata_header_t *data = cameraBase_->ability->get();
64094332d3Sopenharmony_ci    std::vector<uint8_t> afAvailable;
65094332d3Sopenharmony_ci    camera_metadata_item_t entry;
66094332d3Sopenharmony_ci    int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_CONTROL_AF_AVAILABLE_MODES, &entry);
67094332d3Sopenharmony_ci    if (ret != 0) {
68094332d3Sopenharmony_ci        CAMERA_LOGE("get OHOS_CONTROL_AF_AVAILABLE_MODES error.");
69094332d3Sopenharmony_ci        return OHOS::Camera::RC_ERROR;
70094332d3Sopenharmony_ci    }
71094332d3Sopenharmony_ci    uint32_t count = entry.count;
72094332d3Sopenharmony_ci    CAMERA_LOGD("count = %{public}u", count);
73094332d3Sopenharmony_ci
74094332d3Sopenharmony_ci    for (int i = 0; i < count; i++) {
75094332d3Sopenharmony_ci        afAvailable.push_back(*(entry.data.u8 + i));
76094332d3Sopenharmony_ci    }
77094332d3Sopenharmony_ci
78094332d3Sopenharmony_ci    for (auto it = afAvailable.begin(); it != afAvailable.end(); it++) {
79094332d3Sopenharmony_ci        CAMERA_LOGI("afAvailable = %{public}d", static_cast<int>(*it));
80094332d3Sopenharmony_ci    }
81094332d3Sopenharmony_ci    return OHOS::Camera::RC_OK;
82094332d3Sopenharmony_ci}
83094332d3Sopenharmony_ci
84094332d3Sopenharmony_ciOHOS::Camera::RetCode CameraAbilityTest::GetZoomRatioRange(std::shared_ptr<CameraAbility> &ability)
85094332d3Sopenharmony_ci{
86094332d3Sopenharmony_ci    common_metadata_header_t *data = cameraBase_->ability->get();
87094332d3Sopenharmony_ci    std::vector<float> zoomRatioRange;
88094332d3Sopenharmony_ci    camera_metadata_item_t entry;
89094332d3Sopenharmony_ci    int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_ZOOM_RATIO_RANGE, &entry);
90094332d3Sopenharmony_ci    if (ret != 0) {
91094332d3Sopenharmony_ci        CAMERA_LOGE("get OHOS_ABILITY_ZOOM_RATIO_RANGE error.");
92094332d3Sopenharmony_ci        return OHOS::Camera::RC_ERROR;
93094332d3Sopenharmony_ci    }
94094332d3Sopenharmony_ci    uint32_t count = entry.count;
95094332d3Sopenharmony_ci    CAMERA_LOGD("count = %{public}u", count);
96094332d3Sopenharmony_ci
97094332d3Sopenharmony_ci    for (int i = 0; i < count; i++) {
98094332d3Sopenharmony_ci        zoomRatioRange.push_back(*(entry.data.f + i));
99094332d3Sopenharmony_ci    }
100094332d3Sopenharmony_ci
101094332d3Sopenharmony_ci    for (auto it = zoomRatioRange.begin(); it != zoomRatioRange.end(); it++) {
102094332d3Sopenharmony_ci        CAMERA_LOGI("zoomRatioRange = %{public}f", *it);
103094332d3Sopenharmony_ci    }
104094332d3Sopenharmony_ci    return OHOS::Camera::RC_OK;
105094332d3Sopenharmony_ci}
106094332d3Sopenharmony_ci
107094332d3Sopenharmony_ciOHOS::Camera::RetCode CameraAbilityTest::GetJpegOrientation(std::shared_ptr<CameraAbility> &ability)
108094332d3Sopenharmony_ci{
109094332d3Sopenharmony_ci    common_metadata_header_t *data = cameraBase_->ability->get();
110094332d3Sopenharmony_ci    int32_t jpegOrientation;
111094332d3Sopenharmony_ci    camera_metadata_item_t entry;
112094332d3Sopenharmony_ci    int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_JPEG_ORIENTATION, &entry);
113094332d3Sopenharmony_ci    if (ret != 0) {
114094332d3Sopenharmony_ci        CAMERA_LOGE("get OHOS_JPEG_ORIENTATION error.");
115094332d3Sopenharmony_ci        return OHOS::Camera::RC_ERROR;
116094332d3Sopenharmony_ci    }
117094332d3Sopenharmony_ci    jpegOrientation = *(entry.data.i32);
118094332d3Sopenharmony_ci    CAMERA_LOGD("get jpegOrientation = %{public}d", jpegOrientation);
119094332d3Sopenharmony_ci    return OHOS::Camera::RC_OK;
120094332d3Sopenharmony_ci}
121094332d3Sopenharmony_ci
122094332d3Sopenharmony_civoid CameraAbilityTest::TearDown(void)
123094332d3Sopenharmony_ci{
124094332d3Sopenharmony_ci    cameraBase_->Close();
125094332d3Sopenharmony_ci}
126094332d3Sopenharmony_ci
127094332d3Sopenharmony_ci/**
128094332d3Sopenharmony_ci * @tc.name: get camera ability
129094332d3Sopenharmony_ci * @tc.desc: get camera ability
130094332d3Sopenharmony_ci * @tc.level: Level1
131094332d3Sopenharmony_ci * @tc.size: MediumTest
132094332d3Sopenharmony_ci * @tc.type: Function
133094332d3Sopenharmony_ci */
134094332d3Sopenharmony_cistatic HWTEST_F(CameraAbilityTest, camera_ability_001, TestSize.Level1)
135094332d3Sopenharmony_ci{
136094332d3Sopenharmony_ci    EXPECT_EQ(true, cameraBase_->ability != nullptr);
137094332d3Sopenharmony_ci    if (cameraBase_->ability == nullptr) {
138094332d3Sopenharmony_ci        CAMERA_LOGE("ability is null.");
139094332d3Sopenharmony_ci        return;
140094332d3Sopenharmony_ci    }
141094332d3Sopenharmony_ci    GetSensorOrientation(cameraBase_->ability);
142094332d3Sopenharmony_ci    GetFlashAvailable(cameraBase_->ability);
143094332d3Sopenharmony_ci    GetAfAvailable(cameraBase_->ability);
144094332d3Sopenharmony_ci    GetZoomRatioRange(cameraBase_->ability);
145094332d3Sopenharmony_ci    GetJpegOrientation(cameraBase_->ability);
146094332d3Sopenharmony_ci}
147