Skip to content

Commit

Permalink
Unit test for QgsMessageBarItem::dismiss
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 25, 2018
1 parent d679824 commit b039cd1
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/src/gui/CMakeLists.txt
Expand Up @@ -127,6 +127,7 @@ ADD_QGIS_TEST(fieldexpressionwidget testqgsfieldexpressionwidget.cpp)
ADD_QGIS_TEST(filewidget testqgsfilewidget.cpp)
ADD_QGIS_TEST(focuswatcher testqgsfocuswatcher.cpp)
ADD_QGIS_TEST(mapcanvastest testqgsmapcanvas.cpp)
ADD_QGIS_TEST(messagebartest testqgsmessagebar.cpp)
ADD_QGIS_TEST(projectionissues testprojectionissues.cpp)
ADD_QGIS_TEST(qgsguitest testqgsgui.cpp)
ADD_QGIS_TEST(processingguitest testprocessinggui.cpp)
Expand Down
86 changes: 86 additions & 0 deletions tests/src/gui/testqgsmessagebar.cpp
@@ -0,0 +1,86 @@
/***************************************************************************
testqgsmessagebar.cpp
--------------------------------------
Date : October 2018
Copyright : (C) 2018 Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/


#include "qgstest.h"

#include "qgsmessagebar.h"
#include "qgsmessagebaritem.h"
#include <memory>

class TestQgsMessageBar: public QObject
{
Q_OBJECT
private slots:
void initTestCase(); // will be called before the first testfunction is executed.
void cleanupTestCase(); // will be called after the last testfunction was executed.
void init(); // will be called before each testfunction is executed.
void cleanup(); // will be called after every testfunction.
void dismiss();

};

void TestQgsMessageBar::initTestCase()
{

}

void TestQgsMessageBar::cleanupTestCase()
{
}

void TestQgsMessageBar::init()
{
}

void TestQgsMessageBar::cleanup()
{
}

void TestQgsMessageBar::dismiss()
{
QgsMessageBar bar;
bar.show();
QVERIFY( !bar.currentItem() );

QgsMessageBarItem *item = new QgsMessageBarItem( QStringLiteral( "test" ) );
QPointer< QgsMessageBarItem > pItem( item );
item->dismiss(); // should do nothing, not in a bar yet
QgsApplication::sendPostedEvents( nullptr, QEvent::DeferredDelete );
for ( int i = 1; i < 100; ++i )
{
QApplication::processEvents();
}
QCOMPARE( pItem.data(), item );


bar.pushItem( item );
QCOMPARE( bar.currentItem(), item );

item->dismiss();
QgsApplication::sendPostedEvents( nullptr, QEvent::DeferredDelete );

for ( int i = 1; i < 100; ++i )
{
QApplication::processEvents();
}
QVERIFY( !bar.currentItem() );
QVERIFY( !pItem.data() );
}



QGSTEST_MAIN( TestQgsMessageBar )
#include "testqgsmessagebar.moc"

0 comments on commit b039cd1

Please sign in to comment.