File indexing completed on 2024-03-24 15:23:25

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2008 Patrick Spendrin <ps_ml@gmx.de>
0004 //
0005 
0006 #include <QtGui>
0007 #include <QTestEvent>
0008 #include "MarbleDirs.h"
0009 #include "MarbleWidget.h"
0010 #include "TestUtils.h"
0011 
0012 #include "qtest_widgets.h"
0013 #include "qtestmouse.h"
0014 
0015 namespace Marble
0016 {
0017 
0018 class MarbleWidgetTest: public QObject
0019 {
0020     Q_OBJECT
0021 
0022 private Q_SLOTS:
0023     void initTestCase();// will be called before the first testfunction is executed.
0024     void cleanupTestCase(){}// will be called after the last testfunction was executed.
0025     void init(){}// will be called before each testfunction is executed.
0026     void cleanup(){}// will be called after every testfunction.
0027 
0028     void mouseMove();
0029 
0030     void setMapTheme_data();
0031     void setMapTheme();
0032 
0033     void switchMapThemes();
0034 
0035     void paintEvent_data();
0036     void paintEvent();
0037 
0038     void runMultipleWidgets();
0039 };
0040 
0041 void MarbleWidgetTest::initTestCase()
0042 {
0043     MarbleDirs::setMarbleDataPath( DATA_PATH );
0044     MarbleDirs::setMarblePluginPath( PLUGIN_PATH );
0045 }
0046 
0047 void MarbleWidgetTest::mouseMove()
0048 {
0049     MarbleWidget widget;
0050     widget.setMapThemeId("earth/srtm/srtm.dgml");
0051 
0052     QTest::mouseMove( &widget );
0053 
0054     QThreadPool::globalInstance()->waitForDone();  // wait for all runners to terminate
0055 }
0056 
0057 void MarbleWidgetTest::setMapTheme_data()
0058 {
0059     QTest::addColumn<QString>( "mapThemeId" );
0060 
0061     addRow() << "earth/plain/plain.dgml";
0062     addRow() << "earth/srtm/srtm.dgml";
0063     addRow() << "earth/openstreetmap/openstreetmap.dgml";
0064 }
0065 
0066 void MarbleWidgetTest::setMapTheme()
0067 {
0068     QFETCH( QString, mapThemeId );
0069 
0070     MarbleWidget widget;
0071 
0072     widget.setMapThemeId( mapThemeId );
0073 
0074     QCOMPARE( widget.mapThemeId(), mapThemeId );
0075 
0076     QThreadPool::globalInstance()->waitForDone();  // wait for all runners to terminate
0077 }
0078 
0079 void MarbleWidgetTest::switchMapThemes()
0080 {
0081     MarbleWidget widget;
0082 
0083     widget.setMapThemeId( "earth/plain/plain.dgml" );
0084     QCOMPARE( widget.mapThemeId(), QString( "earth/plain/plain.dgml" ) );
0085 
0086     widget.setMapThemeId( "earth/srtm/srtm.dgml" );
0087     QCOMPARE( widget.mapThemeId(), QString( "earth/srtm/srtm.dgml" ) );
0088 
0089     widget.setMapThemeId( "earth/openstreetmap/openstreetmap.dgml" );
0090     QCOMPARE( widget.mapThemeId(), QString( "earth/openstreetmap/openstreetmap.dgml" ) );
0091 
0092     widget.setMapThemeId( "earth/plain/plain.dgml" );
0093     QCOMPARE( widget.mapThemeId(), QString( "earth/plain/plain.dgml" ) );
0094 
0095     QThreadPool::globalInstance()->waitForDone();  // wait for all runners to terminate
0096 }
0097 
0098 void MarbleWidgetTest::paintEvent_data()
0099 {
0100     QTest::addColumn<QString>( "mapThemeId" );
0101 
0102     addRow() << "earth/plain/plain.dgml";
0103     addRow() << "earth/srtm/srtm.dgml";
0104     addRow() << "earth/openstreetmap/openstreetmap.dgml";
0105 }
0106 
0107 void MarbleWidgetTest::paintEvent()
0108 {
0109     QFETCH( QString, mapThemeId );
0110 
0111     MarbleWidget widget;
0112 
0113     widget.setMapThemeId( mapThemeId );
0114     widget.resize( 200, 200 );
0115 
0116     QCOMPARE( widget.mapThemeId(), mapThemeId );
0117 
0118     widget.repaint();
0119 
0120     QThreadPool::globalInstance()->waitForDone();  // wait for all runners to terminate
0121 }
0122 
0123 void MarbleWidgetTest::runMultipleWidgets() {
0124     MarbleWidget widget1;
0125     MarbleWidget widget2;
0126 
0127     QCOMPARE(widget1.mapThemeId(), widget2.mapThemeId());
0128     QThreadPool::globalInstance()->waitForDone();
0129 }
0130 
0131 }
0132 
0133 QTEST_MAIN( Marble::MarbleWidgetTest )
0134 
0135 #include "MarbleWidgetTest.moc"