From eedcfd2f8b9e17f0903b7ff85421636830d2291d Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 31 Aug 2009 15:01:56 +0000 Subject: Some more tests. --- client/test/testcomboboxsearch.cc | 121 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 client/test/testcomboboxsearch.cc (limited to 'client/test/testcomboboxsearch.cc') diff --git a/client/test/testcomboboxsearch.cc b/client/test/testcomboboxsearch.cc new file mode 100644 index 0000000..84f03c4 --- /dev/null +++ b/client/test/testcomboboxsearch.cc @@ -0,0 +1,121 @@ +#include +#include "util.h" +#include "combobox.h" +#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, NULL); + + // Full item search + QTest::keyClicks(&cmb, "Item 2"); + QCOMPARE(cmb.getValue(), QString("Item 2")); + } + + void searchPrefix() + { + QDomDocument doc; doc.setContent(xml); + QDomElement e = doc.documentElement(); + ComboBox cmb(e, NULL); + + // Item prefix search + QTest::keyClicks(&cmb, "T"); + QCOMPARE(cmb.completer()->currentCompletion(), QString("Thingy")); + + QTest::keyClicks(&cmb, cmb.completer()->currentCompletion()); + QCOMPARE(cmb.getValue(), QString("Thingy")); + } + + void searchNegative() + { + QDomDocument doc; doc.setContent(xml); + QDomElement e = doc.documentElement(); + ComboBox cmb(e, NULL); + + // Negative search + QTest::keyClicks(&cmb, "A"); + QCOMPARE(cmb.getValue(), QString("")); + } + + void arrowSelect() + { + QDomDocument doc; doc.setContent(xml); + QDomElement e = doc.documentElement(); + ComboBox cmb(e, NULL); + QTest::keyPress(&cmb, Qt::Key_Down); + QTest::keyPress(&cmb, Qt::Key_Down); + QTest::keyPress(&cmb, Qt::Key_Enter); + QCOMPARE(cmb.getValue(), 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.getValue(), QString("item2")); + } + */ + void changeEmitUser() + { + QDomDocument doc; doc.setContent(xml); + QDomElement e = doc.documentElement(); + ComboBox cmb(e, NULL); + QSignalSpy spy(&cmb, SIGNAL(wasChanged())); + QTest::keyClicks(&cmb, "I"); + QCOMPARE(spy.count(), 1); + } + + void changeEmitSystem() + { + QDomDocument doc; doc.setContent(xml); + QDomElement e = doc.documentElement(); + ComboBox cmb(e, NULL); + 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, NULL); + QSignalSpy spy(&cmb, SIGNAL(wasChanged())); + cmb.setValue("some value", "pracro"); + QCOMPARE(spy.count(), 0); + } +}; + +QTEST_MAIN(TestComboBoxSearch) +#include "testcomboboxsearch.moc" + + -- cgit v1.2.3