• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.EvConnectorType;
25 import android.hardware.automotive.vehicle.FuelType;
26 import android.hardware.automotive.vehicle.VehicleProperty;
27 
28 import androidx.test.ext.junit.runners.AndroidJUnit4;
29 import androidx.test.filters.MediumTest;
30 
31 import com.android.car.hal.test.AidlVehiclePropValueBuilder;
32 
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.rules.TestName;
36 import org.junit.runner.RunWith;
37 
38 import java.util.Arrays;
39 import java.util.List;
40 
41 @RunWith(AndroidJUnit4.class)
42 @MediumTest
43 public class CarInfoManagerTest extends MockedCarTestBase {
44     private static final String MAKE_NAME = "ANDROID";
45     private static final String MODEL_NAME = "TEST";
46     private static final String DEFAULT_STRING_VALUE = "";
47     private static final int DEFAULT_INTEGER_VALUE = 0;
48     private static final float DEFAULT_FLOAT_VALUE = 0f;
49     private static final int MODEL_YEAR = 2020;
50     private static final String MODEL_YEAR_STRING = "2020";
51     private static final float FAKE_CAPACITY = 2.0f;
52     private static final List<Integer> FUEL_TYPES =
53             Arrays.asList(FuelType.FUEL_TYPE_CNG, FuelType.FUEL_TYPE_BIODIESEL);
54     private static final List<Integer> EV_CONNECTOR_TYPES =
55             Arrays.asList(android.car.EvConnectorType.GBT, android.car.EvConnectorType.GBT_DC);
56     private CarInfoManager mCarInfoManager;
57     @Rule
58     public TestName mTestName = new TestName();
59 
60     @Override
configureMockedHal()61     protected void configureMockedHal() {
62         // test if the sensor is unimplemented in cars.
63         if (mTestName.getMethodName().endsWith("unimplemented")) {
64             return;
65         }
66         addAidlStaticProperty(VehicleProperty.INFO_MAKE,
67                 AidlVehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_MAKE)
68                         .setStringValue(MAKE_NAME)
69                         .build());
70         addAidlStaticProperty(VehicleProperty.INFO_MODEL_YEAR,
71                 AidlVehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_MODEL_YEAR)
72                         .addIntValues(MODEL_YEAR).build());
73         addAidlStaticProperty(VehicleProperty.INFO_FUEL_CAPACITY,
74                 AidlVehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_FUEL_CAPACITY)
75                         .addFloatValues(FAKE_CAPACITY).build());
76         addAidlStaticProperty(VehicleProperty.INFO_EV_BATTERY_CAPACITY,
77                 AidlVehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_EV_BATTERY_CAPACITY)
78                         .addFloatValues(FAKE_CAPACITY).build());
79         addAidlStaticProperty(VehicleProperty.INFO_MODEL,
80                 AidlVehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_MODEL)
81                         .setStringValue(MODEL_NAME).build());
82         addAidlStaticProperty(VehicleProperty.INFO_FUEL_TYPE,
83                 AidlVehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_FUEL_TYPE)
84                         .addIntValues(FuelType.FUEL_TYPE_CNG)
85                         .addIntValues(FuelType.FUEL_TYPE_BIODIESEL)
86                         .build());
87         addAidlStaticProperty(VehicleProperty.INFO_EV_CONNECTOR_TYPE,
88                 AidlVehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_EV_CONNECTOR_TYPE)
89                         .addIntValues(EvConnectorType.GBT_AC)
90                         .addIntValues(EvConnectorType.GBT_DC)
91                         .build());
92         addAidlStaticProperty(VehicleProperty.INFO_EV_PORT_LOCATION,
93                 AidlVehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_EV_PORT_LOCATION)
94                         .addIntValues(PortLocationType.FRONT).build());
95         addAidlStaticProperty(VehicleProperty.INFO_FUEL_DOOR_LOCATION,
96                 AidlVehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_FUEL_DOOR_LOCATION)
97                         .addIntValues(PortLocationType.FRONT_LEFT).build());
98         addAidlStaticProperty(VehicleProperty.INFO_DRIVER_SEAT,
99                 AidlVehiclePropValueBuilder.newBuilder(VehicleProperty.INFO_FUEL_DOOR_LOCATION)
100                         .addIntValues(VehicleAreaSeat.SEAT_ROW_1_LEFT).build());
101     }
102 
103     @Override
setUp()104     public void setUp() throws Exception {
105         super.setUp();
106         mCarInfoManager = (CarInfoManager) getCar().getCarManager(Car.INFO_SERVICE);
107     }
108 
109     @Test
testVehicleId()110     public void testVehicleId() throws Exception {
111         assertThat(mCarInfoManager.getVehicleId()).isNotNull();
112     }
113 
114     @Test
testVehicleId_unimplemented()115     public void testVehicleId_unimplemented() throws Exception {
116         assertThat(mCarInfoManager.getVehicleId()).isEqualTo(DEFAULT_STRING_VALUE);
117     }
118 
119     @Test
testManufacturer()120     public void testManufacturer() throws Exception {
121         assertThat(mCarInfoManager.getManufacturer()).isEqualTo(MAKE_NAME);
122     }
123 
124     @Test
testManufacturer_unimplemented()125     public void testManufacturer_unimplemented() throws Exception {
126         assertThat(mCarInfoManager.getManufacturer()).isEqualTo(DEFAULT_STRING_VALUE);
127     }
128 
129     @Test
testGetModel()130     public void testGetModel() throws Exception {
131         assertThat(mCarInfoManager.getModel()).isEqualTo(MODEL_NAME);
132     }
133 
134     @Test
testGetModel_unimplemented()135     public void testGetModel_unimplemented() throws Exception {
136         assertThat(mCarInfoManager.getModel()).isEqualTo(DEFAULT_STRING_VALUE);
137     }
138 
139     @Test
testGetFuelType()140     public void testGetFuelType() throws Exception {
141         assertThat(mCarInfoManager.getFuelTypes()).asList()
142                 .containsAtLeastElementsIn(FUEL_TYPES).inOrder();
143     }
144 
145     @Test
testGetFuelType_unimplemented()146     public void testGetFuelType_unimplemented() throws Exception {
147         assertThat(mCarInfoManager.getFuelTypes()).isEmpty();
148     }
149 
150     @Test
testGetEvConnectorTypes()151     public void testGetEvConnectorTypes() throws Exception {
152         assertThat(mCarInfoManager.getEvConnectorTypes()).asList()
153                 .containsAtLeastElementsIn(EV_CONNECTOR_TYPES).inOrder();
154     }
155 
156     @Test
testGetEvConnectorTypes_unimplemented()157     public void testGetEvConnectorTypes_unimplemented() throws Exception {
158         assertThat(mCarInfoManager.getEvConnectorTypes()).isEmpty();
159     }
160 
161     @Test
testGetModelYear()162     public void testGetModelYear() throws Exception {
163         assertThat(mCarInfoManager.getModelYear()).isEqualTo(MODEL_YEAR_STRING);
164         assertThat(mCarInfoManager.getModelYearInInteger()).isEqualTo(MODEL_YEAR);
165     }
166 
167     @Test
testGetModelYear_unimplemented()168     public void testGetModelYear_unimplemented() throws Exception {
169         assertThat(mCarInfoManager.getModelYear()).isEqualTo(DEFAULT_STRING_VALUE);
170         assertThat(mCarInfoManager.getModelYearInInteger()).isEqualTo(DEFAULT_INTEGER_VALUE);
171     }
172 
173     @Test
testGetPortDoorLocation()174     public void testGetPortDoorLocation() throws Exception {
175         assertThat(mCarInfoManager.getEvPortLocation()).isEqualTo(PortLocationType.FRONT);
176         assertThat(mCarInfoManager.getFuelDoorLocation()).isEqualTo(PortLocationType.FRONT_LEFT);
177     }
178 
179     @Test
testGetPortDoorLocation_unimplemented()180     public void testGetPortDoorLocation_unimplemented() throws Exception {
181         assertThat(mCarInfoManager.getEvPortLocation()).isEqualTo(PortLocationType.UNKNOWN);
182         assertThat(mCarInfoManager.getFuelDoorLocation()).isEqualTo(PortLocationType.UNKNOWN);
183     }
184 
185     @Test
testGetCapacity()186     public void testGetCapacity() throws Exception {
187         assertThat(mCarInfoManager.getEvBatteryCapacity()).isEqualTo(FAKE_CAPACITY);
188         assertThat(mCarInfoManager.getFuelCapacity()).isEqualTo(FAKE_CAPACITY);
189     }
190 
191     @Test
testGetCapacity_unimplemented()192     public void testGetCapacity_unimplemented() throws Exception {
193         assertThat(mCarInfoManager.getEvBatteryCapacity()).isEqualTo(DEFAULT_FLOAT_VALUE);
194         assertThat(mCarInfoManager.getFuelCapacity()).isEqualTo(DEFAULT_FLOAT_VALUE);
195     }
196 
197     @Test
testGetDriverSeat()198     public void testGetDriverSeat() throws Exception {
199         assertThat(mCarInfoManager.getDriverSeat()).isEqualTo(VehicleAreaSeat.SEAT_ROW_1_LEFT);
200     }
201 
202     @Test
testGetDriverSeat_unimplemented()203     public void testGetDriverSeat_unimplemented() throws Exception {
204         assertThat(mCarInfoManager.getDriverSeat()).isEqualTo(VehicleAreaSeat.SEAT_UNKNOWN);
205     }
206 }
207