Home | History | Annotate | Download | only in latin
      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.latin;
     18 
     19 import android.test.suitebuilder.annotation.LargeTest;
     20 
     21 import com.android.inputmethod.event.Event;
     22 import com.android.inputmethod.latin.common.Constants;
     23 
     24 import java.util.ArrayList;
     25 
     26 @LargeTest
     27 public class InputLogicTestsDeadKeys extends InputTestsBase {
     28     // A helper class for readability
     29     static class EventList extends ArrayList<Event> {
     30         public EventList addCodePoint(final int codePoint, final boolean isDead) {
     31             final Event event;
     32             if (isDead) {
     33                 event = Event.createDeadEvent(codePoint, Event.NOT_A_KEY_CODE, null /* next */);
     34             } else {
     35                 event = Event.createSoftwareKeypressEvent(codePoint, Event.NOT_A_KEY_CODE,
     36                         Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE,
     37                         false /* isKeyRepeat */);
     38             }
     39             add(event);
     40             return this;
     41         }
     42 
     43         public EventList addKey(final int keyCode) {
     44             add(Event.createSoftwareKeypressEvent(Event.NOT_A_CODE_POINT, keyCode,
     45                     Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE,
     46                     false /* isKeyRepeat */));
     47             return this;
     48         }
     49     }
     50 
     51     public void testDeadCircumflexSimple() {
     52         final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6;
     53         final String EXPECTED_RESULT = "a";
     54         final EventList events = new EventList()
     55                 .addCodePoint('a', false)
     56                 .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true)
     57                 .addCodePoint('e', false);
     58         for (final Event event : events) {
     59             mLatinIME.onEvent(event);
     60         }
     61         assertEquals("simple dead circumflex", EXPECTED_RESULT, mEditText.getText().toString());
     62     }
     63 
     64     public void testDeadCircumflexBackspace() {
     65         final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6;
     66         final String EXPECTED_RESULT = "ae";
     67         final EventList events = new EventList()
     68                 .addCodePoint('a', false)
     69                 .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true)
     70                 .addKey(Constants.CODE_DELETE)
     71                 .addCodePoint('e', false);
     72         for (final Event event : events) {
     73             mLatinIME.onEvent(event);
     74         }
     75         assertEquals("dead circumflex backspace", EXPECTED_RESULT, mEditText.getText().toString());
     76     }
     77 
     78     public void testDeadCircumflexFeedback() {
     79         final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6;
     80         final String EXPECTED_RESULT = "a\u02C6";
     81         final EventList events = new EventList()
     82                 .addCodePoint('a', false)
     83                 .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true);
     84         for (final Event event : events) {
     85             mLatinIME.onEvent(event);
     86         }
     87         assertEquals("dead circumflex gives feedback", EXPECTED_RESULT,
     88                 mEditText.getText().toString());
     89     }
     90 
     91     public void testDeadDiaeresisSpace() {
     92         final int MODIFIER_LETTER_DIAERESIS = 0xA8;
     93         final String EXPECTED_RESULT = "a\u00A8e\u00A8i";
     94         final EventList events = new EventList()
     95                 .addCodePoint('a', false)
     96                 .addCodePoint(MODIFIER_LETTER_DIAERESIS, true)
     97                 .addCodePoint(Constants.CODE_SPACE, false)
     98                 .addCodePoint('e', false)
     99                 .addCodePoint(MODIFIER_LETTER_DIAERESIS, true)
    100                 .addCodePoint(Constants.CODE_ENTER, false)
    101                 .addCodePoint('i', false);
    102         for (final Event event : events) {
    103             mLatinIME.onEvent(event);
    104         }
    105         assertEquals("dead diaeresis space commits the dead char", EXPECTED_RESULT,
    106                 mEditText.getText().toString());
    107     }
    108 
    109     public void testDeadAcuteLetterBackspace() {
    110         final int MODIFIER_LETTER_ACUTE = 0xB4;
    111         final String EXPECTED_RESULT1 = "a";
    112         final String EXPECTED_RESULT2 = "a";
    113         final EventList events = new EventList()
    114                 .addCodePoint('a', false)
    115                 .addCodePoint(MODIFIER_LETTER_ACUTE, true)
    116                 .addCodePoint('a', false);
    117         for (final Event event : events) {
    118             mLatinIME.onEvent(event);
    119         }
    120         assertEquals("dead acute on a typed", EXPECTED_RESULT1, mEditText.getText().toString());
    121         mLatinIME.onEvent(Event.createSoftwareKeypressEvent(Event.NOT_A_CODE_POINT,
    122                 Constants.CODE_DELETE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE,
    123                 false /* isKeyRepeat */));
    124         assertEquals("a with acute deleted", EXPECTED_RESULT2, mEditText.getText().toString());
    125     }
    126 
    127     public void testFinnishStroke() {
    128         final int MODIFIER_LETTER_STROKE = '-';
    129         final String EXPECTED_RESULT = "x\u0110\u0127";
    130         final EventList events = new EventList()
    131                 .addCodePoint('x', false)
    132                 .addCodePoint(MODIFIER_LETTER_STROKE, true)
    133                 .addCodePoint('D', false)
    134                 .addCodePoint(MODIFIER_LETTER_STROKE, true)
    135                 .addCodePoint('h', false);
    136         for (final Event event : events) {
    137             mLatinIME.onEvent(event);
    138         }
    139         assertEquals("Finnish dead stroke", EXPECTED_RESULT,
    140                 mEditText.getText().toString());
    141     }
    142 
    143     public void testDoubleDeadOgonek() {
    144         final int MODIFIER_LETTER_OGONEK = 0x02DB;
    145         final String EXPECTED_RESULT = "txs\u02DBfk";
    146         final EventList events = new EventList()
    147                 .addCodePoint('t', false)
    148                 .addCodePoint('x', false)
    149                 .addCodePoint(MODIFIER_LETTER_OGONEK, true)
    150                 .addCodePoint('o', false)
    151                 .addCodePoint('s', false)
    152                 .addCodePoint(MODIFIER_LETTER_OGONEK, true)
    153                 .addCodePoint(MODIFIER_LETTER_OGONEK, true)
    154                 .addCodePoint('f', false)
    155                 .addCodePoint(MODIFIER_LETTER_OGONEK, true)
    156                 .addCodePoint(MODIFIER_LETTER_OGONEK, true)
    157                 .addKey(Constants.CODE_DELETE)
    158                 .addCodePoint('k', false);
    159         for (final Event event : events) {
    160             mLatinIME.onEvent(event);
    161         }
    162         assertEquals("double dead ogonek, and backspace", EXPECTED_RESULT,
    163                 mEditText.getText().toString());
    164     }
    165 
    166     public void testDeadCircumflexDeadDiaeresis() {
    167         final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6;
    168         final int MODIFIER_LETTER_DIAERESIS = 0xA8;
    169         final String EXPECTED_RESULT = "r";
    170 
    171         final EventList events = new EventList()
    172                 .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true)
    173                 .addCodePoint(MODIFIER_LETTER_DIAERESIS, true)
    174                 .addCodePoint('r', false);
    175         for (final Event event : events) {
    176             mLatinIME.onEvent(event);
    177         }
    178         assertEquals("both circumflex and diaeresis on r", EXPECTED_RESULT,
    179                 mEditText.getText().toString());
    180     }
    181 
    182     public void testDeadCircumflexDeadDiaeresisBackspace() {
    183         final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6;
    184         final int MODIFIER_LETTER_DIAERESIS = 0xA8;
    185         final String EXPECTED_RESULT = "";
    186 
    187         final EventList events = new EventList()
    188                 .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true)
    189                 .addCodePoint(MODIFIER_LETTER_DIAERESIS, true)
    190                 .addKey(Constants.CODE_DELETE)
    191                 .addCodePoint('u', false);
    192         for (final Event event : events) {
    193             mLatinIME.onEvent(event);
    194         }
    195         assertEquals("dead circumflex, dead diaeresis, backspace, u", EXPECTED_RESULT,
    196                 mEditText.getText().toString());
    197     }
    198 
    199     public void testDeadCircumflexDoubleDeadDiaeresisBackspace() {
    200         final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6;
    201         final int MODIFIER_LETTER_DIAERESIS = 0xA8;
    202         final String EXPECTED_RESULT = "\u02C6u";
    203 
    204         final EventList events = new EventList()
    205                 .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true)
    206                 .addCodePoint(MODIFIER_LETTER_DIAERESIS, true)
    207                 .addCodePoint(MODIFIER_LETTER_DIAERESIS, true)
    208                 .addKey(Constants.CODE_DELETE)
    209                 .addCodePoint('u', false);
    210         for (final Event event : events) {
    211             mLatinIME.onEvent(event);
    212         }
    213         assertEquals("dead circumflex, double dead diaeresis, backspace, u", EXPECTED_RESULT,
    214                 mEditText.getText().toString());
    215     }
    216 }
    217