Skip to content

Commit

Permalink
tests for focus on null field
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Nov 14, 2018
1 parent f96078d commit c8fc7a2
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/src/gui/testqgsrangewidgetwrapper.cpp
Expand Up @@ -51,6 +51,7 @@ class TestQgsRangeWidgetWrapper : public QObject
void test_setDoubleSmallerRange();
void test_setDoubleLimits();
void test_nulls();
void test_focus();

private:
std::unique_ptr<QgsRangeWidgetWrapper> widget0; // For field 0
Expand Down Expand Up @@ -328,7 +329,64 @@ void TestQgsRangeWidgetWrapper::test_nulls()

}

void TestQgsRangeWidgetWrapper::test_focus()
{
QgsApplication::setNullRepresentation( QString( "nope" ) );

QWidget *w = new QWidget(); //required for focus events
QApplication::setActiveWindow( w );

QVariantMap cfg;
cfg.insert( QStringLiteral( "AllowNull" ), true );

widget1->setConfig( cfg );
QgsDoubleSpinBox *editor1 = qobject_cast<QgsDoubleSpinBox *>( widget1->createWidget( w ) );
QVERIFY( editor1 );
widget1->initWidget( editor1 );

widget2->setConfig( cfg );
QgsDoubleSpinBox *editor2 = qobject_cast<QgsDoubleSpinBox *>( widget2->createWidget( w ) );
QVERIFY( editor2 );
widget2->initWidget( editor2 );

editor1->mLineEdit->setNullValue( QgsApplication::nullRepresentation() );
editor2->mLineEdit->setNullValue( QgsApplication::nullRepresentation() );

QVERIFY( editor1->mLineEdit->isNull() );
QVERIFY( editor2->mLineEdit->isNull() );
QVERIFY( !editor1->mLineEdit->hasFocus() );
QVERIFY( !editor2->mLineEdit->hasFocus() );
QCOMPARE( editor1->mLineEdit->text(), QStringLiteral( "nope" ) );
QCOMPARE( editor2->mLineEdit->text(), QStringLiteral( "nope" ) );

editor1->mLineEdit->setFocus();
QVERIFY( editor1->mLineEdit->hasFocus() );
QVERIFY( !editor2->mLineEdit->hasFocus() );
QCOMPARE( editor1->mLineEdit->text(), QStringLiteral( "" ) );
QCOMPARE( editor2->mLineEdit->text(), QStringLiteral( "nope" ) );

editor2->mLineEdit->setFocus();
QVERIFY( !editor1->mLineEdit->hasFocus() );
QVERIFY( editor2->mLineEdit->hasFocus() );
QCOMPARE( editor1->mLineEdit->text(), QStringLiteral( "nope" ) );
QCOMPARE( editor2->mLineEdit->text(), QStringLiteral( "" ) );

editor1->mLineEdit->setFocus();
editor1->mLineEdit->setText( QString( "151.000000000" ) );
QVERIFY( !editor1->mLineEdit->isNull() );
QVERIFY( editor2->mLineEdit->isNull() );
QVERIFY( editor1->mLineEdit->hasFocus() );
QVERIFY( !editor2->mLineEdit->hasFocus() );
QCOMPARE( editor1->mLineEdit->text(), QStringLiteral( "151.000000000" ) );
QCOMPARE( editor2->mLineEdit->text(), QStringLiteral( "nope" ) );

editor2->mLineEdit->setFocus();
QVERIFY( !editor1->mLineEdit->hasFocus() );
QVERIFY( editor2->mLineEdit->hasFocus() );
QCOMPARE( editor1->mLineEdit->text(), QStringLiteral( "151.000000000" ) );
QCOMPARE( editor2->mLineEdit->text(), QStringLiteral( "" ) );

}

QGSTEST_MAIN( TestQgsRangeWidgetWrapper )
#include "testqgsrangewidgetwrapper.moc"

0 comments on commit c8fc7a2

Please sign in to comment.