Migrate to Android Testing Support Lib (part 4/N)

This CL converts 7 test classes under com.android.inputmethod.keyboard
to Android Testing Support Library.

This CL also fix missing annotations in KeyboardLayoutTest.

Bug: 110805255
Test: verified as follows. No new test failures.
        tapas adb LatinIME LatinIMETests arm64 userdebug && \
        DISABLE_PROGUARD=true make -j LatinIME && \
        adb install -r $OUT/system/app/LatinIME/LatinIME.apk && \
        atest LatinIMETests:com.android.inputmethod.keyboard
Change-Id: I8ab9e3329f159f0df02812fafe44c25efa76c0d1
main
Yohei Yukawa 2018-07-06 10:09:43 -07:00
parent bba9005cb4
commit a497886dda
8 changed files with 206 additions and 115 deletions

View File

@ -18,15 +18,17 @@ package com.android.inputmethod.keyboard;
import static org.junit.Assert.assertEquals;
import android.test.suitebuilder.annotation.SmallTest;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import java.util.ArrayList;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest
@RunWith(AndroidJUnit4.class)
public class KeyboardLayoutTest {
@Test
public void testNewKeyboardLayout() {
KeyboardLayout keyboardLayout = KeyboardLayout

View File

@ -16,22 +16,34 @@
package com.android.inputmethod.keyboard;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static com.android.inputmethod.keyboard.KeyboardTheme.THEME_ID_ICS;
import static com.android.inputmethod.keyboard.KeyboardTheme.THEME_ID_KLP;
import static com.android.inputmethod.keyboard.KeyboardTheme.THEME_ID_LXX_DARK;
import static com.android.inputmethod.keyboard.KeyboardTheme.THEME_ID_LXX_LIGHT;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.preference.PreferenceManager;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest
public class KeyboardThemeTests extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class KeyboardThemeTests {
private SharedPreferences mPrefs;
private static final int THEME_ID_NULL = -1;
@ -39,9 +51,12 @@ public class KeyboardThemeTests extends AndroidTestCase {
private static final int THEME_ID_ILLEGAL = -3;
private static final String ILLEGAL_THEME_ID_STRING = "ThisCausesNumberFormatExecption";
@Override
protected void setUp() throws Exception {
super.setUp();
private Context getContext() {
return InstrumentationRegistry.getTargetContext();
}
@Before
public void setUp() throws Exception {
mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
}
@ -110,6 +125,7 @@ public class KeyboardThemeTests extends AndroidTestCase {
assertKeyboardThemePreference(sdkVersion, THEME_ID_ILLEGAL, defaultThemeId);
}
@Test
public void testKeyboardThemePreferenceOnKlp() {
assertKeyboardThemePreferenceOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH);
assertKeyboardThemePreferenceOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
@ -130,6 +146,7 @@ public class KeyboardThemeTests extends AndroidTestCase {
assertKeyboardThemePreference(sdkVersion, THEME_ID_ILLEGAL, defaultThemeId);
}
@Test
public void testKeyboardThemePreferenceOnLxx() {
assertKeyboardThemePreferenceOnLxx(Build.VERSION_CODES.LOLLIPOP);
}
@ -165,6 +182,7 @@ public class KeyboardThemeTests extends AndroidTestCase {
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ILLEGAL, THEME_ID_KLP);
}
@Test
public void testDefaultKeyboardThemeOnKlp() {
assertDefaultKeyboardThemeOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH);
assertDefaultKeyboardThemeOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
@ -183,6 +201,7 @@ public class KeyboardThemeTests extends AndroidTestCase {
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX_LIGHT);
}
@Test
public void testDefaultKeyboardThemeOnLxx() {
assertDefaultKeyboardThemeOnLxx(Build.VERSION_CODES.LOLLIPOP);
}
@ -231,6 +250,7 @@ public class KeyboardThemeTests extends AndroidTestCase {
}
// Upgrading keyboard on I,J and K.
@Test
public void testUpgradeKeyboardToLxxOnKlp() {
assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH);
assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
@ -250,6 +270,7 @@ public class KeyboardThemeTests extends AndroidTestCase {
}
// Upgrading keyboard on L.
@Test
public void testUpgradeKeyboardToLxxOnLxx() {
assertUpgradeKeyboardToLxxOnLxx(Build.VERSION_CODES.LOLLIPOP);
}
@ -293,6 +314,7 @@ public class KeyboardThemeTests extends AndroidTestCase {
}
// Update platform from I,J, and K to I,J, and K
@Test
public void testUpgradePlatformToKlpFromKlp() {
assertUpgradePlatformToKlpFrom(VERSION_CODES.ICE_CREAM_SANDWICH);
assertUpgradePlatformToKlpFrom(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
@ -318,6 +340,7 @@ public class KeyboardThemeTests extends AndroidTestCase {
}
// Update platform from I,J, and K to L
@Test
public void testUpgradePlatformToLxx() {
assertUpgradePlatformToLxxFrom(VERSION_CODES.ICE_CREAM_SANDWICH);
assertUpgradePlatformToLxxFrom(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
@ -328,6 +351,7 @@ public class KeyboardThemeTests extends AndroidTestCase {
}
// Update platform from L to L.
@Test
public void testUpgradePlatformToLxxFromLxx() {
final int oldSdkVersion = Build.VERSION_CODES.LOLLIPOP;
final int newSdkVersion = Build.VERSION_CODES.LOLLIPOP;
@ -364,10 +388,12 @@ public class KeyboardThemeTests extends AndroidTestCase {
}
}
@Test
public void testSortedKeyboardTheme() {
assertSortedKeyboardThemeArray(KeyboardTheme.KEYBOARD_THEMES);
}
@Test
public void testSortedAvailableKeyboardTheme() {
assertSortedKeyboardThemeArray(KeyboardTheme.getAvailableThemeArray(getContext()));
}
@ -384,6 +410,7 @@ public class KeyboardThemeTests extends AndroidTestCase {
assertSortedKeyboardThemeArray(LIMITED_THEMES);
}
@Test
public void testMissingSelectedThemeIcs() {
// Clean up preferences.
setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL);
@ -399,6 +426,7 @@ public class KeyboardThemeTests extends AndroidTestCase {
assertEquals(THEME_ID_KLP, actualTheme.mThemeId);
}
@Test
public void testMissingSelectedThemeKlp() {
// Clean up preferences.
setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL);
@ -414,6 +442,7 @@ public class KeyboardThemeTests extends AndroidTestCase {
assertEquals(THEME_ID_KLP, actualTheme.mThemeId);
}
@Test
public void testMissingSelectedThemeLxx() {
// Clean up preferences.
setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL);

View File

@ -16,25 +16,20 @@
package com.android.inputmethod.keyboard.internal;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import static org.junit.Assert.assertEquals;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest
public class HermiteInterpolatorTests extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class HermiteInterpolatorTests {
private final HermiteInterpolator mInterpolator = new HermiteInterpolator();
@Override
protected void setUp() throws Exception {
super.setUp();
}
private static final float EPSLION = 0.0000005f;
private static void assertFloatEquals(final String message, float expected, float actual) {
if (Math.abs(expected - actual) >= EPSLION) {
fail(String.format("%s expected:<%s> but was:<%s>", message, expected, actual));
}
}
private static final float EPSILON = 0.0000005f;
// t=0 p0=(0,1)
// t=1 p1=(1,0)
@ -57,6 +52,7 @@ public class HermiteInterpolatorTests extends AndroidTestCase {
private static final int p2 = 2;
private static final int p3 = 3;
@Test
public void testP0P1() {
// [(p0 p1) p2 p3]
mInterpolator.reset(mXCoords, mYCoords, p0, p3 + 1);
@ -66,33 +62,34 @@ public class HermiteInterpolatorTests extends AndroidTestCase {
assertEquals("p1x", mXCoords[p1], mInterpolator.mP2X);
assertEquals("p1y", mYCoords[p1], mInterpolator.mP2Y);
// XY-slope at p0=3.0 (-0.75/-0.25)
assertFloatEquals("slope x p0", -0.25f, mInterpolator.mSlope1X);
assertFloatEquals("slope y p0", -0.75f, mInterpolator.mSlope1Y);
assertEquals("slope x p0", -0.25f, mInterpolator.mSlope1X, EPSILON);
assertEquals("slope y p0", -0.75f, mInterpolator.mSlope1Y, EPSILON);
// XY-slope at p1=1/3.0 (0.50/1.50)
assertFloatEquals("slope x p1", 1.50f, mInterpolator.mSlope2X);
assertFloatEquals("slope y p1", 0.50f, mInterpolator.mSlope2Y);
assertEquals("slope x p1", 1.50f, mInterpolator.mSlope2X, EPSILON);
assertEquals("slope y p1", 0.50f, mInterpolator.mSlope2Y, EPSILON);
// t=0.0 (p0)
mInterpolator.interpolate(0.0f);
assertFloatEquals("t=0.0 x", 0.0f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=0.0 y", 1.0f, mInterpolator.mInterpolatedY);
assertEquals("t=0.0 x", 0.0f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=0.0 y", 1.0f, mInterpolator.mInterpolatedY, EPSILON);
// t=0.2
mInterpolator.interpolate(0.2f);
assertFloatEquals("t=0.2 x", 0.02400f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=0.2 y", 0.78400f, mInterpolator.mInterpolatedY);
assertEquals("t=0.2 x", 0.02400f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=0.2 y", 0.78400f, mInterpolator.mInterpolatedY, EPSILON);
// t=0.5
mInterpolator.interpolate(0.5f);
assertFloatEquals("t=0.5 x", 0.28125f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=0.5 y", 0.34375f, mInterpolator.mInterpolatedY);
assertEquals("t=0.5 x", 0.28125f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=0.5 y", 0.34375f, mInterpolator.mInterpolatedY, EPSILON);
// t=0.8
mInterpolator.interpolate(0.8f);
assertFloatEquals("t=0.8 x", 0.69600f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=0.8 y", 0.01600f, mInterpolator.mInterpolatedY);
assertEquals("t=0.8 x", 0.69600f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=0.8 y", 0.01600f, mInterpolator.mInterpolatedY, EPSILON);
// t=1.0 (p1)
mInterpolator.interpolate(1.0f);
assertFloatEquals("t=1.0 x", 1.0f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=1.0 y", 0.0f, mInterpolator.mInterpolatedY);
assertEquals("t=1.0 x", 1.0f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=1.0 y", 0.0f, mInterpolator.mInterpolatedY, EPSILON);
}
@Test
public void testP1P2() {
// [p0 (p1 p2) p3]
mInterpolator.reset(mXCoords, mYCoords, p0, p3 + 1);
@ -102,33 +99,34 @@ public class HermiteInterpolatorTests extends AndroidTestCase {
assertEquals("p2x", mXCoords[p2], mInterpolator.mP2X);
assertEquals("p2y", mYCoords[p2], mInterpolator.mP2Y);
// XY-slope at p1=1/3.0 (0.50/1.50)
assertFloatEquals("slope x p1", 1.50f, mInterpolator.mSlope1X);
assertFloatEquals("slope y p1", 0.50f, mInterpolator.mSlope1Y);
assertEquals("slope x p1", 1.50f, mInterpolator.mSlope1X, EPSILON);
assertEquals("slope y p1", 0.50f, mInterpolator.mSlope1Y, EPSILON);
// XY-slope at p2=3.0 (1.50/0.50)
assertFloatEquals("slope x p2", 0.50f, mInterpolator.mSlope2X);
assertFloatEquals("slope y p2", 1.50f, mInterpolator.mSlope2Y);
assertEquals("slope x p2", 0.50f, mInterpolator.mSlope2X, EPSILON);
assertEquals("slope y p2", 1.50f, mInterpolator.mSlope2Y, EPSILON);
// t=0.0 (p1)
mInterpolator.interpolate(0.0f);
assertFloatEquals("t=0.0 x", 1.0f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=0.0 y", 0.0f, mInterpolator.mInterpolatedY);
assertEquals("t=0.0 x", 1.0f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=0.0 y", 0.0f, mInterpolator.mInterpolatedY, EPSILON);
// t=0.2
mInterpolator.interpolate(0.2f);
assertFloatEquals("t=0.2 x", 1.384f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=0.2 y", 0.224f, mInterpolator.mInterpolatedY);
assertEquals("t=0.2 x", 1.384f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=0.2 y", 0.224f, mInterpolator.mInterpolatedY, EPSILON);
// t=0.5
mInterpolator.interpolate(0.5f);
assertFloatEquals("t=0.5 x", 2.125f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=0.5 y", 0.875f, mInterpolator.mInterpolatedY);
assertEquals("t=0.5 x", 2.125f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=0.5 y", 0.875f, mInterpolator.mInterpolatedY, EPSILON);
// t=0.8
mInterpolator.interpolate(0.8f);
assertFloatEquals("t=0.8 x", 2.776f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=0.8 y", 1.616f, mInterpolator.mInterpolatedY);
assertEquals("t=0.8 x", 2.776f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=0.8 y", 1.616f, mInterpolator.mInterpolatedY, EPSILON);
// t=1.0 (p2)
mInterpolator.interpolate(1.0f);
assertFloatEquals("t=1.0 x", 3.0f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=1.0 y", 2.0f, mInterpolator.mInterpolatedY);
assertEquals("t=1.0 x", 3.0f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=1.0 y", 2.0f, mInterpolator.mInterpolatedY, EPSILON);
}
@Test
public void testP2P3() {
// [p0 p1 (p2 p3)]
mInterpolator.reset(mXCoords, mYCoords, p0, p3 + 1);
@ -138,33 +136,34 @@ public class HermiteInterpolatorTests extends AndroidTestCase {
assertEquals("p3x", mXCoords[p3], mInterpolator.mP2X);
assertEquals("p3y", mYCoords[p3], mInterpolator.mP2Y);
// XY-slope at p2=3.0 (1.50/0.50)
assertFloatEquals("slope x p2", 0.50f, mInterpolator.mSlope1X);
assertFloatEquals("slope y p2", 1.50f, mInterpolator.mSlope1Y);
assertEquals("slope x p2", 0.50f, mInterpolator.mSlope1X, EPSILON);
assertEquals("slope y p2", 1.50f, mInterpolator.mSlope1Y, EPSILON);
// XY-slope at p3=1/3.0 (-0.25/-0.75)
assertFloatEquals("slope x p3", -0.75f, mInterpolator.mSlope2X);
assertFloatEquals("slope y p3", -0.25f, mInterpolator.mSlope2Y);
assertEquals("slope x p3", -0.75f, mInterpolator.mSlope2X, EPSILON);
assertEquals("slope y p3", -0.25f, mInterpolator.mSlope2Y, EPSILON);
// t=0.0 (p2)
mInterpolator.interpolate(0.0f);
assertFloatEquals("t=0.0 x", 3.0f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=0.0 y", 2.0f, mInterpolator.mInterpolatedY);
assertEquals("t=0.0 x", 3.0f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=0.0 y", 2.0f, mInterpolator.mInterpolatedY, EPSILON);
// t=0.2
mInterpolator.interpolate(0.2f);
assertFloatEquals("t=0.2 x", 2.98400f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=0.2 y", 2.30400f, mInterpolator.mInterpolatedY);
assertEquals("t=0.2 x", 2.98400f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=0.2 y", 2.30400f, mInterpolator.mInterpolatedY, EPSILON);
// t=0.5
mInterpolator.interpolate(0.5f);
assertFloatEquals("t=0.5 x", 2.65625f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=0.5 y", 2.71875f, mInterpolator.mInterpolatedY);
assertEquals("t=0.5 x", 2.65625f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=0.5 y", 2.71875f, mInterpolator.mInterpolatedY, EPSILON);
// t=0.8
mInterpolator.interpolate(0.8f);
assertFloatEquals("t=0.8 x", 2.21600f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=0.8 y", 2.97600f, mInterpolator.mInterpolatedY);
assertEquals("t=0.8 x", 2.21600f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=0.8 y", 2.97600f, mInterpolator.mInterpolatedY, EPSILON);
// t=1.0 (p3)
mInterpolator.interpolate(1.0f);
assertFloatEquals("t=1.0 x", 2.0f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=1.0 y", 3.0f, mInterpolator.mInterpolatedY);
assertEquals("t=1.0 x", 2.0f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=1.0 y", 3.0f, mInterpolator.mInterpolatedY, EPSILON);
}
@Test
public void testJustP1P2() {
// [(p1 p2)]
mInterpolator.reset(mXCoords, mYCoords, p1, p2 + 1);
@ -174,30 +173,30 @@ public class HermiteInterpolatorTests extends AndroidTestCase {
assertEquals("p2x", mXCoords[p2], mInterpolator.mP2X);
assertEquals("p2y", mYCoords[p2], mInterpolator.mP2Y);
// XY-slope at p1=1.0 (2.0/2.0)
assertFloatEquals("slope x p1", 2.00f, mInterpolator.mSlope1X);
assertFloatEquals("slope y p1", 2.00f, mInterpolator.mSlope1Y);
assertEquals("slope x p1", 2.00f, mInterpolator.mSlope1X, EPSILON);
assertEquals("slope y p1", 2.00f, mInterpolator.mSlope1Y, EPSILON);
// XY-slope at p2=1.0 (2.0/2.0)
assertFloatEquals("slope x p2", 2.00f, mInterpolator.mSlope2X);
assertFloatEquals("slope y p2", 2.00f, mInterpolator.mSlope2Y);
assertEquals("slope x p2", 2.00f, mInterpolator.mSlope2X, EPSILON);
assertEquals("slope y p2", 2.00f, mInterpolator.mSlope2Y, EPSILON);
// t=0.0 (p1)
mInterpolator.interpolate(0.0f);
assertFloatEquals("t=0.0 x", 1.0f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=0.0 y", 0.0f, mInterpolator.mInterpolatedY);
assertEquals("t=0.0 x", 1.0f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=0.0 y", 0.0f, mInterpolator.mInterpolatedY, EPSILON);
// t=0.2
mInterpolator.interpolate(0.2f);
assertFloatEquals("t=0.2 x", 1.4f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=0.2 y", 0.4f, mInterpolator.mInterpolatedY);
assertEquals("t=0.2 x", 1.4f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=0.2 y", 0.4f, mInterpolator.mInterpolatedY, EPSILON);
// t=0.5
mInterpolator.interpolate(0.5f);
assertFloatEquals("t=0.5 x", 2.0f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=0.5 y", 1.0f, mInterpolator.mInterpolatedY);
assertEquals("t=0.5 x", 2.0f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=0.5 y", 1.0f, mInterpolator.mInterpolatedY, EPSILON);
// t=0.8
mInterpolator.interpolate(0.8f);
assertFloatEquals("t=0.8 x", 2.6f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=0.8 y", 1.6f, mInterpolator.mInterpolatedY);
assertEquals("t=0.8 x", 2.6f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=0.8 y", 1.6f, mInterpolator.mInterpolatedY, EPSILON);
// t=1.0 (p2)
mInterpolator.interpolate(1.0f);
assertFloatEquals("t=1.0 x", 3.0f, mInterpolator.mInterpolatedX);
assertFloatEquals("t=1.0 y", 2.0f, mInterpolator.mInterpolatedY);
assertEquals("t=1.0 x", 3.0f, mInterpolator.mInterpolatedX, EPSILON);
assertEquals("t=1.0 y", 2.0f, mInterpolator.mInterpolatedY, EPSILON);
}
}

View File

@ -16,9 +16,14 @@
package com.android.inputmethod.keyboard.internal;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import android.content.Context;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
@ -30,14 +35,22 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest
public final class KeyboardTextsSetTests extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public final class KeyboardTextsSetTests {
// All input method subtypes of LatinIME.
private List<InputMethodSubtype> mAllSubtypesList;
@Override
protected void setUp() throws Exception {
super.setUp();
private Context getContext() {
return InstrumentationRegistry.getTargetContext();
}
@Before
public void setUp() throws Exception {
RichInputMethodManager.init(getContext());
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
@ -54,6 +67,7 @@ public final class KeyboardTextsSetTests extends AndroidTestCase {
// Test that the text {@link KeyboardTextsSet#SWITCH_TO_ALPHA_KEY_LABEL} exists for all
// subtypes. The text is needed to implement Emoji Keyboard, see
// {@link KeyboardSwitcher#setEmojiKeyboard()}.
@Test
public void testSwitchToAlphaKeyLabel() {
final Context context = getContext();
final KeyboardTextsSet textsSet = new KeyboardTextsSet();
@ -80,6 +94,7 @@ public final class KeyboardTextsSetTests extends AndroidTestCase {
};
// Test that the text from resources are correctly loaded for all subtypes.
@Test
public void testTextFromResources() {
final Context context = getContext();
final KeyboardTextsSet textsSet = new KeyboardTextsSet();

View File

@ -16,25 +16,26 @@
package com.android.inputmethod.keyboard.internal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import com.android.inputmethod.keyboard.internal.MatrixUtils.MatrixOperationFailedException;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest
public class MatrixUtilsTests extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class MatrixUtilsTests {
// "run tests" -c com.android.inputmethod.keyboard.internal.MatrixUtilsTests
private static final boolean DEBUG = false;
private static final float EPSILON = 0.00001f;
private static void assertEqualsFloat(float f0, float f1) {
assertEqualsFloat(f0, f1, EPSILON);
}
/* package */ static void assertEqualsFloat(float f0, float f1, float error) {
assertTrue(Math.abs(f0 - f1) < error);
}
@Test
public void testMulti() {
final float[][] matrixA = {{1, 2}, {3, 4}};
final float[][] matrixB = {{5, 6}, {7, 8}};
@ -47,12 +48,13 @@ public class MatrixUtilsTests extends AndroidTestCase {
if (DEBUG) {
MatrixUtils.dump("multi", retval);
}
assertEqualsFloat(retval[0][0], 19);
assertEqualsFloat(retval[0][1], 22);
assertEqualsFloat(retval[1][0], 43);
assertEqualsFloat(retval[1][1], 50);
assertEquals(retval[0][0], 19, EPSILON);
assertEquals(retval[0][1], 22, EPSILON);
assertEquals(retval[1][0], 43, EPSILON);
assertEquals(retval[1][1], 50, EPSILON);
}
@Test
public void testInverse() {
final int N = 4;
final float[][] matrix =
@ -77,7 +79,7 @@ public class MatrixUtilsTests extends AndroidTestCase {
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
assertEqualsFloat(((i == j) ? 1.0f : 0.0f), retval[i][j]);
assertEquals(((i == j) ? 1.0f : 0.0f), retval[i][j], EPSILON);
}
}
}

View File

@ -16,26 +16,33 @@
package com.android.inputmethod.keyboard.internal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import android.content.Context;
import android.content.res.Resources;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import com.android.inputmethod.latin.R;
import java.util.Arrays;
import java.util.Locale;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest
public class MoreKeySpecSplitTests extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class MoreKeySpecSplitTests {
private static final Locale TEST_LOCALE = Locale.ENGLISH;
private final KeyboardTextsSet mTextsSet = new KeyboardTextsSet();
@Override
protected void setUp() throws Exception {
super.setUp();
final Context targetContext = getContext();
@Before
public void setUp() throws Exception {
final Context targetContext = InstrumentationRegistry.getTargetContext();
final Resources targetRes = targetContext.getResources();
final String targetPackageName = targetRes.getResourcePackageName(
R.string.english_ime_name);
@ -90,6 +97,7 @@ public class MoreKeySpecSplitTests extends AndroidTestCase {
private static final String SURROGATE1 = PAIR1 + PAIR2;
private static final String SURROGATE2 = PAIR1 + PAIR2 + PAIR3;
@Test
public void testSplitZero() {
assertTextArray("Empty string", "");
assertTextArray("Empty entry", ",");
@ -99,6 +107,7 @@ public class MoreKeySpecSplitTests extends AndroidTestCase {
assertTextArray("Empty entries with escape", ",a,b\\,c,,d,", "a", "b\\,c", "d");
}
@Test
public void testSplitSingle() {
assertTextArray("Single char", "a", "a");
assertTextArray("Surrogate pair", PAIR1, PAIR1);
@ -128,6 +137,7 @@ public class MoreKeySpecSplitTests extends AndroidTestCase {
assertTextArray("Incomplete resource reference 4", "!" + SURROGATE2, "!" + SURROGATE2);
}
@Test
public void testSplitSingleEscaped() {
assertTextArray("Escaped char", "\\a", "\\a");
assertTextArray("Escaped surrogate pair", "\\" + PAIR1, "\\" + PAIR1);
@ -163,6 +173,7 @@ public class MoreKeySpecSplitTests extends AndroidTestCase {
assertTextArray("Escaped !TEXT/NAME", "\\!TEXT/EMPTY_STRING", "\\!TEXT/EMPTY_STRING");
}
@Test
public void testSplitMulti() {
assertTextArray("Multiple chars", "a,b,c", "a", "b", "c");
assertTextArray("Multiple chars", "a,b,\\c", "a", "b", "\\c");
@ -178,6 +189,7 @@ public class MoreKeySpecSplitTests extends AndroidTestCase {
" abc ", " def ", " ghi ");
}
@Test
public void testSplitMultiEscaped() {
assertTextArray("Multiple chars with comma", "a,\\,,c", "a", "\\,", "c");
assertTextArray("Multiple chars with comma surrounded by spaces", " a , \\, , c ",
@ -197,16 +209,19 @@ public class MoreKeySpecSplitTests extends AndroidTestCase {
"\\!", "\\!TEXT/EMPTY_STRING");
}
@Test
public void testSplitTextReferenceError() {
assertError("Incomplete text name", "!text/", "!text/");
assertError("Non existing text", "!text/non_existing");
}
@Test
public void testSplitEmptyTextReference() {
// Note that morekeys_q of English locale is empty.
assertTextArray("Empty string", "!text/morekeys_q");
}
@Test
public void testLabelReferece() {
assertTextArray("Label time am", "!text/keylabel_time_am", "AM");
@ -217,6 +232,7 @@ public class MoreKeySpecSplitTests extends AndroidTestCase {
"!icon/settings_key|!code/key_settings");
}
@Test
public void testUselessUpperCaseSpecifier() {
assertTextArray("EMPTY STRING",
"!TEXT/EMPTY_STRING", "!TEXT/EMPTY_STRING");

View File

@ -16,11 +16,19 @@
package com.android.inputmethod.keyboard.internal;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest
public class PointerTrackerQueueTests extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class PointerTrackerQueueTests {
public static class Element implements PointerTrackerQueue.Element {
public static int sPhantomUpCount;
public static final long NOT_HAPPENED = -1;
@ -65,11 +73,13 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
private final Element mElement4 = new Element(4);
private final PointerTrackerQueue mQueue = new PointerTrackerQueue();
@Test
public void testEmpty() {
assertEquals(0, mQueue.size());
assertEquals("[]", mQueue.toString());
}
@Test
public void testAdd() {
mQueue.add(mElement1);
assertEquals(1, mQueue.size());
@ -85,6 +95,7 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
assertEquals("[1 2 3 4]", mQueue.toString());
}
@Test
public void testRemove() {
Element.sPhantomUpCount = 0;
@ -119,6 +130,7 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
}
@Test
public void testAddAndRemove() {
Element.sPhantomUpCount = 0;
@ -158,6 +170,7 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
}
@Test
public void testReleaseAllPointers() {
mElement2.mIsModifier = true;
mQueue.add(mElement1);
@ -177,6 +190,7 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
assertEquals(eventTime + 4, mElement4.mPhantomUpEventTime);
}
@Test
public void testReleaseAllPointersOlderThanFirst() {
mElement2.mIsModifier = true;
mQueue.add(mElement1);
@ -194,6 +208,7 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
assertEquals(Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime);
}
@Test
public void testReleaseAllPointersOlderThanLast() {
mElement2.mIsModifier = true;
mQueue.add(mElement1);
@ -213,6 +228,7 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
}
@Test
public void testReleaseAllPointersOlderThanWithoutModifierMiddle() {
mQueue.add(mElement1);
mQueue.add(mElement2);
@ -231,6 +247,7 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
}
@Test
public void testReleaseAllPointersOlderThanWithoutModifierLast() {
mQueue.add(mElement1);
mQueue.add(mElement2);
@ -249,6 +266,7 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
}
@Test
public void testReleaseAllPointersExcept() {
mElement2.mIsModifier = true;
mQueue.add(mElement1);
@ -268,6 +286,7 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
assertEquals(eventTime + 3, mElement4.mPhantomUpEventTime);
}
@Test
public void testHasModifierKeyOlderThan() {
Element.sPhantomUpCount = 0;
assertFalse("hasModifierKeyOlderThan empty", mQueue.hasModifierKeyOlderThan(mElement1));
@ -297,6 +316,7 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
}
@Test
public void testIsAnyInDraggingFinger() {
Element.sPhantomUpCount = 0;
assertFalse(mQueue.isAnyInDraggingFinger());

View File

@ -16,16 +16,24 @@
package com.android.inputmethod.keyboard.internal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import com.android.inputmethod.keyboard.internal.MatrixUtils.MatrixOperationFailedException;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest
public class SmoothingUtilsTests extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class SmoothingUtilsTests {
// "run tests" -c com.android.inputmethod.keyboard.internal.SmoothingUtilsTests
private static final boolean DEBUG = false;
@Test
public void testGet3DParamaters() {
final float[] xs = new float[] {0, 1, 2, 3, 4};
final float[] ys = new float[] {1, 4, 15, 40, 85}; // y = x^3 + x^2 + x + 1
@ -36,7 +44,7 @@ public class SmoothingUtilsTests extends AndroidTestCase {
MatrixUtils.dump("3d", retval);
}
for (int i = 0; i < 4; ++i) {
MatrixUtilsTests.assertEqualsFloat(retval[i][0], 1.0f, 0.001f);
assertEquals(retval[i][0], 1.0f, 0.001f);
}
} catch (MatrixOperationFailedException e) {
assertTrue(false);