Skip to content
Permalink
Browse files

make tests runable without install

  • Loading branch information
jef-n committed Aug 26, 2012
1 parent 1085443 commit 4cfc365477f6e0cd614ddf3aec1217a8522dd6ee
@@ -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)
@@ -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>( "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 ) )
@@ -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 );
@@ -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 );
@@ -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")
@@ -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

1 comment on commit 4cfc365

@homann

This comment has been minimized.

Copy link
Contributor

@homann homann commented on 4cfc365 Aug 26, 2012

Neat!

Please sign in to comment.
You can’t perform that action at this time.