summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
diff options
context:
space:
mode:
authorMark Brand <mabrand@mabrand.nl>2012-10-13 15:08:11 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-26 15:24:19 +0200
commit5bddaf76e027a4688a9f26a6a6b3fa80e0903cb7 (patch)
tree5842ca0a3e8c8454bc2a293c40afa9ab35c6e615 /tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
parent84787d82ee9369b2a83c5b0568ee62ab602a5528 (diff)
QComboBox: new signal currentTextChanged
Adds NOTIFY to currentText property. Test included. Change-Id: I3e92b585ad6697891d61537c82f6ab9e8beb1a00 Reviewed-by: Andy Shaw <andy.shaw@digia.com> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp')
-rw-r--r--tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
index df0eb89682..3b9f408e73 100644
--- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
@@ -116,6 +116,8 @@ private slots:
void insertOnCurrentIndex();
void textpixmapdata_data();
void textpixmapdata();
+ void currentTextChanged_data();
+ void currentTextChanged();
void editTextChanged();
void setModel();
void modelDeleted();
@@ -1408,6 +1410,59 @@ void tst_QComboBox::setCurrentText()
#endif
}
+void tst_QComboBox::currentTextChanged_data()
+{
+ QTest::addColumn<bool>("editable");
+ QTest::newRow("editable") << true;
+ QTest::newRow("not editable") << false;
+}
+
+void tst_QComboBox::currentTextChanged()
+{
+ QFETCH(bool, editable);
+
+ QCOMPARE(testWidget->count(), 0);
+ testWidget->addItems(QStringList() << "foo" << "bar");
+ QCOMPARE(testWidget->count(), 2);
+
+ QSignalSpy spy(testWidget, SIGNAL(currentTextChanged(QString)));
+
+ testWidget->setEditable(editable);
+
+ // set text in list
+ testWidget->setCurrentIndex(0);
+ QCOMPARE(testWidget->currentIndex(), 0);
+ spy.clear();
+ testWidget->setCurrentText(QString("bar"));
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(qvariant_cast<QString>(spy.at(0).at(0)), QString("bar"));
+
+ // set text not in list
+ testWidget->setCurrentIndex(0);
+ QCOMPARE(testWidget->currentIndex(), 0);
+ spy.clear();
+ testWidget->setCurrentText(QString("qt"));
+ if (editable) {
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(qvariant_cast<QString>(spy.at(0).at(0)), QString("qt"));
+ } else {
+ QCOMPARE(spy.count(), 0);
+ }
+
+ // item changed
+ testWidget->setCurrentIndex(0);
+ QCOMPARE(testWidget->currentIndex(), 0);
+ spy.clear();
+ testWidget->setItemText(0, QString("ape"));
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(qvariant_cast<QString>(spy.at(0).at(0)), QString("ape"));
+ // change it back
+ spy.clear();
+ testWidget->setItemText(0, QString("foo"));
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(qvariant_cast<QString>(spy.at(0).at(0)), QString("foo"));
+}
+
void tst_QComboBox::editTextChanged()
{
QCOMPARE(testWidget->count(), 0);