rbutil: Test for talkgenerator string correction.

Change-Id: I4c21dbbdae492938061883f1694f9c0f7b6b0fd9
This commit is contained in:
Dominik Riebeling 2022-03-23 19:11:13 +01:00
parent 822b16b1c6
commit 1aea2d5b7e
4 changed files with 209 additions and 0 deletions

View file

@ -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)

View file

@ -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"

View file

@ -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"

View file

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file alias="builtin/voice-corrections.txt">../../../tools/voice-corrections.txt</file>
</qresource>
</RCC>