aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/com/android/inputmethod/latin')
-rw-r--r--tests/src/com/android/inputmethod/latin/InputTestsBase.java26
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java28
2 files changed, 29 insertions, 25 deletions
diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
index 4ccbf4857..04e1f932a 100644
--- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java
+++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
@@ -130,7 +130,9 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
protected void setUp() throws Exception {
super.setUp();
mTextView = new MyTextView(getContext());
- mTextView.setInputType(InputType.TYPE_CLASS_TEXT);
+ final int inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT
+ | InputType.TYPE_TEXT_FLAG_MULTI_LINE;
+ mTextView.setInputType(inputType);
mTextView.setEnabled(true);
setupService();
mLatinIME = getService();
@@ -138,9 +140,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
mLatinIME.onCreate();
setDebugMode(previousDebugSetting);
final EditorInfo ei = new EditorInfo();
- ei.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
final InputConnection ic = mTextView.onCreateInputConnection(ei);
- ei.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
final LayoutInflater inflater =
(LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final ViewGroup vg = new FrameLayout(getContext());
@@ -181,17 +181,21 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
// a message that calls it instead of calling it directly.
Looper.loop();
- // Once #quit() has been called, the message queue has an "mQuiting" field that prevents
- // any subsequent post in this queue. However the queue itself is still fully functional!
- // If we have a way of resetting "queue.mQuiting" then we can continue using it as normal,
- // coming back to this method to run the messages.
+ // Once #quit() has been called, the looper is not functional any more (it used to be,
+ // but now it SIGSEGV's if it's used again).
+ // It won't accept creating a new looper for this thread and switching to it...
+ // ...unless we can trick it into throwing out the old looper and believing it hasn't
+ // been initialized before.
MessageQueue queue = Looper.myQueue();
try {
- // However there is no way of doing it externally, and mQuiting is private.
+ // However there is no way of doing it externally, and the static ThreadLocal
+ // field into which it's stored is private.
// So... get out the big guns.
- java.lang.reflect.Field f = MessageQueue.class.getDeclaredField("mQuiting");
- f.setAccessible(true); // What do you mean "private"?
- f.setBoolean(queue, false);
+ java.lang.reflect.Field f = Looper.class.getDeclaredField("sThreadLocal");
+ f.setAccessible(true); // private lolwut
+ final ThreadLocal<Looper> a = (ThreadLocal<Looper>) f.get(looper);
+ a.set(null);
+ looper.prepare();
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java
index ade010981..bd8729203 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java
@@ -72,15 +72,12 @@ public class BinaryDictIOTests extends AndroidTestCase {
private static final FormatSpec.FormatOptions VERSION3_WITH_DYNAMIC_UPDATE =
new FormatSpec.FormatOptions(3, true /* supportsDynamicUpdate */);
- private static final String[] CHARACTERS = {
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
- "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
- };
-
public BinaryDictIOTests() {
super();
- final Random random = new Random(123456);
+ final long time = System.currentTimeMillis();
+ Log.e(TAG, "Testing dictionary: seed is " + time);
+ final Random random = new Random(time);
sWords.clear();
generateWords(MAX_UNIGRAMS, random);
@@ -132,13 +129,16 @@ public class BinaryDictIOTests extends AndroidTestCase {
/**
* Generates a random word.
*/
- private String generateWord(final int value) {
- final int lengthOfChars = CHARACTERS.length;
+ private String generateWord(final Random random) {
StringBuilder builder = new StringBuilder("a");
- long lvalue = Math.abs((long)value);
- while (lvalue > 0) {
- builder.append(CHARACTERS[(int)(lvalue % lengthOfChars)]);
- lvalue /= lengthOfChars;
+ int count = random.nextInt() % 30; // Arbitrarily 30 chars max
+ while (count > 0) {
+ final long r = Math.abs(random.nextInt());
+ if (r < 0) continue;
+ // Don't insert 0~20, but insert any other code point.
+ // Code points are in the range 0~0x10FFFF.
+ builder.appendCodePoint((int)(20 + r % (0x10FFFF - 20)));
+ --count;
}
return builder.toString();
}
@@ -146,7 +146,7 @@ public class BinaryDictIOTests extends AndroidTestCase {
private void generateWords(final int number, final Random random) {
final Set<String> wordSet = CollectionUtils.newHashSet();
while (wordSet.size() < number) {
- wordSet.add(generateWord(random.nextInt()));
+ wordSet.add(generateWord(random));
}
sWords.addAll(wordSet);
}
@@ -555,7 +555,7 @@ public class BinaryDictIOTests extends AndroidTestCase {
// Test a word that isn't contained within the dictionary.
final Random random = new Random((int)System.currentTimeMillis());
for (int i = 0; i < 1000; ++i) {
- final String word = generateWord(random.nextInt());
+ final String word = generateWord(random);
if (sWords.indexOf(word) != -1) continue;
runGetTerminalPosition(buffer, word, i, false);
}