• 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 package android.car.apitest;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 import static com.google.common.truth.Truth.assertWithMessage;
20 
21 import android.car.Car;
22 import android.car.hardware.CarPropertyConfig;
23 import android.car.hardware.hvac.CarHvacManager;
24 import android.car.test.ApiCheckerRule.Builder;
25 import android.hardware.automotive.vehicle.VehicleHvacFanDirection;
26 import android.test.suitebuilder.annotation.MediumTest;
27 import android.util.Log;
28 
29 import org.junit.Before;
30 import org.junit.Test;
31 
32 import java.util.Arrays;
33 import java.util.HashSet;
34 import java.util.List;
35 import java.util.Set;
36 
37 @MediumTest
38 public final class CarHvacManagerTest extends CarApiTestBase {
39     private static final String TAG = CarHvacManagerTest.class.getSimpleName();
40 
41     private CarHvacManager mHvacManager;
42 
43     // TODO(b/242350638): add missing annotations, remove (on child bug of 242350638)
44     @Override
configApiCheckerRule(Builder builder)45     protected void configApiCheckerRule(Builder builder) {
46         Log.w(TAG, "Disabling API requirements check");
47         builder.disableAnnotationsCheck();
48     }
49 
50     @Before
setUp()51     public void setUp() throws Exception {
52         mHvacManager = (CarHvacManager) getCar().getCarManager(Car.HVAC_SERVICE);
53         assertThat(mHvacManager).isNotNull();
54     }
55 
56     @Test
testAllHvacProperties()57     public void testAllHvacProperties() throws Exception {
58         List<CarPropertyConfig> properties = mHvacManager.getPropertyList();
59         Set<Class> supportedTypes = new HashSet<>(Arrays.asList(
60                 new Class[] { Integer.class, Float.class, Boolean.class, Integer[].class }));
61 
62         for (CarPropertyConfig property : properties) {
63             if (supportedTypes.contains(property.getPropertyType())) {
64                 assertTypeAndZone(property);
65             } else {
66                 fail("Type is not supported for " + property);
67             }
68         }
69     }
70 
71     @Test
testHvacPosition()72     public void testHvacPosition() {
73         assertThat(VehicleHvacFanDirection.FACE).isEqualTo(CarHvacManager.FAN_DIRECTION_FACE);
74         assertThat(VehicleHvacFanDirection.FLOOR).isEqualTo(CarHvacManager.FAN_DIRECTION_FLOOR);
75         assertThat(VehicleHvacFanDirection.DEFROST).isEqualTo(CarHvacManager.FAN_DIRECTION_DEFROST);
76     }
77 
assertTypeAndZone(CarPropertyConfig property)78     private void assertTypeAndZone(CarPropertyConfig property) {
79         switch (property.getPropertyId()) {
80             case CarHvacManager.ID_MIRROR_DEFROSTER_ON: // non-zoned bool
81                 checkTypeAndGlobal(Integer.class, false, property);
82                 break;
83             case CarHvacManager.ID_STEERING_WHEEL_HEAT: // non-zoned int
84             case CarHvacManager.ID_TEMPERATURE_DISPLAY_UNITS:
85                 checkTypeAndGlobal(Integer.class, true, property);
86                 checkIntMinMax(property);
87                 break;
88             case CarHvacManager.ID_OUTSIDE_AIR_TEMP:
89                 checkTypeAndGlobal(Float.class, true, property);
90                 break;
91             case CarHvacManager.ID_ZONED_TEMP_SETPOINT: // zoned float
92             case CarHvacManager.ID_ZONED_TEMP_ACTUAL:
93                 checkTypeAndGlobal(Float.class, false, property);
94                 checkFloatMinMax(property);
95                 break;
96             case CarHvacManager.ID_ZONED_FAN_SPEED_SETPOINT: // zoned int
97             case CarHvacManager.ID_ZONED_FAN_SPEED_RPM:
98             case CarHvacManager.ID_ZONED_SEAT_TEMP:
99                 checkTypeAndGlobal(Integer.class, false, property);
100                 checkIntMinMax(property);
101                 break;
102             case CarHvacManager.ID_ZONED_FAN_DIRECTION:
103                 checkTypeAndGlobal(Integer.class, false, property);
104                 break;
105             case CarHvacManager.ID_ZONED_FAN_DIRECTION_AVAILABLE:
106                 checkTypeAndGlobal(Integer[].class, false, property);
107                 break;
108             case CarHvacManager.ID_ZONED_AC_ON: // zoned boolean
109             case CarHvacManager.ID_ZONED_AUTOMATIC_MODE_ON:
110             case CarHvacManager.ID_ZONED_AIR_RECIRCULATION_ON:
111             case CarHvacManager.ID_ZONED_MAX_AC_ON:
112             case CarHvacManager.ID_ZONED_DUAL_ZONE_ON:
113             case CarHvacManager.ID_ZONED_MAX_DEFROST_ON:
114             case CarHvacManager.ID_ZONED_HVAC_POWER_ON:
115             case CarHvacManager.ID_WINDOW_DEFROSTER_ON:
116                 checkTypeAndGlobal(Boolean.class, false, property);
117                 break;
118             default:
119                 break;
120         }
121     }
122 
checkTypeAndGlobal(Class<?> clazz, boolean global, CarPropertyConfig<Integer> property)123     private void checkTypeAndGlobal(Class<?> clazz, boolean global,
124             CarPropertyConfig<Integer> property) {
125         assertWithMessage("Wrong type, expecting %s type for id %s", clazz,
126                 property.getPropertyId()).that(property.getPropertyType()).isEqualTo(clazz);
127         assertWithMessage(
128                 "Wrong zone, should %s be global for id:%s, area type: %s" + property.getAreaType(),
129                 property.getPropertyId(), property.getAreaType(), (global ? "" : "not "))
130                         .that(property.isGlobalProperty()).isEqualTo(global);
131     }
132 
checkIntMinMax(CarPropertyConfig<Integer> property)133     private void checkIntMinMax(CarPropertyConfig<Integer> property) {
134         Log.i(TAG, "checkIntMinMax property:" + property);
135         if (!property.isGlobalProperty()) {
136             int[] areaIds = property.getAreaIds();
137             assertThat(areaIds.length).isGreaterThan(0);
138             assertThat(property.getAreaCount()).isEqualTo(areaIds.length);
139 
140             for (int areaId : areaIds) {
141                 assertThat(property.hasArea(areaId)).isTrue();
142                 int min = property.getMinValue(areaId) == null ? 0 : property.getMinValue(areaId);
143                 int max = property.getMaxValue(areaId) == null ? 0 : property.getMaxValue(areaId);
144                 assertThat(min).isAtMost(max);
145             }
146         } else {
147             int min = property.getMinValue() == null ? 0 : property.getMinValue();
148             int max = property.getMaxValue() == null ? 0 : property.getMinValue();
149             assertThat(min).isAtMost(max);
150             for (int i = 0; i < 32; i++) {
151                 assertThat(property.hasArea(0x1 << i)).isFalse();
152                 assertThat(property.getMinValue(0x1 << i)).isNull();
153                 assertThat(property.getMaxValue(0x1 << i)).isNull();
154             }
155         }
156     }
157 
checkFloatMinMax(CarPropertyConfig<Float> property)158     private void checkFloatMinMax(CarPropertyConfig<Float> property) {
159         Log.i(TAG, "checkFloatMinMax property:" + property);
160         if (!property.isGlobalProperty()) {
161             int[] areaIds = property.getAreaIds();
162             assertThat(areaIds.length).isGreaterThan(0);
163             assertThat(property.getAreaCount()).isEqualTo(areaIds.length);
164 
165             for (int areaId : areaIds) {
166                 assertThat(property.hasArea(areaId)).isTrue();
167                 float min =
168                         property.getMinValue(areaId) == null ? 0f : property.getMinValue(areaId);
169                 float max =
170                         property.getMaxValue(areaId) == null ? 0f : property.getMinValue(areaId);
171                 assertThat(min).isAtMost(max);
172             }
173         } else {
174             float min = property.getMinValue() == null ? 0f : property.getMinValue();
175             float max = property.getMaxValue() == null ? 0f : property.getMinValue();
176             assertThat(min).isAtMost(max);
177             for (int i = 0; i < 32; i++) {
178                 assertThat(property.hasArea(0x1 << i)).isFalse();
179                 assertThat(property.getMinValue(0x1 << i)).isNull();
180                 assertThat(property.getMaxValue(0x1 << i)).isNull();
181             }
182         }
183     }
184 }
185