eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CheckVoiceDataTest.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. package com.reecedunn.espeak.test;
  17. import android.app.Activity;
  18. import android.content.Intent;
  19. import android.speech.tts.TextToSpeech;
  20. import android.test.ActivityUnitTestCase;
  21. import com.reecedunn.espeak.CheckVoiceData;
  22. import java.lang.reflect.Field;
  23. import java.util.ArrayList;
  24. import java.util.HashSet;
  25. import java.util.Set;
  26. import static org.hamcrest.MatcherAssert.assertThat;
  27. import static org.hamcrest.Matchers.*;
  28. public class CheckVoiceDataTest extends ActivityUnitTestCase<CheckVoiceData>
  29. {
  30. Field mResultCode;
  31. Field mResultData;
  32. public void setUp() throws Exception
  33. {
  34. super.setUp();
  35. mResultCode = Activity.class.getDeclaredField("mResultCode");
  36. mResultCode.setAccessible(true);
  37. mResultData = Activity.class.getDeclaredField("mResultData");
  38. mResultData.setAccessible(true);
  39. }
  40. public int getResultCode() throws IllegalAccessException
  41. {
  42. return (Integer)mResultCode.get(getActivity());
  43. }
  44. public Intent getResultData() throws IllegalAccessException
  45. {
  46. return (Intent)mResultData.get(getActivity());
  47. }
  48. public CheckVoiceDataTest()
  49. {
  50. super(CheckVoiceData.class);
  51. }
  52. public Set<String> getExpectedVoices()
  53. {
  54. Set<String> expected = new HashSet<String>();
  55. for (VoiceData.Voice voice : VoiceData.voices)
  56. {
  57. expected.add(voice.locale);
  58. }
  59. return expected;
  60. }
  61. public void testUnavailableVoices() throws IllegalAccessException
  62. {
  63. Intent intent = new Intent(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
  64. startActivity(intent, null, null);
  65. assertThat(getActivity(), is(notNullValue()));
  66. assertThat(isFinishCalled(), is(true));
  67. assertThat(getResultCode(), is(TextToSpeech.Engine.CHECK_VOICE_DATA_PASS));
  68. assertThat(getResultData(), is(notNullValue()));
  69. Intent data = getResultData();
  70. ArrayList<String> unavailable = data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES);
  71. assertThat(unavailable, is(notNullValue()));
  72. assertThat(unavailable.toString(), is("[]"));
  73. }
  74. public void testAvailableVoicesAdded() throws IllegalAccessException
  75. {
  76. Intent intent = new Intent(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
  77. startActivity(intent, null, null);
  78. assertThat(getActivity(), is(notNullValue()));
  79. assertThat(isFinishCalled(), is(true));
  80. assertThat(getResultCode(), is(TextToSpeech.Engine.CHECK_VOICE_DATA_PASS));
  81. assertThat(getResultData(), is(notNullValue()));
  82. Intent data = getResultData();
  83. ArrayList<String> available = data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
  84. assertThat(available, is(notNullValue()));
  85. Set<String> expected = getExpectedVoices();
  86. Set<String> added = new HashSet<String>();
  87. for (String voice : available)
  88. {
  89. if (!expected.contains(voice))
  90. {
  91. added.add(voice);
  92. }
  93. }
  94. assertThat(added.toString(), is("[]"));
  95. }
  96. public void testAvailableVoicesRemoved() throws IllegalAccessException
  97. {
  98. Intent intent = new Intent(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
  99. startActivity(intent, null, null);
  100. assertThat(getActivity(), is(notNullValue()));
  101. assertThat(isFinishCalled(), is(true));
  102. assertThat(getResultCode(), is(TextToSpeech.Engine.CHECK_VOICE_DATA_PASS));
  103. assertThat(getResultData(), is(notNullValue()));
  104. Intent data = getResultData();
  105. ArrayList<String> available = data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
  106. assertThat(available, is(notNullValue()));
  107. Set<String> expected = getExpectedVoices();
  108. Set<String> removed = new HashSet<String>();
  109. for (String voice : expected)
  110. {
  111. if (!available.contains(voice))
  112. {
  113. removed.add(voice);
  114. }
  115. }
  116. assertThat(removed.toString(), is("[]"));
  117. }
  118. }