1 /* 2 * Copyright (C) 2020 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.power; 17 18 import static com.google.common.truth.Truth.assertThat; 19 20 import android.util.SparseArray; 21 22 import org.junit.Test; 23 24 import java.lang.reflect.Field; 25 26 public final class PowerComponentValidityTest { 27 /** 28 * Tests if {@link android.car.hardware.power#PowerComponent} and 29 * {@link android.frameworks.automotive.powerpolicy#PowerComponent} have the same power 30 * component definition. 31 */ 32 @Test testSamePowerComponent()33 public void testSamePowerComponent() throws Exception { 34 SparseArray<String> fieldMap = new SparseArray<>(); 35 Field[] carFields = android.car.hardware.power.PowerComponent.class.getFields(); 36 Field[] frameworksFields = 37 android.frameworks.automotive.powerpolicy.PowerComponent.class.getFields(); 38 39 for (int i = 0; i < carFields.length; i++) { 40 fieldMap.put(carFields[i].getInt(null), carFields[i].getName()); 41 } 42 43 assertThat(carFields.length).isEqualTo(frameworksFields.length); 44 for (int i = 0; i < frameworksFields.length; i++) { 45 int frameworksValue = frameworksFields[i].getInt(null); 46 String frameworksName = frameworksFields[i].getName(); 47 String carName = fieldMap.get(frameworksValue); 48 assertThat(carName).isNotNull(); 49 assertThat(carName).isEqualTo(frameworksName); 50 } 51 } 52 } 53