File indexing completed on 2024-05-12 04:19:59

0001 /*
0002 Gwenview: an image viewer
0003 Copyright 2010 Aurélien Gâteau <agateau@kde.org>
0004 
0005 This program is free software; you can redistribute it and/or
0006 modify it under the terms of the GNU General Public License
0007 as published by the Free Software Foundation; either version 2
0008 of the License, or (at your option) any later version.
0009 
0010 This program is distributed in the hope that it will be useful,
0011 but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 GNU General Public License for more details.
0014 
0015 You should have received a copy of the GNU General Public License
0016 along with this program; if not, write to the Free Software
0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018 
0019 */
0020 // Qt
0021 #include <QEventLoop>
0022 #include <QImage>
0023 #include <QTest>
0024 
0025 // KF
0026 
0027 // Local
0028 #include "../lib/document/documentfactory.h"
0029 #include "../lib/imageutils.h"
0030 #include "../lib/transformimageoperation.h"
0031 #include "testutils.h"
0032 
0033 #include "transformimageoperationtest.h"
0034 
0035 QTEST_MAIN(TransformImageOperationTest)
0036 
0037 using namespace Gwenview;
0038 
0039 void TransformImageOperationTest::initTestCase()
0040 {
0041     qRegisterMetaType<QUrl>("QUrl");
0042 }
0043 
0044 void TransformImageOperationTest::init()
0045 {
0046     DocumentFactory::instance()->clearCache();
0047 }
0048 
0049 void TransformImageOperationTest::testRotate90()
0050 {
0051     QUrl url = urlForTestFile("test.png");
0052     QImage image;
0053 
0054     bool ok = image.load(url.toLocalFile());
0055     QVERIFY2(ok, "Could not load 'test.png'");
0056     QTransform matrix = ImageUtils::transformMatrix(ROT_90);
0057     image = image.transformed(matrix);
0058 
0059     Document::Ptr doc = DocumentFactory::instance()->load(url);
0060 
0061     auto op = new TransformImageOperation(ROT_90);
0062     QEventLoop loop;
0063     connect(doc.data(), &Document::allTasksDone, &loop, &QEventLoop::quit);
0064     op->applyToDocument(doc);
0065     loop.exec();
0066 
0067     QCOMPARE(image, doc->image());
0068 }
0069 
0070 #include "moc_transformimageoperationtest.cpp"