From 0b86bc71adcdec533aa8a1d9d51186d45f310822 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sat, 10 Oct 2015 23:07:58 +0100 Subject: [PATCH] Test TextToSpeech.setLanguage semantics at the TtsService level. --- .../espeak/test/TextToSpeechServiceTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/android/eSpeakTests/src/com/reecedunn/espeak/test/TextToSpeechServiceTest.java b/android/eSpeakTests/src/com/reecedunn/espeak/test/TextToSpeechServiceTest.java index d764192b..df6f4fa9 100644 --- a/android/eSpeakTests/src/com/reecedunn/espeak/test/TextToSpeechServiceTest.java +++ b/android/eSpeakTests/src/com/reecedunn/espeak/test/TextToSpeechServiceTest.java @@ -16,13 +16,17 @@ package com.reecedunn.espeak.test; +import android.annotation.SuppressLint; import android.content.Context; +import android.os.Build; import android.speech.tts.TextToSpeech; import android.test.AndroidTestCase; import com.reecedunn.espeak.TtsService; import com.reecedunn.espeak.Voice; +import java.util.Locale; + import static com.reecedunn.espeak.test.TtsMatcher.isTtsLangCode; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; @@ -51,6 +55,16 @@ public class TextToSpeechServiceTest extends AndroidTestCase public Voice getActiveVoice() { return mMatchingVoice; } + + @SuppressLint("NewApi") + private android.speech.tts.Voice getVoice(String name) { + for (android.speech.tts.Voice voice : onGetVoices()) { + if (voice.getName().equals(name)) { + return voice; + } + } + return null; + } } private TtsServiceTest mService = null; @@ -208,4 +222,27 @@ public class TextToSpeechServiceTest extends AndroidTestCase assertThat(mService.getActiveVoice(), is(notNullValue())); assertThat(mService.getActiveVoice().name, is("vi-sgn")); } + + public void testLanguages() { + for (VoiceData.Voice data : VoiceData.voices) + { + assertThat(mService.onIsLanguageAvailable(data.javaLanguage, data.javaCountry, data.variant), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE)); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + assertThat(mService.onLoadLanguage(data.javaLanguage, data.javaCountry, data.variant), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE)); + checkLanguage(mService.onGetLanguage(), data.javaLanguage, data.javaCountry, data.variant); + } else { + assertThat(mService.onGetDefaultVoiceNameFor(data.javaLanguage, data.javaCountry, data.variant), is(data.name)); + assertThat(mService.onLoadVoice(data.name), is(TextToSpeech.SUCCESS)); + + android.speech.tts.Voice voice = mService.getVoice(data.name); + assertThat(voice, is(notNullValue())); + + Locale locale = voice.getLocale(); + assertThat(locale, is(notNullValue())); + assertThat(locale.getISO3Language(), is(data.javaLanguage)); + assertThat(locale.getISO3Country(), is(data.javaCountry)); + assertThat(locale.getVariant(), is(data.variant)); + } + } + } }