Skip to content

Commit c8fc7a2

Browse files
committedNov 14, 2018
tests for focus on null field
1 parent f96078d commit c8fc7a2

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
 

‎tests/src/gui/testqgsrangewidgetwrapper.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class TestQgsRangeWidgetWrapper : public QObject
5151
void test_setDoubleSmallerRange();
5252
void test_setDoubleLimits();
5353
void test_nulls();
54+
void test_focus();
5455

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

329330
}
330331

332+
void TestQgsRangeWidgetWrapper::test_focus()
333+
{
334+
QgsApplication::setNullRepresentation( QString( "nope" ) );
335+
336+
QWidget *w = new QWidget(); //required for focus events
337+
QApplication::setActiveWindow( w );
338+
339+
QVariantMap cfg;
340+
cfg.insert( QStringLiteral( "AllowNull" ), true );
341+
342+
widget1->setConfig( cfg );
343+
QgsDoubleSpinBox *editor1 = qobject_cast<QgsDoubleSpinBox *>( widget1->createWidget( w ) );
344+
QVERIFY( editor1 );
345+
widget1->initWidget( editor1 );
331346

347+
widget2->setConfig( cfg );
348+
QgsDoubleSpinBox *editor2 = qobject_cast<QgsDoubleSpinBox *>( widget2->createWidget( w ) );
349+
QVERIFY( editor2 );
350+
widget2->initWidget( editor2 );
351+
352+
editor1->mLineEdit->setNullValue( QgsApplication::nullRepresentation() );
353+
editor2->mLineEdit->setNullValue( QgsApplication::nullRepresentation() );
354+
355+
QVERIFY( editor1->mLineEdit->isNull() );
356+
QVERIFY( editor2->mLineEdit->isNull() );
357+
QVERIFY( !editor1->mLineEdit->hasFocus() );
358+
QVERIFY( !editor2->mLineEdit->hasFocus() );
359+
QCOMPARE( editor1->mLineEdit->text(), QStringLiteral( "nope" ) );
360+
QCOMPARE( editor2->mLineEdit->text(), QStringLiteral( "nope" ) );
361+
362+
editor1->mLineEdit->setFocus();
363+
QVERIFY( editor1->mLineEdit->hasFocus() );
364+
QVERIFY( !editor2->mLineEdit->hasFocus() );
365+
QCOMPARE( editor1->mLineEdit->text(), QStringLiteral( "" ) );
366+
QCOMPARE( editor2->mLineEdit->text(), QStringLiteral( "nope" ) );
367+
368+
editor2->mLineEdit->setFocus();
369+
QVERIFY( !editor1->mLineEdit->hasFocus() );
370+
QVERIFY( editor2->mLineEdit->hasFocus() );
371+
QCOMPARE( editor1->mLineEdit->text(), QStringLiteral( "nope" ) );
372+
QCOMPARE( editor2->mLineEdit->text(), QStringLiteral( "" ) );
373+
374+
editor1->mLineEdit->setFocus();
375+
editor1->mLineEdit->setText( QString( "151.000000000" ) );
376+
QVERIFY( !editor1->mLineEdit->isNull() );
377+
QVERIFY( editor2->mLineEdit->isNull() );
378+
QVERIFY( editor1->mLineEdit->hasFocus() );
379+
QVERIFY( !editor2->mLineEdit->hasFocus() );
380+
QCOMPARE( editor1->mLineEdit->text(), QStringLiteral( "151.000000000" ) );
381+
QCOMPARE( editor2->mLineEdit->text(), QStringLiteral( "nope" ) );
382+
383+
editor2->mLineEdit->setFocus();
384+
QVERIFY( !editor1->mLineEdit->hasFocus() );
385+
QVERIFY( editor2->mLineEdit->hasFocus() );
386+
QCOMPARE( editor1->mLineEdit->text(), QStringLiteral( "151.000000000" ) );
387+
QCOMPARE( editor2->mLineEdit->text(), QStringLiteral( "" ) );
388+
389+
}
332390

333391
QGSTEST_MAIN( TestQgsRangeWidgetWrapper )
334392
#include "testqgsrangewidgetwrapper.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.