Skip to content

Commit

Permalink
Add a project properties dialog test case
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Nov 23, 2018
1 parent f209105 commit 8f1c51b
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -1010,7 +1010,8 @@ void QgsProjectProperties::apply()
canvas->setSelectionColor( selectionColor );
canvas->enableMapTileRendering( mMapTileRenderingCheckBox->isChecked() );
}
QgisApp::instance()->mapOverviewCanvas()->setBackgroundColor( canvasColor );
if ( QgisApp::instance()->mapOverviewCanvas() )
QgisApp::instance()->mapOverviewCanvas()->setBackgroundColor( canvasColor );

//save project scales
QStringList myScales;
Expand Down Expand Up @@ -1395,7 +1396,8 @@ void QgsProjectProperties::apply()
{
canvas->refresh();
}
QgisApp::instance()->mapOverviewCanvas()->refresh();
if ( QgisApp::instance()->mapOverviewCanvas() )
QgisApp::instance()->mapOverviewCanvas()->refresh();
}

void QgsProjectProperties::showProjectionsTab()
Expand Down
2 changes: 1 addition & 1 deletion tests/src/app/CMakeLists.txt
Expand Up @@ -110,4 +110,4 @@ ADD_QGIS_TEST(measuretool testqgsmeasuretool.cpp)
ADD_QGIS_TEST(vertextool testqgsvertextool.cpp)
ADD_QGIS_TEST(vectorlayersaveasdialogtest testqgsvectorlayersaveasdialog.cpp)
ADD_QGIS_TEST(maptoolreverselinetest testqgsmaptoolreverseline.cpp)

ADD_QGIS_TEST(projectproperties testqgsprojectproperties.cpp)
87 changes: 87 additions & 0 deletions tests/src/app/testqgsprojectproperties.cpp
@@ -0,0 +1,87 @@
/***************************************************************************
testqgsprojectproperties.cpp
-------------------------
Date : 2018-11-21
Copyright : (C) 2018 by Mathieu Pellerin
Email : nirvn dot asia 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 "qgisapp.h"
#include "qgsapplication.h"
#include "qgsvectorlayer.h"
#include "qgsprojectproperties.h"
#include "qgsproject.h"
#include "qgsmapcanvas.h"

/**
* \ingroup UnitTests
* This is a unit test for the project properties dialog
*/
class TestQgsProjectProperties : public QObject
{
Q_OBJECT
public:
TestQgsProjectProperties();

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 testProjectPropertiesDirty();

private:
QgisApp *mQgisApp = nullptr;
};

TestQgsProjectProperties::TestQgsProjectProperties() = default;

//runs before all tests
void TestQgsProjectProperties::initTestCase()
{
qDebug() << "TestQgsProjectProperties::initTestCase()";
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
QgsApplication::initQgis();
mQgisApp = new QgisApp();
}

//runs after all tests
void TestQgsProjectProperties::cleanupTestCase()
{
QgsApplication::exitQgis();
}

void TestQgsProjectProperties::testProjectPropertiesDirty()
{
// create a temporary layer
std::unique_ptr< QgsVectorLayer> tempLayer( new QgsVectorLayer( QStringLiteral( "none?field=code:int&field=regular:string" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) ) );
QVERIFY( tempLayer->isValid() );

// add layer to project, to insure presence of layer-related project settings
QgsProject::instance()->addMapLayer( tempLayer.get() );

// opening the project properties for the first time in a new project does write new entries
// call apply twice here to test that subsequent opening will not dirty project
QgsProjectProperties *pp = new QgsProjectProperties( mQgisApp->mapCanvas() );
pp->apply();
delete pp;
QgsProject::instance()->setDirty( false );
pp = new QgsProjectProperties( mQgisApp->mapCanvas() );
pp->apply();
delete pp;
QCOMPARE( QgsProject::instance()->isDirty(), false );
}

QGSTEST_MAIN( TestQgsProjectProperties )

#include "testqgsprojectproperties.moc"

0 comments on commit 8f1c51b

Please sign in to comment.