File indexing completed on 2024-12-22 04:10:28

0001 /*
0002  *  SPDX-FileCopyrightText: 2020 Saurabh Kumar <saurabhk660@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "KisKeyframeAnimationInterfaceSignalTest.h"
0008 
0009 #include <simpletest.h>
0010 #include <qsignalspy.h>
0011 
0012 
0013 void KisKeyframeAnimationInterfaceSignalTest::initTestCase()
0014 {
0015     m_image1 = new KisImage(0, 100, 100, nullptr, "image1");
0016     m_image2 = new KisImage(0, 100, 100, nullptr, "image2");
0017     m_layer = new KisPaintLayer(m_image1, "layer1", OPACITY_OPAQUE_U8);
0018     m_image1->addNode(m_layer);
0019     m_channel = m_layer->getKeyframeChannel(KisKeyframeChannel::Raster.id(), true);
0020 }
0021 
0022 void KisKeyframeAnimationInterfaceSignalTest::init()
0023 {
0024     m_channel->addKeyframe(0);
0025 
0026     //delete all  keyframes other than 1st
0027     while (m_channel->keyframeAt(m_channel->firstKeyframeTime()) != m_channel->keyframeAt(m_channel->lastKeyframeTime())) {
0028         m_channel->removeKeyframe(m_channel->lastKeyframeTime());
0029     }
0030     QCOMPARE(m_channel->keyframeCount(), 1);
0031 }
0032 
0033 void KisKeyframeAnimationInterfaceSignalTest::testSignalFromKeyframeChannelToInterface()
0034 {
0035 
0036     QCOMPARE(m_channel->keyframeCount(), 1);
0037 
0038     //add keyframe
0039     qRegisterMetaType<const KisKeyframeChannel*>("const KisKeyframeChannel*");
0040     QSignalSpy spyFrameAdded(m_image1->animationInterface() , SIGNAL(sigKeyframeAdded(const KisKeyframeChannel*, int)));
0041     QVERIFY(spyFrameAdded.isValid());
0042 
0043     m_channel->addKeyframe(2);
0044     QCOMPARE(spyFrameAdded.count(), 1);
0045 
0046     //remove keyframe
0047     QSignalSpy spyFrameRemoved(m_image1->animationInterface() , SIGNAL(sigKeyframeRemoved(const KisKeyframeChannel*, int)));
0048     QVERIFY(spyFrameRemoved.isValid());
0049 
0050     m_channel->removeKeyframe(5);
0051     QCOMPARE(spyFrameRemoved.count(), 1);
0052 }
0053 
0054 void KisKeyframeAnimationInterfaceSignalTest::testSignalOnImageReset()
0055 {
0056     m_image1->removeNode(m_layer);
0057     m_image2->addNode(m_layer);
0058 
0059     QCOMPARE(m_layer->image(), KisImageWSP(m_image2));
0060 
0061     //test the connections between m_channel and new image's animation interface
0062     QVERIFY(!connect(m_channel, SIGNAL(sigAddedKeyframe(const KisKeyframeChannel*,int)), m_image2->animationInterface(), SIGNAL(sigKeyframeAdded(const KisKeyframeChannel*, int)), Qt::UniqueConnection));
0063 
0064     //test signals from the old image on changing m_channel after image reset
0065     QSignalSpy spyFrameAdded(m_image1->animationInterface() , SIGNAL(sigKeyframeAdded(const KisKeyframeChannel*, int)));
0066     QVERIFY(spyFrameAdded.isValid());
0067     
0068     QSignalSpy spyFrameRemoved(m_image1->animationInterface() , SIGNAL(sigKeyframeRemoved(const KisKeyframeChannel*, int)));
0069     QVERIFY(spyFrameRemoved.isValid());
0070 
0071     //check if signal are emitted from the new image on changing m_channel
0072     QSignalSpy newSpyFrameAdded(m_image2->animationInterface() , SIGNAL(sigKeyframeAdded(const KisKeyframeChannel*, int)));
0073     QVERIFY(newSpyFrameAdded.isValid());
0074 
0075     QSignalSpy newSpyFrameRemoved(m_image2->animationInterface() , SIGNAL(sigKeyframeRemoved(const KisKeyframeChannel*, int)));
0076     QVERIFY(newSpyFrameRemoved.isValid());
0077 
0078     m_channel->addKeyframe(2);
0079     m_channel->removeKeyframe(2);
0080 
0081     QCOMPARE(spyFrameAdded.count(), 0);
0082     QCOMPARE(spyFrameRemoved.count(), 0);
0083 
0084     QCOMPARE(newSpyFrameAdded.count(), 1);
0085     QCOMPARE(newSpyFrameRemoved.count(), 1);
0086 
0087     QCOMPARE(m_channel->keyframeCount(), 1);
0088 }
0089 
0090 SIMPLE_TEST_MAIN(KisKeyframeAnimationInterfaceSignalTest)