TST_TSTranslation refactoring. An error shouldn't stop test anymore.

(grafted from 49c0b5d59998c1ef3a100e9c0defab8ba30c5508)

--HG--
branch : release
This commit is contained in:
Roman Telezhynskyi 2016-08-03 19:59:57 +03:00
parent d6eb42dbe6
commit 08c80f6a3d
2 changed files with 149 additions and 112 deletions

View File

@ -33,6 +33,8 @@
#include <QDomDocument> #include <QDomDocument>
#include <QtTest> #include <QtTest>
Q_DECLARE_METATYPE(QDomElement) // Need for testing
const QString TST_TSTranslation::TagName = QStringLiteral("name"); const QString TST_TSTranslation::TagName = QStringLiteral("name");
const QString TST_TSTranslation::TagMessage = QStringLiteral("message"); const QString TST_TSTranslation::TagMessage = QStringLiteral("message");
const QString TST_TSTranslation::TagSource = QStringLiteral("source"); 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"); const QString TST_TSTranslation::AttrValObsolete = QStringLiteral("obsolete");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
TST_TSTranslation::TST_TSTranslation(QObject *parent) : TST_TSTranslation::TST_TSTranslation(QObject *parent)
QObject(parent), : QObject(parent),
tsFile(), tsFile(),
tsXML() 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()) if (messages.isEmpty())
{ {
QSKIP("Can't begin test."); QFAIL("Can't begin test.");
} }
for (qint32 i = 0, num = messages.size(); i < num; ++i) for (qint32 i = 0, num = messages.size(); i < num; ++i)
@ -86,7 +92,9 @@ void TST_TSTranslation::CheckEnglishLocalization()
continue; 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 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()) if (messages.isEmpty())
{ {
QSKIP("Can't begin test."); QFAIL("Can't begin test.");
} }
for (qint32 i = 0, num = messages.size(); i < num; ++i) for (qint32 i = 0, num = messages.size(); i < num; ++i)
@ -116,7 +137,25 @@ void TST_TSTranslation::CheckEmptyToolButton()
continue; continue;
} }
if (source == QLatin1Literal("...")) 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); const QDomElement translationTag = message.firstChildElement(TagTranslation);
if (translationTag.hasAttribute(AttrType)) if (translationTag.hasAttribute(AttrType))
@ -124,7 +163,7 @@ void TST_TSTranslation::CheckEmptyToolButton()
const QString attrVal = translationTag.attribute(AttrType); const QString attrVal = translationTag.attribute(AttrType);
if (attrVal == AttrValVanished || attrVal == AttrValObsolete) if (attrVal == AttrValVanished || attrVal == AttrValObsolete)
{ {
continue; return;
} }
} }
@ -139,13 +178,6 @@ void TST_TSTranslation::CheckEmptyToolButton()
QFAIL(qUtf8Printable(error)); QFAIL(qUtf8Printable(error));
} }
} }
else
{
const QString message = QString("Message %1 is null.").arg(i);
QFAIL(qUtf8Printable(message));
}
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TST_TSTranslation::CheckPlaceMarkerExist_data() void TST_TSTranslation::CheckPlaceMarkerExist_data()
@ -158,25 +190,17 @@ void TST_TSTranslation::CheckPlaceMarkerExist_data()
QVERIFY2(locales.size() == fileNames.size()-1, "Unexpected count of files."); 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 filename = QString("valentina_%1.ts").arg(locales.at(j));
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 QDomNodeList messages = LoadTSFile(filename); const QDomNodeList messages = LoadTSFile(filename);
if (messages.isEmpty()) if (messages.isEmpty())
{ {
QSKIP("Can't begin test."); QFAIL("Can't begin test.");
} }
for (qint32 i = 0, num = messages.size(); i < num; ++i) for (qint32 i = 0, num = messages.size(); i < num; ++i)
@ -205,12 +229,31 @@ void TST_TSTranslation::CheckPlaceMarkerExist()
continue; 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 sourceMarkCount = 0;
int translationMarkCount = 0; int translationMarkCount = 0;
for (int i = 1; i <= 99; ++i) for (int i = 1; i <= 99; ++i)
{ {
const QString marker = QLatin1Literal("%") + QString().setNum(i); const QString marker = QLatin1String("%") + QString().setNum(i);
const bool sourceMark = source.indexOf(marker) != -1; const bool sourceMark = source.indexOf(marker) != -1;
if (sourceMark) if (sourceMark)
{ {
@ -218,8 +261,8 @@ void TST_TSTranslation::CheckPlaceMarkerExist()
if (sourceMarkCount != i) if (sourceMarkCount != i)
{ {
const QString message = QString("In source string '%1' was missed place marker ") const QString message = QString("In source string '%1' was missed place marker ")
.arg(source) + QLatin1Literal("'%") + QString().setNum(sourceMarkCount) + .arg(source) + QLatin1String("'%") + QString().setNum(sourceMarkCount) +
QLatin1Literal("'."); QLatin1String("'.");
QFAIL(qUtf8Printable(message)); QFAIL(qUtf8Printable(message));
} }
} }
@ -231,8 +274,8 @@ void TST_TSTranslation::CheckPlaceMarkerExist()
if (translationMarkCount != i) if (translationMarkCount != i)
{ {
const QString message = QString("In translation string '%1' was missed place marker ") const QString message = QString("In translation string '%1' was missed place marker ")
.arg(translation) + QLatin1Literal("'%") + QString().setNum(translationMarkCount) + .arg(translation) + QLatin1String("'%") + QString().setNum(translationMarkCount) +
QLatin1Literal("'."); QLatin1String("'.");
QFAIL(qUtf8Printable(message)); QFAIL(qUtf8Printable(message));
} }
} }
@ -241,16 +284,8 @@ void TST_TSTranslation::CheckPlaceMarkerExist()
{ {
const QString message = const QString message =
QString("Compare to source string in the translation string '%1' was missed place marker ") QString("Compare to source string in the translation string '%1' was missed place marker ")
.arg(translation) + QLatin1Literal("'%") + QString().setNum(sourceMarkCount) + .arg(translation) + QLatin1String("'%") + QString().setNum(sourceMarkCount) +
QLatin1Literal("'."); QLatin1String("'.");
QFAIL(qUtf8Printable(message));
}
}
}
else
{
const QString message = QString("Message %1 is null.").arg(i);
QFAIL(qUtf8Printable(message)); QFAIL(qUtf8Printable(message));
} }
} }
@ -282,8 +317,8 @@ QDomNodeList TST_TSTranslation::LoadTSFile(const QString &filename)
tsXML = QSharedPointer<QDomDocument>(new QDomDocument()); tsXML = QSharedPointer<QDomDocument>(new QDomDocument());
if (tsXML->setContent(tsFile.data(), &errorMsg, &errorLine, &errorColumn) == false) 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.") const QString message = QString("Parsing error file %1 in line %2 column %3.")
.arg(errorLine).arg(errorColumn); .arg(filename).arg(errorLine).arg(errorColumn);
QWARN(qUtf8Printable(message)); QWARN(qUtf8Printable(message));
return QDomNodeList(); return QDomNodeList();
} }

View File

@ -41,7 +41,9 @@ public:
explicit TST_TSTranslation(QObject *parent = 0); explicit TST_TSTranslation(QObject *parent = 0);
private slots: private slots:
void CheckEnglishLocalization_data();
void CheckEnglishLocalization(); void CheckEnglishLocalization();
void CheckEmptyToolButton_data();
void CheckEmptyToolButton(); void CheckEmptyToolButton();
void CheckPlaceMarkerExist_data(); void CheckPlaceMarkerExist_data();
void CheckPlaceMarkerExist(); void CheckPlaceMarkerExist();