Skip to content

Commit 72c5978

Browse files
author
timlinux
committed
Regression test for ticket #1141
git-svn-id: http://svn.osgeo.org/qgis/trunk@8762 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 3f75413 commit 72c5978

File tree

2 files changed

+177
-0
lines changed

2 files changed

+177
-0
lines changed

tests/src/core/CMakeLists.txt

+23
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,29 @@ ELSE (APPLE)
125125
INSTALL(TARGETS qgis_filewritertest RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
126126
ADD_TEST(qgis_filewritertest ${CMAKE_INSTALL_PREFIX}/bin/qgis_filewritertest)
127127
ENDIF (APPLE)
128+
129+
130+
#
131+
# Ticket 1141 Regression1141 test
132+
#
133+
SET(regression1141_SRCS regression1141.cpp ${util_SRCS})
134+
SET(regression1141_MOC_CPPS regression1141.cpp)
135+
QT4_WRAP_CPP(regression1141_MOC_SRCS ${regression1141_MOC_CPPS})
136+
ADD_CUSTOM_TARGET(regression1141moc ALL DEPENDS ${regression1141_MOC_SRCS})
137+
ADD_EXECUTABLE(regression1141 ${regression1141_SRCS})
138+
ADD_DEPENDENCIES(regression1141 regression1141moc)
139+
TARGET_LINK_LIBRARIES(regression1141 ${QT_LIBRARIES} qgis_core)
140+
SET_TARGET_PROPERTIES(regression1141
141+
PROPERTIES INSTALL_RPATH ${QGIS_LIB_DIR}
142+
INSTALL_RPATH_USE_LINK_PATH true)
143+
IF (APPLE)
144+
# For Mac OS X, the executable must be at the root of the bundle's executable folder
145+
INSTALL(TARGETS regression1141 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
146+
ADD_TEST(regression1141 ${CMAKE_INSTALL_PREFIX}/regression1141)
147+
ELSE (APPLE)
148+
INSTALL(TARGETS regression1141 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
149+
ADD_TEST(regression1141 ${CMAKE_INSTALL_PREFIX}/bin/regression1141)
150+
ENDIF (APPLE)
128151
#
129152
# QgsRasterLayer test
130153
#

tests/src/core/regression1141.cpp

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/***************************************************************************
2+
testqgsvectorfilewriter.cpp
3+
--------------------------------------
4+
Date : Sun Sep 16 12:22:54 AKDT 2007
5+
Copyright : (C) 2007 by Tim Sutton
6+
Email : tim @ linfiniti.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
#include <QtTest>
16+
#include <QObject>
17+
#include <QString>
18+
#include <QStringList>
19+
#include <QObject>
20+
#include <QPainter>
21+
#include <QSettings>
22+
#include <QTime>
23+
#include <iostream>
24+
25+
#include <QApplication>
26+
#include <QDesktopServices>
27+
28+
//qgis includes...
29+
#include <qgsvectorlayer.h> //defines QgsFieldMap
30+
#include <qgsvectorfilewriter.h> //logic for writing shpfiles
31+
#include <qgsfeature.h> //we will need to pass a bunch of these for each rec
32+
#include <qgsgeometry.h> //each feature needs a geometry
33+
#include <qgspoint.h> //we will use point geometry
34+
#include <qgsspatialrefsys.h> //needed for creating a srs
35+
#include <qgsapplication.h> //search path for srs.db
36+
#include <qgsfield.h>
37+
#include <qgis.h> //defines GEOWKT
38+
#include <qgsproviderregistry.h>
39+
40+
41+
/** \ingroup UnitTests
42+
* This is a unit test for the QgsMapRender class.
43+
* It will do some performance testing too
44+
*
45+
*/
46+
class Regression1141: public QObject
47+
{
48+
Q_OBJECT;
49+
private slots:
50+
void initTestCase();// will be called before the first testfunction is executed.
51+
void cleanupTestCase();// will be called after the last testfunction was executed.
52+
void init(){};// will be called before each testfunction is executed.
53+
void cleanup(){};// will be called after every testfunction.
54+
55+
/** This method tests that we can create a shpfile with diacriticals in its name
56+
* and with fields that have diacriticals in their names*/
57+
void diacriticalTest();
58+
59+
private:
60+
QString mEncoding;
61+
QgsVectorFileWriter::WriterError mError;
62+
QgsSpatialRefSys mSRS;
63+
QgsFieldMap mFields;
64+
QString mFileName;
65+
};
66+
67+
void Regression1141::initTestCase()
68+
{
69+
//
70+
// Runs once before any tests are run
71+
//
72+
// init QGIS's paths - true means that all path will be inited from prefix
73+
QString qgisPath = QCoreApplication::applicationDirPath ();
74+
QgsApplication::setPrefixPath(INSTALL_PREFIX, true);
75+
QgsApplication::showSettings();
76+
// Instantiate the plugin directory so that providers are loaded
77+
QgsProviderRegistry::instance(QgsApplication::pluginPath());
78+
// compute our test file name:
79+
QString myTmpDir = QDir::tempPath() + QDir::separator() ;
80+
mFileName = myTmpDir + "ąęćń.shp";
81+
}
82+
83+
84+
void Regression1141::cleanupTestCase()
85+
{
86+
//
87+
// Runs after all tests are done
88+
//
89+
}
90+
91+
92+
93+
void Regression1141::diacriticalTest()
94+
{
95+
//create some objects that will be used in all tests...
96+
mEncoding = "UTF-8";
97+
QgsField myField( "ąęćń", QVariant::Int, "int", 10, 0, "Value on lon" );
98+
mFields.insert( 0, myField );
99+
mSRS = QgsSpatialRefSys( GEOWKT );
100+
101+
qDebug( "Checking test dataset exists..." );
102+
qDebug( mFileName.toLocal8Bit() );
103+
104+
if ( !QFile::exists( mFileName ) )
105+
{
106+
qDebug( "Creating test dataset: " );
107+
108+
QgsVectorFileWriter myWriter( mFileName,
109+
mEncoding,
110+
mFields,
111+
QGis::WKBPolygon,
112+
&mSRS );
113+
114+
QgsPoint myPoint = QgsPoint( 10.0, 10.0 );
115+
// NOTE: dont delete this pointer again -
116+
// ownership is passed to the feature which will
117+
// delete it in its dtor!
118+
QgsGeometry * mypPointGeometry = QgsGeometry::fromPoint( myPoint );
119+
QgsFeature myFeature;
120+
myFeature.setTypeName( "WKBPoint" );
121+
myFeature.setGeometry( mypPointGeometry );
122+
myFeature.addAttribute( 0, 10 );
123+
//
124+
// Write the feature to the filewriter
125+
// and check for errors
126+
//
127+
QVERIFY( myWriter.addFeature( myFeature ) );
128+
mError = myWriter.hasError();
129+
130+
if ( mError == QgsVectorFileWriter::ErrDriverNotFound )
131+
{
132+
std::cout << "Driver not found error" << std::endl;
133+
}
134+
else if ( mError == QgsVectorFileWriter::ErrCreateDataSource )
135+
{
136+
std::cout << "Create data source error" << std::endl;
137+
}
138+
else if ( mError == QgsVectorFileWriter::ErrCreateLayer )
139+
{
140+
std::cout << "Create layer error" << std::endl;
141+
}
142+
143+
QVERIFY( mError == QgsVectorFileWriter::NoError );
144+
// Now check we can delete it again ok
145+
QVERIFY(QgsVectorFileWriter::deleteShapeFile(mFileName));
146+
147+
} //file exists
148+
}
149+
150+
151+
QTEST_MAIN(Regression1141)
152+
153+
#include "moc_regression1141.cxx"
154+

0 commit comments

Comments
 (0)