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

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-08-03 19:56:04 +03:00
parent 0cdd058eb4
commit ec800565d7
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,6 +137,24 @@ void TST_TSTranslation::CheckEmptyToolButton()
continue; 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("...")) if (source == QLatin1String("..."))
{ {
const QDomElement translationTag = message.firstChildElement(TagTranslation); const QDomElement translationTag = message.firstChildElement(TagTranslation);
@ -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;
} }
} }
@ -138,13 +177,6 @@ void TST_TSTranslation::CheckEmptyToolButton()
const QString error = QString("Found '...' in context '%1'").arg(contextName); const QString error = QString("Found '...' in context '%1'").arg(contextName);
QFAIL(qUtf8Printable(error)); QFAIL(qUtf8Printable(error));
} }
}
else
{
const QString message = QString("Message %1 is null.").arg(i);
QFAIL(qUtf8Printable(message));
}
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -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,6 +229,25 @@ 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;
@ -246,14 +289,6 @@ void TST_TSTranslation::CheckPlaceMarkerExist()
QFAIL(qUtf8Printable(message)); 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()); 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 = nullptr); explicit TST_TSTranslation(QObject *parent = nullptr);
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();