Skip to content
Permalink
Browse files

Add tests

  • Loading branch information
pblottiere committed Jul 27, 2017
1 parent 7b5b628 commit 399f01afb4352de6c561d02efaf3afb27ad6e11e
@@ -89,6 +89,7 @@ class GUI_EXPORT QgsValueRelationWidgetWrapper : public QgsEditorWidgetWrapper
bool mUpdating;

friend class QgsValueRelationWidgetFactory;
friend class TestQgsValueRelationWidgetWrapper;
};

Q_DECLARE_METATYPE( QgsValueRelationWidgetWrapper::ValueRelationCache )
@@ -144,4 +144,4 @@ ADD_QGIS_TEST(spinbox testqgsspinbox.cpp)
ADD_QGIS_TEST(sqlcomposerdialog testqgssqlcomposerdialog.cpp)
ADD_QGIS_TEST(filedownloader testqgsfiledownloader.cpp)
ADD_QGIS_TEST(composergui testqgscomposergui.cpp)

ADD_QGIS_TEST(valuerelationwidgetwrapper testqgsvaluerelationwidgetwrapper.cpp)
@@ -0,0 +1,107 @@
/***************************************************************************
testqgsvaluerelationwidgetwrapper.cpp
--------------------------------------
Date : 21 07 2017
Copyright : (C) 2017 Paul Blottiere
Email : paul dot blottiere at oslandia dot 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 <QtTest/QtTest>
#include <QScrollBar>

#include <editorwidgets/core/qgseditorwidgetregistry.h>
#include <qgsapplication.h>
#include <qgsproject.h>
#include <qgsvectorlayer.h>
#include "qgseditorwidgetwrapper.h"
#include <editorwidgets/qgsvaluerelationwidgetwrapper.h>

class TestQgsValueRelationWidgetWrapper : public QObject
{
Q_OBJECT
public:
TestQgsValueRelationWidgetWrapper() {}

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 testScrollBarUnlocked();
};

void TestQgsValueRelationWidgetWrapper::initTestCase()
{
QgsApplication::init();
QgsApplication::initQgis();
QgsEditorWidgetRegistry::initEditors();
}

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

void TestQgsValueRelationWidgetWrapper::init()
{
}

void TestQgsValueRelationWidgetWrapper::cleanup()
{
}

void TestQgsValueRelationWidgetWrapper::testScrollBarUnlocked()
{
// create a vector layer
QgsVectorLayer vl1( QString( "LineString?crs=epsg:3111&field=pk:int&field=fk|:int" ), QString( "vl1" ), QString( "memory" ) );

// build a value relation widget wrapper
QListWidget lw;
QWidget editor;
QgsValueRelationWidgetWrapper w( &vl1, 0, &editor, nullptr );
w.setEnabled( true );
w.initWidget( &lw );

// add an item virtually
QListWidgetItem item;
item.setText( "MyText" );
w.mListWidget->addItem( &item );
QCOMPARE( w.mListWidget->item( 0 )->text(), QString( "MyText" ) );

// when the widget wrapper is enabled, the container should be enabled
// as well as items
w.setEnabled( true );

QCOMPARE( w.widget()->isEnabled(), true );

bool itemEnabled = w.mListWidget->item( 0 )->flags() & Qt::ItemIsEnabled;
QCOMPARE( itemEnabled, true );

// when the widget wrapper is disabled, the container should still be enabled
// to keep the scrollbar available but items should be disabled to avoid
// edition
w.setEnabled( false );

itemEnabled = w.mListWidget->item( 0 )->flags() & Qt::ItemIsEnabled;
QCOMPARE( itemEnabled, false );

QCOMPARE( w.widget()->isEnabled(), true );

// recheck after re-enabled
w.setEnabled( true );

QCOMPARE( w.widget()->isEnabled(), true );
itemEnabled = w.mListWidget->item( 0 )->flags() & Qt::ItemIsEnabled;
QCOMPARE( itemEnabled, true );
}

QTEST_MAIN( TestQgsValueRelationWidgetWrapper )
#include "testqgsvaluerelationwidgetwrapper.moc"

0 comments on commit 399f01a

Please sign in to comment.
You can’t perform that action at this time.