Skip to content

Commit

Permalink
Test TextToSpeech.setLanguage semantics at the TtsService level.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhdunn committed Oct 10, 2015
1 parent 7c8128c commit 0b86bc7
Showing 1 changed file with 37 additions and 0 deletions.
Expand Up @@ -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.*;
Expand Down Expand Up @@ -51,6 +55,16 @@ public int onLoadLanguage(String language, String country, String variant) {
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;
Expand Down Expand Up @@ -208,4 +222,27 @@ public void testOnGetDefaultVoiceNameFor() {
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));
}
}
}
}

0 comments on commit 0b86bc7

Please sign in to comment.