kis_kra_saver_test.cpp 19 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 *  Copyright (c) 2007 Boudewijn Rempt boud@valdyas.org
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "kis_kra_saver_test.h"

21
#include <QTest>
22

23 24
#include <QBitArray>

25
#include <KisDocument.h>
26
#include <KoDocumentInfo.h>
27 28
#include <KoShapeContainer.h>
#include <KoPathShape.h>
29

30 31 32
#include "filter/kis_filter_registry.h"
#include "filter/kis_filter_configuration.h"
#include "filter/kis_filter.h"
33
#include "KisDocument.h"
34
#include "kis_image.h"
35 36 37 38 39 40 41 42 43 44 45 46
#include "kis_pixel_selection.h"
#include "kis_group_layer.h"
#include "kis_paint_layer.h"
#include "kis_clone_layer.h"
#include "kis_adjustment_layer.h"
#include "kis_shape_layer.h"
#include "kis_filter_mask.h"
#include "kis_transparency_mask.h"
#include "kis_selection_mask.h"
#include "kis_selection.h"
#include "kis_fill_painter.h"
#include "kis_shape_selection.h"
47
#include "util.h"
48
#include "testutil.h"
49 50
#include "kis_keyframe_channel.h"
#include "kis_image_animation_interface.h"
51
#include "kis_layer_properties_icons.h"
52 53 54

#include "kis_transform_mask_params_interface.h"

Boudewijn Rempt's avatar
Boudewijn Rempt committed
55 56 57
#include <filter/kis_filter_registry.h>
#include <generator/kis_generator_registry.h>

58 59
#include <KoResourcePaths.h>

Boudewijn Rempt's avatar
Boudewijn Rempt committed
60 61
void KisKraSaverTest::initTestCase()
{
62 63
    KoResourcePaths::addResourceDir("ko_patterns", QString(SYSTEM_RESOURCES_DATA_DIR) + "/patterns");

Boudewijn Rempt's avatar
Boudewijn Rempt committed
64 65 66 67
    KisFilterRegistry::instance();
    KisGeneratorRegistry::instance();
}

68 69 70 71 72 73 74 75
void KisKraSaverTest::testCrashyShapeLayer()
{
    /**
     * KisShapeLayer used to call setImage from its destructor and
     * therefore causing an infinite recursion (when at least one transparency
     * mask was preset. This testcase just checks that.
     */

76 77
    //QScopedPointer<KisDocument> doc(createCompleteDocument(true));
    //Q_UNUSED(doc);
78
}
79 80 81

void KisKraSaverTest::testRoundTrip()
{
82
    KisDocument* doc = createCompleteDocument();
83 84
    KoColor bgColor(Qt::red, doc->image()->colorSpace());
    doc->image()->setDefaultProjectionColor(bgColor);
85
    doc->exportDocument(QUrl::fromLocalFile("roundtriptest.kra"));
86

87 88 89 90
    QStringList list;
    KisCountVisitor cv1(list, KoProperties());
    doc->image()->rootLayer()->accept(cv1);

91
    KisDocument *doc2 = KisPart::instance()->createDocument();
92

93 94
    bool result = doc2->loadNativeFormat("roundtriptest.kra");
    QVERIFY(result);
95 96

    KisCountVisitor cv2(list, KoProperties());
97
    doc2->image()->rootLayer()->accept(cv2);
Boudewijn Rempt's avatar
Boudewijn Rempt committed
98
    QCOMPARE(cv1.count(), cv2.count());
99 100

    // check whether the BG color is saved correctly
101
    QCOMPARE(doc2->image()->defaultProjectionColor(), bgColor);
102 103

    // test round trip of a transform mask
104 105
    KisNode* tnode =
        TestUtil::findNode(doc2->image()->rootLayer(), "testTransformMask").data();
106
    QVERIFY(tnode);
107
    KisTransformMask *tmask = dynamic_cast<KisTransformMask*>(tnode);
108 109 110 111 112
    QVERIFY(tmask);
    KisDumbTransformMaskParams *params = dynamic_cast<KisDumbTransformMaskParams*>(tmask->transformParams().data());
    QVERIFY(params);
    QTransform t = params->testingGetTransform();
    QCOMPARE(t, createTestingTransform());
113 114 115 116


    delete doc2;
    delete doc;
117 118
}

119 120
void KisKraSaverTest::testSaveEmpty()
{
121
    KisDocument* doc = createEmptyDocument();
122
    doc->exportDocument(QUrl::fromLocalFile("emptytest.kra"));
123 124 125 126
    QStringList list;
    KisCountVisitor cv1(list, KoProperties());
    doc->image()->rootLayer()->accept(cv1);

127 128
    KisDocument *doc2 = KisPart::instance()->createDocument();
    doc2->loadNativeFormat("emptytest.kra");
129 130

    KisCountVisitor cv2(list, KoProperties());
131
    doc2->image()->rootLayer()->accept(cv2);
132
    QCOMPARE(cv1.count(), cv2.count());
133 134 135

    delete doc2;
    delete doc;
136
}
137 138 139 140 141

#include <filter/kis_filter_configuration.h>
#include "generator/kis_generator_registry.h"
#include <generator/kis_generator.h>

142
void testRoundTripFillLayerImpl(const QString &testName, KisFilterConfigurationSP config)
143 144
{
    TestUtil::ExternalImageChecker chk(testName, "fill_layer");
145
    chk.setFuzzy(2);
146

147 148 149
    QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument());

    // mask parent should be destructed before the document!
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
    QRect refRect(0,0,512,512);
    TestUtil::MaskParent p(refRect);

    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");

165
    doc->exportDocument(QUrl::fromLocalFile("roundtrip_fill_layer_test.kra"));
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183

    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
184
    KisFilterConfigurationSP config = generator->factoryConfiguration();
185 186 187 188 189 190 191 192 193 194 195 196
    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");
197
    QVERIFY(generator);
198 199

    // warning: we pass null paint device to the default constructed value
200
    KisFilterConfigurationSP config = generator->factoryConfiguration();
201
    QVERIFY(config);
202 203 204 205 206 207 208 209

    QVariant v;
    v.setValue(QString("11_drawed_furry.png"));
    config->setProperty("pattern", v);

    testRoundTripFillLayerImpl("fill_layer_pattern", config);
}

210 211 212 213 214 215 216 217 218
#include "kis_psd_layer_style.h"


void KisKraSaverTest::testRoundTripLayerStyles()
{
    TestUtil::ExternalImageChecker chk("kra_saver_test", "layer_styles");

    QRect imageRect(0,0,512,512);

219 220 221
    // the document should be created before the image!
    QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument());

222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
    const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
    KisImageSP image = new KisImage(new KisSurrogateUndoStore(), imageRect.width(), imageRect.height(), cs, "test image");
    KisPaintLayerSP layer1 = new KisPaintLayer(image, "paint1", OPACITY_OPAQUE_U8);
    KisPaintLayerSP layer2 = new KisPaintLayer(image, "paint2", OPACITY_OPAQUE_U8);
    KisPaintLayerSP layer3 = new KisPaintLayer(image, "paint3", OPACITY_OPAQUE_U8);
    image->addNode(layer1);
    image->addNode(layer2);
    image->addNode(layer3);

    doc->setCurrentImage(image);
    doc->documentInfo()->setAboutInfo("title", image->objectName());

    layer1->paintDevice()->fill(QRect(100, 100, 100, 100), KoColor(Qt::red, cs));
    layer2->paintDevice()->fill(QRect(200, 200, 100, 100), KoColor(Qt::green, cs));
    layer3->paintDevice()->fill(QRect(300, 300, 100, 100), KoColor(Qt::blue, cs));

    KisPSDLayerStyleSP style(new KisPSDLayerStyle());
    style->dropShadow()->setEffectEnabled(true);


    style->dropShadow()->setAngle(-90);
    style->dropShadow()->setUseGlobalLight(false);
    layer1->setLayerStyle(style->clone());

    style->dropShadow()->setAngle(180);
    style->dropShadow()->setUseGlobalLight(true);
    layer2->setLayerStyle(style->clone());

    style->dropShadow()->setAngle(90);
    style->dropShadow()->setUseGlobalLight(false);
    layer3->setLayerStyle(style->clone());

    image->initialRefreshGraph();
    chk.checkImage(image, "00_initial_layers");

257
    doc->exportDocument(QUrl::fromLocalFile("roundtrip_layer_styles.kra"));
258 259 260 261 262 263 264 265 266 267 268


    QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument());
    doc2->loadNativeFormat("roundtrip_layer_styles.kra");

    doc2->image()->waitForDone();
    chk.checkImage(doc2->image(), "00_initial_layers");

    QVERIFY(chk.testPassed());
}

269 270
void KisKraSaverTest::testRoundTripAnimation()
{
271 272
    QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument());

273 274 275 276 277 278 279
    QRect imageRect(0,0,512,512);
    const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
    KisImageSP image = new KisImage(new KisSurrogateUndoStore(), imageRect.width(), imageRect.height(), cs, "test image");
    KisPaintLayerSP layer1 = new KisPaintLayer(image, "paint1", OPACITY_OPAQUE_U8);
    image->addNode(layer1);

    layer1->paintDevice()->fill(QRect(100, 100, 50, 50), KoColor(Qt::black, cs));
280
    layer1->paintDevice()->setDefaultPixel(KoColor(Qt::red, cs));
281

282 283
    KUndo2Command parentCommand;

284 285 286
    layer1->enableAnimation();
    KisKeyframeChannel *rasterChannel = layer1->getKeyframeChannel(KisKeyframeChannel::Content.id(), true);
    QVERIFY(rasterChannel);
287 288

    rasterChannel->addKeyframe(10, &parentCommand);
289 290 291
    image->animationInterface()->switchCurrentTimeAsync(10);
    image->waitForDone();
    layer1->paintDevice()->fill(QRect(200, 50, 10, 10), KoColor(Qt::black, cs));
292
    layer1->paintDevice()->moveTo(25, 15);
293
    layer1->paintDevice()->setDefaultPixel(KoColor(Qt::green, cs));
294

295
    rasterChannel->addKeyframe(20, &parentCommand);
296 297 298
    image->animationInterface()->switchCurrentTimeAsync(20);
    image->waitForDone();
    layer1->paintDevice()->fill(QRect(150, 200, 30, 30), KoColor(Qt::black, cs));
299
    layer1->paintDevice()->moveTo(100, 50);
300
    layer1->paintDevice()->setDefaultPixel(KoColor(Qt::blue, cs));
301

302 303
    QVERIFY(!layer1->useInTimeline());
    layer1->setUseInTimeline(true);
304

305
    doc->setCurrentImage(image);
306
    doc->exportDocument(QUrl::fromLocalFile("roundtrip_animation.kra"));
307 308 309 310 311 312 313 314 315 316 317 318

    QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument());
    doc2->loadNativeFormat("roundtrip_animation.kra");
    KisImageSP image2 = doc2->image();
    KisNodeSP node = image2->root()->firstChild();

    QVERIFY(node->inherits("KisPaintLayer"));
    KisPaintLayerSP layer2 = qobject_cast<KisPaintLayer*>(node.data());
    cs = layer2->paintDevice()->colorSpace();

    QCOMPARE(image2->animationInterface()->currentTime(), 20);
    KisKeyframeChannel *channel = layer2->getKeyframeChannel(KisKeyframeChannel::Content.id());
319
    QVERIFY(channel);
320 321 322 323 324 325 326 327
    QCOMPARE(channel->keyframeCount(), 3);

    image2->animationInterface()->switchCurrentTimeAsync(0);
    image2->waitForDone();

    QCOMPARE(layer2->paintDevice()->nonDefaultPixelArea(), QRect(64, 64, 128, 128));
    QCOMPARE(layer2->paintDevice()->x(), 0);
    QCOMPARE(layer2->paintDevice()->y(), 0);
328
    QCOMPARE(layer2->paintDevice()->defaultPixel(), KoColor(Qt::red, cs));
329 330 331 332 333 334 335

    image2->animationInterface()->switchCurrentTimeAsync(10);
    image2->waitForDone();

    QCOMPARE(layer2->paintDevice()->nonDefaultPixelArea(), QRect(217, 15, 64, 64));
    QCOMPARE(layer2->paintDevice()->x(), 25);
    QCOMPARE(layer2->paintDevice()->y(), 15);
336
    QCOMPARE(layer2->paintDevice()->defaultPixel(), KoColor(Qt::green, cs));
337 338 339 340 341 342 343

    image2->animationInterface()->switchCurrentTimeAsync(20);
    image2->waitForDone();

    QCOMPARE(layer2->paintDevice()->nonDefaultPixelArea(), QRect(228, 242, 64, 64));
    QCOMPARE(layer2->paintDevice()->x(), 100);
    QCOMPARE(layer2->paintDevice()->y(), 50);
344
    QCOMPARE(layer2->paintDevice()->defaultPixel(), KoColor(Qt::blue, cs));
345

346 347
    QVERIFY(layer2->useInTimeline());

348 349
}

350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
#include "lazybrush/kis_lazy_fill_tools.h"

void KisKraSaverTest::testRoundTripColorizeMask()
{
    QRect imageRect(0,0,512,512);
    const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
    const KoColorSpace * weirdCS = KoColorSpaceRegistry::instance()->rgb16();

    QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument());
    KisImageSP image = new KisImage(new KisSurrogateUndoStore(), imageRect.width(), imageRect.height(), cs, "test image");
    doc->setCurrentImage(image);

    KisPaintLayerSP layer1 = new KisPaintLayer(image, "paint1", OPACITY_OPAQUE_U8, weirdCS);
    image->addNode(layer1);

    KisColorizeMaskSP mask = new KisColorizeMask();
    image->addNode(mask, layer1);
    mask->initializeCompositeOp();
368
    delete mask->setColorSpace(layer1->colorSpace());
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395

    {
        KisPaintDeviceSP key1 = new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha8());
        key1->fill(QRect(50,50,10,20), KoColor(Qt::black, key1->colorSpace()));
        mask->testingAddKeyStroke(key1, KoColor(Qt::green, layer1->colorSpace()));
        // KIS_DUMP_DEVICE_2(key1, refRect, "key1", "dd");
    }

    {
        KisPaintDeviceSP key2 = new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha8());
        key2->fill(QRect(150,50,10,20), KoColor(Qt::black, key2->colorSpace()));
        mask->testingAddKeyStroke(key2, KoColor(Qt::red, layer1->colorSpace()));
        // KIS_DUMP_DEVICE_2(key2, refRect, "key2", "dd");
    }

    {
        KisPaintDeviceSP key3 = new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha8());
        key3->fill(QRect(0,0,10,10), KoColor(Qt::black, key3->colorSpace()));
        mask->testingAddKeyStroke(key3, KoColor(Qt::blue, layer1->colorSpace()), true);
        // KIS_DUMP_DEVICE_2(key3, refRect, "key3", "dd");
    }

    KisLayerPropertiesIcons::setNodeProperty(mask, KisLayerPropertiesIcons::colorizeEditKeyStrokes, false, image);
    KisLayerPropertiesIcons::setNodeProperty(mask, KisLayerPropertiesIcons::colorizeShowColoring, false, image);



396
    doc->exportDocument(QUrl::fromLocalFile("roundtrip_colorize.kra"));
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427

    QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument());
    doc2->loadNativeFormat("roundtrip_colorize.kra");
    KisImageSP image2 = doc2->image();
    KisNodeSP node = image2->root()->firstChild()->firstChild();

    KisColorizeMaskSP mask2 = dynamic_cast<KisColorizeMask*>(node.data());
    QVERIFY(mask2);

    QCOMPARE(mask2->compositeOpId(), mask->compositeOpId());
    QCOMPARE(mask2->colorSpace(), mask->colorSpace());
    QCOMPARE(KisLayerPropertiesIcons::nodeProperty(mask, KisLayerPropertiesIcons::colorizeEditKeyStrokes, true).toBool(), false);
    QCOMPARE(KisLayerPropertiesIcons::nodeProperty(mask, KisLayerPropertiesIcons::colorizeShowColoring, true).toBool(), false);

    QList<KisLazyFillTools::KeyStroke> strokes = mask->fetchKeyStrokesDirect();

    qDebug() << ppVar(strokes.size());

    QCOMPARE(strokes[0].dev->exactBounds(), QRect(50,50,10,20));
    QCOMPARE(strokes[0].isTransparent, false);
    QCOMPARE(strokes[0].color.colorSpace(), weirdCS);

    QCOMPARE(strokes[1].dev->exactBounds(), QRect(150,50,10,20));
    QCOMPARE(strokes[1].isTransparent, false);
    QCOMPARE(strokes[1].color.colorSpace(), weirdCS);

    QCOMPARE(strokes[2].dev->exactBounds(), QRect(0,0,10,10));
    QCOMPARE(strokes[2].isTransparent, true);
    QCOMPARE(strokes[2].color.colorSpace(), weirdCS);
}

428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
#include "kis_shape_layer.h"
#include <KoPathShape.h>
#include <KoColorBackground.h>

void KisKraSaverTest::testRoundTripShapeLayer()
{
    TestUtil::ExternalImageChecker chk("kra_saver_test", "shape_layer");

    QRect refRect(0,0,512,512);

    QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument());
    TestUtil::MaskParent p(refRect);

    const qreal resolution = 144.0 / 72.0;
    p.image->setResolution(resolution, resolution);

    doc->setCurrentImage(p.image);
    doc->documentInfo()->setAboutInfo("title", p.image->objectName());

    KoPathShape* path = new KoPathShape();
    path->setShapeId(KoPathShapeId);
    path->moveTo(QPointF(10, 10));
    path->lineTo(QPointF( 10, 110));
    path->lineTo(QPointF(110, 110));
    path->lineTo(QPointF(110,  10));
    path->close();
    path->normalize();
    path->setBackground(toQShared(new KoColorBackground(Qt::red)));

    path->setName("my_precious_shape");

    KisShapeLayerSP shapeLayer = new KisShapeLayer(doc->shapeController(), p.image, "shapeLayer1", 75);
    shapeLayer->addShape(path);
    p.image->addNode(shapeLayer);
    shapeLayer->setDirty();

    qApp->processEvents();
    p.image->waitForDone();

    chk.checkImage(p.image, "00_initial_layer_update");

469
    doc->exportDocument(QUrl::fromLocalFile("roundtrip_shapelayer_test.kra"));
470 471 472 473 474 475 476 477 478 479 480 481 482

    QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument());
    doc2->loadNativeFormat("roundtrip_shapelayer_test.kra");

    qApp->processEvents();
    doc2->image()->waitForDone();
    QCOMPARE(doc2->image()->xRes(), resolution);
    QCOMPARE(doc2->image()->yRes(), resolution);
    chk.checkImage(doc2->image(), "01_shape_layer_round_trip");

    QVERIFY(chk.testPassed());
}

483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
void KisKraSaverTest::testRoundTripShapeSelection()
{
    TestUtil::ExternalImageChecker chk("kra_saver_test", "shape_selection");

    QRect refRect(0,0,512,512);

    QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument());
    TestUtil::MaskParent p(refRect);

    const qreal resolution = 144.0 / 72.0;
    p.image->setResolution(resolution, resolution);

    doc->setCurrentImage(p.image);
    doc->documentInfo()->setAboutInfo("title", p.image->objectName());

    p.layer->paintDevice()->setDefaultPixel(KoColor(Qt::green, p.layer->colorSpace()));

    KisSelectionSP selection = new KisSelection(p.layer->paintDevice()->defaultBounds());

    KisShapeSelection *shapeSelection = new KisShapeSelection(p.image, selection);
    selection->setShapeSelection(shapeSelection);

    KoPathShape* path = new KoPathShape();
    path->setShapeId(KoPathShapeId);
    path->moveTo(QPointF(10, 10));
    path->lineTo(QPointF( 10, 110));
    path->lineTo(QPointF(110, 110));
    path->lineTo(QPointF(110,  10));
    path->close();
    path->normalize();
    path->setBackground(toQShared(new KoColorBackground(Qt::red)));
    path->setName("my_precious_shape");

    shapeSelection->addShape(path);

    KisTransparencyMaskSP tmask = new KisTransparencyMask();
    tmask->setSelection(selection);
    p.image->addNode(tmask, p.layer);

    tmask->setDirty(p.image->bounds());

    qApp->processEvents();
    p.image->waitForDone();

    chk.checkImage(p.image, "00_initial_shape_selection");

    doc->exportDocument(QUrl::fromLocalFile("roundtrip_shapeselection_test.kra"));

    QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument());
    doc2->loadNativeFormat("roundtrip_shapeselection_test.kra");

    qApp->processEvents();
    doc2->image()->waitForDone();
    QCOMPARE(doc2->image()->xRes(), resolution);
    QCOMPARE(doc2->image()->yRes(), resolution);
    chk.checkImage(doc2->image(), "00_initial_shape_selection");

    KisNodeSP node = doc2->image()->root()->firstChild()->firstChild();
    KisTransparencyMask *newMask = dynamic_cast<KisTransparencyMask*>(node.data());
    QVERIFY(newMask);

    QVERIFY(newMask->selection()->hasShapeSelection());

    QVERIFY(chk.testPassed());
}

549
QTEST_MAIN(KisKraSaverTest)