Skip to content

Commit 399f01a

Browse files
committedJul 27, 2017
Add tests
1 parent 7b5b628 commit 399f01a

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed
 

‎src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.h

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

9191
friend class QgsValueRelationWidgetFactory;
92+
friend class TestQgsValueRelationWidgetWrapper;
9293
};
9394

9495
Q_DECLARE_METATYPE( QgsValueRelationWidgetWrapper::ValueRelationCache )

‎tests/src/gui/CMakeLists.txt

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

0 commit comments

Comments
 (0)
Please sign in to comment.