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

Commit 6f4eba81 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Add test entry for BinaryDictionary class

Bug: 3414081
Change-Id: I1a3d60698795bf28c477086838e726d498fb6de0
parent 654db88d
Loading
Loading
Loading
Loading
+27 −19
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.inputmethod.latin;

import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.ProximityInfo;

@@ -93,8 +94,7 @@ public class BinaryDictionary extends Dictionary {
        return sInstance;
    }

    // For unit test
    /* package */ static BinaryDictionary initDictionary(File dictionary, long startOffset,
    /* package for test */ static BinaryDictionary initDictionary(File dictionary, long startOffset,
            long length, int dicTypeId) {
        synchronized (sInstance) {
            sInstance.closeInternal();
@@ -166,11 +166,32 @@ public class BinaryDictionary extends Dictionary {

    @Override
    public void getWords(final WordComposer codes, final WordCallback callback) {
        if (mNativeDict == 0) return;
        final int count = getSuggestions(codes, mKeyboardSwitcher.getLatinKeyboard());

        for (int j = 0; j < count; ++j) {
            if (mFrequencies[j] < 1) break;
            final int start = j * MAX_WORD_LENGTH;
            int len = 0;
            while (len < MAX_WORD_LENGTH && mOutputChars[start + len] != 0) {
                ++len;
            }
            if (len > 0) {
                callback.addWord(mOutputChars, start, len, mFrequencies[j], mDicTypeId,
                        DataType.UNIGRAM);
            }
        }
    }

    /* package for test */ boolean isValidDictionary() {
        return mNativeDict != 0;
    }

    /* package for test */ int getSuggestions(final WordComposer codes, final Keyboard keyboard) {
        if (!isValidDictionary()) return -1;

        final int codesSize = codes.size();
        // Won't deal with really long words.
        if (codesSize > MAX_WORD_LENGTH - 1) return;
        if (codesSize > MAX_WORD_LENGTH - 1) return -1;

        Arrays.fill(mInputCodes, WordComposer.NOT_A_CODE);
        for (int i = 0; i < codesSize; i++) {
@@ -181,23 +202,10 @@ public class BinaryDictionary extends Dictionary {
        Arrays.fill(mOutputChars, (char) 0);
        Arrays.fill(mFrequencies, 0);

        int count = getSuggestionsNative(
                mNativeDict, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo(),
        return getSuggestionsNative(
                mNativeDict, keyboard.getProximityInfo(),
                codes.getXCoordinates(), codes.getYCoordinates(), mInputCodes, codesSize,
                mOutputChars, mFrequencies);

        for (int j = 0; j < count; ++j) {
            if (mFrequencies[j] < 1) break;
            final int start = j * MAX_WORD_LENGTH;
            int len = 0;
            while (len < MAX_WORD_LENGTH && mOutputChars[start + len] != 0) {
                ++len;
            }
            if (len > 0) {
                callback.addWord(mOutputChars, start, len, mFrequencies[j], mDicTypeId,
                        DataType.UNIGRAM);
            }
        }
    }

    @Override