Skip to content

Commit

Permalink
Add processing gui tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Apr 10, 2018
1 parent ffb2817 commit fbb4ef5
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/src/gui/CMakeLists.txt
Expand Up @@ -7,25 +7,28 @@ SET (util_SRCS)
# the UI file won't be wrapped!
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/tests/core #for render checker class
${CMAKE_SOURCE_DIR}/src/analysis/processing
${CMAKE_SOURCE_DIR}/src/gui
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets/core
${CMAKE_SOURCE_DIR}/src/gui/layout
${CMAKE_SOURCE_DIR}/src/gui/symbology
${CMAKE_SOURCE_DIR}/src/gui/processing
${CMAKE_SOURCE_DIR}/src/gui/raster
${CMAKE_SOURCE_DIR}/src/core
${CMAKE_SOURCE_DIR}/src/core/expression
${CMAKE_SOURCE_DIR}/src/core/auth
${CMAKE_SOURCE_DIR}/src/core/geometry
${CMAKE_SOURCE_DIR}/src/core/layout
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/processing
${CMAKE_SOURCE_DIR}/src/core/raster
${CMAKE_SOURCE_DIR}/src/core/symbology
${CMAKE_SOURCE_DIR}/src/core/fieldformatter
${CMAKE_SOURCE_DIR}/src/test
${CMAKE_SOURCE_DIR}/src/native


${CMAKE_BINARY_DIR}/src/analysis
${CMAKE_BINARY_DIR}/src/core
${CMAKE_BINARY_DIR}/src/gui
${CMAKE_BINARY_DIR}/src/ui
Expand Down Expand Up @@ -92,6 +95,7 @@ MACRO (ADD_QGIS_TEST testname testsrc)
${GEOS_LIBRARY}
${GDAL_LIBRARY}
${QWT_LIBRARY}
qgis_analysis
qgis_core
qgis_gui)
ADD_TEST(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname} -maxwarnings 10000)
Expand Down Expand Up @@ -123,6 +127,7 @@ ADD_QGIS_TEST(focuswatcher testqgsfocuswatcher.cpp)
ADD_QGIS_TEST(mapcanvastest testqgsmapcanvas.cpp)
ADD_QGIS_TEST(projectionissues testprojectionissues.cpp)
ADD_QGIS_TEST(qgsguitest testqgsgui.cpp)
ADD_QGIS_TEST(processingguitest testprocessinggui.cpp)
ADD_QGIS_TEST(rubberbandtest testqgsrubberband.cpp)
ADD_QGIS_TEST(scalecombobox testqgsscalecombobox.cpp)
ADD_QGIS_TEST(scalerangewidget testqgsscalerangewidget.cpp)
Expand Down
114 changes: 114 additions & 0 deletions tests/src/gui/testprocessinggui.cpp
@@ -0,0 +1,114 @@
/***************************************************************************
testprocesinggui.cpp
---------------------------
begin : April 2018
copyright : (C) 2018 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************/

/***************************************************************************
* *
* 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 <QObject>
#include "qgstest.h"
#include "qgsgui.h"
#include "qgsprocessingguiregistry.h"
#include "qgsprocessingregistry.h"
#include "qgsprocessingalgorithmconfigurationwidget.h"
#include "qgsnativealgorithms.h"
#include "qgsxmlutils.h"

class TestProcessingGui : public QObject
{
Q_OBJECT
public:
TestProcessingGui() = default;

private slots:
void initTestCase();// will be called before the first testfunction is executed.
void cleanupTestCase();// will be called after the last testfunction was executed.
void init();// will be called before each testfunction is executed.
void cleanup();// will be called after every testfunction.
void testSetGetConfig();
void testFilterAlgorithmConfig();
};

void TestProcessingGui::initTestCase()
{
QgsApplication::init();
QgsApplication::initQgis();
QgsApplication::processingRegistry()->addProvider( new QgsNativeAlgorithms( QgsApplication::processingRegistry() ) );
}

void TestProcessingGui::cleanupTestCase()
{
QgsApplication::exitQgis();
}
void TestProcessingGui::init()
{

}

void TestProcessingGui::cleanup()
{

}

void TestProcessingGui::testSetGetConfig()
{
const QList< const QgsProcessingAlgorithm * > algorithms = QgsApplication::instance()->processingRegistry()->algorithms();

// Find all defined widgets for native algorithms
// and get the default configuration (that is, we create a widget
// and get the configuration it returns without being modified in any way)
// We then set and get this configuration and validate that it matches the original one.
for ( const QgsProcessingAlgorithm *algorithm : algorithms )
{
std::unique_ptr<QgsProcessingAlgorithmConfigurationWidget> configWidget( QgsGui::instance()->processingGuiRegistry()->algorithmConfigurationWidget( algorithm ) );

if ( configWidget )
{
const QVariantMap defaultConfig = configWidget->configuration();
configWidget->setConfiguration( defaultConfig );
const QVariantMap defaultControlConfig = configWidget->configuration();
QDomDocument defaultConfigDoc;
QDomDocument defaultConfigControlDoc;
QgsXmlUtils::writeVariant( defaultConfig, defaultConfigDoc );
QgsXmlUtils::writeVariant( defaultControlConfig, defaultConfigControlDoc );
QCOMPARE( defaultConfigDoc.toString(), defaultConfigControlDoc.toString() );
}
}
}

void TestProcessingGui::testFilterAlgorithmConfig()
{
const QgsProcessingAlgorithm *algorithm = QgsApplication::instance()->processingRegistry()->algorithmById( QStringLiteral( "native:filter" ) );
std::unique_ptr<QgsProcessingAlgorithmConfigurationWidget> configWidget( QgsGui::instance()->processingGuiRegistry()->algorithmConfigurationWidget( algorithm ) );

QVariantMap config;
QVariantList outputs;
QVariantMap output;
output.insert( QStringLiteral( "name" ), QStringLiteral( "test" ) );
output.insert( QStringLiteral( "expression" ), QStringLiteral( "I am an expression" ) );
output.insert( QStringLiteral( "isModelOutput" ), true );
outputs.append( output );
config.insert( QStringLiteral( "outputs" ), outputs );
configWidget->setConfiguration( config );

QVariantMap configControl = configWidget->configuration();

QDomDocument configDoc;
QDomDocument configControlDoc;
QgsXmlUtils::writeVariant( config, configDoc );
QgsXmlUtils::writeVariant( configControl, configControlDoc );
QCOMPARE( configDoc.toString(), configControlDoc.toString() );
}

QGSTEST_MAIN( TestProcessingGui )
#include "testprocessinggui.moc"

0 comments on commit fbb4ef5

Please sign in to comment.