From c8fc7a2419f6cdf1101b0e3adb30344d7625857d Mon Sep 17 00:00:00 2001 From: signedav Date: Wed, 14 Nov 2018 12:43:26 +0100 Subject: [PATCH] tests for focus on null field --- tests/src/gui/testqgsrangewidgetwrapper.cpp | 58 +++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/src/gui/testqgsrangewidgetwrapper.cpp b/tests/src/gui/testqgsrangewidgetwrapper.cpp index e38f65bef67..a8bcd3a5fc2 100644 --- a/tests/src/gui/testqgsrangewidgetwrapper.cpp +++ b/tests/src/gui/testqgsrangewidgetwrapper.cpp @@ -51,6 +51,7 @@ class TestQgsRangeWidgetWrapper : public QObject void test_setDoubleSmallerRange(); void test_setDoubleLimits(); void test_nulls(); + void test_focus(); private: std::unique_ptr widget0; // For field 0 @@ -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( widget1->createWidget( w ) ); + QVERIFY( editor1 ); + widget1->initWidget( editor1 ); + + widget2->setConfig( cfg ); + QgsDoubleSpinBox *editor2 = qobject_cast( 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"