Browse Source

tests: map TextToSpeech.LANG_* to strings.

This creates a custom hamcrest matcher that maps the TextToSpeech
LANG_* constants to strings. This makes it easier to read the
text output when the tests fail.
master
Reece H. Dunn 10 years ago
parent
commit
cc0341e799

+ 68
- 67
android/eSpeakTests/src/com/reecedunn/espeak/test/SpeechSynthesisTest.java View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012-2013 Reece H. Dunn
* Copyright (C) 2012-2014 Reece H. Dunn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@ import android.media.AudioFormat;
import android.speech.tts.TextToSpeech;
import android.util.Log;

import static com.reecedunn.espeak.test.TtsMatcher.isTtsLangCode;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.AnyOf.anyOf;
@@ -248,20 +249,20 @@ public class SpeechSynthesisTest extends TextToSpeechTestCase
final Voice voice = getVoice("de"); // language="de" country="" variant=""
assertThat(voice, is(notNullValue()));

assertThat(voice.match(fr), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(fr_BE), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(fr_1694acad), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(fr_FR_1694acad), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(fr), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(fr_BE), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(fr_1694acad), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(fr_FR_1694acad), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));

assertThat(voice.match(de), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(voice.match(de_1996), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(de_DE), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(de_CH_1901), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(de), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(voice.match(de_1996), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(de_DE), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(de_CH_1901), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));

assertThat(voice.match(deu), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(voice.match(deu_1996), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(deu_DEU), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(deu_CHE_1901), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(deu), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(voice.match(deu_1996), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(deu_DEU), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(deu_CHE_1901), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
}

public void testMatchVoiceWithLanguageAndCountry()
@@ -269,24 +270,24 @@ public class SpeechSynthesisTest extends TextToSpeechTestCase
final Voice voice = getVoice("fr-fr"); // language="fr" country="fr" variant=""
assertThat(voice, is(notNullValue()));

assertThat(voice.match(de), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(de_1996), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(de_DE), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(de_CH_1901), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(fr), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(fr_FR), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(voice.match(fr_BE), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(fr_1694acad), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(fr_FR_1694acad), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(fr_BE_1694acad), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(fra), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(fra_FRA), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(voice.match(fra_BEL), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(fra_1694acad), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(fra_FRA_1694acad), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(fra_BEL_1694acad), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(de), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(de_1996), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(de_DE), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(de_CH_1901), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(fr), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(fr_FR), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(voice.match(fr_BE), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(fr_1694acad), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(fr_FR_1694acad), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(fr_BE_1694acad), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(fra), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(fra_FRA), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(voice.match(fra_BEL), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(fra_1694acad), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(fra_FRA_1694acad), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(fra_BEL_1694acad), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
}

public void testMatchVoiceWithLanguageAndVariant()
@@ -294,24 +295,24 @@ public class SpeechSynthesisTest extends TextToSpeechTestCase
final Voice voice = getVoice("hy-west"); // language="hy" country="" variant="arevmda"
assertThat(voice, is(notNullValue()));

assertThat(voice.match(fr), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(fr_BE), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(fr_1694acad), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(fr_FR_1694acad), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(hy), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(hy_AM), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(hy_arevela), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(hy_arevmda), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(voice.match(hy_AM_arevela), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(hy_AM_arevmda), is(TextToSpeech.LANG_AVAILABLE)); // NOTE: Android does not support LANG_VAR_AVAILABLE.
assertThat(voice.match(hye), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(hye_ARM), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(hye_arevela), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(hye_arevmda), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(voice.match(hye_ARM_arevela), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(hye_ARM_arevmda), is(TextToSpeech.LANG_AVAILABLE)); // NOTE: Android does not support LANG_VAR_AVAILABLE.
assertThat(voice.match(fr), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(fr_BE), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(fr_1694acad), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(fr_FR_1694acad), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(hy), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(hy_AM), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(hy_arevela), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(hy_arevmda), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(voice.match(hy_AM_arevela), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(hy_AM_arevmda), isTtsLangCode(TextToSpeech.LANG_AVAILABLE)); // NOTE: Android does not support LANG_VAR_AVAILABLE.
assertThat(voice.match(hye), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(hye_ARM), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(hye_arevela), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(hye_arevmda), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(voice.match(hye_ARM_arevela), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(hye_ARM_arevmda), isTtsLangCode(TextToSpeech.LANG_AVAILABLE)); // NOTE: Android does not support LANG_VAR_AVAILABLE.
}

public void testMatchVoiceWithLanguageCountryAndVariant()
@@ -319,24 +320,24 @@ public class SpeechSynthesisTest extends TextToSpeechTestCase
final Voice voice = getVoice("en-sc"); // language="en" country="GB" variant="scotland"
assertThat(voice, is(notNullValue()));

assertThat(voice.match(de), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(de_1996), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(de_DE), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(de_CH_1901), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(en), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(en_GB), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(en_US), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(en_scotland), is(TextToSpeech.LANG_AVAILABLE)); // NOTE: Android does not support LANG_VAR_AVAILABLE.
assertThat(voice.match(en_GB_scotland), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(voice.match(en_GB_north), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(eng), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(eng_GBR), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(eng_USA), is(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(eng_scotland), is(TextToSpeech.LANG_AVAILABLE)); // NOTE: Android does not support LANG_VAR_AVAILABLE.
assertThat(voice.match(eng_GBR_scotland), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(voice.match(eng_GBR_north), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(de), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(de_1996), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(de_DE), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(de_CH_1901), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(voice.match(en), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(en_GB), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(en_US), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(en_scotland), isTtsLangCode(TextToSpeech.LANG_AVAILABLE)); // NOTE: Android does not support LANG_VAR_AVAILABLE.
assertThat(voice.match(en_GB_scotland), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(voice.match(en_GB_north), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(eng), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(eng_GBR), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(voice.match(eng_USA), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(voice.match(eng_scotland), isTtsLangCode(TextToSpeech.LANG_AVAILABLE)); // NOTE: Android does not support LANG_VAR_AVAILABLE.
assertThat(voice.match(eng_GBR_scotland), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(voice.match(eng_GBR_north), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
}

public void testGetSampleText()

+ 14
- 13
android/eSpeakTests/src/com/reecedunn/espeak/test/TextToSpeechTest.java View File

@@ -20,6 +20,7 @@ import java.util.Locale;

import android.speech.tts.TextToSpeech;

import static com.reecedunn.espeak.test.TtsMatcher.isTtsLangCode;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

@@ -30,7 +31,7 @@ public class TextToSpeechTest extends TextToSpeechTestCase
assertThat(getEngine(), is(notNullValue()));

Locale initialLocale = getEngine().getLanguage();
assertThat(getEngine().isLanguageAvailable(new Locale("cel")), is(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(getEngine().isLanguageAvailable(new Locale("cel")), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(getEngine().getLanguage().getLanguage(), is(initialLocale.getLanguage()));
assertThat(getEngine().getLanguage().getCountry(), is(initialLocale.getCountry()));
assertThat(getEngine().getLanguage().getVariant(), is(initialLocale.getVariant()));
@@ -57,43 +58,43 @@ public class TextToSpeechTest extends TextToSpeechTestCase
final Locale java3 = new Locale(data.javaLanguage, "VUT", data.variant);

context = "iana1";
assertThat(getEngine().isLanguageAvailable(iana1), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().setLanguage(iana1), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().isLanguageAvailable(iana1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().setLanguage(iana1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
assertThat(getEngine().getLanguage().getVariant(), is(data.variant));

context = "iana2";
assertThat(getEngine().isLanguageAvailable(iana2), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().setLanguage(iana2), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().isLanguageAvailable(iana2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().setLanguage(iana2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
assertThat(getEngine().getLanguage().getVariant(), is(""));

context = "iana3";
assertThat(getEngine().isLanguageAvailable(iana3), is(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().setLanguage(iana3), is(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().isLanguageAvailable(iana3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().setLanguage(iana3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(""));
assertThat(getEngine().getLanguage().getVariant(), is(""));

context = "java1";
assertThat(getEngine().isLanguageAvailable(java1), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().setLanguage(java1), is(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().isLanguageAvailable(java1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().setLanguage(java1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
assertThat(getEngine().getLanguage().getVariant(), is(data.variant));

context = "java2";
assertThat(getEngine().isLanguageAvailable(java2), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().setLanguage(java2), is(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().isLanguageAvailable(java2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().setLanguage(java2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
assertThat(getEngine().getLanguage().getVariant(), is(""));

context = "java3";
assertThat(getEngine().isLanguageAvailable(java3), is(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().setLanguage(java3), is(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().isLanguageAvailable(java3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().setLanguage(java3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(""));
assertThat(getEngine().getLanguage().getVariant(), is(""));

+ 62
- 0
android/eSpeakTests/src/com/reecedunn/espeak/test/TtsMatcher.java View File

@@ -0,0 +1,62 @@
/*
* Copyright (C) 2014 Reece H. Dunn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.reecedunn.espeak.test;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

import android.speech.tts.TextToSpeech;

import com.reecedunn.espeak.InformationListAdapter;

public class TtsMatcher
{
private static String ttsLangCode(final Integer value) {
if (value == null) return "null";
switch (value.intValue()) {
case TextToSpeech.LANG_AVAILABLE: return "TextToSpeech.LANG_AVAILABLE";
case TextToSpeech.LANG_COUNTRY_AVAILABLE: return "TextToSpeech.LANG_COUNTRY_AVAILABLE";
case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE: return "TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE";
case TextToSpeech.LANG_MISSING_DATA: return "TextToSpeech.LANG_MISSING_DATA";
case TextToSpeech.LANG_NOT_SUPPORTED: return "TextToSpeech.LANG_NOT_SUPPORTED";
}
return value.toString();
}

public static Matcher<Integer> isTtsLangCode(final Integer value) {
return new TypeSafeMatcher<Integer>() {
@Override
protected boolean matchesSafely(Integer item) {
return item.equals(value);
}

@Override
public void describeTo(Description description) {
description.appendText("expected constant: ");
description.appendValue(ttsLangCode(value));
}

@Override
public void describeMismatchSafely(final Integer item, final Description description) {
description.appendText("was ");
description.appendValue(ttsLangCode(item));
}
};
}
}

Loading…
Cancel
Save