diff options
Diffstat (limited to 'client/test')
-rw-r--r-- | client/test/testaltcombobox.cc | 93 | ||||
-rw-r--r-- | client/test/testcomboboxedit.cc | 2 | ||||
-rw-r--r-- | client/test/testcomboboxsearch.cc | 4 | ||||
-rw-r--r-- | client/test/testcomboboxselect.cc | 2 | ||||
-rw-r--r-- | client/test/util.cc | 8 |
5 files changed, 88 insertions, 21 deletions
diff --git a/client/test/testaltcombobox.cc b/client/test/testaltcombobox.cc index 84d92ad..5eb7afb 100644 --- a/client/test/testaltcombobox.cc +++ b/client/test/testaltcombobox.cc @@ -1,31 +1,72 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ #include <QtTest/QtTest> + +#include <QComboBox> + #include "util.h" #include "altcombobox.h" -#include <QAbstractItemView> static QString xml = - "<altcombobox name=\"mycombobox\" type=\"search\">\n" + "<altcombobox name=\"mycombobox\" value=\"item1\" type=\"search\">\n" " <item value=\"item1\" caption=\"Item 1\"/>\n" " <item value=\"item3\" caption=\"Item 3\"/>\n" - " <item value=\"item2\" caption=\"Item 2\"/>\n" + " <altitem value=\"item2\" caption=\"Item 2\" innerwidget=\"in\">\n" + " <lineedit name=\"in\" value=\"test\">\n" + " </altitem>\n" + "</altcombobox>\n"; + +static QString xml_lua = + "<altcombobox name=\"mycombobox\" value=\"item1\" type=\"search\"\n" + " onInit=\"this:addItem('Item 4')\">\n" + " <item value=\"item1\" caption=\"Item 1\"/>\n" + " <item value=\"item3\" caption=\"Item 3\"/>\n" + " <altitem value=\"item2\" caption=\"Item 2\" innerwidget=\"in\">\n" + " <lineedit name=\"in\" value=\"test\">\n" + " </altitem>\n" "</altcombobox>\n"; class TestAltComboBox: public QObject { Q_OBJECT private slots: + void creation() { TEST_CREATION(AltComboBox); } void disable() { TEST_DISABLE(AltComboBox); } - void edit() + void visible() + { + QDomDocument doc; doc.setContent(xml); + QDomElement e = doc.documentElement(); + AltComboBox cmb(e, createMacroWindow()); + cmb.qwidget()->show(); + cmb.setValues(); + + QCOMPARE(cmb.visible(), true); + + Widget *w = cmb.findWidget("in", true); + QCOMPARE(w->visible(), false); + + QTest::keyClicks(cmb.qcombobox(), "\b2"); + QCOMPARE(w->visible(), true); + + QTest::keyClicks(cmb.qcombobox(), "\b3"); + QCOMPARE(w->visible(), false); + } + + void value() { QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); AltComboBox cmb(e, createMacroWindow()); + cmb.setValues(); - QTest::keyClicks(cmb.qwidget(), "Item 2"); - QCOMPARE(cmb.value(), QString("Item 2")); + QCOMPARE(cmb.value(), QString("item1")); + + QTest::keyClicks(cmb.qcombobox(), "\b3"); + QCOMPARE(cmb.value(), QString("item3")); + + QTest::keyClicks(cmb.qcombobox(), "\b2"); + QCOMPARE(cmb.value(), QString("test")); } void arrow() @@ -34,12 +75,18 @@ private slots: QDomElement e = doc.documentElement(); AltComboBox cmb(e, createMacroWindow()); + cmb.setValues(); + + QCOMPARE(cmb.value(), QString("item1")); - cmb.qwidget()->setFocus(); - QTest::keyPress(cmb.qwidget(), Qt::Key_Down); - QTest::keyPress(cmb.qwidget(), Qt::Key_Down); - QTest::keyPress(cmb.qwidget(), Qt::Key_Enter); + cmb.qcombobox()->setFocus(); + QTest::keyPress(cmb.qcombobox(), Qt::Key_Down); + QTest::keyPress(cmb.qcombobox(), Qt::Key_Enter); QCOMPARE(cmb.value(), QString("item3")); + + QTest::keyPress(cmb.qcombobox(), Qt::Key_Down); + QTest::keyPress(cmb.qcombobox(), Qt::Key_Enter); + QCOMPARE(cmb.value(), QString("test")); } void changeEmits() @@ -47,10 +94,32 @@ private slots: QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); AltComboBox cmb(e, createMacroWindow()); + cmb.setValues(); + QSignalSpy spy(&cmb, SIGNAL(wasChanged())); - QTest::keyClicks(cmb.qwidget(), "I"); - QCOMPARE(spy.count(), 1); + + QTest::keyClicks(cmb.qcombobox(), "\b2"); + QCOMPARE(spy.count(), 2); + QCOMPARE(cmb.value(), QString("test")); + + Widget *w = cmb.findWidget("in", true); + QTest::keyClicks(w->qwidget(), "A"); + QCOMPARE(cmb.value(), QString("testA")); + QCOMPARE(spy.count(), 3); } + + void lua() + { + QDomDocument doc; doc.setContent(xml_lua); + QDomElement e = doc.documentElement(); + AltComboBox cmb(e, createMacroWindow()); + cmb.setValues(); + cmb.qwidget()->show(); + cmb.runEventOnInit(true); + + QTest::keyClicks(cmb.qcombobox(), "\b4"); + QCOMPARE(cmb.value(), QString("Item 4")); + } }; QTEST_MAIN(TestAltComboBox) diff --git a/client/test/testcomboboxedit.cc b/client/test/testcomboboxedit.cc index 76a9792..d85c4e5 100644 --- a/client/test/testcomboboxedit.cc +++ b/client/test/testcomboboxedit.cc @@ -39,7 +39,7 @@ private slots: ComboBox cmb(e, createMacroWindow()); QTest::keyClicks(cmb.qwidget(), "Item 2"); - QCOMPARE(cmb.value(), QString("Item 2")); + QCOMPARE(cmb.value(), QString("item2")); } void arrowSelect() diff --git a/client/test/testcomboboxsearch.cc b/client/test/testcomboboxsearch.cc index ff737db..564f5c1 100644 --- a/client/test/testcomboboxsearch.cc +++ b/client/test/testcomboboxsearch.cc @@ -39,7 +39,7 @@ private slots: // Full item search QTest::keyClicks(cmb.qwidget(), "Item 2"); - QCOMPARE(cmb.value(), QString("Item 2")); + QCOMPARE(cmb.value(), QString("item2")); } void searchPrefix() @@ -54,7 +54,7 @@ private slots: QCOMPARE(qcmb->completer()->currentCompletion(), QString("Thingy")); QTest::keyClicks(cmb.qwidget(), qcmb->completer()->currentCompletion()); - QCOMPARE(cmb.value(), QString("Thingy")); + QCOMPARE(cmb.value(), QString("thingy")); } void searchNegative() diff --git a/client/test/testcomboboxselect.cc b/client/test/testcomboboxselect.cc index 3eaac00..86700c1 100644 --- a/client/test/testcomboboxselect.cc +++ b/client/test/testcomboboxselect.cc @@ -39,7 +39,7 @@ private slots: ComboBox cmb(e, createMacroWindow()); QTest::keyClicks(cmb.qwidget(), "Item 2"); - QCOMPARE(cmb.value(), QString("Item 2")); + QCOMPARE(cmb.value(), QString("item2")); } void arrowSelect() diff --git a/client/test/util.cc b/client/test/util.cc index 1fd09d4..80556c8 100644 --- a/client/test/util.cc +++ b/client/test/util.cc @@ -9,17 +9,14 @@ MacroWindow *createMacroWindow() { - MacroWindow *m; - QSettings settings("pracro.ini", QSettings::IniFormat); settings.beginGroup("server"); QString host = settings.value("host").toString(); int port = settings.value("port").toInt(); settings.endGroup(); - NetCom netcom(host, port); - QDomNode node; - m = new MacroWindow(netcom, node, "test"); + NetCom netcom(host, port); + MacroWindow *m = new MacroWindow(netcom, "test", true, false, NULL, NULL); return m; } @@ -33,3 +30,4 @@ QDomElement getWidgetElement(QString type, QString name, QString value) return e; } + |