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

Commit 81754949 authored by Narayan Kamath's avatar Narayan Kamath Committed by Android (Google) Code Review
Browse files

Merge "Write unit tests for android.speech.tts."

parents 49a13f00 c60aad2a
Loading
Loading
Loading
Loading
+23 −6
Original line number Diff line number Diff line
@@ -486,6 +486,11 @@ public class TextToSpeech {
    private final Object mStartLock = new Object();

    private String mRequestedEngine;
    // Whether to initialize this TTS object with the default engine,
    // if the requested engine is not available. Valid only if mRequestedEngine
    // is not null. Used only for testing, though potentially useful API wise
    // too.
    private final boolean mUseFallback;
    private final Map<String, Uri> mEarcons;
    private final Map<String, Uri> mUtterances;
    private final Bundle mParams = new Bundle();
@@ -519,7 +524,7 @@ public class TextToSpeech {
     * @param engine Package name of the TTS engine to use.
     */
    public TextToSpeech(Context context, OnInitListener listener, String engine) {
        this(context, listener, engine, null);
        this(context, listener, engine, null, true);
    }

    /**
@@ -529,10 +534,11 @@ public class TextToSpeech {
     * @hide
     */
    public TextToSpeech(Context context, OnInitListener listener, String engine,
            String packageName) {
            String packageName, boolean useFallback) {
        mContext = context;
        mInitListener = listener;
        mRequestedEngine = engine;
        mUseFallback = useFallback;

        mEarcons = new HashMap<String, Uri>();
        mUtterances = new HashMap<String, Uri>();
@@ -567,10 +573,21 @@ public class TextToSpeech {

    private int initTts() {
        // Step 1: Try connecting to the engine that was requested.
        if (mRequestedEngine != null && mEnginesHelper.isEngineInstalled(mRequestedEngine)) {
        if (mRequestedEngine != null) {
            if (mEnginesHelper.isEngineInstalled(mRequestedEngine)) {
                if (connectToEngine(mRequestedEngine)) {
                    mCurrentEngine = mRequestedEngine;
                    return SUCCESS;
                } else if (!mUseFallback) {
                    mCurrentEngine = null;
                    dispatchOnInit(ERROR);
                    return ERROR;
                }
            } else if (!mUseFallback) {
                Log.i(TAG, "Requested engine not installed: " + mRequestedEngine);
                mCurrentEngine = null;
                dispatchOnInit(ERROR);
                return ERROR;
            }
        }

+1 −1
Original line number Diff line number Diff line
@@ -1363,7 +1363,7 @@ public class WebView extends AbsoluteLayout
                final String packageName = ctx.getPackageName();
                if (packageName != null) {
                    mTextToSpeech = new TextToSpeech(getContext(), null, null,
                            packageName + ".**webview**");
                            packageName + ".**webview**", true);
                    addJavascriptInterface(mTextToSpeech, ALIAS_ACCESSIBILITY_JS_INTERFACE);
                }
            }
+28 −0
Original line number Diff line number Diff line
#
# Copyright (C) 2011 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.
#
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := tests

LOCAL_SRC_FILES := $(call all-subdir-java-files)

LOCAL_STATIC_JAVA_LIBRARIES := littlemock
LOCAL_JAVA_LIBRARIES := android.test.runner

LOCAL_PACKAGE_NAME := TtsTests

include $(BUILD_PACKAGE)
+43 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2011 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.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.speech.tts">
    <application>
        <uses-library android:name="android.test.runner" />


        <service android:name=".MockableTextToSpeechService"
                 android:label="Mockable Text-to-speech Service">
            <intent-filter>
                <action android:name="android.intent.action.TTS_SERVICE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </service>

        <activity android:name=".MockableCheckVoiceData"
                  android:theme="@android:style/Theme.NoDisplay">
            <intent-filter>
                <action android:name="android.speech.tts.engine.CHECK_TTS_DATA" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

    <instrumentation android:name="android.test.InstrumentationTestRunner"
                     android:targetPackage="com.android.speech.tts"
                     android:label="Tests for android.speech.tts" />
</manifest>
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 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.speech.tts;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;

import java.util.ArrayList;
import java.util.List;

public class MockableCheckVoiceData extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        MockableTextToSpeechService.IDelegate delegate =
                MockableTextToSpeechService.getMocker();

        ArrayList<String> availableLangs = delegate.getAvailableVoices();
        ArrayList<String> unavailableLangs = delegate.getUnavailableVoices();

        final Intent returnVal = new Intent();

        // Returns early.
        if (availableLangs == null) {
            setResult(TextToSpeech.Engine.CHECK_VOICE_DATA_FAIL, returnVal);
            finish();
            return;
        }

        returnVal.putStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES,
                    availableLangs);

        if (unavailableLangs != null && unavailableLangs.size() > 0) {
            returnVal.putStringArrayListExtra(TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES,
                    unavailableLangs);
        }

        setResult(TextToSpeech.Engine.CHECK_VOICE_DATA_PASS, returnVal);
        finish();
    }

}
Loading