summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/test.pro.in7
-rwxr-xr-xclient/test.sh42
-rw-r--r--client/test/testlineedit.cc55
-rw-r--r--client/test/util.cc20
-rw-r--r--client/test/util.h32
5 files changed, 156 insertions, 0 deletions
diff --git a/client/test.pro.in b/client/test.pro.in
new file mode 100644
index 0000000..0442489
--- /dev/null
+++ b/client/test.pro.in
@@ -0,0 +1,7 @@
+include('client.pro')
+TARGET = test_app
+CONFIG += qtestlib
+DEFINES += TESTING
+SOURCES += \
+ TESTFILE \
+ test/util.cc
diff --git a/client/test.sh b/client/test.sh
new file mode 100755
index 0000000..1c3c96d
--- /dev/null
+++ b/client/test.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+TEST_PRO_IN=test.pro.in
+TEST_PRO=test.pro
+MAKEFILE=Makefile.test
+TESTFILES=test/test*.cc
+TEST_APP=test_app
+
+rm -f test.log
+
+for TEST in $TESTFILES
+do
+ OUTPUT=$TEST.log
+
+ echo -e "\033[0;2mTesting $TEST:"
+ echo Testing $TEST: > $OUTPUT
+
+ echo -n "* Compiling $TEST test"
+ echo Compiling $TEST test: > $OUTPUT
+ echo ${COMPILE} >> $OUTPUT
+ cpp -P -E -DTESTFILE=\"$TEST\" $TEST_PRO_IN -o $TEST_PRO
+ qmake -makefile $TEST_PRO -o $MAKEFILE
+ if make -f $MAKEFILE >> ${OUTPUT} 2>&1; then
+ echo -e "\r\t\t\t\t\t\t[\033[1;32mSuccess\033[0;2m]"
+ echo "[Success]" >> $OUTPUT
+
+ echo -n "* Running $TEST test"
+ echo Running $TEST test: >> $OUTPUT
+ if ./$TEST_APP >> $OUTPUT 2>&1; then
+ echo -e "\r\t\t\t\t\t\t[\033[1;32mSuccess\033[0;2m]"
+ echo "[Success]" >> $OUTPUT
+ else
+ echo -e "\r\t\t\t\t\t\t[\033[1;31mFailure\033[0;2m]"
+ echo "[Failure]" >> $OUTPUT
+ fi
+ else
+ echo -e "\r\t\t\t\t\t\t[\033[1;31mFailure\033[0;2m]"
+ echo "[Failure]" >> $OUTPUT
+ fi
+done
+
+rm -f $MAKEFILE $TEST_PRO $TEST_APP
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 <QtTest/QtTest>
+#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 <QDomDocument>
+
+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 <QDomElement>
+
+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"));