From d9338083192084613e5530b02710b796252d342b Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 12 Aug 2010 10:57:04 +0000 Subject: New scripting system part2. --- client/test/testcomboboxedit.cc | 23 ++++++++++---------- client/test/testcomboboxsearch.cc | 44 ++++++++++++++++++++------------------- client/test/testcomboboxselect.cc | 22 ++++++++++---------- client/test/testlineedit.cc | 10 ++++----- client/test/util.cc | 17 ++++++++++++++- client/test/util.h | 32 ++++++++++++++-------------- 6 files changed, 82 insertions(+), 66 deletions(-) (limited to 'client/test') diff --git a/client/test/testcomboboxedit.cc b/client/test/testcomboboxedit.cc index 7fdbfb1..76a9792 100644 --- a/client/test/testcomboboxedit.cc +++ b/client/test/testcomboboxedit.cc @@ -36,10 +36,10 @@ private slots: { QDomDocument doc; doc.setContent(xml_search); QDomElement e = doc.documentElement(); - ComboBox cmb(e, NULL); + ComboBox cmb(e, createMacroWindow()); - QTest::keyClicks(&cmb, "Item 2"); - QCOMPARE(cmb.getValue(), QString("Item 2")); + QTest::keyClicks(cmb.qwidget(), "Item 2"); + QCOMPARE(cmb.value(), QString("Item 2")); } void arrowSelect() @@ -47,22 +47,21 @@ private slots: 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")); + ComboBox cmb(e, createMacroWindow()); + cmb.qwidget()->setFocus(); + 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")); } void changeEmits() { QDomDocument doc; doc.setContent(xml_search); QDomElement e = doc.documentElement(); - ComboBox cmb(e, NULL); + ComboBox cmb(e, createMacroWindow()); QSignalSpy spy(&cmb, SIGNAL(wasChanged())); - QTest::keyClicks(&cmb, "I"); + QTest::keyClicks(cmb.qwidget(), "I"); QCOMPARE(spy.count(), 1); } }; diff --git a/client/test/testcomboboxsearch.cc b/client/test/testcomboboxsearch.cc index 7ac0db4..ff737db 100644 --- a/client/test/testcomboboxsearch.cc +++ b/client/test/testcomboboxsearch.cc @@ -4,6 +4,7 @@ #include "combobox.h" #include #include +#include static QString xml = "\n" @@ -34,47 +35,48 @@ private slots: { QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); - ComboBox cmb(e, NULL); + ComboBox cmb(e, createMacroWindow()); // Full item search - QTest::keyClicks(&cmb, "Item 2"); - QCOMPARE(cmb.getValue(), QString("Item 2")); + QTest::keyClicks(cmb.qwidget(), "Item 2"); + QCOMPARE(cmb.value(), QString("Item 2")); } void searchPrefix() { QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); - ComboBox cmb(e, NULL); + ComboBox cmb(e, createMacroWindow()); + QComboBox *qcmb = (QComboBox *)cmb.qwidget(); // Item prefix search - QTest::keyClicks(&cmb, "T"); - QCOMPARE(cmb.completer()->currentCompletion(), QString("Thingy")); + QTest::keyClicks(cmb.qwidget(), "T"); + QCOMPARE(qcmb->completer()->currentCompletion(), QString("Thingy")); - QTest::keyClicks(&cmb, cmb.completer()->currentCompletion()); - QCOMPARE(cmb.getValue(), 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, NULL); + ComboBox cmb(e, createMacroWindow()); // Negative search - QTest::keyClicks(&cmb, "A"); - QCOMPARE(cmb.getValue(), QString("")); + QTest::keyClicks(cmb.qwidget(), "A"); + QCOMPARE(cmb.value(), 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")); + 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() @@ -82,16 +84,16 @@ private slots: QDomDocument doc; doc.setContent(xml_default); QDomElement e = doc.documentElement(); ComboBox cmb(e, NULL); - QCOMPARE(cmb.getValue(), QString("item2")); + QCOMPARE(cmb.value(), QString("item2")); } */ void changeEmitUser() { QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); - ComboBox cmb(e, NULL); + ComboBox cmb(e, createMacroWindow()); QSignalSpy spy(&cmb, SIGNAL(wasChanged())); - QTest::keyClicks(&cmb, "I"); + QTest::keyClicks(cmb.qwidget(), "I"); QCOMPARE(spy.count(), 1); } @@ -99,7 +101,7 @@ private slots: { QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); - ComboBox cmb(e, NULL); + ComboBox cmb(e, createMacroWindow()); QSignalSpy spy(&cmb, SIGNAL(wasChanged())); cmb.setValue("some value", "pentominos"); QCOMPARE(spy.count(), 1); @@ -109,7 +111,7 @@ private slots: { QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); - ComboBox cmb(e, NULL); + ComboBox cmb(e, createMacroWindow()); QSignalSpy spy(&cmb, SIGNAL(wasChanged())); cmb.setValue("some value", "pracro"); QCOMPARE(spy.count(), 0); diff --git a/client/test/testcomboboxselect.cc b/client/test/testcomboboxselect.cc index 1439440..3eaac00 100644 --- a/client/test/testcomboboxselect.cc +++ b/client/test/testcomboboxselect.cc @@ -36,10 +36,10 @@ private slots: { QDomDocument doc; doc.setContent(xml_search); QDomElement e = doc.documentElement(); - ComboBox cmb(e, NULL); + ComboBox cmb(e, createMacroWindow()); - QTest::keyClicks(&cmb, "Item 2"); - QCOMPARE(cmb.getValue(), QString("Item 2")); + QTest::keyClicks(cmb.qwidget(), "Item 2"); + QCOMPARE(cmb.value(), QString("Item 2")); } void arrowSelect() @@ -47,22 +47,22 @@ private slots: QDomDocument doc; doc.setContent(xml_select); QDomElement e = doc.documentElement(); - ComboBox cmb(e, NULL); + ComboBox cmb(e, createMacroWindow()); - 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")); + cmb.qwidget()->setFocus(); + 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")); } void changeEmits() { QDomDocument doc; doc.setContent(xml_search); QDomElement e = doc.documentElement(); - ComboBox cmb(e, NULL); + ComboBox cmb(e, createMacroWindow()); QSignalSpy spy(&cmb, SIGNAL(wasChanged())); - QTest::keyClicks(&cmb, "I"); + QTest::keyClicks(cmb.qwidget(), "I"); QCOMPARE(spy.count(), 1); } }; diff --git a/client/test/testlineedit.cc b/client/test/testlineedit.cc index 8b30295..0cf70fd 100644 --- a/client/test/testlineedit.cc +++ b/client/test/testlineedit.cc @@ -16,19 +16,19 @@ private slots: { QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); - LineEdit le(e, NULL); + LineEdit le(e, createMacroWindow()); QString teststring("hello"); - QTest::keyClicks(&le, teststring); - QCOMPARE(le.getValue(), teststring); + QTest::keyClicks(le.qwidget(), teststring); + QCOMPARE(le.value(), teststring); } void changeEmits() { QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); - LineEdit le(e, NULL); + LineEdit le(e, createMacroWindow()); QSignalSpy spy(&le, SIGNAL(wasChanged())); - QTest::keyClicks(&le, "h"); + QTest::keyClicks(le.qwidget(), "h"); QCOMPARE(spy.count(), 1); } }; diff --git a/client/test/util.cc b/client/test/util.cc index 257b561..1fd09d4 100644 --- a/client/test/util.cc +++ b/client/test/util.cc @@ -1,10 +1,25 @@ #include "util.h" #include +#include +#include + +#include "netcom.h" + +#define CONFIG_DEFAULT "pracro.ini" MacroWindow *createMacroWindow() { MacroWindow *m; - m = NULL; + + 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"); return m; } diff --git a/client/test/util.h b/client/test/util.h index 89a887d..abf7df5 100644 --- a/client/test/util.h +++ b/client/test/util.h @@ -10,24 +10,24 @@ QDomElement getWidgetElement(QString type = "", // // Predefined tests // -#define TEST_CREATION(W) \ +#define TEST_CREATION(W) \ QDomElement n = getWidgetElement(#W, "mywidget"); \ - MacroWindow *wnd = createMacroWindow(); \ - W wgd(n, wnd); \ + MacroWindow *wnd = createMacroWindow(); \ + W wgd(n, wnd); -#define TEST_DISABLE(W) \ +#define TEST_DISABLE(W) \ QDomElement n = getWidgetElement(#W, "mywidget"); \ - MacroWindow *wnd = createMacroWindow(); \ - W wdg(n, wnd); \ - wdg.disable(); \ - QCOMPARE(wdg.isDisabled(), true); \ - wdg.enable(); \ - QCOMPARE(wdg.isDisabled(), false); + MacroWindow *wnd = createMacroWindow(); \ + W wdg(n, wnd); \ + wdg.setEnabled(false); \ + QCOMPARE(wdg.enabled(), false); \ + wdg.setEnabled(true); \ + QCOMPARE(wdg.enabled(), true); -#define TEST_VALUE(W) \ +#define TEST_VALUE(W) \ QDomElement n = getWidgetElement(#W, "mywidget"); \ - MacroWindow *wnd = createMacroWindow(); \ - W wdg(n, wnd); \ - QCOMPARE(wdg.getValue(), QString("")); \ - wdg.setValue("hello", "source"); \ - QCOMPARE(wdg.getValue(), QString("hello")); + MacroWindow *wnd = createMacroWindow(); \ + W wdg(n, wnd); \ + QCOMPARE(wdg.value(), QString("")); \ + wdg.setValue("hello", "source"); \ + QCOMPARE(wdg.value(), QString("hello")); -- cgit v1.2.3