Changeset View
Changeset View
Standalone View
Standalone View
autotests/kcombobox_unittest.cpp
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 41 | { | |||
---|---|---|---|---|---|
50 | w.setEditable(true); | 50 | w.setEditable(true); | ||
51 | QCOMPARE(w.lineEdit(), lineEdit); | 51 | QCOMPARE(w.lineEdit(), lineEdit); | ||
52 | // KLineEdit signals | 52 | // KLineEdit signals | ||
53 | QSignalSpy qReturnPressedSpy(w.lineEdit(), SIGNAL(returnPressed())); | 53 | QSignalSpy qReturnPressedSpy(w.lineEdit(), SIGNAL(returnPressed())); | ||
54 | QSignalSpy kReturnPressedSpy(w.lineEdit(), SIGNAL(returnPressed(QString))); | 54 | QSignalSpy kReturnPressedSpy(w.lineEdit(), SIGNAL(returnPressed(QString))); | ||
55 | // KComboBox signals | 55 | // KComboBox signals | ||
56 | QSignalSpy comboReturnPressedSpy(&w, SIGNAL(returnPressed())); | 56 | QSignalSpy comboReturnPressedSpy(&w, SIGNAL(returnPressed())); | ||
57 | QSignalSpy comboReturnPressedStringSpy(&w, SIGNAL(returnPressed(QString))); | 57 | QSignalSpy comboReturnPressedStringSpy(&w, SIGNAL(returnPressed(QString))); | ||
58 | #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) | ||||
58 | QSignalSpy comboActivatedSpy(&w, SIGNAL(activated(QString))); | 59 | QSignalSpy comboActivatedSpy(&w, SIGNAL(activated(QString))); | ||
60 | #else | ||||
61 | QSignalSpy comboActivatedSpy(&w, &QComboBox::textActivated); | ||||
62 | #endif | ||||
59 | QTest::keyClick(&w, Qt::Key_Return); | 63 | QTest::keyClick(&w, Qt::Key_Return); | ||
60 | QCOMPARE(qReturnPressedSpy.count(), 1); | 64 | QCOMPARE(qReturnPressedSpy.count(), 1); | ||
61 | QCOMPARE(kReturnPressedSpy.count(), 1); | 65 | QCOMPARE(kReturnPressedSpy.count(), 1); | ||
62 | QCOMPARE(kReturnPressedSpy[0][0].toString(), QString("Hello world")); | 66 | QCOMPARE(kReturnPressedSpy[0][0].toString(), QString("Hello world")); | ||
63 | QCOMPARE(comboReturnPressedSpy.count(), 1); | 67 | QCOMPARE(comboReturnPressedSpy.count(), 1); | ||
64 | QCOMPARE(comboReturnPressedStringSpy.count(), 1); | 68 | QCOMPARE(comboReturnPressedStringSpy.count(), 1); | ||
65 | QCOMPARE(comboReturnPressedStringSpy[0][0].toString(), QString("Hello world")); | 69 | QCOMPARE(comboReturnPressedStringSpy[0][0].toString(), QString("Hello world")); | ||
66 | QCOMPARE(comboActivatedSpy.count(), 1); | 70 | QCOMPARE(comboActivatedSpy.count(), 1); | ||
67 | QCOMPARE(comboActivatedSpy[0][0].toString(), QString("Hello world")); | 71 | QCOMPARE(comboActivatedSpy[0][0].toString(), QString("Hello world")); | ||
68 | } | 72 | } | ||
69 | 73 | | |||
70 | private Q_SLOTS: | 74 | private Q_SLOTS: | ||
71 | void testComboReturnPressed() | 75 | void testComboReturnPressed() | ||
72 | { | 76 | { | ||
73 | testComboReturnPressed(false); | 77 | testComboReturnPressed(false); | ||
74 | testComboReturnPressed(true); | 78 | testComboReturnPressed(true); | ||
75 | } | 79 | } | ||
76 | 80 | | |||
77 | void testHistoryComboReturnPressed() | 81 | void testHistoryComboReturnPressed() | ||
78 | { | 82 | { | ||
79 | KHistoryComboBox w; | 83 | KHistoryComboBox w; | ||
80 | QVERIFY(qobject_cast<KLineEdit *>(w.lineEdit())); | 84 | QVERIFY(qobject_cast<KLineEdit *>(w.lineEdit())); | ||
81 | connect(&w, SIGNAL(activated(QString)), | | |||
82 | &w, SLOT(addToHistory(QString))); | | |||
83 | QSignalSpy comboReturnPressedSpy(&w, SIGNAL(returnPressed())); | 85 | QSignalSpy comboReturnPressedSpy(&w, SIGNAL(returnPressed())); | ||
84 | QSignalSpy comboReturnPressedStringSpy(&w, SIGNAL(returnPressed(QString))); | 86 | QSignalSpy comboReturnPressedStringSpy(&w, SIGNAL(returnPressed(QString))); | ||
87 | #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) | ||||
88 | connect(&w, SIGNAL(activated(QString)), | ||||
89 | &w, SLOT(addToHistory(QString))); | ||||
85 | QSignalSpy comboActivatedSpy(&w, SIGNAL(activated(QString))); | 90 | QSignalSpy comboActivatedSpy(&w, SIGNAL(activated(QString))); | ||
91 | #else | ||||
92 | connect(&w, &KHistoryComboBox::textActivated, | ||||
93 | &w, &KHistoryComboBox::addToHistory); | ||||
94 | QSignalSpy comboActivatedSpy(&w, &QComboBox::textActivated); | ||||
95 | #endif | ||||
86 | QTest::keyClicks(&w, QStringLiteral("Hello world")); | 96 | QTest::keyClicks(&w, QStringLiteral("Hello world")); | ||
87 | QTest::keyClick(&w, Qt::Key_Return); | 97 | QTest::keyClick(&w, Qt::Key_Return); | ||
88 | qApp->processEvents(); // QueuedConnection in KHistoryComboBox | 98 | qApp->processEvents(); // QueuedConnection in KHistoryComboBox | ||
89 | QCOMPARE(comboReturnPressedSpy.count(), 1); | 99 | QCOMPARE(comboReturnPressedSpy.count(), 1); | ||
90 | QCOMPARE(comboReturnPressedStringSpy.count(), 1); | 100 | QCOMPARE(comboReturnPressedStringSpy.count(), 1); | ||
91 | QCOMPARE(comboReturnPressedStringSpy[0][0].toString(), QString("Hello world")); | 101 | QCOMPARE(comboReturnPressedStringSpy[0][0].toString(), QString("Hello world")); | ||
92 | QCOMPARE(comboActivatedSpy.count(), 1); | 102 | QCOMPARE(comboActivatedSpy.count(), 1); | ||
93 | QCOMPARE(comboActivatedSpy[0][0].toString(), QString("Hello world")); | 103 | QCOMPARE(comboActivatedSpy[0][0].toString(), QString("Hello world")); | ||
▲ Show 20 Lines • Show All 124 Lines • Show Last 20 Lines |