Commit f24ef827 authored by Jouni Pentikäinen's avatar Jouni Pentikäinen

Add unit tests for animated file format

parent e0c03504
......@@ -169,10 +169,8 @@ public:
data = new Data(srcData, false);
}
if (!offset.isNull()) {
data->setX(offset.x());
data->setY(offset.y());
}
data->setX(offset.x());
data->setY(offset.y());
int frameId = nextFreeFrameId++;
m_frames.insert(frameId, data);
......
......@@ -24,6 +24,7 @@
#include <KoDocumentInfo.h>
#include <KoColorSpaceRegistry.h>
#include <KoColorSpace.h>
#include <KoColor.h>
#include "KisDocument.h"
#include "kis_image.h"
......@@ -33,6 +34,9 @@
#include <filter/kis_filter_registry.h>
#include <generator/kis_generator_registry.h>
#include "kis_image_animation_interface.h"
#include "kis_keyframe_channel.h"
#include "kis_time_range.h"
void KisKraLoaderTest::initTestCase()
{
......@@ -108,6 +112,62 @@ void KisKraLoaderTest::testObligeSingleChildNonTranspPixel()
testObligeSingleChildImpl(false);
}
void KisKraLoaderTest::testLoadAnimated()
{
KisDocument *doc = KisPart::instance()->createDocument();
doc->loadNativeFormat(QString(FILES_DATA_DIR) + QDir::separator() + "load_test_animation.kra");
KisImageWSP image = doc->image();
KisNodeSP node1 = image->root()->firstChild();
KisNodeSP node2 = node1->nextSibling();
QVERIFY(node1->inherits("KisPaintLayer"));
QVERIFY(node2->inherits("KisPaintLayer"));
KisPaintLayerSP layer1 = qobject_cast<KisPaintLayer*>(node1.data());
KisPaintLayerSP layer2 = qobject_cast<KisPaintLayer*>(node2.data());
KisKeyframeChannel *channel1 = layer1->getKeyframeChannel(KisKeyframeChannel::Content.id());
KisKeyframeChannel *channel2 = layer2->getKeyframeChannel(KisKeyframeChannel::Content.id());
QCOMPARE(channel1->keyframeCount(), 3);
QCOMPARE(channel2->keyframeCount(), 1);
QCOMPARE(image->animationInterface()->framerate(), 17.0f);
QCOMPARE(image->animationInterface()->currentRange(), KisTimeRange::fromTime(15, 45));
QCOMPARE(image->animationInterface()->currentTime(), 19);
KisPaintDeviceSP dev = layer1->paintDevice();
const KoColorSpace *cs = dev->colorSpace();
KoColor transparent(Qt::transparent, cs);
KoColor white(Qt::white, cs);
KoColor red(Qt::red, cs);
image->animationInterface()->switchCurrentTimeAsync(0);
image->waitForDone();
QCOMPARE(dev->exactBounds(), QRect(506, 378, 198, 198));
QCOMPARE(dev->x(), -26);
QCOMPARE(dev->y(), -128);
QVERIFY(!memcmp(dev->defaultPixel(), transparent.data(), cs->pixelSize()));
image->animationInterface()->switchCurrentTimeAsync(20);
image->waitForDone();
QCOMPARE(dev->nonDefaultPixelArea(), QRect(615, 416, 129, 129));
QCOMPARE(dev->x(), 502);
QCOMPARE(dev->y(), 224);
QVERIFY(!memcmp(dev->defaultPixel(), white.data(), cs->pixelSize()));
image->animationInterface()->switchCurrentTimeAsync(30);
image->waitForDone();
QCOMPARE(dev->nonDefaultPixelArea(), QRect(729, 452, 45, 44));
QCOMPARE(dev->x(), 645);
QCOMPARE(dev->y(), -10);
QVERIFY(!memcmp(dev->defaultPixel(), red.data(), cs->pixelSize()));
}
QTEST_KDEMAIN(KisKraLoaderTest, GUI)
#include "kis_kra_loader_test.moc"
......@@ -30,6 +30,8 @@ private Q_SLOTS:
void testLoading();
void testObligeSingleChild();
void testObligeSingleChildNonTranspPixel();
void testLoadAnimated();
};
#endif
......@@ -46,6 +46,8 @@
#include "kis_shape_selection.h"
#include "util.h"
#include "testutil.h"
#include "kis_keyframe_channel.h"
#include "kis_image_animation_interface.h"
#include "kis_transform_mask_params_interface.h"
......@@ -245,5 +247,73 @@ void KisKraSaverTest::testRoundTripLayerStyles()
QVERIFY(chk.testPassed());
}
void KisKraSaverTest::testRoundTripAnimation()
{
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));
layer1->paintDevice()->setDefaultPixel(KoColor(Qt::red, cs).data());
layer1->addNewFrame(10, true);
image->animationInterface()->switchCurrentTimeAsync(10);
image->waitForDone();
layer1->paintDevice()->fill(QRect(200, 50, 10, 10), KoColor(Qt::black, cs));
layer1->paintDevice()->move(25, 15);
layer1->paintDevice()->setDefaultPixel(KoColor(Qt::green, cs).data());
layer1->addNewFrame(20, true);
image->animationInterface()->switchCurrentTimeAsync(20);
image->waitForDone();
layer1->paintDevice()->fill(QRect(150, 200, 30, 30), KoColor(Qt::black, cs));
layer1->paintDevice()->move(100, 50);
layer1->paintDevice()->setDefaultPixel(KoColor(Qt::blue, cs).data());
QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument());
doc->setCurrentImage(image);
doc->saveNativeFormat("roundtrip_animation.kra");
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());
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);
QVERIFY(!memcmp(layer2->paintDevice()->defaultPixel(), KoColor(Qt::red, cs).data(), cs->pixelSize()));
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);
QVERIFY(!memcmp(layer2->paintDevice()->defaultPixel(), KoColor(Qt::green, cs).data(), cs->pixelSize()));
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);
QVERIFY(!memcmp(layer2->paintDevice()->defaultPixel(), KoColor(Qt::blue, cs).data(), cs->pixelSize()));
}
QTEST_KDEMAIN(KisKraSaverTest, GUI)
#include "kis_kra_saver_test.moc"
......@@ -37,6 +37,8 @@ private Q_SLOTS:
void testRoundTripLayerStyles();
void testRoundTripAnimation();
};
#endif
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