Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7b494d2a authored by Jimmy's avatar Jimmy
Browse files

Add KeyCharacterMapTest unit test

Adds unit test for KeyCharacterMapTest, primarily focusing on test
cases not covered in existing CTS tests.

Bug: None
Test: atest com.android.test.input.KeyCharacterMapTest

Flag: TEST_ONLY

Change-Id: Ie36f8ad505b26a2a1c2741804fcfd31d56649bc2
parent 6136c48d
Loading
Loading
Loading
Loading
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.test.input

import android.view.KeyCharacterMap
import android.view.KeyEvent

import org.junit.Assert.assertEquals
import org.junit.Test

/**
 * Tests for {@link KeyCharacterMap}.
 *
 * <p>Build/Install/Run:
 * atest KeyCharacterMapTest
 *
 */
class KeyCharacterMapTest {
    @Test
    fun testGetFallback() {
        // Based off of VIRTUAL kcm fallbacks.
        val keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD)

        // One modifier fallback.
        assertEquals(
            keyCharacterMap.getFallbackAction(KeyEvent.KEYCODE_SPACE,
                KeyEvent.META_CTRL_ON).keyCode,
            KeyEvent.KEYCODE_LANGUAGE_SWITCH)

        // Multiple modifier fallback.
        assertEquals(
            keyCharacterMap.getFallbackAction(KeyEvent.KEYCODE_DEL,
                KeyEvent.META_CTRL_ON or KeyEvent.META_ALT_ON).keyCode,
            KeyEvent.KEYCODE_BACK)

        // No default button, fallback only.
        assertEquals(
            keyCharacterMap.getFallbackAction(KeyEvent.KEYCODE_BUTTON_A, 0).keyCode,
            KeyEvent.KEYCODE_DPAD_CENTER)
    }
}