1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 //#define LOG_NDEBUG 0
18 #define LOG_TAG "ExifUtilsTest"
19
20 #include <camera/CameraMetadata.h>
21 #include "../utils/ExifUtils.h"
22 #include <gtest/gtest.h>
23
24 using android::camera3::ExifUtils;
25 using android::camera3::ExifOrientation;
26 using android::CameraMetadata;
27
28 uint32_t kImageWidth = 1920;
29 uint32_t kImageHeight = 1440;
30 ExifOrientation kExifOrientation = ExifOrientation::ORIENTATION_0_DEGREES;
31
32 // Test that setFromMetadata works correctly, without errors.
TEST(ExifUtilsTest,SetFromMetadataTest)33 TEST(ExifUtilsTest, SetFromMetadataTest) {
34 std::unique_ptr<ExifUtils> utils(ExifUtils::create());
35 uint8_t invalidSensorPixelMode = 2;
36 uint8_t validSensorPixelMode = ANDROID_SENSOR_PIXEL_MODE_DEFAULT;
37 CameraMetadata metadata;
38 // Empty staticInfo
39 CameraMetadata staticInfo;
40 ASSERT_TRUE(utils->initializeEmpty());
41 ASSERT_TRUE(
42 metadata.update(ANDROID_SENSOR_PIXEL_MODE, &invalidSensorPixelMode, 1) == android::OK);
43 ASSERT_FALSE(utils->setFromMetadata(metadata, staticInfo, kImageWidth, kImageHeight));
44 ASSERT_TRUE(
45 metadata.update(ANDROID_SENSOR_PIXEL_MODE, &validSensorPixelMode, 1) == android::OK);
46 ASSERT_TRUE(utils->setFromMetadata(metadata, staticInfo, kImageWidth, kImageHeight));
47 ASSERT_TRUE(utils->setImageWidth(kImageWidth));
48 ASSERT_TRUE(utils->setImageHeight(kImageHeight));
49 ASSERT_TRUE(utils->setOrientationValue(kExifOrientation));
50 ASSERT_TRUE(utils->generateApp1());
51 const uint8_t* exifBuffer = utils->getApp1Buffer();
52 ASSERT_NE(exifBuffer, nullptr);
53 size_t exifBufferSize = utils->getApp1Length();
54 ASSERT_TRUE(exifBufferSize != 0);
55 }
56