1 /*
2  *  Copyright (c) 2007 Boudewijn Rempt boud@valdyas.org
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_pattern_test.h"
20 
21 #include <QTest>
22 #include <resources/KoPattern.h>
23 
24 #include <QCryptographicHash>
25 #include <QByteArray>
26 
27 #include <kis_debug.h>
28 
testCreation()29 void KoPatternTest::testCreation()
30 {
31     KoPattern test(QString(FILES_DATA_DIR) + '/' + "pattern.pat");
32 }
33 
testRoundTripMd5()34 void KoPatternTest::testRoundTripMd5()
35 {
36     QString filename(QString(FILES_DATA_DIR) + '/' + "test_pattern.png");
37     QString patFilename("test_pattern.pat");
38 
39     KoPattern pngPattern(filename);
40     QVERIFY(pngPattern.load());
41 
42     dbgKrita << "PNG Name:" << pngPattern.name();
43     dbgKrita << "PNG Filename:" << pngPattern.filename();
44 
45     pngPattern.setFilename(patFilename);
46     pngPattern.save();
47 
48     KoPattern patPattern(patFilename);
49     QVERIFY(patPattern.load());
50 
51     dbgKrita << "PAT Name:" << patPattern.name();
52     dbgKrita << "PAT Filename:" << patPattern.filename();
53 
54     dbgKrita << pngPattern.pattern().format();
55     dbgKrita << patPattern.pattern().format();
56 
57     QCOMPARE(pngPattern.pattern().convertToFormat(QImage::Format_ARGB32), patPattern.pattern().convertToFormat(QImage::Format_ARGB32));
58     QImage im1 = pngPattern.pattern().convertToFormat(QImage::Format_ARGB32);
59     QImage im2 = patPattern.pattern().convertToFormat(QImage::Format_ARGB32);
60 
61     QCryptographicHash h1(QCryptographicHash::Md5);
62 #if QT_VERSION >= QT_VERSION_CHECK(5,10,0)
63     h1.addData(QByteArray::fromRawData((const char*)im1.constBits(), im1.sizeInBytes()));
64 #else
65     h1.addData(QByteArray::fromRawData((const char*)im1.constBits(), im1.byteCount()));
66 #endif
67     QCryptographicHash h2(QCryptographicHash::Md5);
68 #if QT_VERSION >= QT_VERSION_CHECK(5,10,0)
69     h2.addData(QByteArray::fromRawData((const char*)im2.constBits(), im2.sizeInBytes()));
70 #else
71     h2.addData(QByteArray::fromRawData((const char*)im2.constBits(), im2.byteCount()));
72 #endif
73 
74     QCOMPARE(h1.result(), h2.result());
75     QCOMPARE(im1, im2);
76     QCOMPARE(pngPattern.md5(), patPattern.md5());
77 }
78 
79 
80 QTEST_MAIN(KoPatternTest)
81