TST_TSTranslation refactoring. An error shouldn't stop test anymore.
--HG-- branch : develop
This commit is contained in:
parent
0cdd058eb4
commit
ec800565d7
|
@ -33,6 +33,8 @@
|
|||
#include <QDomDocument>
|
||||
#include <QtTest>
|
||||
|
||||
Q_DECLARE_METATYPE(QDomElement) // Need for testing
|
||||
|
||||
const QString TST_TSTranslation::TagName = QStringLiteral("name");
|
||||
const QString TST_TSTranslation::TagMessage = QStringLiteral("message");
|
||||
const QString TST_TSTranslation::TagSource = QStringLiteral("source");
|
||||
|
@ -44,20 +46,24 @@ const QString TST_TSTranslation::AttrValUnfinished = QStringLiteral("unfinished"
|
|||
const QString TST_TSTranslation::AttrValObsolete = QStringLiteral("obsolete");
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
TST_TSTranslation::TST_TSTranslation(QObject *parent) :
|
||||
QObject(parent),
|
||||
TST_TSTranslation::TST_TSTranslation(QObject *parent)
|
||||
: QObject(parent),
|
||||
tsFile(),
|
||||
tsXML()
|
||||
{
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_TSTranslation::CheckEnglishLocalization()
|
||||
void TST_TSTranslation::CheckEnglishLocalization_data()
|
||||
{
|
||||
const QDomNodeList messages = LoadTSFile(QStringLiteral("valentina_en_US.ts"));
|
||||
QTest::addColumn<QString>("source");
|
||||
QTest::addColumn<QString>("translation");
|
||||
|
||||
const QString fileName = QStringLiteral("valentina_en_US.ts");
|
||||
const QDomNodeList messages = LoadTSFile(fileName);
|
||||
if (messages.isEmpty())
|
||||
{
|
||||
QSKIP("Can't begin test.");
|
||||
QFAIL("Can't begin test.");
|
||||
}
|
||||
|
||||
for (qint32 i = 0, num = messages.size(); i < num; ++i)
|
||||
|
@ -86,7 +92,9 @@ void TST_TSTranslation::CheckEnglishLocalization()
|
|||
continue;
|
||||
}
|
||||
|
||||
QCOMPARE(source, translation);
|
||||
const QString message = QString("File '%1'. Check modification source message '%2'.").arg(fileName)
|
||||
.arg(source);
|
||||
QTest::newRow(qUtf8Printable(message)) << source << translation;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -97,12 +105,25 @@ void TST_TSTranslation::CheckEnglishLocalization()
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_TSTranslation::CheckEmptyToolButton()
|
||||
void TST_TSTranslation::CheckEnglishLocalization()
|
||||
{
|
||||
const QDomNodeList messages = LoadTSFile(QStringLiteral("valentina.ts"));
|
||||
QFETCH(QString, source);
|
||||
QFETCH(QString, translation);
|
||||
|
||||
QCOMPARE(source, translation);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_TSTranslation::CheckEmptyToolButton_data()
|
||||
{
|
||||
QTest::addColumn<QString>("source");
|
||||
QTest::addColumn<QDomElement>("message");
|
||||
|
||||
const QString fileName = QStringLiteral("valentina.ts");
|
||||
const QDomNodeList messages = LoadTSFile(fileName);
|
||||
if (messages.isEmpty())
|
||||
{
|
||||
QSKIP("Can't begin test.");
|
||||
QFAIL("Can't begin test.");
|
||||
}
|
||||
|
||||
for (qint32 i = 0, num = messages.size(); i < num; ++i)
|
||||
|
@ -116,6 +137,24 @@ void TST_TSTranslation::CheckEmptyToolButton()
|
|||
continue;
|
||||
}
|
||||
|
||||
const QString tag = QString("File '%1'. Check modification source message '%2'.").arg(fileName)
|
||||
.arg(source);
|
||||
QTest::newRow(qUtf8Printable(tag)) << source << message;
|
||||
}
|
||||
else
|
||||
{
|
||||
const QString message = QString("Message %1 is null.").arg(i);
|
||||
QFAIL(qUtf8Printable(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_TSTranslation::CheckEmptyToolButton()
|
||||
{
|
||||
QFETCH(QString, source);
|
||||
QFETCH(QDomElement, message);
|
||||
|
||||
if (source == QLatin1String("..."))
|
||||
{
|
||||
const QDomElement translationTag = message.firstChildElement(TagTranslation);
|
||||
|
@ -124,7 +163,7 @@ void TST_TSTranslation::CheckEmptyToolButton()
|
|||
const QString attrVal = translationTag.attribute(AttrType);
|
||||
if (attrVal == AttrValVanished || attrVal == AttrValObsolete)
|
||||
{
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,13 +178,6 @@ void TST_TSTranslation::CheckEmptyToolButton()
|
|||
QFAIL(qUtf8Printable(error));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const QString message = QString("Message %1 is null.").arg(i);
|
||||
QFAIL(qUtf8Printable(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_TSTranslation::CheckPlaceMarkerExist_data()
|
||||
|
@ -158,25 +190,17 @@ void TST_TSTranslation::CheckPlaceMarkerExist_data()
|
|||
QVERIFY2(locales.size() == fileNames.size()-1, "Unexpected count of files.");
|
||||
}
|
||||
|
||||
QTest::addColumn<QString>("filename");
|
||||
QTest::addColumn<QString>("source");
|
||||
QTest::addColumn<QString>("translation");
|
||||
|
||||
for(int i = 0; i < locales.size(); ++i)
|
||||
for(int j = 0; j < locales.size(); ++j)
|
||||
{
|
||||
const QString filename = QString("valentina_%1.ts").arg(locales.at(i));
|
||||
const QString tag = QString("Check localization strings valentina_%1.ts").arg(locales.at(i));
|
||||
QTest::newRow(qUtf8Printable(tag)) << filename;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_TSTranslation::CheckPlaceMarkerExist()
|
||||
{
|
||||
QFETCH(QString, filename);
|
||||
const QString filename = QString("valentina_%1.ts").arg(locales.at(j));
|
||||
|
||||
const QDomNodeList messages = LoadTSFile(filename);
|
||||
if (messages.isEmpty())
|
||||
{
|
||||
QSKIP("Can't begin test.");
|
||||
QFAIL("Can't begin test.");
|
||||
}
|
||||
|
||||
for (qint32 i = 0, num = messages.size(); i < num; ++i)
|
||||
|
@ -205,6 +229,25 @@ void TST_TSTranslation::CheckPlaceMarkerExist()
|
|||
continue;
|
||||
}
|
||||
|
||||
const QString message = QString("File '%1'. Check place holder source message '%2'").arg(filename)
|
||||
.arg(source);
|
||||
QTest::newRow(qUtf8Printable(message)) << source << translation;
|
||||
}
|
||||
else
|
||||
{
|
||||
const QString message = QString("File '%2'. Message %1 is null.").arg(i).arg(filename);
|
||||
QFAIL(qUtf8Printable(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_TSTranslation::CheckPlaceMarkerExist()
|
||||
{
|
||||
QFETCH(QString, source);
|
||||
QFETCH(QString, translation);
|
||||
|
||||
int sourceMarkCount = 0;
|
||||
int translationMarkCount = 0;
|
||||
|
||||
|
@ -246,14 +289,6 @@ void TST_TSTranslation::CheckPlaceMarkerExist()
|
|||
QFAIL(qUtf8Printable(message));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
const QString message = QString("Message %1 is null.").arg(i);
|
||||
QFAIL(qUtf8Printable(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -282,8 +317,8 @@ QDomNodeList TST_TSTranslation::LoadTSFile(const QString &filename)
|
|||
tsXML = QSharedPointer<QDomDocument>(new QDomDocument());
|
||||
if (tsXML->setContent(tsFile.data(), &errorMsg, &errorLine, &errorColumn) == false)
|
||||
{
|
||||
const QString message = QString("Parsing error file valentina_en_US.ts in line %1 column %2.")
|
||||
.arg(errorLine).arg(errorColumn);
|
||||
const QString message = QString("Parsing error file %1 in line %2 column %3.")
|
||||
.arg(filename).arg(errorLine).arg(errorColumn);
|
||||
QWARN(qUtf8Printable(message));
|
||||
return QDomNodeList();
|
||||
}
|
||||
|
|
|
@ -41,7 +41,9 @@ public:
|
|||
explicit TST_TSTranslation(QObject *parent = nullptr);
|
||||
|
||||
private slots:
|
||||
void CheckEnglishLocalization_data();
|
||||
void CheckEnglishLocalization();
|
||||
void CheckEmptyToolButton_data();
|
||||
void CheckEmptyToolButton();
|
||||
void CheckPlaceMarkerExist_data();
|
||||
void CheckPlaceMarkerExist();
|
||||
|
|
Loading…
Reference in New Issue
Block a user