Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 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 <gtest/gtest.h> |
| 18 | |
| 19 | #include <vehicle_hal_manager/VehiclePropConfigIndex.h> |
| 20 | |
| 21 | #include "VehicleHalTestUtils.h" |
| 22 | |
| 23 | namespace android { |
| 24 | namespace hardware { |
| 25 | namespace vehicle { |
| 26 | namespace V2_0 { |
| 27 | |
| 28 | namespace { |
| 29 | |
| 30 | class PropConfigTest : public ::testing::Test { |
| 31 | protected: |
| 32 | void SetUp() override { |
| 33 | configs.assign(std::begin(kVehicleProperties), |
| 34 | std::end(kVehicleProperties)); |
| 35 | } |
| 36 | |
| 37 | void TearDown() override {} |
| 38 | |
| 39 | public: |
| 40 | std::vector<VehiclePropConfig> configs; |
| 41 | }; |
| 42 | |
| 43 | TEST_F(PropConfigTest, hasConfig) { |
| 44 | VehiclePropConfigIndex index(configs); |
| 45 | |
| 46 | ASSERT_TRUE(index.hasConfig(VehicleProperty::HVAC_FAN_SPEED)); |
| 47 | ASSERT_TRUE(index.hasConfig(VehicleProperty::INFO_MAKE)); |
| 48 | ASSERT_TRUE(index.hasConfig(VehicleProperty::INFO_FUEL_CAPACITY)); |
| 49 | |
| 50 | ASSERT_FALSE(index.hasConfig(VehicleProperty::INVALID)); |
| 51 | } |
| 52 | |
| 53 | TEST_F(PropConfigTest, getAllConfig) { |
| 54 | VehiclePropConfigIndex index(configs); |
| 55 | |
| 56 | std::vector<VehiclePropConfig> actualConfigs = index.getAllConfigs(); |
| 57 | ASSERT_EQ(configs.size(), actualConfigs.size()); |
| 58 | |
| 59 | for (size_t i = 0; i < actualConfigs.size(); i++) { |
| 60 | ASSERT_EQ(toString(configs[i]), toString(actualConfigs[i])); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | TEST_F(PropConfigTest, getConfigs) { |
| 65 | VehiclePropConfigIndex index(configs); |
| 66 | auto actualConfig = index.getConfig(VehicleProperty::HVAC_FAN_SPEED); |
| 67 | ASSERT_EQ(toString(configs[1]), toString(actualConfig)); |
| 68 | } |
| 69 | |
| 70 | } // namespace anonymous |
| 71 | |
| 72 | } // namespace V2_0 |
| 73 | } // namespace vehicle |
| 74 | } // namespace hardware |
| 75 | } // namespace android |