From bceb18d4a5421fbde145abfd43fd6b2fb563cb46 Mon Sep 17 00:00:00 2001
From: Roman Telezhynskyi <kroluku@gmail.com>
Date: Mon, 14 Dec 2015 09:41:42 +0200
Subject: [PATCH] New test that help find and remove '...' string inside
 localization.

--HG--
branch : develop
---
 src/test/ValentinaTest/tst_tstranslation.cpp | 82 ++++++++++++++++++++
 src/test/ValentinaTest/tst_tstranslation.h   |  1 +
 2 files changed, 83 insertions(+)

diff --git a/src/test/ValentinaTest/tst_tstranslation.cpp b/src/test/ValentinaTest/tst_tstranslation.cpp
index 83719282b..6eec1fea7 100644
--- a/src/test/ValentinaTest/tst_tstranslation.cpp
+++ b/src/test/ValentinaTest/tst_tstranslation.cpp
@@ -111,3 +111,85 @@ void TST_TSTranslation::CheckEnglishLocalization()
         }
     }
 }
+
+//---------------------------------------------------------------------------------------------------------------------
+void TST_TSTranslation::CheckEmptyToolButton()
+{
+    const QString path = QString("%1/valentina.ts").arg(TS_DIR);
+    QFile tsFile(path);
+    if (not tsFile.exists())
+    {
+        QSKIP("Can't find valentina.ts");
+    }
+
+    if (tsFile.open(QIODevice::ReadOnly) == false)
+    {
+        const QString message = QString("Can't open file valentina.ts.\n%1").arg(tsFile.errorString());
+        QSKIP(qUtf8Printable(message));
+    }
+
+    QString errorMsg;
+    int errorLine = -1;
+    int errorColumn = -1;
+    QDomDocument ts;
+    if (ts.setContent(&tsFile, &errorMsg, &errorLine, &errorColumn) == false)
+    {
+        tsFile.close();
+        const QString message = QString("Parsing error file valentina.ts in line %1 column %2")
+                .arg(errorLine).arg(errorColumn);
+        QFAIL(qUtf8Printable(message));
+    }
+
+    const QDomNodeList messages = ts.elementsByTagName(QStringLiteral("message"));
+    if (messages.isEmpty())
+    {
+        tsFile.close();
+        QFAIL("File doesn't contain any messages");
+    }
+
+    const QString attrType = QStringLiteral("type");
+    const qint32 num = messages.size();
+    for (qint32 i = 0; i < num; ++i)
+    {
+        const QDomElement message = messages.at(i).toElement();
+        if (message.isNull() == false)
+        {
+            const QString source = message.firstChildElement(QStringLiteral("source")).text();
+            if (source.isEmpty())
+            {
+                continue;
+            }
+
+            if (source == QLatin1Literal("..."))
+            {
+                const QDomElement translationTag = message.firstChildElement(QStringLiteral("translation"));
+                if (translationTag.hasAttribute(attrType))
+                {
+                    const QString attrVal = translationTag.attribute(attrType);
+                    if (attrVal == QLatin1Literal("vanished"))
+                    {
+                        continue;
+                    }
+                }
+
+                const QDomNode context = message.parentNode();
+                if (context.isNull())
+                {
+                    tsFile.close();
+                    QFAIL("Can't get context.");
+                }
+
+                const QString contextName = context.firstChildElement(QStringLiteral("name")).text();
+                const QString error = QString("Found '...' in context '%1'").arg(contextName);
+                tsFile.close();
+                QFAIL(qUtf8Printable(error));
+            }
+        }
+        else
+        {
+            tsFile.close();
+            const QString message = QString("Message %1 is null.").arg(i);
+            QFAIL(qUtf8Printable(message));
+        }
+    }
+}
diff --git a/src/test/ValentinaTest/tst_tstranslation.h b/src/test/ValentinaTest/tst_tstranslation.h
index ec3314ea8..587b67949 100644
--- a/src/test/ValentinaTest/tst_tstranslation.h
+++ b/src/test/ValentinaTest/tst_tstranslation.h
@@ -39,6 +39,7 @@ public:
 
 private slots:
     void CheckEnglishLocalization();
+    void CheckEmptyToolButton();
 
 private:
     Q_DISABLE_COPY(TST_TSTranslation)