Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Mar 28, 2019
1 parent 60b308e commit c5817cb
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/src/server/wms/CMakeLists.txt
Expand Up @@ -37,13 +37,19 @@ SET(MODULE_WMS_SRCS
${CMAKE_SOURCE_DIR}/src/server/services/wms/qgswmsrendercontext.cpp
)

SET(MODULE_WMS_HDRS
${CMAKE_SOURCE_DIR}/src/server/services/wms/qgswmsserviceexception.h
)

QT5_WRAP_CPP(MODULE_WMS_MOC_SRCS ${MODULE_WMS_HDRS})

MACRO (ADD_QGIS_TEST TESTSRC)
SET (TESTNAME ${TESTSRC})
STRING(REPLACE "test" "" TESTNAME ${TESTNAME})
STRING(REPLACE "qgs" "" TESTNAME ${TESTNAME})
STRING(REPLACE ".cpp" "" TESTNAME ${TESTNAME})
SET (TESTNAME "qgis_${TESTNAME}test")
ADD_EXECUTABLE(${TESTNAME} ${TESTSRC} ${MODULE_WMS_SRCS})
ADD_EXECUTABLE(${TESTNAME} ${TESTSRC} ${MODULE_WMS_SRCS} ${MODULE_WMS_MOC_SRCS})
SET_TARGET_PROPERTIES(${TESTNAME} PROPERTIES AUTOMOC TRUE)
TARGET_LINK_LIBRARIES(${TESTNAME}
${Qt5Core_LIBRARIES}
Expand All @@ -64,6 +70,7 @@ ENDMACRO (ADD_QGIS_TEST)

SET(TESTS
test_qgsserver_wms_dxf.cpp
test_qgsserver_wms_exceptions.cpp
)

FOREACH(TESTSRC ${TESTS})
Expand Down
57 changes: 57 additions & 0 deletions tests/src/server/wms/test_qgsserver_wms_exceptions.cpp
@@ -0,0 +1,57 @@
/***************************************************************************
test_qgsserver_wms_exceptions.cpp
---------------------------------
Date : 27 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 "qgswmsserviceexception.h"

/**
* \ingroup UnitTests
* This is a unit test for the WMS Exceptions
*/
class TestQgsServerWmsExceptions : public QObject
{
Q_OBJECT

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

void exception_code();
};

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

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

void TestQgsServerWmsExceptions::exception_code()
{
QgsWms::QgsServiceException::ExceptionCode code = QgsWms::QgsServiceException::OGC_INVALID_FORMAT;
QgsWms::QgsServiceException exception0( code, QString(), 400 );
QCOMPARE( exception0.code(), QString( "InvalidFormat" ) );

code = QgsWms::QgsServiceException::QGIS_ERROR;
QgsWms::QgsServiceException exception1( code, QString(), 400 );
QCOMPARE( exception1.code(), QString( "Error" ) );
}

QGSTEST_MAIN( TestQgsServerWmsExceptions )
#include "test_qgsserver_wms_exceptions.moc"

0 comments on commit c5817cb

Please sign in to comment.