aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/client/CMakeLists.txt8
-rw-r--r--tests/client/actiongrouptest.cpp9
-rw-r--r--tests/client/convertertest.cpp28
-rw-r--r--tests/client/modeltest.cpp20
-rwxr-xr-xtests/client/script_actiongrouptest.py5
-rwxr-xr-xtests/client/script_modeltest.py1
-rw-r--r--tests/script/dbusmenuscript.cpp11
-rw-r--r--tests/script/dbusmenuscript.h2
-rw-r--r--tests/script/menuscript.py15
9 files changed, 84 insertions, 15 deletions
diff --git a/tests/client/CMakeLists.txt b/tests/client/CMakeLists.txt
index d946fad..392437c 100644
--- a/tests/client/CMakeLists.txt
+++ b/tests/client/CMakeLists.txt
@@ -8,9 +8,15 @@ macro(declare_test testname)
${GIO_LDFLAGS}
)
+ if(TEST_XML_OUTPUT)
+ set(TEST_ARGS -p -xunitxml -p -o -p test_${testname}.xml)
+ else()
+ set(TEST_ARGS "")
+ endif()
+
add_test(${testname}
${DBUS_RUNNER}
- --task ${CMAKE_CURRENT_BINARY_DIR}/${testname} -p -xunitxml -p -o -p test_${testname}.xml --task-name Client
+ --task ${CMAKE_CURRENT_BINARY_DIR}/${testname} ${TEST_ARGS} --task-name Client
--task ${CMAKE_CURRENT_SOURCE_DIR}/script_${testname}.py --task-name Server
--ignore-return)
set_tests_properties(${testname} PROPERTIES
diff --git a/tests/client/actiongrouptest.cpp b/tests/client/actiongrouptest.cpp
index 6598d2e..d187ea7 100644
--- a/tests/client/actiongrouptest.cpp
+++ b/tests/client/actiongrouptest.cpp
@@ -141,11 +141,16 @@ private Q_SLOTS:
QStateAction *act = m_actionGroup.action(action.toString());
QVERIFY(act);
- act->trigger();
+ // test action name
+ QCOMPARE(act->property("name").toString(), QString("Menu1Act"));
+
+ act->activate(QVariant("42"));
// wait for dbus propagation
QTest::qWait(500);
- QCOMPARE(m_script.popActivatedAction(), QString("Menu1Act"));
+ QPair<QString, QVariant> result = m_script.popActivatedAction();
+ QCOMPARE(result.first, QString("Menu1Act"));
+ QCOMPARE(result.second.toString(), QString("42"));
}
/*
diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp
index 5301653..f382332 100644
--- a/tests/client/convertertest.cpp
+++ b/tests/client/convertertest.cpp
@@ -88,6 +88,34 @@ private Q_SLOTS:
// Map
QVERIFY(compare(QVariantMap(), G_VARIANT_TYPE_VARDICT));
+
+ }
+
+ void testTupleConversion()
+ {
+ QVariantList qTuple;
+ qTuple << 1 << "2" << 3.3;
+
+ GVariant *gTuple = Converter::toGVariant(qTuple);
+ QVERIFY(g_variant_type_is_tuple(g_variant_get_type(gTuple)));
+ QCOMPARE(g_variant_n_children(gTuple), (gsize)3);
+
+ GVariant *v = g_variant_get_child_value(gTuple, 0);
+ int v0 = g_variant_get_int32(v);
+ QCOMPARE(v0, 1);
+ g_variant_unref(v);
+
+ v = g_variant_get_child_value(gTuple, 1);
+ const gchar *v1 = g_variant_get_string(v, NULL);
+ QCOMPARE(QString(v1), QString("2"));
+ g_variant_unref(v);
+
+ v = g_variant_get_child_value(gTuple, 2);
+ gdouble v2 = g_variant_get_double(v);
+ QCOMPARE(v2, 3.3);
+ g_variant_unref(v);
+
+ g_variant_unref(gTuple);
}
};
diff --git a/tests/client/modeltest.cpp b/tests/client/modeltest.cpp
index c6b2f0e..8be92a6 100644
--- a/tests/client/modeltest.cpp
+++ b/tests/client/modeltest.cpp
@@ -25,6 +25,19 @@
#include <QtTest>
#include <QDebug>
+extern "C" {
+#include <gio/gio.h>
+}
+
+class TestMenuModel : public QMenuModel
+{
+public:
+ TestMenuModel(GMenuModel *other, QObject *parent=0)
+ : QMenuModel(other, parent)
+ {
+ }
+};
+
class ModelTest : public QObject
{
Q_OBJECT
@@ -218,6 +231,12 @@ private Q_SLOTS:
QCOMPARE(v.type(), QVariant::String);
QCOMPARE(v.toString(), QString("dança"));
+ // Tuple
+ v = extra["tuple"];
+ QVariantList lst;
+ lst << "1" << 2 << 3.3;
+ QCOMPARE(v.type(), QVariant::List);
+ QCOMPARE(v.toList(), lst);
}
/*
@@ -241,7 +260,6 @@ private Q_SLOTS:
delete model;
}
-
};
QTEST_MAIN(ModelTest)
diff --git a/tests/client/script_actiongrouptest.py b/tests/client/script_actiongrouptest.py
index 2af4841..bb54dae 100755
--- a/tests/client/script_actiongrouptest.py
+++ b/tests/client/script_actiongrouptest.py
@@ -3,10 +3,11 @@
import time
from gi.repository import GLib
from menuscript import Script, ActionList, MENU_OBJECT_PATH
+from gi._gi import variant_type_from_string
al = ActionList(MENU_OBJECT_PATH)
-al.appendItem("Menu0", "Menu0Act")
-al.appendItem("Menu1", "Menu1Act")
+al.appendItem("Menu0", "Menu0Act", actionStateType=variant_type_from_string('s'))
+al.appendItem("Menu1", "Menu1Act", actionStateType=variant_type_from_string('s'))
al.removeItem("1", "Menu1Act")
t = Script.create(al)
diff --git a/tests/client/script_modeltest.py b/tests/client/script_modeltest.py
index 72c294c..9f5df9c 100755
--- a/tests/client/script_modeltest.py
+++ b/tests/client/script_modeltest.py
@@ -24,6 +24,7 @@ al.appendItem("Menu0", "Menu0Act", None, None, {'x-boolean' : GLib.Variant('b',
'x-string' : GLib.Variant('s', '42'),
'x-utf8' : GLib.Variant('s', 'dança'),
'x-map' : GLib.Variant('a{sv}', pmap),
+ 'x-tuple' : GLib.Variant('(sid)', ("1", 2, 3.3)),
})
al.appendItem("Menu1", "Menu1Act")
diff --git a/tests/script/dbusmenuscript.cpp b/tests/script/dbusmenuscript.cpp
index b190d5b..8fa46c7 100644
--- a/tests/script/dbusmenuscript.cpp
+++ b/tests/script/dbusmenuscript.cpp
@@ -92,15 +92,20 @@ void DBusMenuScript::run()
}
}
-QString DBusMenuScript::popActivatedAction()
+QPair<QString, QVariant> DBusMenuScript::popActivatedAction()
{
if (m_script) {
QDBusMessage reply = m_script->call("popActivatedAction");
if (reply.arguments().count() > 0) {
- return reply.arguments()[0].toString();
+ QVariant value;
+ QString name = reply.arguments()[0].toString();
+ if (reply.arguments().count() > 1) {
+ value = reply.arguments()[1];
+ }
+ return qMakePair(name, value);
}
}
- return QString();
+ return qMakePair(QString(), QVariant());
}
diff --git a/tests/script/dbusmenuscript.h b/tests/script/dbusmenuscript.h
index 8a93e83..862686c 100644
--- a/tests/script/dbusmenuscript.h
+++ b/tests/script/dbusmenuscript.h
@@ -47,7 +47,7 @@ public:
void publishMenu();
void unpublishMenu();
- QString popActivatedAction();
+ QPair<QString, QVariant> popActivatedAction();
private:
QDBusInterface *m_script;
diff --git a/tests/script/menuscript.py b/tests/script/menuscript.py
index 60cb33b..542308a 100644
--- a/tests/script/menuscript.py
+++ b/tests/script/menuscript.py
@@ -53,8 +53,9 @@ class Script(dbus.service.Object):
self._list.walk()
steps -= 1
+ """ TODO: We only support string states for now """
@dbus.service.method(dbus_interface=INTERFACE_NAME,
- in_signature='', out_signature='s')
+ in_signature='', out_signature='ss')
def popActivatedAction(self):
return self._list._activatedActions.pop(0)
@@ -94,7 +95,7 @@ class Action(object):
parent.append_item(item)
# Action
- act = Gio.SimpleAction.new(self._kargs['actionName'], None)
+ act = Gio.SimpleAction.new(self._kargs['actionName'], self._kargs['actionStateType'])
act.connect('activate', self._list._onActionActivated)
self._list._rootAction.insert(act)
@@ -135,13 +136,14 @@ class ActionList(object):
self._rootAction = None
self._activatedActions = []
- def appendItem(self, label, actionName, link=None, parentId=None, properties=None):
+ def appendItem(self, label, actionName, link=None, parentId=None, properties=None, actionStateType=None):
self._actions.append(Action(self, 'append',
parentId=parentId,
label=label,
actionName=actionName,
link=link,
- properties=properties))
+ properties=properties,
+ actionStateType=actionStateType))
def removeItem(self, menuId, actionName=None):
self._actions.append(Action(self, 'remove',
@@ -205,7 +207,10 @@ class ActionList(object):
if self._ownNameID:
Gio.bus_unown_name(self._ownNameID)
self._ownNameID = None
+
+ self._root = None
+ self._rootAction = None
self._restore()
def _onActionActivated(self, action, parameter):
- self._activatedActions.append(action.get_name())
+ self._activatedActions.append((action.get_name(), parameter.get_string()))