Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3d98b6bb authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka Committed by Android Git Automerger
Browse files

am 88984aed: Split up long unit tests into smaller ones

* commit '88984aed':
  Split up long unit tests into smaller ones
parents 4806a946 88984aed
Loading
Loading
Loading
Loading
+7 −47
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.inputmethod.keyboard;
package com.android.inputmethod.keyboard.action;

import android.content.Context;
import android.content.res.Resources;
@@ -22,6 +22,11 @@ import android.text.InputType;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;

import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.KeyboardLayoutSet;
import com.android.inputmethod.keyboard.KeyboardLayoutSetTestsBase;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyVisual;
import com.android.inputmethod.latin.Constants;
@@ -31,7 +36,7 @@ import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;

import java.util.Locale;

abstract class KeyboardLayoutSetActionLabelBase extends KeyboardLayoutSetTestsBase {
abstract class ActionTestsBase extends KeyboardLayoutSetTestsBase {
    static class ExpectedActionKey {
        static ExpectedActionKey newIconKey(final String iconName) {
            final int iconId = KeyboardIconsSet.getIconId(iconName);
@@ -72,51 +77,6 @@ abstract class KeyboardLayoutSetActionLabelBase extends KeyboardLayoutSetTestsBa
        return LocaleUtils.constructLocaleFromString(localeString);
    }

    public void testActionUnspecified() {
        final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey(
                KeyboardIconsSet.NAME_ENTER_KEY);
        for (final InputMethodSubtype subtype : getAllSubtypesList()) {
            final String tag = "unspecifiled "
                    + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
            doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED, expectedKey);
        }
    }

    public void testActionNone() {
        final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey(
                KeyboardIconsSet.NAME_ENTER_KEY);
        for (final InputMethodSubtype subtype : getAllSubtypesList()) {
            final String tag = "none " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
            doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_NONE, expectedKey);
        }
    }

    public void testActionSearch() {
        final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey(
                KeyboardIconsSet.NAME_SEARCH_KEY);
        for (final InputMethodSubtype subtype : getAllSubtypesList()) {
            final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
            doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_SEARCH, expectedKey);
        }
    }

    public abstract void testActionGo();
    public abstract void testActionSend();
    public abstract void testActionNext();
    public abstract void testActionDone();
    public abstract void testActionPrevious();

    public void testActionCustom() {
        for (final InputMethodSubtype subtype : getAllSubtypesList()) {
            final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
            final EditorInfo editorInfo = new EditorInfo();
            editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED;
            editorInfo.actionLabel = "customLabel";
            final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey("customLabel");
            doTestActionKey(tag, subtype, editorInfo, expectedKey);
        }
    }

    private static void assertActionKey(final String tag, final KeyboardLayoutSet layoutSet,
            final int elementId, final ExpectedActionKey expectedKey) {
        final Keyboard keyboard = layoutSet.getKeyboard(elementId);
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.inputmethod.keyboard.action;

import android.test.suitebuilder.annotation.MediumTest;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;

import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;

@MediumTest
public class KlpActionCustomTests extends KlpActionTestsBase {
    public void testActionCustom() {
        for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) {
            final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
            final EditorInfo editorInfo = new EditorInfo();
            editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED;
            editorInfo.actionLabel = "customLabel";
            final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey("customLabel");
            doTestActionKey(tag, subtype, editorInfo, expectedKey);
        }
    }
}
+36 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.inputmethod.keyboard.action;

import android.test.suitebuilder.annotation.MediumTest;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;

import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;

@MediumTest
public class KlpActionDoneTests extends KlpActionTestsBase {
    public void testActionDone() {
        for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) {
            final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
            final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey(
                    R.string.label_done_key, getLabelLocale(subtype), getContext());
            doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_DONE, expectedKey);
        }
    }
}
+36 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.inputmethod.keyboard.action;

import android.test.suitebuilder.annotation.MediumTest;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;

import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;

@MediumTest
public class KlpActionGoTests extends KlpActionTestsBase {
    public void testActionGo() {
        for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) {
            final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
            final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey(
                    R.string.label_go_key, getLabelLocale(subtype), getContext());
            doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_GO, expectedKey);
        }
    }
}
+4 −82
Original line number Diff line number Diff line
@@ -14,13 +14,14 @@
 * limitations under the License.
 */

package com.android.inputmethod.keyboard;
package com.android.inputmethod.keyboard.action;

import android.content.res.Resources;
import android.test.suitebuilder.annotation.MediumTest;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;

import com.android.inputmethod.keyboard.KeyboardLayoutSet;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.keyboard.internal.KeyboardTextsSet;
import com.android.inputmethod.latin.R;
@@ -28,90 +29,11 @@ import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.utils.RunInLocale;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;

import java.util.ArrayList;
import java.util.Locale;

@MediumTest
public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActionLabelBase {
    // Filter a subtype whose name should be displayed using {@link Locale#ROOT}, such like
    // Hinglish (hi_ZZ) and Serbian-Latn (sr_ZZ).
    static final SubtypeFilter SUBTYPE_FILTER_NAME_IN_BASE_LOCALE = new SubtypeFilter() {
        @Override
        public boolean accept(final InputMethodSubtype subtype) {
            return Locale.ROOT.equals(
                    SubtypeLocaleUtils.getDisplayLocaleOfSubtypeLocale(subtype.getLocale()));
        }
    };

    private ArrayList<InputMethodSubtype> mSubtypesWhoseNameIsDisplayedInItsLocale;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        mSubtypesWhoseNameIsDisplayedInItsLocale = getSubtypesFilteredBy(new SubtypeFilter() {
            @Override
            public boolean accept(final InputMethodSubtype subtype) {
                return !SUBTYPE_FILTER_NAME_IN_BASE_LOCALE.accept(subtype);
            }
        });
    }

    @Override
    protected int getKeyboardThemeForTests() {
        return KeyboardTheme.THEME_ID_KLP;
    }

    @Override
    public void testActionGo() {
        for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) {
            final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
            final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey(
                    R.string.label_go_key, getLabelLocale(subtype), getContext());
            doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_GO, expectedKey);
        }
    }

    @Override
    public void testActionSend() {
        for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) {
            final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
            final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey(
                    R.string.label_send_key, getLabelLocale(subtype), getContext());
            doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_SEND, expectedKey);
        }
    }

    @Override
    public void testActionNext() {
        for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) {
            final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
            final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey(
                    R.string.label_next_key, getLabelLocale(subtype), getContext());
            doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_NEXT, expectedKey);
        }
    }

    @Override
    public void testActionDone() {
        for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) {
            final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
            final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey(
                    R.string.label_done_key, getLabelLocale(subtype), getContext());
            doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_DONE, expectedKey);
        }
    }

    @Override
    public void testActionPrevious() {
        for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) {
            final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype);
            final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey(
                    R.string.label_previous_key, getLabelLocale(subtype), getContext());
            doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, expectedKey);
        }
    }

    private void doTestActionKeys(final InputMethodSubtype subtype, final String tag,
public class KlpActionLabelTests extends KlpActionTestsBase {
    void doTestActionKeys(final InputMethodSubtype subtype, final String tag,
            final ExpectedActionKey unspecifiedKey, final ExpectedActionKey noneKey,
            final ExpectedActionKey goKey, final ExpectedActionKey searchKey,
            final ExpectedActionKey sendKey, final ExpectedActionKey nextKey,
Loading