/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ #include <QtTest/QtTest> #include "util.h" #include "combobox.h" #include <QAbstractItemView> static QString xml_search = "<combobox name=\"mycombobox\" type=\"search\">\n" " <item value=\"item1\" caption=\"Item 1\"/>\n" " <item value=\"item3\" caption=\"Item 3\"/>\n" " <item value=\"item2\" caption=\"Item 2\"/>\n" "</combobox>\n"; static QString xml_edit = "<combobox name=\"mycombobox\" type=\"edit\">\n" " <item value=\"item1\" caption=\"Item 1\"/>\n" " <item value=\"item3\" caption=\"Item 3\"/>\n" " <item value=\"item2\" caption=\"Item 2\"/>\n" "</combobox>\n"; static QString xml_select = "<combobox name=\"mycombobox\" type=\"select\">\n" " <item value=\"item1\" caption=\"Item 1\"/>\n" " <item value=\"item3\" caption=\"Item 3\"/>\n" " <item value=\"item2\" caption=\"Item 2\"/>\n" "</combobox>\n"; class TestComboBoxEdit: public QObject { Q_OBJECT private slots: void creation() { TEST_CREATION(ComboBox); } void disable() { TEST_DISABLE(ComboBox); } void editSelect() { QDomDocument doc; doc.setContent(xml_search); QDomElement e = doc.documentElement(); ComboBox cmb(e, NULL); QTest::keyClicks(&cmb, "Item 2"); QCOMPARE(cmb.getValue(), QString("Item 2")); } void arrowSelect() { QDomDocument doc; doc.setContent(xml_select); QDomElement e = doc.documentElement(); ComboBox cmb(e, NULL); cmb.setFocus(); QTest::keyPress(&cmb, Qt::Key_Down); QTest::keyPress(&cmb, Qt::Key_Down); QTest::keyPress(&cmb, Qt::Key_Enter); QCOMPARE(cmb.getValue(), QString("item3")); } void changeEmits() { QDomDocument doc; doc.setContent(xml_search); QDomElement e = doc.documentElement(); ComboBox cmb(e, NULL); QSignalSpy spy(&cmb, SIGNAL(wasChanged())); QTest::keyClicks(&cmb, "I"); QCOMPARE(spy.count(), 1); } }; QTEST_MAIN(TestComboBoxEdit) #include "testcomboboxedit.moc"