diff --git a/src/core/qgsproject.cpp b/src/core/qgsproject.cpp index abecfba53c2..16041ccdad9 100644 --- a/src/core/qgsproject.cpp +++ b/src/core/qgsproject.cpp @@ -1477,7 +1477,12 @@ QString QgsProject::readPath( QString src ) const QString vsiPrefix = qgsVsiPrefix( src ); if ( ! vsiPrefix.isEmpty() ) { - src.remove( 0, vsiPrefix.size() ); + // unfortunately qgsVsiPrefix returns prefix also for files like "/x/y/z.gz" + // so we need to check if we really have the prefix + if ( src.startsWith( "/vsi", Qt::CaseInsensitive ) ) + src.remove( 0, vsiPrefix.size() ); + else + vsiPrefix.clear(); } // relative path should always start with ./ or ../ diff --git a/tests/src/core/CMakeLists.txt b/tests/src/core/CMakeLists.txt index 1baf66e9d46..872dc3fed39 100644 --- a/tests/src/core/CMakeLists.txt +++ b/tests/src/core/CMakeLists.txt @@ -83,6 +83,7 @@ ADD_QGIS_TEST(diagramtest testqgsdiagram.cpp) ADD_QGIS_TEST(diagramexpressiontest testqgsdiagramexpression.cpp) ADD_QGIS_TEST(expressiontest testqgsexpression.cpp) ADD_QGIS_TEST(filewritertest testqgsvectorfilewriter.cpp) +ADD_QGIS_TEST(projecttest testqgsproject.cpp) ADD_QGIS_TEST(regression992 regression992.cpp) ADD_QGIS_TEST(regression1141 regression1141.cpp) ADD_QGIS_TEST(rasterlayertest testqgsrasterlayer.cpp) diff --git a/tests/src/core/testqgsproject.cpp b/tests/src/core/testqgsproject.cpp new file mode 100644 index 00000000000..c4caeeb7e68 --- /dev/null +++ b/tests/src/core/testqgsproject.cpp @@ -0,0 +1,77 @@ +/*************************************************************************** + testqgsproject.cpp + -------------------------------------- + Date : June 2014 + Copyright : (C) 2014 by Martin Dobias + Email : wonder.sk at gmail dot 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 +#include + +#include +#include + + +class TestQgsProject : 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. + + void testReadPath(); +}; + +void TestQgsProject::init() +{ +} + +void TestQgsProject::cleanup() +{ + // will be called after every testfunction. +} + +void TestQgsProject::initTestCase() +{ + // Runs once before any tests are run +} + + +void TestQgsProject::cleanupTestCase() +{ + // Runs once after all tests are run +} + +void TestQgsProject::testReadPath() +{ + QgsProject* prj = QgsProject::instance(); + // this is a bit hacky as we do not really load such project + prj->setFileName( "/home/qgis/a-project-file.qgs" ); // not expected to exist + // make sure we work with relative paths! + prj->writeEntry( "Paths", "Absolute", false ); + + QCOMPARE( prj->readPath( "./x.shp" ), QString( "/home/qgis/x.shp" ) ); + QCOMPARE( prj->readPath( "../x.shp" ), QString( "/home/x.shp" ) ); + + // TODO: old style (seems QGIS < 1.3) - needs existing project file and existing file + // QCOMPARE( prj->readPath( "x.shp" ), QString( "/home/qgis/x.shp" ) ); + + // VSI: /vsizip, /vsitar, /vsigzip, *.zip, *.gz, *.tgz, ... + + QCOMPARE( prj->readPath( "./x.gz" ), QString( "/home/qgis/x.gz" ) ); + QCOMPARE( prj->readPath( "/vsigzip/./x.gz" ), QString( "/vsigzip//home/qgis/x.gz" ) ); // not sure how useful this really is... + +} + + +QTEST_MAIN( TestQgsProject ) +#include "moc_testqgsproject.cxx"