Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add additional tests, adjust preexisting one
  • Loading branch information
nirvn authored and github-actions[bot] committed Nov 9, 2021
1 parent 712ec3c commit d052fdb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
12 changes: 12 additions & 0 deletions tests/src/core/testqgsgdalprovider.cpp
Expand Up @@ -120,6 +120,12 @@ void TestQgsGdalProvider::decodeUri()
components = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "gdal" ), uri );
QCOMPARE( components[QStringLiteral( "path" )].toString(), QStringLiteral( "c:/home/to/path/my_file.gpkg" ) );
QCOMPARE( components[QStringLiteral( "layerName" )].toString(), QStringLiteral( "layer_name" ) );

// test authcfg with vsicurl URI
uri = QStringLiteral( "/vsicurl/https://www.qgis.org/dataset.tif authcfg='1234567'" );
components = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "gdal" ), uri );
QCOMPARE( components.value( QStringLiteral( "path" ) ).toString(), QString( "/vsicurl/https://www.qgis.org/dataset.tif" ) );
QCOMPARE( components.value( QStringLiteral( "authcfg" ) ).toString(), QString( "1234567" ) );
}

void TestQgsGdalProvider::encodeUri()
Expand All @@ -136,6 +142,12 @@ void TestQgsGdalProvider::encodeUri()
parts.insert( QStringLiteral( "vsiPrefix" ), QStringLiteral( "/vsizip/" ) );
parts.insert( QStringLiteral( "vsiSuffix" ), QStringLiteral( "/my.tif" ) );
QCOMPARE( QgsProviderRegistry::instance()->encodeUri( QStringLiteral( "gdal" ), parts ), QStringLiteral( "/vsizip//home/user/test.zip/my.tif" ) );

// test authcfg with vsicurl
parts.clear();
parts.insert( QStringLiteral( "path" ), QStringLiteral( "/vsicurl/https://www.qgis.org/dataset.tif" ) );
parts.insert( QStringLiteral( "authcfg" ), QStringLiteral( "1234567" ) );
QCOMPARE( QgsProviderRegistry::instance()->encodeUri( QStringLiteral( "gdal" ), parts ), QStringLiteral( "/vsicurl/https://www.qgis.org/dataset.tif authcfg='1234567'" ) );
}

void TestQgsGdalProvider::scaleDataType()
Expand Down
16 changes: 14 additions & 2 deletions tests/src/core/testqgsogrprovider.cpp
Expand Up @@ -127,11 +127,12 @@ void TestQgsOgrProvider::setupProxy()
void TestQgsOgrProvider::decodeUri()
{
auto parts( QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "ogr" ), QStringLiteral( "MySQL:database_name,host=localhost,port=3306 authcfg='f8wwfx8'" ) ) );
QCOMPARE( parts.size(), 4 );
QCOMPARE( parts.size(), 5 );
QCOMPARE( parts.value( QStringLiteral( "databaseName" ) ).toString(), QString( "database_name" ) );
QVERIFY( parts.value( QStringLiteral( "layerName" ) ).toString().isEmpty() );
QVERIFY( !parts.value( QStringLiteral( "layerId" ) ).isValid() );
QCOMPARE( parts.value( QStringLiteral( "path" ) ).toString(), QString( "MySQL:database_name,host=localhost,port=3306 authcfg='f8wwfx8'" ) );
QCOMPARE( parts.value( QStringLiteral( "path" ) ).toString(), QString( "MySQL:database_name,host=localhost,port=3306" ) );
QCOMPARE( parts.value( QStringLiteral( "authcfg" ) ).toString(), QString( "f8wwfx8" ) );
QCOMPARE( QgsProviderRegistry::instance()->encodeUri( QStringLiteral( "ogr" ), parts ), QStringLiteral( "MySQL:database_name,host=localhost,port=3306 authcfg='f8wwfx8'" ) );

parts = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "ogr" ), QStringLiteral( "MYSQL:westholland,user=root,password=psv9570,port=3306,tables=bedrijven" ) );
Expand Down Expand Up @@ -233,6 +234,11 @@ void TestQgsOgrProvider::decodeUri()
parts = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "ogr" ), QStringLiteral( "/path/to/a/geopackage.gpkg|option:FOO=BAR|option:FOO2=BAR2" ) );
QCOMPARE( parts.value( QStringLiteral( "path" ) ).toString(), QString( "/path/to/a/geopackage.gpkg" ) );
QCOMPARE( parts.value( QStringLiteral( "openOptions" ) ).toStringList(), QStringList() << QStringLiteral( "FOO=BAR" ) << QStringLiteral( "FOO2=BAR2" ) );

// test authcfg with vsicurl URI
parts = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "ogr" ), QStringLiteral( "/vsicurl/https://www.qgis.org/dataset.gpkg authcfg='1234567'" ) );
QCOMPARE( parts.value( QStringLiteral( "path" ) ).toString(), QString( "/vsicurl/https://www.qgis.org/dataset.gpkg" ) );
QCOMPARE( parts.value( QStringLiteral( "authcfg" ) ).toString(), QString( "1234567" ) );
}

void TestQgsOgrProvider::encodeUri()
Expand Down Expand Up @@ -264,6 +270,12 @@ void TestQgsOgrProvider::encodeUri()
parts.insert( QStringLiteral( "path" ), QStringLiteral( "/home/user/test.gpkg" ) );
parts.insert( QStringLiteral( "openOptions" ), QStringList() << QStringLiteral( "FOO=BAR" ) << QStringLiteral( "FOO2=BAR2" ) );
QCOMPARE( QgsProviderRegistry::instance()->encodeUri( QStringLiteral( "ogr" ), parts ), QStringLiteral( "/home/user/test.gpkg|option:FOO=BAR|option:FOO2=BAR2" ) );

// test authcfg with vsicurl
parts.clear();
parts.insert( QStringLiteral( "path" ), QStringLiteral( "/vsicurl/https://www.qgis.org/dataset.gpkg" ) );
parts.insert( QStringLiteral( "authcfg" ), QStringLiteral( "1234567" ) );
QCOMPARE( QgsProviderRegistry::instance()->encodeUri( QStringLiteral( "ogr" ), parts ), QStringLiteral( "/vsicurl/https://www.qgis.org/dataset.gpkg authcfg='1234567'" ) );
}

class ReadVectorLayer : public QThread
Expand Down

0 comments on commit d052fdb

Please sign in to comment.