|
| 1 | +/*************************************************************************** |
| 2 | + testqgslayoutview.cpp |
| 3 | + -------------------- |
| 4 | + Date : July 2017 |
| 5 | + Copyright : (C) 2017 Nyall Dawson |
| 6 | + Email : nyall dot dawson at gmail dot com |
| 7 | + *************************************************************************** |
| 8 | + * * |
| 9 | + * This program is free software; you can redistribute it and/or modify * |
| 10 | + * it under the terms of the GNU General Public License as published by * |
| 11 | + * the Free Software Foundation; either version 2 of the License, or * |
| 12 | + * (at your option) any later version. * |
| 13 | + * * |
| 14 | + ***************************************************************************/ |
| 15 | + |
| 16 | +#include "qgstest.h" |
| 17 | +#include "qgslayout.h" |
| 18 | +#include "qgslayoutview.h" |
| 19 | +#include "qgslayoutviewtool.h" |
| 20 | +#include <QtTest/QSignalSpy> |
| 21 | + |
| 22 | +class TestQgsLayoutView: public QObject |
| 23 | +{ |
| 24 | + Q_OBJECT |
| 25 | + private slots: |
| 26 | + void initTestCase(); // will be called before the first testfunction is executed. |
| 27 | + void cleanupTestCase(); // will be called after the last testfunction was executed. |
| 28 | + void init(); // will be called before each testfunction is executed. |
| 29 | + void cleanup(); // will be called after every testfunction. |
| 30 | + void basic(); |
| 31 | + void tool(); |
| 32 | + |
| 33 | + private: |
| 34 | + |
| 35 | +}; |
| 36 | + |
| 37 | +void TestQgsLayoutView::initTestCase() |
| 38 | +{ |
| 39 | + |
| 40 | +} |
| 41 | + |
| 42 | +void TestQgsLayoutView::cleanupTestCase() |
| 43 | +{ |
| 44 | +} |
| 45 | + |
| 46 | +void TestQgsLayoutView::init() |
| 47 | +{ |
| 48 | +} |
| 49 | + |
| 50 | +void TestQgsLayoutView::cleanup() |
| 51 | +{ |
| 52 | +} |
| 53 | + |
| 54 | +void TestQgsLayoutView::basic() |
| 55 | +{ |
| 56 | + QgsLayout *layout = new QgsLayout(); |
| 57 | + QgsLayoutView *view = new QgsLayoutView(); |
| 58 | + |
| 59 | + QSignalSpy spyLayoutChanged( view, &QgsLayoutView::layoutSet ); |
| 60 | + view->setCurrentLayout( layout ); |
| 61 | + QCOMPARE( view->currentLayout(), layout ); |
| 62 | + QCOMPARE( spyLayoutChanged.count(), 1 ); |
| 63 | + |
| 64 | + delete view; |
| 65 | + delete layout; |
| 66 | +} |
| 67 | + |
| 68 | +void TestQgsLayoutView::tool() |
| 69 | +{ |
| 70 | + QgsLayoutView *view = new QgsLayoutView(); |
| 71 | + QgsLayoutViewTool *tool = new QgsLayoutViewTool( view, QStringLiteral( "name" ) ); |
| 72 | + QgsLayoutViewTool *tool2 = new QgsLayoutViewTool( view, QStringLiteral( "name2" ) ); |
| 73 | + |
| 74 | + QSignalSpy spySetTool( view, &QgsLayoutView::toolSet ); |
| 75 | + QSignalSpy spyToolActivated( tool, &QgsLayoutViewTool::activated ); |
| 76 | + QSignalSpy spyToolActivated2( tool2, &QgsLayoutViewTool::activated ); |
| 77 | + QSignalSpy spyToolDeactivated( tool, &QgsLayoutViewTool::deactivated ); |
| 78 | + QSignalSpy spyToolDeactivated2( tool2, &QgsLayoutViewTool::deactivated ); |
| 79 | + view->setTool( tool ); |
| 80 | + QCOMPARE( view->tool(), tool ); |
| 81 | + QCOMPARE( spySetTool.count(), 1 ); |
| 82 | + QCOMPARE( spyToolActivated.count(), 1 ); |
| 83 | + QCOMPARE( spyToolDeactivated.count(), 0 ); |
| 84 | + |
| 85 | + view->setTool( tool2 ); |
| 86 | + QCOMPARE( view->tool(), tool2 ); |
| 87 | + QCOMPARE( spySetTool.count(), 2 ); |
| 88 | + QCOMPARE( spyToolActivated.count(), 1 ); |
| 89 | + QCOMPARE( spyToolDeactivated.count(), 1 ); |
| 90 | + QCOMPARE( spyToolActivated2.count(), 1 ); |
| 91 | + QCOMPARE( spyToolDeactivated2.count(), 0 ); |
| 92 | + |
| 93 | + delete tool2; |
| 94 | + QVERIFY( !view->tool() ); |
| 95 | + QCOMPARE( spySetTool.count(), 3 ); |
| 96 | + QCOMPARE( spyToolActivated.count(), 1 ); |
| 97 | + QCOMPARE( spyToolDeactivated.count(), 1 ); |
| 98 | + QCOMPARE( spyToolActivated2.count(), 1 ); |
| 99 | + QCOMPARE( spyToolDeactivated2.count(), 1 ); |
| 100 | + |
| 101 | + delete view; |
| 102 | +} |
| 103 | + |
| 104 | +QGSTEST_MAIN( TestQgsLayoutView ) |
| 105 | +#include "testqgslayoutview.moc" |
0 commit comments