1 /* 2 * Copyright (C) 2015 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.inputmethod.keyboard; 18 19 import static org.junit.Assert.assertEquals; 20 21 import androidx.test.filters.SmallTest; 22 import androidx.test.runner.AndroidJUnit4; 23 24 import org.junit.Test; 25 import org.junit.runner.RunWith; 26 27 import java.util.ArrayList; 28 29 @SmallTest 30 @RunWith(AndroidJUnit4.class) 31 public class KeyboardLayoutTest { 32 @Test testNewKeyboardLayout()33 public void testNewKeyboardLayout() { 34 KeyboardLayout keyboardLayout = KeyboardLayout 35 .newKeyboardLayout(new ArrayList<Key>(), 11, 12, 13, 14); 36 37 assertEquals(11, keyboardLayout.mMostCommonKeyWidth); 38 assertEquals(12, keyboardLayout.mMostCommonKeyHeight); 39 assertEquals(13, keyboardLayout.mKeyboardWidth); 40 assertEquals(14, keyboardLayout.mKeyboardHeight); 41 42 assertEquals(0, keyboardLayout.getKeyCodes().length); 43 assertEquals(0, keyboardLayout.getKeyWidths().length); 44 assertEquals(0, keyboardLayout.getKeyHeights().length); 45 assertEquals(0, keyboardLayout.getKeyXCoordinates().length); 46 assertEquals(0, keyboardLayout.getKeyYCoordinates().length); 47 48 Key key1 = new Key("label1", 101, 102, "101", "101hint", 103, 104, 105, 106, 1100, 1101, 49 10, 10); 50 Key key2 = new Key("label2", 201, 103, "201", "201hint", 203, 204, 205, 206, 2100, 2101, 51 10, 10); 52 53 ArrayList<Key> sortedKeys = new ArrayList<>(2); 54 sortedKeys.add(key1); 55 sortedKeys.add(key2); 56 keyboardLayout = KeyboardLayout.newKeyboardLayout(sortedKeys, 11, 12, 13, 14); 57 assertEquals(2, keyboardLayout.getKeyCodes().length); 58 assertEquals(2, keyboardLayout.getKeyWidths().length); 59 assertEquals(2, keyboardLayout.getKeyHeights().length); 60 assertEquals(2, keyboardLayout.getKeyXCoordinates().length); 61 assertEquals(2, keyboardLayout.getKeyYCoordinates().length); 62 63 assertEquals(102, keyboardLayout.getKeyCodes()[0]); 64 // xCo + horizontalGap/2 65 assertEquals(105 + 5, keyboardLayout.getKeyXCoordinates()[0]); 66 assertEquals(106, keyboardLayout.getKeyYCoordinates()[0]); 67 // width - horizontalGap 68 assertEquals(1100 - 10, keyboardLayout.getKeyWidths()[0]); 69 // height - verticalGap 70 assertEquals(1101 - 10, keyboardLayout.getKeyHeights()[0]); 71 72 assertEquals(103, keyboardLayout.getKeyCodes()[1]); 73 // xCo + horizontalGap/2 74 assertEquals(205 + 5, keyboardLayout.getKeyXCoordinates()[1]); 75 assertEquals(206, keyboardLayout.getKeyYCoordinates()[1]); 76 // width - horizontalGap 77 assertEquals(2100 - 10, keyboardLayout.getKeyWidths()[1]); 78 // height - verticalGap 79 assertEquals(2101 - 10, keyboardLayout.getKeyHeights()[1]); 80 } 81 } 82