Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Regression test for ticket #1141
git-svn-id: http://svn.osgeo.org/qgis/trunk@8762 c8812cc2-4d05-0410-92ff-de0c093fc19c
- Loading branch information
timlinux
committed
Jul 12, 2008
1 parent
3f75413
commit 72c5978
Showing
2 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/*************************************************************************** | ||
testqgsvectorfilewriter.cpp | ||
-------------------------------------- | ||
Date : Sun Sep 16 12:22:54 AKDT 2007 | ||
Copyright : (C) 2007 by Tim Sutton | ||
Email : tim @ linfiniti.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 <QtTest> | ||
#include <QObject> | ||
#include <QString> | ||
#include <QStringList> | ||
#include <QObject> | ||
#include <QPainter> | ||
#include <QSettings> | ||
#include <QTime> | ||
#include <iostream> | ||
|
||
#include <QApplication> | ||
#include <QDesktopServices> | ||
|
||
//qgis includes... | ||
#include <qgsvectorlayer.h> //defines QgsFieldMap | ||
#include <qgsvectorfilewriter.h> //logic for writing shpfiles | ||
#include <qgsfeature.h> //we will need to pass a bunch of these for each rec | ||
#include <qgsgeometry.h> //each feature needs a geometry | ||
#include <qgspoint.h> //we will use point geometry | ||
#include <qgsspatialrefsys.h> //needed for creating a srs | ||
#include <qgsapplication.h> //search path for srs.db | ||
#include <qgsfield.h> | ||
#include <qgis.h> //defines GEOWKT | ||
#include <qgsproviderregistry.h> | ||
|
||
|
||
/** \ingroup UnitTests | ||
* This is a unit test for the QgsMapRender class. | ||
* It will do some performance testing too | ||
* | ||
*/ | ||
class Regression1141: public QObject | ||
{ | ||
Q_OBJECT; | ||
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. | ||
|
||
/** This method tests that we can create a shpfile with diacriticals in its name | ||
* and with fields that have diacriticals in their names*/ | ||
void diacriticalTest(); | ||
|
||
private: | ||
QString mEncoding; | ||
QgsVectorFileWriter::WriterError mError; | ||
QgsSpatialRefSys mSRS; | ||
QgsFieldMap mFields; | ||
QString mFileName; | ||
}; | ||
|
||
void Regression1141::initTestCase() | ||
{ | ||
// | ||
// Runs once before any tests are run | ||
// | ||
// init QGIS's paths - true means that all path will be inited from prefix | ||
QString qgisPath = QCoreApplication::applicationDirPath (); | ||
QgsApplication::setPrefixPath(INSTALL_PREFIX, true); | ||
QgsApplication::showSettings(); | ||
// Instantiate the plugin directory so that providers are loaded | ||
QgsProviderRegistry::instance(QgsApplication::pluginPath()); | ||
// compute our test file name: | ||
QString myTmpDir = QDir::tempPath() + QDir::separator() ; | ||
mFileName = myTmpDir + "ąęćń.shp"; | ||
} | ||
|
||
|
||
void Regression1141::cleanupTestCase() | ||
{ | ||
// | ||
// Runs after all tests are done | ||
// | ||
} | ||
|
||
|
||
|
||
void Regression1141::diacriticalTest() | ||
{ | ||
//create some objects that will be used in all tests... | ||
mEncoding = "UTF-8"; | ||
QgsField myField( "ąęćń", QVariant::Int, "int", 10, 0, "Value on lon" ); | ||
mFields.insert( 0, myField ); | ||
mSRS = QgsSpatialRefSys( GEOWKT ); | ||
|
||
qDebug( "Checking test dataset exists..." ); | ||
qDebug( mFileName.toLocal8Bit() ); | ||
|
||
if ( !QFile::exists( mFileName ) ) | ||
{ | ||
qDebug( "Creating test dataset: " ); | ||
|
||
QgsVectorFileWriter myWriter( mFileName, | ||
mEncoding, | ||
mFields, | ||
QGis::WKBPolygon, | ||
&mSRS ); | ||
|
||
QgsPoint myPoint = QgsPoint( 10.0, 10.0 ); | ||
// NOTE: dont delete this pointer again - | ||
// ownership is passed to the feature which will | ||
// delete it in its dtor! | ||
QgsGeometry * mypPointGeometry = QgsGeometry::fromPoint( myPoint ); | ||
QgsFeature myFeature; | ||
myFeature.setTypeName( "WKBPoint" ); | ||
myFeature.setGeometry( mypPointGeometry ); | ||
myFeature.addAttribute( 0, 10 ); | ||
// | ||
// Write the feature to the filewriter | ||
// and check for errors | ||
// | ||
QVERIFY( myWriter.addFeature( myFeature ) ); | ||
mError = myWriter.hasError(); | ||
|
||
if ( mError == QgsVectorFileWriter::ErrDriverNotFound ) | ||
{ | ||
std::cout << "Driver not found error" << std::endl; | ||
} | ||
else if ( mError == QgsVectorFileWriter::ErrCreateDataSource ) | ||
{ | ||
std::cout << "Create data source error" << std::endl; | ||
} | ||
else if ( mError == QgsVectorFileWriter::ErrCreateLayer ) | ||
{ | ||
std::cout << "Create layer error" << std::endl; | ||
} | ||
|
||
QVERIFY( mError == QgsVectorFileWriter::NoError ); | ||
// Now check we can delete it again ok | ||
QVERIFY(QgsVectorFileWriter::deleteShapeFile(mFileName)); | ||
|
||
} //file exists | ||
} | ||
|
||
|
||
QTEST_MAIN(Regression1141) | ||
|
||
#include "moc_regression1141.cxx" | ||
|