|
| 1 | +/*************************************************************************** |
| 2 | + testqgswmsparameters.cpp |
| 3 | + -------------------------------------- |
| 4 | + Date : 20 Mar 2019 |
| 5 | + Copyright : (C) 2019 by Paul Blottiere |
| 6 | + Email : paul dot blottiere @ oslandia.com |
| 7 | + *************************************************************************** |
| 8 | + * * |
| 9 | + * This program is free software; you can redistribute it and/or modify * |
| 10 | + * it under the terms of the GNU General Public License as published by * |
| 11 | + * the Free Software Foundation; either version 2 of the License, or * |
| 12 | + * (at your option) any later version. * |
| 13 | + * * |
| 14 | + ***************************************************************************/ |
| 15 | + |
| 16 | +#include "qgstest.h" |
| 17 | +#include "qgsproject.h" |
| 18 | +#include "qgsvectorlayer.h" |
| 19 | +#include "qgsserverinterfaceimpl.h" |
| 20 | +#include "qgswmsparameters.h" |
| 21 | +#include "qgswmsrenderer.h" |
| 22 | + |
| 23 | +/** |
| 24 | + * \ingroup UnitTests |
| 25 | + * This is a unit test for the WMS parameters parsing |
| 26 | + */ |
| 27 | +class TestQgsServerWmsDxf : public QObject |
| 28 | +{ |
| 29 | + Q_OBJECT |
| 30 | + |
| 31 | + private slots: |
| 32 | + void initTestCase(); |
| 33 | + void cleanupTestCase(); |
| 34 | + |
| 35 | + void use_title_as_layername_true(); |
| 36 | + void use_title_as_layername_false(); |
| 37 | +}; |
| 38 | + |
| 39 | +void TestQgsServerWmsDxf::initTestCase() |
| 40 | +{ |
| 41 | + QgsApplication::init(); |
| 42 | + QgsApplication::initQgis(); |
| 43 | +} |
| 44 | + |
| 45 | +void TestQgsServerWmsDxf::cleanupTestCase() |
| 46 | +{ |
| 47 | + QgsApplication::exitQgis(); |
| 48 | +} |
| 49 | + |
| 50 | +void TestQgsServerWmsDxf::use_title_as_layername_true() |
| 51 | +{ |
| 52 | + const QString key = "FORMAT_OPTIONS"; |
| 53 | + const QString value = "MODE:SYMBOLLAYERSYMBOLOGY;SCALE:250;USE_TITLE_AS_LAYERNAME:FALSE;LAYERATTRIBUTES:name;CODEC:my_codec_name"; |
| 54 | + |
| 55 | + QUrlQuery query; |
| 56 | + query.addQueryItem( key, value ); |
| 57 | + query.addQueryItem( "LAYERS", "testlayer èé" ); |
| 58 | + |
| 59 | + QgsWms::QgsWmsParameters parameters( query ); |
| 60 | + |
| 61 | + QCOMPARE( int( parameters.dxfScale() ), 250 ); |
| 62 | + QCOMPARE( parameters.dxfCodec(), QString( "my_codec_name" ) ); |
| 63 | + QCOMPARE( parameters.dxfUseLayerTitleAsName(), false ); |
| 64 | + QCOMPARE( parameters.dxfMode(), QgsDxfExport::SymbolLayerSymbology ); |
| 65 | + QCOMPARE( int( parameters.dxfLayerAttributes().size() ), 1 ); |
| 66 | + QCOMPARE( parameters.dxfLayerAttributes()[0], QString( "name" ) ); |
| 67 | + |
| 68 | + const QString filename = QString( "%1/qgis_server/test_project.qgs" ).arg( TEST_DATA_DIR ); |
| 69 | + QgsProject project; |
| 70 | + project.read( filename ); |
| 71 | + |
| 72 | + QgsMapLayer *layer = project.layerStore()->mapLayersByName( "testlayer èé" )[0]; |
| 73 | + QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer ); |
| 74 | + |
| 75 | + QgsCapabilitiesCache cache; |
| 76 | + QgsServiceRegistry registry; |
| 77 | + QgsServerSettings settings; |
| 78 | + QgsServerInterfaceImpl interface( &cache, ®istry, &settings ); |
| 79 | + QgsWms::QgsRenderer renderer( &interface, &project, parameters ); |
| 80 | + |
| 81 | + QgsDxfExport exporter = renderer.getDxf(); |
| 82 | + const QString name = exporter.layerName( vl ); |
| 83 | + QCOMPARE( exporter.layerName( vl ), QString( "testlayer \u00E8\u00E9" ) ); |
| 84 | + |
| 85 | + const QgsFeature ft = vl->getFeature( 1 ); |
| 86 | + QCOMPARE( exporter.layerName( vl->id(), ft ), QString( "two" ) ); |
| 87 | +} |
| 88 | + |
| 89 | +void TestQgsServerWmsDxf::use_title_as_layername_false() |
| 90 | +{ |
| 91 | + const QString key = "FORMAT_OPTIONS"; |
| 92 | + const QString value = "MODE:SYMBOLLAYERSYMBOLOGY;SCALE:250;USE_TITLE_AS_LAYERNAME:TRUE;LAYERATTRIBUTES:pif,paf,pouf;CODEC:my_codec_name"; |
| 93 | + |
| 94 | + QUrlQuery query; |
| 95 | + query.addQueryItem( key, value ); |
| 96 | + query.addQueryItem( "LAYERS", "testlayer èé" ); |
| 97 | + |
| 98 | + QgsWms::QgsWmsParameters parameters( query ); |
| 99 | + |
| 100 | + QCOMPARE( int( parameters.dxfScale() ), 250 ); |
| 101 | + QCOMPARE( parameters.dxfCodec(), QString( "my_codec_name" ) ); |
| 102 | + QCOMPARE( parameters.dxfUseLayerTitleAsName(), true ); |
| 103 | + QCOMPARE( parameters.dxfMode(), QgsDxfExport::SymbolLayerSymbology ); |
| 104 | + QCOMPARE( int( parameters.dxfLayerAttributes().size() ), 3 ); |
| 105 | + QCOMPARE( parameters.dxfLayerAttributes()[0], QString( "pif" ) ); |
| 106 | + QCOMPARE( parameters.dxfLayerAttributes()[1], QString( "paf" ) ); |
| 107 | + QCOMPARE( parameters.dxfLayerAttributes()[2], QString( "pouf" ) ); |
| 108 | + |
| 109 | + const QString filename = QString( "%1/qgis_server/test_project.qgs" ).arg( TEST_DATA_DIR ); |
| 110 | + QgsProject project; |
| 111 | + project.read( filename ); |
| 112 | + |
| 113 | + QgsMapLayer *layer = project.layerStore()->mapLayersByName( "testlayer èé" )[0]; |
| 114 | + QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer ); |
| 115 | + |
| 116 | + QgsCapabilitiesCache cache; |
| 117 | + QgsServiceRegistry registry; |
| 118 | + QgsServerSettings settings; |
| 119 | + QgsServerInterfaceImpl interface( &cache, ®istry, &settings ); |
| 120 | + QgsWms::QgsRenderer renderer( &interface, &project, parameters ); |
| 121 | + |
| 122 | + QgsDxfExport exporter = renderer.getDxf(); |
| 123 | + const QString name = exporter.layerName( vl ); |
| 124 | + QCOMPARE( exporter.layerName( vl ), QString( "A test vector layer" ) ); |
| 125 | + |
| 126 | + const QgsFeature ft = vl->getFeature( 1 ); |
| 127 | + QCOMPARE( exporter.layerName( vl->id(), ft ), QString( "A test vector layer" ) ); |
| 128 | +} |
| 129 | + |
| 130 | +QGSTEST_MAIN( TestQgsServerWmsDxf ) |
| 131 | +#include "test_qgsserver_wms_dxf.moc" |
0 commit comments