Fix tests

Change-Id: I12ba56d021b50c03dc62e3f3c8db3ecada2f6a4b
main
Jean Chalard 2014-06-30 15:25:14 +09:00
parent 4db7da92f2
commit 3fb5a541a4
4 changed files with 40 additions and 46 deletions

View File

@ -35,7 +35,7 @@ public class InputLogicTests extends InputTestsBase {
final String WORD_TO_TYPE = "this"; final String WORD_TO_TYPE = "this";
final String EXPECTED_RESULT = "thi"; final String EXPECTED_RESULT = "thi";
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
pickSuggestionManually(0, WORD_TO_TYPE); pickSuggestionManually(WORD_TO_TYPE);
mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1); mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
type(Constants.CODE_DELETE); type(Constants.CODE_DELETE);
assertEquals("press suggestion then backspace", EXPECTED_RESULT, assertEquals("press suggestion then backspace", EXPECTED_RESULT,
@ -47,9 +47,8 @@ public class InputLogicTests extends InputTestsBase {
final String WORD_TO_PICK = "this"; final String WORD_TO_PICK = "this";
final String EXPECTED_RESULT = "thi"; final String EXPECTED_RESULT = "thi";
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
// Choose the auto-correction, which is always in position 0. For "tgis", the // Choose the auto-correction. For "tgis", the auto-correction should be "this".
// auto-correction should be "this". pickSuggestionManually(WORD_TO_PICK);
pickSuggestionManually(0, WORD_TO_PICK);
mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1); mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
assertEquals("pick typed word over auto-correction then backspace", WORD_TO_PICK, assertEquals("pick typed word over auto-correction then backspace", WORD_TO_PICK,
mEditText.getText().toString()); mEditText.getText().toString());
@ -62,9 +61,8 @@ public class InputLogicTests extends InputTestsBase {
final String WORD_TO_TYPE = "tgis"; final String WORD_TO_TYPE = "tgis";
final String EXPECTED_RESULT = "tgi"; final String EXPECTED_RESULT = "tgi";
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
// Choose the typed word, which should be in position 1 (because position 0 should // Choose the typed word.
// be occupied by the "this" auto-correction, as checked by testAutoCorrect()) pickSuggestionManually(WORD_TO_TYPE);
pickSuggestionManually(1, WORD_TO_TYPE);
mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1); mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
assertEquals("pick typed word over auto-correction then backspace", WORD_TO_TYPE, assertEquals("pick typed word over auto-correction then backspace", WORD_TO_TYPE,
mEditText.getText().toString()); mEditText.getText().toString());
@ -78,9 +76,8 @@ public class InputLogicTests extends InputTestsBase {
final String WORD_TO_PICK = "thus"; final String WORD_TO_PICK = "thus";
final String EXPECTED_RESULT = "thu"; final String EXPECTED_RESULT = "thu";
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
// Choose the second suggestion, which should be in position 2 and should be "thus" // Choose the second suggestion, which should be "thus" when "tgis" is typed.
// when "tgis is typed. pickSuggestionManually(WORD_TO_PICK);
pickSuggestionManually(2, WORD_TO_PICK);
mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1); mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
assertEquals("pick different suggestion then backspace", WORD_TO_PICK, assertEquals("pick different suggestion then backspace", WORD_TO_PICK,
mEditText.getText().toString()); mEditText.getText().toString());
@ -309,7 +306,7 @@ public class InputLogicTests extends InputTestsBase {
final String WORD_TO_TYPE = "this"; final String WORD_TO_TYPE = "this";
final String EXPECTED_RESULT = WORD_TO_TYPE; final String EXPECTED_RESULT = WORD_TO_TYPE;
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
pickSuggestionManually(0, WORD_TO_TYPE); pickSuggestionManually(WORD_TO_TYPE);
assertEquals("no space after manual pick", EXPECTED_RESULT, assertEquals("no space after manual pick", EXPECTED_RESULT,
mEditText.getText().toString()); mEditText.getText().toString());
} }
@ -319,7 +316,7 @@ public class InputLogicTests extends InputTestsBase {
final String WORD2_TO_TYPE = "is"; final String WORD2_TO_TYPE = "is";
final String EXPECTED_RESULT = "this is"; final String EXPECTED_RESULT = "this is";
type(WORD1_TO_TYPE); type(WORD1_TO_TYPE);
pickSuggestionManually(0, WORD1_TO_TYPE); pickSuggestionManually(WORD1_TO_TYPE);
type(WORD2_TO_TYPE); type(WORD2_TO_TYPE);
assertEquals("manual pick then type", EXPECTED_RESULT, mEditText.getText().toString()); assertEquals("manual pick then type", EXPECTED_RESULT, mEditText.getText().toString());
} }
@ -329,7 +326,7 @@ public class InputLogicTests extends InputTestsBase {
final String WORD2_TO_TYPE = "!"; final String WORD2_TO_TYPE = "!";
final String EXPECTED_RESULT = "this!"; final String EXPECTED_RESULT = "this!";
type(WORD1_TO_TYPE); type(WORD1_TO_TYPE);
pickSuggestionManually(0, WORD1_TO_TYPE); pickSuggestionManually(WORD1_TO_TYPE);
type(WORD2_TO_TYPE); type(WORD2_TO_TYPE);
assertEquals("manual pick then separator", EXPECTED_RESULT, mEditText.getText().toString()); assertEquals("manual pick then separator", EXPECTED_RESULT, mEditText.getText().toString());
} }
@ -341,7 +338,7 @@ public class InputLogicTests extends InputTestsBase {
final String WORD2_TO_TYPE = "!!?!:!"; final String WORD2_TO_TYPE = "!!?!:!";
final String EXPECTED_RESULT = "test!!?!:!"; final String EXPECTED_RESULT = "test!!?!:!";
type(WORD1_TO_TYPE); type(WORD1_TO_TYPE);
pickSuggestionManually(0, WORD1_TO_TYPE); pickSuggestionManually(WORD1_TO_TYPE);
type(WORD2_TO_TYPE); type(WORD2_TO_TYPE);
assertEquals("clustering punctuation", EXPECTED_RESULT, mEditText.getText().toString()); assertEquals("clustering punctuation", EXPECTED_RESULT, mEditText.getText().toString());
} }
@ -351,10 +348,10 @@ public class InputLogicTests extends InputTestsBase {
final String STRIPPER = "\n"; final String STRIPPER = "\n";
final String EXPECTED_RESULT = "this\nthis"; final String EXPECTED_RESULT = "this\nthis";
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
pickSuggestionManually(0, WORD_TO_TYPE); pickSuggestionManually(WORD_TO_TYPE);
type(STRIPPER); type(STRIPPER);
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
pickSuggestionManually(0, WORD_TO_TYPE); pickSuggestionManually(WORD_TO_TYPE);
assertEquals("manual pick then \\n then manual pick", EXPECTED_RESULT, assertEquals("manual pick then \\n then manual pick", EXPECTED_RESULT,
mEditText.getText().toString()); mEditText.getText().toString());
} }
@ -364,7 +361,7 @@ public class InputLogicTests extends InputTestsBase {
final String WORD2_TO_TYPE = " is"; final String WORD2_TO_TYPE = " is";
final String EXPECTED_RESULT = "this is"; final String EXPECTED_RESULT = "this is";
type(WORD1_TO_TYPE); type(WORD1_TO_TYPE);
pickSuggestionManually(0, WORD1_TO_TYPE); pickSuggestionManually(WORD1_TO_TYPE);
type(WORD2_TO_TYPE); type(WORD2_TO_TYPE);
assertEquals("manual pick then space then type", EXPECTED_RESULT, assertEquals("manual pick then space then type", EXPECTED_RESULT,
mEditText.getText().toString()); mEditText.getText().toString());
@ -375,11 +372,9 @@ public class InputLogicTests extends InputTestsBase {
final String WORD2_TO_PICK = "is"; final String WORD2_TO_PICK = "is";
final String EXPECTED_RESULT = "this is"; final String EXPECTED_RESULT = "this is";
type(WORD1_TO_TYPE); type(WORD1_TO_TYPE);
pickSuggestionManually(0, WORD1_TO_TYPE); pickSuggestionManually(WORD1_TO_TYPE);
// Here we fake picking a word through bigram prediction. This test is taking // Here we fake picking a word through bigram prediction.
// advantage of the fact that Latin IME blindly trusts the caller of #pickSuggestionManually pickSuggestionManually(WORD2_TO_PICK);
// to actually pass the right string.
pickSuggestionManually(1, WORD2_TO_PICK);
assertEquals("manual pick then manual pick", EXPECTED_RESULT, assertEquals("manual pick then manual pick", EXPECTED_RESULT,
mEditText.getText().toString()); mEditText.getText().toString());
} }
@ -506,9 +501,8 @@ public class InputLogicTests extends InputTestsBase {
public void testPredictionsAfterManualPick() { public void testPredictionsAfterManualPick() {
final String WORD_TO_TYPE = "Barack"; final String WORD_TO_TYPE = "Barack";
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
// Choose the auto-correction, which is always in position 0. For "Barack", the // Choose the auto-correction. For "Barack", the auto-correction should be "Barack".
// auto-correction should be "Barack". pickSuggestionManually(WORD_TO_TYPE);
pickSuggestionManually(0, WORD_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS); sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
runMessages(); runMessages();
// Test the first prediction is displayed // Test the first prediction is displayed
@ -545,7 +539,7 @@ public class InputLogicTests extends InputTestsBase {
type(PREFIX); type(PREFIX);
mLatinIME.onUpdateSelection(0, 0, endOfPrefix, endOfPrefix, -1, -1); mLatinIME.onUpdateSelection(0, 0, endOfPrefix, endOfPrefix, -1, -1);
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
pickSuggestionManually(1, FIRST_NON_TYPED_SUGGESTION); pickSuggestionManually(FIRST_NON_TYPED_SUGGESTION);
mLatinIME.onUpdateSelection(endOfPrefix, endOfPrefix, endOfSuggestion, endOfSuggestion, mLatinIME.onUpdateSelection(endOfPrefix, endOfPrefix, endOfSuggestion, endOfSuggestion,
-1, -1); -1, -1);
runMessages(); runMessages();
@ -560,7 +554,7 @@ public class InputLogicTests extends InputTestsBase {
indexForManualCursor, indexForManualCursor, -1, -1); indexForManualCursor, indexForManualCursor, -1, -1);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS); sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
runMessages(); runMessages();
pickSuggestionManually(0, WORD_TO_TYPE); pickSuggestionManually(WORD_TO_TYPE);
mLatinIME.onUpdateSelection(indexForManualCursor, indexForManualCursor, mLatinIME.onUpdateSelection(indexForManualCursor, indexForManualCursor,
endOfWord, endOfWord, -1, -1); endOfWord, endOfWord, -1, -1);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS); sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);

View File

@ -37,7 +37,7 @@ public class InputLogicTestsNonEnglish extends InputTestsBase {
final String EXPECTED_RESULT = "test !"; final String EXPECTED_RESULT = "test !";
changeLanguage("fr"); changeLanguage("fr");
type(WORD1_TO_TYPE); type(WORD1_TO_TYPE);
pickSuggestionManually(0, WORD1_TO_TYPE); pickSuggestionManually(WORD1_TO_TYPE);
type(WORD2_TO_TYPE); type(WORD2_TO_TYPE);
assertEquals("manual pick then separator for French", EXPECTED_RESULT, assertEquals("manual pick then separator for French", EXPECTED_RESULT,
mEditText.getText().toString()); mEditText.getText().toString());
@ -50,7 +50,7 @@ public class InputLogicTestsNonEnglish extends InputTestsBase {
final String EXPECTED_RESULT = "test !!?! : !"; final String EXPECTED_RESULT = "test !!?! : !";
changeLanguage("fr"); changeLanguage("fr");
type(WORD1_TO_TYPE); type(WORD1_TO_TYPE);
pickSuggestionManually(0, WORD1_TO_TYPE); pickSuggestionManually(WORD1_TO_TYPE);
type(WORD2_TO_TYPE); type(WORD2_TO_TYPE);
assertEquals("clustering punctuation for French", EXPECTED_RESULT, assertEquals("clustering punctuation for French", EXPECTED_RESULT,
mEditText.getText().toString()); mEditText.getText().toString());
@ -72,8 +72,8 @@ public class InputLogicTestsNonEnglish extends InputTestsBase {
runMessages(); runMessages();
assertTrue("type word then type space should display punctuation strip", assertTrue("type word then type space should display punctuation strip",
mLatinIME.getSuggestedWordsForTest().isPunctuationSuggestions()); mLatinIME.getSuggestedWordsForTest().isPunctuationSuggestions());
pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); pickSuggestionManually(PUNCTUATION_FROM_STRIP);
pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); pickSuggestionManually(PUNCTUATION_FROM_STRIP);
assertEquals("type word then type space then punctuation from strip twice for French", assertEquals("type word then type space then punctuation from strip twice for French",
EXPECTED_RESULT, mEditText.getText().toString()); EXPECTED_RESULT, mEditText.getText().toString());
} finally { } finally {

View File

@ -345,8 +345,8 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
waitForDictionariesToBeLoaded(); waitForDictionariesToBeLoaded();
} }
protected void pickSuggestionManually(final int index, final String suggestion) { protected void pickSuggestionManually(final String suggestion) {
mLatinIME.pickSuggestionManually(index, new SuggestedWordInfo(suggestion, 1, mLatinIME.pickSuggestionManually(new SuggestedWordInfo(suggestion, 1,
SuggestedWordInfo.KIND_CORRECTION, null /* sourceDict */, SuggestedWordInfo.KIND_CORRECTION, null /* sourceDict */,
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */, SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */)); SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */));

View File

@ -42,8 +42,8 @@ public class PunctuationTests extends InputTestsBase {
runMessages(); runMessages();
assertTrue("type word then type space should display punctuation strip", assertTrue("type word then type space should display punctuation strip",
mLatinIME.getSuggestedWordsForTest().isPunctuationSuggestions()); mLatinIME.getSuggestedWordsForTest().isPunctuationSuggestions());
pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); pickSuggestionManually(PUNCTUATION_FROM_STRIP);
pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); pickSuggestionManually(PUNCTUATION_FROM_STRIP);
assertEquals("type word then type space then punctuation from strip twice", assertEquals("type word then type space then punctuation from strip twice",
EXPECTED_RESULT, mEditText.getText().toString()); EXPECTED_RESULT, mEditText.getText().toString());
} finally { } finally {
@ -66,9 +66,9 @@ public class PunctuationTests extends InputTestsBase {
final String PUNCTUATION_FROM_STRIP = "!"; final String PUNCTUATION_FROM_STRIP = "!";
final String EXPECTED_RESULT = "this!! is"; final String EXPECTED_RESULT = "this!! is";
type(WORD1_TO_TYPE); type(WORD1_TO_TYPE);
pickSuggestionManually(0, WORD1_TO_TYPE); pickSuggestionManually(WORD1_TO_TYPE);
pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); pickSuggestionManually(PUNCTUATION_FROM_STRIP);
pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); pickSuggestionManually(PUNCTUATION_FROM_STRIP);
type(WORD2_TO_TYPE); type(WORD2_TO_TYPE);
assertEquals("pick word then pick punctuation twice then type", EXPECTED_RESULT, assertEquals("pick word then pick punctuation twice then type", EXPECTED_RESULT,
mEditText.getText().toString()); mEditText.getText().toString());
@ -79,8 +79,8 @@ public class PunctuationTests extends InputTestsBase {
final String WORD2_TO_PICK = "!is"; final String WORD2_TO_PICK = "!is";
final String EXPECTED_RESULT = "this!is"; final String EXPECTED_RESULT = "this!is";
type(WORD1_TO_TYPE); type(WORD1_TO_TYPE);
pickSuggestionManually(0, WORD1_TO_TYPE); pickSuggestionManually(WORD1_TO_TYPE);
pickSuggestionManually(1, WORD2_TO_PICK); pickSuggestionManually(WORD2_TO_PICK);
assertEquals("manual pick then manual pick a word with punct at start", EXPECTED_RESULT, assertEquals("manual pick then manual pick a word with punct at start", EXPECTED_RESULT,
mEditText.getText().toString()); mEditText.getText().toString());
} }
@ -90,7 +90,7 @@ public class PunctuationTests extends InputTestsBase {
final String PUNCTUATION = ":"; final String PUNCTUATION = ":";
final String EXPECTED_RESULT = "this:"; final String EXPECTED_RESULT = "this:";
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
pickSuggestionManually(0, WORD_TO_TYPE); pickSuggestionManually(WORD_TO_TYPE);
type(PUNCTUATION); type(PUNCTUATION);
assertEquals("manually pick word then colon", assertEquals("manually pick word then colon",
EXPECTED_RESULT, mEditText.getText().toString()); EXPECTED_RESULT, mEditText.getText().toString());
@ -101,7 +101,7 @@ public class PunctuationTests extends InputTestsBase {
final String PUNCTUATION = "("; final String PUNCTUATION = "(";
final String EXPECTED_RESULT = "this ("; final String EXPECTED_RESULT = "this (";
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
pickSuggestionManually(0, WORD_TO_TYPE); pickSuggestionManually(WORD_TO_TYPE);
type(PUNCTUATION); type(PUNCTUATION);
assertEquals("manually pick word then open paren", assertEquals("manually pick word then open paren",
EXPECTED_RESULT, mEditText.getText().toString()); EXPECTED_RESULT, mEditText.getText().toString());
@ -112,7 +112,7 @@ public class PunctuationTests extends InputTestsBase {
final String PUNCTUATION = ")"; final String PUNCTUATION = ")";
final String EXPECTED_RESULT = "this)"; final String EXPECTED_RESULT = "this)";
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
pickSuggestionManually(0, WORD_TO_TYPE); pickSuggestionManually(WORD_TO_TYPE);
type(PUNCTUATION); type(PUNCTUATION);
assertEquals("manually pick word then close paren", assertEquals("manually pick word then close paren",
EXPECTED_RESULT, mEditText.getText().toString()); EXPECTED_RESULT, mEditText.getText().toString());
@ -123,7 +123,7 @@ public class PunctuationTests extends InputTestsBase {
final String SPECIAL_KEY = ":-)"; final String SPECIAL_KEY = ":-)";
final String EXPECTED_RESULT = "this :-)"; final String EXPECTED_RESULT = "this :-)";
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
pickSuggestionManually(0, WORD_TO_TYPE); pickSuggestionManually(WORD_TO_TYPE);
mLatinIME.onTextInput(SPECIAL_KEY); mLatinIME.onTextInput(SPECIAL_KEY);
assertEquals("manually pick word then press the smiley key", assertEquals("manually pick word then press the smiley key",
EXPECTED_RESULT, mEditText.getText().toString()); EXPECTED_RESULT, mEditText.getText().toString());
@ -134,7 +134,7 @@ public class PunctuationTests extends InputTestsBase {
final String SPECIAL_KEY = ".com"; final String SPECIAL_KEY = ".com";
final String EXPECTED_RESULT = "this.com"; final String EXPECTED_RESULT = "this.com";
type(WORD_TO_TYPE); type(WORD_TO_TYPE);
pickSuggestionManually(0, WORD_TO_TYPE); pickSuggestionManually(WORD_TO_TYPE);
mLatinIME.onTextInput(SPECIAL_KEY); mLatinIME.onTextInput(SPECIAL_KEY);
assertEquals("manually pick word then press the .com key", assertEquals("manually pick word then press the .com key",
EXPECTED_RESULT, mEditText.getText().toString()); EXPECTED_RESULT, mEditText.getText().toString());
@ -189,7 +189,7 @@ public class PunctuationTests extends InputTestsBase {
if (wordToType.matches("^\\w+$")) { if (wordToType.matches("^\\w+$")) {
// Only pick selection if that was a word, because if that was not a word, // Only pick selection if that was a word, because if that was not a word,
// then we don't have a composition. // then we don't have a composition.
pickSuggestionManually(0, wordToType); pickSuggestionManually(wordToType);
} }
} }
type("\""); type("\"");