Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for QgsDataItem - verify that .gz and .vrt files are not re…
…cognized as both gdal and ogr items (bug #5636)
- Loading branch information
1 parent
db164df
commit 589460b
Showing
5 changed files
with
181 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/*************************************************************************** | ||
testqgsdataitem.cpp | ||
-------------------------------------- | ||
Date : Thu May 24 10:44:50 BRT 2012 | ||
Copyright : (C) 2012 Etienne Tourigny | ||
Email : etourigny.dev 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 <QString> | ||
#include <QStringList> | ||
#include <QSettings> | ||
|
||
//qgis includes... | ||
#include <qgsdataitem.h> | ||
#include <qgsvectorlayer.h> | ||
#include <qgsapplication.h> | ||
#include <qgslogger.h> | ||
|
||
/** \ingroup UnitTests | ||
* This is a unit test for the QgsDataItem class. | ||
*/ | ||
class TestQgsDataItem: 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 testValid(); | ||
void testDirItemChildren(); | ||
|
||
private: | ||
QgsDirectoryItem* mDirItem; | ||
int mScanItemsSetting; | ||
bool isValidDirItem( QgsDirectoryItem *item ); | ||
}; | ||
|
||
void TestQgsDataItem::initTestCase() | ||
{ | ||
// | ||
// Runs once before any tests are run | ||
// | ||
// init QGIS's paths - true means that all path will be inited from prefix | ||
QgsApplication::init(); | ||
QgsApplication::initQgis(); | ||
QgsApplication::showSettings(); | ||
|
||
// Set up the QSettings environment | ||
QCoreApplication::setOrganizationName( "QuantumGIS" ); | ||
QCoreApplication::setOrganizationDomain( "qgis.org" ); | ||
QCoreApplication::setApplicationName( "QGIS-TEST" ); | ||
// save current scanItemsSetting value | ||
QSettings settings; | ||
mScanItemsSetting = settings.value( "/qgis/scanItemsInBrowser", 0 ).toInt(); | ||
|
||
//create a directory item that will be used in all tests... | ||
mDirItem = new QgsDirectoryItem( 0, "Test", TEST_DATA_DIR ); | ||
} | ||
|
||
void TestQgsDataItem::cleanupTestCase() | ||
{ | ||
// restore scanItemsSetting | ||
QSettings settings; | ||
settings.setValue( "/qgis/scanItemsInBrowser", mScanItemsSetting ); | ||
if ( mDirItem ) | ||
delete mDirItem; | ||
} | ||
|
||
bool TestQgsDataItem::isValidDirItem( QgsDirectoryItem *item ) | ||
{ | ||
return ( item && item->hasChildren() ); | ||
} | ||
|
||
void TestQgsDataItem::testValid() | ||
{ | ||
if ( mDirItem ) | ||
QgsDebugMsg( QString( "dirItem has %1 children" ).arg( mDirItem->rowCount() ) ); | ||
QVERIFY( isValidDirItem( mDirItem ) ); | ||
} | ||
|
||
void TestQgsDataItem::testDirItemChildren() | ||
{ | ||
QSettings settings; | ||
// test scanItems setting=1 to test .vrt and .gz files are not loaded by gdal and ogr | ||
for ( int iSetting = 0 ; iSetting <= 1 ; iSetting++ ) | ||
{ | ||
settings.setValue( "/qgis/scanItemsInBrowser", iSetting ); | ||
QgsDirectoryItem* dirItem = new QgsDirectoryItem( 0, "Test", TEST_DATA_DIR ); | ||
QVERIFY( isValidDirItem( dirItem ) ); | ||
|
||
QVector<QgsDataItem*> children = dirItem->createChildren(); | ||
for ( int i = 0; i < children.size(); i++ ) | ||
{ | ||
QgsDataItem* dataItem = children[i]; | ||
QgsLayerItem* layerItem = dynamic_cast<QgsLayerItem*>( dataItem ); | ||
if ( ! layerItem ) | ||
continue; | ||
QFileInfo info( layerItem->path() ); | ||
QString lFile = info.fileName(); | ||
QString lProvider = layerItem->providerKey(); | ||
QString errStr = QString( "layer #%1 - %2 provider = %3 iSetting = %4" ).arg( i ).arg( lFile ).arg( lProvider ).arg( iSetting ); | ||
const char* err = errStr.toLocal8Bit().constData(); | ||
|
||
QgsDebugMsg( QString( "child name=%1 provider=%2 path=%3" ).arg( layerItem->name() ).arg( lProvider ).arg( lFile ) ); | ||
|
||
if ( lFile == "landsat.tif" ) | ||
{ | ||
QVERIFY2( lProvider == "gdal", err ); | ||
} | ||
else if ( lFile == "points.vrt" ) | ||
{ | ||
QVERIFY2( lProvider == "ogr", err ); | ||
} | ||
else if ( lFile == "landsat.vrt" ) | ||
{ | ||
QVERIFY2( lProvider == "gdal", err ); | ||
} | ||
else if ( lFile == "landsat_b1.tif.gz" ) | ||
{ | ||
QVERIFY2( lProvider == "gdal", err ); | ||
} | ||
else if ( lFile == "points3.geojson.gz" ) | ||
{ | ||
QVERIFY2( lProvider == "ogr", err ); | ||
} | ||
} | ||
if ( dirItem ) | ||
delete dirItem; | ||
} | ||
} | ||
|
||
QTEST_MAIN( TestQgsDataItem ) | ||
#include "moc_testqgsdataitem.cxx" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<OGRVRTDataSource> | ||
<OGRVRTLayer name="points"> | ||
<SrcDataSource relativeToVRT="1">points.shp</SrcDataSource> | ||
</OGRVRTLayer> | ||
</OGRVRTDataSource> |
Binary file not shown.