Home | History | Annotate | Download | only in metadata
      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 "default_option_delegate.h"
     18 
     19 #include <memory>
     20 
     21 #include <gtest/gtest.h>
     22 #include <hardware/camera3.h>
     23 
     24 using testing::Test;
     25 
     26 namespace v4l2_camera_hal {
     27 
     28 class DefaultOptionDelegateTest : public Test {
     29  protected:
     30   virtual void SetUp() {
     31     dut_.reset(new DefaultOptionDelegate<int>(defaults_));
     32   }
     33 
     34   std::unique_ptr<DefaultOptionDelegate<int>> dut_;
     35   std::map<int, int> defaults_{{CAMERA3_TEMPLATE_STILL_CAPTURE, 10},
     36                                {OTHER_TEMPLATES, 20},
     37                                {CAMERA3_TEMPLATE_VIDEO_SNAPSHOT, 30}};
     38 };
     39 
     40 TEST_F(DefaultOptionDelegateTest, SpecificDefault) {
     41   int actual = 0;
     42   EXPECT_TRUE(
     43       dut_->DefaultValueForTemplate(CAMERA3_TEMPLATE_STILL_CAPTURE, &actual));
     44   EXPECT_EQ(actual, defaults_[CAMERA3_TEMPLATE_STILL_CAPTURE]);
     45 }
     46 
     47 TEST_F(DefaultOptionDelegateTest, GeneralDefault) {
     48   int actual = 0;
     49   // No ZSL default; should fall back to the OTHER_TEMPLATES default.
     50   EXPECT_TRUE(dut_->DefaultValueForTemplate(CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG,
     51                                             &actual));
     52   EXPECT_EQ(actual, defaults_[OTHER_TEMPLATES]);
     53 }
     54 
     55 TEST_F(DefaultOptionDelegateTest, NoDefaults) {
     56   dut_.reset(new DefaultOptionDelegate<int>({}));
     57   int actual = 0;
     58   EXPECT_FALSE(dut_->DefaultValueForTemplate(CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG,
     59                                              &actual));
     60 }
     61 
     62 }  // namespace v4l2_camera_hal
     63