• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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.internal;
18 
19 import static com.android.inputmethod.keyboard.internal.KeyboardIconsSet.ICON_UNDEFINED;
20 import static com.android.inputmethod.latin.common.Constants.CODE_UNSPECIFIED;
21 
22 import android.test.suitebuilder.annotation.SmallTest;
23 
24 import com.android.inputmethod.latin.common.Constants;
25 
26 @SmallTest
27 public final class KeySpecParserTests extends KeySpecParserTestsBase {
28     @Override
assertParser(final String message, final String keySpec, final String expectedLabel, final String expectedOutputText, final int expectedIcon, final int expectedCode)29     protected void assertParser(final String message, final String keySpec,
30             final String expectedLabel, final String expectedOutputText, final int expectedIcon,
31             final int expectedCode) {
32         final String keySpecResolved = mTextsSet.resolveTextReference(keySpec);
33         final String actualLabel = KeySpecParser.getLabel(keySpecResolved);
34         final String actualOutputText = KeySpecParser.getOutputText(keySpecResolved);
35         final int actualIcon = KeySpecParser.getIconId(keySpecResolved);
36         final int actualCode = KeySpecParser.getCode(keySpecResolved);
37         assertEquals(message + " [label]", expectedLabel, actualLabel);
38         assertEquals(message + " [ouptputText]", expectedOutputText, actualOutputText);
39         assertEquals(message + " [icon]",
40                 KeyboardIconsSet.getIconName(expectedIcon),
41                 KeyboardIconsSet.getIconName(actualIcon));
42         assertEquals(message + " [code]",
43                 Constants.printableCode(expectedCode),
44                 Constants.printableCode(actualCode));
45     }
46 
47     // TODO: Remove this method.
48     // These should throw {@link KeySpecParserError} when Key.keyLabel attribute become mandatory.
testEmptySpec()49     public void testEmptySpec() {
50         assertParser("Null spec", null,
51                 null, null, ICON_UNDEFINED, CODE_UNSPECIFIED);
52         assertParser("Empty spec", "",
53                 null, null, ICON_UNDEFINED, CODE_UNSPECIFIED);
54     }
55 }
56