From 27ef10df2e9b596a96a6974d02c7a9d782f5001c Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 25 Apr 2022 17:12:01 +0200 Subject: Skip speaking tests if there is no audio device Those tests will fail, as the audio playback will either not start at all or finish immediately. Skip those tests, unless we use the mock engine. Fixes: QTBUG-82545 Change-Id: Ib3b51a1b38928bcbea20f1515d231637608fd206 Reviewed-by: Volker Hilsheimer Reviewed-by: Axel Spoerl --- tests/auto/qtexttospeech/CMakeLists.txt | 6 ++++++ tests/auto/qtexttospeech/tst_qtexttospeech.cpp | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) (limited to 'tests') diff --git a/tests/auto/qtexttospeech/CMakeLists.txt b/tests/auto/qtexttospeech/CMakeLists.txt index 6dd3c7d..e28b477 100644 --- a/tests/auto/qtexttospeech/CMakeLists.txt +++ b/tests/auto/qtexttospeech/CMakeLists.txt @@ -1,8 +1,14 @@ +if(NOT TARGET Qt::Multimedia) + message(WARNING "The test case requires Qt::Multimedia to verify the presence of audio devices") + return() +endif() + qt_internal_add_test(tst_qtexttospeech SOURCES tst_qtexttospeech.cpp PUBLIC_LIBRARIES Qt::TextToSpeechPrivate + Qt::Multimedia ) # on macOS we need to run a Cocoa event dispatcher diff --git a/tests/auto/qtexttospeech/tst_qtexttospeech.cpp b/tests/auto/qtexttospeech/tst_qtexttospeech.cpp index 4fff2b3..29b8f0e 100644 --- a/tests/auto/qtexttospeech/tst_qtexttospeech.cpp +++ b/tests/auto/qtexttospeech/tst_qtexttospeech.cpp @@ -38,6 +38,8 @@ #include #include #include +#include +#include #include #if QT_CONFIG(speechd) @@ -71,6 +73,12 @@ private slots: void pauseResume(); void sayWithVoices(); void sayWithRates(); + +private: + static bool hasDefaultAudioOutput() + { + return !QMediaDevices::defaultAudioOutput().isNull(); + } }; void tst_QTextToSpeech::initTestCase_data() @@ -315,6 +323,9 @@ void tst_QTextToSpeech::volume() void tst_QTextToSpeech::sayHello() { QFETCH_GLOBAL(QString, engine); + if (!hasDefaultAudioOutput() && engine != "mock") + QSKIP("No audio device present"); + const QString text = QStringLiteral("saying hello with %1"); QTextToSpeech tts(engine); QTRY_COMPARE(tts.state(), QTextToSpeech::Ready); @@ -332,6 +343,9 @@ void tst_QTextToSpeech::sayHello() void tst_QTextToSpeech::pauseResume() { QFETCH_GLOBAL(QString, engine); + if (!hasDefaultAudioOutput() && engine != "mock") + QSKIP("No audio device present"); + const QString text = QStringLiteral("Hello. World."); QTextToSpeech tts(engine); QTRY_COMPARE(tts.state(), QTextToSpeech::Ready); @@ -350,6 +364,9 @@ void tst_QTextToSpeech::pauseResume() void tst_QTextToSpeech::sayWithVoices() { QFETCH_GLOBAL(QString, engine); + if (!hasDefaultAudioOutput() && engine != "mock") + QSKIP("No audio device present"); + const QString text = QStringLiteral("engine %1 with voice of %2"); QTextToSpeech tts(engine); QTRY_COMPARE(tts.state(), QTextToSpeech::Ready); @@ -377,6 +394,9 @@ void tst_QTextToSpeech::sayWithVoices() void tst_QTextToSpeech::sayWithRates() { QFETCH_GLOBAL(QString, engine); + if (!hasDefaultAudioOutput() && engine != "mock") + QSKIP("No audio device present"); + const QString text = QStringLiteral("test at different rates"); QTextToSpeech tts(engine); QTRY_COMPARE(tts.state(), QTextToSpeech::Ready); -- cgit v1.2.3