1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package com.anysoftkeyboard.ui.settings.setup;
import android.content.ComponentName;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@RunWith(RobolectricTestRunner.class)
public class SetupSupportTest {
@Test
public void testIsThisKeyboardSetAsDefaultIME() throws Exception {
final String MY_IME_PACKAGE = "net.evendanan.ime";
assertFalse(SetupSupport.isThisKeyboardSetAsDefaultIME(new ComponentName("net.some.one.else", "net.some.one.else.IME").flattenToString(), MY_IME_PACKAGE));
assertFalse(SetupSupport.isThisKeyboardSetAsDefaultIME(new ComponentName("net.some.one.else", "net.some.other.IME").flattenToString(), MY_IME_PACKAGE));
assertFalse(SetupSupport.isThisKeyboardSetAsDefaultIME(new ComponentName("net.some.one.else", ".IME").flattenToString(), MY_IME_PACKAGE));
assertFalse(SetupSupport.isThisKeyboardSetAsDefaultIME(null, MY_IME_PACKAGE));
assertTrue(SetupSupport.isThisKeyboardSetAsDefaultIME(new ComponentName(MY_IME_PACKAGE, MY_IME_PACKAGE + ".IME").flattenToString(), MY_IME_PACKAGE));
assertTrue(SetupSupport.isThisKeyboardSetAsDefaultIME(new ComponentName(MY_IME_PACKAGE, "net.some.other.IME").flattenToString(), MY_IME_PACKAGE));
assertTrue(SetupSupport.isThisKeyboardSetAsDefaultIME(new ComponentName(MY_IME_PACKAGE, ".IME").flattenToString(), MY_IME_PACKAGE));
}
public void testIsThisKeyboardEnabled() throws Exception {
final String MY_IME_PACKAGE = "net.evendanan.ime";
assertFalse(SetupSupport.isThisKeyboardEnabled("", MY_IME_PACKAGE));
//one keyboard
assertFalse(SetupSupport.isThisKeyboardEnabled(new ComponentName("net.some.one.else", "net.some.one.else.IME").flattenToString(), MY_IME_PACKAGE));
assertFalse(SetupSupport.isThisKeyboardEnabled(new ComponentName("net.some.one.else", "net.some.other.IME").flattenToString(), MY_IME_PACKAGE));
assertFalse(SetupSupport.isThisKeyboardEnabled(new ComponentName("net.some.one.else", ".IME").flattenToString(), MY_IME_PACKAGE));
assertFalse(SetupSupport.isThisKeyboardEnabled(null, MY_IME_PACKAGE));
assertTrue(SetupSupport.isThisKeyboardEnabled(new ComponentName(MY_IME_PACKAGE, MY_IME_PACKAGE + ".IME").flattenToString(), MY_IME_PACKAGE));
assertTrue(SetupSupport.isThisKeyboardEnabled(new ComponentName(MY_IME_PACKAGE, "net.some.other.IME").flattenToString(), MY_IME_PACKAGE));
assertTrue(SetupSupport.isThisKeyboardEnabled(new ComponentName(MY_IME_PACKAGE, ".IME").flattenToString(), MY_IME_PACKAGE));
//now, two keyboards
assertFalse(SetupSupport.isThisKeyboardEnabled(
new ComponentName("net.some.one.else", "net.some.one.else.IME").flattenToString() + ":" + new ComponentName("net.some.one.e1", "net.some.one.e1.IME").flattenToString(),
MY_IME_PACKAGE));
assertFalse(SetupSupport.isThisKeyboardEnabled(
new ComponentName("net.some.one.else", "net.some.other.IME").flattenToString() + ":" + new ComponentName("net.some.one.e1", "net.some.one.e1.IME").flattenToString(),
MY_IME_PACKAGE));
assertFalse(SetupSupport.isThisKeyboardEnabled(
new ComponentName("net.some.one.else", ".IME").flattenToString() + ":" + new ComponentName("net.some.one.e1", "net.some.one.e1.IME").flattenToString(),
MY_IME_PACKAGE));
assertTrue(SetupSupport.isThisKeyboardEnabled(
new ComponentName(MY_IME_PACKAGE, MY_IME_PACKAGE + ".IME").flattenToString() + ":" + new ComponentName("net.some.one.e1", "net.some.one.e1.IME").flattenToString(),
MY_IME_PACKAGE));
assertTrue(SetupSupport.isThisKeyboardEnabled(
new ComponentName("net.some.one.e1", "net.some.one.e1.IME").flattenToString() + ":" + new ComponentName(MY_IME_PACKAGE, "net.some.other.IME").flattenToString(),
MY_IME_PACKAGE));
assertTrue(SetupSupport.isThisKeyboardEnabled(
new ComponentName(MY_IME_PACKAGE, ".IME").flattenToString() + ":" + new ComponentName("net.some.one.e1", "net.some.one.e1.IME").flattenToString(),
MY_IME_PACKAGE));
//last test, three
assertFalse(SetupSupport.isThisKeyboardEnabled(
new ComponentName("net.some.one.else", "net.some.one.else.IME").flattenToString() + ":" + new ComponentName("net.some.one.e1", "net.some.one.e1.IME").flattenToString() + ":" + new ComponentName("net.some.one.e2", "net.some.one.e2.IME").flattenToString(),
MY_IME_PACKAGE));
assertTrue(SetupSupport.isThisKeyboardEnabled(
new ComponentName("net.some.one.e2", ".IME").flattenToString() + ":" + new ComponentName(MY_IME_PACKAGE, ".IME").flattenToString() + ":" + new ComponentName("net.some.one.e1", ".IME").flattenToString(),
MY_IME_PACKAGE));
}
}
|