| }; | }; | ||||
| private List<Voice> mVoices = null; | private List<Voice> mVoices = null; | ||||
| private Set<String> mAdded = new HashSet<String>(); | |||||
| private Set<String> mRemoved = new HashSet<String>(); | |||||
| public List<Voice> getVoices() | public List<Voice> getVoices() | ||||
| { | { | ||||
| final SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback); | final SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback); | ||||
| mVoices = synth.getAvailableVoices(); | mVoices = synth.getAvailableVoices(); | ||||
| assertThat(mVoices, is(notNullValue())); | assertThat(mVoices, is(notNullValue())); | ||||
| Set<String> voices = new HashSet<String>(); | |||||
| for (Voice data : mVoices) | |||||
| { | |||||
| voices.add(data.name); | |||||
| } | |||||
| Set<String> expected = new HashSet<String>(); | |||||
| for (VoiceData.Voice data : VoiceData.voices) | |||||
| { | |||||
| expected.add(data.name); | |||||
| } | |||||
| for (String voice : voices) | |||||
| { | |||||
| if (!expected.contains(voice)) | |||||
| { | |||||
| mAdded.add(voice); | |||||
| } | |||||
| } | |||||
| for (String voice : expected) | |||||
| { | |||||
| if (!voices.contains(voice)) | |||||
| { | |||||
| mRemoved.add(voice); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| return mVoices; | return mVoices; | ||||
| } | } | ||||
| public void testAddedVoices() | public void testAddedVoices() | ||||
| { | { | ||||
| Set<String> voices = new HashSet<String>(); | |||||
| for (Voice data : getVoices()) | |||||
| { | |||||
| voices.add(data.name); | |||||
| } | |||||
| Set<String> expected = new HashSet<String>(); | |||||
| for (VoiceData.Voice data : VoiceData.voices) | |||||
| { | |||||
| expected.add(data.name); | |||||
| } | |||||
| Set<String> added = new HashSet<String>(); | |||||
| for (String voice : voices) | |||||
| { | |||||
| if (!expected.contains(voice)) | |||||
| { | |||||
| added.add(voice); | |||||
| } | |||||
| } | |||||
| assertThat(added.toString(), is("[]")); | |||||
| getVoices(); // Ensure that the voice data has been populated. | |||||
| assertThat(mAdded.toString(), is("[]")); | |||||
| } | } | ||||
| public void testRemovedVoices() | public void testRemovedVoices() | ||||
| { | { | ||||
| Set<String> voices = new HashSet<String>(); | |||||
| for (Voice data : getVoices()) | |||||
| { | |||||
| voices.add(data.name); | |||||
| } | |||||
| Set<String> expected = new HashSet<String>(); | |||||
| for (VoiceData.Voice data : VoiceData.voices) | |||||
| { | |||||
| expected.add(data.name); | |||||
| } | |||||
| Set<String> removed = new HashSet<String>(); | |||||
| for (String voice : expected) | |||||
| { | |||||
| if (!voices.contains(voice)) | |||||
| { | |||||
| removed.add(voice); | |||||
| } | |||||
| } | |||||
| assertThat(removed.toString(), is("[]")); | |||||
| getVoices(); // Ensure that the voice data has been populated. | |||||
| assertThat(mRemoved.toString(), is("[]")); | |||||
| } | } | ||||
| public void testVoiceData() | public void testVoiceData() |