mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
Merge indidividual regression1141.cpp and regression1141.cpp checks
into testqgsrasterlayer and testqgsvectorfilewriter (slightly speeds up compiling and running tests)
This commit is contained in:
parent
eb31e01a2f
commit
a89b51076c
@ -165,8 +165,6 @@ ADD_QGIS_TEST(rasterfilltest testqgsrasterfill.cpp )
|
|||||||
ADD_QGIS_TEST(rasterlayertest testqgsrasterlayer.cpp)
|
ADD_QGIS_TEST(rasterlayertest testqgsrasterlayer.cpp)
|
||||||
ADD_QGIS_TEST(rastersublayertest testqgsrastersublayer.cpp)
|
ADD_QGIS_TEST(rastersublayertest testqgsrastersublayer.cpp)
|
||||||
ADD_QGIS_TEST(rectangletest testqgsrectangle.cpp)
|
ADD_QGIS_TEST(rectangletest testqgsrectangle.cpp)
|
||||||
ADD_QGIS_TEST(regression1141 regression1141.cpp)
|
|
||||||
ADD_QGIS_TEST(regression992 regression992.cpp)
|
|
||||||
ADD_QGIS_TEST(rendererstest testqgsrenderers.cpp)
|
ADD_QGIS_TEST(rendererstest testqgsrenderers.cpp)
|
||||||
ADD_QGIS_TEST(rulebasedrenderertest testqgsrulebasedrenderer.cpp)
|
ADD_QGIS_TEST(rulebasedrenderertest testqgsrulebasedrenderer.cpp)
|
||||||
ADD_QGIS_TEST(scaleexpressiontest testqgsscaleexpression.cpp)
|
ADD_QGIS_TEST(scaleexpressiontest testqgsscaleexpression.cpp)
|
||||||
|
@ -1,176 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
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/QtTest>
|
|
||||||
#include <QObject>
|
|
||||||
#include <QString>
|
|
||||||
#include <QStringList>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QTime>
|
|
||||||
|
|
||||||
#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 <qgscoordinatereferencesystem.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>
|
|
||||||
#include <qgslogger.h>
|
|
||||||
|
|
||||||
#if defined(linux)
|
|
||||||
#include <langinfo.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/** \ingroup UnitTests
|
|
||||||
* This is a regression test ticket 1141.
|
|
||||||
* broken Polish characters support since r8592
|
|
||||||
* http://hub.qgis.org/issues/1141
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class Regression1141: public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
Regression1141();
|
|
||||||
|
|
||||||
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;
|
|
||||||
QgsCoordinateReferenceSystem mCRS;
|
|
||||||
QgsFields mFields;
|
|
||||||
QString mFileName;
|
|
||||||
};
|
|
||||||
|
|
||||||
Regression1141::Regression1141()
|
|
||||||
: mError( QgsVectorFileWriter::NoError )
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Regression1141::initTestCase()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Runs once before any tests are run
|
|
||||||
//
|
|
||||||
// init QGIS's paths - true means that all path will be inited from prefix
|
|
||||||
QgsApplication::init();
|
|
||||||
QgsApplication::initQgis();
|
|
||||||
QgsApplication::showSettings();
|
|
||||||
// compute our test file name:
|
|
||||||
QString myTmpDir = QDir::tempPath() + '/';
|
|
||||||
mFileName = myTmpDir + "ąęćń.shp";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Regression1141::cleanupTestCase()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Runs after all tests are done
|
|
||||||
//
|
|
||||||
QgsApplication::exitQgis();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Regression1141::diacriticalTest()
|
|
||||||
{
|
|
||||||
#if defined(linux)
|
|
||||||
const char *cs = nl_langinfo( CODESET );
|
|
||||||
QgsDebugMsg( QString( "CODESET:%1" ).arg( cs ? cs : "unset" ) );
|
|
||||||
if ( !cs || strcmp( cs, "UTF-8" ) != 0 )
|
|
||||||
{
|
|
||||||
QSKIP( "This test requires a UTF-8 locale", SkipSingle );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//create some objects that will be used in all tests...
|
|
||||||
mEncoding = "UTF-8";
|
|
||||||
QgsField myField( "ąęćń", QVariant::Int, "int", 10, 0, "Value on lon" );
|
|
||||||
mFields.append( myField );
|
|
||||||
mCRS = QgsCoordinateReferenceSystem( GEOWKT );
|
|
||||||
|
|
||||||
qDebug( "Checking test dataset exists...\n%s", mFileName.toLocal8Bit().constData() );
|
|
||||||
|
|
||||||
if ( !QFile::exists( mFileName ) )
|
|
||||||
{
|
|
||||||
qDebug( "Creating test dataset: " );
|
|
||||||
|
|
||||||
{
|
|
||||||
QgsVectorFileWriter myWriter( mFileName,
|
|
||||||
mEncoding,
|
|
||||||
mFields,
|
|
||||||
QGis::WKBPoint,
|
|
||||||
&mCRS );
|
|
||||||
|
|
||||||
QgsPoint myPoint = QgsPoint( 10.0, 10.0 );
|
|
||||||
// NOTE: don't 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.setGeometry( mypPointGeometry );
|
|
||||||
myFeature.initAttributes( 1 );
|
|
||||||
myFeature.setAttribute( 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 "regression1141.moc"
|
|
@ -1,134 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
testqgsvectorfilewriter.cpp
|
|
||||||
--------------------------------------
|
|
||||||
Date : Frida Nov 23 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/QtTest>
|
|
||||||
#include <QObject>
|
|
||||||
#include <QString>
|
|
||||||
#include <QStringList>
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QTime>
|
|
||||||
#include <QDesktopServices>
|
|
||||||
|
|
||||||
//qgis includes...
|
|
||||||
#include <qgsrasterlayer.h>
|
|
||||||
#include <qgsrasterbandstats.h>
|
|
||||||
#include <qgsmaplayerregistry.h>
|
|
||||||
#include <qgsapplication.h>
|
|
||||||
#include <qgsproviderregistry.h>
|
|
||||||
#include <qgsmapsettings.h>
|
|
||||||
|
|
||||||
//qgis unit test includes
|
|
||||||
#include <qgsrenderchecker.h>
|
|
||||||
|
|
||||||
|
|
||||||
/** \ingroup UnitTests
|
|
||||||
* This is a regression test for ticket #992.
|
|
||||||
*/
|
|
||||||
class Regression992 : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
Regression992();
|
|
||||||
|
|
||||||
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 regression992();
|
|
||||||
private:
|
|
||||||
bool render( QString theFileName );
|
|
||||||
QString mTestDataDir;
|
|
||||||
QgsRasterLayer *mpRasterLayer;
|
|
||||||
QString mReport;
|
|
||||||
};
|
|
||||||
|
|
||||||
Regression992::Regression992()
|
|
||||||
: mpRasterLayer( nullptr )
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//runs before all tests
|
|
||||||
void Regression992::initTestCase()
|
|
||||||
{
|
|
||||||
// init QGIS's paths - true means that all path will be inited from prefix
|
|
||||||
QgsApplication::init();
|
|
||||||
QgsApplication::initQgis();
|
|
||||||
QgsApplication::showSettings();
|
|
||||||
// QgsApplication::skipGdalDriver( "JP2ECW" );
|
|
||||||
// QgsApplication::skipGdalDriver( "JP2MrSID" );
|
|
||||||
|
|
||||||
//create some objects that will be used in all tests...
|
|
||||||
//create a raster layer that will be used in all tests...
|
|
||||||
mTestDataDir = QString( TEST_DATA_DIR ) + '/'; //defined in CMakeLists.txt
|
|
||||||
QString myFileName = mTestDataDir + "rgbwcmyk01_YeGeo.jp2";
|
|
||||||
QFileInfo myRasterFileInfo( myFileName );
|
|
||||||
mpRasterLayer = new QgsRasterLayer( myRasterFileInfo.filePath(),
|
|
||||||
myRasterFileInfo.completeBaseName() );
|
|
||||||
if ( ! mpRasterLayer->isValid() )
|
|
||||||
{
|
|
||||||
QSKIP( "This test requires the JPEG2000 GDAL driver", SkipAll );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug() << mpRasterLayer->dataProvider()->metadata();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register the layer with the registry
|
|
||||||
QList<QgsMapLayer *> myList;
|
|
||||||
myList << mpRasterLayer;
|
|
||||||
QgsMapLayerRegistry::instance()->addMapLayers( myList );
|
|
||||||
// add the test layer to the maprender
|
|
||||||
mReport += "<h1>Regression 992 Test</h1>\n";
|
|
||||||
mReport += "<p>See <a href=\"http://hub.qgis.org/issues/992\">"
|
|
||||||
"redmine ticket 992</a> for more details.</p>";
|
|
||||||
}
|
|
||||||
//runs after all tests
|
|
||||||
void Regression992::cleanupTestCase()
|
|
||||||
{
|
|
||||||
QString myReportFile = QDir::tempPath() + "/qgistest.html";
|
|
||||||
QFile myFile( myReportFile );
|
|
||||||
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
|
|
||||||
{
|
|
||||||
QTextStream myQTextStream( &myFile );
|
|
||||||
myQTextStream << mReport;
|
|
||||||
myFile.close();
|
|
||||||
//QDesktopServices::openUrl( "file:///" + myReportFile );
|
|
||||||
}
|
|
||||||
|
|
||||||
QgsApplication::exitQgis();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Regression992::regression992()
|
|
||||||
{
|
|
||||||
QgsMapSettings settings;
|
|
||||||
settings.setExtent( mpRasterLayer->extent() );
|
|
||||||
settings.setLayers( QStringList() << mpRasterLayer->id() );
|
|
||||||
QgsRenderChecker myChecker;
|
|
||||||
myChecker.setMapSettings( settings );
|
|
||||||
myChecker.setControlName( "expected_rgbwcmyk01_YeGeo.jp2" );
|
|
||||||
// allow up to 300 mismatched pixels
|
|
||||||
bool myResultFlag = myChecker.runTest( "regression992", 400 );
|
|
||||||
mReport += "\n\n\n" + myChecker.report();
|
|
||||||
QVERIFY( myResultFlag );
|
|
||||||
}
|
|
||||||
|
|
||||||
QTEST_MAIN( Regression992 )
|
|
||||||
#include "regression992.moc"
|
|
@ -54,6 +54,7 @@ class TestQgsRasterLayer : public QObject
|
|||||||
, mpLandsatRasterLayer( nullptr )
|
, mpLandsatRasterLayer( nullptr )
|
||||||
, mpFloat32RasterLayer( nullptr )
|
, mpFloat32RasterLayer( nullptr )
|
||||||
, mPngRasterLayer( nullptr )
|
, mPngRasterLayer( nullptr )
|
||||||
|
, mGeoJp2RasterLayer( nullptr )
|
||||||
, mMapSettings( nullptr )
|
, mMapSettings( nullptr )
|
||||||
{}
|
{}
|
||||||
~TestQgsRasterLayer()
|
~TestQgsRasterLayer()
|
||||||
@ -83,8 +84,11 @@ class TestQgsRasterLayer : public QObject
|
|||||||
void transparency();
|
void transparency();
|
||||||
void multiBandColorRenderer();
|
void multiBandColorRenderer();
|
||||||
void setRenderer();
|
void setRenderer();
|
||||||
|
void regression992(); //test for issue #992 - GeoJP2 images improperly displayed as all black
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool render( const QString& theFileName );
|
bool render( const QString& theFileName, int mismatchCount = 0 );
|
||||||
bool setQml( const QString& theType, QString& msg );
|
bool setQml( const QString& theType, QString& msg );
|
||||||
void populateColorRampShader( QgsColorRampShader* colorRampShader,
|
void populateColorRampShader( QgsColorRampShader* colorRampShader,
|
||||||
QgsVectorColorRampV2* colorRamp,
|
QgsVectorColorRampV2* colorRamp,
|
||||||
@ -96,6 +100,8 @@ class TestQgsRasterLayer : public QObject
|
|||||||
QgsRasterLayer * mpLandsatRasterLayer;
|
QgsRasterLayer * mpLandsatRasterLayer;
|
||||||
QgsRasterLayer * mpFloat32RasterLayer;
|
QgsRasterLayer * mpFloat32RasterLayer;
|
||||||
QgsRasterLayer * mPngRasterLayer;
|
QgsRasterLayer * mPngRasterLayer;
|
||||||
|
QgsRasterLayer * mGeoJp2RasterLayer;
|
||||||
|
|
||||||
QgsMapSettings * mMapSettings;
|
QgsMapSettings * mMapSettings;
|
||||||
QString mReport;
|
QString mReport;
|
||||||
};
|
};
|
||||||
@ -137,6 +143,7 @@ void TestQgsRasterLayer::initTestCase()
|
|||||||
QString myLandsatFileName = mTestDataDir + "landsat.tif";
|
QString myLandsatFileName = mTestDataDir + "landsat.tif";
|
||||||
QString myFloat32FileName = mTestDataDir + "/raster/band1_float32_noct_epsg4326.tif";
|
QString myFloat32FileName = mTestDataDir + "/raster/band1_float32_noct_epsg4326.tif";
|
||||||
QString pngRasterFileName = mTestDataDir + "rgb256x256.png";
|
QString pngRasterFileName = mTestDataDir + "rgb256x256.png";
|
||||||
|
QString geoJp2RasterFileName = mTestDataDir + "rgbwcmyk01_YeGeo.jp2";
|
||||||
|
|
||||||
QFileInfo myRasterFileInfo( myFileName );
|
QFileInfo myRasterFileInfo( myFileName );
|
||||||
mpRasterLayer = new QgsRasterLayer( myRasterFileInfo.filePath(),
|
mpRasterLayer = new QgsRasterLayer( myRasterFileInfo.filePath(),
|
||||||
@ -157,12 +164,17 @@ void TestQgsRasterLayer::initTestCase()
|
|||||||
mPngRasterLayer = new QgsRasterLayer( pngRasterFileInfo.filePath(),
|
mPngRasterLayer = new QgsRasterLayer( pngRasterFileInfo.filePath(),
|
||||||
pngRasterFileInfo.completeBaseName() );
|
pngRasterFileInfo.completeBaseName() );
|
||||||
|
|
||||||
|
QFileInfo geoJp2RasterFileInfo( geoJp2RasterFileName );
|
||||||
|
mGeoJp2RasterLayer = new QgsRasterLayer( geoJp2RasterFileInfo.filePath(),
|
||||||
|
geoJp2RasterFileInfo.completeBaseName() );
|
||||||
|
|
||||||
// Register the layer with the registry
|
// Register the layer with the registry
|
||||||
QgsMapLayerRegistry::instance()->addMapLayers(
|
QgsMapLayerRegistry::instance()->addMapLayers(
|
||||||
QList<QgsMapLayer *>() << mpRasterLayer
|
QList<QgsMapLayer *>() << mpRasterLayer
|
||||||
<< mpLandsatRasterLayer
|
<< mpLandsatRasterLayer
|
||||||
<< mpFloat32RasterLayer
|
<< mpFloat32RasterLayer
|
||||||
<< mPngRasterLayer );
|
<< mPngRasterLayer
|
||||||
|
<< mGeoJp2RasterLayer );
|
||||||
|
|
||||||
// add the test layer to the maprender
|
// add the test layer to the maprender
|
||||||
mMapSettings->setLayers( QStringList() << mpRasterLayer->id() );
|
mMapSettings->setLayers( QStringList() << mpRasterLayer->id() );
|
||||||
@ -537,13 +549,13 @@ void TestQgsRasterLayer::registry()
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
bool TestQgsRasterLayer::render( const QString& theTestType )
|
bool TestQgsRasterLayer::render( const QString& theTestType, int mismatchCount )
|
||||||
{
|
{
|
||||||
mReport += "<h2>" + theTestType + "</h2>\n";
|
mReport += "<h2>" + theTestType + "</h2>\n";
|
||||||
QgsRenderChecker myChecker;
|
QgsRenderChecker myChecker;
|
||||||
myChecker.setControlName( "expected_" + theTestType );
|
myChecker.setControlName( "expected_" + theTestType );
|
||||||
myChecker.setMapSettings( *mMapSettings );
|
myChecker.setMapSettings( *mMapSettings );
|
||||||
bool myResultFlag = myChecker.runTest( theTestType );
|
bool myResultFlag = myChecker.runTest( theTestType, mismatchCount );
|
||||||
mReport += "\n\n\n" + myChecker.report();
|
mReport += "\n\n\n" + myChecker.report();
|
||||||
return myResultFlag;
|
return myResultFlag;
|
||||||
}
|
}
|
||||||
@ -626,5 +638,17 @@ void TestQgsRasterLayer::setRenderer()
|
|||||||
QCOMPARE( mpRasterLayer->renderer(), renderer );
|
QCOMPARE( mpRasterLayer->renderer(), renderer );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestQgsRasterLayer::regression992()
|
||||||
|
{
|
||||||
|
if ( ! mGeoJp2RasterLayer->isValid() )
|
||||||
|
{
|
||||||
|
QSKIP( "This test requires the JPEG2000 GDAL driver", SkipAll );
|
||||||
|
}
|
||||||
|
|
||||||
|
mMapSettings->setExtent( mGeoJp2RasterLayer->extent() );
|
||||||
|
mMapSettings->setLayers( QStringList() << mGeoJp2RasterLayer->id() );
|
||||||
|
QVERIFY( render( "raster_geojp2", 400 ) );
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN( TestQgsRasterLayer )
|
QTEST_MAIN( TestQgsRasterLayer )
|
||||||
#include "testqgsrasterlayer.moc"
|
#include "testqgsrasterlayer.moc"
|
||||||
|
@ -60,6 +60,7 @@ class TestQgsVectorFileWriter: public QObject
|
|||||||
void initTestCase();// will be called before the first testfunction is executed.
|
void initTestCase();// will be called before the first testfunction is executed.
|
||||||
void init() {} // will be called before each testfunction is executed.
|
void init() {} // will be called before each testfunction is executed.
|
||||||
void cleanup() {} // will be called after every testfunction.
|
void cleanup() {} // will be called after every testfunction.
|
||||||
|
void cleanupTestCase();// will be called after the last testfunction was executed.
|
||||||
|
|
||||||
/** This method tests writing a point to a shapefile */
|
/** This method tests writing a point to a shapefile */
|
||||||
void createPoint();
|
void createPoint();
|
||||||
@ -71,6 +72,8 @@ class TestQgsVectorFileWriter: public QObject
|
|||||||
void polygonGridTest();
|
void polygonGridTest();
|
||||||
/** As above but using a projected CRS*/
|
/** As above but using a projected CRS*/
|
||||||
void projectedPlygonGridTest();
|
void projectedPlygonGridTest();
|
||||||
|
/** This is a regression test ticket 1141 (broken Polish characters support since r8592) http://hub.qgis.org/issues/1141 */
|
||||||
|
void regression1141();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// a little util fn used by all tests
|
// a little util fn used by all tests
|
||||||
@ -112,6 +115,12 @@ void TestQgsVectorFileWriter::initTestCase()
|
|||||||
mPoint3 = QgsPoint( 15.0, 12.0 );
|
mPoint3 = QgsPoint( 15.0, 12.0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestQgsVectorFileWriter::cleanupTestCase()
|
||||||
|
{
|
||||||
|
// Runs after all tests are done
|
||||||
|
QgsApplication::exitQgis();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestQgsVectorFileWriter::createPoint()
|
void TestQgsVectorFileWriter::createPoint()
|
||||||
{
|
{
|
||||||
@ -396,5 +405,74 @@ void TestQgsVectorFileWriter::projectedPlygonGridTest()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestQgsVectorFileWriter::regression1141()
|
||||||
|
{
|
||||||
|
#if defined(linux)
|
||||||
|
const char *cs = nl_langinfo( CODESET );
|
||||||
|
QgsDebugMsg( QString( "CODESET:%1" ).arg( cs ? cs : "unset" ) );
|
||||||
|
if ( !cs || strcmp( cs, "UTF-8" ) != 0 )
|
||||||
|
{
|
||||||
|
QSKIP( "This test requires a UTF-8 locale", SkipSingle );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//create some objects that will be used in all tests...
|
||||||
|
QString encoding = "UTF-8";
|
||||||
|
QgsField myField( "ąęćń", QVariant::Int, "int", 10, 0, "Value on lon" );
|
||||||
|
QgsFields fields;
|
||||||
|
fields.append( myField );
|
||||||
|
QgsCoordinateReferenceSystem crs;
|
||||||
|
crs = QgsCoordinateReferenceSystem( GEOWKT );
|
||||||
|
QString tmpDir = QDir::tempPath() + '/';
|
||||||
|
QString fileName = tmpDir + "ąęćń.shp";
|
||||||
|
|
||||||
|
QVERIFY2( !QFile::exists( fileName ), QString( "File %1 already exists, cannot run test" ).arg( fileName ).toLocal8Bit().constData() );
|
||||||
|
|
||||||
|
qDebug( "Creating test dataset: " );
|
||||||
|
|
||||||
|
{
|
||||||
|
QgsVectorFileWriter myWriter( fileName,
|
||||||
|
encoding,
|
||||||
|
fields,
|
||||||
|
QGis::WKBPoint,
|
||||||
|
&crs );
|
||||||
|
|
||||||
|
QgsPoint myPoint = QgsPoint( 10.0, 10.0 );
|
||||||
|
// NOTE: don't 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.setGeometry( mypPointGeometry );
|
||||||
|
myFeature.initAttributes( 1 );
|
||||||
|
myFeature.setAttribute( 0, 10 );
|
||||||
|
//
|
||||||
|
// Write the feature to the filewriter
|
||||||
|
// and check for errors
|
||||||
|
//
|
||||||
|
QVERIFY( myWriter.addFeature( myFeature ) );
|
||||||
|
QgsVectorFileWriter::WriterError error = myWriter.hasError();
|
||||||
|
|
||||||
|
if ( error == QgsVectorFileWriter::ErrDriverNotFound )
|
||||||
|
{
|
||||||
|
std::cout << "Driver not found error" << std::endl;
|
||||||
|
}
|
||||||
|
else if ( error == QgsVectorFileWriter::ErrCreateDataSource )
|
||||||
|
{
|
||||||
|
std::cout << "Create data source error" << std::endl;
|
||||||
|
}
|
||||||
|
else if ( error == QgsVectorFileWriter::ErrCreateLayer )
|
||||||
|
{
|
||||||
|
std::cout << "Create layer error" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVERIFY( error == QgsVectorFileWriter::NoError );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now check we can delete it again ok
|
||||||
|
QVERIFY( QgsVectorFileWriter::deleteShapeFile( fileName ) );
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN( TestQgsVectorFileWriter )
|
QTEST_MAIN( TestQgsVectorFileWriter )
|
||||||
#include "testqgsvectorfilewriter.moc"
|
#include "testqgsvectorfilewriter.moc"
|
||||||
|
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 118 KiB |
Before Width: | Height: | Size: 644 B After Width: | Height: | Size: 644 B |
Binary file not shown.
Before Width: | Height: | Size: 625 B |
Loading…
x
Reference in New Issue
Block a user