From 2075f2b41a7bad1cab697f03a230ccbda8577d17 Mon Sep 17 00:00:00 2001 From: Mark Doffman Date: Mon, 18 Aug 2008 15:02:48 +0100 Subject: [PATCH] 2008-08-18 Mark Doffman * 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 | 2 +- tests/data/object-test-stage1.xml | 2 +- tests/dummyatk/my-atk-object.c | 9 +- tests/pyatspi/accessibletest.py | 148 +++++++++++++++++++++++++++++- tests/pyatspi/pasytest/Pasy.py | 10 +- tests/pyatspi/testrunner.py | 7 +- 6 files changed, 160 insertions(+), 18 deletions(-) diff --git a/tests/data/object-test-stage1-results.xml b/tests/data/object-test-stage1-results.xml index 9a0ebd3..a522187 100644 --- a/tests/data/object-test-stage1-results.xml +++ b/tests/data/object-test-stage1-results.xml @@ -1,5 +1,5 @@ - + diff --git a/tests/data/object-test-stage1.xml b/tests/data/object-test-stage1.xml index 54729ca..c881873 100644 --- a/tests/data/object-test-stage1.xml +++ b/tests/data/object-test-stage1.xml @@ -1,5 +1,5 @@ - + diff --git a/tests/dummyatk/my-atk-object.c b/tests/dummyatk/my-atk-object.c index fec5f99..23f6c65 100644 --- a/tests/dummyatk/my-atk-object.c +++ b/tests/dummyatk/my-atk-object.c @@ -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) diff --git a/tests/pyatspi/accessibletest.py b/tests/pyatspi/accessibletest.py index b7b2c8c..a504cca 100644 --- a/tests/pyatspi/accessibletest.py +++ b/tests/pyatspi/accessibletest.py @@ -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 diff --git a/tests/pyatspi/pasytest/Pasy.py b/tests/pyatspi/pasytest/Pasy.py index 166c3e1..80318ee 100644 --- a/tests/pyatspi/pasytest/Pasy.py +++ b/tests/pyatspi/pasytest/Pasy.py @@ -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,) diff --git a/tests/pyatspi/testrunner.py b/tests/pyatspi/testrunner.py index efd9289..b74929e 100755 --- a/tests/pyatspi/testrunner.py +++ b/tests/pyatspi/testrunner.py @@ -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,) -- 2.7.4