diff --git a/libs/libkis/tests/TestDocument.cpp b/libs/libkis/tests/TestDocument.cpp index bdf3c14c50..cb15b3f74d 100644 --- a/libs/libkis/tests/TestDocument.cpp +++ b/libs/libkis/tests/TestDocument.cpp @@ -1,214 +1,219 @@ /* Copyright (C) 2017 Boudewijn Rempt This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "TestDocument.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void TestDocument::testSetColorSpace() { KisDocument *kisdoc = KisPart::instance()->createDocument(); KisImageSP image = new KisImage(0, 100, 100, KoColorSpaceRegistry::instance()->rgb8(), "test"); KisNodeSP layer = new KisPaintLayer(image, "test1", 255); image->addNode(layer); kisdoc->setCurrentImage(image); Document d(kisdoc); QStringList profiles = Krita().profiles("GRAYA", "U16"); d.setColorSpace("GRAYA", "U16", profiles.first()); QVERIFY(layer->colorSpace()->colorModelId().id() == "GRAYA"); QVERIFY(layer->colorSpace()->colorDepthId().id() == "U16"); QVERIFY(layer->colorSpace()->profile()->name() == "gray built-in"); + + KisPart::instance()->removeDocument(kisdoc); } void TestDocument::testSetColorProfile() { KisDocument *kisdoc = KisPart::instance()->createDocument(); KisImageSP image = new KisImage(0, 100, 100, KoColorSpaceRegistry::instance()->rgb8(), "test"); KisNodeSP layer = new KisPaintLayer(image, "test1", 255); image->addNode(layer); kisdoc->setCurrentImage(image); Document d(kisdoc); QStringList profiles = Krita().profiles("RGBA", "U8"); Q_FOREACH(const QString &profile, profiles) { d.setColorProfile(profile); QVERIFY(image->colorSpace()->profile()->name() == profile); } + KisPart::instance()->removeDocument(kisdoc); } void TestDocument::testPixelData() { KisDocument *kisdoc = KisPart::instance()->createDocument(); KisImageSP image = new KisImage(0, 100, 100, KoColorSpaceRegistry::instance()->rgb8(), "test"); KisNodeSP layer = new KisPaintLayer(image, "test1", 255); KisFillPainter gc(layer->paintDevice()); gc.fillRect(0, 0, 100, 100, KoColor(Qt::red, layer->colorSpace())); image->addNode(layer); kisdoc->setCurrentImage(image); Document d(kisdoc); d.refreshProjection(); QByteArray ba = d.pixelData(0, 0, 100, 100); QDataStream ds(ba); do { quint8 channelvalue; ds >> channelvalue; QVERIFY(channelvalue == 0); ds >> channelvalue; QVERIFY(channelvalue == 0); ds >> channelvalue; QVERIFY(channelvalue == 255); ds >> channelvalue; QVERIFY(channelvalue == 255); } while (!ds.atEnd()); + + KisPart::instance()->removeDocument(kisdoc); } void TestDocument::testThumbnail() { KisDocument *kisdoc = KisPart::instance()->createDocument(); KisImageSP image = new KisImage(0, 100, 100, KoColorSpaceRegistry::instance()->rgb8(), "test"); KisNodeSP layer = new KisPaintLayer(image, "test1", 255); KisFillPainter gc(layer->paintDevice()); gc.fillRect(0, 0, 100, 100, KoColor(Qt::red, layer->colorSpace())); image->addNode(layer); kisdoc->setCurrentImage(image); Document d(kisdoc); d.refreshProjection(); QImage thumb = d.thumbnail(10, 10); thumb.save("thumb.png"); QVERIFY(thumb.width() == 10); QVERIFY(thumb.height() == 10); // Our thumbnail calculator in KisPaintDevice cannot make a filled 10x10 thumbnail from a 100x100 device, // it makes it 10x10 empty, then puts 8x8 pixels in there... Not a bug in the Node class for (int i = 0; i < 8; ++i) { for (int j = 0; j < 8; ++j) { #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) QVERIFY(thumb.pixelColor(i, j) == QColor(Qt::red)); #else QVERIFY(QColor(thumb.pixel(i, j)) == QColor(Qt::red)); #endif } } + KisPart::instance()->removeDocument(kisdoc); } void TestDocument::testCreateAndSave() { KisDocument *kisdoc = KisPart::instance()->createDocument(); KisImageSP image = new KisImage(0, 5000, 5000, KoColorSpaceRegistry::instance()->rgb16(), "test"); KisNodeSP layer = new KisPaintLayer(image, "test1", 128); KisFillPainter gc(layer->paintDevice()); gc.fillRect(100, 100, 4000, 4000, KoColor(Qt::red, layer->colorSpace())); image->addNode(layer); for(int i = 0; i < 10; ++i) { image->addNode(layer->clone()); } kisdoc->setCurrentImage(image); Document d(kisdoc); d.setBatchmode(true); d.refreshProjection(); QString filename = QDir::tempPath() + "/TestDocumentTestCreateAndSave.kra"; d.saveAs(filename); QVERIFY2(QFileInfo(filename).exists(), filename.toUtf8()); Document *d2 = Krita::instance()->openDocument(filename); Q_ASSERT(d2->colorDepth() == "U16"); - delete kisdoc; - delete d2; + KisPart::instance()->removeDocument(kisdoc); } void TestDocument::testCreateFillLayer() { KisDocument *kisdoc = KisPart::instance()->createDocument(); KisImageSP image = new KisImage(0, 50, 50, KoColorSpaceRegistry::instance()->rgb16(), "test"); kisdoc->setCurrentImage(image); Document d(kisdoc); const QString pattern("pattern"); const QString color("color"); const QString filllayer = "filllayer"; InfoObject info; Selection sel(image->globalSelection()); FillLayer *f = d.createFillLayer("test1", pattern, info, sel); QVERIFY(f->generatorName() == pattern); QVERIFY(f->type() == filllayer); delete f; f = d.createFillLayer("test1", color, info, sel); QVERIFY(f->generatorName() == color); QVERIFY(f->type() == filllayer); info.setProperty(pattern, "Cross01.pat"); QVERIFY(f->setGenerator(pattern, &info)); QVERIFY(f->filterConfig()->property(pattern).toString() == "Cross01.pat"); QVERIFY(f->generatorName() == pattern); QVERIFY(f->type() == filllayer); info.setProperty(color, QColor(Qt::red)); QVERIFY(f->setGenerator(color, &info)); QVariant v = f->filterConfig()->property(color); QColor c = v.value(); QVERIFY(c == QColor(Qt::red)); QVERIFY(f->generatorName() == color); QVERIFY(f->type() == filllayer); bool r = f->setGenerator(QString("xxx"), &info); QVERIFY(!r); delete f; QVERIFY(d.createFillLayer("test1", "xxx", info, sel) == 0); - delete kisdoc; + KisPart::instance()->removeDocument(kisdoc); } QTEST_MAIN(TestDocument)