summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-04-25 17:12:01 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-04-27 12:55:18 +0200
commit27ef10df2e9b596a96a6974d02c7a9d782f5001c (patch)
treeddcc47cab9ceaa7f780fc57ef7ca5125d66ec839 /tests
parent216c984aa5ca5b09ded4d3bb23c8998b8080d416 (diff)
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 <volker.hilsheimer@qt.io> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qtexttospeech/CMakeLists.txt6
-rw-r--r--tests/auto/qtexttospeech/tst_qtexttospeech.cpp20
2 files changed, 26 insertions, 0 deletions
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 <QTest>
#include <QTextToSpeech>
#include <QSignalSpy>
+#include <QMediaDevices>
+#include <QAudioDevice>
#include <qttexttospeech-config.h>
#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);