[QGIS Commit] r8762 - trunk/qgis/tests/src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Jul 12 16:27:14 EDT 2008


Author: timlinux
Date: 2008-07-12 16:27:14 -0400 (Sat, 12 Jul 2008)
New Revision: 8762

Added:
   trunk/qgis/tests/src/core/regression1141.cpp
Modified:
   trunk/qgis/tests/src/core/CMakeLists.txt
Log:
Regression test for ticket #1141

Modified: trunk/qgis/tests/src/core/CMakeLists.txt
===================================================================
--- trunk/qgis/tests/src/core/CMakeLists.txt	2008-07-12 20:24:49 UTC (rev 8761)
+++ trunk/qgis/tests/src/core/CMakeLists.txt	2008-07-12 20:27:14 UTC (rev 8762)
@@ -125,7 +125,30 @@
   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
 #
 SET(qgis_rasterlayertest_SRCS testqgsrasterlayer.cpp ${util_SRCS})

Added: trunk/qgis/tests/src/core/regression1141.cpp
===================================================================
--- trunk/qgis/tests/src/core/regression1141.cpp	                        (rev 0)
+++ trunk/qgis/tests/src/core/regression1141.cpp	2008-07-12 20:27:14 UTC (rev 8762)
@@ -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"
+    
\ No newline at end of file



More information about the QGIS-commit mailing list