Skip to content

Commit b039cd1

Browse files
committedOct 25, 2018
Unit test for QgsMessageBarItem::dismiss
1 parent d679824 commit b039cd1

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
 

‎tests/src/gui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ ADD_QGIS_TEST(fieldexpressionwidget testqgsfieldexpressionwidget.cpp)
127127
ADD_QGIS_TEST(filewidget testqgsfilewidget.cpp)
128128
ADD_QGIS_TEST(focuswatcher testqgsfocuswatcher.cpp)
129129
ADD_QGIS_TEST(mapcanvastest testqgsmapcanvas.cpp)
130+
ADD_QGIS_TEST(messagebartest testqgsmessagebar.cpp)
130131
ADD_QGIS_TEST(projectionissues testprojectionissues.cpp)
131132
ADD_QGIS_TEST(qgsguitest testqgsgui.cpp)
132133
ADD_QGIS_TEST(processingguitest testprocessinggui.cpp)

‎tests/src/gui/testqgsmessagebar.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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

Comments
 (0)
Please sign in to comment.