Skip to content
Permalink
Browse files

Add a project properties dialog test case

  • Loading branch information
nirvn committed Nov 21, 2018
1 parent 4e1d684 commit d257cf077649df9b3699000f019ed9c339b94d3e
Showing with 92 additions and 2 deletions.
  1. +4 −2 src/app/qgsprojectproperties.cpp
  2. +1 −0 tests/src/app/CMakeLists.txt
  3. +87 −0 tests/src/app/testqgsprojectproperties.cpp
@@ -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;
@@ -1395,7 +1396,8 @@ void QgsProjectProperties::apply()
{
canvas->refresh();
}
QgisApp::instance()->mapOverviewCanvas()->refresh();
if ( QgisApp::instance()->mapOverviewCanvas() )
QgisApp::instance()->mapOverviewCanvas()->refresh();
}

void QgsProjectProperties::showProjectionsTab()
@@ -112,4 +112,5 @@ ADD_QGIS_TEST(vertextool testqgsvertextool.cpp)
ADD_QGIS_TEST(vectorlayersaveasdialogtest testqgsvectorlayersaveasdialog.cpp)
ADD_QGIS_TEST(maptoolreverselinetest testqgsmaptoolreverseline.cpp)
ADD_QGIS_TEST(maptooltrimextendfeaturetest testqgsmaptooltrimextendfeature.cpp)
ADD_QGIS_TEST(projectproperties 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 d257cf0

Please sign in to comment.
You can’t perform that action at this time.