diff options
Diffstat (limited to 'utils/rbutilqt')
-rw-r--r-- | utils/rbutilqt/CMakeLists.txt | 17 | ||||
-rw-r--r-- | utils/rbutilqt/test/stubs/stubs-talkgenerator.cpp | 104 | ||||
-rw-r--r-- | utils/rbutilqt/test/test-talkgenerator.cpp | 83 | ||||
-rw-r--r-- | utils/rbutilqt/test/test-talkgenerator.qrc | 5 |
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) | |||
406 | qtest_discover_tests(test_rockboxinfo) | 406 | qtest_discover_tests(test_rockboxinfo) |
407 | set_property(TARGET test_rockboxinfo PROPERTY AUTOMOC ON) | 407 | set_property(TARGET test_rockboxinfo PROPERTY AUTOMOC ON) |
408 | 408 | ||
409 | add_executable(test_talkgenerator | ||
410 | base/talkgenerator.cpp | ||
411 | base/talkgenerator.h | ||
412 | base/encttssettings.cpp | ||
413 | base/encttssettings.h | ||
414 | base/ttsbase.h | ||
415 | test/stubs/stubs-talkgenerator.cpp | ||
416 | test/test-talkgenerator.qrc | ||
417 | test/test-talkgenerator.cpp) | ||
418 | |||
419 | target_link_libraries(test_talkgenerator Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Test) | ||
420 | target_include_directories(test_talkgenerator PRIVATE base test/stubs | ||
421 | ${CMAKE_CURRENT_LIST_DIR}/../../tools) | ||
422 | target_compile_definitions(test_talkgenerator PRIVATE UNICODE) | ||
423 | qtest_discover_tests(test_talkgenerator) | ||
424 | set_property(TARGET test_talkgenerator PROPERTY AUTOMOC ON) | ||
425 | set_property(TARGET test_talkgenerator PROPERTY AUTORCC ON) | ||
409 | 426 | ||
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 | |||
28 | extern "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 | |||
37 | static QMap<RbSettings::UserSettings, QVariant> stubUserSettings; | ||
38 | |||
39 | QVariant 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 | |||
50 | class TTSFakeEspeak : public TTSBase | ||
51 | { | ||
52 | Q_OBJECT | ||
53 | public: | ||
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 | |||
66 | TTSBase::TTSBase(QObject* parent) : EncTtsSettingInterface(parent) | ||
67 | { | ||
68 | } | ||
69 | |||
70 | TTSStatus TTSBase::voice(QString /*text*/, QString /*wavfile*/, QString* /*errStr*/) | ||
71 | { | ||
72 | return NoError; | ||
73 | } | ||
74 | |||
75 | TTSBase* TTSBase::getTTS(QObject* parent, QString /*ttsName*/) | ||
76 | { | ||
77 | return new TTSFakeEspeak(parent); | ||
78 | } | ||
79 | |||
80 | EncoderBase* EncoderBase::getEncoder(QObject*, QString) | ||
81 | { | ||
82 | return nullptr; | ||
83 | } | ||
84 | |||
85 | QVariant PlayerBuildInfo::value(PlayerBuildInfo::DeviceInfo /*item*/, QString /*target*/) | ||
86 | { | ||
87 | return QVariant(); | ||
88 | } | ||
89 | |||
90 | PlayerBuildInfo* PlayerBuildInfo::infoInstance = nullptr; | ||
91 | |||
92 | PlayerBuildInfo::PlayerBuildInfo() | ||
93 | { | ||
94 | } | ||
95 | |||
96 | PlayerBuildInfo* 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 | |||
26 | class TestTalkGenerator : public QObject | ||
27 | { | ||
28 | Q_OBJECT | ||
29 | private slots: | ||
30 | void testCorrectString(); | ||
31 | void testCorrectString_data(); | ||
32 | }; | ||
33 | |||
34 | |||
35 | |||
36 | void 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 | |||
65 | void 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 | |||
78 | QTEST_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> | ||