Browse Source

Test TextToSpeech.setLanguage semantics at the TtsService level.

master
Reece H. Dunn 9 years ago
parent
commit
0b86bc71ad

+ 37
- 0
android/eSpeakTests/src/com/reecedunn/espeak/test/TextToSpeechServiceTest.java View File



package com.reecedunn.espeak.test; package com.reecedunn.espeak.test;


import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.os.Build;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
import android.test.AndroidTestCase; import android.test.AndroidTestCase;


import com.reecedunn.espeak.TtsService; import com.reecedunn.espeak.TtsService;
import com.reecedunn.espeak.Voice; import com.reecedunn.espeak.Voice;


import java.util.Locale;

import static com.reecedunn.espeak.test.TtsMatcher.isTtsLangCode; import static com.reecedunn.espeak.test.TtsMatcher.isTtsLangCode;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
public Voice getActiveVoice() { public Voice getActiveVoice() {
return mMatchingVoice; 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; private TtsServiceTest mService = null;
assertThat(mService.getActiveVoice(), is(notNullValue())); assertThat(mService.getActiveVoice(), is(notNullValue()));
assertThat(mService.getActiveVoice().name, is("vi-sgn")); 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));
}
}
}
} }

Loading…
Cancel
Save