Skip to content

Commit 240f1fe

Browse files
committed
Add cpp test for server modules
1 parent aac6ecc commit 240f1fe

File tree

4 files changed

+129
-0
lines changed

4 files changed

+129
-0
lines changed

tests/src/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,7 @@ IF (ENABLE_TESTS)
5050
IF (WITH_QUICK)
5151
ADD_SUBDIRECTORY(quickgui)
5252
ENDIF (WITH_QUICK)
53+
IF (WITH_SERVER)
54+
ADD_SUBDIRECTORY(server)
55+
ENDIF (WITH_SERVER)
5356
ENDIF (ENABLE_TESTS)

tests/src/server/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ADD_SUBDIRECTORY(wms)

tests/src/server/wms/CMakeLists.txt

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#####################################################
2+
# Don't forget to include output directory, otherwise
3+
# the UI file won't be wrapped!
4+
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
5+
${CMAKE_CURRENT_BINARY_DIR}
6+
${CMAKE_SOURCE_DIR}/src/core
7+
${CMAKE_SOURCE_DIR}/src/core/geometry
8+
${CMAKE_SOURCE_DIR}/src/core/expression
9+
${CMAKE_SOURCE_DIR}/src/core/dxf
10+
${CMAKE_SOURCE_DIR}/src/core/symbology
11+
${CMAKE_SOURCE_DIR}/src/core/metadata
12+
${CMAKE_BINARY_DIR}/src/core
13+
${CMAKE_SOURCE_DIR}/src/test
14+
${CMAKE_SOURCE_DIR}/src/server
15+
${CMAKE_BINARY_DIR}/src/server
16+
${CMAKE_SOURCE_DIR}/src/server/services/wms
17+
)
18+
19+
#note for tests we should not include the moc of our
20+
#qtests in the executable file list as the moc is
21+
#directly included in the sources
22+
#and should not be compiled twice. Trying to include
23+
#them in will cause an error at build time
24+
25+
#No relinking and full RPATH for the install tree
26+
#See: http://www.cmake.org/Wiki/CMake_RPATH_handling#No_relinking_and_full_RPATH_for_the_install_tree
27+
SET(MODULE_WMS_SRCS
28+
${CMAKE_SOURCE_DIR}/src/server/services/wms/qgswmsparameters.cpp)
29+
30+
MACRO (ADD_QGIS_TEST TESTSRC)
31+
SET (TESTNAME ${TESTSRC})
32+
STRING(REPLACE "test" "" TESTNAME ${TESTNAME})
33+
STRING(REPLACE "qgs" "" TESTNAME ${TESTNAME})
34+
STRING(REPLACE ".cpp" "" TESTNAME ${TESTNAME})
35+
SET (TESTNAME "qgis_${TESTNAME}test")
36+
ADD_EXECUTABLE(${TESTNAME} ${TESTSRC} ${MODULE_WMS_SRCS})
37+
SET_TARGET_PROPERTIES(${TESTNAME} PROPERTIES AUTOMOC TRUE)
38+
TARGET_LINK_LIBRARIES(${TESTNAME}
39+
${Qt5Core_LIBRARIES}
40+
${Qt5Xml_LIBRARIES}
41+
${Qt5Svg_LIBRARIES}
42+
${Qt5Test_LIBRARIES}
43+
${PROJ_LIBRARY}
44+
${GEOS_LIBRARY}
45+
${GDAL_LIBRARY}
46+
qgis_core
47+
qgis_server
48+
)
49+
ADD_TEST(${TESTNAME} ${CMAKE_BINARY_DIR}/output/bin/${TESTNAME} -maxwarnings 10000)
50+
ENDMACRO (ADD_QGIS_TEST)
51+
52+
#############################################################
53+
# Tests:
54+
55+
SET(TESTS
56+
testqgswmsparameters.cpp
57+
)
58+
59+
FOREACH(TESTSRC ${TESTS})
60+
ADD_QGIS_TEST(${TESTSRC})
61+
ENDFOREACH(TESTSRC)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
18+
#include "qgswmsparameters.h"
19+
20+
/**
21+
* \ingroup UnitTests
22+
* This is a unit test for the WMS parameters parsing
23+
*/
24+
class TestQgsWmsParameters : public QObject
25+
{
26+
Q_OBJECT
27+
28+
private slots:
29+
void initTestCase();
30+
void cleanupTestCase();
31+
32+
// fake
33+
void dxfOptions();
34+
};
35+
36+
void TestQgsWmsParameters::initTestCase()
37+
{
38+
}
39+
40+
void TestQgsWmsParameters::cleanupTestCase()
41+
{
42+
}
43+
44+
void TestQgsWmsParameters::dxfOptions()
45+
{
46+
const QString key = "FORMAT_OPTIONS";
47+
const QString value = "MODE:SYMBOLLAYERSYMBOLOGY;SCALE:250;USE_TITLE_AS_LAYERNAME:TRUE;LAYERATTRIBUTES:pif,paf,pouf";
48+
49+
QUrlQuery query;
50+
query.addQueryItem( key, value );
51+
52+
QgsWms::QgsWmsParameters parameters( query );
53+
54+
QCOMPARE( parameters.dxfScale(), 250 );
55+
QCOMPARE( parameters.dxfUseLayerTitleAsName(), true );
56+
QCOMPARE( parameters.dxfMode(), QgsDxfExport::SymbolLayerSymbology );
57+
QCOMPARE( parameters.dxfLayerAttributes().size(), 3 );
58+
QCOMPARE( parameters.dxfLayerAttributes()[0], "pif" );
59+
QCOMPARE( parameters.dxfLayerAttributes()[1], "paf" );
60+
QCOMPARE( parameters.dxfLayerAttributes()[2], "pouf" );
61+
}
62+
63+
QGSTEST_MAIN( TestQgsWmsParameters )
64+
#include "testqgswmsparameters.moc"

0 commit comments

Comments
 (0)