/
testqgsprojectproperties.cpp
153 lines (128 loc) · 5.7 KB
/
testqgsprojectproperties.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/***************************************************************************
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();
void testEllipsoidChange();
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 );
}
void TestQgsProjectProperties::testEllipsoidChange()
{
QgsProject::instance()->clear();
QgsProject::instance()->setCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ) );
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "NONE" ) );
std::unique_ptr< QgsProjectProperties > pp = qgis::make_unique< QgsProjectProperties >( mQgisApp->mapCanvas() );
pp->apply();
pp.reset();
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "NONE" ) );
#if PROJ_VERSION_MAJOR>=6
QgsProject::instance()->setEllipsoid( QStringLiteral( "ESRI:107900" ) );
pp = qgis::make_unique< QgsProjectProperties >( mQgisApp->mapCanvas() );
pp->apply();
pp.reset();
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "ESRI:107900" ) );
QgsProject::instance()->setEllipsoid( QStringLiteral( "EPSG:7002" ) );
pp = qgis::make_unique< QgsProjectProperties >( mQgisApp->mapCanvas() );
pp->apply();
pp.reset();
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "EPSG:7002" ) );
QgsProject::instance()->setEllipsoid( QStringLiteral( "EPSG:7005" ) );
pp = qgis::make_unique< QgsProjectProperties >( mQgisApp->mapCanvas() );
pp->apply();
pp.reset();
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "EPSG:7005" ) );
#else
QgsProject::instance()->setEllipsoid( QStringLiteral( "bessel" ) );
pp = qgis::make_unique< QgsProjectProperties >( mQgisApp->mapCanvas() );
pp->apply();
pp.reset();
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "bessel" ) );
QgsProject::instance()->setEllipsoid( QStringLiteral( "IGNF:ELG052" ) );
pp = qgis::make_unique< QgsProjectProperties >( mQgisApp->mapCanvas() );
pp->apply();
pp.reset();
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "IGNF:ELG052" ) );
QgsProject::instance()->setEllipsoid( QStringLiteral( "IGNF:ELG037" ) );
pp = qgis::make_unique< QgsProjectProperties >( mQgisApp->mapCanvas() );
pp->apply();
pp.reset();
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "IGNF:ELG037" ) );
#endif
QgsProject::instance()->setEllipsoid( QStringLiteral( "NONE" ) );
pp = qgis::make_unique< QgsProjectProperties >( mQgisApp->mapCanvas() );
pp->apply();
pp.reset();
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "NONE" ) );
QgsProject::instance()->setEllipsoid( QStringLiteral( "PARAMETER:55:66" ) );
pp = qgis::make_unique< QgsProjectProperties >( mQgisApp->mapCanvas() );
pp->apply();
pp.reset();
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "PARAMETER:55:66" ) );
}
QGSTEST_MAIN( TestQgsProjectProperties )
#include "testqgsprojectproperties.moc"