summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2022-03-23 19:11:13 +0100
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2022-03-23 19:34:30 +0100
commit1aea2d5b7e3b5f9ac7f8abdcdce57eeddf46e48d (patch)
treef35ffaec079a68ed380b8fb414307b06353277d4
parent822b16b1c6d7b406981ab7177b784479cd37e1a6 (diff)
downloadrockbox-1aea2d5b7e.tar.gz
rockbox-1aea2d5b7e.zip
rbutil: Test for talkgenerator string correction.
Change-Id: I4c21dbbdae492938061883f1694f9c0f7b6b0fd9
-rw-r--r--utils/rbutilqt/CMakeLists.txt17
-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
4 files changed, 209 insertions, 0 deletions
diff --git a/utils/rbutilqt/CMakeLists.txt b/utils/rbutilqt/CMakeLists.txt
index 2293b8ebc4..6b4062c266 100644
--- a/utils/rbutilqt/CMakeLists.txt
+++ b/utils/rbutilqt/CMakeLists.txt
@@ -406,4 +406,21 @@ target_compile_definitions(test_rockboxinfo PRIVATE UNICODE)
qtest_discover_tests(test_rockboxinfo)
set_property(TARGET test_rockboxinfo PROPERTY AUTOMOC ON)
+add_executable(test_talkgenerator
+ base/talkgenerator.cpp
+ base/talkgenerator.h
+ base/encttssettings.cpp
+ base/encttssettings.h
+ base/ttsbase.h
+ test/stubs/stubs-talkgenerator.cpp
+ test/test-talkgenerator.qrc
+ test/test-talkgenerator.cpp)
+
+target_link_libraries(test_talkgenerator Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Test)
+target_include_directories(test_talkgenerator PRIVATE base test/stubs
+ ${CMAKE_CURRENT_LIST_DIR}/../../tools)
+target_compile_definitions(test_talkgenerator PRIVATE UNICODE)
+qtest_discover_tests(test_talkgenerator)
+set_property(TARGET test_talkgenerator PROPERTY AUTOMOC ON)
+set_property(TARGET test_talkgenerator PROPERTY AUTORCC ON)
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 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2022 Dominik Riebeling
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+// Stubs for TalkGenerator unit test.
+
+#include "rbsettings.h"
+#include "ttsbase.h"
+#include "encoderbase.h"
+#include "playerbuildinfo.h"
+
+extern "C" int wavtrim(char* filename, int maxsilence, char* errstring, int errsize)
+{
+ (void)filename;
+ (void)maxsilence;
+ (void)errstring;
+ (void)errsize;
+ return 0;
+}
+
+static QMap<RbSettings::UserSettings, QVariant> stubUserSettings;
+
+QVariant RbSettings::value(UserSettings setting)
+{
+ switch (setting)
+ {
+ case RbSettings::Tts:
+ return QString("espeak");
+ default:
+ return QVariant();
+ }
+}
+
+class TTSFakeEspeak : public TTSBase
+{
+ Q_OBJECT
+public:
+ TTSFakeEspeak(QObject *parent): TTSBase(parent) {}
+ virtual bool start(QString *errStr) { (void)errStr; return true; }
+ virtual bool stop() { return true; }
+ virtual TTSStatus voice(QString text, QString wavfile, QString *errStr)
+ { (void)text; (void)wavfile; (void)errStr; return NoError; }
+ virtual QString voiceVendor() { return QString("DummyVendor"); }
+ virtual bool configOk() { return true; }
+ virtual void generateSettings() {}
+ virtual void saveSettings() {}
+ virtual Capabilities capabilities() { return None; }
+};
+
+TTSBase::TTSBase(QObject* parent) : EncTtsSettingInterface(parent)
+{
+}
+
+TTSStatus TTSBase::voice(QString /*text*/, QString /*wavfile*/, QString* /*errStr*/)
+{
+ return NoError;
+}
+
+TTSBase* TTSBase::getTTS(QObject* parent, QString /*ttsName*/)
+{
+ return new TTSFakeEspeak(parent);
+}
+
+EncoderBase* EncoderBase::getEncoder(QObject*, QString)
+{
+ return nullptr;
+}
+
+QVariant PlayerBuildInfo::value(PlayerBuildInfo::DeviceInfo /*item*/, QString /*target*/)
+{
+ return QVariant();
+}
+
+PlayerBuildInfo* PlayerBuildInfo::infoInstance = nullptr;
+
+PlayerBuildInfo::PlayerBuildInfo()
+{
+}
+
+PlayerBuildInfo* PlayerBuildInfo::instance()
+{
+ if (infoInstance == nullptr) {
+ infoInstance = new PlayerBuildInfo();
+ }
+ return infoInstance;
+}
+
+#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 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2022 Dominik Riebeling
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QObject>
+#include "talkgenerator.h"
+
+
+class TestTalkGenerator : public QObject
+{
+ Q_OBJECT
+ private slots:
+ void testCorrectString();
+ void testCorrectString_data();
+};
+
+
+
+void TestTalkGenerator::testCorrectString_data()
+{
+ struct {
+ const char* language;
+ const char* from;
+ const char* to;
+ } const correctdata[] =
+ {
+ { "english", "dummy text", "dummy text" },
+ { "deutsch", "alkaline", "alkalein" },
+ { "deutsch", "Batterie Typ Alkaline", "Batterie Typ alkalein" },
+ { "deutsch", "512 kilobytes frei", "512 kilobeits frei" },
+ // AT&T engine only.
+ { "deutsch", "alphabet", "alphabet" },
+
+ // espeak
+ {"svenska", "5 ampere", "5 ampär" },
+ {"svenska", "bokmärken...", "bok-märken..." },
+ };
+
+ QTest::addColumn<QString>("language");
+ QTest::addColumn<QString>("from");
+ QTest::addColumn<QString>("to");
+ for(size_t i = 0; i < sizeof(correctdata) / sizeof(correctdata[0]); i++) {
+ QTest::newRow(correctdata[i].from)
+ << correctdata[i].language << correctdata[i].from << correctdata[i].to;
+ }
+}
+
+void TestTalkGenerator::testCorrectString()
+{
+ QFETCH(QString, language);
+ QFETCH(QString, from);
+ QFETCH(QString, to);
+
+ TalkGenerator t(this);
+ t.setLang(language);
+ QString corrected = t.correctString(from);
+ QCOMPARE(corrected, to);
+}
+
+
+QTEST_MAIN(TestTalkGenerator)
+
+// this include is needed because we don't use a separate header file for the
+// test class. It also needs to be at the end.
+#include "test-talkgenerator.moc"
+
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 @@
+<RCC>
+ <qresource prefix="/">
+ <file alias="builtin/voice-corrections.txt">../../../tools/voice-corrections.txt</file>
+ </qresource>
+</RCC>