summaryrefslogtreecommitdiff
path: root/client/test/testcomboboxedit.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/test/testcomboboxedit.cc')
-rw-r--r--client/test/testcomboboxedit.cc72
1 files changed, 72 insertions, 0 deletions
diff --git a/client/test/testcomboboxedit.cc b/client/test/testcomboboxedit.cc
new file mode 100644
index 0000000..5294886
--- /dev/null
+++ b/client/test/testcomboboxedit.cc
@@ -0,0 +1,72 @@
+#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 TestComboBox: 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(TestComboBox)
+#include "testcombobox.moc"
+
+