From 4cfc365477f6e0cd614ddf3aec1217a8522dd6ee Mon Sep 17 00:00:00 2001 From: "Juergen E. Fischer" Date: Sun, 26 Aug 2012 18:05:35 +0200 Subject: [PATCH] make tests runable without install --- CMakeLists.txt | 2 +- src/core/qgsapplication.cpp | 43 +++++++++++++----------------- src/core/qgsexpression.cpp | 3 ++- src/plugins/globe/globe_plugin.cpp | 2 +- tests/CMakeLists.txt | 5 ---- tests/src/python/utilities.py | 5 +--- 6 files changed, 24 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f763a88c854..c5c4a36d700 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -461,7 +461,7 @@ SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/${QGIS_LIB_SUBDIR}) # write a marker with source directory path into the output's bin directory # if run from the build directory QGIS will detect it and alter the paths -FILE(WRITE ${QGIS_OUTPUT_DIRECTORY}/${QGIS_BIN_SUBDIR}/source_path.txt "${CMAKE_SOURCE_DIR}") +FILE(WRITE ${QGIS_OUTPUT_DIRECTORY}/${QGIS_BIN_SUBDIR}/path.txt "${CMAKE_SOURCE_DIR}\n${QGIS_OUTPUT_DIRECTORY}") # symlink provider plugins dir for Mac unit tests IF (APPLE AND ENABLE_TESTS) diff --git a/src/core/qgsapplication.cpp b/src/core/qgsapplication.cpp index 93dfd548667..bdf938dc1b0 100644 --- a/src/core/qgsapplication.cpp +++ b/src/core/qgsapplication.cpp @@ -77,43 +77,38 @@ QgsApplication::QgsApplication( int & argc, char ** argv, bool GUIenabled, QStri { init( customConfigPath ); // init can also be called directly by e.g. unit tests that don't inherit QApplication. } + void QgsApplication::init( QString customConfigPath ) { if ( customConfigPath.isEmpty() ) { customConfigPath = QDir::homePath() + QString( "/.qgis/" ); } + qRegisterMetaType( "QgsGeometry::Error" ); QString prefixPath( getenv( "QGIS_PREFIX_PATH" ) ? getenv( "QGIS_PREFIX_PATH" ) : applicationDirPath() ); // check if QGIS is run from build directory (not the install directory) - QDir appDir( prefixPath ); -#ifndef _MSC_VER -#define SOURCE_PATH "source_path.txt" -#else -#define SOURCE_PATH "../source_path.txt" -#endif - if ( appDir.exists( SOURCE_PATH ) ) + QFile f; + foreach( QString path, QStringList() << "" << "/.." << "/bin" ) { - QFile f( prefixPath + "/" + SOURCE_PATH ); - if ( f.open( QIODevice::ReadOnly ) ) - { - ABISYM( mRunningFromBuildDir ) = true; - ABISYM( mBuildSourcePath ) = f.readAll(); -#if _MSC_VER - QStringList elems = prefixPath.split( "/", QString::SkipEmptyParts ); - ABISYM( mCfgIntDir ) = elems.last(); - ABISYM( mBuildOutputPath ) = prefixPath + "/../.."; -#elif defined(Q_WS_MACX) - ABISYM( mBuildOutputPath ) = prefixPath; -#else - ABISYM( mBuildOutputPath ) = prefixPath + "/.."; // on linux + f.setFileName( prefixPath + path + "/path.txt" ); + if( f.exists() ) + break; + } + if ( f.exists() && f.open( QIODevice::ReadOnly ) ) + { + ABISYM( mRunningFromBuildDir ) = true; + ABISYM( mBuildSourcePath ) = f.readLine().trimmed(); + ABISYM( mBuildOutputPath ) = f.readLine().trimmed(); + qDebug( "Running from build directory!" ); + qDebug( "- source directory: %s", ABISYM( mBuildSourcePath ).toUtf8().data() ); + qDebug( "- output directory of the build: %s", ABISYM( mBuildOutputPath ).toUtf8().data() ); +#ifdef _MSC_VER + ABISYM( mCfgIntDir ) = prefixPath.split( "/", QString::SkipEmptyParts ).last(); + qDebug( "- cfg: %s", ABISYM( mCfgIntDir ).toUtf8().data() ); #endif - qDebug( "Running from build directory!" ); - qDebug( "- source directory: %s", ABISYM( mBuildSourcePath ).toAscii().data() ); - qDebug( "- output directory of the build: %s", ABISYM( mBuildOutputPath ).toAscii().data() ); - } } if ( ABISYM( mRunningFromBuildDir ) ) diff --git a/src/core/qgsexpression.cpp b/src/core/qgsexpression.cpp index 6e0748bc15a..f7a0409a1c2 100644 --- a/src/core/qgsexpression.cpp +++ b/src/core/qgsexpression.cpp @@ -775,8 +775,9 @@ static QVariant fcnGeomPerimeter( const QVariantList& , QgsFeature* f, QgsExpres return QVariant( calc->measurePerimeter( f->geometry() ) ); } -static QVariant fcnRound( const QVariantList& values , QgsFeature* f, QgsExpression* parent ) +static QVariant fcnRound( const QVariantList& values , QgsFeature *f, QgsExpression* parent ) { + Q_UNUSED( f ); if ( values.length() == 2 ) { double number = getDoubleValue( values.at( 0 ), parent ); diff --git a/src/plugins/globe/globe_plugin.cpp b/src/plugins/globe/globe_plugin.cpp index 12d1e24cc16..f3550a799c0 100644 --- a/src/plugins/globe/globe_plugin.cpp +++ b/src/plugins/globe/globe_plugin.cpp @@ -422,7 +422,7 @@ void GlobePlugin::syncExtent() //get mapCanvas->extent().height() in meters QgsRectangle extent = mQGisIface->mapCanvas()->extent(); QgsDistanceArea dist; - dist.setProjectionsEnabled( true ); + dist.setEllipsoidalMode( true ); QgsPoint ll = QgsPoint( extent.xMinimum(), extent.yMinimum() ); QgsPoint ul = QgsPoint( extent.xMinimum(), extent.yMaximum() ); double height = dist.measureLine( ll, ul ); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7bdc410176f..abfb3c46841 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,9 +1,4 @@ IF (ENABLE_TESTS) - - # Install any resoure files needed here... - INSTALL(FILES ${CMAKE_SOURCE_DIR}/resources/srs.db DESTINATION ${QGIS_OUTPUT_DIRECTORY}/share/qgis/resources/) - INSTALL(FILES ${CMAKE_SOURCE_DIR}/resources/qgis.db DESTINATION ${QGIS_OUTPUT_DIRECTORY}/share/qgis/resources/) - IF (APPLE) # override default data path, otherwise looks for Resources in app bundle SET (QGIS_DATA_SUBDIR "${CMAKE_SOURCE_DIR}/resources") diff --git a/tests/src/python/utilities.py b/tests/src/python/utilities.py index 4f117f44eed..fb347a4ce39 100644 --- a/tests/src/python/utilities.py +++ b/tests/src/python/utilities.py @@ -67,11 +67,8 @@ def getQgisTestApp(): if QGISAPP is None: myGuiFlag = True # All test will run qgis in gui mode + QGISAPP = QgsApplication(sys.argv, myGuiFlag) - if 'QGIS_PREFIX_PATH' in os.environ: - myPath = os.environ['QGIS_PREFIX_PATH'] - myUseDefaultPathFlag = True - QGISAPP.setPrefixPath(myPath, myUseDefaultPathFlag) if sys.platform.startswith('darwin'): # override resource paths, otherwise looks for Resources in app