summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/TtsTests/src/com/android/speech/tts/MockableTextToSpeechService.java2
-rw-r--r--tests/TtsTests/src/com/android/speech/tts/TextToSpeechTests.java29
2 files changed, 24 insertions, 7 deletions
diff --git a/tests/TtsTests/src/com/android/speech/tts/MockableTextToSpeechService.java b/tests/TtsTests/src/com/android/speech/tts/MockableTextToSpeechService.java
index 20648a4..06fbcdc 100644
--- a/tests/TtsTests/src/com/android/speech/tts/MockableTextToSpeechService.java
+++ b/tests/TtsTests/src/com/android/speech/tts/MockableTextToSpeechService.java
@@ -19,8 +19,10 @@ package com.android.speech.tts;
import android.speech.tts.SynthesisCallback;
import android.speech.tts.SynthesisRequest;
import android.speech.tts.TextToSpeechService;
+import android.util.Log;
import java.util.ArrayList;
+import java.util.logging.Logger;
public class MockableTextToSpeechService extends TextToSpeechService {
diff --git a/tests/TtsTests/src/com/android/speech/tts/TextToSpeechTests.java b/tests/TtsTests/src/com/android/speech/tts/TextToSpeechTests.java
index 78d4f96..faf6827 100644
--- a/tests/TtsTests/src/com/android/speech/tts/TextToSpeechTests.java
+++ b/tests/TtsTests/src/com/android/speech/tts/TextToSpeechTests.java
@@ -43,11 +43,18 @@ public class TextToSpeechTests extends InstrumentationTestCase {
IDelegate passThrough = LittleMock.mock(IDelegate.class);
MockableTextToSpeechService.setMocker(passThrough);
+ // For the default voice selection
+ LittleMock.doReturn(TextToSpeech.LANG_COUNTRY_AVAILABLE).when(passThrough)
+ .onIsLanguageAvailable(
+ LittleMock.anyString(), LittleMock.anyString(), LittleMock.anyString());
+ LittleMock.doReturn(TextToSpeech.LANG_COUNTRY_AVAILABLE).when(passThrough)
+ .onLoadLanguage(
+ LittleMock.anyString(), LittleMock.anyString(), LittleMock.anyString());
+
blockingInitAndVerify(MOCK_ENGINE, TextToSpeech.SUCCESS);
assertEquals(MOCK_ENGINE, mTts.getCurrentEngine());
}
-
@Override
public void tearDown() {
if (mTts != null) {
@@ -77,7 +84,7 @@ public class TextToSpeechTests extends InstrumentationTestCase {
assertEquals(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE, mTts.setLanguage(new Locale("eng", "USA", "variant")));
LittleMock.verify(delegate, LittleMock.anyTimes()).onIsLanguageAvailable(
"eng", "USA", "variant");
- LittleMock.verify(delegate, LittleMock.times(1)).onLoadLanguage(
+ LittleMock.verify(delegate, LittleMock.anyTimes()).onLoadLanguage(
"eng", "USA", "variant");
}
@@ -147,26 +154,34 @@ public class TextToSpeechTests extends InstrumentationTestCase {
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(
- LittleMock.anyString(), LittleMock.anyString(), LittleMock.anyString());
- LittleMock.doReturn(TextToSpeech.LANG_COUNTRY_AVAILABLE).when(delegate).onLoadLanguage(
- LittleMock.anyString(), LittleMock.anyString(), LittleMock.anyString());
+ 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());
- Locale defaultLocale = Locale.getDefault();
assertEquals(defaultLocale.getISO3Language(), req.getValue().getLanguage());
assertEquals(defaultLocale.getISO3Country(), req.getValue().getCountry());
assertEquals("", req.getValue().getVariant());
assertEquals(defaultLocale.toLanguageTag(), req.getValue().getVoiceName());
}
+
private void blockingCallSpeak(String speech, IDelegate mock) throws
InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);