1 /*
2  * Copyright (C) 2015 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 package com.android.car;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 
20 import android.car.Car;
21 import android.car.CarInfoManager;
22 import android.car.PortLocationType;
23 import android.car.VehicleAreaSeat;
24 import android.hardware.automotive.vehicle.V2_0.EvConnectorType;
25 import android.hardware.automotive.vehicle.V2_0.FuelType;
26 import android.hardware.automotive.vehicle.V2_0.VehicleProperty;
27 
28 import androidx.test.ext.junit.runners.AndroidJUnit4;
29 import androidx.test.filters.MediumTest;
30 
31 import com.android.car.vehiclehal.VehiclePropValueBuilder;
32 
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 
36 import java.util.Arrays;
37 import java.util.List;
38 
39 @RunWith(AndroidJUnit4.class)
40 @MediumTest
41 public class CarInfoManagerTest extends MockedCarTestBase {
42     private static final String MAKE_NAME = "ANDROID";
43     private static final String MODEL_NAME = "TEST";
44     private static final int MODEL_YEAR = 2020;
45     private static final String MODEL_YEAR_STRING = "2020";
46     private static final float FAKE_CAPACITY = 2.0f;
47     private static final List<Integer> FUEL_TYPES =
48             Arrays.asList(FuelType.FUEL_TYPE_CNG, FuelType.FUEL_TYPE_BIODIESEL);
49     private static final List<Integer> EV_CONNECTOR_TYPES =
50             Arrays.asList(android.car.EvConnectorType.GBT, android.car.EvConnectorType.GBT_DC);
51     private CarInfoManager mCarInfoManager;
52 
53     @Override
configureMockedHal()54     protected synchronized void configureMockedHal() {
55         addStaticProperty(VehicleProperty.INFO_MAKE,
56                 VehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_MAKE)
57                         .setStringValue(MAKE_NAME)
58                         .build());
59         addStaticProperty(VehicleProperty.INFO_MODEL_YEAR,
60                 VehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_MODEL_YEAR)
61                         .addIntValue(MODEL_YEAR).build());
62         addStaticProperty(VehicleProperty.INFO_FUEL_CAPACITY,
63                 VehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_FUEL_CAPACITY)
64                         .addFloatValue(FAKE_CAPACITY).build());
65         addStaticProperty(VehicleProperty.INFO_EV_BATTERY_CAPACITY,
66                 VehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_EV_BATTERY_CAPACITY)
67                         .addFloatValue(FAKE_CAPACITY).build());
68         addStaticProperty(VehicleProperty.INFO_MODEL,
69                 VehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_MODEL)
70                         .setStringValue(MODEL_NAME).build());
71         addStaticProperty(VehicleProperty.INFO_FUEL_TYPE,
72                 VehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_FUEL_TYPE)
73                         .addIntValue(FuelType.FUEL_TYPE_CNG)
74                         .addIntValue(FuelType.FUEL_TYPE_BIODIESEL)
75                         .build());
76         addStaticProperty(VehicleProperty.INFO_EV_CONNECTOR_TYPE,
77                 VehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_EV_CONNECTOR_TYPE)
78                         .addIntValue(EvConnectorType.GBT_AC)
79                         .addIntValue(EvConnectorType.GBT_DC)
80                         .build());
81         addStaticProperty(VehicleProperty.INFO_EV_PORT_LOCATION,
82                 VehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_EV_PORT_LOCATION)
83                         .addIntValue(PortLocationType.FRONT).build());
84         addStaticProperty(VehicleProperty.INFO_FUEL_DOOR_LOCATION,
85                 VehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_FUEL_DOOR_LOCATION)
86                         .addIntValue(PortLocationType.FRONT_LEFT).build());
87         addStaticProperty(VehicleProperty.INFO_DRIVER_SEAT,
88                 VehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_FUEL_DOOR_LOCATION)
89                         .addIntValue(VehicleAreaSeat.SEAT_ROW_1_LEFT).build());
90     }
91 
92     @Override
setUp()93     public void setUp() throws Exception {
94         super.setUp();
95         mCarInfoManager = (CarInfoManager) getCar().getCarManager(Car.INFO_SERVICE);
96     }
97 
98     @Test
testVehicleId()99     public void testVehicleId() throws Exception {
100         assertThat(mCarInfoManager.getVehicleId()).isNotNull();
101     }
102 
103     @Test
testManufacturer()104     public void testManufacturer() throws Exception {
105         assertThat(mCarInfoManager.getManufacturer()).isEqualTo(MAKE_NAME);
106     }
107 
108     @Test
testGetModel()109     public void testGetModel() throws Exception {
110         assertThat(mCarInfoManager.getModel()).isEqualTo(MODEL_NAME);
111     }
112 
113     @Test
testGetFuelType()114     public void testGetFuelType() throws Exception {
115         assertThat(mCarInfoManager.getFuelTypes()).asList().containsAllIn(FUEL_TYPES).inOrder();
116     }
117 
118     @Test
testGetEvConnectorTypes()119     public void testGetEvConnectorTypes() throws Exception {
120         assertThat(mCarInfoManager.getEvConnectorTypes()).asList().containsAllIn(EV_CONNECTOR_TYPES)
121                 .inOrder();
122     }
123 
124     @Test
testGetModelYear()125     public void testGetModelYear() throws Exception {
126         assertThat(mCarInfoManager.getModelYear()).isEqualTo(MODEL_YEAR_STRING);
127         assertThat(mCarInfoManager.getModelYearInInteger()).isEqualTo(MODEL_YEAR);
128     }
129 
130     @Test
testGetPortDoorLocation()131     public void testGetPortDoorLocation() throws Exception {
132         assertThat(mCarInfoManager.getEvPortLocation()).isEqualTo(PortLocationType.FRONT);
133         assertThat(mCarInfoManager.getFuelDoorLocation()).isEqualTo(PortLocationType.FRONT_LEFT);
134     }
135 
136     @Test
testGetCapacity()137     public void testGetCapacity() throws Exception {
138         assertThat(mCarInfoManager.getEvBatteryCapacity()).isEqualTo(FAKE_CAPACITY);
139         assertThat(mCarInfoManager.getFuelCapacity()).isEqualTo(FAKE_CAPACITY);
140     }
141 
142     @Test
testGetDriverSeat()143     public void testGetDriverSeat() throws Exception {
144         assertThat(mCarInfoManager.getDriverSeat()).isEqualTo(VehicleAreaSeat.SEAT_ROW_1_LEFT);
145     }
146 }
147