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