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
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2015 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** 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"
|
|
|
|
#include "../vmisc/logging.h"
|
|
|
|
|
|
|
|
#include <QDomDocument>
|
|
|
|
#include <QtTest>
|
|
|
|
|
2015-12-14 10:56:21 +01:00
|
|
|
const QString TST_TSTranslation::TagName = QStringLiteral("name");
|
|
|
|
const QString TST_TSTranslation::TagMessage = QStringLiteral("message");
|
|
|
|
const QString TST_TSTranslation::TagSource = QStringLiteral("source");
|
|
|
|
const QString TST_TSTranslation::TagTranslation = QStringLiteral("translation");
|
|
|
|
|
|
|
|
const QString TST_TSTranslation::AttrType = QStringLiteral("type");
|
|
|
|
const QString TST_TSTranslation::AttrValVanished = QStringLiteral("vanished");
|
|
|
|
const QString TST_TSTranslation::AttrValUnfinished = QStringLiteral("unfinished");
|
|
|
|
|
2015-12-13 17:33:00 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
TST_TSTranslation::TST_TSTranslation(QObject *parent) :
|
2015-12-14 10:56:21 +01:00
|
|
|
QObject(parent),
|
|
|
|
tsFile(),
|
|
|
|
tsXML()
|
2015-12-13 17:33:00 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TST_TSTranslation::CheckEnglishLocalization()
|
|
|
|
{
|
2015-12-14 10:56:21 +01:00
|
|
|
const QDomNodeList messages = LoadTSFile(QStringLiteral("valentina_en_US.ts"));
|
2015-12-13 17:33:00 +01:00
|
|
|
if (messages.isEmpty())
|
|
|
|
{
|
2015-12-14 10:56:21 +01:00
|
|
|
QSKIP("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();
|
|
|
|
if (message.isNull() == false)
|
|
|
|
{
|
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);
|
|
|
|
if (attrVal == AttrValVanished || attrVal == AttrValUnfinished)
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
QCOMPARE(source, translation);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString message = QString("Message %1 is null.").arg(i);
|
|
|
|
QFAIL(qUtf8Printable(message));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-14 08:41:42 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void TST_TSTranslation::CheckEmptyToolButton()
|
|
|
|
{
|
2015-12-14 10:56:21 +01:00
|
|
|
const QDomNodeList messages = LoadTSFile(QStringLiteral("valentina.ts"));
|
2015-12-14 08:41:42 +01:00
|
|
|
if (messages.isEmpty())
|
|
|
|
{
|
2015-12-14 10:56:21 +01:00
|
|
|
QSKIP("Can't begin test.");
|
2015-12-14 08:41:42 +01:00
|
|
|
}
|
|
|
|
|
2015-12-14 10:56:21 +01:00
|
|
|
for (qint32 i = 0, num = messages.size(); i < num; ++i)
|
2015-12-14 08:41:42 +01:00
|
|
|
{
|
|
|
|
const QDomElement message = messages.at(i).toElement();
|
|
|
|
if (message.isNull() == false)
|
|
|
|
{
|
2015-12-14 10:56:21 +01:00
|
|
|
const QString source = message.firstChildElement(TagSource).text();
|
2015-12-14 08:41:42 +01:00
|
|
|
if (source.isEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source == QLatin1Literal("..."))
|
|
|
|
{
|
2015-12-14 10:56:21 +01:00
|
|
|
const QDomElement translationTag = message.firstChildElement(TagTranslation);
|
|
|
|
if (translationTag.hasAttribute(AttrType))
|
2015-12-14 08:41:42 +01:00
|
|
|
{
|
2015-12-14 10:56:21 +01:00
|
|
|
const QString attrVal = translationTag.attribute(AttrType);
|
|
|
|
if (attrVal == AttrValVanished)
|
2015-12-14 08:41:42 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDomNode context = message.parentNode();
|
|
|
|
if (context.isNull())
|
|
|
|
{
|
|
|
|
QFAIL("Can't get context.");
|
|
|
|
}
|
|
|
|
|
2015-12-14 10:56:21 +01:00
|
|
|
const QString contextName = context.firstChildElement(TagName).text();
|
2015-12-14 08:41:42 +01:00
|
|
|
const QString error = QString("Found '...' in context '%1'").arg(contextName);
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString message = QString("Message %1 is null.").arg(i);
|
|
|
|
QFAIL(qUtf8Printable(message));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-14 10:56:21 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDomNodeList TST_TSTranslation::LoadTSFile(const QString &filename)
|
|
|
|
{
|
|
|
|
tsFile.reset();
|
|
|
|
tsFile = QSharedPointer<QFile>(new QFile(QString("%1/%2").arg(TS_DIR).arg(filename)));
|
|
|
|
if (not tsFile->exists())
|
|
|
|
{
|
|
|
|
const QString message = QString("Can't find '%1'.\n%2.").arg(filename).arg(tsFile->errorString());
|
|
|
|
QWARN(qUtf8Printable(message));
|
|
|
|
return QDomNodeList();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tsFile->open(QIODevice::ReadOnly) == false)
|
|
|
|
{
|
|
|
|
const QString message = QString("Can't open file '%1'.\n%2.").arg(filename).arg(tsFile->errorString());
|
|
|
|
QWARN(qUtf8Printable(message));
|
|
|
|
return QDomNodeList();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString errorMsg;
|
|
|
|
int errorLine = -1;
|
|
|
|
int errorColumn = -1;
|
|
|
|
tsXML.reset();
|
|
|
|
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);
|
|
|
|
QWARN(qUtf8Printable(message));
|
|
|
|
return QDomNodeList();
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDomNodeList messages = tsXML->elementsByTagName(TagMessage);
|
|
|
|
if (messages.isEmpty())
|
|
|
|
{
|
|
|
|
QWARN("File doesn't contain any messages.");
|
|
|
|
return QDomNodeList();
|
|
|
|
}
|
|
|
|
|
|
|
|
return messages;
|
|
|
|
}
|