-
Notifications
You must be signed in to change notification settings - Fork 52
[flutter_tts] Add integration tests for the supported TTS APIs #1041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
dde61b4
b269aa5
3df5b4e
4f36aa8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,90 @@ import 'package:integration_test/integration_test.dart'; | |
| void main() { | ||
| IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
|
||
| testWidgets('Can speak', (WidgetTester tester) async { | ||
| final flutterTts = FlutterTts(); | ||
| late FlutterTts flutterTts; | ||
|
|
||
| setUpAll(() async { | ||
| flutterTts = FlutterTts(); | ||
| // Give the native TTS engine time to initialize. | ||
| await Future<void>.delayed(const Duration(seconds: 2)); | ||
| var result = await flutterTts.speak('Hello, world!'); | ||
| expect(result, 1); | ||
| }); | ||
|
|
||
| tearDown(() async { | ||
| await flutterTts.stop(); | ||
| }); | ||
|
|
||
| testWidgets('speak returns 1', (WidgetTester tester) async { | ||
| expect(await flutterTts.speak('Hello, world!'), 1); | ||
| }); | ||
|
|
||
| testWidgets('stop returns 1', (WidgetTester tester) async { | ||
| expect(await flutterTts.stop(), 1); | ||
| }); | ||
|
|
||
| testWidgets('getLanguages returns a non-empty list', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| final languages = await flutterTts.getLanguages; | ||
| expect(languages, isNotNull); | ||
| expect(languages, isNotEmpty); | ||
| }); | ||
|
|
||
| testWidgets('isLanguageAvailable is true for a supported language', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| final languages = (await flutterTts.getLanguages as List).cast<String>(); | ||
| expect(languages, isNotEmpty); | ||
| expect(await flutterTts.isLanguageAvailable(languages.first), isTrue); | ||
| }); | ||
|
|
||
| testWidgets('setLanguage returns 1 for a supported language', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| final languages = (await flutterTts.getLanguages as List).cast<String>(); | ||
| expect(languages, isNotEmpty); | ||
| expect(await flutterTts.setLanguage(languages.first), 1); | ||
|
seungsoo47 marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| testWidgets('getVoices returns a non-empty list', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| final voices = await flutterTts.getVoices; | ||
| expect(voices, isNotNull); | ||
| expect(voices, isNotEmpty); | ||
|
Comment on lines
+55
to
+57
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm just wondering, I think
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Integration tests run against real devices or specific emulators where the TTS engine is always present. If 'getVoices' returns empty, it means the device or emulator is not properly configured for TTS, which is a valid test failure. |
||
| }); | ||
|
|
||
| testWidgets('getDefaultVoice returns a voice', (WidgetTester tester) async { | ||
| expect(await flutterTts.getDefaultVoice, isNotNull); | ||
| }); | ||
|
|
||
| testWidgets('setVoice returns 1', (WidgetTester tester) async { | ||
| final voices = (await flutterTts.getVoices as List).cast<Map>(); | ||
| expect(voices, isNotEmpty); | ||
| final voice = voices.first; | ||
| expect( | ||
| await flutterTts.setVoice(<String, String>{ | ||
| 'name': voice['name'].toString(), | ||
| 'locale': voice['locale'].toString(), | ||
| }), | ||
| 1, | ||
| ); | ||
|
seungsoo47 marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| testWidgets('setSpeechRate returns 1', (WidgetTester tester) async { | ||
| expect(await flutterTts.setSpeechRate(0.5), 1); | ||
| }); | ||
|
|
||
| testWidgets('setVolume returns 1', (WidgetTester tester) async { | ||
| expect(await flutterTts.setVolume(1), 1); | ||
| }); | ||
|
|
||
| testWidgets('getMaxSpeechInputLength is positive', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| // tts_get_max_text_size requires the ready state; stop() ensures it. | ||
| await flutterTts.stop(); | ||
| final maxLength = await flutterTts.getMaxSpeechInputLength; | ||
| expect(maxLength, isNotNull); | ||
| expect(maxLength, greaterThan(0)); | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -298,11 +298,11 @@ class FlutterTtsTizenPlugin : public flutter::Plugin { | |
| if (std::holds_alternative<std::string>(arguments)) { | ||
| std::string language = std::move(std::get<std::string>(arguments)); | ||
| if (!language.empty() && tts_->IsLanguageAvailable(language)) { | ||
| SendResult(flutter::EncodableValue(1)); | ||
| SendResult(flutter::EncodableValue(true)); | ||
| return; | ||
| } | ||
| } | ||
| SendResult(flutter::EncodableValue(0)); | ||
| SendResult(flutter::EncodableValue(false)); | ||
|
Comment on lines
+301
to
+305
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this part is a change to the interface (
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| } | ||
|
|
||
| void SendResult(const flutter::EncodableValue &result) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.