Debian Codegraph @

android/eSpeakTests/src/com/reecedunn/espeak/test/TtsMatcher.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2014 Reece H. Dunn
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 }