• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 #include "property.h"
18 
19 #include <array>
20 #include <vector>
21 
22 #include <camera/CameraMetadata.h>
23 #include <gmock/gmock.h>
24 #include <gtest/gtest.h>
25 #include <hardware/camera3.h>
26 
27 #include "array_vector.h"
28 #include "metadata_common.h"
29 #include "test_common.h"
30 
31 using testing::AtMost;
32 using testing::Return;
33 using testing::ReturnRef;
34 using testing::Test;
35 using testing::_;
36 
37 namespace v4l2_camera_hal {
38 
39 class PropertyTest : public Test {
40  protected:
41   // Need tags that match the data types being passed.
42   static constexpr int32_t byte_tag_ = ANDROID_CONTROL_SCENE_MODE_OVERRIDES;
43   static constexpr int32_t float_tag_ = ANDROID_COLOR_CORRECTION_GAINS;
44   static constexpr int32_t int_tag_ = ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION;
45   static constexpr int32_t int_tag2_ = ANDROID_JPEG_ORIENTATION;
46 };
47 
TEST_F(PropertyTest,Tags)48 TEST_F(PropertyTest, Tags) {
49   Property<int32_t> property(int_tag_, 1);
50 
51   // Should have only the single tag it was constructed with.
52   EXPECT_EQ(property.ControlTags().size(), 0u);
53   EXPECT_EQ(property.DynamicTags().size(), 0u);
54   ASSERT_EQ(property.StaticTags().size(), 1u);
55   // The macro doesn't like the int_tag_ variable being passed in directly.
56   int32_t expected_tag = int_tag_;
57   EXPECT_EQ(property.StaticTags()[0], expected_tag);
58 }
59 
TEST_F(PropertyTest,PopulateStaticSingleNumber)60 TEST_F(PropertyTest, PopulateStaticSingleNumber) {
61   // Set up a fixed property.
62   int32_t data = 1234;
63   Property<int32_t> property(int_tag_, data);
64 
65   // Populate static fields.
66   android::CameraMetadata metadata;
67   ASSERT_EQ(property.PopulateStaticFields(&metadata), 0);
68 
69   // Check the results.
70   // Should only have added 1 entry.
71   EXPECT_EQ(metadata.entryCount(), 1u);
72   // Should have added the right entry.
73   ExpectMetadataEq(metadata, int_tag_, data);
74 }
75 
76 // TODO(b/30839858): These tests are really testing the metadata_common.h
77 // UpdateMetadata methods, and shouldn't be conducted here.
TEST_F(PropertyTest,PopulateStaticVector)78 TEST_F(PropertyTest, PopulateStaticVector) {
79   // Set up a fixed property.
80   std::vector<float> data({0.1, 2.3, 4.5, 6.7});
81   Property<std::vector<float>> property(float_tag_, data);
82 
83   // Populate static fields.
84   android::CameraMetadata metadata;
85   ASSERT_EQ(property.PopulateStaticFields(&metadata), 0);
86 
87   // Check the results.
88   // Should only have added 1 entry.
89   EXPECT_EQ(metadata.entryCount(), 1u);
90   // Should have added the right entry.
91   ExpectMetadataEq(metadata, float_tag_, data);
92 }
93 
TEST_F(PropertyTest,PopulateStaticArray)94 TEST_F(PropertyTest, PopulateStaticArray) {
95   // Set up a fixed property.
96   std::array<float, 4> data({{0.1, 2.3, 4.5, 6.7}});
97   Property<std::array<float, 4>> property(float_tag_, data);
98 
99   // Populate static fields.
100   android::CameraMetadata metadata;
101   ASSERT_EQ(property.PopulateStaticFields(&metadata), 0);
102 
103   // Check the results.
104   // Should only have added 1 entry.
105   EXPECT_EQ(metadata.entryCount(), 1u);
106   // Should have added the right entry.
107   ExpectMetadataEq(metadata, float_tag_, data);
108 }
109 
TEST_F(PropertyTest,PopulateStaticArrayVector)110 TEST_F(PropertyTest, PopulateStaticArrayVector) {
111   // Set up a fixed property.
112   ArrayVector<uint8_t, 3> data;
113   data.push_back({{1, 2, 3}});
114   data.push_back({{4, 5, 6}});
115   Property<ArrayVector<uint8_t, 3>> property(byte_tag_, data);
116 
117   // Populate static fields.
118   android::CameraMetadata metadata;
119   ASSERT_EQ(property.PopulateStaticFields(&metadata), 0);
120 
121   // Check the results.
122   // Should only have added 1 entry.
123   EXPECT_EQ(metadata.entryCount(), 1u);
124   // Should have added the right entry.
125   ExpectMetadataEq(metadata, byte_tag_, data);
126 }
127 
TEST_F(PropertyTest,PopulateDynamic)128 TEST_F(PropertyTest, PopulateDynamic) {
129   Property<int32_t> property(int_tag_, 1);
130 
131   android::CameraMetadata metadata;
132   EXPECT_EQ(property.PopulateDynamicFields(&metadata), 0);
133 
134   // Shouldn't have added anything.
135   EXPECT_TRUE(metadata.isEmpty());
136 }
137 
TEST_F(PropertyTest,PopulateTemplate)138 TEST_F(PropertyTest, PopulateTemplate) {
139   Property<int32_t> property(int_tag_, 1);
140 
141   for (int i = 1; i < CAMERA3_TEMPLATE_COUNT; ++i) {
142     android::CameraMetadata metadata;
143     EXPECT_EQ(property.PopulateTemplateRequest(i, &metadata), 0);
144     // Shouldn't have added anything.
145     EXPECT_TRUE(metadata.isEmpty());
146   }
147 }
148 
TEST_F(PropertyTest,SupportsRequest)149 TEST_F(PropertyTest, SupportsRequest) {
150   Property<int32_t> property(int_tag_, 1);
151   android::CameraMetadata metadata;
152   EXPECT_EQ(property.SupportsRequestValues(metadata), true);
153 }
154 
TEST_F(PropertyTest,SetRequest)155 TEST_F(PropertyTest, SetRequest) {
156   Property<int32_t> property(int_tag_, 1);
157   android::CameraMetadata metadata;
158   EXPECT_EQ(property.SetRequestValues(metadata), 0);
159 }
160 
161 }  // namespace v4l2_camera_hal
162