2015-12-13 17:33:00 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file tst_tstranslation.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 13 12, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-12-13 17:33:00 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2015-12-13 17:33:00 +01:00
|
|
|
**
|
|
|
|
** Valentina 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 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "tst_tstranslation.h"
|
2015-12-14 11:49:48 +01:00
|
|
|
#include "../vmisc/def.h"
|
2015-12-13 17:33:00 +01:00
|
|
|
|
|
|
|
#include <QDomDocument>
|
|
|
|
#include <QtTest>
|
|
|
|
|
2016-08-03 18:56:04 +02:00
|
|
|
Q_DECLARE_METATYPE(QDomElement) // Need for testing
|
|
|
|
|
2015-12-13 17:33:00 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-08-03 18:56:04 +02:00
|
|
|
TST_TSTranslation::TST_TSTranslation(QObject *parent)
|
2018-02-17 19:26:25 +01:00
|
|
|
: TST_AbstractTranslation(parent)
|
|
|
|
{}
|
2015-12-13 17:33:00 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-08-03 18:56:04 +02:00
|
|
|
void TST_TSTranslation::CheckEnglishLocalization_data()
|
2015-12-13 17:33:00 +01:00
|
|
|
{
|
2016-08-03 18:56:04 +02:00
|
|
|
QTest::addColumn<QString>("source");
|
|
|
|
QTest::addColumn<QString>("translation");
|
|
|
|
|
|
|
|
const QString fileName = QStringLiteral("valentina_en_US.ts");
|
|
|
|
const QDomNodeList messages = LoadTSFile(fileName);
|
2015-12-13 17:33:00 +01:00
|
|
|
if (messages.isEmpty())
|
|
|
|
{
|
2016-08-03 18:56:04 +02:00
|
|
|
QFAIL("Can't begin test.");
|
2015-12-13 17:33:00 +01:00
|
|
|
}
|
|
|
|
|
2015-12-14 10:56:21 +01:00
|
|
|
for (qint32 i = 0, num = messages.size(); i < num; ++i)
|
2015-12-13 17:33:00 +01:00
|
|
|
{
|
|
|
|
const QDomElement message = messages.at(i).toElement();
|
2022-08-08 14:25:14 +02:00
|
|
|
if (not message.isNull())
|
2015-12-13 17:33:00 +01:00
|
|
|
{
|
2015-12-14 10:56:21 +01:00
|
|
|
const QString source = message.firstChildElement(TagSource).text();
|
2015-12-13 17:33:00 +01:00
|
|
|
if (source.isEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-12-14 10:56:21 +01:00
|
|
|
const QDomElement translationTag = message.firstChildElement(TagTranslation);
|
|
|
|
if (translationTag.hasAttribute(AttrType))
|
2015-12-13 17:33:00 +01:00
|
|
|
{
|
2015-12-14 10:56:21 +01:00
|
|
|
const QString attrVal = translationTag.attribute(AttrType);
|
2015-12-14 17:05:09 +01:00
|
|
|
if (attrVal == AttrValVanished || attrVal == AttrValUnfinished || attrVal == AttrValObsolete)
|
2015-12-13 17:33:00 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2015-12-13 18:29:39 +01:00
|
|
|
const QString translation = translationTag.text();
|
2015-12-13 17:33:00 +01:00
|
|
|
if (translation.isEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-08-08 14:25:14 +02:00
|
|
|
const QString caseName = QStringLiteral("File '%1'. Check modification source message '%2'.")
|
|
|
|
.arg(fileName, source);
|
|
|
|
QTest::newRow(qUtf8Printable(caseName)) << source << translation;
|
2015-12-13 17:33:00 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-08 14:25:14 +02:00
|
|
|
const QString caseName = QStringLiteral("Message %1 is null.").arg(i);
|
|
|
|
QFAIL(qUtf8Printable(caseName));
|
2015-12-13 17:33:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-14 08:41:42 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-08-03 18:56:04 +02:00
|
|
|
void TST_TSTranslation::CheckEnglishLocalization()
|
2015-12-14 08:41:42 +01:00
|
|
|
{
|
2016-08-03 18:56:04 +02:00
|
|
|
QFETCH(QString, source);
|
|
|
|
QFETCH(QString, translation);
|
|
|
|
|
|
|
|
QCOMPARE(source, translation);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TST_TSTranslation::CheckEmptyToolButton_data()
|
|
|
|
{
|
2017-09-24 09:33:35 +02:00
|
|
|
PrepareOriginalStrings();
|
2015-12-14 08:41:42 +01:00
|
|
|
}
|
2015-12-14 10:56:21 +01:00
|
|
|
|
2015-12-14 11:49:48 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-08-03 18:56:04 +02:00
|
|
|
void TST_TSTranslation::CheckEmptyToolButton()
|
2015-12-14 11:49:48 +01:00
|
|
|
{
|
2016-08-03 18:56:04 +02:00
|
|
|
QFETCH(QString, source);
|
|
|
|
QFETCH(QDomElement, message);
|
2015-12-14 11:49:48 +01:00
|
|
|
|
2016-08-03 18:56:04 +02:00
|
|
|
if (source == QLatin1String("..."))
|
2015-12-14 11:49:48 +01:00
|
|
|
{
|
2016-08-03 18:56:04 +02:00
|
|
|
const QDomElement translationTag = message.firstChildElement(TagTranslation);
|
|
|
|
if (translationTag.hasAttribute(AttrType))
|
|
|
|
{
|
|
|
|
const QString attrVal = translationTag.attribute(AttrType);
|
|
|
|
if (attrVal == AttrValVanished || attrVal == AttrValObsolete)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-12-14 11:49:48 +01:00
|
|
|
|
2016-08-03 18:56:04 +02:00
|
|
|
const QDomNode context = message.parentNode();
|
|
|
|
if (context.isNull())
|
|
|
|
{
|
|
|
|
QFAIL("Can't get context.");
|
|
|
|
}
|
2015-12-14 11:49:48 +01:00
|
|
|
|
2016-08-03 18:56:04 +02:00
|
|
|
const QString contextName = context.firstChildElement(TagName).text();
|
|
|
|
const QString error = QString("Found '...' in context '%1'").arg(contextName);
|
|
|
|
QFAIL(qUtf8Printable(error));
|
2015-12-14 11:49:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-24 09:33:35 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TST_TSTranslation::CheckEllipsis_data()
|
|
|
|
{
|
|
|
|
PrepareOriginalStrings();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TST_TSTranslation::CheckEllipsis()
|
|
|
|
{
|
|
|
|
QFETCH(QString, source);
|
|
|
|
QFETCH(QDomElement, message);
|
|
|
|
|
|
|
|
if (source.endsWith("..."))
|
|
|
|
{
|
|
|
|
const QDomElement translationTag = message.firstChildElement(TagTranslation);
|
|
|
|
if (translationTag.hasAttribute(AttrType))
|
|
|
|
{
|
|
|
|
const QString attrVal = translationTag.attribute(AttrType);
|
|
|
|
if (attrVal == AttrValVanished || attrVal == AttrValObsolete)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDomNode context = message.parentNode();
|
|
|
|
if (context.isNull())
|
|
|
|
{
|
|
|
|
QFAIL("Can't get context.");
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString contextName = context.firstChildElement(TagName).text();
|
|
|
|
const QString error = QString("String '%1' ends with '...' in context '%2'. Repalce it with '…'.")
|
|
|
|
.arg(source, contextName);
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-27 10:25:31 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TST_TSTranslation::CheckInvalidCharacter_data()
|
|
|
|
{
|
|
|
|
PrepareOriginalStrings();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TST_TSTranslation::CheckInvalidCharacter()
|
|
|
|
{
|
|
|
|
QFETCH(QString, source);
|
|
|
|
QFETCH(QDomElement, message);
|
|
|
|
|
2020-03-27 11:30:36 +01:00
|
|
|
if (source == QChar('=') or source == QChar('%'))
|
2020-03-27 10:25:31 +01:00
|
|
|
{
|
|
|
|
const QDomNode context = message.parentNode();
|
|
|
|
if (context.isNull())
|
|
|
|
{
|
|
|
|
QFAIL("Can't get context.");
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString contextName = context.firstChildElement(TagName).text();
|
|
|
|
const QString error = QString("String contains invalid character '%1' in context '%2'. It should not be "
|
|
|
|
"marked for translation.")
|
|
|
|
.arg(source, contextName);
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-24 09:33:35 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TST_TSTranslation::PrepareOriginalStrings()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("source");
|
|
|
|
QTest::addColumn<QDomElement>("message");
|
|
|
|
|
|
|
|
const QString fileName = QStringLiteral("valentina.ts");
|
|
|
|
const QDomNodeList messages = LoadTSFile(fileName);
|
|
|
|
if (messages.isEmpty())
|
|
|
|
{
|
|
|
|
QFAIL("Can't begin test.");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (qint32 i = 0, num = messages.size(); i < num; ++i)
|
|
|
|
{
|
|
|
|
const QDomElement message = messages.at(i).toElement();
|
2022-08-08 14:25:14 +02:00
|
|
|
if (not message.isNull())
|
2017-09-24 09:33:35 +02:00
|
|
|
{
|
|
|
|
const QString source = message.firstChildElement(TagSource).text();
|
|
|
|
if (source.isEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-08-08 14:25:14 +02:00
|
|
|
const QString tag = QStringLiteral("File '%1'. Check modification source message '%2'.").arg(fileName, source);
|
2017-09-24 09:33:35 +02:00
|
|
|
QTest::newRow(qUtf8Printable(tag)) << source << message;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-08 14:25:14 +02:00
|
|
|
const QString errorMessage = QStringLiteral("Message %1 is null.").arg(i);
|
|
|
|
QFAIL(qUtf8Printable(errorMessage));
|
2017-09-24 09:33:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|