summaryrefslogtreecommitdiff
path: root/utils/rbutilqt/test
diff options
context:
space:
mode:
Diffstat (limited to 'utils/rbutilqt/test')
-rw-r--r--utils/rbutilqt/test/stubs/stubs-talkgenerator.cpp104
-rw-r--r--utils/rbutilqt/test/test-talkgenerator.cpp83
-rw-r--r--utils/rbutilqt/test/test-talkgenerator.qrc5
3 files changed, 192 insertions, 0 deletions
diff --git a/utils/rbutilqt/test/stubs/stubs-talkgenerator.cpp b/utils/rbutilqt/test/stubs/stubs-talkgenerator.cpp
new file mode 100644
index 0000000000..295dc81a78
--- /dev/null
+++ b/utils/rbutilqt/test/stubs/stubs-talkgenerator.cpp
@@ -0,0 +1,104 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2022 Dominik Riebeling
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20
21// Stubs for TalkGenerator unit test.
22
23#include "rbsettings.h"
24#include "ttsbase.h"
25#include "encoderbase.h"
26#include "playerbuildinfo.h"
27
28extern "C" int wavtrim(char* filename, int maxsilence, char* errstring, int errsize)
29{
30 (void)filename;
31 (void)maxsilence;
32 (void)errstring;
33 (void)errsize;
34 return 0;
35}
36
37static QMap<RbSettings::UserSettings, QVariant> stubUserSettings;
38
39QVariant RbSettings::value(UserSettings setting)
40{
41 switch (setting)
42 {
43 case RbSettings::Tts:
44 return QString("espeak");
45 default:
46 return QVariant();
47 }
48}
49
50class TTSFakeEspeak : public TTSBase
51{
52 Q_OBJECT
53public:
54 TTSFakeEspeak(QObject *parent): TTSBase(parent) {}
55 virtual bool start(QString *errStr) { (void)errStr; return true; }
56 virtual bool stop() { return true; }
57 virtual TTSStatus voice(QString text, QString wavfile, QString *errStr)
58 { (void)text; (void)wavfile; (void)errStr; return NoError; }
59 virtual QString voiceVendor() { return QString("DummyVendor"); }
60 virtual bool configOk() { return true; }
61 virtual void generateSettings() {}
62 virtual void saveSettings() {}
63 virtual Capabilities capabilities() { return None; }
64};
65
66TTSBase::TTSBase(QObject* parent) : EncTtsSettingInterface(parent)
67{
68}
69
70TTSStatus TTSBase::voice(QString /*text*/, QString /*wavfile*/, QString* /*errStr*/)
71{
72 return NoError;
73}
74
75TTSBase* TTSBase::getTTS(QObject* parent, QString /*ttsName*/)
76{
77 return new TTSFakeEspeak(parent);
78}
79
80EncoderBase* EncoderBase::getEncoder(QObject*, QString)
81{
82 return nullptr;
83}
84
85QVariant PlayerBuildInfo::value(PlayerBuildInfo::DeviceInfo /*item*/, QString /*target*/)
86{
87 return QVariant();
88}
89
90PlayerBuildInfo* PlayerBuildInfo::infoInstance = nullptr;
91
92PlayerBuildInfo::PlayerBuildInfo()
93{
94}
95
96PlayerBuildInfo* PlayerBuildInfo::instance()
97{
98 if (infoInstance == nullptr) {
99 infoInstance = new PlayerBuildInfo();
100 }
101 return infoInstance;
102}
103
104#include "stubs-talkgenerator.moc"
diff --git a/utils/rbutilqt/test/test-talkgenerator.cpp b/utils/rbutilqt/test/test-talkgenerator.cpp
new file mode 100644
index 0000000000..82649471da
--- /dev/null
+++ b/utils/rbutilqt/test/test-talkgenerator.cpp
@@ -0,0 +1,83 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2022 Dominik Riebeling
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20
21#include <QtTest/QtTest>
22#include <QObject>
23#include "talkgenerator.h"
24
25
26class TestTalkGenerator : public QObject
27{
28 Q_OBJECT
29 private slots:
30 void testCorrectString();
31 void testCorrectString_data();
32};
33
34
35
36void TestTalkGenerator::testCorrectString_data()
37{
38 struct {
39 const char* language;
40 const char* from;
41 const char* to;
42 } const correctdata[] =
43 {
44 { "english", "dummy text", "dummy text" },
45 { "deutsch", "alkaline", "alkalein" },
46 { "deutsch", "Batterie Typ Alkaline", "Batterie Typ alkalein" },
47 { "deutsch", "512 kilobytes frei", "512 kilobeits frei" },
48 // AT&T engine only.
49 { "deutsch", "alphabet", "alphabet" },
50
51 // espeak
52 {"svenska", "5 ampere", "5 ampär" },
53 {"svenska", "bokmärken...", "bok-märken..." },
54 };
55
56 QTest::addColumn<QString>("language");
57 QTest::addColumn<QString>("from");
58 QTest::addColumn<QString>("to");
59 for(size_t i = 0; i < sizeof(correctdata) / sizeof(correctdata[0]); i++) {
60 QTest::newRow(correctdata[i].from)
61 << correctdata[i].language << correctdata[i].from << correctdata[i].to;
62 }
63}
64
65void TestTalkGenerator::testCorrectString()
66{
67 QFETCH(QString, language);
68 QFETCH(QString, from);
69 QFETCH(QString, to);
70
71 TalkGenerator t(this);
72 t.setLang(language);
73 QString corrected = t.correctString(from);
74 QCOMPARE(corrected, to);
75}
76
77
78QTEST_MAIN(TestTalkGenerator)
79
80// this include is needed because we don't use a separate header file for the
81// test class. It also needs to be at the end.
82#include "test-talkgenerator.moc"
83
diff --git a/utils/rbutilqt/test/test-talkgenerator.qrc b/utils/rbutilqt/test/test-talkgenerator.qrc
new file mode 100644
index 0000000000..4855e78732
--- /dev/null
+++ b/utils/rbutilqt/test/test-talkgenerator.qrc
@@ -0,0 +1,5 @@
1<RCC>
2 <qresource prefix="/">
3 <file alias="builtin/voice-corrections.txt">../../../tools/voice-corrections.txt</file>
4 </qresource>
5</RCC>