Skip to content

Commit

Permalink
make tests runable without install
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Aug 26, 2012
1 parent 1085443 commit 4cfc365
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 36 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -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)
Expand Down
43 changes: 19 additions & 24 deletions src/core/qgsapplication.cpp
Expand Up @@ -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 ) )
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsexpression.cpp
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/globe/globe_plugin.cpp
Expand Up @@ -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 );
Expand Down
5 changes: 0 additions & 5 deletions 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")
Expand Down
5 changes: 1 addition & 4 deletions tests/src/python/utilities.py
Expand Up @@ -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
Expand Down

1 comment on commit 4cfc365

@homann
Copy link
Contributor

@homann homann commented on 4cfc365 Aug 26, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat!

Please sign in to comment.