From 86bd08d47842e5681835412ac6c08d7135a6adc5 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 31 Aug 2009 11:33:57 +0000 Subject: Initial attempt on a unit test system. --- client/test/testlineedit.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++ client/test/util.cc | 20 +++++++++++++++++ client/test/util.h | 32 ++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 client/test/testlineedit.cc create mode 100644 client/test/util.cc create mode 100644 client/test/util.h (limited to 'client/test') diff --git a/client/test/testlineedit.cc b/client/test/testlineedit.cc new file mode 100644 index 0000000..4eb886b --- /dev/null +++ b/client/test/testlineedit.cc @@ -0,0 +1,55 @@ +#include +#include "util.h" +#include "lineedit.h" + +class TestLineEdit: public QObject +{ +Q_OBJECT +private slots: + void creation() { TEST_CREATION(LineEdit); } + void disable() { TEST_DISABLE(LineEdit); } + void value() { TEST_VALUE(LineEdit); } + void edit() + { + QDomElement e = getWidgetElement("LineEdit", "mywidget"); + MacroWindow *wnd = createMacroWindow(); + LineEdit le(e, wnd); + QTest::keyClicks(&le, "hello"); + QCOMPARE(le.getValue(), QString("hello")); + } +}; + +QTEST_MAIN(TestLineEdit) +#include "testlineedit.moc" + +/** +class LineEdit : public QLineEdit, public Widget +{ +Q_OBJECT +public: + LineEdit(QDomNode &node, MacroWindow *macrowindow); + + QString getValue(); + void setValue(QString value, QString source = ""); + + void enable(); + void disable(); + bool isDisabled(); + + void connectFrom(const char *signal, + const QObject *receiver, const char *method); + + void connectTo(const QObject *sender, const char *signal, + const char *method); + + bool setKeyboardFocus(); + void setVisibility(bool visible); + +public slots: + void changed(); + void user_changed(); + +signals: + void wasChanged(); +}; + **/ diff --git a/client/test/util.cc b/client/test/util.cc new file mode 100644 index 0000000..257b561 --- /dev/null +++ b/client/test/util.cc @@ -0,0 +1,20 @@ +#include "util.h" +#include + +MacroWindow *createMacroWindow() +{ + MacroWindow *m; + m = NULL; + return m; +} + +QDomElement getWidgetElement(QString type, QString name, QString value) +{ + QDomDocument doc; + + QDomElement e = doc.createElement(type); + e.setAttribute("name", name); + if(value != "") e.setAttribute("value", value); + + return e; +} diff --git a/client/test/util.h b/client/test/util.h new file mode 100644 index 0000000..98da0e9 --- /dev/null +++ b/client/test/util.h @@ -0,0 +1,32 @@ +#include "macrowindow.h" +#include + +MacroWindow *createMacroWindow(); +QDomElement getWidgetElement(QString type = "", + QString name = "", + QString value = ""); + +// +// Predefined tests +// +#define TEST_CREATION(W) \ + QDomElement n = getWidgetElement(#W, "mywidget"); \ + MacroWindow *wnd = createMacroWindow(); \ + W wgd(n, wnd); \ + +#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); + +#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")); -- cgit v1.2.3