2009-27-09 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / tests / pyatspi / accessibletest.py
index 3aa4ca3..6cd2cdd 100644 (file)
@@ -8,6 +8,13 @@ import os
 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")
@@ -48,14 +55,16 @@ class AccessibleTest(_PasyTest):
                self._path = path
 
        def setup(self, test):
-               self._cache = pyatspi.TestApplicationCache(self._bus, self._path)
+               self._registry = pyatspi.Registry()
+               print self._path
+               self._desktop = self._registry.getDesktop(0)
 
        def test_name(self, test):
-               root = self._cache.root
+               root = self._desktop.getChildAtIndex(0)
                test.assertEqual(root.name, "main", "Expected name - \"main\". Recieved - \"%s\"" % (root.name,))
 
        def test_getChildAtIndex(self, test):
-               root = self._cache.root
+               root = self._desktop.getChildAtIndex(0)
                a = root.getChildAtIndex(0)
                test.assertEqual(a.name, "gnome-settings-daemon",
                                         "Expected name - \"gnome-settings-daemon\". Recieved - \"%s\"" % (a.name,))
@@ -67,7 +76,7 @@ class AccessibleTest(_PasyTest):
                                         "Expected name - \"nautilus\". Recieved - \"%s\"" % (c.name,))
                
        def test_isEqual(self, test):
-               root = self._cache.root
+               root = self._desktop.getChildAtIndex(0)
 
                a = root.getChildAtIndex(1)
                if not a.isEqual(a):
@@ -86,7 +95,7 @@ class AccessibleTest(_PasyTest):
                        test.fail("Different accessibles found equal")
 
        def test_getApplication(self, test):
-               root = self._cache.root
+               root = self._desktop.getChildAtIndex(0)
                application = root.getApplication()
                if not root.isEqual(application):
                        test.fail("Root accessible does not provide itself as its Application")
@@ -98,12 +107,15 @@ class AccessibleTest(_PasyTest):
 
 
        def test_getAttributes(self, test):
-               root = self._cache.root
-               #TODO The AttributeSet test needs expanding. Check attributes are passed correctly.
+               root = self._desktop.getChildAtIndex(0)
                attr = root.getAttributes()
+               res = ["foo:bar", "baz:qux", "quux:corge"]
+                attr.sort()
+                res.sort()
+               test.assertEqual(attr, res, "Attributes expected %s, recieved %s" % (attr, res))
 
        def test_parent(self, test):
-               root = self._cache.root
+               root = self._desktop.getChildAtIndex(0)
 
                a = root.getChildAtIndex(1)
                pa = a.parent
@@ -111,14 +123,14 @@ class AccessibleTest(_PasyTest):
                        test.fail("Child does not correctly report its parent")
 
        def test_getIndexInParent(self, test):
-               root = self._cache.root
+               root = self._desktop.getChildAtIndex(0)
 
                for i in range(0, root.childCount):
                        child = root.getChildAtIndex(i)
                        test.assertEqual(i, child.getIndexInParent(), "Childs index in parent reported incorrectly")
 
        def test_getLocalizedRoleName(self, test):
-               root = self._cache.root
+               root = self._desktop.getChildAtIndex(0)
 
                ans = "window"
                res = root.getLocalizedRoleName()
@@ -133,17 +145,17 @@ class AccessibleTest(_PasyTest):
                                 "Expected LocalizedRoleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
 
        def test_getRelationSet(self, test):
-               root = self._cache.root
+               root = self._desktop.getChildAtIndex(0)
                # Complete test of Relation interface is separate
                rset = root.getRelationSet()
 
        def test_getRole(self, test):
-               root = self._cache.root
+               root = self._desktop.getChildAtIndex(0)
                test.assertEqual(root.getRole(), 69,
-                                "Expected role - \"69\". Recieved - \"%d\"" % (root.getRole(),))
+                                "Expected role - \"69\". Recieved - \"%d\"" % (int(root.getRole()),))
 
        def test_getRoleName(self, test):
-               root = self._cache.root
+               root = self._desktop.getChildAtIndex(0)
 
                ans = "window"
                res = root.getRoleName()
@@ -158,18 +170,19 @@ class AccessibleTest(_PasyTest):
                                 "Expected roleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
 
        def test_getState(self, test):
-               # Complete test of StateSet interface is separate
-               root = self._cache.root
+               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._cache.root
+               root = self._desktop.getChildAtIndex(0)
                test.assertEqual(root.childCount, 11,
                                 "Expected role - \"11\". Recieved - \"%d\"" % (root.childCount,))
 
        def test_description(self, test):
-               root = self._cache.root
+               root = self._desktop.getChildAtIndex(0)
                description = "The main accessible object, root of the accessible tree"
                test.assertEqual(root.description, description,
                                 "Expected description - \"%s\". Recieved - \"%s\"" % (description, root.description,))
@@ -189,7 +202,7 @@ class AccessibleTest(_PasyTest):
                It checks a tree of these values is correctly
                passed from Application to AT.
                """
-               root = self._cache.root
+               root = self._desktop.getChildAtIndex(0)
 
                doc = minidom.Document()
                _createNode(root, doc)