From d48326b56b48173daf0a93223dd31293c280ac63 Mon Sep 17 00:00:00 2001 From: Mark Doffman Date: Sat, 23 Aug 2008 18:56:07 +0100 Subject: [PATCH] 2008-08-23 Mark Doffman * tests/pyatspi/ pyatspi/ Add an action interface and unit test --- pyatspi/__init__.py | 1 + pyatspi/action.py | 18 +++++------ pyatspi/base.py | 4 +-- tests/apps/Makefile.am | 10 +++++- tests/apps/action-app.c | 29 +++++++++++++++++ tests/dummyatk/my-atk-action.c | 2 +- tests/dummyatk/my-atk-action.h | 6 ++-- tests/pyatspi/actiontest.py | 73 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 127 insertions(+), 16 deletions(-) create mode 100644 tests/apps/action-app.c create mode 100644 tests/pyatspi/actiontest.py diff --git a/pyatspi/__init__.py b/pyatspi/__init__.py index acf0da2..ed9ba49 100644 --- a/pyatspi/__init__.py +++ b/pyatspi/__init__.py @@ -21,6 +21,7 @@ import registry from constants import * from accessible import * +from action import * from application import * from component import * from desktop import * diff --git a/pyatspi/action.py b/pyatspi/action.py index d1ab641..4d0c6d4 100644 --- a/pyatspi/action.py +++ b/pyatspi/action.py @@ -34,7 +34,7 @@ class Action(BaseProxy): folders, and others. """ - def doAction(self, *args, **kwargs): + def doAction(self, index): """ doAction: @param : index @@ -43,9 +43,9 @@ class Action(BaseProxy): @return : a boolean indicating success or failure. """ func = self.get_dbus_method("doAction") - return func(*args, **kwargs) + return func(index) - def getDescription(self, *args, **kwargs): + def getDescription(self, index): """ getDescription: @param : index @@ -57,9 +57,9 @@ class Action(BaseProxy): action. """ func = self.get_dbus_method("getDescription") - return func(*args, **kwargs) + return func(index) - def getKeyBinding(self, *args, **kwargs): + def getKeyBinding(self, index): """ getKeyBinding: @param : index @@ -69,9 +69,9 @@ class Action(BaseProxy): action, or an empty string ("") if none exists. """ func = self.get_dbus_method("getKeyBinding") - return func(*args, **kwargs) + return func(index) - def getName(self, *args, **kwargs): + def getName(self, index): """ getName: @param : index @@ -82,10 +82,10 @@ class Action(BaseProxy): @return : a string containing the name of the specified action. """ func = self.get_dbus_method("getName") - return func(*args, **kwargs) + return func(index) def get_nActions(self): - self._pgetter(self._dbus_interface, "nActions") + return self._pgetter(self._dbus_interface, "nActions") def set_nActions(self, value): self._psetter(self._dbus_interface, "nActions", value) _nActionsDoc = \ diff --git a/pyatspi/base.py b/pyatspi/base.py index bcbfb72..e8ed466 100644 --- a/pyatspi/base.py +++ b/pyatspi/base.py @@ -106,8 +106,8 @@ class BaseProxy(Interface): self._pgetter = self.get_dbus_method("Get", dbus_interface="org.freedesktop.DBus.Properties") self._psetter = self.get_dbus_method("Set", dbus_interface="org.freedesktop.DBus.Properties") - def __getattr__(*args, **kwargs): - return object.__getattr__(*args, **kwargs) + def __getattr__(self, attr): + raise AttributeError("\'%s\' has no attribute \'%s\'" % (self.__class__.__name__, attr)) def get_dbus_method(self, *args, **kwargs): method = Interface.get_dbus_method(self, *args, **kwargs) diff --git a/tests/apps/Makefile.am b/tests/apps/Makefile.am index c058f82..7cd93d5 100644 --- a/tests/apps/Makefile.am +++ b/tests/apps/Makefile.am @@ -1,5 +1,8 @@ check_PROGRAMS = test-application -check_LTLIBRARIES = libnoopapp.la libaccessibleapp.la libcomponentapp.la +check_LTLIBRARIES = libnoopapp.la \ + libaccessibleapp.la \ + libcomponentapp.la \ + libactionapp.la test_application_CFLAGS = $(DBUS_GLIB_CFLAGS) \ $(ATK_CFLAGS) \ @@ -31,3 +34,8 @@ libcomponentapp_la_CFLAGS = $(TEST_APP_CFLAGS) libcomponentapp_la_LDFLAGS = $(TEST_APP_LDFLAGS) libcomponentapp_la_LIBADD = $(TEST_APP_LIBADD) libcomponentapp_la_SOURCES = component-app.c + +libactionapp_la_CFLAGS = $(TEST_APP_CFLAGS) +libactionapp_la_LDFLAGS = $(TEST_APP_LDFLAGS) +libactionapp_la_LIBADD = $(TEST_APP_LIBADD) +libactionapp_la_SOURCES = action-app.c diff --git a/tests/apps/action-app.c b/tests/apps/action-app.c new file mode 100644 index 0000000..612cd59 --- /dev/null +++ b/tests/apps/action-app.c @@ -0,0 +1,29 @@ +#include +#include +#include + +static AtkObject *root_accessible; + +G_MODULE_EXPORT void +test_init (gchar *path) +{ + root_accessible = g_object_new(MY_TYPE_ATK_ACTION, NULL); +} + +G_MODULE_EXPORT void +test_next (int argc, char *argv[]) +{ + g_print("Moving to next stage\n"); +} + +G_MODULE_EXPORT void +test_finished (int argc, char *argv[]) +{ + g_print("Test has completed\n"); +} + +G_MODULE_EXPORT AtkObject * +test_get_root (void) +{ + return root_accessible; +} diff --git a/tests/dummyatk/my-atk-action.c b/tests/dummyatk/my-atk-action.c index 1d189fe..363356a 100644 --- a/tests/dummyatk/my-atk-action.c +++ b/tests/dummyatk/my-atk-action.c @@ -121,7 +121,7 @@ static void my_atk_action_instance_init(GTypeInstance *instance, gpointer g_clas { self->actions[i].name = (gchar*)strdup(DEFAULT_ACTION_NAME); self->actions[i].description = (gchar*)strdup(DEFAULT_ACTION_DESCRIPTION); - self->actions[i].keybinding = (gchar*)strdup(DEFAULT_ACTION_KEYBINDING); + self->actions[i].keybinding = g_strdup_printf("%d", i); } self->disposed = FALSE; self->last_performed_action = -1; diff --git a/tests/dummyatk/my-atk-action.h b/tests/dummyatk/my-atk-action.h index 35d7e1d..f33e75d 100644 --- a/tests/dummyatk/my-atk-action.h +++ b/tests/dummyatk/my-atk-action.h @@ -17,9 +17,9 @@ static const gchar* keybinding_note_define = "none"; -#define FIRST_ACTION_NAME "Default action" -#define FIRST_ACTION_DESCRIPTION "This action will be perfomed by default" -#define FIRST_ACTION_KEYBINDING "12345" +#define FIRST_ACTION_NAME "First action" +#define FIRST_ACTION_DESCRIPTION "First action performed" +#define FIRST_ACTION_KEYBINDING "0" #define DEFAULT_NUMBER_ACTIONS 10 #define DEFAULT_ACTION_NAME "Action" diff --git a/tests/pyatspi/actiontest.py b/tests/pyatspi/actiontest.py new file mode 100644 index 0000000..870bf19 --- /dev/null +++ b/tests/pyatspi/actiontest.py @@ -0,0 +1,73 @@ +import dbus +import gobject +import os.path + +from xml.dom import minidom +import os + +from pasytest import PasyTest as _PasyTest + +import pyatspi + +class ActionTest(_PasyTest): + + __tests__ = ["setup", + "test_nActions", + "test_getDescription", + "test_getName", + "test_doAction", + "test_getKeyBinding", + "teardown", + ] + + def __init__(self, bus, path): + _PasyTest.__init__(self, "Action", False) + self._bus = bus + self._path = path + + def setup(self, test): + self._registry = pyatspi.registry.Registry(self._path) + self._desktop = self._registry.getDesktop(0) + + def test_nActions(self, test): + root = self._desktop[0] + root = root.queryAction() + nact = root.nActions + test.assertEqual(nact, 10, "nActions expected %d, recieved %d" % (10, nact)) + + def test_getName(self, test): + root = self._desktop[0] + root = root.queryAction() + name = root.getName(0) + test.assertEqual(name, "First action", "Name expected %s, recieved %s" % ("First action", name)) + name = root.getName(1) + test.assertEqual(name, "Action", "Name expected %s, recieved %s" % ("Action", name)) + + def test_getDescription(self, test): + root = self._desktop[0] + root = root.queryAction() + description = root.getDescription(0) + expected = "First action performed" + test.assertEqual(description, expected, "Description expected %s, recieved %s" % (expected, description)) + description = root.getDescription(1) + expected = "Description of action" + test.assertEqual(description, expected, "Description expected %s, recieved %s" % (expected, description)) + + def test_doAction(self, test): + root = self._desktop[0] + root = root.queryAction() + #TODO have event emitted to check action has been performed + for i in range(0, root.nActions): + root.doAction(i) + + def test_getKeyBinding(self, test): + root = self._desktop[0] + root = root.queryAction() + for i in range(0, root.nActions): + keybinding = root.getKeyBinding(i) + expected = "%s" % (i,) + test.assertEqual(keybinding, expected, + "Keybinding expected %s, recieved %s" % (expected, keybinding)) + + def teardown(self, test): + pass -- 2.7.4