|
| 1 | +/*************************************************************************** |
| 2 | + testqgsmessagebar.cpp |
| 3 | + -------------------------------------- |
| 4 | + Date : October 2018 |
| 5 | + Copyright : (C) 2018 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 | + |
| 17 | +#include "qgstest.h" |
| 18 | + |
| 19 | +#include "qgsmessagebar.h" |
| 20 | +#include "qgsmessagebaritem.h" |
| 21 | +#include <memory> |
| 22 | + |
| 23 | +class TestQgsMessageBar: public QObject |
| 24 | +{ |
| 25 | + Q_OBJECT |
| 26 | + private slots: |
| 27 | + void initTestCase(); // will be called before the first testfunction is executed. |
| 28 | + void cleanupTestCase(); // will be called after the last testfunction was executed. |
| 29 | + void init(); // will be called before each testfunction is executed. |
| 30 | + void cleanup(); // will be called after every testfunction. |
| 31 | + void dismiss(); |
| 32 | + |
| 33 | +}; |
| 34 | + |
| 35 | +void TestQgsMessageBar::initTestCase() |
| 36 | +{ |
| 37 | + |
| 38 | +} |
| 39 | + |
| 40 | +void TestQgsMessageBar::cleanupTestCase() |
| 41 | +{ |
| 42 | +} |
| 43 | + |
| 44 | +void TestQgsMessageBar::init() |
| 45 | +{ |
| 46 | +} |
| 47 | + |
| 48 | +void TestQgsMessageBar::cleanup() |
| 49 | +{ |
| 50 | +} |
| 51 | + |
| 52 | +void TestQgsMessageBar::dismiss() |
| 53 | +{ |
| 54 | + QgsMessageBar bar; |
| 55 | + bar.show(); |
| 56 | + QVERIFY( !bar.currentItem() ); |
| 57 | + |
| 58 | + QgsMessageBarItem *item = new QgsMessageBarItem( QStringLiteral( "test" ) ); |
| 59 | + QPointer< QgsMessageBarItem > pItem( item ); |
| 60 | + item->dismiss(); // should do nothing, not in a bar yet |
| 61 | + QgsApplication::sendPostedEvents( nullptr, QEvent::DeferredDelete ); |
| 62 | + for ( int i = 1; i < 100; ++i ) |
| 63 | + { |
| 64 | + QApplication::processEvents(); |
| 65 | + } |
| 66 | + QCOMPARE( pItem.data(), item ); |
| 67 | + |
| 68 | + |
| 69 | + bar.pushItem( item ); |
| 70 | + QCOMPARE( bar.currentItem(), item ); |
| 71 | + |
| 72 | + item->dismiss(); |
| 73 | + QgsApplication::sendPostedEvents( nullptr, QEvent::DeferredDelete ); |
| 74 | + |
| 75 | + for ( int i = 1; i < 100; ++i ) |
| 76 | + { |
| 77 | + QApplication::processEvents(); |
| 78 | + } |
| 79 | + QVERIFY( !bar.currentItem() ); |
| 80 | + QVERIFY( !pItem.data() ); |
| 81 | +} |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +QGSTEST_MAIN( TestQgsMessageBar ) |
| 86 | +#include "testqgsmessagebar.moc" |
0 commit comments