Skip to content

Commit

Permalink
Raster vrt items are containers, so update zip layer test to reflect …
Browse files Browse the repository at this point in the history
…this
  • Loading branch information
nyalldawson committed Apr 4, 2023
1 parent 96d203f commit 01f8ac8
Showing 1 changed file with 66 additions and 6 deletions.
72 changes: 66 additions & 6 deletions tests/src/core/testziplayer.cpp
Expand Up @@ -12,6 +12,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsfilebaseddataitemprovider.h"
#include "qgstest.h"

#include <QObject>
Expand Down Expand Up @@ -145,6 +146,29 @@ bool TestZipLayer::testZipItemPassthru( const QString &myFileName, const QString
return layer && layer->isValid();
}

QgsDataItem *getItemFromZip( const QString &fileName, const QString &childName )
{
const QFileInfo fileInfo( fileName );
QgsZipItem *zipItem = new QgsZipItem( nullptr, fileInfo.fileName(), fileName );
zipItem->populate();
// wait until populated in separate thread
QElapsedTimer time;
time.start();
while ( zipItem->state() != Qgis::BrowserItemState::Populated && time.elapsed() < 5000 )
{
QTest::qSleep( 100 );
QCoreApplication::processEvents();
}

const QVector<QgsDataItem *> children = zipItem->children();
for ( QgsDataItem *item : std::as_const( children ) )
{
if ( item->name() == childName )
return item;
}
return nullptr;
}

bool TestZipLayer::testZipItem( const QString &myFileName, const QString &myChildName, const QString &myProviderName )
{
QgsDebugMsgLevel( QStringLiteral( "\n=======================================\nfile = %1 name = %2 provider = %3"
Expand Down Expand Up @@ -475,14 +499,50 @@ void TestZipLayer::testZipItemVRT()
QgsSettings settings;

settings.setValue( mSettingsKey, QStringLiteral( "basic" ) );
QVERIFY( testZipItem( QDir::tempPath() + "/testzip.zip", "landsat_b1.vrt", "gdal" ) );
// this file is buggy with gdal svn - skip for now
// QVERIFY( testZipItem( QDir::tempPath() + "/testzip.zip", "points.vrt", "ogr" ) );

QgsDataItem *zipItem = getItemFromZip( QDir::tempPath() + "/testzip.zip", "landsat_b1.vrt" );
QVERIFY( zipItem );

// VRT items will be a collection type
QgsFileDataCollectionItem *collectionItem = dynamic_cast< QgsFileDataCollectionItem * >( zipItem );
QVERIFY( collectionItem );

collectionItem->populate();
// wait until populated in separate thread
QElapsedTimer time;
time.start();
while ( collectionItem->state() != Qgis::BrowserItemState::Populated && time.elapsed() < 5000 )
{
QTest::qSleep( 100 );
QCoreApplication::processEvents();
}

QgsProviderSublayerItem *sublayerItem = qobject_cast< QgsProviderSublayerItem * >( collectionItem->children().at( 0 ) );
QVERIFY( sublayerItem );
QCOMPARE( sublayerItem->sublayerDetails().name(), QStringLiteral( "landsat_b1.vrt" ) );
QCOMPARE( sublayerItem->sublayerDetails().providerKey(), QStringLiteral( "gdal" ) );

settings.setValue( mSettingsKey, QStringLiteral( "full" ) );
QVERIFY( testZipItem( QDir::tempPath() + "/testzip.zip", "landsat_b1.vrt", "gdal" ) );
// this file is buggy with gdal svn - skip for now
// QVERIFY( testZipItem( QDir::tempPath() + "/testzip.zip", "points.vrt", "ogr" ) );

zipItem = getItemFromZip( QDir::tempPath() + "/testzip.zip", "landsat_b1.vrt" );
QVERIFY( zipItem );

collectionItem = dynamic_cast< QgsFileDataCollectionItem * >( zipItem );
QVERIFY( collectionItem );

collectionItem->populate();
// wait until populated in separate thread
time.start();
while ( collectionItem->state() != Qgis::BrowserItemState::Populated && time.elapsed() < 5000 )
{
QTest::qSleep( 100 );
QCoreApplication::processEvents();
}

sublayerItem = qobject_cast< QgsProviderSublayerItem * >( collectionItem->children().at( 0 ) );
QVERIFY( sublayerItem );
QCOMPARE( sublayerItem->sublayerDetails().name(), QStringLiteral( "landsat_b1.vrt" ) );
QCOMPARE( sublayerItem->sublayerDetails().providerKey(), QStringLiteral( "gdal" ) );

}

Expand Down

0 comments on commit 01f8ac8

Please sign in to comment.