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_loader_test.h" 0008 0009 #include <simpletest.h> 0010 0011 #include <KisDocument.h> 0012 #include <KoDocumentInfo.h> 0013 #include <KoColorSpaceRegistry.h> 0014 #include <KoColorSpace.h> 0015 #include <KoColor.h> 0016 0017 #include "kis_image.h" 0018 #include <testutil.h> 0019 #include "KisPart.h" 0020 0021 #include <filter/kis_filter_registry.h> 0022 #include <generator/kis_generator_registry.h> 0023 0024 #include "kis_image_animation_interface.h" 0025 #include "kis_keyframe_channel.h" 0026 #include "kis_time_span.h" 0027 0028 #include <filestest.h> 0029 0030 #include <testui.h> 0031 0032 const QString KraMimetype = "application/x-krita"; 0033 0034 void KisKraLoaderTest::initTestCase() 0035 { 0036 KisFilterRegistry::instance(); 0037 KisGeneratorRegistry::instance(); 0038 } 0039 0040 void KisKraLoaderTest::testLoading() 0041 { 0042 QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument()); 0043 doc->loadNativeFormat(QString(FILES_DATA_DIR) + '/' + "load_test.kra"); 0044 KisImageSP image = doc->image(); 0045 image->waitForDone(); 0046 QCOMPARE(image->nlayers(), 12); 0047 QCOMPARE(doc->documentInfo()->aboutInfo("title"), QString("test image for loading")); 0048 QCOMPARE(image->height(), 753); 0049 QCOMPARE(image->width(), 1000); 0050 QCOMPARE(image->colorSpace()->id(), KoColorSpaceRegistry::instance()->rgb8()->id()); 0051 0052 KisNodeSP node = image->root()->firstChild(); 0053 QVERIFY(node); 0054 QCOMPARE(node->name(), QString("Background")); 0055 QVERIFY(node->inherits("KisPaintLayer")); 0056 0057 node = node->nextSibling(); 0058 QVERIFY(node); 0059 QCOMPARE(node->name(), QString("Group 1")); 0060 QVERIFY(node->inherits("KisGroupLayer")); 0061 QCOMPARE((int) node->childCount(), 2); 0062 } 0063 0064 void testObligeSingleChildImpl(bool transpDefaultPixel) 0065 { 0066 0067 QString id = !transpDefaultPixel ? 0068 "single_layer_no_channel_flags_nontransp_def_pixel.kra" : 0069 "single_layer_no_channel_flags_transp_def_pixel.kra"; 0070 0071 QString fileName = TestUtil::fetchDataFileLazy(id); 0072 0073 QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument()); 0074 const bool result = doc->loadNativeFormat(fileName); 0075 QVERIFY(result); 0076 0077 KisImageSP image = doc->image(); 0078 0079 QVERIFY(image); 0080 QCOMPARE(image->nlayers(), 2); 0081 0082 KisNodeSP root = image->root(); 0083 KisNodeSP child = root->firstChild(); 0084 0085 QVERIFY(child); 0086 0087 QCOMPARE(root->original(), root->projection()); 0088 0089 if (transpDefaultPixel) { 0090 QCOMPARE(root->original(), child->projection()); 0091 } else { 0092 QVERIFY(root->original() != child->projection()); 0093 } 0094 } 0095 0096 void KisKraLoaderTest::testObligeSingleChild() 0097 { 0098 testObligeSingleChildImpl(true); 0099 } 0100 0101 void KisKraLoaderTest::testObligeSingleChildNonTranspPixel() 0102 { 0103 testObligeSingleChildImpl(false); 0104 } 0105 0106 void KisKraLoaderTest::testLoadAnimated() 0107 { 0108 QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument()); 0109 doc->loadNativeFormat(QString(FILES_DATA_DIR) + '/' + "load_test_animation.kra"); 0110 KisImageSP image = doc->image(); 0111 0112 KisNodeSP node1 = image->root()->firstChild(); 0113 KisNodeSP node2 = node1->nextSibling(); 0114 0115 QVERIFY(node1->inherits("KisPaintLayer")); 0116 QVERIFY(node2->inherits("KisPaintLayer")); 0117 0118 KisPaintLayerSP layer1 = qobject_cast<KisPaintLayer*>(node1.data()); 0119 KisPaintLayerSP layer2 = qobject_cast<KisPaintLayer*>(node2.data()); 0120 0121 QVERIFY(layer1->isAnimated()); 0122 QVERIFY(!layer2->isAnimated()); 0123 0124 KisKeyframeChannel *channel1 = layer1->getKeyframeChannel(KisKeyframeChannel::Raster.id()); 0125 QVERIFY(channel1); 0126 QCOMPARE(channel1->keyframeCount(), 3); 0127 0128 QCOMPARE(image->animationInterface()->framerate(), 17); 0129 QCOMPARE(image->animationInterface()->documentPlaybackRange(), KisTimeSpan::fromTimeToTime(15, 45)); 0130 QCOMPARE(image->animationInterface()->currentTime(), 19); 0131 0132 KisPaintDeviceSP dev = layer1->paintDevice(); 0133 0134 const KoColorSpace *cs = dev->colorSpace(); 0135 KoColor transparent(Qt::transparent, cs); 0136 KoColor white(Qt::white, cs); 0137 KoColor red(Qt::red, cs); 0138 0139 image->animationInterface()->switchCurrentTimeAsync(0); 0140 image->waitForDone(); 0141 0142 QCOMPARE(dev->exactBounds(), QRect(506, 378, 198, 198)); 0143 QCOMPARE(dev->x(), -26); 0144 QCOMPARE(dev->y(), -128); 0145 QCOMPARE(dev->defaultPixel(), transparent); 0146 0147 image->animationInterface()->switchCurrentTimeAsync(20); 0148 image->waitForDone(); 0149 0150 QCOMPARE(dev->nonDefaultPixelArea(), QRect(615, 416, 129, 129)); 0151 QCOMPARE(dev->x(), 502); 0152 QCOMPARE(dev->y(), 224); 0153 QCOMPARE(dev->defaultPixel(), white); 0154 0155 image->animationInterface()->switchCurrentTimeAsync(30); 0156 image->waitForDone(); 0157 0158 QCOMPARE(dev->nonDefaultPixelArea(), QRect(729, 452, 45, 44)); 0159 QCOMPARE(dev->x(), 645); 0160 QCOMPARE(dev->y(), -10); 0161 QCOMPARE(dev->defaultPixel(), red); 0162 } 0163 0164 0165 0166 void KisKraLoaderTest::testImportFromWriteonly() 0167 { 0168 TestUtil::testImportFromWriteonly(KraMimetype); 0169 } 0170 0171 0172 void KisKraLoaderTest::testImportIncorrectFormat() 0173 { 0174 TestUtil::testImportIncorrectFormat(KraMimetype); 0175 } 0176 0177 0178 0179 KISTEST_MAIN(KisKraLoaderTest)