Skip to content

Commit cdfca0a

Browse files
committedJul 21, 2017
Add tests
1 parent e6eeacf commit cdfca0a

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed
 

‎src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class GUI_EXPORT QgsValueRelationWidgetWrapper : public QgsEditorWidgetWrapper
8080
bool mUpdating;
8181

8282
friend class QgsValueRelationWidgetFactory;
83+
friend class TestQgsValueRelationWidgetWrapper;
8384
};
8485

8586
#endif // QGSVALUERELATIONWIDGETWRAPPER_H

‎tests/src/gui/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
2222
${CMAKE_SOURCE_DIR}/src/core/metadata
2323
${CMAKE_SOURCE_DIR}/src/core/raster
2424
${CMAKE_SOURCE_DIR}/src/core/symbology-ng
25+
${CMAKE_SOURCE_DIR}/src/core/fieldformatter
2526
${CMAKE_SOURCE_DIR}/src/test
2627
${CMAKE_SOURCE_DIR}/src/native
2728

@@ -134,3 +135,4 @@ ADD_QGIS_TEST(listwidgettest testqgslistwidget.cpp)
134135
ADD_QGIS_TEST(filedownloader testqgsfiledownloader.cpp)
135136
ADD_QGIS_TEST(composergui testqgscomposergui.cpp)
136137
ADD_QGIS_TEST(layoutview testqgslayoutview.cpp)
138+
ADD_QGIS_TEST(valuerelationwidgetwrapper testqgsvaluerelationwidgetwrapper.cpp)
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/***************************************************************************
2+
testqgsvaluerelationwidgetwrapper.cpp
3+
--------------------------------------
4+
Date : 21 07 2017
5+
Copyright : (C) 2017 Paul Blottiere
6+
Email : paul dot blottiere at oslandia dot 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+
17+
#include "qgstest.h"
18+
#include <QScrollBar>
19+
20+
#include <editorwidgets/core/qgseditorwidgetregistry.h>
21+
#include <qgsapplication.h>
22+
#include <qgsproject.h>
23+
#include <qgsvectorlayer.h>
24+
#include "qgseditorwidgetwrapper.h"
25+
#include <editorwidgets/qgsvaluerelationwidgetwrapper.h>
26+
#include "qgsgui.h"
27+
28+
class TestQgsValueRelationWidgetWrapper : public QObject
29+
{
30+
Q_OBJECT
31+
public:
32+
TestQgsValueRelationWidgetWrapper() {}
33+
34+
private slots:
35+
void initTestCase(); // will be called before the first testfunction is executed.
36+
void cleanupTestCase(); // will be called after the last testfunction was executed.
37+
void init(); // will be called before each testfunction is executed.
38+
void cleanup(); // will be called after every testfunction.
39+
40+
void testScrollBarUnlocked();
41+
};
42+
43+
void TestQgsValueRelationWidgetWrapper::initTestCase()
44+
{
45+
QgsApplication::init();
46+
QgsApplication::initQgis();
47+
QgsGui::editorWidgetRegistry()->initEditors();
48+
}
49+
50+
void TestQgsValueRelationWidgetWrapper::cleanupTestCase()
51+
{
52+
QgsApplication::exitQgis();
53+
}
54+
55+
void TestQgsValueRelationWidgetWrapper::init()
56+
{
57+
}
58+
59+
void TestQgsValueRelationWidgetWrapper::cleanup()
60+
{
61+
}
62+
63+
void TestQgsValueRelationWidgetWrapper::testScrollBarUnlocked()
64+
{
65+
// create a vector layer
66+
QgsVectorLayer vl1( QStringLiteral( "LineString?crs=epsg:3111&field=pk:int&field=fk|:int" ), QStringLiteral( "vl1" ), QStringLiteral( "memory" ) );
67+
QgsProject::instance()->addMapLayer( &vl1, false, false );
68+
69+
// build a value relation widget wrapper
70+
QListWidget lw;
71+
QWidget editor;
72+
QgsValueRelationWidgetWrapper w( &vl1, 0, &editor, nullptr );
73+
w.setEnabled( true );
74+
w.initWidget( &lw );
75+
76+
// add an item virtually
77+
QListWidgetItem item;
78+
item.setText( "MyText" );
79+
w.mListWidget->addItem( &item );
80+
QCOMPARE( w.mListWidget->item( 0 )->text(), QString( "MyText" ) );
81+
82+
// when the widget wrapper is enabled, the container should be enabled
83+
// as well as items
84+
w.setEnabled( true );
85+
86+
QCOMPARE( w.widget()->isEnabled(), true );
87+
88+
bool itemEnabled = w.mListWidget->item( 0 )->flags() & Qt::ItemIsEnabled;
89+
QCOMPARE( itemEnabled, true );
90+
91+
// when the widget wrapper is disabled, the container should still be enabled
92+
// to keep the scrollbar available but items should be disabled to avoid
93+
// edition
94+
w.setEnabled( false );
95+
96+
itemEnabled = w.mListWidget->item( 0 )->flags() & Qt::ItemIsEnabled;
97+
QCOMPARE( itemEnabled, false );
98+
99+
QCOMPARE( w.widget()->isEnabled(), true );
100+
101+
// recheck after re-enabled
102+
w.setEnabled( true );
103+
104+
QCOMPARE( w.widget()->isEnabled(), true );
105+
itemEnabled = w.mListWidget->item( 0 )->flags() & Qt::ItemIsEnabled;
106+
QCOMPARE( itemEnabled, true );
107+
}
108+
109+
QGSTEST_MAIN( TestQgsValueRelationWidgetWrapper )
110+
#include "testqgsvaluerelationwidgetwrapper.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.