Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3077 from pvalsecc/legend_url
WMS: Better logic to pick the legend URL
- Loading branch information
Showing
7 changed files
with
405 additions
and
16 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
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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,70 @@ | |||
#include <QFile> | |||
#include <QObject> | |||
#include <QtTest/QtTest> | |||
#include <qgswmscapabilities.h> | |||
#include <qgsapplication.h> | |||
|
|||
/** \ingroup UnitTests | |||
* This is a unit test for the WMS capabilities parser. | |||
*/ | |||
class TestQgsWmsCapabilities: public QObject | |||
{ | |||
Q_OBJECT | |||
private slots: | |||
|
|||
void initTestCase() | |||
{ | |||
// init QGIS's paths - true means that all path will be inited from prefix | |||
QgsApplication::init(); | |||
QgsApplication::initQgis(); | |||
} | |||
|
|||
//runs after all tests | |||
void cleanupTestCase() | |||
{ | |||
QgsApplication::exitQgis(); | |||
} | |||
|
|||
|
|||
void read() | |||
{ | |||
QgsWmsCapabilities capabilities; | |||
|
|||
QFile file( QString( TEST_DATA_DIR ) + "/provider/GetCapabilities.xml" ); | |||
QVERIFY( file.open( QIODevice::ReadOnly | QIODevice::Text ) ); | |||
const QByteArray content = file.readAll(); | |||
QVERIFY( content.size() > 0 ); | |||
const QgsWmsParserSettings config; | |||
|
|||
QVERIFY( capabilities.parseResponse( content, config ) ); | |||
QCOMPARE( capabilities.supportedLayers().size(), 5 ); | |||
QCOMPARE( capabilities.supportedLayers()[0].name, QString( "agri_zones" ) ); | |||
QCOMPARE( capabilities.supportedLayers()[1].name, QString( "buildings" ) ); | |||
QCOMPARE( capabilities.supportedLayers()[2].name, QString( "land_surveing_parcels" ) ); | |||
QCOMPARE( capabilities.supportedLayers()[3].name, QString( "cadastre" ) ); | |||
QCOMPARE( capabilities.supportedLayers()[4].name, QString( "test" ) ); | |||
|
|||
// make sure the default style is not seen twice in the child layers | |||
QCOMPARE( capabilities.supportedLayers()[3].style.size(), 1 ); | |||
QCOMPARE( capabilities.supportedLayers()[3].style[0].name, QString( "default" ) ); | |||
QCOMPARE( capabilities.supportedLayers()[1].style.size(), 1 ); | |||
QCOMPARE( capabilities.supportedLayers()[1].style[0].name, QString( "default" ) ); | |||
QCOMPARE( capabilities.supportedLayers()[2].style.size(), 1 ); | |||
QCOMPARE( capabilities.supportedLayers()[2].style[0].name, QString( "default" ) ); | |||
|
|||
// check it can read 2 styles for a layer and that the legend URL is OK | |||
QCOMPARE( capabilities.supportedLayers()[0].style.size(), 2 ); | |||
QCOMPARE( capabilities.supportedLayers()[0].style[0].name, QString( "yt_style" ) ); | |||
QCOMPARE( capabilities.supportedLayers()[0].style[0].legendUrl.size(), 1 ); | |||
QCOMPARE( capabilities.supportedLayers()[0].style[0].legendUrl[0].onlineResource.xlinkHref, | |||
QString( "http://www.example.com/yt.png" ) ); | |||
QCOMPARE( capabilities.supportedLayers()[0].style[1].name, QString( "fb_style" ) ); | |||
QCOMPARE( capabilities.supportedLayers()[0].style[1].legendUrl.size(), 1 ); | |||
QCOMPARE( capabilities.supportedLayers()[0].style[1].legendUrl[0].onlineResource.xlinkHref, | |||
QString( "http://www.example.com/fb.png" ) ); | |||
} | |||
|
|||
}; | |||
|
|||
QTEST_MAIN( TestQgsWmsCapabilities ) | |||
#include "testqgswmscapabilities.moc" |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,69 @@ | |||
#include <QFile> | |||
#include <QObject> | |||
#include <QtTest/QtTest> | |||
#include <qgswmsprovider.h> | |||
#include <qgsapplication.h> | |||
|
|||
/** \ingroup UnitTests | |||
* This is a unit test for the WMS provider. | |||
*/ | |||
class TestQgsWmsProvider: public QObject | |||
{ | |||
Q_OBJECT | |||
private slots: | |||
|
|||
void initTestCase() | |||
{ | |||
// init QGIS's paths - true means that all path will be inited from prefix | |||
QgsApplication::init(); | |||
QgsApplication::initQgis(); | |||
|
|||
QFile file( QString( TEST_DATA_DIR ) + "/provider/GetCapabilities.xml" ); | |||
QVERIFY( file.open( QIODevice::ReadOnly | QIODevice::Text ) ); | |||
const QByteArray content = file.readAll(); | |||
QVERIFY( content.size() > 0 ); | |||
const QgsWmsParserSettings config; | |||
|
|||
mCapabilities = new QgsWmsCapabilities(); | |||
QVERIFY( mCapabilities->parseResponse( content, config ) ); | |||
} | |||
|
|||
//runs after all tests | |||
void cleanupTestCase() | |||
{ | |||
delete mCapabilities; | |||
QgsApplication::exitQgis(); | |||
} | |||
|
|||
void legendGraphicsWithStyle() | |||
{ | |||
QgsWmsProvider provider( "http://localhost:8380/mapserv?xxx&layers=agri_zones&styles=fb_style&format=image/jpg", mCapabilities ); | |||
QCOMPARE( provider.getLegendGraphicUrl(), QString( "http://www.example.com/fb.png?" ) ); | |||
} | |||
|
|||
void legendGraphicsWithSecondStyle() | |||
{ | |||
QgsWmsProvider provider( "http://localhost:8380/mapserv?xxx&layers=agri_zones&styles=yt_style&format=image/jpg", mCapabilities ); | |||
QCOMPARE( provider.getLegendGraphicUrl(), QString( "http://www.example.com/yt.png?" ) ); | |||
} | |||
|
|||
void legendGraphicsWithoutStyleWithDefault() | |||
{ | |||
QgsWmsProvider provider( "http://localhost:8380/mapserv?xxx&layers=buildings&styles=&format=image/jpg", mCapabilities ); | |||
//only one style, can guess default => use it | |||
QCOMPARE( provider.getLegendGraphicUrl(), QString( "http://www.example.com/buildings.png?" ) ); | |||
} | |||
|
|||
void legendGraphicsWithoutStyleWithoutDefault() | |||
{ | |||
QgsWmsProvider provider( "http://localhost:8380/mapserv?xxx&layers=agri_zones&styles=&format=image/jpg", mCapabilities ); | |||
//two style, cannot guess default => use the WMS GetLegendGraphics | |||
QCOMPARE( provider.getLegendGraphicUrl(), QString( "http://localhost:8380/mapserv?" ) ); | |||
} | |||
|
|||
private: | |||
QgsWmsCapabilities* mCapabilities; | |||
}; | |||
|
|||
QTEST_MAIN( TestQgsWmsProvider ) | |||
#include "testqgswmsprovider.moc" |
Oops, something went wrong.