Skip to content

Commit 50f6f4c

Browse files
committedMay 8, 2012
Merge pull request #139 from etiennesky/zip_fixes
Zip support fixes from Etienne
2 parents 0dbf937 + f60d40a commit 50f6f4c

36 files changed

+124
-7421
lines changed
 

‎CMakeLists.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -258,20 +258,6 @@ FIND_PROGRAM(QT_LRELEASE_EXECUTABLE
258258
NO_DEFAULT_PATH
259259
)
260260

261-
262-
#############################################################
263-
# search for zlib optional, used by quazip
264-
# this uses script provided by cmake
265-
# if WIN32 should use zlib from QT
266-
FIND_PACKAGE(ZLIB)
267-
IF (ZLIB_FOUND)
268-
MESSAGE(STATUS "Found zlib: ${ZLIB_LIBRARY}")
269-
SET(HAVE_ZLIB TRUE)
270-
ELSE (ZLIB_FOUND)
271-
MESSAGE(STATUS "Could not find zlib (optional)")
272-
ENDIF(ZLIB_FOUND)
273-
274-
275261
#############################################################
276262
# enable warnings
277263

‎PROVENANCE

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -68,35 +68,4 @@ licensed under the GPL or LGPL, version 2.
6868
== External Source Files ==
6969
The following files are included in the QGIS source tree from external
7070
sources. The source, license, and copyright are noted for each.
71-
=== src/core/quazip ===
72-
QuaZIP is the C++ wrapper for the Gilles Vollant's ZIP/UNZIP package
73-
using Trolltech's Qt library.
74-
Copyright (C) 2005-2011 Sergey A. Tachenov
75-
Added to the QGIS source tree 17 April 2012 as part of a patch from
76-
Etienne Tourigny <etourigny.dev@gmail.com>
77-
78-
* COPYING
79-
* ioapi.h
80-
* JlCompress.h
81-
* quaadler32.cpp
82-
* quachecksum32.h
83-
* quacrc32.h
84-
* quazipfile.cpp
85-
* quazipfileinfo.h
86-
* quazip.h
87-
* quazipnewinfo.h
88-
* unzip.c
89-
* zip.c
90-
* crypt.h
91-
* JlCompress.cpp
92-
* qioapi.cpp
93-
* quaadler32.h
94-
* quacrc32.cpp
95-
* quazip.cpp
96-
* quazipfile.h
97-
* quazip_global.h
98-
* quazipnewinfo.cpp
99-
* README.txt
100-
* unzip.h
101-
* zip.h
10271

‎cmake_templates/qgsconfig.h.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
#cmakedefine HAVE_SPATIALITE
3333

34-
#cmakedefine HAVE_ZLIB
35-
3634
#cmakedefine HAVE_MSSQL
3735

3836
#cmakedefine HAVE_PYTHON

‎src/app/qgsoptions.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
210210
cmbScanZipInBrowser->clear();
211211
cmbScanZipInBrowser->addItem( tr( "No" ) ); // 0
212212
cmbScanZipInBrowser->addItem( tr( "Passthru" ) ); // 1
213-
// only add these options if zlib is available
214-
#ifdef HAVE_ZLIB
215213
cmbScanZipInBrowser->addItem( tr( "Basic scan" ) ); // 2
216214
cmbScanZipInBrowser->addItem( tr( "Full scan" ) ); // 3
217-
cmbScanZipInBrowser->setCurrentIndex( settings.value( "/qgis/scanZipInBrowser", 1 ).toInt() );
218-
#else
219-
if ( settings.value( "/qgis/scanZipInBrowser", 1 ) == 0 )
220-
cmbScanZipInBrowser->setCurrentIndex( 0 );
221-
else
222-
cmbScanZipInBrowser->setCurrentIndex( 1 );
223-
#endif
215+
cmbScanZipInBrowser->setCurrentIndex( settings.value( "/qgis/scanZipInBrowser", 2 ).toInt() );
224216

225217
// set the display update threshold
226218
spinBoxUpdateThreshold->setValue( settings.value( "/Map/updateThreshold" ).toInt() );

‎src/core/CMakeLists.txt

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -177,23 +177,6 @@ SET(QGIS_CORE_SRCS
177177
qgsspatialindex.cpp
178178
)
179179

180-
IF(HAVE_ZLIB)
181-
ADD_DEFINITIONS(-DQUAZIP_BUILD)
182-
183-
SET(QGIS_CORE_SRCS
184-
${QGIS_CORE_SRCS}
185-
quazip/unzip.c
186-
quazip/zip.c
187-
quazip/JlCompress.cpp
188-
quazip/qioapi.cpp
189-
quazip/quaadler32.cpp
190-
quazip/quacrc32.cpp
191-
quazip/quazip.cpp
192-
quazip/quazipfile.cpp
193-
quazip/quazipnewinfo.cpp
194-
)
195-
ENDIF(HAVE_ZLIB)
196-
197180
IF(WIN32)
198181
SET(QGIS_CORE_SRCS
199182
${QGIS_CORE_SRCS}
@@ -298,13 +281,6 @@ SET(QGIS_CORE_MOC_HDRS
298281
gps/qextserialport/qextserialenumerator.h
299282
)
300283

301-
IF (HAVE_ZLIB)
302-
SET(QGIS_CORE_MOC_HDRS
303-
${QGIS_CORE_MOC_HDRS}
304-
quazip/quazipfile.h
305-
)
306-
ENDIF(HAVE_ZLIB)
307-
308284

309285
IF (QT_MOBILITY_LOCATION_FOUND)
310286
SET(QGIS_CORE_MOC_HDRS
@@ -541,11 +517,6 @@ ELSE (WITH_INTERNAL_SPATIALITE)
541517
TARGET_LINK_LIBRARIES(qgis_core ${SQLITE3_LIBRARY})
542518
ENDIF (WITH_INTERNAL_SPATIALITE)
543519

544-
IF (HAVE_ZLIB)
545-
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS})
546-
TARGET_LINK_LIBRARIES(qgis_core ${ZLIB_LIBRARY})
547-
ENDIF (HAVE_ZLIB)
548-
549520
IF (APPLE)
550521
SET_TARGET_PROPERTIES(qgis_core PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
551522
ENDIF (APPLE)

‎src/core/qgsdataitem.cpp

Lines changed: 71 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@
3636
#include "qgsproviderregistry.h"
3737
#include "qgsconfig.h"
3838

39-
// use internal quazip for /vsizip support
40-
#ifdef HAVE_ZLIB
41-
#define QUAZIP_STATIC
42-
#include <quazip/quazip.h>
43-
#endif
39+
// use GDAL VSI mechanism
40+
#include "cpl_vsi.h"
41+
#include "cpl_string.h"
4442

4543
// shared icons
4644
const QIcon &QgsLayerItem::iconPoint()
@@ -449,7 +447,7 @@ QVector<QgsDataItem*> QgsDirectoryItem::createChildren( )
449447
QVector<QgsDataItem*> children;
450448
QDir dir( mPath );
451449
QSettings settings;
452-
bool scanZip = ( settings.value( "/qgis/scanZipInBrowser", 1 ).toInt() != 0 );
450+
bool scanZip = ( settings.value( "/qgis/scanZipInBrowser", 2 ).toInt() != 0 );
453451

454452
QStringList entries = dir.entryList( QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
455453
foreach( QString subdir, entries )
@@ -775,14 +773,70 @@ QgsZipItem::~QgsZipItem()
775773
{
776774
}
777775

776+
// internal function to scan a vsidir (zip or tar file) recursively
777+
// hopefully this will make it to GDAL
778+
char **VSIReadDirRecursive1( const char *pszPath )
779+
{
780+
char **papszFiles = NULL;
781+
char **papszFiles1 = NULL;
782+
char **papszFiles2 = NULL;
783+
VSIStatBufL psStatBuf;
784+
char szTemp1[1096];
785+
char szTemp2[1096];
786+
787+
// get listing
788+
papszFiles1 = VSIReadDir( pszPath );
789+
if ( ! papszFiles1 )
790+
return NULL;
791+
792+
// get files and directories inside listing
793+
for ( int i = 0; i < CSLCount( papszFiles1 ); i++ )
794+
{
795+
// build complete file name for stat
796+
strcpy( szTemp1, pszPath );
797+
strcat( szTemp1, ( char* )"/" ); // this might not be ok on windows
798+
strcat( szTemp1, papszFiles1[i] );
799+
// if is file, add it
800+
if ( VSIStatL( szTemp1, &psStatBuf ) == 0 &&
801+
VSI_ISREG( psStatBuf.st_mode ) )
802+
{
803+
papszFiles = CSLAddString( papszFiles, papszFiles1[i] );
804+
}
805+
else if ( VSIStatL( szTemp1, &psStatBuf ) == 0 &&
806+
VSI_ISDIR( psStatBuf.st_mode ) )
807+
{
808+
// add directory entry
809+
strcpy( szTemp2, papszFiles1[i] );
810+
strcat( szTemp2, ( char* )"/" ); // this might not be ok on windows
811+
papszFiles = CSLAddString( papszFiles, szTemp2 );
812+
// recursively add files inside directory
813+
papszFiles2 = VSIReadDirRecursive1( szTemp1 );
814+
if ( papszFiles2 )
815+
{
816+
for ( int j = 0; j < CSLCount( papszFiles2 ); j++ )
817+
{
818+
strcpy( szTemp2, papszFiles1[i] );
819+
strcat( szTemp2, ( char* )"/" ); // this might not be ok on windows
820+
strcat( szTemp2, papszFiles2[j] );
821+
papszFiles = CSLAddString( papszFiles, szTemp2 );
822+
}
823+
CSLDestroy( papszFiles2 );
824+
}
825+
}
826+
}
827+
CSLDestroy( papszFiles1 );
828+
829+
return papszFiles;
830+
}
831+
778832
QVector<QgsDataItem*> QgsZipItem::createChildren( )
779833
{
780834
QVector<QgsDataItem*> children;
781835
QString tmpPath;
782836
QString childPath;
783837

784838
QSettings settings;
785-
int scanZipSetting = settings.value( "/qgis/scanZipInBrowser", 1 ).toInt();
839+
int scanZipSetting = settings.value( "/qgis/scanZipInBrowser", 2 ).toInt();
786840

787841
mZipFileList.clear();
788842

@@ -794,15 +848,6 @@ QVector<QgsDataItem*> QgsZipItem::createChildren( )
794848
return children;
795849
}
796850

797-
#ifndef HAVE_ZLIB
798-
// if zlib not available, only support Passthru
799-
if ( scanZipSetting == 2 || scanZipSetting == 3 )
800-
{
801-
scanZipSetting = 1;
802-
settings.setValue( "/qgis/scanZipInBrowser", 1 );
803-
}
804-
#endif
805-
806851
// if scanZipBrowser == 1 (Passthru): do not scan zip and allow to open directly with /vsizip/
807852
if ( scanZipSetting == 1 )
808853
{
@@ -811,32 +856,25 @@ QVector<QgsDataItem*> QgsZipItem::createChildren( )
811856
return children;
812857
}
813858

814-
#ifdef HAVE_ZLIB
815-
QgsDebugMsg( QString( "Open file %1 with quazip" ).arg( path() ) );
816859
// get list of files inside zip file
817-
QuaZip zip( path() );
818-
if ( ! zip.open( QuaZip::mdUnzip ) || ! zip.isOpen() )
819-
{
820-
QgsDebugMsg( QString( "Zip error: %1" ).arg( zip.getZipError() ) );
821-
}
822-
else
860+
QgsDebugMsg( QString( "Open file %1 with gdal vsi" ).arg( path() ) );
861+
char **papszSiblingFiles = VSIReadDirRecursive1( QString( "/vsizip/" + path() ).toLocal8Bit().constData() );
862+
if ( papszSiblingFiles )
823863
{
824-
for ( bool more = zip.goToFirstFile(); more; more = zip.goToNextFile() )
864+
for ( int i = 0; i < CSLCount( papszSiblingFiles ); i++ )
825865
{
826-
tmpPath = zip.getCurrentFileName();
866+
tmpPath = papszSiblingFiles[i];
867+
QgsDebugMsg( QString( "Read file %1" ).arg( tmpPath ) );
827868
// skip directories (files ending with /)
828869
if ( tmpPath.right( 1 ) != "/" )
829870
mZipFileList << tmpPath;
830871
}
831-
zip.close();
872+
CSLDestroy( papszSiblingFiles );
832873
}
833-
if ( zip.getZipError() != UNZ_OK )
874+
else
834875
{
835-
QgsDebugMsg( QString( "Zip error: %1" ).arg( zip.getZipError() ) );
876+
QgsDebugMsg( QString( "Error reading %1" ).arg( path() ) );
836877
}
837-
#else
838-
QgsDebugMsg( QString( "Cannot open file %1 with quazip - zlib not configured" ).arg( path() ) );
839-
#endif
840878

841879
// loop over files inside zip
842880
foreach( QString fileName, mZipFileList )
@@ -897,9 +935,8 @@ QVector<QgsDataItem*> QgsZipItem::createChildren( )
897935

898936
QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, QString path, QString name )
899937
{
900-
901938
QSettings settings;
902-
int scanZipSetting = settings.value( "/qgis/scanZipInBrowser", 1 ).toInt();
939+
int scanZipSetting = settings.value( "/qgis/scanZipInBrowser", 2 ).toInt();
903940
QString vsizipPath = path;
904941
int zipFileCount = 0;
905942
QFileInfo fileInfo( path );

‎src/core/qgsmaplayer.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -553,15 +553,16 @@ QString QgsMapLayer::styleURI( )
553553
{
554554
QString myURI = publicSource();
555555

556-
// if file is using the /vsizip/ or /vsigzip/ mechanism, cleanup the name
557-
if ( myURI.left( 9 ) == "/vsigzip/" )
556+
// if file is using the VSIFILE mechanism, remove the prefix
557+
if ( myURI.startsWith( "/vsigzip/", Qt::CaseInsensitive ) )
558558
{
559-
myURI.remove( 1, 9 );
559+
myURI.remove( 0, 9 );
560560
}
561-
else if ( myURI.left( 8 ) == "/vsizip/" && myURI.right( 4 ) == ".zip" )
561+
else if ( myURI.startsWith( "/vsizip/", Qt::CaseInsensitive ) &&
562+
myURI.endsWith( ".zip", Qt::CaseInsensitive ) )
562563
{
563564
// ideally we should look for .qml file inside zip file
564-
myURI.remove( 1, 8 );
565+
myURI.remove( 0, 8 );
565566
}
566567

567568
QFileInfo myFileInfo( myURI );
@@ -570,12 +571,12 @@ QString QgsMapLayer::styleURI( )
570571
if ( myFileInfo.exists() )
571572
{
572573
// if file is using the /vsizip/ or /vsigzip/ mechanism, cleanup the name
573-
if ( myURI.right( 3 ) == ".gz" )
574+
if ( myURI.endsWith( ".gz", Qt::CaseInsensitive ) )
574575
{
575576
myURI.chop( 3 );
576577
myFileInfo.setFile( myURI );
577578
}
578-
else if ( myURI.right( 4 ) == ".zip" )
579+
else if ( myURI.endsWith( ".zip", Qt::CaseInsensitive ) )
579580
{
580581
myURI.chop( 4 );
581582
myFileInfo.setFile( myURI );

‎src/core/quazip/COPYING

Lines changed: 0 additions & 458 deletions
This file was deleted.

‎src/core/quazip/JlCompress.cpp

Lines changed: 0 additions & 535 deletions
This file was deleted.

‎src/core/quazip/JlCompress.h

Lines changed: 0 additions & 115 deletions
This file was deleted.

‎src/core/quazip/README.txt

Lines changed: 0 additions & 66 deletions
This file was deleted.

‎src/core/quazip/crypt.h

Lines changed: 0 additions & 136 deletions
This file was deleted.

‎src/core/quazip/ioapi.h

Lines changed: 0 additions & 77 deletions
This file was deleted.

‎src/core/quazip/qioapi.cpp

Lines changed: 0 additions & 150 deletions
This file was deleted.

‎src/core/quazip/quaadler32.cpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎src/core/quazip/quaadler32.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

‎src/core/quazip/quachecksum32.h

Lines changed: 0 additions & 54 deletions
This file was deleted.

‎src/core/quazip/quacrc32.cpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎src/core/quazip/quacrc32.h

Lines changed: 0 additions & 27 deletions
This file was deleted.

‎src/core/quazip/quazip.cpp

Lines changed: 0 additions & 588 deletions
This file was deleted.

‎src/core/quazip/quazip.h

Lines changed: 0 additions & 410 deletions
This file was deleted.

‎src/core/quazip/quazip_global.h

Lines changed: 0 additions & 55 deletions
This file was deleted.

‎src/core/quazip/quazipfile.cpp

Lines changed: 0 additions & 517 deletions
This file was deleted.

‎src/core/quazip/quazipfile.h

Lines changed: 0 additions & 443 deletions
This file was deleted.

‎src/core/quazip/quazipfileinfo.h

Lines changed: 0 additions & 67 deletions
This file was deleted.

‎src/core/quazip/quazipnewinfo.cpp

Lines changed: 0 additions & 51 deletions
This file was deleted.

‎src/core/quazip/quazipnewinfo.h

Lines changed: 0 additions & 103 deletions
This file was deleted.

‎src/core/quazip/unzip.c

Lines changed: 0 additions & 1513 deletions
This file was deleted.

‎src/core/quazip/unzip.h

Lines changed: 0 additions & 357 deletions
This file was deleted.

‎src/core/quazip/zip.c

Lines changed: 0 additions & 1208 deletions
This file was deleted.

‎src/core/quazip/zip.h

Lines changed: 0 additions & 246 deletions
This file was deleted.

‎src/providers/gdal/qgsgdaldataitems.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
108108
// zip settings + info
109109
QSettings settings;
110110
int scanItemsSetting = settings.value( "/qgis/scanItemsInBrowser", 0 ).toInt();
111-
int scanZipSetting = settings.value( "/qgis/scanZipInBrowser", 1 ).toInt();
111+
int scanZipSetting = settings.value( "/qgis/scanZipInBrowser", 2 ).toInt();
112112
bool is_vsizip = ( thePath.startsWith( "/vsizip/" ) ||
113113
thePath.endsWith( ".zip", Qt::CaseInsensitive ) );
114114
bool is_vsigzip = ( thePath.startsWith( "/vsigzip/" ) ||

‎src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,9 +1843,8 @@ void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString
18431843

18441844
// VSIFileHandler (see qgsogrprovider.cpp)
18451845
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1600
1846-
// QSettings settings;
1847-
// if ( settings.value( "/qgis/scanZipInBrowser", 1 ).toInt() != 0 )
1848-
if ( 1 )
1846+
QSettings settings;
1847+
if ( settings.value( "/qgis/scanZipInBrowser", 2 ).toInt() != 0 )
18491848
{
18501849
QString glob = "*.zip";
18511850
glob += " *.gz";

‎src/providers/ogr/qgsogrdataitems.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
231231
// zip settings + info
232232
QSettings settings;
233233
int scanItemsSetting = settings.value( "/qgis/scanItemsInBrowser", 0 ).toInt();
234-
int scanZipSetting = settings.value( "/qgis/scanZipInBrowser", 1 ).toInt();
234+
int scanZipSetting = settings.value( "/qgis/scanZipInBrowser", 2 ).toInt();
235235
bool is_vsizip = ( thePath.startsWith( "/vsizip/" ) ||
236236
thePath.endsWith( ".zip", Qt::CaseInsensitive ) );
237237
bool is_vsigzip = ( thePath.startsWith( "/vsigzip/" ) ||

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,9 +1791,8 @@ QString createFilters( QString type )
17911791
// This does not work for some file types, see VSIFileHandler doc.
17921792
// Ideally we should also add support for /vsitar/ (requires cpl_vsil_tar.cpp).
17931793
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1600
1794-
// QSettings settings;
1795-
// if ( settings.value( "/qgis/scanZipInBrowser", 1 ).toInt() != 0 )
1796-
if ( 1 )
1794+
QSettings settings;
1795+
if ( settings.value( "/qgis/scanZipInBrowser", 2 ).toInt() != 0 )
17971796
{
17981797
myFileFilters += createFileFilter_( QObject::tr( "GDAL/OGR VSIFileHandler" ), "*.zip *.gz" );
17991798
myExtensions << "zip" << "gz";

‎tests/src/core/testziplayer.cpp

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class TestZipLayer: public QObject
4141
private:
4242

4343
QString mDataDir;
44-
QSettings mSettings;
4544
int mMaxScanZipSetting;
4645
int mScanZipSetting;
4746

@@ -191,7 +190,11 @@ bool TestZipLayer::testZipItem( QString myFileName, QString myChildName = "" )
191190
int TestZipLayer::getLayerTransparency( QString myFileName, QString myProviderKey, int myScanZipSetting )
192191
{
193192
int myTransparency = -1;
194-
mSettings.setValue( "/qgis/scanZipInBrowser", myScanZipSetting );
193+
QSettings settings;
194+
settings.setValue( "/qgis/scanZipInBrowser", myScanZipSetting );
195+
if ( myScanZipSetting != settings.value( "/qgis/scanZipInBrowser" ).toInt() )
196+
return myTransparency;
197+
195198
QgsMapLayer * myLayer = NULL;
196199
if ( myScanZipSetting == 1 )
197200
myLayer = getLayer( myFileName, "", myProviderKey );
@@ -214,26 +217,32 @@ void TestZipLayer::initTestCase()
214217
QgsApplication::initQgis();
215218
// save data dir
216219
mDataDir = QString( TEST_DATA_DIR ) + QDir::separator();
217-
// set zipSetting to 1 (Passthru) and save current value
218-
mScanZipSetting = mSettings.value( "/qgis/scanZipInBrowser", 1 ).toInt();
219-
mSettings.setValue( "/qgis/scanZipInBrowser", 1 );
220-
// max zipSetting value, depending on zlib presence
220+
// Set up the QSettings environment
221+
QCoreApplication::setOrganizationName( "QuantumGIS" );
222+
QCoreApplication::setOrganizationDomain( "qgis.org" );
223+
QCoreApplication::setApplicationName( "QGIS-TEST" );
224+
225+
// save current zipSetting value
226+
QSettings settings;
227+
mScanZipSetting = settings.value( "/qgis/scanZipInBrowser", 1 ).toInt();
228+
229+
// max zipSetting value depends on zlib presence
221230
mMaxScanZipSetting = 1;
222-
#ifdef HAVE_ZLIB
223231
mMaxScanZipSetting = 3;
224-
#endif
225232

226233
}
227234

228235
void TestZipLayer::cleanupTestCase()
229236
{
230237
// restore zipSetting
231-
mSettings.setValue( "/qgis/scanZipInBrowser", mScanZipSetting );
238+
QSettings settings;
239+
settings.setValue( "/qgis/scanZipInBrowser", mScanZipSetting );
232240
}
233241

234242

235243
void TestZipLayer::testPassthruVectorZip()
236244
{
245+
QSettings settings;
237246
QString myFileName = mDataDir + "points2.zip";
238247
QgsDebugMsg( "GDAL: " + QString( GDAL_RELEASE_NAME ) );
239248
#if GDAL_VERSION_NUM < 1800
@@ -242,76 +251,79 @@ void TestZipLayer::testPassthruVectorZip()
242251
QgsDebugMsg( "FILE: " + QString( myFileName ) );
243252
for ( int i = 1 ; i <= mMaxScanZipSetting ; i++ )
244253
{
245-
mSettings.setValue( "/qgis/scanZipInBrowser", i );
254+
settings.setValue( "/qgis/scanZipInBrowser", i );
255+
QVERIFY( i == settings.value( "/qgis/scanZipInBrowser" ).toInt() );
246256
QVERIFY( testZipItemPassthru( myFileName, "ogr" ) );
247257
}
248258
}
249259

250260
void TestZipLayer::testPassthruVectorGzip()
251261
{
262+
QSettings settings;
252263
#if GDAL_VERSION_NUM < 1700
253264
QSKIP( "This test requires GDAL > 1.7", SkipSingle );
254265
#endif
255266
for ( int i = 1 ; i <= mMaxScanZipSetting ; i++ )
256267
{
257-
mSettings.setValue( "/qgis/scanZipInBrowser", i );
268+
settings.setValue( "/qgis/scanZipInBrowser", i );
269+
QVERIFY( i == settings.value( "/qgis/scanZipInBrowser" ).toInt() );
258270
QVERIFY( testZipItemPassthru( mDataDir + "points3.geojson.gz", "ogr" ) );
259271
}
260272
}
261273

262274
void TestZipLayer::testPassthruRasterZip()
263275
{
276+
QSettings settings;
264277
for ( int i = 1 ; i <= mMaxScanZipSetting ; i++ )
265278
{
266-
mSettings.setValue( "/qgis/scanZipInBrowser", i );
279+
settings.setValue( "/qgis/scanZipInBrowser", i );
280+
QVERIFY( i == settings.value( "/qgis/scanZipInBrowser" ).toInt() );
267281
QVERIFY( testZipItemPassthru( mDataDir + "landsat_b1.zip", "gdal" ) );
268282
}
269283
}
270284

271285
void TestZipLayer::testPassthruRasterGzip()
272286
{
287+
QSettings settings;
273288
for ( int i = 1 ; i <= mMaxScanZipSetting ; i++ )
274289
{
275-
mSettings.setValue( "/qgis/scanZipInBrowser", i );
290+
settings.setValue( "/qgis/scanZipInBrowser", i );
291+
QVERIFY( i == settings.value( "/qgis/scanZipInBrowser" ).toInt() );
276292
QVERIFY( testZipItemPassthru( mDataDir + "landsat_b1.tif.gz", "gdal" ) );
277293
}
278294
}
279295

280296
void TestZipLayer::testZipItemRaster()
281297
{
282-
#ifndef HAVE_ZLIB
283-
QSKIP( "This test requires ZLIB", SkipSingle );
284-
#endif
285-
298+
QSettings settings;
286299
for ( int i = 2 ; i <= mMaxScanZipSetting ; i++ )
287300
{
288-
mSettings.setValue( "/qgis/scanZipInBrowser", i );
301+
settings.setValue( "/qgis/scanZipInBrowser", i );
302+
QVERIFY( i == settings.value( "/qgis/scanZipInBrowser" ).toInt() );
289303
QVERIFY( testZipItem( mDataDir + "testzip.zip", "landsat_b1.tif" ) );
290304
}
291305
}
292306

293307
void TestZipLayer::testZipItemVector()
294308
{
295-
#ifndef HAVE_ZLIB
296-
QSKIP( "This test requires ZLIB", SkipSingle );
297-
#endif
309+
QSettings settings;
298310
for ( int i = 2 ; i <= mMaxScanZipSetting ; i++ )
299311
{
300-
mSettings.setValue( "/qgis/scanZipInBrowser", i );
312+
settings.setValue( "/qgis/scanZipInBrowser", i );
313+
QVERIFY( i == settings.value( "/qgis/scanZipInBrowser" ).toInt() );
301314
QVERIFY( testZipItem( mDataDir + "testzip.zip", "points.shp" ) );
302315
}
303316
}
304317

305318
void TestZipLayer::testZipItemAll()
306319
{
307-
#ifndef HAVE_ZLIB
308-
QSKIP( "This test requires ZLIB", SkipSingle );
309-
#endif
310320
// test file contains invalid items (tmp1.tif, tmp1.txt and tmp1.xml)
311321
// test for all items inside zip, using zipSetting 3 (Full Scan) which will ignore invalid items
312322
// using zipSetting 2 (Basic Scan) would raise errors, because QgsZipItem would not test for valid items
313323
// and return child names of the invalid items
314-
mSettings.setValue( "/qgis/scanZipInBrowser", 3 );
324+
QSettings settings;
325+
settings.setValue( "/qgis/scanZipInBrowser", 3 );
326+
QVERIFY( 3 == settings.value( "/qgis/scanZipInBrowser" ).toInt() );
315327
QVERIFY( testZipItem( mDataDir + "testzip.zip", "" ) );
316328
}
317329

0 commit comments

Comments
 (0)
Please sign in to comment.