1 /*
2  *  Copyright (c) 2011 Dmitry Kazakov <dimula73@gmail.com>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #include "kis_image_signal_router_test.h"
20 
21 #include <QTest>
22 
23 
checkNotification(KisImageSignalType notification,const char * signal)24 inline void KisImageSignalRouterTest::checkNotification(KisImageSignalType notification, const char *signal)
25 {
26     QSignalSpy *spy = new QSignalSpy(m_image.data(), signal);
27     QCOMPARE(spy->count(), 0);
28     m_image->signalRouter()->emitNotification(notification);
29     QCOMPARE(spy->count(), 1);
30     delete spy;
31 }
32 
33 #define checkComplexSignal(method, signal)                      \
34     {                                                           \
35     QSignalSpy *spy = new QSignalSpy(m_image.data(), signal);   \
36     QCOMPARE(spy->count(), 0);                                  \
37     m_image->signalRouter()->method;                            \
38     QCOMPARE(spy->count(), 1);                                  \
39     delete spy;                                                 \
40     }
41 
init()42 void KisImageSignalRouterTest::init()
43 {
44     initBase();
45     constructImage();
46 }
47 
cleanup()48 void KisImageSignalRouterTest::cleanup()
49 {
50     cleanupBase();
51 }
52 
testSignalForwarding()53 void KisImageSignalRouterTest::testSignalForwarding()
54 {
55 
56     checkNotification(LayersChangedSignal, SIGNAL(sigLayersChangedAsync()));
57     checkNotification(ModifiedSignal, SIGNAL(sigImageModified()));
58     checkNotification(SizeChangedSignal, SIGNAL(sigSizeChanged(QPointF,QPointF)));
59     checkNotification(ComplexSizeChangedSignal(), SIGNAL(sigSizeChanged(QPointF,QPointF)));
60 // These cannot be checked because KoColorProfile and KoColorSpace are not registered metatypes,
61 // and cannot be registered as metatypes because they are abstract classes.
62 //    checkNotification(ProfileChangedSignal, SIGNAL(sigProfileChanged(const KoColorProfile*)));
63 //    checkNotification(ColorSpaceChangedSignal, SIGNAL(sigColorSpaceChanged(const KoColorSpace*)));
64     checkNotification(ResolutionChangedSignal, SIGNAL(sigResolutionChanged(double,double)));
65 
66     checkComplexSignal(emitNodeChanged(m_layer1.data()), SIGNAL(sigNodeChanged(KisNodeSP)));
67     checkComplexSignal(emitNodeHasBeenAdded(m_layer3.data(),0), SIGNAL(sigNodeAddedAsync(KisNodeSP)));
68     checkComplexSignal(emitAboutToRemoveANode(m_layer3.data(),0), SIGNAL(sigRemoveNodeAsync(KisNodeSP)));
69 }
70 
71 QTEST_MAIN(KisImageSignalRouterTest)
72