Search in sources :

Example 11 with IDelegate

use of com.android.speech.tts.MockableTextToSpeechService.IDelegate in project platform_frameworks_base by android.

the class TextToSpeechTests method testSetLanguage_unavailableLanguage.

public void testSetLanguage_unavailableLanguage() throws Exception {
    IDelegate delegate = Mockito.mock(IDelegate.class);
    MockableTextToSpeechService.setMocker(delegate);
    // ---------------------------------------------------------
    // TEST 3 : Tests that the language that is set does not change when the
    // engine reports it could not load the specified language.
    Mockito.doReturn(TextToSpeech.LANG_NOT_SUPPORTED).when(delegate).onIsLanguageAvailable("fra", "FRA", "");
    Mockito.doReturn(TextToSpeech.LANG_NOT_SUPPORTED).when(delegate).onLoadLanguage("fra", "FRA", "");
    mTts.setLanguage(Locale.FRANCE);
    blockingCallSpeak("le fou barre", delegate);
    ArgumentCaptor<SynthesisRequest> req2 = ArgumentCaptor.forClass(SynthesisRequest.class);
    Mockito.verify(delegate, Mockito.times(1)).onSynthesizeText(req2.capture(), Mockito.<SynthesisCallback>anyObject());
    // The params are basically unchanged.
    assertEquals("eng", req2.getValue().getLanguage());
    assertEquals("USA", req2.getValue().getCountry());
    assertEquals("", req2.getValue().getVariant());
    assertEquals("en-US", req2.getValue().getVoiceName());
}
Also used : SynthesisRequest(android.speech.tts.SynthesisRequest) IDelegate(com.android.speech.tts.MockableTextToSpeechService.IDelegate)

Example 12 with IDelegate

use of com.android.speech.tts.MockableTextToSpeechService.IDelegate in project platform_frameworks_base by android.

the class TextToSpeechTests method setUp.

@Override
public void setUp() throws Exception {
    IDelegate passThrough = Mockito.mock(IDelegate.class);
    MockableTextToSpeechService.setMocker(passThrough);
    // For the default voice selection
    Mockito.doReturn(TextToSpeech.LANG_COUNTRY_AVAILABLE).when(passThrough).onIsLanguageAvailable(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    Mockito.doReturn(TextToSpeech.LANG_COUNTRY_AVAILABLE).when(passThrough).onLoadLanguage(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    blockingInitAndVerify(MOCK_ENGINE, TextToSpeech.SUCCESS);
    assertEquals(MOCK_ENGINE, mTts.getCurrentEngine());
}
Also used : IDelegate(com.android.speech.tts.MockableTextToSpeechService.IDelegate)

Example 13 with IDelegate

use of com.android.speech.tts.MockableTextToSpeechService.IDelegate in project platform_frameworks_base by android.

the class TextToSpeechTests method testIsLanguageAvailable.

public void testIsLanguageAvailable() {
    IDelegate delegate = Mockito.mock(IDelegate.class);
    MockableTextToSpeechService.setMocker(delegate);
    // Test1: Simple end to end test.
    Mockito.doReturn(TextToSpeech.LANG_COUNTRY_AVAILABLE).when(delegate).onIsLanguageAvailable("eng", "USA", "");
    assertEquals(TextToSpeech.LANG_COUNTRY_AVAILABLE, mTts.isLanguageAvailable(Locale.US));
    Mockito.verify(delegate, Mockito.times(1)).onIsLanguageAvailable("eng", "USA", "");
}
Also used : IDelegate(com.android.speech.tts.MockableTextToSpeechService.IDelegate)

Example 14 with IDelegate

use of com.android.speech.tts.MockableTextToSpeechService.IDelegate in project platform_frameworks_base by android.

the class TextToSpeechTests method testDefaultLanguage_setsVoiceName.

public void testDefaultLanguage_setsVoiceName() throws Exception {
    IDelegate delegate = Mockito.mock(IDelegate.class);
    MockableTextToSpeechService.setMocker(delegate);
    Locale defaultLocale = Locale.getDefault();
    // ---------------------------------------------------------
    // Test that default language also sets the default voice
    // name
    Mockito.doReturn(TextToSpeech.LANG_COUNTRY_AVAILABLE).when(delegate).onIsLanguageAvailable(defaultLocale.getISO3Language(), defaultLocale.getISO3Country().toUpperCase(), defaultLocale.getVariant());
    Mockito.doReturn(TextToSpeech.LANG_COUNTRY_AVAILABLE).when(delegate).onLoadLanguage(defaultLocale.getISO3Language(), defaultLocale.getISO3Country(), defaultLocale.getVariant());
    blockingCallSpeak("foo bar", delegate);
    ArgumentCaptor<SynthesisRequest> req = ArgumentCaptor.forClass(SynthesisRequest.class);
    Mockito.verify(delegate, Mockito.times(1)).onSynthesizeText(req.capture(), Mockito.<SynthesisCallback>anyObject());
    assertEquals(defaultLocale.getISO3Language(), req.getValue().getLanguage());
    assertEquals(defaultLocale.getISO3Country(), req.getValue().getCountry());
    assertEquals("", req.getValue().getVariant());
    assertEquals(defaultLocale.toLanguageTag(), req.getValue().getVoiceName());
}
Also used : Locale(java.util.Locale) SynthesisRequest(android.speech.tts.SynthesisRequest) IDelegate(com.android.speech.tts.MockableTextToSpeechService.IDelegate)

Example 15 with IDelegate

use of com.android.speech.tts.MockableTextToSpeechService.IDelegate in project android_frameworks_base by crdroidandroid.

the class TextToSpeechTests method testDefaultLanguage_setsVoiceName.

public void testDefaultLanguage_setsVoiceName() throws Exception {
    IDelegate delegate = LittleMock.mock(IDelegate.class);
    MockableTextToSpeechService.setMocker(delegate);
    Locale defaultLocale = Locale.getDefault();
    // ---------------------------------------------------------
    // Test that default language also sets the default voice
    // name
    LittleMock.doReturn(TextToSpeech.LANG_COUNTRY_AVAILABLE).when(delegate).onIsLanguageAvailable(defaultLocale.getISO3Language(), defaultLocale.getISO3Country().toUpperCase(), defaultLocale.getVariant());
    LittleMock.doReturn(TextToSpeech.LANG_COUNTRY_AVAILABLE).when(delegate).onLoadLanguage(defaultLocale.getISO3Language(), defaultLocale.getISO3Country(), defaultLocale.getVariant());
    blockingCallSpeak("foo bar", delegate);
    ArgumentCaptor<SynthesisRequest> req = LittleMock.createCaptor();
    LittleMock.verify(delegate, LittleMock.times(1)).onSynthesizeText(req.capture(), LittleMock.<SynthesisCallback>anyObject());
    assertEquals(defaultLocale.getISO3Language(), req.getValue().getLanguage());
    assertEquals(defaultLocale.getISO3Country(), req.getValue().getCountry());
    assertEquals("", req.getValue().getVariant());
    assertEquals(defaultLocale.toLanguageTag(), req.getValue().getVoiceName());
}
Also used : Locale(java.util.Locale) SynthesisRequest(android.speech.tts.SynthesisRequest) IDelegate(com.android.speech.tts.MockableTextToSpeechService.IDelegate)

Aggregations

IDelegate (com.android.speech.tts.MockableTextToSpeechService.IDelegate)31 Locale (java.util.Locale)16 SynthesisRequest (android.speech.tts.SynthesisRequest)14