2026-10-12 13:43:50 +08:00
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
|
|
#include "transcript.h"
|
|
|
|
|
|
|
|
|
|
// 输出解析:Qwen3-ASR 的原始输出形如 "language English<asr_text>正文"
|
|
|
|
|
class TstTranscript : public QObject {
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void splitsLanguageAndText()
|
|
|
|
|
{
|
|
|
|
|
const auto r = lc::parseAsrOutput("language English<asr_text>He hoped there would be stew.");
|
|
|
|
|
QCOMPARE(QString::fromStdString(r.language), QString("English"));
|
|
|
|
|
QCOMPARE(QString::fromStdString(r.text), QString("He hoped there would be stew."));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handlesChinese()
|
|
|
|
|
{
|
|
|
|
|
const auto r = lc::parseAsrOutput("language Chinese<asr_text>不排除购房者可以在互联网上下单。");
|
|
|
|
|
QCOMPARE(QString::fromStdString(r.language), QString("Chinese"));
|
|
|
|
|
QCOMPARE(QString::fromStdString(r.text), QString("不排除购房者可以在互联网上下单。"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void withoutMarkerKeepsWholeText()
|
|
|
|
|
{
|
|
|
|
|
const auto r = lc::parseAsrOutput(" just text ");
|
|
|
|
|
QVERIFY(r.language.empty());
|
|
|
|
|
QCOMPARE(QString::fromStdString(r.text), QString("just text"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void trimsSurroundingWhitespaceOfBody()
|
|
|
|
|
{
|
|
|
|
|
const auto r = lc::parseAsrOutput("language English<asr_text> hi there ");
|
|
|
|
|
QCOMPARE(QString::fromStdString(r.text), QString("hi there"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void displayNameMapping()
|
|
|
|
|
{
|
|
|
|
|
QCOMPARE(QString::fromStdString(lc::languageDisplayName("English")), QString("英语"));
|
|
|
|
|
QCOMPARE(QString::fromStdString(lc::languageDisplayName("Chinese")), QString("中文"));
|
|
|
|
|
// 未收录的语言原样返回
|
|
|
|
|
QCOMPARE(QString::fromStdString(lc::languageDisplayName("Klingon")), QString("Klingon"));
|
|
|
|
|
QVERIFY(lc::languageDisplayName("").empty());
|
|
|
|
|
}
|
2026-10-12 17:48:21 +08:00
|
|
|
|
|
|
|
|
// 设置里的语言提示是 ISO 码,界面要把它显示成中文名。
|
|
|
|
|
// 覆盖注册表里出现过的所有语言码,避免加了模型却漏了显示名。
|
|
|
|
|
void isoCodeDisplayName()
|
|
|
|
|
{
|
|
|
|
|
const struct { const char * code; const char * display; } kCases[] = {
|
|
|
|
|
{ "zh", "中文" }, { "en", "英语" }, { "ja", "日语" },
|
|
|
|
|
{ "ko", "韩语" }, { "fr", "法语" }, { "de", "德语" },
|
|
|
|
|
{ "es", "西班牙语" },{ "ru", "俄语" }, { "ar", "阿拉伯语" },
|
|
|
|
|
{ "hi", "印地语" }, { "vi", "越南语" }, { "it", "意大利语" },
|
|
|
|
|
{ "pt", "葡萄牙语" },{ "nl", "荷兰语" }, { "tr", "土耳其语" },
|
|
|
|
|
{ "uk", "乌克兰语" },{ "auto", "自动检测" },
|
|
|
|
|
};
|
|
|
|
|
for (const auto & c : kCases) {
|
|
|
|
|
QCOMPARE(QString::fromStdString(lc::languageDisplayNameFromCode(c.code)),
|
|
|
|
|
QString::fromUtf8(c.display));
|
|
|
|
|
}
|
|
|
|
|
// 未知码原样返回;空串返回空
|
|
|
|
|
QCOMPARE(QString::fromStdString(lc::languageDisplayNameFromCode("xx")), QString("xx"));
|
|
|
|
|
QVERIFY(lc::languageDisplayNameFromCode("").empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 注册表里每个模型声明的语言都必须能显示成中文名,
|
|
|
|
|
// 否则设置里的「识别语言」下拉会出现英文码。
|
|
|
|
|
void registryLanguagesAllHaveDisplayNames()
|
|
|
|
|
{
|
|
|
|
|
for (const char * code : { "zh", "en", "ja", "ko", "fr", "de", "es", "ru", "ar",
|
|
|
|
|
"hi", "vi", "it", "pt", "nl", "tr", "uk" }) {
|
|
|
|
|
const QString display =
|
|
|
|
|
QString::fromStdString(lc::languageDisplayNameFromCode(code));
|
|
|
|
|
QVERIFY2(display != QString::fromLatin1(code),
|
|
|
|
|
qPrintable(QStringLiteral("语言码没有显示名: %1").arg(code)));
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-10-12 13:43:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QTEST_MAIN(TstTranscript)
|
|
|
|
|
#include "tst_transcript.moc"
|