From 5d755f40091afb5e1f2c4db1c7ba75c36e2d4a74 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 23 Nov 2012 10:22:04 -0300 Subject: Create unit test for name property and activate function. --- tests/client/actiongrouptest.cpp | 9 +++++++-- tests/client/script_actiongrouptest.py | 5 +++-- tests/script/dbusmenuscript.cpp | 11 ++++++++--- tests/script/dbusmenuscript.h | 2 +- tests/script/menuscript.py | 12 +++++++----- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/tests/client/actiongrouptest.cpp b/tests/client/actiongrouptest.cpp index 3e0065f..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->activate(); + // 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 result = m_script.popActivatedAction(); + QCOMPARE(result.first, QString("Menu1Act")); + QCOMPARE(result.second.toString(), QString("42")); } /* 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/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 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 popActivatedAction(); private: QDBusInterface *m_script; diff --git a/tests/script/menuscript.py b/tests/script/menuscript.py index 60cb33b..d30adc5 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', @@ -208,4 +210,4 @@ class ActionList(object): self._restore() def _onActionActivated(self, action, parameter): - self._activatedActions.append(action.get_name()) + self._activatedActions.append((action.get_name(), parameter.get_string())) -- cgit v1.2.3