diff options
author | Mark Brand <mabrand@mabrand.nl> | 2012-10-15 23:46:44 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-17 00:47:10 (GMT) |
commit | b96e1454a50dae2e4941ba9bd94a0fd5b56914a7 (patch) | |
tree | 5c918a3f190a0089eadd19cb7bdcff53f46724f2 /tests | |
parent | 623c581b0a1d819efff597ab91730ac5766eba04 (diff) | |
download | Qt-b96e1454a50dae2e4941ba9bd94a0fd5b56914a7.zip Qt-b96e1454a50dae2e4941ba9bd94a0fd5b56914a7.tar.gz Qt-b96e1454a50dae2e4941ba9bd94a0fd5b56914a7.tar.bz2 |
QComboBox: replace homebrew with QSignalSpy for editTextChanged test
Change-Id: Id4c81ae71d6dc87f9ad7cfb99a89d335162e1f75
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
(cherry picked from qt5/qtbase commit e437051ff51d57bcc6937dc23fe6a77bf9897130)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qcombobox/tst_qcombobox.cpp | 47 |
1 files changed, 12 insertions, 35 deletions
diff --git a/tests/auto/qcombobox/tst_qcombobox.cpp b/tests/auto/qcombobox/tst_qcombobox.cpp index 0ad1b95..b6b4436 100644 --- a/tests/auto/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/qcombobox/tst_qcombobox.cpp @@ -159,15 +159,10 @@ private slots: void maxVisibleItems(); void task_QTBUG_10491_currentIndexAndModelColumn(); -protected slots: - void onEditTextChanged( const QString &newString ); - private: QComboBox *testWidget; QWidget *parent; QPushButton* ok; - int editTextCount; - QString editText; }; class MyAbstractItemDelegate : public QAbstractItemDelegate @@ -402,10 +397,6 @@ void tst_QComboBox::initTestCase() testWidget = new QComboBox(parent); testWidget->setObjectName("testObject"); testWidget->setGeometry(0, 0, 100, 100); - editTextCount = 0; - editText.clear(); - connect(testWidget, SIGNAL(editTextChanged(const QString&)), - this, SLOT(onEditTextChanged(const QString&))); parent->show(); } @@ -1390,23 +1381,19 @@ void tst_QComboBox::editTextChanged() testWidget->setEditable(false); QCOMPARE(testWidget->isEditable(), false); + QSignalSpy spy(testWidget, SIGNAL(editTextChanged(QString))); + // no signal should be sent when current is set to the same QCOMPARE(testWidget->currentIndex(), 0); - editTextCount = 0; - editText.clear(); testWidget->setCurrentIndex(0); QCOMPARE(testWidget->currentIndex(), 0); - QCOMPARE(editTextCount, 0); - QCOMPARE(editText.isEmpty(), true); + QCOMPARE(spy.count(), 0); // no signal should be sent when changing to other index because we are not editable QCOMPARE(testWidget->currentIndex(), 0); - editTextCount = 0; - editText.clear(); testWidget->setCurrentIndex(1); QCOMPARE(testWidget->currentIndex(), 1); - QCOMPARE(editTextCount, 0); - QCOMPARE(editText.isEmpty(), true); + QCOMPARE(spy.count(), 0); // now set to editable and reset current index testWidget->setEditable(true); @@ -1414,35 +1401,25 @@ void tst_QComboBox::editTextChanged() testWidget->setCurrentIndex(0); // no signal should be sent when current is set to the same + spy.clear(); QCOMPARE(testWidget->currentIndex(), 0); - editTextCount = 0; - editText.clear(); testWidget->setCurrentIndex(0); QCOMPARE(testWidget->currentIndex(), 0); - QCOMPARE(editTextCount, 0); - QCOMPARE(editText.isEmpty(), true); + QCOMPARE(spy.count(), 0); // signal should be sent when changing to other index QCOMPARE(testWidget->currentIndex(), 0); - editTextCount = 0; - editText.clear(); testWidget->setCurrentIndex(1); QCOMPARE(testWidget->currentIndex(), 1); - QCOMPARE(editTextCount, 1); - QCOMPARE(editText, QString("bar")); + QCOMPARE(spy.count(), 1); + QCOMPARE(qvariant_cast<QString>(spy.at(0).at(0)), QString("bar")); + // insert some keys and notice they are all signaled - editTextCount = 0; - editText.clear(); + spy.clear(); QTest::keyClicks(testWidget, "bingo"); - QCOMPARE(editTextCount, 5); - QCOMPARE(editText, QString("barbingo")); -} - -void tst_QComboBox::onEditTextChanged(const QString &text) -{ - editTextCount++; - editText = text; + QCOMPARE(spy.count(), 5); + QCOMPARE(qvariant_cast<QString>(spy.at(4).at(0)), QString("barbingo")); } void tst_QComboBox::setModel() |