• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 com.android.car.input;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.car.CarOccupantZoneManager;
22 import android.car.input.CustomInputEvent;
23 import android.os.Parcel;
24 
25 import org.junit.Test;
26 
27 public final class CustomInputEventTest {
28 
29     @Test
testCustomInputEventWriteAndReadParcel()30     public void testCustomInputEventWriteAndReadParcel() {
31         CustomInputEvent original = new CustomInputEvent(
32                 /* inputCode= */ CustomInputEvent.INPUT_CODE_F1,
33                 /* targetDisplayType= */ CarOccupantZoneManager.DISPLAY_TYPE_INSTRUMENT_CLUSTER,
34                 /* repeatCounter= */ 3);
35 
36         Parcel parcel = Parcel.obtain();
37         original.writeToParcel(parcel, 0);
38         parcel.setDataPosition(0);
39 
40         CustomInputEvent actual = CustomInputEvent.CREATOR.createFromParcel(parcel);
41         assertThat(actual).isEqualTo(original);
42 
43         // Check generated getters
44         assertThat(actual.getInputCode()).isEqualTo(CustomInputEvent.INPUT_CODE_F1);
45         assertThat(actual.getRepeatCounter()).isEqualTo(3);
46         assertThat(actual.getTargetDisplayType()).isEqualTo(
47                 CarOccupantZoneManager.DISPLAY_TYPE_INSTRUMENT_CLUSTER);
48     }
49 
50     @Test
testInputCodeToString()51     public void testInputCodeToString() {
52         assertThat(CustomInputEvent.inputCodeToString(CustomInputEvent.INPUT_CODE_F1)).isEqualTo(
53                 Integer.toString(CustomInputEvent.INPUT_CODE_F1));
54     }
55 
56     @Test
testCustomInputEventParcelNewArray()57     public void testCustomInputEventParcelNewArray() {
58         CustomInputEvent[] eventArray = CustomInputEvent.CREATOR.newArray(10);
59         assertThat(eventArray).hasLength(10);
60     }
61 }
62