Fix TTS tests.

Fix breakages steaming from recent changes:
- onGetLanguage is no longer called anywhere (it's used in API <= 17),
tests for it no longer apply.
- onLoadLanguage is called as item on synthesis thread queue. To return
value to client asap, onIsLanguageAvailable is called as well - added
missing expectations for mocks.

Change-Id: I205bc406f085e2c2f7e98f8495ddb96ad3701b97
This commit is contained in:
Przemyslaw Szczepaniak
2013-07-29 16:30:32 +01:00
parent 9ba21fdc9d
commit 93d34a61db

View File

@@ -70,6 +70,8 @@ public class TextToSpeechTests extends InstrumentationTestCase {
// Test 1 :Tests that calls to onLoadLanguage( ) are delegated through to the
// service without any caching or intermediate steps.
mTts.setLanguage(new Locale("eng", "USA", "variant"));
LittleMock.verify(delegate, LittleMock.times(1)).onIsLanguageAvailable(
"eng", "USA", "variant");
LittleMock.verify(delegate, LittleMock.times(1)).onLoadLanguage(
"eng", "USA", "variant");
}
@@ -82,6 +84,8 @@ public class TextToSpeechTests extends InstrumentationTestCase {
// Test 2 : Tests that when the language is successfully set
// like above (returns LANG_COUNTRY_AVAILABLE). That the
// request language changes from that point on.
LittleMock.doReturn(TextToSpeech.LANG_COUNTRY_AVAILABLE).when(delegate).onIsLanguageAvailable(
"eng", "USA", "variant");
LittleMock.doReturn(TextToSpeech.LANG_COUNTRY_AVAILABLE).when(delegate).onLoadLanguage(
"eng", "USA", "variant");
mTts.setLanguage(new Locale("eng", "USA", "variant"));
@@ -102,6 +106,8 @@ public class TextToSpeechTests extends InstrumentationTestCase {
// ---------------------------------------------------------
// TEST 3 : Tests that the language that is set does not change when the
// engine reports it could not load the specified language.
LittleMock.doReturn(TextToSpeech.LANG_NOT_SUPPORTED).when(
delegate).onIsLanguageAvailable("fra", "FRA", "");
LittleMock.doReturn(TextToSpeech.LANG_NOT_SUPPORTED).when(
delegate).onLoadLanguage("fra", "FRA", "");
mTts.setLanguage(Locale.FRANCE);
@@ -116,38 +122,6 @@ public class TextToSpeechTests extends InstrumentationTestCase {
assertEquals("", req2.getValue().getVariant());
}
public void testGetLanguage_invalidReturnValues() {
IDelegate delegate = LittleMock.mock(IDelegate.class);
MockableTextToSpeechService.setMocker(delegate);
// Test1: Simple end to end test. Ensure that bad return values
// are dealt with appropriately.
LittleMock.doReturn(null).when(delegate).onGetLanguage();
Locale returnVal = mTts.getLanguage();
assertNull(returnVal);
// Bad value 2. An array of length < 3.
LittleMock.doReturn(new String[] {"eng", "usa"}).when(delegate).onGetLanguage();
returnVal = mTts.getLanguage();
assertNull(returnVal);
}
public void testGetLanguage_validReturnValues() {
IDelegate delegate = LittleMock.mock(IDelegate.class);
MockableTextToSpeechService.setMocker(delegate);
// A correct value.
LittleMock.doReturn(new String[] {"eng", "usa", ""}).when(delegate).onGetLanguage();
Locale returnVal = mTts.getLanguage();
// Note: This is not the same as Locale.US . Well tough luck for
// being the only component of the entire framework that standardized
// three letter country and language codes.
assertEquals(new Locale("eng", "USA", ""), returnVal);
}
public void testIsLanguageAvailable() {
IDelegate delegate = LittleMock.mock(IDelegate.class);
MockableTextToSpeechService.setMocker(delegate);