Skip to content

Commit a859c62

Browse files
committed
test that styles are loaded from qml files outside zip
1 parent 2bd054c commit a859c62

File tree

9 files changed

+373
-49
lines changed

9 files changed

+373
-49
lines changed

tests/src/core/testziplayer.cpp

Lines changed: 123 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <qgsrasterlayer.h>
2727
#include <qgsdataitem.h>
2828
#include "qgsconfig.h"
29+
#include <qgsrenderer.h>
30+
#include <qgsuniquevaluerenderer.h>
2931

3032
#include <gdal.h>
3133

@@ -43,9 +45,15 @@ class TestZipLayer: public QObject
4345
int mMaxScanZipSetting;
4446
int mScanZipSetting;
4547

46-
bool testPassthruVector( QString myFileName );
47-
bool testPassthruRaster( QString myFileName );
48+
// get map layer using Passthru
49+
QgsMapLayer * getLayer( QString myPath, QString myName, QString myProviderKey );
50+
bool testZipItemPassthru( QString myFileName, QString myProviderKey );
51+
// get map layer using QgsZipItem (only 1 child)
52+
QgsMapLayer * getZipLayer( QString myPath, QString myName );
53+
// test item(s) in zip item (supply name or test all)
4854
bool testZipItem( QString myFileName, QString myChildName );
55+
// get layer transparency to test for .qml loading
56+
int getLayerTransparency( QString myFileName, QString myProviderKey, int myScanZipSetting = 1 );
4957

5058
private slots:
5159

@@ -65,28 +73,57 @@ class TestZipLayer: public QObject
6573
void testZipItemRaster();
6674
void testZipItemVector();
6775
void testZipItemAll();
68-
76+
// test that styles are loaded from .qml files outside zip files
77+
void testZipItemVectorTransparency();
78+
void testGipItemVectorTransparency();
79+
void testZipItemRasterTransparency();
80+
void testGZipItemRasterTransparency();
6981
};
7082

71-
bool TestZipLayer::testPassthruVector( QString myFileName )
83+
84+
QgsMapLayer *TestZipLayer::getLayer( QString myPath, QString myName, QString myProviderKey )
7285
{
73-
QFileInfo myFileInfo( myFileName );
74-
QgsVectorLayer * myVectorLayer;
75-
myVectorLayer = new QgsVectorLayer( myFileInfo.filePath(),
76-
myFileInfo.completeBaseName(), "ogr" );
77-
bool ok = myVectorLayer->isValid();
78-
delete myVectorLayer;
79-
return ok;
86+
if ( myName == "" )
87+
{
88+
QFileInfo myFileInfo( myPath );
89+
myName = myFileInfo.completeBaseName();
90+
}
91+
QgsMapLayer *myLayer = NULL;
92+
93+
if ( myProviderKey == "ogr" )
94+
{
95+
myLayer = new QgsVectorLayer( myPath, myName, "ogr" );
96+
}
97+
else if ( myProviderKey == "gdal" )
98+
{
99+
myLayer = new QgsRasterLayer( myPath, myName, "gdal" );
100+
}
101+
// item should not have other provider key, but if it does will return NULL
102+
103+
return myLayer;
80104
}
81105

82-
bool TestZipLayer::testPassthruRaster( QString myFileName )
106+
QgsMapLayer *TestZipLayer::getZipLayer( QString myPath, QString myName )
83107
{
84-
QFileInfo myFileInfo( myFileName );
85-
QgsRasterLayer * myRasterLayer;
86-
myRasterLayer = new QgsRasterLayer( myFileInfo.filePath(),
87-
myFileInfo.completeBaseName(), "gdal" );
88-
bool ok = myRasterLayer->isValid();
89-
delete myRasterLayer;
108+
QgsMapLayer *myLayer = NULL;
109+
QgsDirectoryItem *dirItem = new QgsDirectoryItem( NULL, "/", "" );
110+
QgsDataItem* myItem = QgsZipItem::itemFromPath( dirItem, myPath, myName );
111+
if ( myItem )
112+
{
113+
QgsLayerItem *layerItem = dynamic_cast<QgsLayerItem*>( myItem );
114+
if ( layerItem )
115+
myLayer = getLayer( layerItem->path(), layerItem->name(), layerItem->providerKey() );
116+
}
117+
delete dirItem;
118+
return myLayer;
119+
}
120+
121+
bool TestZipLayer::testZipItemPassthru( QString myFileName, QString myProviderKey )
122+
{
123+
QgsMapLayer * myLayer = getLayer( myFileName, "", myProviderKey );
124+
bool ok = myLayer && myLayer->isValid();
125+
if ( myLayer )
126+
delete myLayer;
90127
return ok;
91128
}
92129

@@ -111,33 +148,18 @@ bool TestZipLayer::testZipItem( QString myFileName, QString myChildName = "" )
111148
QgsDebugMsg( QString( "child name=%1 provider=%2 path=%3" ).arg( layerItem->name() ).arg( layerItem->providerKey() ).arg( layerItem->path() ) );
112149
if ( myChildName == "" || myChildName == item->name() )
113150
{
114-
QgsMapLayer* myLayer = NULL;
115-
if ( layerItem->providerKey() == "ogr" )
116-
{
117-
myLayer = new QgsVectorLayer( item->path(), item->name(), "ogr" );
118-
}
119-
else if ( layerItem->providerKey() == "gdal" )
120-
{
121-
myLayer = new QgsRasterLayer( item->path(), item->name(), "gdal" );
122-
}
123-
else
124-
{
125-
// item should not have other provider key, but if it does the test will fail
126-
ok = false;
127-
QWARN( QString( "Invalid provider %1" ).arg( layerItem->providerKey() ).toLocal8Bit().data() );
128-
break;
129-
}
130-
if ( myLayer != NULL )
151+
QgsMapLayer* layer = getLayer( layerItem->path(), layerItem->name(), layerItem->providerKey() );
152+
if ( layer != NULL )
131153
{
132154
// we got a layer, check if it is valid and exit
133-
QgsDebugMsg( QString( "valid: %1" ).arg( myLayer->isValid() ) );
134-
ok = myLayer->isValid();
135-
delete myLayer;
155+
// if no child name given in argument, then pass to next one (unless current child is invalid)
156+
QgsDebugMsg( QString( "valid: %1" ).arg( layer->isValid() ) );
157+
ok = layer->isValid();
158+
delete layer;
136159
if ( ! ok )
137160
{
138-
QWARN( QString( "Invalid item %1" ).arg( layerItem->path() ).toLocal8Bit().data() );
161+
QWARN( QString( "Invalid layer %1" ).arg( layerItem->path() ).toLocal8Bit().data() );
139162
}
140-
// if no child name given, then pass to next one (unless current child is invalid)
141163
if ( myChildName == "" )
142164
{
143165
if ( ! ok )
@@ -150,14 +172,14 @@ bool TestZipLayer::testZipItem( QString myFileName, QString myChildName = "" )
150172
}
151173
else
152174
{
153-
QWARN( QString( "Invalid item %1" ).arg( layerItem->path() ).toLocal8Bit().data() );
175+
QWARN( QString( "Invalid layer %1" ).arg( layerItem->path() ).toLocal8Bit().data() );
154176
break;
155177
}
156178
}
157179
}
158180
else
159181
{
160-
QWARN( QString( "Invalid item %1" ).arg( layerItem->path() ).toLocal8Bit().data() );
182+
QWARN( QString( "Invalid layer %1" ).arg( layerItem->path() ).toLocal8Bit().data() );
161183
break;
162184
}
163185
}
@@ -166,6 +188,24 @@ bool TestZipLayer::testZipItem( QString myFileName, QString myChildName = "" )
166188
return ok;
167189
}
168190

191+
int TestZipLayer::getLayerTransparency( QString myFileName, QString myProviderKey, int myScanZipSetting )
192+
{
193+
int myTransparency = -1;
194+
mSettings.setValue( "/qgis/scanZipInBrowser", myScanZipSetting );
195+
QgsMapLayer * myLayer = NULL;
196+
if ( myScanZipSetting == 1 )
197+
myLayer = getLayer( myFileName, "", myProviderKey );
198+
else
199+
myLayer = getZipLayer( myFileName, "" );
200+
if ( myLayer && myLayer->isValid() )
201+
myTransparency = myLayer->getTransparency();
202+
if ( myLayer )
203+
delete myLayer;
204+
return myTransparency;
205+
}
206+
207+
208+
// slots
169209
void TestZipLayer::initTestCase()
170210
{
171211
QgsApplication::init();
@@ -192,7 +232,7 @@ void TestZipLayer::cleanupTestCase()
192232

193233
void TestZipLayer::testPassthruVectorZip()
194234
{
195-
QString myFileName = mDataDir + "points.zip";
235+
QString myFileName = mDataDir + "points2.zip";
196236
QgsDebugMsg( "GDAL: " + QString( GDAL_RELEASE_NAME ) );
197237
#if GDAL_VERSION_NUM < 1800
198238
myFileName = "/vsizip/" + myFileName + "/points.shp";
@@ -201,7 +241,7 @@ void TestZipLayer::testPassthruVectorZip()
201241
for ( int i = 1 ; i <= mMaxScanZipSetting ; i++ )
202242
{
203243
mSettings.setValue( "/qgis/scanZipInBrowser", i );
204-
QVERIFY( testPassthruVector( myFileName ) );
244+
QVERIFY( testZipItemPassthru( myFileName, "ogr" ) );
205245
}
206246
}
207247

@@ -210,7 +250,7 @@ void TestZipLayer::testPassthruVectorGzip()
210250
for ( int i = 1 ; i <= mMaxScanZipSetting ; i++ )
211251
{
212252
mSettings.setValue( "/qgis/scanZipInBrowser", i );
213-
QVERIFY( testPassthruVector( mDataDir + "points.geojson.gz" ) );
253+
QVERIFY( testZipItemPassthru( mDataDir + "points3.geojson.gz", "ogr" ) );
214254
}
215255
}
216256

@@ -219,7 +259,7 @@ void TestZipLayer::testPassthruRasterZip()
219259
for ( int i = 1 ; i <= mMaxScanZipSetting ; i++ )
220260
{
221261
mSettings.setValue( "/qgis/scanZipInBrowser", i );
222-
QVERIFY( testPassthruRaster( mDataDir + "landsat_b1.zip" ) );
262+
QVERIFY( testZipItemPassthru( mDataDir + "landsat_b1.zip", "gdal" ) );
223263
}
224264
}
225265

@@ -228,7 +268,7 @@ void TestZipLayer::testPassthruRasterGzip()
228268
for ( int i = 1 ; i <= mMaxScanZipSetting ; i++ )
229269
{
230270
mSettings.setValue( "/qgis/scanZipInBrowser", i );
231-
QVERIFY( testPassthruRaster( mDataDir + "landsat_b1.tif.gz" ) );
271+
QVERIFY( testZipItemPassthru( mDataDir + "landsat_b1.tif.gz", "gdal" ) );
232272
}
233273
}
234274

@@ -270,9 +310,43 @@ void TestZipLayer::testZipItemAll()
270310
QVERIFY( testZipItem( mDataDir + "testzip.zip", "" ) );
271311
}
272312

273-
QTEST_MAIN( TestZipLayer )
274-
#include "moc_testziplayer.cxx"
275313

314+
void TestZipLayer::testZipItemVectorTransparency()
315+
{
316+
int myTarget = 250;
317+
int myTransparency = getLayerTransparency( mDataDir + "points2.zip", "ogr", 1 );
318+
QVERIFY2(( myTransparency == myTarget ), QString( "Transparency is %1, should be %2" ).arg( myTransparency ).arg( myTarget ).toLocal8Bit().data() );
319+
myTransparency = getLayerTransparency( mDataDir + "points2.zip", "ogr", 2 );
320+
QVERIFY2(( myTransparency == myTarget ), QString( "Transparency is %1, should be %2" ).arg( myTransparency ).arg( myTarget ).toLocal8Bit().data() );
321+
}
322+
323+
void TestZipLayer::testGipItemVectorTransparency()
324+
{
325+
int myTarget = 250;
326+
int myTransparency = getLayerTransparency( mDataDir + "points3.geojson.gz", "ogr", 1 );
327+
QVERIFY2(( myTransparency == myTarget ), QString( "Transparency is %1, should be %2" ).arg( myTransparency ).arg( myTarget ).toLocal8Bit().data() );
328+
myTransparency = getLayerTransparency( mDataDir + "points3.geojson.gz", "ogr", 2 );
329+
QVERIFY2(( myTransparency == myTarget ), QString( "Transparency is %1, should be %2" ).arg( myTransparency ).arg( myTarget ).toLocal8Bit().data() );
330+
}
276331

332+
void TestZipLayer::testZipItemRasterTransparency()
333+
{
334+
int myTarget = 250;
335+
int myTransparency = getLayerTransparency( mDataDir + "landsat_b1.zip", "gdal", 1 );
336+
QVERIFY2(( myTransparency == myTarget ), QString( "Transparency is %1, should be %2" ).arg( myTransparency ).arg( myTarget ).toLocal8Bit().data() );
337+
myTransparency = getLayerTransparency( mDataDir + "landsat_b1.zip", "gdal", 2 );
338+
QVERIFY2(( myTransparency == myTarget ), QString( "Transparency is %1, should be %2" ).arg( myTransparency ).arg( myTarget ).toLocal8Bit().data() );
339+
}
340+
341+
void TestZipLayer::testGZipItemRasterTransparency()
342+
{
343+
int myTarget = 250;
344+
int myTransparency = getLayerTransparency( mDataDir + "landsat_b1.tif.gz", "gdal", 1 );
345+
QVERIFY2(( myTransparency == myTarget ), QString( "Transparency is %1, should be %2" ).arg( myTransparency ).arg( myTarget ).toLocal8Bit().data() );
346+
myTransparency = getLayerTransparency( mDataDir + "landsat_b1.tif.gz", "gdal", 2 );
347+
QVERIFY2(( myTransparency == myTarget ), QString( "Transparency is %1, should be %2" ).arg( myTransparency ).arg( myTarget ).toLocal8Bit().data() );
348+
}
277349

278350

351+
QTEST_MAIN( TestZipLayer )
352+
#include "moc_testziplayer.cxx"

tests/testdata/landsat_b1.qml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
2+
<qgis version="1.9.90-Alpha" minimumScale="0" maximumScale="1e+08" hasScaleBasedVisibilityFlag="0">
3+
<transparencyLevelInt>250</transparencyLevelInt>
4+
<rasterproperties>
5+
<mDrawingStyle>SingleBandGray</mDrawingStyle>
6+
<mColorShadingAlgorithm>UndefinedShader</mColorShadingAlgorithm>
7+
<mInvertColor boolean="false"/>
8+
<mRedBandName>Not Set</mRedBandName>
9+
<mGreenBandName>Not Set</mGreenBandName>
10+
<mBlueBandName>Not Set</mBlueBandName>
11+
<mGrayBandName>Band 1</mGrayBandName>
12+
<mStandardDeviations>0</mStandardDeviations>
13+
<mUserDefinedRGBMinimumMaximum boolean="false"/>
14+
<mRGBMinimumMaximumEstimated boolean="true"/>
15+
<mUserDefinedGrayMinimumMaximum boolean="false"/>
16+
<mGrayMinimumMaximumEstimated boolean="true"/>
17+
<mContrastEnhancementAlgorithm>StretchAndClipToMinimumMaximum</mContrastEnhancementAlgorithm>
18+
<contrastEnhancementMinMaxValues>
19+
<minMaxEntry>
20+
<min>122</min>
21+
<max>130</max>
22+
</minMaxEntry>
23+
</contrastEnhancementMinMaxValues>
24+
<mNoDataValue mValidNoDataValue="true">-32768.000000</mNoDataValue>
25+
<singleValuePixelList>
26+
<pixelListEntry pixelValue="-32768.000000" percentTransparent="100"/>
27+
</singleValuePixelList>
28+
<threeValuePixelList>
29+
<pixelListEntry red="-32768.000000" blue="-32768.000000" green="-32768.000000" percentTransparent="100"/>
30+
</threeValuePixelList>
31+
</rasterproperties>
32+
</qgis>

tests/testdata/landsat_b1.tif.qml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
2+
<qgis version="1.9.90-Alpha" minimumScale="0" maximumScale="1e+08" hasScaleBasedVisibilityFlag="0">
3+
<transparencyLevelInt>248</transparencyLevelInt>
4+
<rasterproperties>
5+
<mDrawingStyle>SingleBandGray</mDrawingStyle>
6+
<mColorShadingAlgorithm>UndefinedShader</mColorShadingAlgorithm>
7+
<mInvertColor boolean="false"/>
8+
<mRedBandName></mRedBandName>
9+
<mGreenBandName></mGreenBandName>
10+
<mBlueBandName></mBlueBandName>
11+
<mGrayBandName>Band 1</mGrayBandName>
12+
<mStandardDeviations>0</mStandardDeviations>
13+
<mUserDefinedRGBMinimumMaximum boolean="false"/>
14+
<mRGBMinimumMaximumEstimated boolean="true"/>
15+
<mUserDefinedGrayMinimumMaximum boolean="false"/>
16+
<mGrayMinimumMaximumEstimated boolean="true"/>
17+
<mContrastEnhancementAlgorithm>StretchAndClipToMinimumMaximum</mContrastEnhancementAlgorithm>
18+
<contrastEnhancementMinMaxValues>
19+
<minMaxEntry>
20+
<min>122</min>
21+
<max>130</max>
22+
</minMaxEntry>
23+
</contrastEnhancementMinMaxValues>
24+
<mNoDataValue mValidNoDataValue="true">-32768.000000</mNoDataValue>
25+
<singleValuePixelList>
26+
<pixelListEntry pixelValue="-32768.000000" percentTransparent="100"/>
27+
</singleValuePixelList>
28+
<threeValuePixelList>
29+
<pixelListEntry red="-32768.000000" blue="-32768.000000" green="-32768.000000" percentTransparent="100"/>
30+
</threeValuePixelList>
31+
</rasterproperties>
32+
</qgis>

tests/testdata/landsat_b1.zip

0 Bytes
Binary file not shown.

tests/testdata/points.zip

-2.34 KB
Binary file not shown.

0 commit comments

Comments
 (0)