Search in sources :

Example 1 with ExpectedKey

use of com.android.inputmethod.keyboard.layout.expected.ExpectedKey in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class LayoutTestsBase method doKeyboardTests.

// Comparing expected keyboard and actual keyboard.
private void doKeyboardTests(final int elementId) {
    final ExpectedKey[][] expectedKeyboard = mLayout.getLayout(isPhone(), elementId);
    // Skip test if no keyboard is defined.
    if (expectedKeyboard == null) {
        return;
    }
    final String tag = mLogTag + "/" + KeyboardId.elementIdToName(elementId);
    // Create actual keyboard object.
    final Keyboard keyboard = mKeyboardLayoutSet.getKeyboard(elementId);
    // Create actual keyboard to be compared with the expected keyboard.
    final Key[][] actualKeyboard = ActualKeyboardBuilder.buildKeyboard(keyboard.getSortedKeys());
    // Dump human readable definition of expected/actual keyboards.
    Log.d(tag, "expected=\n" + ExpectedKeyboardBuilder.toString(expectedKeyboard));
    Log.d(tag, "actual  =\n" + ActualKeyboardBuilder.toString(actualKeyboard));
    // Test both keyboards have the same number of rows.
    assertEquals(tag + " labels" + "\nexpected=" + ExpectedKeyboardBuilder.toString(expectedKeyboard) + "\nactual  =" + ActualKeyboardBuilder.toString(actualKeyboard), expectedKeyboard.length, actualKeyboard.length);
    for (int r = 0; r < actualKeyboard.length; r++) {
        final int row = r + 1;
        // Test both keyboards' rows have the same number of columns.
        assertEquals(tag + " labels row=" + row + "\nexpected=" + Arrays.toString(expectedKeyboard[r]) + "\nactual  =" + ActualKeyboardBuilder.toString(actualKeyboard[r]), expectedKeyboard[r].length, actualKeyboard[r].length);
        for (int c = 0; c < actualKeyboard[r].length; c++) {
            final int column = c + 1;
            final Key actualKey = actualKeyboard[r][c];
            final ExpectedKey expectedKey = expectedKeyboard[r][c];
            // Test both keyboards' keys have the same visual outlook and key output.
            assertTrue(tag + " labels row,column=" + row + "," + column + "\nexpected=" + expectedKey + "\nactual  =" + ActualKeyboardBuilder.toString(actualKey), expectedKey.equalsTo(actualKey));
        }
    }
}
Also used : ExpectedKey(com.android.inputmethod.keyboard.layout.expected.ExpectedKey) Keyboard(com.android.inputmethod.keyboard.Keyboard) ExpectedAdditionalMoreKey(com.android.inputmethod.keyboard.layout.expected.ExpectedKey.ExpectedAdditionalMoreKey) ExpectedKey(com.android.inputmethod.keyboard.layout.expected.ExpectedKey) Key(com.android.inputmethod.keyboard.Key)

Aggregations

Key (com.android.inputmethod.keyboard.Key)1 Keyboard (com.android.inputmethod.keyboard.Keyboard)1 ExpectedKey (com.android.inputmethod.keyboard.layout.expected.ExpectedKey)1 ExpectedAdditionalMoreKey (com.android.inputmethod.keyboard.layout.expected.ExpectedKey.ExpectedAdditionalMoreKey)1