Commit 5d7e1045 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Added unittests for fill layer loading

CCBUG:343807
parent 15a217ac
......@@ -33,6 +33,8 @@
#include <kis_undo_adapter.h>
#include "kis_node_graph_listener.h"
#include "kis_iterator_ng.h"
#include "kis_image.h"
#ifndef FILES_DATA_DIR
#define FILES_DATA_DIR "."
......@@ -387,6 +389,45 @@ inline bool checkQImageExternal(const QImage &image, const QString &testName,
fuzzy, fuzzyAlpha, maxNumFailingPixels);
}
struct ExternalImageChecker
{
ExternalImageChecker(const QString &prefix, const QString &testName)
: m_prefix(prefix),
m_testName(testName),
m_success(true)
{
}
bool testPassed() const {
return m_success;
}
inline bool checkDevice(KisPaintDeviceSP device, KisImageSP image, const QString &caseName) {
bool result =
checkQImageExternal(device->convertToQImage(0, image->bounds()),
m_testName,
m_prefix,
caseName, 1, 1, 100);
m_success &= result;
return result;
}
inline bool checkImage(KisImageSP image, const QString &testName) {
bool result = checkDevice(image->projection(), image, testName);
m_success &= result;
return result;
}
private:
QString m_prefix;
QString m_testName;
bool m_success;
};
#endif
inline quint8 alphaDevicePixel(KisPaintDeviceSP dev, qint32 x, qint32 y)
......
......@@ -28,19 +28,10 @@
#include <testutil.h>
bool checkDeviceImpl(KisPaintDeviceSP device, KisImageSP image, const QString &testName, const QString &prefix) {
return TestUtil::checkQImageExternal(device->convertToQImage(0, image->bounds()),
"file_layer",
prefix,
testName, 1, 1, 100);
}
bool checkImage(KisImageSP image, const QString &testName, const QString &prefix) {
return checkDeviceImpl(image->projection(), image, testName, prefix);
}
void KisFileLayerTest::testFileLayerPlusTransformMaskOffImage()
{
TestUtil::ExternalImageChecker chk("flayer_tmask_offimage", "file_layer");
QRect refRect(0,0,640,441);
QRect fillRect(400,400,100,100);
TestUtil::MaskParent p(refRect);
......@@ -60,11 +51,11 @@ void KisFileLayerTest::testFileLayerPlusTransformMaskOffImage()
flayer->setDirty(refRect);
p.image->waitForDone();
QVERIFY(checkImage(p.image, "00_initial_layer_update", "flayer_tmask_offimage"));
chk.checkImage(p.image, "00_initial_layer_update");
QTest::qWait(4000);
p.image->waitForDone();
QVERIFY(checkImage(p.image, "00X_initial_layer_update", "flayer_tmask_offimage"));
chk.checkImage(p.image, "00X_initial_layer_update");
flayer->setX(580);
......@@ -72,11 +63,11 @@ void KisFileLayerTest::testFileLayerPlusTransformMaskOffImage()
flayer->setDirty(refRect);
p.image->waitForDone();
QVERIFY(checkImage(p.image, "01_file_layer_moved", "flayer_tmask_offimage"));
chk.checkImage(p.image, "01_file_layer_moved");
QTest::qWait(4000);
p.image->waitForDone();
QVERIFY(checkImage(p.image, "01X_file_layer_moved", "flayer_tmask_offimage"));
chk.checkImage(p.image, "01X_file_layer_moved");
QTransform transform = QTransform::fromTranslate(-580, -400);
......@@ -93,15 +84,19 @@ void KisFileLayerTest::testFileLayerPlusTransformMaskOffImage()
mask1->setDirty(refRect);
p.image->waitForDone();
QVERIFY(checkImage(p.image, "02_mask1_moved_mask_update", "flayer_tmask_offimage"));
chk.checkImage(p.image, "02_mask1_moved_mask_update");
QTest::qWait(4000);
p.image->waitForDone();
QVERIFY(checkImage(p.image, "02X_mask1_moved_mask_update", "flayer_tmask_offimage"));
chk.checkImage(p.image, "02X_mask1_moved_mask_update");
QVERIFY(chk.testPassed());
}
void KisFileLayerTest::testFileLayerPlusTransformMaskSmallFileBigOffset()
{
TestUtil::ExternalImageChecker chk("flayer_tmask_huge_offset", "file_layer");
QRect refRect(0,0,2000,1500);
QRect fillRect(400,400,100,100);
TestUtil::MaskParent p(refRect);
......@@ -125,11 +120,11 @@ void KisFileLayerTest::testFileLayerPlusTransformMaskSmallFileBigOffset()
flayer->setDirty(refRect);
p.image->waitForDone();
QVERIFY(checkImage(p.image, "00_initial_layer_update", "flayer_tmask_huge_offset"));
chk.checkImage(p.image, "00_initial_layer_update");
QTest::qWait(4000);
p.image->waitForDone();
QVERIFY(checkImage(p.image, "00X_initial_layer_update", "flayer_tmask_huge_offset"));
chk.checkImage(p.image, "00X_initial_layer_update");
QTransform transform;
......@@ -139,11 +134,13 @@ void KisFileLayerTest::testFileLayerPlusTransformMaskSmallFileBigOffset()
mask1->setDirty(refRect);
p.image->waitForDone();
QVERIFY(checkImage(p.image, "01_mask1_moved_mask_update", "flayer_tmask_huge_offset"));
chk.checkImage(p.image, "01_mask1_moved_mask_update");
QTest::qWait(4000);
p.image->waitForDone();
QVERIFY(checkImage(p.image, "01X_mask1_moved_mask_update", "flayer_tmask_huge_offset"));
chk.checkImage(p.image, "01X_mask1_moved_mask_update");
QVERIFY(chk.testPassed());
}
QTEST_KDEMAIN(KisFileLayerTest, GUI)
......@@ -108,5 +108,76 @@ void KisKraSaverTest::testSaveEmpty()
delete doc2;
delete doc;
}
#include <filter/kis_filter_configuration.h>
#include "generator/kis_generator_registry.h"
#include <generator/kis_generator.h>
void testRoundTripFillLayerImpl(const QString &testName, KisFilterConfiguration *config)
{
TestUtil::ExternalImageChecker chk(testName, "fill_layer");
QRect refRect(0,0,512,512);
TestUtil::MaskParent p(refRect);
QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument());
doc->setCurrentImage(p.image);
doc->documentInfo()->setAboutInfo("title", p.image->objectName());
KisSelectionSP selection;
KisGeneratorLayerSP glayer = new KisGeneratorLayer(p.image, "glayer", config, selection);
p.image->addNode(glayer, p.image->root(), KisNodeSP());
glayer->setDirty();
p.image->waitForDone();
chk.checkImage(p.image, "00_initial_layer_update");
doc->saveNativeFormat("roundtrip_fill_layer_test.kra");
QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument());
doc2->loadNativeFormat("roundtrip_fill_layer_test.kra");
doc2->image()->waitForDone();
chk.checkImage(doc2->image(), "01_fill_layer_round_trip");
QVERIFY(chk.testPassed());
}
void KisKraSaverTest::testRoundTripFillLayerColor()
{
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
KisGeneratorSP generator = KisGeneratorRegistry::instance()->get("color");
Q_ASSERT(generator);
// warning: we pass null paint device to the default constructed value
KisFilterConfiguration *config = generator->factoryConfiguration(0);
Q_ASSERT(config);
QVariant v;
v.setValue(KoColor(Qt::red, cs));
config->setProperty("color", v);
testRoundTripFillLayerImpl("fill_layer_color", config);
}
void KisKraSaverTest::testRoundTripFillLayerPattern()
{
KisGeneratorSP generator = KisGeneratorRegistry::instance()->get("pattern");
Q_ASSERT(generator);
// warning: we pass null paint device to the default constructed value
KisFilterConfiguration *config = generator->factoryConfiguration(0);
Q_ASSERT(config);
QVariant v;
v.setValue(QString("11_drawed_furry.png"));
config->setProperty("pattern", v);
testRoundTripFillLayerImpl("fill_layer_pattern", config);
}
QTEST_KDEMAIN(KisKraSaverTest, GUI)
#include "kis_kra_saver_test.moc"
......@@ -30,6 +30,8 @@ private slots:
void testRoundTrip();
void testSaveEmpty();
void testRoundTripFillLayerColor();
void testRoundTripFillLayerPattern();
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment