|
16 | 16 | import json |
17 | 17 | import os |
18 | 18 | import pyatspi |
| 19 | +import re |
19 | 20 | import signal |
20 | 21 | import subprocess |
21 | 22 | import sys |
@@ -264,6 +265,9 @@ def _parse_assertion(self, assertion): |
264 | 265 | if test_type == "object": |
265 | 266 | return (self._has_attribute_value, test_value, expected_result), self.SUCCESS |
266 | 267 |
|
| 268 | + if test_type == "relation": |
| 269 | + return (self._has_relation, test_value, expected_result), self.SUCCESS |
| 270 | + |
267 | 271 | print("ERROR: Unhandled assertion type: %s" % test_type) |
268 | 272 | return None, self.FAILURE_INVALID_REQUEST |
269 | 273 |
|
@@ -585,6 +589,44 @@ def _has_name(self, obj, name_string, expected_result): |
585 | 589 |
|
586 | 590 | return success, self.SUCCESS, actual_name |
587 | 591 |
|
| 592 | + def _has_relation(self, obj, type_string, target_ids, expected_result=True): |
| 593 | + """Checks if the obj has the specified accessible relation type pointing |
| 594 | + to the element(s) with the specified id(s). Test writers may provide all |
| 595 | + of the targets in a single assertion or create multiple assertions, each |
| 596 | + of which contains a subset of the targets. |
| 597 | +
|
| 598 | + Arguments: |
| 599 | + - obj: The AtspiAccessible to check |
| 600 | + - type_string: A string containing the AtspiRelationType being checked |
| 601 | + - target_ids: A string containing the id(s) of the referenced element(s) |
| 602 | + - expected_result: A boolean reflecting if the names should match |
| 603 | +
|
| 604 | + Returns: |
| 605 | + - A boolean reflecting if the actual result is the expected_result |
| 606 | + - A string indicating success, or the cause of failure |
| 607 | + - A string containing the id(s) of the target(s) |
| 608 | + """ |
| 609 | + |
| 610 | + targets = [] |
| 611 | + relations = obj.getRelationSet() |
| 612 | + for r in relations: |
| 613 | + string = r.getRelationType().value_name.replace("ATSPI_", "") |
| 614 | + if string == type_string: |
| 615 | + targets = [r.getTarget(i) for i in range(r.getNTargets())] |
| 616 | + break |
| 617 | + |
| 618 | + desired_ids = re.compile("\W+").split(target_ids) |
| 619 | + actual_ids = list(map(lambda x: self._get_element_id(x)[0], targets)) |
| 620 | + not_found = list(filter(lambda x: x not in actual_ids, desired_ids)) |
| 621 | + |
| 622 | + result = not not_found |
| 623 | + success = result == expected_result |
| 624 | + |
| 625 | + if success == False: |
| 626 | + return success, self.FAILURE_RESULTS, actual_ids |
| 627 | + |
| 628 | + return success, self.SUCCESS, actual_ids |
| 629 | + |
588 | 630 | def _has_role(self, obj, role_string, expected_result): |
589 | 631 | """Checks if the accessible role of obj is role_string. |
590 | 632 |
|
|
0 commit comments