File indexing completed on 2024-05-12 16:15:57
0001 /* 0002 SPDX-FileCopyrightText: 2014-2023 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "texttospeechconfigwidgettest.h" 0008 #include "texttospeechconfiginterface.h" 0009 #include "texttospeechconfigwidget.h" 0010 #include "texttospeechlanguagecombobox.h" 0011 #include "texttospeechsliderwidget.h" 0012 #include "texttospeechvoicecombobox.h" 0013 0014 #include <QComboBox> 0015 #include <QPushButton> 0016 #include <QSignalSpy> 0017 #include <QTest> 0018 0019 QTEST_MAIN(TextToSpeechConfigWidgetTest) 0020 0021 TextToSpeechConfigWidgetTest::TextToSpeechConfigWidgetTest(QObject *parent) 0022 : QObject(parent) 0023 { 0024 } 0025 0026 TextToSpeechConfigWidgetTest::~TextToSpeechConfigWidgetTest() = default; 0027 0028 void TextToSpeechConfigWidgetTest::addInterface(TextEditTextToSpeech::TextToSpeechConfigWidget *widget) 0029 { 0030 auto interface = new TextEditTextToSpeech::TextToSpeechConfigInterface(this); 0031 widget->setTextToSpeechConfigInterface(interface); 0032 } 0033 0034 void TextToSpeechConfigWidgetTest::shouldHaveDefaultValue() 0035 { 0036 TextEditTextToSpeech::TextToSpeechConfigWidget textToSpeechConfigWidget; 0037 addInterface(&textToSpeechConfigWidget); 0038 auto volume = textToSpeechConfigWidget.findChild<TextEditTextToSpeech::TextToSpeechSliderWidget *>(QStringLiteral("volume")); 0039 QVERIFY(volume); 0040 0041 auto rate = textToSpeechConfigWidget.findChild<TextEditTextToSpeech::TextToSpeechSliderWidget *>(QStringLiteral("rate")); 0042 QVERIFY(rate); 0043 0044 auto pitch = textToSpeechConfigWidget.findChild<TextEditTextToSpeech::TextToSpeechSliderWidget *>(QStringLiteral("pitch")); 0045 QVERIFY(pitch); 0046 0047 auto language = textToSpeechConfigWidget.findChild<TextEditTextToSpeech::TextToSpeechLanguageComboBox *>(QStringLiteral("language")); 0048 QVERIFY(language); 0049 // FIXME 0050 // QVERIFY(language->count()>0); 0051 0052 auto availableEngine = textToSpeechConfigWidget.findChild<QComboBox *>(QStringLiteral("engine")); 0053 QVERIFY(availableEngine); 0054 0055 auto voice = textToSpeechConfigWidget.findChild<TextEditTextToSpeech::TextToSpeechVoiceComboBox *>(QStringLiteral("voice")); 0056 QVERIFY(voice); 0057 0058 auto mTestButton = textToSpeechConfigWidget.findChild<QPushButton *>(QStringLiteral("mTestButton")); 0059 QVERIFY(mTestButton); 0060 } 0061 0062 void TextToSpeechConfigWidgetTest::shouldEmitConfigChangedWhenChangeConfigValue() 0063 { 0064 TextEditTextToSpeech::TextToSpeechConfigWidget textToSpeechConfigWidget; 0065 addInterface(&textToSpeechConfigWidget); 0066 QSignalSpy spy(&textToSpeechConfigWidget, &TextEditTextToSpeech::TextToSpeechConfigWidget::configChanged); 0067 auto volume = textToSpeechConfigWidget.findChild<TextEditTextToSpeech::TextToSpeechSliderWidget *>(QStringLiteral("volume")); 0068 volume->setValue(5); 0069 // It updates slider too! => 2 emit signal. 0070 QCOMPARE(spy.count(), 2); 0071 0072 spy.clear(); 0073 auto rate = textToSpeechConfigWidget.findChild<TextEditTextToSpeech::TextToSpeechSliderWidget *>(QStringLiteral("rate")); 0074 rate->setValue(5); 0075 QCOMPARE(spy.count(), 2); 0076 0077 spy.clear(); 0078 auto pitch = textToSpeechConfigWidget.findChild<TextEditTextToSpeech::TextToSpeechSliderWidget *>(QStringLiteral("pitch")); 0079 pitch->setValue(5); 0080 QCOMPARE(spy.count(), 2); 0081 0082 auto language = textToSpeechConfigWidget.findChild<QComboBox *>(QStringLiteral("language")); 0083 language->blockSignals(true); 0084 QStringList lst; 0085 lst << QStringLiteral("foo"); 0086 lst << QStringLiteral("foo"); 0087 lst << QStringLiteral("foo"); 0088 lst << QStringLiteral("foo"); 0089 language->addItems(lst); 0090 language->blockSignals(false); 0091 language->setCurrentIndex(3); 0092 QCOMPARE(spy.count(), 3); 0093 } 0094 0095 #include "moc_texttospeechconfigwidgettest.cpp"