Fix #10212 (fail to handle relative paths to gzipped files)

This commit is contained in:
Martin Dobias 2014-06-09 12:46:50 +07:00
parent 7c0da6d4a5
commit 48b099c8b6
3 changed files with 84 additions and 1 deletions

View File

@ -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 ../

View File

@ -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)

View File

@ -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 <QtTest>
#include <QObject>
#include <qgsapplication.h>
#include <qgsproject.h>
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"