2008-08-18 Mark Doffman <mark.doffman@codethink.co.uk>
authorMark Doffman <mdoff@silver-wind.(none)>
Mon, 18 Aug 2008 14:02:48 +0000 (15:02 +0100)
committerMark Doffman <mdoff@silver-wind.(none)>
Mon, 18 Aug 2008 14:02:48 +0000 (15:02 +0100)
* tests/data/
Add a description attribute to the root accessible
for testing the description property.

* tests/dummyatk/my-atk-object.c
Fix the add_child function to correctly set
a childs parent.

* tests/pyatspi/Pasy.py
Pass a test function its own test object.

* tests/pyatspi/accessibletest.py
Add getState test to the Accessible unit test.

* tests/pyatspi/testrunner.py
Modify to enable waiting on test application
for debug.

tests/data/object-test-stage1-results.xml
tests/data/object-test-stage1.xml
tests/dummyatk/my-atk-object.c
tests/pyatspi/accessibletest.py
tests/pyatspi/pasytest/Pasy.py
tests/pyatspi/testrunner.py

index 9a0ebd3..a522187 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" ?>
-<accessible description="" name="main" role="69">
+<accessible description="The main accessible object, root of the accessible tree" name="main" role="69">
        <accessible description="" name="gnome-settings-daemon" role="79"/>
        <accessible description="" name="gnome-panel" role="79">
                <accessible description="" name="Bottom Expanded Edge Panel" role="25"/>
index 54729ca..c881873 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" ?>
-<accessible description="" name="main" role="68">
+<accessible description="The main accessible object, root of the accessible tree" name="main" role="68">
        <accessible description="" name="gnome-settings-daemon" role="77"/>
        <accessible description="" name="gnome-panel" role="77">
                <accessible description="" name="Bottom Expanded Edge Panel" role="24"/>
index fec5f99..23f6c65 100644 (file)
@@ -9,6 +9,8 @@ void my_atk_object_add_child(MyAtkObject* parent, MyAtkObject* child)
 {
     g_ptr_array_add(parent->children, child);
     g_object_ref_sink(child);
+
+    atk_object_set_parent(ATK_OBJECT(child), ATK_OBJECT(parent));
     
     g_signal_emit_by_name(parent, "children-changed::add",
         parent->children->len - 1, child);
@@ -31,8 +33,7 @@ void my_atk_object_remove_child(MyAtkObject* parent, MyAtkObject* child)
 
 static void my_atk_object_set_parent(AtkObject *accessible, AtkObject *parent)
 {
-    //applicable only with corresponding type of parent
-    g_return_if_fail(parent == NULL || MY_IS_ATK_OBJECT(parent));
+    g_return_if_fail(parent != NULL);
 
     MyAtkObject *self = MY_ATK_OBJECT(accessible);
     AtkObject *parent_old = (atk_object_get_parent(accessible));
@@ -50,10 +51,6 @@ static void my_atk_object_set_parent(AtkObject *accessible, AtkObject *parent)
     {
         my_atk_object_remove_child((MyAtkObject*)parent_old, self);
     }
-    if(parent != NULL)
-    {
-        my_atk_object_add_child((MyAtkObject*)parent, self);
-    }
 }
 
 static gint my_atk_object_get_n_children(AtkObject *accessible)
index b7b2c8c..a504cca 100644 (file)
@@ -23,17 +23,154 @@ def _createNode(accessible, parentElement):
 
 class AccessibleTest(_PasyTest):
 
-       __tests__ = ["setup", "tree"]
+       __tests__ = ["setup",
+                    "test_name",
+                    "test_getChildAtIndex",
+                    "test_isEqual",
+                    "test_getApplication",
+                    "test_getAttributes",
+                    "test_parent",
+                    "test_getIndexInParent",
+                    "test_getLocalizedRoleName",
+                    "test_getRelationSet",
+                    "test_getRole",
+                    "test_getRoleName",
+                    "test_getState",
+                    "test_childCount",
+                    "test_description",
+                    "test_tree",
+                    "teardown",
+                    ]
 
        def __init__(self, bus, path):
                _PasyTest.__init__(self, "Accessible", False)
                self._bus = bus
                self._path = path
 
-       def setup(self):
+       def setup(self, test):
                self._cache = pyatspi.TestApplicationCache(self._bus, self._path)
 
-       def tree(self):
+       def test_name(self, test):
+               root = self._cache.root
+               test.assertEqual(root.name, "main", "Expected name - \"main\". Recieved - \"%s\"" % (root.name,))
+
+       def test_getChildAtIndex(self, test):
+               root = self._cache.root
+               a = root.getChildAtIndex(0)
+               test.assertEqual(a.name, "gnome-settings-daemon",
+                                        "Expected name - \"gnome-settings-daemon\". Recieved - \"%s\"" % (a.name,))
+               b = root.getChildAtIndex(1)
+               test.assertEqual(b.name, "gnome-panel",
+                                        "Expected name - \"gnome-panel\". Recieved - \"%s\"" % (b.name,))
+               c = root.getChildAtIndex(2)
+               test.assertEqual(c.name, "nautilus",
+                                        "Expected name - \"nautilus\". Recieved - \"%s\"" % (c.name,))
+               
+       def test_isEqual(self, test):
+               root = self._cache.root
+
+               a = root.getChildAtIndex(1)
+               if not a.isEqual(a):
+                       test.fail("Same accessible found unequal to self")
+
+               b = root.getChildAtIndex(1)
+               if not a.isEqual(b):
+                       test.fail("Similar accessibles found unequal")
+               if not b.isEqual(a):
+                       test.fail("Similar accessibles found unequal")
+
+               c = root.getChildAtIndex(2)
+               if c.isEqual(a):
+                       test.fail("Different accessibles found equal")
+               if a.isEqual(c):
+                       test.fail("Different accessibles found equal")
+
+       def test_getApplication(self, test):
+               root = self._cache.root
+               application = root.getApplication()
+               if not root.isEqual(application):
+                       test.fail("Root accessible does not provide itself as its Application")
+
+               a = root.getChildAtIndex(1)
+               application = a.getApplication()
+               if not root.isEqual(application):
+                       test.fail("Child accessible does not provide the root as its Application")
+
+
+       def test_getAttributes(self, test):
+               pass
+
+       def test_parent(self, test):
+               root = self._cache.root
+
+               a = root.getChildAtIndex(1)
+               pa = a.parent
+               if not root.isEqual(pa):
+                       test.fail("Child does not correctly report its parent")
+
+       def test_getIndexInParent(self, test):
+               root = self._cache.root
+
+               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
+
+               ans = "window"
+               res = root.getLocalizedRoleName()
+               test.assertEqual(ans, res,
+                                "Expected LocalizedRoleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
+
+               a = root.getChildAtIndex(1)
+               a = a.getChildAtIndex(0)
+               ans = "window"
+               res = a.getLocalizedRoleName()
+               test.assertEqual(ans, res,
+                                "Expected LocalizedRoleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
+
+       def test_getRelationSet(self, test):
+               pass
+
+       def test_getRole(self, test):
+               root = self._cache.root
+               test.assertEqual(root.getRole(), 69,
+                                "Expected role - \"69\". Recieved - \"%d\"" % (root.getRole(),))
+
+       def test_getRoleName(self, test):
+               root = self._cache.root
+
+               ans = "window"
+               res = root.getRoleName()
+               test.assertEqual(ans, res,
+                                "Expected roleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
+
+               a = root.getChildAtIndex(1)
+               a = a.getChildAtIndex(0)
+               ans = "window"
+               res = a.getRoleName()
+               test.assertEqual(ans, res,
+                                "Expected roleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
+
+       def test_getState(self, test):
+               # Complete test of StateSet interface is separate
+               root = self._cache.root
+               state = root.getState()
+               list = state.getStates()
+
+       def test_childCount(self, test):
+               root = self._cache.root
+               test.assertEqual(root.childCount, 11,
+                                "Expected role - \"11\". Recieved - \"%d\"" % (root.childCount,))
+
+       def test_description(self, test):
+               root = self._cache.root
+               description = "The main accessible object, root of the accessible tree"
+               test.assertEqual(root.description, description,
+                                "Expected description - \"%s\". Recieved - \"%s\"" % (description, root.description,))
+
+       def test_tree(self, test):
                """
                This is a mild stress test for the 
                methods:
@@ -59,4 +196,7 @@ class AccessibleTest(_PasyTest):
                file = open(correct)
                cstring = file.read()
                
-               self.assertEqual(answer, cstring, "Object tree not passed correctly")
+               test.assertEqual(answer, cstring, "Object tree not passed correctly")
+
+       def teardown(self, test):
+               pass
index 166c3e1..80318ee 100644 (file)
@@ -49,6 +49,10 @@ class PasyTestStep(object):
                if a != b:
                        self.fail(msg)
 
+       def assertNotEqual(self, a, b, msg):
+               if a == b:
+                       self.fail(msg)
+
        def run(self):
                self._state = PASY_TEST_IN_PROGRESS
                self.entry()
@@ -59,7 +63,7 @@ class PasyTestStep(object):
                elif self._state == PASY_TEST_FAIL:
                        return "%s - FAILED - %s" % (self._name, self.failMsg)
                else:
-                       return "%s - INCOMPLETE" %s (self._name,)
+                       return "%s - INCOMPLETE" % (self._name,)
 
        @property
        def state(self):
@@ -73,7 +77,7 @@ class PasyTestFunc(PasyTestStep):
 
        def entry(self):
                try:
-                       self._func()
+                       self._func(self)
                except Exception, e:
                        self.fail(e.message)
                        traceback.print_exc()
@@ -130,7 +134,7 @@ class PasyTest(PasyTestStep):
                if self._state == PASY_TEST_WIN:
                        header =  "%s - PASSED" % (self._name,)
                elif self._state == PASY_TEST_FAIL:
-                       header =  "%s - FAILED - %s" % (self._name, self.failMsg)
+                       header =  "%s - FAILED" % (self._name,)
                else:
                        header =  "%s - INCOMPLETE" %s (self._name,)
 
index efd9289..b74929e 100755 (executable)
@@ -13,7 +13,7 @@ from dbus.mainloop.glib import DBusGMainLoop
 
 DBusGMainLoop(set_as_default=True)
 
-def run_test_app(module_name, dbus_name=None):
+def run_test_app(module_name, dbus_name=None, wait_for_debug=False):
        import os
        from subprocess import Popen
 
@@ -50,7 +50,7 @@ def run_test_app(module_name, dbus_name=None):
        
        To continue the test press ENTER.\n\n
        """
-       if ("TEST_APP_WAIT_FOR_DEBUG" in os.environ.keys()):
+       if (wait_for_debug):
                raw_input(wait_message % (module_name, pop.pid))
 
 def main(argv):
@@ -58,12 +58,13 @@ def main(argv):
        parser.add_option("-l", "--library", dest="test_library")
        parser.add_option("-m", "--module", dest="test_module")
        parser.add_option("-n", "--name", dest="test_name")
+       parser.add_option("-w", "--wait", action="store_true", dest="wait", default=False)
        (options, args) = parser.parse_args()
 
        bus = dbus.SessionBus()
        name = "test.atspi.R" + str(randint(1, 1000)) 
 
-       app = run_test_app(options.test_library, name)
+       app = run_test_app(options.test_library, name, wait_for_debug=options.wait)
        time.sleep(1)
        print "Started test app on bus name %s" % (name,)