summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rwxr-xr-xclient/test.sh45
-rw-r--r--client/test/testcomboboxedit.cc72
-rw-r--r--client/test/testcomboboxsearch.cc121
-rw-r--r--client/test/testcomboboxselect.cc72
-rw-r--r--client/test/testlineedit.cc57
-rw-r--r--client/widgets/combobox.cc2
6 files changed, 311 insertions, 58 deletions
diff --git a/client/test.sh b/client/test.sh
index 1c3c96d..83dc675 100755
--- a/client/test.sh
+++ b/client/test.sh
@@ -3,9 +3,15 @@
TEST_PRO_IN=test.pro.in
TEST_PRO=test.pro
MAKEFILE=Makefile.test
-TESTFILES=test/test*.cc
TEST_APP=test_app
+if [ -z $1 ]
+then
+ TESTFILES=test/test*.cc
+else
+ TESTFILES=$1
+fi
+
rm -f test.log
for TEST in $TESTFILES
@@ -16,27 +22,28 @@ do
echo Testing $TEST: > $OUTPUT
echo -n "* Compiling $TEST test"
- echo Compiling $TEST test: > $OUTPUT
+ 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
+ qmake -makefile $TEST_PRO -o $MAKEFILE
+ if make -f $MAKEFILE 2>&1 >> ${OUTPUT}; 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 2>&1 >> $OUTPUT ; 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
+ echo -e "\r\t\t\t\t\t\t[\033[1;31mFailure\033[0;2m]"
+ echo "[Failure]" >> $OUTPUT
fi
+
+ rm -f $MAKEFILE $TEST_PRO $TEST_APP
done
-rm -f $MAKEFILE $TEST_PRO $TEST_APP
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"
+
+
diff --git a/client/test/testcomboboxsearch.cc b/client/test/testcomboboxsearch.cc
new file mode 100644
index 0000000..84f03c4
--- /dev/null
+++ b/client/test/testcomboboxsearch.cc
@@ -0,0 +1,121 @@
+#include <QtTest/QtTest>
+#include "util.h"
+#include "combobox.h"
+#include <QAbstractItemView>
+#include <QCompleter>
+
+static QString xml =
+ "<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"
+ " <item value=\"thingy\" caption=\"Thingy\"/>\n"
+ " <item value=\"bob\" caption=\"Bob\"/>\n"
+ "</combobox>\n";
+
+static QString xml_default =
+ "<combobox name=\"mycombobox\" type=\"search\" value=\"item2\">\n"
+ " <item value=\"item1\" caption=\"Item 1\"/>\n"
+ " <item value=\"item3\" caption=\"Item 3\"/>\n"
+ " <item value=\"item2\" caption=\"Item 2\"/>\n"
+ " <item value=\"thingy\" caption=\"Thingy\"/>\n"
+ " <item value=\"bob\" caption=\"Bob\"/>\n"
+ "</combobox>\n";
+
+class TestComboBoxSearch: public QObject
+{
+Q_OBJECT
+private slots:
+ void creation() { TEST_CREATION(ComboBox); }
+ void disable() { TEST_DISABLE(ComboBox); }
+
+ void searchFullItem()
+ {
+ QDomDocument doc; doc.setContent(xml);
+ QDomElement e = doc.documentElement();
+ ComboBox cmb(e, NULL);
+
+ // Full item search
+ QTest::keyClicks(&cmb, "Item 2");
+ QCOMPARE(cmb.getValue(), QString("Item 2"));
+ }
+
+ void searchPrefix()
+ {
+ QDomDocument doc; doc.setContent(xml);
+ QDomElement e = doc.documentElement();
+ ComboBox cmb(e, NULL);
+
+ // Item prefix search
+ QTest::keyClicks(&cmb, "T");
+ QCOMPARE(cmb.completer()->currentCompletion(), QString("Thingy"));
+
+ QTest::keyClicks(&cmb, cmb.completer()->currentCompletion());
+ QCOMPARE(cmb.getValue(), QString("Thingy"));
+ }
+
+ void searchNegative()
+ {
+ QDomDocument doc; doc.setContent(xml);
+ QDomElement e = doc.documentElement();
+ ComboBox cmb(e, NULL);
+
+ // Negative search
+ QTest::keyClicks(&cmb, "A");
+ QCOMPARE(cmb.getValue(), 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"));
+ }
+ /* // It is set in MacroWindow generation .. not directly in the Widget.
+ void defaultValue()
+ {
+ QDomDocument doc; doc.setContent(xml_default);
+ QDomElement e = doc.documentElement();
+ ComboBox cmb(e, NULL);
+ QCOMPARE(cmb.getValue(), QString("item2"));
+ }
+ */
+ void changeEmitUser()
+ {
+ QDomDocument doc; doc.setContent(xml);
+ QDomElement e = doc.documentElement();
+ ComboBox cmb(e, NULL);
+ QSignalSpy spy(&cmb, SIGNAL(wasChanged()));
+ QTest::keyClicks(&cmb, "I");
+ QCOMPARE(spy.count(), 1);
+ }
+
+ void changeEmitSystem()
+ {
+ QDomDocument doc; doc.setContent(xml);
+ QDomElement e = doc.documentElement();
+ ComboBox cmb(e, NULL);
+ QSignalSpy spy(&cmb, SIGNAL(wasChanged()));
+ cmb.setValue("some value", "pentominos");
+ QCOMPARE(spy.count(), 1);
+ }
+
+ void changeNoEmitSystem()
+ {
+ QDomDocument doc; doc.setContent(xml);
+ QDomElement e = doc.documentElement();
+ ComboBox cmb(e, NULL);
+ QSignalSpy spy(&cmb, SIGNAL(wasChanged()));
+ cmb.setValue("some value", "pracro");
+ QCOMPARE(spy.count(), 0);
+ }
+};
+
+QTEST_MAIN(TestComboBoxSearch)
+#include "testcomboboxsearch.moc"
+
+
diff --git a/client/test/testcomboboxselect.cc b/client/test/testcomboboxselect.cc
new file mode 100644
index 0000000..5294886
--- /dev/null
+++ b/client/test/testcomboboxselect.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"
+
+
diff --git a/client/test/testlineedit.cc b/client/test/testlineedit.cc
index 4eb886b..c5ab8b3 100644
--- a/client/test/testlineedit.cc
+++ b/client/test/testlineedit.cc
@@ -2,6 +2,8 @@
#include "util.h"
#include "lineedit.h"
+static QString xml = "<lineedit name=\"mylineedit\"/>\n";
+
class TestLineEdit: public QObject
{
Q_OBJECT
@@ -10,46 +12,25 @@ private slots:
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"));
+ {
+ QDomDocument doc; doc.setContent(xml);
+ QDomElement e = doc.documentElement();
+ LineEdit le(e, NULL);
+ QString teststring("hello");
+ QTest::keyClicks(&le, teststring);
+ QCOMPARE(le.getValue(), teststring);
}
+
+ void changeEmits()
+ {
+ QDomDocument doc; doc.setContent(xml);
+ QDomElement e = doc.documentElement();
+ LineEdit le(e, NULL);
+ QSignalSpy spy(&le, SIGNAL(wasChanged()));
+ QTest::keyClicks(&le, "h");
+ QCOMPARE(spy.count(), 1);
+ }
};
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/widgets/combobox.cc b/client/widgets/combobox.cc
index c4a7f13..bf25475 100644
--- a/client/widgets/combobox.cc
+++ b/client/widgets/combobox.cc
@@ -145,7 +145,7 @@ void ComboBox::setValue(QString value, QString source)
int idx = findData(value);
- printf("setValue(\"%s\") - %d\n", value.toStdString().c_str(), idx);
+ // printf("setValue(\"%s\") - %d\n", value.toStdString().c_str(), idx);
ischangingbyuser = false;
setCurrentIndex(idx);