Skip to content

Commit 4cfc365

Browse files
committed
make tests runable without install
1 parent 1085443 commit 4cfc365

File tree

6 files changed

+24
-36
lines changed

6 files changed

+24
-36
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/${QGIS_LIB_SUBDIR})
461461

462462
# write a marker with source directory path into the output's bin directory
463463
# if run from the build directory QGIS will detect it and alter the paths
464-
FILE(WRITE ${QGIS_OUTPUT_DIRECTORY}/${QGIS_BIN_SUBDIR}/source_path.txt "${CMAKE_SOURCE_DIR}")
464+
FILE(WRITE ${QGIS_OUTPUT_DIRECTORY}/${QGIS_BIN_SUBDIR}/path.txt "${CMAKE_SOURCE_DIR}\n${QGIS_OUTPUT_DIRECTORY}")
465465

466466
# symlink provider plugins dir for Mac unit tests
467467
IF (APPLE AND ENABLE_TESTS)

src/core/qgsapplication.cpp

+19-24
Original file line numberDiff line numberDiff line change
@@ -77,43 +77,38 @@ QgsApplication::QgsApplication( int & argc, char ** argv, bool GUIenabled, QStri
7777
{
7878
init( customConfigPath ); // init can also be called directly by e.g. unit tests that don't inherit QApplication.
7979
}
80+
8081
void QgsApplication::init( QString customConfigPath )
8182
{
8283
if ( customConfigPath.isEmpty() )
8384
{
8485
customConfigPath = QDir::homePath() + QString( "/.qgis/" );
8586
}
87+
8688
qRegisterMetaType<QgsGeometry::Error>( "QgsGeometry::Error" );
8789

8890
QString prefixPath( getenv( "QGIS_PREFIX_PATH" ) ? getenv( "QGIS_PREFIX_PATH" ) : applicationDirPath() );
8991

9092
// check if QGIS is run from build directory (not the install directory)
91-
QDir appDir( prefixPath );
92-
#ifndef _MSC_VER
93-
#define SOURCE_PATH "source_path.txt"
94-
#else
95-
#define SOURCE_PATH "../source_path.txt"
96-
#endif
97-
if ( appDir.exists( SOURCE_PATH ) )
93+
QFile f;
94+
foreach( QString path, QStringList() << "" << "/.." << "/bin" )
9895
{
99-
QFile f( prefixPath + "/" + SOURCE_PATH );
100-
if ( f.open( QIODevice::ReadOnly ) )
101-
{
102-
ABISYM( mRunningFromBuildDir ) = true;
103-
ABISYM( mBuildSourcePath ) = f.readAll();
104-
#if _MSC_VER
105-
QStringList elems = prefixPath.split( "/", QString::SkipEmptyParts );
106-
ABISYM( mCfgIntDir ) = elems.last();
107-
ABISYM( mBuildOutputPath ) = prefixPath + "/../..";
108-
#elif defined(Q_WS_MACX)
109-
ABISYM( mBuildOutputPath ) = prefixPath;
110-
#else
111-
ABISYM( mBuildOutputPath ) = prefixPath + "/.."; // on linux
96+
f.setFileName( prefixPath + path + "/path.txt" );
97+
if( f.exists() )
98+
break;
99+
}
100+
if ( f.exists() && f.open( QIODevice::ReadOnly ) )
101+
{
102+
ABISYM( mRunningFromBuildDir ) = true;
103+
ABISYM( mBuildSourcePath ) = f.readLine().trimmed();
104+
ABISYM( mBuildOutputPath ) = f.readLine().trimmed();
105+
qDebug( "Running from build directory!" );
106+
qDebug( "- source directory: %s", ABISYM( mBuildSourcePath ).toUtf8().data() );
107+
qDebug( "- output directory of the build: %s", ABISYM( mBuildOutputPath ).toUtf8().data() );
108+
#ifdef _MSC_VER
109+
ABISYM( mCfgIntDir ) = prefixPath.split( "/", QString::SkipEmptyParts ).last();
110+
qDebug( "- cfg: %s", ABISYM( mCfgIntDir ).toUtf8().data() );
112111
#endif
113-
qDebug( "Running from build directory!" );
114-
qDebug( "- source directory: %s", ABISYM( mBuildSourcePath ).toAscii().data() );
115-
qDebug( "- output directory of the build: %s", ABISYM( mBuildOutputPath ).toAscii().data() );
116-
}
117112
}
118113

119114
if ( ABISYM( mRunningFromBuildDir ) )

src/core/qgsexpression.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,9 @@ static QVariant fcnGeomPerimeter( const QVariantList& , QgsFeature* f, QgsExpres
775775
return QVariant( calc->measurePerimeter( f->geometry() ) );
776776
}
777777

778-
static QVariant fcnRound( const QVariantList& values , QgsFeature* f, QgsExpression* parent )
778+
static QVariant fcnRound( const QVariantList& values , QgsFeature *f, QgsExpression* parent )
779779
{
780+
Q_UNUSED( f );
780781
if ( values.length() == 2 )
781782
{
782783
double number = getDoubleValue( values.at( 0 ), parent );

src/plugins/globe/globe_plugin.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ void GlobePlugin::syncExtent()
422422
//get mapCanvas->extent().height() in meters
423423
QgsRectangle extent = mQGisIface->mapCanvas()->extent();
424424
QgsDistanceArea dist;
425-
dist.setProjectionsEnabled( true );
425+
dist.setEllipsoidalMode( true );
426426
QgsPoint ll = QgsPoint( extent.xMinimum(), extent.yMinimum() );
427427
QgsPoint ul = QgsPoint( extent.xMinimum(), extent.yMaximum() );
428428
double height = dist.measureLine( ll, ul );

tests/CMakeLists.txt

-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
IF (ENABLE_TESTS)
2-
3-
# Install any resoure files needed here...
4-
INSTALL(FILES ${CMAKE_SOURCE_DIR}/resources/srs.db DESTINATION ${QGIS_OUTPUT_DIRECTORY}/share/qgis/resources/)
5-
INSTALL(FILES ${CMAKE_SOURCE_DIR}/resources/qgis.db DESTINATION ${QGIS_OUTPUT_DIRECTORY}/share/qgis/resources/)
6-
72
IF (APPLE)
83
# override default data path, otherwise looks for Resources in app bundle
94
SET (QGIS_DATA_SUBDIR "${CMAKE_SOURCE_DIR}/resources")

tests/src/python/utilities.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,8 @@ def getQgisTestApp():
6767

6868
if QGISAPP is None:
6969
myGuiFlag = True # All test will run qgis in gui mode
70+
7071
QGISAPP = QgsApplication(sys.argv, myGuiFlag)
71-
if 'QGIS_PREFIX_PATH' in os.environ:
72-
myPath = os.environ['QGIS_PREFIX_PATH']
73-
myUseDefaultPathFlag = True
74-
QGISAPP.setPrefixPath(myPath, myUseDefaultPathFlag)
7572

7673
if sys.platform.startswith('darwin'):
7774
# override resource paths, otherwise looks for Resources in app

0 commit comments

Comments
 (0)