aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/inputmethod/latin/InputTestsBase.java41
-rw-r--r--tests/src/com/android/inputmethod/latin/StringUtilsTests.java79
2 files changed, 88 insertions, 32 deletions
diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
index 4583eab2f..9e107a49c 100644
--- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java
+++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
@@ -162,45 +162,22 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
// on the same thread that the tests are running on to mimic the actual environment as
// closely as possible.
// Now, Looper#loop() never exits in normal operation unless the Looper#quit() method
- // is called, so we need to do that at the right time so that #loop() returns at some
- // point and we don't end up in an infinite loop.
- // After we quit, the looper is still technically ready to process more messages but
- // the handler will refuse to enqueue any because #quit() has been called and it
- // explicitly tests for it on message enqueuing, so we'll have to reset it so that
- // it lets us continue normal operation.
+ // is called, which has a lot of bad side effects. We can however just throw an exception
+ // in the runnable which will unwind the stack and allow us to exit.
+ private final class InterruptRunMessagesException extends RuntimeException {
+ // Empty class
+ }
protected void runMessages() {
- // Here begins deep magic.
- final Looper looper = mLatinIME.mHandler.getLooper();
mLatinIME.mHandler.post(new Runnable() {
@Override
public void run() {
- looper.quit();
+ throw new InterruptRunMessagesException();
}
});
- // The only way to get out of Looper#loop() is to call #quit() on it (or on its queue).
- // Once #quit() is called remaining messages are not processed, which is why we post
- // a message that calls it instead of calling it directly.
- Looper.loop();
-
- // 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 the static ThreadLocal
- // field into which it's stored is private.
- // So... get out the big guns.
- 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) {
- throw new RuntimeException(e);
+ Looper.loop();
+ } catch (InterruptRunMessagesException e) {
+ // Resume normal operation
}
}
diff --git a/tests/src/com/android/inputmethod/latin/StringUtilsTests.java b/tests/src/com/android/inputmethod/latin/StringUtilsTests.java
index b6a05e9fb..136faff71 100644
--- a/tests/src/com/android/inputmethod/latin/StringUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/StringUtilsTests.java
@@ -154,4 +154,83 @@ public class StringUtilsTests extends AndroidTestCase {
assertEquals(StringUtils.CAPITALIZE_NONE,
StringUtils.getCapitalizationType(""));
}
+
+ public void testIsIdenticalAfterUpcaseIsIdenticalAfterDowncase() {
+ assertFalse(StringUtils.isIdenticalAfterUpcase("capitalize"));
+ assertTrue(StringUtils.isIdenticalAfterDowncase("capitalize"));
+ assertFalse(StringUtils.isIdenticalAfterUpcase("cApITalize"));
+ assertFalse(StringUtils.isIdenticalAfterDowncase("cApITalize"));
+ assertFalse(StringUtils.isIdenticalAfterUpcase("capitalizE"));
+ assertFalse(StringUtils.isIdenticalAfterDowncase("capitalizE"));
+ assertFalse(StringUtils.isIdenticalAfterUpcase("__c a piu$@tali56ze"));
+ assertTrue(StringUtils.isIdenticalAfterDowncase("__c a piu$@tali56ze"));
+ assertFalse(StringUtils.isIdenticalAfterUpcase("A__c a piu$@tali56ze"));
+ assertFalse(StringUtils.isIdenticalAfterDowncase("A__c a piu$@tali56ze"));
+ assertFalse(StringUtils.isIdenticalAfterUpcase("Capitalize"));
+ assertFalse(StringUtils.isIdenticalAfterDowncase("Capitalize"));
+ assertFalse(StringUtils.isIdenticalAfterUpcase(" Capitalize"));
+ assertFalse(StringUtils.isIdenticalAfterDowncase(" Capitalize"));
+ assertTrue(StringUtils.isIdenticalAfterUpcase("CAPITALIZE"));
+ assertFalse(StringUtils.isIdenticalAfterDowncase("CAPITALIZE"));
+ assertTrue(StringUtils.isIdenticalAfterUpcase(" PI26LIE"));
+ assertFalse(StringUtils.isIdenticalAfterDowncase(" PI26LIE"));
+ assertTrue(StringUtils.isIdenticalAfterUpcase(""));
+ assertTrue(StringUtils.isIdenticalAfterDowncase(""));
+ }
+
+ private void checkCapitalize(final String src, final String dst, final String separators,
+ final Locale locale) {
+ assertEquals(dst, StringUtils.capitalizeEachWord(src, separators, locale));
+ assert(src.equals(dst)
+ == StringUtils.isIdenticalAfterCapitalizeEachWord(src, separators));
+ }
+
+ public void testCapitalizeEachWord() {
+ checkCapitalize("", "", " ", Locale.ENGLISH);
+ checkCapitalize("test", "Test", " ", Locale.ENGLISH);
+ checkCapitalize(" test", " Test", " ", Locale.ENGLISH);
+ checkCapitalize("Test", "Test", " ", Locale.ENGLISH);
+ checkCapitalize(" Test", " Test", " ", Locale.ENGLISH);
+ checkCapitalize(".Test", ".test", " ", Locale.ENGLISH);
+ checkCapitalize(".Test", ".Test", " .", Locale.ENGLISH);
+ checkCapitalize(".Test", ".Test", ". ", Locale.ENGLISH);
+ checkCapitalize("test and retest", "Test And Retest", " .", Locale.ENGLISH);
+ checkCapitalize("Test and retest", "Test And Retest", " .", Locale.ENGLISH);
+ checkCapitalize("Test And Retest", "Test And Retest", " .", Locale.ENGLISH);
+ checkCapitalize("Test And.Retest ", "Test And.Retest ", " .", Locale.ENGLISH);
+ checkCapitalize("Test And.retest ", "Test And.Retest ", " .", Locale.ENGLISH);
+ checkCapitalize("Test And.retest ", "Test And.retest ", " ", Locale.ENGLISH);
+ checkCapitalize("Test And.Retest ", "Test And.retest ", " ", Locale.ENGLISH);
+ checkCapitalize("test and ietest", "Test And İetest", " .", new Locale("tr"));
+ checkCapitalize("test and ietest", "Test And Ietest", " .", Locale.ENGLISH);
+ checkCapitalize("Test&Retest", "Test&Retest", " \n.!?*()&", Locale.ENGLISH);
+ checkCapitalize("Test&retest", "Test&Retest", " \n.!?*()&", Locale.ENGLISH);
+ checkCapitalize("test&Retest", "Test&Retest", " \n.!?*()&", Locale.ENGLISH);
+ checkCapitalize("rest\nrecreation! And in the end...",
+ "Rest\nRecreation! And In The End...", " \n.!?*,();&", Locale.ENGLISH);
+ checkCapitalize("lorem ipsum dolor sit amet", "Lorem Ipsum Dolor Sit Amet",
+ " \n.,!?*()&;", Locale.ENGLISH);
+ checkCapitalize("Lorem!Ipsum (Dolor) Sit * Amet", "Lorem!Ipsum (Dolor) Sit * Amet",
+ " \n,.;!?*()&", Locale.ENGLISH);
+ checkCapitalize("Lorem!Ipsum (dolor) Sit * Amet", "Lorem!Ipsum (Dolor) Sit * Amet",
+ " \n,.;!?*()&", Locale.ENGLISH);
+ }
+
+ public void testContainsAny() {
+ assertFalse(StringUtils.containsAny("", " "));
+ assertFalse(StringUtils.containsAny("test and retest", ""));
+ assertTrue(StringUtils.containsAny("test and retest", "x3iq o"));
+ assertTrue(StringUtils.containsAny("test and retest", "x3iqo "));
+ assertTrue(StringUtils.containsAny("test and retest", " x3iqo"));
+ assertFalse(StringUtils.containsAny("test and retest", "x3iqo"));
+ assertTrue(StringUtils.containsAny("test and retest", "tse "));
+ assertTrue(StringUtils.containsAny("test and retest.", ".?()"));
+ assertFalse(StringUtils.containsAny("test and retest", ".?()"));
+ // Surrogate pair
+ assertTrue(StringUtils.containsAny("test and \uD861\uDED7 retest.", "\uD861\uDED7"));
+ // Ill-formed string
+ assertFalse(StringUtils.containsAny("test and \uD861 retest.", "\uD861\uDED7"));
+ // Ill-formed string
+ assertFalse(StringUtils.containsAny("test and \uDED7 retest.", "\uD861\uDED7"));
+ }
}