Use API 21.

This commit is contained in:
Reece H. Dunn
2014-10-28 18:30:16 +00:00
parent 6ac54860a1
commit 3d2308e285
5 changed files with 67 additions and 31 deletions
@@ -30,11 +30,11 @@ public class TextToSpeechTest extends TextToSpeechTestCase
{
assertThat(getEngine(), is(notNullValue()));
Locale initialLocale = getEngine().getLanguage();
Locale initialLocale = getLanguage(getEngine());
assertThat(getEngine().isLanguageAvailable(new Locale("cel")), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(getEngine().getLanguage().getLanguage(), is(initialLocale.getLanguage()));
assertThat(getEngine().getLanguage().getCountry(), is(initialLocale.getCountry()));
assertThat(getEngine().getLanguage().getVariant(), is(initialLocale.getVariant()));
assertThat(getLanguage(getEngine()).getLanguage(), is(initialLocale.getLanguage()));
assertThat(getLanguage(getEngine()).getCountry(), is(initialLocale.getCountry()));
assertThat(getLanguage(getEngine()).getVariant(), is(initialLocale.getVariant()));
}
public void testLanguages()
@@ -60,44 +60,44 @@ public class TextToSpeechTest extends TextToSpeechTestCase
context = "iana1";
assertThat(getEngine().isLanguageAvailable(iana1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().setLanguage(iana1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
assertThat(getEngine().getLanguage().getVariant(), is(data.variant));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(data.javaCountry));
assertThat(getLanguage(getEngine()).getVariant(), is(data.variant));
context = "iana2";
assertThat(getEngine().isLanguageAvailable(iana2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().setLanguage(iana2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
assertThat(getEngine().getLanguage().getVariant(), is(""));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(data.javaCountry));
assertThat(getLanguage(getEngine()).getVariant(), is(""));
context = "iana3";
assertThat(getEngine().isLanguageAvailable(iana3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().setLanguage(iana3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(""));
assertThat(getEngine().getLanguage().getVariant(), is(""));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(""));
assertThat(getLanguage(getEngine()).getVariant(), is(""));
context = "java1";
assertThat(getEngine().isLanguageAvailable(java1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().setLanguage(java1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
assertThat(getEngine().getLanguage().getVariant(), is(data.variant));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(data.javaCountry));
assertThat(getLanguage(getEngine()).getVariant(), is(data.variant));
context = "java2";
assertThat(getEngine().isLanguageAvailable(java2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().setLanguage(java2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
assertThat(getEngine().getLanguage().getVariant(), is(""));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(data.javaCountry));
assertThat(getLanguage(getEngine()).getVariant(), is(""));
context = "java3";
assertThat(getEngine().isLanguageAvailable(java3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().setLanguage(java3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(""));
assertThat(getEngine().getLanguage().getVariant(), is(""));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(""));
assertThat(getLanguage(getEngine()).getVariant(), is(""));
}
catch (AssertionError e)
{
@@ -16,6 +16,7 @@
package com.reecedunn.espeak.test;
import android.os.Build;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.test.AndroidTestCase;
@@ -93,4 +94,19 @@ public class TextToSpeechTestCase extends AndroidTestCase
{
return mEngine;
}
@SuppressWarnings("deprecation")
public static Locale getLanguage(TextToSpeech engine) {
if (engine != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
android.speech.tts.Voice voice = engine.getVoice();
if (voice != null) {
return voice.getLocale();
}
} else {
return engine.getLanguage();
}
}
return null;
}
}