File indexing completed on 2024-12-22 04:15:45
0001 /* 0002 * SPDX-FileCopyrightText: 2007 Boudewijn Rempt boud @valdyas.org 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_kra_saver_test.h" 0008 0009 #include <simpletest.h> 0010 0011 #include <QBitArray> 0012 0013 #include <KisDocument.h> 0014 #include <KoDocumentInfo.h> 0015 #include <KoShapeContainer.h> 0016 #include <KoPathShape.h> 0017 0018 #include "filter/kis_filter_registry.h" 0019 #include "filter/kis_filter_configuration.h" 0020 #include "filter/kis_filter.h" 0021 #include "kis_image.h" 0022 #include <KisImageResolutionProxy.h> 0023 #include "kis_pixel_selection.h" 0024 #include "kis_group_layer.h" 0025 #include "kis_paint_layer.h" 0026 #include "kis_clone_layer.h" 0027 #include "kis_adjustment_layer.h" 0028 #include "kis_shape_layer.h" 0029 #include "kis_filter_mask.h" 0030 #include "kis_transparency_mask.h" 0031 #include "kis_selection_mask.h" 0032 #include "kis_selection.h" 0033 #include "kis_fill_painter.h" 0034 #include "kis_shape_selection.h" 0035 #include "util.h" 0036 #include <testutil.h> 0037 #include "kis_keyframe_channel.h" 0038 #include "kis_image_animation_interface.h" 0039 #include "kis_layer_properties_icons.h" 0040 #include <KisGlobalResourcesInterface.h> 0041 0042 #include "KritaTransformMaskStubs.h" 0043 #include "KisDumbTransformMaskParams.h" 0044 0045 #include "StoryboardItem.h" 0046 0047 #include <generator/kis_generator_registry.h> 0048 0049 #include <KoResourcePaths.h> 0050 #include <filestest.h> 0051 #include <testui.h> 0052 0053 0054 const QString KraMimetype = "application/x-krita"; 0055 0056 void KisKraSaverTest::initTestCase() 0057 { 0058 KoResourcePaths::addAssetDir(ResourceType::Patterns, QString(SYSTEM_RESOURCES_DATA_DIR) + "/patterns"); 0059 0060 KisFilterRegistry::instance(); 0061 KisGeneratorRegistry::instance(); 0062 0063 TestUtil::registerTransformMaskStubs(); 0064 } 0065 0066 void KisKraSaverTest::testCrashyShapeLayer() 0067 { 0068 /** 0069 * KisShapeLayer used to call setImage from its destructor and 0070 * therefore causing an infinite recursion (when at least one transparency 0071 * mask was preset. This testcase just checks that. 0072 */ 0073 0074 //QScopedPointer<KisDocument> doc(createCompleteDocument(true)); 0075 //Q_UNUSED(doc); 0076 } 0077 0078 void KisKraSaverTest::testRoundTrip() 0079 { 0080 KisDocument* doc = createCompleteDocument(); 0081 KoColor bgColor(Qt::red, doc->image()->colorSpace()); 0082 doc->image()->setDefaultProjectionColor(bgColor); 0083 doc->exportDocumentSync("roundtriptest.kra", doc->mimeType()); 0084 0085 QStringList list; 0086 KisCountVisitor cv1(list, KoProperties()); 0087 doc->image()->rootLayer()->accept(cv1); 0088 0089 KisDocument *doc2 = KisPart::instance()->createDocument(); 0090 bool result = doc2->loadNativeFormat("roundtriptest.kra"); 0091 QVERIFY(result); 0092 0093 KisCountVisitor cv2(list, KoProperties()); 0094 doc2->image()->rootLayer()->accept(cv2); 0095 QCOMPARE(cv1.count(), cv2.count()); 0096 0097 // check whether the BG color is saved correctly 0098 QCOMPARE(doc2->image()->defaultProjectionColor(), bgColor); 0099 0100 // test round trip of a transform mask 0101 KisNode* tnode = 0102 TestUtil::findNode(doc2->image()->rootLayer(), "testTransformMask").data(); 0103 QVERIFY(tnode); 0104 KisTransformMask *tmask = dynamic_cast<KisTransformMask*>(tnode); 0105 QVERIFY(tmask); 0106 KisDumbTransformMaskParams *params = dynamic_cast<KisDumbTransformMaskParams*>(tmask->transformParams().data()); 0107 QVERIFY(params); 0108 QTransform t = params->testingGetTransform(); 0109 QCOMPARE(t, createTestingTransform()); 0110 0111 0112 delete doc2; 0113 delete doc; 0114 } 0115 0116 void KisKraSaverTest::testSaveEmpty() 0117 { 0118 KisDocument* doc = createEmptyDocument(); 0119 doc->exportDocumentSync("emptytest.kra", doc->mimeType()); 0120 QStringList list; 0121 KisCountVisitor cv1(list, KoProperties()); 0122 doc->image()->rootLayer()->accept(cv1); 0123 0124 KisDocument *doc2 = KisPart::instance()->createDocument(); 0125 doc2->loadNativeFormat("emptytest.kra"); 0126 0127 KisCountVisitor cv2(list, KoProperties()); 0128 doc2->image()->rootLayer()->accept(cv2); 0129 QCOMPARE(cv1.count(), cv2.count()); 0130 0131 delete doc2; 0132 delete doc; 0133 } 0134 0135 #include <generator/kis_generator.h> 0136 0137 void testRoundTripFillLayerImpl(const QString &testName, KisFilterConfigurationSP config) 0138 { 0139 TestUtil::ReferenceImageChecker chk(testName, "fill_layer"); 0140 chk.setFuzzy(2); 0141 0142 QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument()); 0143 0144 // mask parent should be destructed before the document! 0145 QRect refRect(0,0,512,512); 0146 TestUtil::MaskParent p(refRect); 0147 0148 doc->setCurrentImage(p.image); 0149 doc->documentInfo()->setAboutInfo("title", p.image->objectName()); 0150 0151 KisSelectionSP selection; 0152 KisGeneratorLayerSP glayer = new KisGeneratorLayer(p.image, "glayer", config->cloneWithResourcesSnapshot(), selection); 0153 0154 p.image->addNode(glayer, p.image->root(), KisNodeSP()); 0155 glayer->setDirty(); 0156 0157 p.image->waitForDone(); 0158 chk.checkImage(p.image, "00_initial_layer_update"); 0159 0160 doc->exportDocumentSync("roundtrip_fill_layer_test.kra", doc->mimeType()); 0161 0162 QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument()); 0163 doc2->loadNativeFormat("roundtrip_fill_layer_test.kra"); 0164 0165 doc2->image()->waitForDone(); 0166 chk.checkImage(doc2->image(), "01_fill_layer_round_trip"); 0167 0168 QVERIFY(chk.testPassed()); 0169 } 0170 0171 void KisKraSaverTest::testRoundTripFillLayerColor() 0172 { 0173 const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8(); 0174 0175 KisGeneratorSP generator = KisGeneratorRegistry::instance()->get("color"); 0176 Q_ASSERT(generator); 0177 0178 // warning: we pass null paint device to the default constructed value 0179 KisFilterConfigurationSP config = generator->defaultConfiguration(KisGlobalResourcesInterface::instance()); 0180 Q_ASSERT(config); 0181 0182 QVariant v; 0183 v.setValue(KoColor(Qt::red, cs)); 0184 config->setProperty("color", v); 0185 0186 testRoundTripFillLayerImpl("fill_layer_color", config); 0187 } 0188 0189 void KisKraSaverTest::testRoundTripFillLayerPattern() 0190 { 0191 KisGeneratorSP generator = KisGeneratorRegistry::instance()->get("pattern"); 0192 QVERIFY(generator); 0193 0194 // warning: we pass null paint device to the default constructed value 0195 KisFilterConfigurationSP config = generator->defaultConfiguration(KisGlobalResourcesInterface::instance()); 0196 QVERIFY(config); 0197 0198 QVariant v; 0199 v.setValue(QString("11_drawed_furry.png")); 0200 config->setProperty("pattern", v); 0201 0202 testRoundTripFillLayerImpl("fill_layer_pattern", config); 0203 } 0204 0205 #include "kis_psd_layer_style.h" 0206 0207 0208 void KisKraSaverTest::testRoundTripLayerStyles() 0209 { 0210 TestUtil::ReferenceImageChecker chk("kra_saver_test", "layer_styles"); 0211 0212 QRect imageRect(0,0,512,512); 0213 0214 // the document should be created before the image! 0215 QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument()); 0216 0217 const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8(); 0218 KisImageSP image = new KisImage(new KisSurrogateUndoStore(), imageRect.width(), imageRect.height(), cs, "test image"); 0219 KisPaintLayerSP layer1 = new KisPaintLayer(image, "paint1", OPACITY_OPAQUE_U8); 0220 KisPaintLayerSP layer2 = new KisPaintLayer(image, "paint2", OPACITY_OPAQUE_U8); 0221 KisPaintLayerSP layer3 = new KisPaintLayer(image, "paint3", OPACITY_OPAQUE_U8); 0222 image->addNode(layer1); 0223 image->addNode(layer2); 0224 image->addNode(layer3); 0225 0226 doc->setCurrentImage(image); 0227 doc->documentInfo()->setAboutInfo("title", image->objectName()); 0228 0229 layer1->paintDevice()->fill(QRect(100, 100, 100, 100), KoColor(Qt::red, cs)); 0230 layer2->paintDevice()->fill(QRect(200, 200, 100, 100), KoColor(Qt::green, cs)); 0231 layer3->paintDevice()->fill(QRect(300, 300, 100, 100), KoColor(Qt::blue, cs)); 0232 0233 KisPSDLayerStyleSP style(new KisPSDLayerStyle()); 0234 style->dropShadow()->setEffectEnabled(true); 0235 0236 0237 style->dropShadow()->setAngle(-90); 0238 style->dropShadow()->setUseGlobalLight(false); 0239 layer1->setLayerStyle(style->clone().dynamicCast<KisPSDLayerStyle>()); 0240 0241 style->dropShadow()->setAngle(180); 0242 style->dropShadow()->setUseGlobalLight(true); 0243 layer2->setLayerStyle(style->clone().dynamicCast<KisPSDLayerStyle>()); 0244 0245 style->dropShadow()->setAngle(90); 0246 style->dropShadow()->setUseGlobalLight(false); 0247 layer3->setLayerStyle(style->clone().dynamicCast<KisPSDLayerStyle>()); 0248 0249 image->initialRefreshGraph(); 0250 chk.checkImage(image, "00_initial_layers"); 0251 0252 doc->exportDocumentSync("roundtrip_layer_styles.kra", doc->mimeType()); 0253 0254 0255 QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument()); 0256 doc2->loadNativeFormat("roundtrip_layer_styles.kra"); 0257 0258 doc2->image()->waitForDone(); 0259 chk.checkImage(doc2->image(), "00_initial_layers"); 0260 0261 QVERIFY(chk.testPassed()); 0262 } 0263 0264 void KisKraSaverTest::testRoundTripAnimation() 0265 { 0266 QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument()); 0267 0268 QRect imageRect(0,0,512,512); 0269 const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8(); 0270 KisImageSP image = new KisImage(new KisSurrogateUndoStore(), imageRect.width(), imageRect.height(), cs, "test image"); 0271 KisPaintLayerSP layer1 = new KisPaintLayer(image, "paint1", OPACITY_OPAQUE_U8); 0272 image->addNode(layer1); 0273 0274 layer1->paintDevice()->fill(QRect(100, 100, 50, 50), KoColor(Qt::black, cs)); 0275 layer1->paintDevice()->setDefaultPixel(KoColor(Qt::red, cs)); 0276 0277 KUndo2Command parentCommand; 0278 0279 layer1->enableAnimation(); 0280 KisKeyframeChannel *rasterChannel = layer1->getKeyframeChannel(KisKeyframeChannel::Raster.id(), true); 0281 QVERIFY(rasterChannel); 0282 0283 rasterChannel->addKeyframe(10, &parentCommand); 0284 image->animationInterface()->switchCurrentTimeAsync(10); 0285 image->waitForDone(); 0286 layer1->paintDevice()->fill(QRect(200, 50, 10, 10), KoColor(Qt::black, cs)); 0287 layer1->paintDevice()->moveTo(25, 15); 0288 layer1->paintDevice()->setDefaultPixel(KoColor(Qt::green, cs)); 0289 0290 rasterChannel->addKeyframe(20, &parentCommand); 0291 image->animationInterface()->switchCurrentTimeAsync(20); 0292 image->waitForDone(); 0293 layer1->paintDevice()->fill(QRect(150, 200, 30, 30), KoColor(Qt::black, cs)); 0294 layer1->paintDevice()->moveTo(100, 50); 0295 layer1->paintDevice()->setDefaultPixel(KoColor(Qt::blue, cs)); 0296 0297 QVERIFY(!layer1->isPinnedToTimeline()); 0298 layer1->setPinnedToTimeline(true); 0299 0300 doc->setCurrentImage(image); 0301 doc->exportDocumentSync("roundtrip_animation.kra", doc->mimeType()); 0302 0303 QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument()); 0304 doc2->loadNativeFormat("roundtrip_animation.kra"); 0305 KisImageSP image2 = doc2->image(); 0306 KisNodeSP node = image2->root()->firstChild(); 0307 0308 QVERIFY(node->inherits("KisPaintLayer")); 0309 KisPaintLayerSP layer2 = qobject_cast<KisPaintLayer*>(node.data()); 0310 cs = layer2->paintDevice()->colorSpace(); 0311 0312 QCOMPARE(image2->animationInterface()->currentTime(), 20); 0313 KisKeyframeChannel *channel = layer2->getKeyframeChannel(KisKeyframeChannel::Raster.id()); 0314 QVERIFY(channel); 0315 QCOMPARE(channel->keyframeCount(), 3); 0316 0317 image2->animationInterface()->switchCurrentTimeAsync(0); 0318 image2->waitForDone(); 0319 0320 QCOMPARE(layer2->paintDevice()->nonDefaultPixelArea(), QRect(64, 64, 128, 128)); 0321 QCOMPARE(layer2->paintDevice()->x(), 0); 0322 QCOMPARE(layer2->paintDevice()->y(), 0); 0323 QCOMPARE(layer2->paintDevice()->defaultPixel(), KoColor(Qt::red, cs)); 0324 0325 image2->animationInterface()->switchCurrentTimeAsync(10); 0326 image2->waitForDone(); 0327 0328 QCOMPARE(layer2->paintDevice()->nonDefaultPixelArea(), QRect(217, 15, 64, 64)); 0329 QCOMPARE(layer2->paintDevice()->x(), 25); 0330 QCOMPARE(layer2->paintDevice()->y(), 15); 0331 QCOMPARE(layer2->paintDevice()->defaultPixel(), KoColor(Qt::green, cs)); 0332 0333 image2->animationInterface()->switchCurrentTimeAsync(20); 0334 image2->waitForDone(); 0335 0336 QCOMPARE(layer2->paintDevice()->nonDefaultPixelArea(), QRect(228, 242, 64, 64)); 0337 QCOMPARE(layer2->paintDevice()->x(), 100); 0338 QCOMPARE(layer2->paintDevice()->y(), 50); 0339 QCOMPARE(layer2->paintDevice()->defaultPixel(), KoColor(Qt::blue, cs)); 0340 0341 QVERIFY(layer2->isPinnedToTimeline()); 0342 0343 } 0344 0345 #include "lazybrush/kis_lazy_fill_tools.h" 0346 0347 void KisKraSaverTest::testRoundTripColorizeMask() 0348 { 0349 QRect imageRect(0,0,512,512); 0350 const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8(); 0351 const KoColorSpace * weirdCS = KoColorSpaceRegistry::instance()->rgb16(); 0352 0353 QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument()); 0354 KisImageSP image = new KisImage(new KisSurrogateUndoStore(), imageRect.width(), imageRect.height(), cs, "test image"); 0355 doc->setCurrentImage(image); 0356 0357 KisPaintLayerSP layer1 = new KisPaintLayer(image, "paint1", OPACITY_OPAQUE_U8, weirdCS); 0358 image->addNode(layer1); 0359 0360 KisColorizeMaskSP mask = new KisColorizeMask(image, "mask1"); 0361 image->addNode(mask, layer1); 0362 mask->initializeCompositeOp(); 0363 delete mask->setColorSpace(layer1->colorSpace()); 0364 0365 { 0366 KisPaintDeviceSP key1 = new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha8()); 0367 key1->fill(QRect(50,50,10,20), KoColor(Qt::black, key1->colorSpace())); 0368 mask->testingAddKeyStroke(key1, KoColor(Qt::green, layer1->colorSpace())); 0369 // KIS_DUMP_DEVICE_2(key1, refRect, "key1", "dd"); 0370 } 0371 0372 { 0373 KisPaintDeviceSP key2 = new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha8()); 0374 key2->fill(QRect(150,50,10,20), KoColor(Qt::black, key2->colorSpace())); 0375 mask->testingAddKeyStroke(key2, KoColor(Qt::red, layer1->colorSpace())); 0376 // KIS_DUMP_DEVICE_2(key2, refRect, "key2", "dd"); 0377 } 0378 0379 { 0380 KisPaintDeviceSP key3 = new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha8()); 0381 key3->fill(QRect(0,0,10,10), KoColor(Qt::black, key3->colorSpace())); 0382 mask->testingAddKeyStroke(key3, KoColor(Qt::blue, layer1->colorSpace()), true); 0383 // KIS_DUMP_DEVICE_2(key3, refRect, "key3", "dd"); 0384 } 0385 0386 KisLayerPropertiesIcons::setNodePropertyAutoUndo(mask, KisLayerPropertiesIcons::colorizeEditKeyStrokes, false, image); 0387 KisLayerPropertiesIcons::setNodePropertyAutoUndo(mask, KisLayerPropertiesIcons::colorizeShowColoring, false, image); 0388 image->waitForDone(); 0389 0390 0391 0392 doc->exportDocumentSync("roundtrip_colorize.kra", doc->mimeType()); 0393 0394 QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument()); 0395 doc2->loadNativeFormat("roundtrip_colorize.kra"); 0396 KisImageSP image2 = doc2->image(); 0397 KisNodeSP node = image2->root()->firstChild()->firstChild(); 0398 0399 KisColorizeMaskSP mask2 = dynamic_cast<KisColorizeMask*>(node.data()); 0400 QVERIFY(mask2); 0401 0402 QCOMPARE(mask2->compositeOpId(), mask->compositeOpId()); 0403 QCOMPARE(*mask2->colorSpace(), *mask->colorSpace()); 0404 QCOMPARE(KisLayerPropertiesIcons::nodeProperty(mask, KisLayerPropertiesIcons::colorizeEditKeyStrokes, true).toBool(), false); 0405 QCOMPARE(KisLayerPropertiesIcons::nodeProperty(mask, KisLayerPropertiesIcons::colorizeShowColoring, true).toBool(), false); 0406 0407 QList<KisLazyFillTools::KeyStroke> strokes = mask->fetchKeyStrokesDirect(); 0408 0409 QCOMPARE(strokes[0].dev->exactBounds(), QRect(50,50,10,20)); 0410 QCOMPARE(strokes[0].isTransparent, false); 0411 QCOMPARE(strokes[0].color.colorSpace(), weirdCS); 0412 0413 QCOMPARE(strokes[1].dev->exactBounds(), QRect(150,50,10,20)); 0414 QCOMPARE(strokes[1].isTransparent, false); 0415 QCOMPARE(strokes[1].color.colorSpace(), weirdCS); 0416 0417 QCOMPARE(strokes[2].dev->exactBounds(), QRect(0,0,10,10)); 0418 QCOMPARE(strokes[2].isTransparent, true); 0419 QCOMPARE(strokes[2].color.colorSpace(), weirdCS); 0420 } 0421 0422 #include <KoColorBackground.h> 0423 0424 void KisKraSaverTest::testRoundTripShapeLayer() 0425 { 0426 TestUtil::ReferenceImageChecker chk("kra_saver_test", "shape_layer"); 0427 0428 QRect refRect(0,0,512,512); 0429 0430 QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument()); 0431 TestUtil::MaskParent p(refRect); 0432 0433 const qreal resolution = 144.0 / 72.0; 0434 p.image->setResolution(resolution, resolution); 0435 0436 doc->setCurrentImage(p.image); 0437 doc->documentInfo()->setAboutInfo("title", p.image->objectName()); 0438 0439 KoPathShape* path = new KoPathShape(); 0440 path->setShapeId(KoPathShapeId); 0441 path->moveTo(QPointF(10, 10)); 0442 path->lineTo(QPointF( 10, 110)); 0443 path->lineTo(QPointF(110, 110)); 0444 path->lineTo(QPointF(110, 10)); 0445 path->close(); 0446 path->normalize(); 0447 path->setBackground(toQShared(new KoColorBackground(Qt::red))); 0448 0449 path->setName("my_precious_shape"); 0450 0451 KisShapeLayerSP shapeLayer = new KisShapeLayer(doc->shapeController(), p.image, "shapeLayer1", 75); 0452 shapeLayer->addShape(path); 0453 p.image->addNode(shapeLayer); 0454 shapeLayer->setDirty(); 0455 0456 qApp->processEvents(); 0457 p.image->waitForDone(); 0458 0459 chk.checkImage(p.image, "00_initial_layer_update"); 0460 0461 doc->exportDocumentSync("roundtrip_shapelayer_test.kra", doc->mimeType()); 0462 0463 QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument()); 0464 doc2->loadNativeFormat("roundtrip_shapelayer_test.kra"); 0465 0466 qApp->processEvents(); 0467 doc2->image()->waitForDone(); 0468 QCOMPARE(doc2->image()->xRes(), resolution); 0469 QCOMPARE(doc2->image()->yRes(), resolution); 0470 chk.checkImage(doc2->image(), "01_shape_layer_round_trip"); 0471 0472 QVERIFY(chk.testPassed()); 0473 } 0474 0475 void KisKraSaverTest::testRoundTripShapeSelection() 0476 { 0477 TestUtil::ReferenceImageChecker chk("kra_saver_test", "shape_selection"); 0478 0479 QRect refRect(0,0,512,512); 0480 0481 QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument()); 0482 TestUtil::MaskParent p(refRect); 0483 doc->setCurrentImage(p.image); 0484 const qreal resolution = 144.0 / 72.0; 0485 p.image->setResolution(resolution, resolution); 0486 0487 doc->setCurrentImage(p.image); 0488 doc->documentInfo()->setAboutInfo("title", p.image->objectName()); 0489 0490 p.layer->paintDevice()->setDefaultPixel(KoColor(Qt::green, p.layer->colorSpace())); 0491 0492 KisImageResolutionProxySP resolutionProxy(new KisImageResolutionProxy(p.image)); 0493 KisSelectionSP selection = new KisSelection(p.layer->paintDevice() ->defaultBounds(), resolutionProxy); 0494 KisShapeSelection *shapeSelection = new KisShapeSelection(doc->shapeController(), selection); 0495 selection->convertToVectorSelectionNoUndo(shapeSelection); 0496 0497 KoPathShape* path = new KoPathShape(); 0498 path->setShapeId(KoPathShapeId); 0499 path->moveTo(QPointF(10, 10)); 0500 path->lineTo(QPointF( 10, 110)); 0501 path->lineTo(QPointF(110, 110)); 0502 path->lineTo(QPointF(110, 10)); 0503 path->close(); 0504 path->normalize(); 0505 path->setBackground(toQShared(new KoColorBackground(Qt::red))); 0506 path->setName("my_precious_shape"); 0507 0508 shapeSelection->addShape(path); 0509 0510 KisTransparencyMaskSP tmask = new KisTransparencyMask(p.image, "tmask"); 0511 tmask->setSelection(selection); 0512 p.image->addNode(tmask, p.layer); 0513 0514 tmask->setDirty(p.image->bounds()); 0515 0516 qApp->processEvents(); 0517 p.image->waitForDone(); 0518 0519 chk.checkImage(p.image, "00_initial_shape_selection"); 0520 0521 doc->exportDocumentSync("roundtrip_shapeselection_test.kra", doc->mimeType()); 0522 0523 QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument()); 0524 doc2->loadNativeFormat("roundtrip_shapeselection_test.kra"); 0525 0526 qApp->processEvents(); 0527 doc2->image()->waitForDone(); 0528 QCOMPARE(doc2->image()->xRes(), resolution); 0529 QCOMPARE(doc2->image()->yRes(), resolution); 0530 chk.checkImage(doc2->image(), "00_initial_shape_selection"); 0531 0532 KisNodeSP node = doc2->image()->root()->firstChild()->firstChild(); 0533 KisTransparencyMask *newMask = dynamic_cast<KisTransparencyMask*>(node.data()); 0534 QVERIFY(newMask); 0535 0536 QVERIFY(newMask->selection()->hasNonEmptyShapeSelection()); 0537 0538 QVERIFY(chk.testPassed()); 0539 } 0540 0541 0542 void KisKraSaverTest::testRoundTripStoryboard() 0543 { 0544 const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8(); 0545 QRect imageRect(0,0,512,512); 0546 0547 QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument()); 0548 KisImageSP image = new KisImage(new KisSurrogateUndoStore(), imageRect.width(), imageRect.height(), cs, "test image"); 0549 doc->setCurrentImage(image); 0550 0551 // TODO: make initialization of StoryboardItem more fool-proof 0552 StoryboardItemSP item(new StoryboardItem()); 0553 item->appendChild(QVariant::fromValue(ThumbnailData())); 0554 item->appendChild("scene0"); 0555 item->appendChild(10); 0556 item->appendChild(2); 0557 0558 StoryboardItemList list; 0559 list.append(item); 0560 0561 doc->setStoryboardItemList(list); 0562 bool result = doc->exportDocumentSync("storyboardroundtriptest.kra", doc->mimeType()); 0563 QVERIFY(result); 0564 0565 QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument()); 0566 result = doc2->loadNativeFormat("storyboardroundtriptest.kra"); 0567 QVERIFY(result); 0568 0569 QCOMPARE(doc2->getStoryboardItemList().count(), list.count()); 0570 } 0571 0572 void KisKraSaverTest::testExportToReadonly() 0573 { 0574 TestUtil::testExportToReadonly(KraMimetype); 0575 } 0576 0577 KISTEST_MAIN(KisKraSaverTest)