/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ #include #include "util.h" #include "combobox.h" #include #include #include static QString xml = "\n" " \n" " \n" " \n" " \n" " \n" "\n"; static QString xml_default = "\n" " \n" " \n" " \n" " \n" " \n" "\n"; class TestComboBoxSearch: public QObject { Q_OBJECT private slots: void creation() { TEST_CREATION(ComboBox); } void disable() { TEST_DISABLE(ComboBox); } void searchFullItem() { QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); ComboBox cmb(e, createMacroWindow()); // Full item search QTest::keyClicks(cmb.qwidget(), "Item 2"); QCOMPARE(cmb.value(), QString("item2")); } void searchPrefix() { QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); ComboBox cmb(e, createMacroWindow()); QComboBox *qcmb = (QComboBox *)cmb.qwidget(); // Item prefix search QTest::keyClicks(cmb.qwidget(), "T"); QCOMPARE(qcmb->completer()->currentCompletion(), QString("Thingy")); QTest::keyClicks(cmb.qwidget(), qcmb->completer()->currentCompletion()); QCOMPARE(cmb.value(), QString("thingy")); } void searchNegative() { QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); ComboBox cmb(e, createMacroWindow()); // Negative search QTest::keyClicks(cmb.qwidget(), "A"); QCOMPARE(cmb.value(), QString("")); } void arrowSelect() { QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); ComboBox cmb(e, createMacroWindow()); QTest::keyPress(cmb.qwidget(), Qt::Key_Down); QTest::keyPress(cmb.qwidget(), Qt::Key_Down); QTest::keyPress(cmb.qwidget(), Qt::Key_Enter); QCOMPARE(cmb.value(), QString("item3")); } /* // It is set in MacroWindow generation .. not directly in the Widget. void defaultValue() { QDomDocument doc; doc.setContent(xml_default); QDomElement e = doc.documentElement(); ComboBox cmb(e, NULL); QCOMPARE(cmb.value(), QString("item2")); } */ void changeEmitUser() { QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); ComboBox cmb(e, createMacroWindow()); QSignalSpy spy(&cmb, SIGNAL(wasChanged())); QTest::keyClicks(cmb.qwidget(), "I"); QCOMPARE(spy.count(), 1); } void changeEmitSystem() { QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); ComboBox cmb(e, createMacroWindow()); QSignalSpy spy(&cmb, SIGNAL(wasChanged())); cmb.setValue("some value", "pentominos"); QCOMPARE(spy.count(), 1); } void changeNoEmitSystem() { QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); ComboBox cmb(e, createMacroWindow()); QSignalSpy spy(&cmb, SIGNAL(wasChanged())); cmb.setValue("some value", "pracro"); QCOMPARE(spy.count(), 0); } }; QTEST_MAIN(TestComboBoxSearch) #include "testcomboboxsearch.moc"