Skip to content

Commit a2319f4

Browse files
author
timlinux
committedSep 21, 2007
Tidy up to qgis unit tests:
- install then in same dir as qgis - prefix installed tests with qgis_ Added test to make sure theme exists git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7216 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

2 files changed

+47
-156
lines changed

2 files changed

+47
-156
lines changed
 

‎tests/src/core/CMakeLists.txt

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,38 +55,26 @@ ENDIF (APPLE)
5555
#
5656
# QgsApplication test
5757
#
58-
SET(applicationtest_SRCS testqgsapplication.cpp)
59-
SET(applicationtest_MOC_CPPS testqgsapplication.cpp)
60-
QT4_WRAP_CPP(applicationtest_MOC_SRCS ${applicationtest_MOC_CPPS})
61-
ADD_CUSTOM_TARGET(applicationtestmoc ALL DEPENDS ${applicationtest_MOC_SRCS})
62-
ADD_EXECUTABLE(applicationtest ${applicationtest_SRCS})
63-
ADD_DEPENDENCIES(applicationtest applicationtestmoc)
64-
TARGET_LINK_LIBRARIES(applicationtest ${QT_LIBRARIES} qgis_core)
65-
IF (APPLE)
66-
INSTALL(TARGETS applicationtest RUNTIME DESTINATION ${QGIS_BIN_DIR}/../)
67-
ADD_TEST(application ${QGIS_BIN_DIR}/../applicationtest)
68-
ELSE (APPLE)
69-
INSTALL(TARGETS applicationtest RUNTIME DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
70-
ADD_TEST(application ${CMAKE_CURRENT_BINARY_DIR}/applicationtest)
71-
ENDIF (APPLE)
58+
SET(qgis_applicationtest_SRCS testqgsapplication.cpp)
59+
SET(qgis_applicationtest_MOC_CPPS testqgsapplication.cpp)
60+
QT4_WRAP_CPP(qgis_applicationtest_MOC_SRCS ${qgis_applicationtest_MOC_CPPS})
61+
ADD_CUSTOM_TARGET(qgis_applicationtestmoc ALL DEPENDS ${qgis_applicationtest_MOC_SRCS})
62+
ADD_EXECUTABLE(qgis_applicationtest ${qgis_applicationtest_SRCS})
63+
ADD_DEPENDENCIES(qgis_applicationtest qgis_applicationtestmoc)
64+
TARGET_LINK_LIBRARIES(qgis_applicationtest ${QT_LIBRARIES} qgis_core)
65+
INSTALL(TARGETS qgis_applicationtest RUNTIME DESTINATION ${QGIS_BIN_DIR})
66+
ADD_TEST(qgis_applicationtest ${QGIS_BIN_DIR}/qgis_applicationtest)
7267
#
7368
# QgsFileWriter test
7469
#
75-
SET(filewritertest_SRCS testqgsvectorfilewriter.cpp)
76-
SET(filewritertest_MOC_CPPS testqgsvectorfilewriter.cpp)
77-
QT4_WRAP_CPP(filewritertest_MOC_SRCS ${filewritertest_MOC_CPPS})
78-
ADD_CUSTOM_TARGET(filewritertestmoc ALL DEPENDS ${filewritertest_MOC_SRCS})
79-
ADD_EXECUTABLE(filewritertest ${filewritertest_SRCS})
80-
ADD_DEPENDENCIES(filewritertest filewritertestmoc)
81-
TARGET_LINK_LIBRARIES(filewritertest ${QT_LIBRARIES} qgis_core)
82-
83-
84-
85-
#
86-
# We need to install to a path
87-
#
88-
89-
INSTALL(TARGETS filewritertest RUNTIME DESTINATION ${QGIS_BIN_DIR}/../)
90-
ADD_TEST(filewriter ${QGIS_BIN_DIR}/../filewritertest)
70+
SET(qgis_filewritertest_SRCS testqgsvectorfilewriter.cpp)
71+
SET(qgis_filewritertest_MOC_CPPS testqgsvectorfilewriter.cpp)
72+
QT4_WRAP_CPP(qgis_filewritertest_MOC_SRCS ${qgis_filewritertest_MOC_CPPS})
73+
ADD_CUSTOM_TARGET(qgis_filewritertestmoc ALL DEPENDS ${qgis_filewritertest_MOC_SRCS})
74+
ADD_EXECUTABLE(qgis_filewritertest ${qgis_filewritertest_SRCS})
75+
ADD_DEPENDENCIES(qgis_filewritertest qgis_filewritertestmoc)
76+
TARGET_LINK_LIBRARIES(qgis_filewritertest ${QT_LIBRARIES} qgis_core)
77+
INSTALL(TARGETS qgis_filewritertest RUNTIME DESTINATION ${QGIS_BIN_DIR})
78+
ADD_TEST(qgis_filewritertest ${QGIS_BIN_DIR}/qgis_filewritertest)
9179

9280

‎tests/src/core/testqgsapplication.cpp

Lines changed: 29 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/***************************************************************************
2-
testqgsapplication.cpp
3-
--------------------------------------
4-
Date : Sun Sep 16 12:22:49 AKDT 2007
5-
Copyright : (C) 2007 by Gary E. Sherman
6-
Email : sherman at mrcc dot com
2+
testqgsapplication.cpp
3+
--------------------------------------
4+
Date : Sun Sep 16 12:22:49 AKDT 2007
5+
Copyright : (C) 2007 by Gary E. Sherman
6+
Email : sherman at mrcc dot com
77
***************************************************************************
88
* *
99
* This program is free software; you can redistribute it and/or modify *
@@ -13,21 +13,11 @@
1313
* *
1414
***************************************************************************/
1515
#include <QtTest>
16-
#include <QObject>
17-
#include <QString>
18-
#include <QStringList>
19-
#include <QObject>
2016
#include <iostream>
2117

22-
#include <QApplication>
23-
#include <QImage>
24-
#include <QPainter>
18+
#include <QPixmap>
2519

2620
#include <qgsapplication.h>
27-
#include <qgsmaplayerregistry.h>
28-
#include <qgsmaprender.h>
29-
#include <qgsspatialrefsys.h>
30-
#include <qgsvectorlayer.h>
3121

3222
//header for class being tested
3323
#include <qgsapplication.h>
@@ -36,127 +26,40 @@ class TestQgsApplication: public QObject
3626
{
3727
Q_OBJECT;
3828
private slots:
39-
void QgsApplicationQgsApplication()
40-
{
41-
// init QGIS's paths - true means that all path will be inited from prefix
42-
QString qgisPath = QCoreApplication::applicationDirPath ();
43-
QgsApplication::setPrefixPath(qgisPath, TRUE);
44-
45-
std::cout << "Prefix PATH: " << QgsApplication::prefixPath().toLocal8Bit().data() << std::endl;
46-
std::cout << "Plugin PATH: " << QgsApplication::pluginPath().toLocal8Bit().data() << std::endl;
47-
std::cout << "PkgData PATH: " << QgsApplication::pkgDataPath().toLocal8Bit().data() << std::endl;
48-
std::cout << "User DB PATH: " << QgsApplication::qgisUserDbFilePath().toLocal8Bit().data() << std::endl;
49-
50-
QgsApplication::initQgis();
51-
/* QStringList myLayerList;
52-
myLayerList << "../../../points.shp";
53-
QStringList::Iterator myIterator = myLayerList.begin();
54-
while( myIterator!= myLayerList.end() )
55-
{
56-
QString myLayerName=*myIterator;
57-
QgsVectorLayer* layer = new QgsVectorLayer(myLayerName, myLayerName, "ogr");
58-
if (layer && layer->isValid())
59-
{
60-
std::cout << "Added layer is valid " << std::endl;
61-
}
62-
// something's wrong
63-
else if (layer)
64-
{
65-
//test must be failed here!
66-
delete layer;
67-
}
68-
//Register this layer with the layers registry
69-
QgsMapLayerRegistry::instance()->addMapLayer(layer);
70-
++myIterator;
71-
72-
}
73-
74-
75-
// create image and painter for it
76-
QImage img(QSize(800,600), QImage::Format_ARGB32_Premultiplied);
77-
QColor bgColor(255,255,255);
78-
img.fill(bgColor.rgb());
79-
QPainter p;
80-
p.begin(&img);
81-
p.setRenderHint(QPainter::Antialiasing); // use antialiasing!
82-
83-
QgsMapRender mapRender;
84-
85-
// set layers
86-
mapRender.setLayerSet(myLayerList);
87-
88-
// use projection
89-
mapRender.setProjectionsEnabled(TRUE);
90-
QgsSpatialRefSys srs(32633); // postgis srid: wgs84 / utm zone 33N
91-
mapRender.setDestinationSrs(srs);
92-
93-
// set extent
94-
QgsRect r = mapRender.fullExtent();
95-
r.scale(1.1); // make rectangle a bit bigger
96-
mapRender.setExtent(r);
97-
98-
// set output size
99-
mapRender.setOutputSize(img.size(), img.logicalDpiX());
100-
101-
// render!
102-
mapRender.render(&p);
103-
104-
// painting done
105-
p.end();
106-
107-
// delete layers
108-
QgsMapLayerRegistry::instance()->removeAllMapLayers();
109-
110-
// save image
111-
img.save("render.png","png");*/
112-
QgsApplication::exitQgis();
113-
};
114-
void QgsApplicationselectTheme()
115-
{
116-
117-
};
118-
void QgsApplicationauthorsFilePath()
119-
{
120-
29+
void getPaths();
30+
void checkTheme();
12131
};
122-
void QgsApplicationdeveloperPath()
123-
{
12432

125-
};
126-
void QgsApplicationhelpAppPath()
127-
{
128-
129-
};
130-
void QgsApplicationi18nPath()
33+
void TestQgsApplication::getPaths()
13134
{
35+
// init QGIS's paths - true means that all path will be inited from prefix
36+
QString qgisPath = QCoreApplication::applicationDirPath () + "/../";
37+
QgsApplication::setPrefixPath(qgisPath, TRUE);
13238

133-
};
134-
void QgsApplicationqgisMasterDbFilePath()
135-
{
39+
std::cout << "Prefix PATH: " << QgsApplication::prefixPath().toLocal8Bit().data() << std::endl;
40+
std::cout << "Plugin PATH: " << QgsApplication::pluginPath().toLocal8Bit().data() << std::endl;
41+
std::cout << "PkgData PATH: " << QgsApplication::pkgDataPath().toLocal8Bit().data() << std::endl;
42+
std::cout << "User DB PATH: " << QgsApplication::qgisUserDbFilePath().toLocal8Bit().data() << std::endl;
13643

13744
};
138-
void QgsApplicationqgisSettingsDirPath()
139-
{
14045

141-
};
142-
void QgsApplicationqgisUserDbFilePath()
46+
void TestQgsApplication::checkTheme()
14347
{
48+
QString qgisPath = QCoreApplication::applicationDirPath () + "/../";
49+
QgsApplication::setPrefixPath(qgisPath, TRUE);
50+
std::cout << "Prefix PATH: " << QgsApplication::prefixPath().toLocal8Bit().data() << std::endl;
51+
std::cout << "Plugin PATH: " << QgsApplication::pluginPath().toLocal8Bit().data() << std::endl;
52+
std::cout << "PkgData PATH: " << QgsApplication::pkgDataPath().toLocal8Bit().data() << std::endl;
53+
std::cout << "User DB PATH: " << QgsApplication::qgisUserDbFilePath().toLocal8Bit().data() << std::endl;
54+
QString myIconPath = QgsApplication::themePath();
55+
QPixmap myPixmap;
56+
myPixmap.load(myIconPath+"/mIconProjectionDisabled.png");
57+
qDebug("Checking if a theme icon exists:");
58+
qDebug(myIconPath.toLocal8Bit()+"/mIconProjectionDisabled.png");
59+
QVERIFY(!myPixmap.isNull());
14460

14561
};
146-
void QgsApplicationsplashPath()
147-
{
14862

149-
};
150-
void QgsApplicationsrsDbFilePath()
151-
{
152-
153-
};
154-
void QgsApplicationsvgPath()
155-
{
156-
157-
};
158-
159-
};
16063

16164
QTEST_MAIN(TestQgsApplication)
16265
#include "moc_testqgsapplication.cxx"

0 commit comments

Comments
 (0)
Please sign in to comment.