Make unit test independent from test device locale

Bug: 9112465
Change-Id: I4fe39bebf130799397485dbe6d23199a29a8641e
This commit is contained in:
Tadashi G. Takaoka 2013-05-24 12:23:55 -07:00
parent dbed20ad8d
commit 8586a43424
2 changed files with 29 additions and 7 deletions

View file

@ -17,10 +17,13 @@
package com.android.inputmethod.keyboard.internal;
import android.app.Instrumentation;
import android.content.Context;
import android.content.res.Resources;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.MediumTest;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
import java.lang.reflect.Field;
import java.util.ArrayList;
@ -29,15 +32,23 @@ import java.util.Locale;
@MediumTest
public class KeySpecParserSplitTests extends InstrumentationTestCase {
private final KeyboardTextsSet mTextsSet = new KeyboardTextsSet();
private static final Locale TEST_LOCALE = Locale.ENGLISH;
final KeyboardTextsSet mTextsSet = new KeyboardTextsSet();
@Override
protected void setUp() throws Exception {
super.setUp();
final Instrumentation instrumentation = getInstrumentation();
mTextsSet.setLanguage(Locale.ENGLISH.getLanguage());
mTextsSet.loadStringResources(instrumentation.getTargetContext());
final Context targetContext = instrumentation.getTargetContext();
mTextsSet.setLanguage(TEST_LOCALE.getLanguage());
new RunInLocale<Void>() {
@Override
protected Void job(final Resources res) {
mTextsSet.loadStringResources(targetContext);
return null;
}
}.runInLocale(targetContext.getResources(), TEST_LOCALE);
final String[] testResourceNames = getAllResourceIdNames(
com.android.inputmethod.latin.tests.R.string.class);
mTextsSet.loadStringResourcesInternal(instrumentation.getContext(),

View file

@ -20,18 +20,22 @@ import static com.android.inputmethod.keyboard.internal.KeyboardIconsSet.ICON_UN
import static com.android.inputmethod.latin.Constants.CODE_OUTPUT_TEXT;
import static com.android.inputmethod.latin.Constants.CODE_UNSPECIFIED;
import android.content.Context;
import android.content.res.Resources;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
import java.util.Arrays;
import java.util.Locale;
@SmallTest
public class KeySpecParserTests extends AndroidTestCase {
private final KeyboardCodesSet mCodesSet = new KeyboardCodesSet();
private final KeyboardTextsSet mTextsSet = new KeyboardTextsSet();
private final static Locale TEST_LOCALE = Locale.ENGLISH;
final KeyboardCodesSet mCodesSet = new KeyboardCodesSet();
final KeyboardTextsSet mTextsSet = new KeyboardTextsSet();
private static final String CODE_SETTINGS = "!code/key_settings";
private static final String ICON_SETTINGS = "!icon/settings_key";
@ -48,10 +52,17 @@ public class KeySpecParserTests extends AndroidTestCase {
protected void setUp() throws Exception {
super.setUp();
final String language = Locale.ENGLISH.getLanguage();
final String language = TEST_LOCALE.getLanguage();
mCodesSet.setLanguage(language);
mTextsSet.setLanguage(language);
mTextsSet.loadStringResources(getContext());
final Context context = getContext();
new RunInLocale<Void>() {
@Override
protected Void job(final Resources res) {
mTextsSet.loadStringResources(context);
return null;
}
}.runInLocale(context.getResources(), TEST_LOCALE);
mCodeSettings = KeySpecParser.parseCode(
CODE_SETTINGS, mCodesSet, CODE_UNSPECIFIED);