1 /* 2 * Copyright (C) 2019 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 package android.car; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.car.navigation.CarNavigationInstrumentCluster; 22 import android.car.navigation.CarNavigationStatusManager; 23 import android.car.testapi.CarNavigationStatusController; 24 import android.car.testapi.FakeCar; 25 import android.content.Context; 26 import android.os.Bundle; 27 28 import androidx.test.core.app.ApplicationProvider; 29 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 import org.robolectric.RobolectricTestRunner; 34 import org.robolectric.annotation.internal.DoNotInstrument; 35 36 @RunWith(RobolectricTestRunner.class) 37 @DoNotInstrument 38 public class CarNavigationStatusManagerTest { 39 private Context mContext; 40 private FakeCar mFakeCar; 41 private Car mCar; 42 private CarNavigationStatusManager mCarNavigationStatusManager; 43 private CarNavigationStatusController mCarNavigationStatusController; 44 45 @Before setUp()46 public void setUp() { 47 mContext = ApplicationProvider.getApplicationContext(); 48 mFakeCar = FakeCar.createFakeCar(mContext); 49 mCar = mFakeCar.getCar(); 50 mCarNavigationStatusManager = 51 (CarNavigationStatusManager) mCar.getCarManager(Car.CAR_NAVIGATION_SERVICE); 52 mCarNavigationStatusController = mFakeCar.getCarNavigationStatusController(); 53 54 // There should be no value after set up of the service. 55 assertThat(mCarNavigationStatusController.getCurrentNavState()).isNull(); 56 } 57 58 @Test onNavigationStateChanged_bundleIsReceived()59 public void onNavigationStateChanged_bundleIsReceived() { 60 Bundle bundle = new Bundle(); 61 mCarNavigationStatusManager.sendNavigationStateChange(bundle); 62 63 assertThat(mCarNavigationStatusController.getCurrentNavState()).isEqualTo(bundle); 64 } 65 66 @Test getInstrumentClusterInfo_returnsImageCodeCluster()67 public void getInstrumentClusterInfo_returnsImageCodeCluster() { 68 // default cluster should be an image code cluster (no custom images) 69 assertThat(mCarNavigationStatusManager.getInstrumentClusterInfo().getType()).isEqualTo( 70 CarNavigationInstrumentCluster.CLUSTER_TYPE_IMAGE_CODES_ONLY); 71 } 72 73 @Test setImageCodeClusterInfo_returnsImageCodeCluster()74 public void setImageCodeClusterInfo_returnsImageCodeCluster() { 75 mCarNavigationStatusController.setImageCodeClusterInfo(42); 76 77 CarNavigationInstrumentCluster instrumentCluster = 78 mCarNavigationStatusManager.getInstrumentClusterInfo(); 79 80 assertThat(instrumentCluster.getType()) 81 .isEqualTo(CarNavigationInstrumentCluster.CLUSTER_TYPE_IMAGE_CODES_ONLY); 82 assertThat(instrumentCluster.getMinIntervalMillis()).isEqualTo(42); 83 } 84 85 @Test setCustomImageClusterInfo_returnsCustomImageCluster()86 public void setCustomImageClusterInfo_returnsCustomImageCluster() { 87 mCarNavigationStatusController.setCustomImageClusterInfo( 88 100, 89 1024, 90 768, 91 32); 92 93 CarNavigationInstrumentCluster instrumentCluster = 94 mCarNavigationStatusManager.getInstrumentClusterInfo(); 95 96 assertThat(instrumentCluster.getType()) 97 .isEqualTo(CarNavigationInstrumentCluster.CLUSTER_TYPE_CUSTOM_IMAGES_SUPPORTED); 98 assertThat(instrumentCluster.getMinIntervalMillis()).isEqualTo(100); 99 assertThat(instrumentCluster.getImageWidth()).isEqualTo(1024); 100 assertThat(instrumentCluster.getImageHeight()).isEqualTo(768); 101 assertThat(instrumentCluster.getImageColorDepthBits()).isEqualTo(32); 102 } 103 } 104