pos = 0
while (lower):
if (1L)&lower:
- #TODO Return the state objects rather than integers.
- states.append(pos)
+ states.append(StateType(pos))
pos+=1
+ lower >>= 1
+
+ pos = 32
while (upper):
if (1L)&upper:
- #TODO return the state objects rather than integers.
- states.append(pos)
+ states.append(StateType(pos))
+ pos+=1
+ upper >>= 1
return StateSet(*states)
@param states: States to add immediately
@type states: list
"""
- map(self.add, states)
self.states = set()
+ map(self.add, states)
def contains(self, state):
"""
@param states: State(s) to add
@type states: Accessibility.StateType
"""
- self.states.add(state)
+ for state in states:
+ self.states.add(state)
def remove(self, state):
"""
static AtkObject *root_accessible;
+static AtkStateType states[] =
+{
+ ATK_STATE_MULTI_LINE,
+ ATK_STATE_MODAL,
+ ATK_STATE_INDETERMINATE,
+ ATK_STATE_SUPPORTS_AUTOCOMPLETION,
+ ATK_STATE_VERTICAL
+};
+
#define OBJECT_TEST_1 "accessible-test.xml"
G_MODULE_EXPORT void
test_init (gchar *path)
{
+ AtkStateSet *ss;
gchar *td;
if (path == NULL)
td = g_build_path(G_DIR_SEPARATOR_S, tdata_path, OBJECT_TEST_1, NULL);
root_accessible = ATK_OBJECT(atk_object_xml_parse(td));
g_free(td);
+
+ ss = atk_object_ref_state_set(ATK_OBJECT(root_accessible));
+ atk_state_set_add_states(ss, states, 5);
+ g_object_unref(G_OBJECT(ss));
}
G_MODULE_EXPORT void
+#include <stdio.h>
#include <atk/atk.h>
#include "my-atk-object.h"
return i;//if error, i will be equal to -1
}
+static AtkStateSet *my_atk_object_ref_state_set(AtkObject *accessible)
+{
+ MyAtkObject *obj = MY_ATK_OBJECT(accessible);
+
+ if (obj->state_set == NULL)
+ obj->state_set = atk_state_set_new();
+ return g_object_ref(G_OBJECT(obj->state_set));
+}
+
+static AtkAttributeSet *my_atk_object_get_attributes (AtkObject *accessible)
+{
+ MyAtkObject *obj = MY_ATK_OBJECT(accessible);
+ AtkAttributeSet *rs = obj->attributes = NULL;
+ AtkAttribute *a, *b, *c;
+
+ a = g_new(AtkAttribute, 1);
+ b = g_new(AtkAttribute, 1);
+ c = g_new(AtkAttribute, 1);
+
+ a->name = g_strdup("foo");
+ a->value = g_strdup("bar");
+ b->name = g_strdup("baz");
+ b->value = g_strdup("qux");
+ c->name = g_strdup("quux");
+ c->value = g_strdup("corge");
+
+ rs = g_slist_append(rs, (gpointer) a);
+ rs = g_slist_append(rs, (gpointer) b);
+ rs = g_slist_append(rs, (gpointer) c);
+}
+
//function, needed in instance_finalize()
static void my_unref1(gpointer data, gpointer user_data)
{
atkObjectClass->get_n_children = my_atk_object_get_n_children;
atkObjectClass->ref_child = my_atk_object_ref_child;
atkObjectClass->get_index_in_parent = my_atk_object_get_index_in_parent;
+ atkObjectClass->ref_state_set = my_atk_object_ref_state_set;
+ atkObjectClass->get_attributes = my_atk_object_get_attributes;
atk_object_parent_class = g_type_class_peek_parent(g_class);
}
MyAtkObject *self = (MyAtkObject*)obj;
self->children = g_ptr_array_sized_new(10);
+ self->attributes = g_slist_alloc();
}
GType my_atk_object_get_type()
{
AtkObject parent;
//array of children
+ AtkStateSet *state_set;
+ AtkAttributeSet *attributes;
GPtrArray* children;
gint id;
};
from pasytest import PasyTest as _PasyTest
import pyatspi
+from pyatspi import StateSet
+
+st = [pyatspi.STATE_MULTI_LINE,
+ pyatspi.STATE_MODAL,
+ pyatspi.STATE_INDETERMINATE,
+ pyatspi.STATE_SUPPORTS_AUTOCOMPLETION,
+ pyatspi.STATE_VERTICAL,]
def _createNode(accessible, parentElement):
e = minidom.Element("accessible")
def test_getAttributes(self, test):
root = self._desktop.getChildAtIndex(0)
- #TODO The AttributeSet test needs expanding. Check attributes are passed correctly.
attr = root.getAttributes()
+ res = ["foo:bar", "baz:qux", "quux:corge"]
+ test.assertEqual(attr, res, "Attributes expected %s, recieved %s" % (attr, res))
+
def test_parent(self, test):
root = self._desktop.getChildAtIndex(0)
"Expected roleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
def test_getState(self, test):
- # Complete test of StateSet interface is separate
root = self._desktop.getChildAtIndex(0)
state = root.getState()
- list = state.getStates()
+ res = StateSet(*st)
+ if not res.equals(state):
+ test.fail("States not reported correctly")
def test_childCount(self, test):
root = self._desktop.getChildAtIndex(0)
]
def __init__(self, bus, path):
- _PasyTest.__init__(self, "Accessible", False)
+ _PasyTest.__init__(self, "Component", False)
self._bus = bus
self._path = path
]
def __init__(self, bus, path):
- _PasyTest.__init__(self, "Accessible", False)
+ _PasyTest.__init__(self, "Desktop", False)
self._bus = bus
self._path = path
--- /dev/null
+import dbus
+import gobject
+import os.path
+
+from xml.dom import minidom
+import os
+
+from pasytest import PasyTest as _PasyTest
+
+import pyatspi
+from pyatspi import StateSet
+
+os = [pyatspi.STATE_MULTISELECTABLE,
+ pyatspi.STATE_PRESSED,
+ pyatspi.STATE_SHOWING,
+ pyatspi.STATE_TRANSIENT,
+ pyatspi.STATE_COLLAPSED,
+ pyatspi.STATE_EDITABLE,]
+
+class StateTest(_PasyTest):
+
+ __tests__ = ["setup",
+ "test_contains",
+ "test_add",
+ "test_remove",
+ "test_equals",
+ "test_compare",
+ "test_isEmpty",
+ "test_getStates",
+ "teardown",
+ ]
+
+ def __init__(self, bus, path):
+ _PasyTest.__init__(self, "State", False)
+
+ def setup(self, test):
+ pass
+
+ def test_contains(self, test):
+ state = StateSet(*os)
+ if not state.contains(pyatspi.STATE_PRESSED):
+ test.fail("Does not find contained state")
+ if state.contains(pyatspi.STATE_ACTIVE):
+ test.fail("Finds state not contained")
+
+ def test_add(self, test):
+ state = StateSet()
+ state.add(pyatspi.STATE_PRESSED)
+ if not state.contains(pyatspi.STATE_PRESSED):
+ test.fail("State not added")
+
+ def test_remove(self, test):
+ state = StateSet(*os)
+ state.remove(pyatspi.STATE_PRESSED)
+ if state.contains(pyatspi.STATE_PRESSED):
+ test.fail("State not removed")
+
+ def test_equals(self, test):
+ one = StateSet(*os)
+ two = StateSet(*os)
+ if not one.equals(two):
+ test.fail("Same states not found equal")
+ two.remove(pyatspi.STATE_PRESSED)
+ if two.equals(one):
+ test.fail("Unequal states found equal")
+
+ def test_isEmpty(self, test):
+ emp = StateSet()
+ if not emp.isEmpty():
+ test.fail("Empty state found non-empty")
+ emp.add(pyatspi.STATE_PRESSED)
+ if emp.isEmpty():
+ test.fail("State incorrectly found empty")
+
+ def test_compare(self, test):
+ one = StateSet(*os)
+ two = StateSet(*os)
+
+ onemtwo = one.compare(two)
+ if not onemtwo.isEmpty():
+ test.fail("Equal states when compared yeilds non-empty state")
+
+ one.add(pyatspi.STATE_ACTIVE)
+ onemtwo = one.compare(two)
+
+ act = StateSet(pyatspi.STATE_ACTIVE)
+ if not onemtwo.equals(act):
+ test.fail("Compared states do not yeild correct state")
+
+ def test_getStates(self, test):
+ state = StateSet(*os)
+
+ states = state.getStates()
+ cone = set(states)
+ ctwo = set(os)
+
+ if not (cone.issubset(ctwo) and ctwo.issubset(cone)):
+ test.fail("States not reported correctly")
+
+ def teardown(self, test):
+ pass