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