diff options
author | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2014-05-30 11:00:17 +0100 |
---|---|---|
committer | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2014-06-11 13:49:48 +0100 |
commit | 1b5637ee32c5d4e5d857fa86a1b1c1db23d027b7 (patch) | |
tree | 4c857c995524f7763fb4ef3b3cd280d3a9af7d48 /tests | |
parent | dad8f819a710510be28e9fdeee84f9b5b2ddacbf (diff) | |
download | frameworks_base-1b5637ee32c5d4e5d857fa86a1b1c1db23d027b7.zip frameworks_base-1b5637ee32c5d4e5d857fa86a1b1c1db23d027b7.tar.gz frameworks_base-1b5637ee32c5d4e5d857fa86a1b1c1db23d027b7.tar.bz2 |
Expose "default tts locale" to the TTS V2 API.
This change allows TTS V2 API client applications to honor the
"default TTS locale" set by the user in the TTS settings.
Note that the TTS V1 API uses 3 character country/language codes
for locale encoding. It's the only system component that does
that. TTS V2 uses the standard, valid Locale objects. The default
TTS locale setting was stored as a 3 character locale string with
"-" as the separator.
This change switches the TTS locale setting format to the output of
Locale.toString() call (on a valid Locale object). Methods used for
reading this value can interpret both forms and try to return a valid
Locale object as an output.
Change-Id: Ice2e6c25a43eb9dd6e17d371ee582c2dae3329c9
Diffstat (limited to 'tests')
-rw-r--r-- | tests/TtsTests/src/com/android/speech/tts/TtsEnginesTests.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/TtsTests/src/com/android/speech/tts/TtsEnginesTests.java b/tests/TtsTests/src/com/android/speech/tts/TtsEnginesTests.java new file mode 100644 index 0000000..45e5216 --- /dev/null +++ b/tests/TtsTests/src/com/android/speech/tts/TtsEnginesTests.java @@ -0,0 +1,64 @@ +package com.android.speech.tts; + +import android.speech.tts.TtsEngines; +import android.test.InstrumentationTestCase; + +import java.util.Locale; + +public class TtsEnginesTests extends InstrumentationTestCase { + private TtsEngines mTtsHelper; + + @Override + public void setUp() { + mTtsHelper = new TtsEngines(getInstrumentation().getContext()); + } + + public void testParseLocaleString() { + assertEquals(new Locale("en", "US"), mTtsHelper.parseLocaleString("eng-usa")); + assertEquals(new Locale("en", "US"), mTtsHelper.parseLocaleString("eng-USA")); + assertEquals(new Locale("en", "US"), mTtsHelper.parseLocaleString("en-US")); + assertEquals(new Locale("en", "US"), mTtsHelper.parseLocaleString("en_us")); + assertEquals(new Locale("en", "US"), mTtsHelper.parseLocaleString("eng_US")); + assertEquals(new Locale("en", "US", "foobar"), + mTtsHelper.parseLocaleString("eng_US-foobar")); + assertEquals(new Locale("en", "", "foobar"), mTtsHelper.parseLocaleString("eng__foobar")); + assertNull(mTtsHelper.parseLocaleString("cc_xx_barbar")); + assertNull(mTtsHelper.parseLocaleString("cc--barbar")); + + assertEquals(new Locale("en"), mTtsHelper.parseLocaleString("eng")); + assertEquals(new Locale("en","US","var"), mTtsHelper.parseLocaleString("eng-USA-var")); + } + + public void testToOldLocaleStringFormat() { + assertArraysEqual(new String[]{"deu", "DEU", ""}, + TtsEngines.toOldLocaleStringFormat(new Locale("de", "DE"))); + assertArraysEqual(new String[]{"deu", "", ""}, + TtsEngines.toOldLocaleStringFormat(new Locale("de"))); + assertArraysEqual(new String[]{"eng", "", ""}, + TtsEngines.toOldLocaleStringFormat(new Locale("en"))); + assertArraysEqual(new String[]{"eng", "USA", ""}, + TtsEngines.toOldLocaleStringFormat(new Locale("foo"))); + } + + public void testGetLocalePrefForEngine() { + assertEquals(new Locale("en", "US"), + mTtsHelper.getLocalePrefForEngine("foo","foo:en-US")); + assertEquals(new Locale("en", "US"), + mTtsHelper.getLocalePrefForEngine("foo","foo:eng-usa")); + assertEquals(new Locale("en", "US"), + mTtsHelper.getLocalePrefForEngine("foo","foo:eng_USA")); + assertEquals(new Locale("de", "DE"), + mTtsHelper.getLocalePrefForEngine("foo","foo:deu-deu")); + assertEquals(Locale.getDefault(), + mTtsHelper.getLocalePrefForEngine("foo","foo:,bar:xx")); + assertEquals(Locale.getDefault(), + mTtsHelper.getLocalePrefForEngine("other","foo:,bar:xx")); + } + + private void assertArraysEqual(String[] expected, String[] actual) { + assertEquals("array length", expected.length, actual.length); + for (int i = 0; i < expected.length; i++) { + assertEquals("index " + i, expected[i], actual[i]); + } + } +}
\ No newline at end of file |