Skip to content

Commit

Permalink
Regression test for ticket #1141
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8762 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Jul 12, 2008
1 parent e6d6bbd commit 3b86e82
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/src/core/CMakeLists.txt
Expand Up @@ -125,6 +125,29 @@ ELSE (APPLE)
INSTALL(TARGETS qgis_filewritertest RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
ADD_TEST(qgis_filewritertest ${CMAKE_INSTALL_PREFIX}/bin/qgis_filewritertest)
ENDIF (APPLE)


#
# Ticket 1141 Regression1141 test
#
SET(regression1141_SRCS regression1141.cpp ${util_SRCS})
SET(regression1141_MOC_CPPS regression1141.cpp)
QT4_WRAP_CPP(regression1141_MOC_SRCS ${regression1141_MOC_CPPS})
ADD_CUSTOM_TARGET(regression1141moc ALL DEPENDS ${regression1141_MOC_SRCS})
ADD_EXECUTABLE(regression1141 ${regression1141_SRCS})
ADD_DEPENDENCIES(regression1141 regression1141moc)
TARGET_LINK_LIBRARIES(regression1141 ${QT_LIBRARIES} qgis_core)
SET_TARGET_PROPERTIES(regression1141
PROPERTIES INSTALL_RPATH ${QGIS_LIB_DIR}
INSTALL_RPATH_USE_LINK_PATH true)
IF (APPLE)
# For Mac OS X, the executable must be at the root of the bundle's executable folder
INSTALL(TARGETS regression1141 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
ADD_TEST(regression1141 ${CMAKE_INSTALL_PREFIX}/regression1141)
ELSE (APPLE)
INSTALL(TARGETS regression1141 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
ADD_TEST(regression1141 ${CMAKE_INSTALL_PREFIX}/bin/regression1141)
ENDIF (APPLE)
#
# QgsRasterLayer test
#
Expand Down
154 changes: 154 additions & 0 deletions tests/src/core/regression1141.cpp
@@ -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"

0 comments on commit 3b86e82

Please sign in to comment.