1 /*
2  *  Copyright (c) 2016 Dmitry Kazakov <dimula73@gmail.com>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #include "kis_grid_config_test.h"
20 
21 #include <QTest>
22 #include "kis_grid_config.h"
23 #include "kis_guides_config.h"
24 #include <QDomDocument>
25 #include <QDomElement>
26 
27 
testGridConfig()28 void KisGridConfigTest::testGridConfig()
29 {
30     KisGridConfig config;
31     config.setSpacing(QPoint(10,13));
32     config.setOffset(QPoint(13,14));
33     config.setOffsetAspectLocked(false);
34     config.setSubdivision(4);
35 
36     QVERIFY(!config.isDefault());
37 
38     QDomDocument doc;
39     QDomElement root = doc.createElement("TestXMLRoot");
40     doc.appendChild(root);
41     QDomElement el = config.saveDynamicDataToXml(doc, "test_tag");
42     root.appendChild(el);
43 
44     QByteArray b = doc.toByteArray(4);
45     //printf(b.data());
46 
47     KisGridConfig config2;
48     QVERIFY(config2.isDefault());
49     QVERIFY(config2.loadDynamicDataFromXml(el));
50 
51     QCOMPARE(config2, config);
52     QVERIFY(!config2.isDefault());
53 }
54 
testGuidesConfig()55 void KisGridConfigTest::testGuidesConfig()
56 {
57     KisGuidesConfig config;
58     config.setShowGuides(true);
59     config.setLockGuides(true);
60     config.setSnapToGuides(true);
61 
62     config.addGuideLine(Qt::Horizontal, 100.0);
63     config.addGuideLine(Qt::Horizontal, 200.0);
64 
65     config.addGuideLine(Qt::Vertical, 300.0);
66     config.addGuideLine(Qt::Vertical, 400.0);
67 
68     QVERIFY(config.hasGuides());
69 
70     QDomDocument doc;
71     QDomElement root = doc.createElement("TestXMLRoot");
72     doc.appendChild(root);
73     QDomElement el = config.saveToXml(doc, "test_tag");
74     root.appendChild(el);
75 
76     QByteArray b = doc.toByteArray(4);
77     //printf(b.data());
78 
79     KisGuidesConfig config2;
80     QVERIFY(!config2.hasGuides());
81     QVERIFY(config2.loadFromXml(el));
82 
83     QCOMPARE(config2, config);
84     QVERIFY(config2.hasGuides());
85 }
86 
87 QTEST_MAIN(KisGridConfigTest)
88