| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.reecedunn.espeak.test; |
| 18 |
|
| 19 |
import org.hamcrest.Description; |
| 20 |
import org.hamcrest.Matcher; |
| 21 |
import org.hamcrest.TypeSafeMatcher; |
| 22 |
|
| 23 |
import android.speech.tts.TextToSpeech; |
| 24 |
|
| 25 |
public class TtsMatcher |
| 26 |
{ |
| 27 |
private static String ttsLangCode(final Integer value) { |
| 28 |
if (value == null) return "null"; |
| 29 |
switch (value.intValue()) { |
| 30 |
case TextToSpeech.LANG_AVAILABLE: return "TextToSpeech.LANG_AVAILABLE"; |
| 31 |
case TextToSpeech.LANG_COUNTRY_AVAILABLE: return "TextToSpeech.LANG_COUNTRY_AVAILABLE"; |
| 32 |
case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE: return "TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE"; |
| 33 |
case TextToSpeech.LANG_MISSING_DATA: return "TextToSpeech.LANG_MISSING_DATA"; |
| 34 |
case TextToSpeech.LANG_NOT_SUPPORTED: return "TextToSpeech.LANG_NOT_SUPPORTED"; |
| 35 |
} |
| 36 |
return value.toString(); |
| 37 |
} |
| 38 |
|
| 39 |
public static Matcher<Integer> isTtsLangCode(final Integer value) { |
| 40 |
return new TypeSafeMatcher<Integer>() { |
| 41 |
@Override |
| 42 |
protected boolean matchesSafely(Integer item) { |
| 43 |
return item.equals(value); |
| 44 |
} |
| 45 |
|
| 46 |
@Override |
| 47 |
public void describeTo(Description description) { |
| 48 |
description.appendText("expected constant: "); |
| 49 |
description.appendValue(ttsLangCode(value)); |
| 50 |
} |
| 51 |
|
| 52 |
@Override |
| 53 |
public void describeMismatchSafely(final Integer item, final Description description) { |
| 54 |
description.appendText("was "); |
| 55 |
description.appendValue(ttsLangCode(item)); |
| 56 |
} |
| 57 |
}; |
| 58 |
} |
| 59 |
} |