[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra/calligra/2.9] krita/image: Fix KisDomUtils on Qt 4.7
From:       Dmitry Kazakov <dimula73 () gmail ! com>
Date:       2015-03-02 10:19:43
Message-ID: E1YSNRv-0004W2-Vg () scm ! kde ! org
[Download RAW message or body]

Git commit d686d56ea8d420bc2b5cdd357c66dd3588c83fa0 by Dmitry Kazakov.
Committed on 02/03/2015 at 09:10.
Pushed by dkazakov into branch 'calligra/2.9'.

Fix KisDomUtils on Qt 4.7

QLocale::c().toString(value) gives values with decimal separater,
which is not exactly what we want. Use QString::number() instead.

CCBUG:344478

M  +1    -1    krita/image/kis_dom_utils.h
M  +7    -0    krita/image/tests/CMakeLists.txt
A  +158  -0    krita/image/tests/kis_dom_utils_test.cpp     [License: GPL (v2+)]
A  +39   -0    krita/image/tests/kis_dom_utils_test.h     [License: GPL (v2+)]

http://commits.kde.org/calligra/d686d56ea8d420bc2b5cdd357c66dd3588c83fa0

diff --git a/krita/image/kis_dom_utils.h b/krita/image/kis_dom_utils.h
index c10a5b9..532d064 100644
--- a/krita/image/kis_dom_utils.h
+++ b/krita/image/kis_dom_utils.h
@@ -37,7 +37,7 @@ namespace KisDomUtils {
 
         template<typename T>
         inline QString numberToString(T value) {
-            return QLocale::c().toString(value);
+            return QString::number(value);
         }
 
 
diff --git a/krita/image/tests/CMakeLists.txt b/krita/image/tests/CMakeLists.txt
index d5e9311..cda9007 100644
--- a/krita/image/tests/CMakeLists.txt
+++ b/krita/image/tests/CMakeLists.txt
@@ -607,3 +607,10 @@ target_link_libraries(KisFillIntervalMapTest  ${KDE4_KDEUI_LIBS} \
kritaimage ${QT  set(kis_scanline_fill_test_SRCS kis_scanline_fill_test.cpp )
 kde4_add_unit_test(KisScanlineFillTest TESTNAME krita-image-ScanlineFill-Test \
${kis_scanline_fill_test_SRCS})  target_link_libraries(KisScanlineFillTest  \
${KDE4_KDEUI_LIBS} kritaimage ${QT_QTTEST_LIBRARY}) +
+
+########### next target ###############
+
+set(kis_dom_utils_test_SRCS kis_dom_utils_test.cpp )
+kde4_add_unit_test(KisDomUtilsTest TESTNAME krita-image-DomUtils-Test \
${kis_dom_utils_test_SRCS}) +target_link_libraries(KisDomUtilsTest  \
                ${KDE4_KDEUI_LIBS} kritaimage ${QT_QTTEST_LIBRARY})
diff --git a/krita/image/tests/kis_dom_utils_test.cpp \
b/krita/image/tests/kis_dom_utils_test.cpp new file mode 100644
index 0000000..ef237c0
--- /dev/null
+++ b/krita/image/tests/kis_dom_utils_test.cpp
@@ -0,0 +1,158 @@
+/*
+ *  Copyright (c) 2015 Dmitry Kazakov <dimula73@gmail.com>
+ *
+ *  This program 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 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "kis_dom_utils_test.h"
+
+#include <qtest_kde.h>
+
+#include "kis_dom_utils.h"
+#include "kis_debug.h"
+
+
+const qreal f1 = 0.0003;
+const qreal f2 = 1e-15;
+const qreal f3 = 1356.78301;
+const qreal f4 = 1234567.8901;
+
+const int i1 = 0;
+const int i2 = 13;
+const int i3 = -13;
+
+inline bool checkDifference(qreal a, qreal b, qreal portionTolerance)
+{
+    return qAbs(a) > 1e-10 ?
+        qAbs(a - b) / qAbs(a) < portionTolerance :
+        qAbs(a - b) < 1e-10;
+}
+
+QString saveData()
+{
+    QDomDocument doc("testdoc");
+
+    QDomElement root = doc.createElement("rootNode");
+    doc.appendChild(root);
+
+    KisDomUtils::saveValue(&root, "valueF1", f1);
+    KisDomUtils::saveValue(&root, "valueF2", f2);
+    KisDomUtils::saveValue(&root, "valueF3", f3);
+    KisDomUtils::saveValue(&root, "valueF4", f4);
+
+    KisDomUtils::saveValue(&root, "valueI1", i1);
+    KisDomUtils::saveValue(&root, "valueI2", i2);
+    KisDomUtils::saveValue(&root, "valueI3", i3);
+
+    return doc.toString();
+}
+
+void checkLoadData(const QString &xmlData)
+{
+    QDomDocument doc;
+    doc.setContent(xmlData);
+
+    QDomElement root = doc.documentElement();
+
+    qreal value = 0.0;
+
+    QVERIFY(KisDomUtils::loadValue(root, "valueF1", &value));
+    QVERIFY(checkDifference(f1, value, 0.01));
+
+    QVERIFY(KisDomUtils::loadValue(root, "valueF2", &value));
+    QVERIFY(checkDifference(f2, value, 0.01));
+
+    QVERIFY(KisDomUtils::loadValue(root, "valueF3", &value));
+    QVERIFY(checkDifference(f3, value, 0.01));
+
+    QVERIFY(KisDomUtils::loadValue(root, "valueF4", &value));
+    QVERIFY(checkDifference(f4, value, 0.01));
+
+    int iValue = 0;
+
+    QVERIFY(KisDomUtils::loadValue(root, "valueI1", &iValue));
+    QCOMPARE(i1, iValue);
+
+    QVERIFY(KisDomUtils::loadValue(root, "valueI2", &iValue));
+    QCOMPARE(i2, iValue);
+
+    QVERIFY(KisDomUtils::loadValue(root, "valueI3", &iValue));
+    QCOMPARE(i3, iValue);
+}
+
+void KisDomUtilsTest::testC2C()
+{
+    QLocale::setDefault(QLocale::C);
+    QString xmlData = saveData();
+
+    QLocale::setDefault(QLocale::C);
+    checkLoadData(xmlData);
+}
+
+void KisDomUtilsTest::testG2G()
+{
+    QLocale::setDefault(QLocale::German);
+    QString xmlData = saveData();
+
+    QLocale::setDefault(QLocale::German);
+    checkLoadData(xmlData);
+}
+
+void KisDomUtilsTest::testR2R()
+{
+    QLocale::setDefault(QLocale::Russian);
+    QString xmlData = saveData();
+
+    QLocale::setDefault(QLocale::Russian);
+    checkLoadData(xmlData);
+}
+
+void KisDomUtilsTest::testC2G()
+{
+    QLocale::setDefault(QLocale::C);
+    QString xmlData = saveData();
+
+    QLocale::setDefault(QLocale::German);
+    checkLoadData(xmlData);
+}
+
+void KisDomUtilsTest::testR2G()
+{
+    QLocale::setDefault(QLocale::Russian);
+    QString xmlData = saveData();
+
+    QLocale::setDefault(QLocale::German);
+    checkLoadData(xmlData);
+}
+
+void KisDomUtilsTest::testG2C()
+{
+    QLocale::setDefault(QLocale::German);
+    QString xmlData = saveData();
+
+    QLocale::setDefault(QLocale::C);
+    checkLoadData(xmlData);
+}
+
+void KisDomUtilsTest::testG2R()
+{
+    QLocale::setDefault(QLocale::German);
+    QString xmlData = saveData();
+
+    QLocale::setDefault(QLocale::Russian);
+    checkLoadData(xmlData);
+}
+
+QTEST_KDEMAIN(KisDomUtilsTest, GUI)
diff --git a/krita/image/tests/kis_dom_utils_test.h \
b/krita/image/tests/kis_dom_utils_test.h new file mode 100644
index 0000000..b6a2562
--- /dev/null
+++ b/krita/image/tests/kis_dom_utils_test.h
@@ -0,0 +1,39 @@
+/*
+ *  Copyright (c) 2015 Dmitry Kazakov <dimula73@gmail.com>
+ *
+ *  This program 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 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __KIS_DOM_UTILS_TEST_H
+#define __KIS_DOM_UTILS_TEST_H
+
+#include <QtTest/QtTest>
+
+class KisDomUtilsTest : public QObject
+{
+    Q_OBJECT
+private slots:
+
+    void testC2C();
+    void testG2G();
+    void testR2R();
+
+    void testC2G();
+    void testR2G();
+    void testG2C();
+    void testG2R();
+};
+
+#endif /* __KIS_DOM_UTILS_TEST_H */


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic