• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2023 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.hardware.input
18 
19 import android.content.ContextWrapper
20 import android.graphics.drawable.Drawable
21 import android.platform.test.annotations.Presubmit
22 import androidx.test.platform.app.InstrumentationRegistry
23 import org.junit.Assert.assertEquals
24 import org.junit.Test
25 import org.junit.runner.RunWith
26 import org.mockito.junit.MockitoJUnitRunner
27 
28 /**
29  * Tests for Keyboard layout preview
30  *
31  * Build/Install/Run: atest InputTests:KeyboardLayoutPreviewTests
32  */
33 @Presubmit
34 @RunWith(MockitoJUnitRunner::class)
35 class KeyboardLayoutPreviewTests {
36 
37     companion object {
38         const val WIDTH = 100
39         const val HEIGHT = 100
40     }
41 
createDrawablenull42     private fun createDrawable(): Drawable? {
43         val context = ContextWrapper(InstrumentationRegistry.getInstrumentation().getContext())
44         val inputManager = context.getSystemService(InputManager::class.java)!!
45         return inputManager.getKeyboardLayoutPreview(null, WIDTH, HEIGHT)
46     }
47 
48     @Test
testKeyboardLayoutDrawable_hasCorrectDimensionsnull49     fun testKeyboardLayoutDrawable_hasCorrectDimensions() {
50         val drawable = createDrawable()!!
51         assertEquals(WIDTH, drawable.intrinsicWidth)
52         assertEquals(HEIGHT, drawable.intrinsicHeight)
53     }
54 }
55