Skip to content

Commit fbb4ef5

Browse files
committed
Add processing gui tests
1 parent ffb2817 commit fbb4ef5

File tree

2 files changed

+120
-1
lines changed

2 files changed

+120
-1
lines changed

tests/src/gui/CMakeLists.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,28 @@ SET (util_SRCS)
77
# the UI file won't be wrapped!
88
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
99
${CMAKE_SOURCE_DIR}/tests/core #for render checker class
10+
${CMAKE_SOURCE_DIR}/src/analysis/processing
1011
${CMAKE_SOURCE_DIR}/src/gui
1112
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets
1213
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets/core
1314
${CMAKE_SOURCE_DIR}/src/gui/layout
1415
${CMAKE_SOURCE_DIR}/src/gui/symbology
16+
${CMAKE_SOURCE_DIR}/src/gui/processing
1517
${CMAKE_SOURCE_DIR}/src/gui/raster
1618
${CMAKE_SOURCE_DIR}/src/core
1719
${CMAKE_SOURCE_DIR}/src/core/expression
1820
${CMAKE_SOURCE_DIR}/src/core/auth
1921
${CMAKE_SOURCE_DIR}/src/core/geometry
2022
${CMAKE_SOURCE_DIR}/src/core/layout
2123
${CMAKE_SOURCE_DIR}/src/core/metadata
24+
${CMAKE_SOURCE_DIR}/src/core/processing
2225
${CMAKE_SOURCE_DIR}/src/core/raster
2326
${CMAKE_SOURCE_DIR}/src/core/symbology
2427
${CMAKE_SOURCE_DIR}/src/core/fieldformatter
2528
${CMAKE_SOURCE_DIR}/src/test
2629
${CMAKE_SOURCE_DIR}/src/native
2730

28-
31+
${CMAKE_BINARY_DIR}/src/analysis
2932
${CMAKE_BINARY_DIR}/src/core
3033
${CMAKE_BINARY_DIR}/src/gui
3134
${CMAKE_BINARY_DIR}/src/ui
@@ -92,6 +95,7 @@ MACRO (ADD_QGIS_TEST testname testsrc)
9295
${GEOS_LIBRARY}
9396
${GDAL_LIBRARY}
9497
${QWT_LIBRARY}
98+
qgis_analysis
9599
qgis_core
96100
qgis_gui)
97101
ADD_TEST(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname} -maxwarnings 10000)
@@ -123,6 +127,7 @@ ADD_QGIS_TEST(focuswatcher testqgsfocuswatcher.cpp)
123127
ADD_QGIS_TEST(mapcanvastest testqgsmapcanvas.cpp)
124128
ADD_QGIS_TEST(projectionissues testprojectionissues.cpp)
125129
ADD_QGIS_TEST(qgsguitest testqgsgui.cpp)
130+
ADD_QGIS_TEST(processingguitest testprocessinggui.cpp)
126131
ADD_QGIS_TEST(rubberbandtest testqgsrubberband.cpp)
127132
ADD_QGIS_TEST(scalecombobox testqgsscalecombobox.cpp)
128133
ADD_QGIS_TEST(scalerangewidget testqgsscalerangewidget.cpp)

tests/src/gui/testprocessinggui.cpp

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/***************************************************************************
2+
testprocesinggui.cpp
3+
---------------------------
4+
begin : April 2018
5+
copyright : (C) 2018 by Matthias Kuhn
6+
email : matthias@opengis.ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include <QObject>
19+
#include "qgstest.h"
20+
#include "qgsgui.h"
21+
#include "qgsprocessingguiregistry.h"
22+
#include "qgsprocessingregistry.h"
23+
#include "qgsprocessingalgorithmconfigurationwidget.h"
24+
#include "qgsnativealgorithms.h"
25+
#include "qgsxmlutils.h"
26+
27+
class TestProcessingGui : public QObject
28+
{
29+
Q_OBJECT
30+
public:
31+
TestProcessingGui() = default;
32+
33+
private slots:
34+
void initTestCase();// will be called before the first testfunction is executed.
35+
void cleanupTestCase();// will be called after the last testfunction was executed.
36+
void init();// will be called before each testfunction is executed.
37+
void cleanup();// will be called after every testfunction.
38+
void testSetGetConfig();
39+
void testFilterAlgorithmConfig();
40+
};
41+
42+
void TestProcessingGui::initTestCase()
43+
{
44+
QgsApplication::init();
45+
QgsApplication::initQgis();
46+
QgsApplication::processingRegistry()->addProvider( new QgsNativeAlgorithms( QgsApplication::processingRegistry() ) );
47+
}
48+
49+
void TestProcessingGui::cleanupTestCase()
50+
{
51+
QgsApplication::exitQgis();
52+
}
53+
void TestProcessingGui::init()
54+
{
55+
56+
}
57+
58+
void TestProcessingGui::cleanup()
59+
{
60+
61+
}
62+
63+
void TestProcessingGui::testSetGetConfig()
64+
{
65+
const QList< const QgsProcessingAlgorithm * > algorithms = QgsApplication::instance()->processingRegistry()->algorithms();
66+
67+
// Find all defined widgets for native algorithms
68+
// and get the default configuration (that is, we create a widget
69+
// and get the configuration it returns without being modified in any way)
70+
// We then set and get this configuration and validate that it matches the original one.
71+
for ( const QgsProcessingAlgorithm *algorithm : algorithms )
72+
{
73+
std::unique_ptr<QgsProcessingAlgorithmConfigurationWidget> configWidget( QgsGui::instance()->processingGuiRegistry()->algorithmConfigurationWidget( algorithm ) );
74+
75+
if ( configWidget )
76+
{
77+
const QVariantMap defaultConfig = configWidget->configuration();
78+
configWidget->setConfiguration( defaultConfig );
79+
const QVariantMap defaultControlConfig = configWidget->configuration();
80+
QDomDocument defaultConfigDoc;
81+
QDomDocument defaultConfigControlDoc;
82+
QgsXmlUtils::writeVariant( defaultConfig, defaultConfigDoc );
83+
QgsXmlUtils::writeVariant( defaultControlConfig, defaultConfigControlDoc );
84+
QCOMPARE( defaultConfigDoc.toString(), defaultConfigControlDoc.toString() );
85+
}
86+
}
87+
}
88+
89+
void TestProcessingGui::testFilterAlgorithmConfig()
90+
{
91+
const QgsProcessingAlgorithm *algorithm = QgsApplication::instance()->processingRegistry()->algorithmById( QStringLiteral( "native:filter" ) );
92+
std::unique_ptr<QgsProcessingAlgorithmConfigurationWidget> configWidget( QgsGui::instance()->processingGuiRegistry()->algorithmConfigurationWidget( algorithm ) );
93+
94+
QVariantMap config;
95+
QVariantList outputs;
96+
QVariantMap output;
97+
output.insert( QStringLiteral( "name" ), QStringLiteral( "test" ) );
98+
output.insert( QStringLiteral( "expression" ), QStringLiteral( "I am an expression" ) );
99+
output.insert( QStringLiteral( "isModelOutput" ), true );
100+
outputs.append( output );
101+
config.insert( QStringLiteral( "outputs" ), outputs );
102+
configWidget->setConfiguration( config );
103+
104+
QVariantMap configControl = configWidget->configuration();
105+
106+
QDomDocument configDoc;
107+
QDomDocument configControlDoc;
108+
QgsXmlUtils::writeVariant( config, configDoc );
109+
QgsXmlUtils::writeVariant( configControl, configControlDoc );
110+
QCOMPARE( configDoc.toString(), configControlDoc.toString() );
111+
}
112+
113+
QGSTEST_MAIN( TestProcessingGui )
114+
#include "testprocessinggui.moc"

0 commit comments

Comments
 (0)