Skip to content
Permalink
Browse files

Add getDxf test

  • Loading branch information
pblottiere committed Mar 21, 2019
1 parent 240f1fe commit 5704f70d94b35dc60c32f7e9d10330672a41ebbb
@@ -32,7 +32,7 @@
* \brief Interfaces exposed by QGIS Server and made available to plugins.
* \since QGIS 2.8
*/
class QgsServerInterfaceImpl : public QgsServerInterface
class SERVER_EXPORT QgsServerInterfaceImpl : public QgsServerInterface
{
public:

@@ -42,6 +42,7 @@ class QgsAccessControl;
class QgsDxfExport;
class QgsLayerTreeModel;
class QgsLayerTree;
class QgsServerInterface;

class QImage;
class QPaintDevice;
@@ -9,10 +9,15 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/core/dxf
${CMAKE_SOURCE_DIR}/src/core/symbology
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/layertree
${CMAKE_SOURCE_DIR}/src/core/raster
${CMAKE_SOURCE_DIR}/src/core/annotations
${CMAKE_SOURCE_DIR}/src/core/layout
${CMAKE_BINARY_DIR}/src/core
${CMAKE_SOURCE_DIR}/src/test
${CMAKE_SOURCE_DIR}/src/server
${CMAKE_BINARY_DIR}/src/server
${CMAKE_SOURCE_DIR}/src/server/services
${CMAKE_SOURCE_DIR}/src/server/services/wms
)

@@ -25,7 +30,11 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
#No relinking and full RPATH for the install tree
#See: http://www.cmake.org/Wiki/CMake_RPATH_handling#No_relinking_and_full_RPATH_for_the_install_tree
SET(MODULE_WMS_SRCS
${CMAKE_SOURCE_DIR}/src/server/services/wms/qgswmsparameters.cpp)
${CMAKE_SOURCE_DIR}/src/server/services/wms/qgswmsrenderer.cpp
${CMAKE_SOURCE_DIR}/src/server/services/wms/qgslayerrestorer.cpp
${CMAKE_SOURCE_DIR}/src/server/services/wms/qgsmaprendererjobproxy.cpp
${CMAKE_SOURCE_DIR}/src/server/services/wms/qgswmsparameters.cpp
)

MACRO (ADD_QGIS_TEST TESTSRC)
SET (TESTNAME ${TESTSRC})
@@ -45,15 +54,15 @@ MACRO (ADD_QGIS_TEST TESTSRC)
${GDAL_LIBRARY}
qgis_core
qgis_server
)
)
ADD_TEST(${TESTNAME} ${CMAKE_BINARY_DIR}/output/bin/${TESTNAME} -maxwarnings 10000)
ENDMACRO (ADD_QGIS_TEST)

#############################################################
# Tests:

SET(TESTS
testqgswmsparameters.cpp
test_qgsserver_wms_dxf.cpp
)

FOREACH(TESTSRC ${TESTS})
@@ -0,0 +1,131 @@
/***************************************************************************
testqgswmsparameters.cpp
--------------------------------------
Date : 20 Mar 2019
Copyright : (C) 2019 by Paul Blottiere
Email : paul dot blottiere @ oslandia.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 "qgstest.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgsserverinterfaceimpl.h"
#include "qgswmsparameters.h"
#include "qgswmsrenderer.h"

/**
* \ingroup UnitTests
* This is a unit test for the WMS parameters parsing
*/
class TestQgsServerWmsDxf : public QObject
{
Q_OBJECT

private slots:
void initTestCase();
void cleanupTestCase();

void use_title_as_layername_true();
void use_title_as_layername_false();
};

void TestQgsServerWmsDxf::initTestCase()
{
QgsApplication::init();
QgsApplication::initQgis();
}

void TestQgsServerWmsDxf::cleanupTestCase()
{
QgsApplication::exitQgis();
}

void TestQgsServerWmsDxf::use_title_as_layername_true()
{
const QString key = "FORMAT_OPTIONS";
const QString value = "MODE:SYMBOLLAYERSYMBOLOGY;SCALE:250;USE_TITLE_AS_LAYERNAME:FALSE;LAYERATTRIBUTES:name;CODEC:my_codec_name";

QUrlQuery query;
query.addQueryItem( key, value );
query.addQueryItem( "LAYERS", "testlayer èé" );

QgsWms::QgsWmsParameters parameters( query );

QCOMPARE( int( parameters.dxfScale() ), 250 );
QCOMPARE( parameters.dxfCodec(), QString( "my_codec_name" ) );
QCOMPARE( parameters.dxfUseLayerTitleAsName(), false );
QCOMPARE( parameters.dxfMode(), QgsDxfExport::SymbolLayerSymbology );
QCOMPARE( int( parameters.dxfLayerAttributes().size() ), 1 );
QCOMPARE( parameters.dxfLayerAttributes()[0], QString( "name" ) );

const QString filename = QString( "%1/qgis_server/test_project.qgs" ).arg( TEST_DATA_DIR );
QgsProject project;
project.read( filename );

QgsMapLayer *layer = project.layerStore()->mapLayersByName( "testlayer èé" )[0];
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );

QgsCapabilitiesCache cache;
QgsServiceRegistry registry;
QgsServerSettings settings;
QgsServerInterfaceImpl interface( &cache, &registry, &settings );
QgsWms::QgsRenderer renderer( &interface, &project, parameters );

QgsDxfExport exporter = renderer.getDxf();
const QString name = exporter.layerName( vl );
QCOMPARE( exporter.layerName( vl ), QString( "testlayer \u00E8\u00E9" ) );

const QgsFeature ft = vl->getFeature( 1 );
QCOMPARE( exporter.layerName( vl->id(), ft ), QString( "two" ) );
}

void TestQgsServerWmsDxf::use_title_as_layername_false()
{
const QString key = "FORMAT_OPTIONS";
const QString value = "MODE:SYMBOLLAYERSYMBOLOGY;SCALE:250;USE_TITLE_AS_LAYERNAME:TRUE;LAYERATTRIBUTES:pif,paf,pouf;CODEC:my_codec_name";

QUrlQuery query;
query.addQueryItem( key, value );
query.addQueryItem( "LAYERS", "testlayer èé" );

QgsWms::QgsWmsParameters parameters( query );

QCOMPARE( int( parameters.dxfScale() ), 250 );
QCOMPARE( parameters.dxfCodec(), QString( "my_codec_name" ) );
QCOMPARE( parameters.dxfUseLayerTitleAsName(), true );
QCOMPARE( parameters.dxfMode(), QgsDxfExport::SymbolLayerSymbology );
QCOMPARE( int( parameters.dxfLayerAttributes().size() ), 3 );
QCOMPARE( parameters.dxfLayerAttributes()[0], QString( "pif" ) );
QCOMPARE( parameters.dxfLayerAttributes()[1], QString( "paf" ) );
QCOMPARE( parameters.dxfLayerAttributes()[2], QString( "pouf" ) );

const QString filename = QString( "%1/qgis_server/test_project.qgs" ).arg( TEST_DATA_DIR );
QgsProject project;
project.read( filename );

QgsMapLayer *layer = project.layerStore()->mapLayersByName( "testlayer èé" )[0];
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );

QgsCapabilitiesCache cache;
QgsServiceRegistry registry;
QgsServerSettings settings;
QgsServerInterfaceImpl interface( &cache, &registry, &settings );
QgsWms::QgsRenderer renderer( &interface, &project, parameters );

QgsDxfExport exporter = renderer.getDxf();
const QString name = exporter.layerName( vl );
QCOMPARE( exporter.layerName( vl ), QString( "A test vector layer" ) );

const QgsFeature ft = vl->getFeature( 1 );
QCOMPARE( exporter.layerName( vl->id(), ft ), QString( "A test vector layer" ) );
}

QGSTEST_MAIN( TestQgsServerWmsDxf )
#include "test_qgsserver_wms_dxf.moc"

This file was deleted.

0 comments on commit 5704f70

Please sign in to comment.
You can’t perform that action at this time.