Added printing supported actions to at_spi2_tool 00/234900/7
authorMaria Bialota <m.bialota@samsung.com>
Tue, 26 May 2020 16:11:38 +0000 (18:11 +0200)
committerMaria Bialota <m.bialota@samsung.com>
Mon, 1 Jun 2020 15:38:08 +0000 (17:38 +0200)
Change-Id: I15ba50fb0b06990d314a1f8ad554baf909c2312b

test/at_spi2_tool.c

index cca84f1..f10778c 100644 (file)
 #define FIRST_MATCH 2
 #define RELATION_TABLE_COLUMN_COUNT 7
 #define ATTRIBUTE_TABLE_COLUMN_COUNT 3
+#define ACTIONS_TABLE_COLUMN_COUNT 2
 #define RELATION_TABLE_COLUMN_WIDTH 20
 #define ATTRIBUTE_TABLE_BASE_COLUMN_WIDTH 20
+#define ACTIONS_TABLE_BASE_COLUMN_WIDTH 20
 #define VERSION "1.1"
 
 static unsigned indent_width = 2;
@@ -299,7 +301,7 @@ static char *_get_attributes(AtspiAccessible *node, int length_limit, bool *attr
        return result;
 }
 
-static char *_get_info(AtspiAccessible *node, int length_limit, bool *attributes_are_too_long, bool *app_has_relations)
+static char *_get_info(AtspiAccessible *node, int length_limit, bool *attributes_are_too_long, bool *app_has_relations, bool *app_has_actions)
 {
        if (!node)
                return NULL;
@@ -318,6 +320,15 @@ static char *_get_info(AtspiAccessible *node, int length_limit, bool *attributes
        GArray *relations = atspi_accessible_get_relation_set(node, NULL);
        bool current_node_has_relations = (relations && relations->len);
 
+       bool current_node_has_actions = false;
+
+       AtspiAction* action_if = atspi_accessible_get_action_iface (node);
+       if (action_if)
+       {
+               gint no_actions = atspi_action_get_n_actions (action_if, NULL);
+               if (no_actions > 0) current_node_has_actions = true;
+       }
+
        char result[SAFE_BUFFER_SIZE];
        int ret = snprintf(result, SAFE_BUFFER_SIZE, "[[%s(%p)],[%s],[%s],[%s,%s,%s,%s],[%s],[%s],[%s]]",
                                                unique_id, (uintptr_t)eo_ptr,
@@ -337,6 +348,9 @@ static char *_get_info(AtspiAccessible *node, int length_limit, bool *attributes
        if (current_node_has_relations)
                *app_has_relations = true;
 
+       if (current_node_has_actions)
+               *app_has_actions = true;
+
        free(node_name);
        free(node_role_name);
        free(unique_id);
@@ -383,7 +397,7 @@ static void _test_atspi_parent_child_relation(AtspiAccessible *obj, AtspiAccessi
 }
 
 static int _print_atspi_tree_verify_maybe_r(int indent_number, AtspiAccessible *object, bool check_integrity, int length_limit,
-                                                                                       bool *attributes_are_too_long, bool *app_has_relations)
+                                               bool *attributes_are_too_long, bool *app_has_relations, bool *app_has_actions)
 {
        char *indent = _multiply_string(' ', indent_number*indent_width);
        if (indent != NULL) {
@@ -391,7 +405,7 @@ static int _print_atspi_tree_verify_maybe_r(int indent_number, AtspiAccessible *
                free(indent);
        }
 
-       char *node_info = _get_info(object, length_limit, attributes_are_too_long, app_has_relations);
+       char *node_info = _get_info(object, length_limit, attributes_are_too_long, app_has_relations, app_has_actions);
        if (node_info != NULL) {
                printf("%s\n", node_info);
                free(node_info);
@@ -404,7 +418,7 @@ static int _print_atspi_tree_verify_maybe_r(int indent_number, AtspiAccessible *
                        if (check_integrity)
                                _test_atspi_parent_child_relation(child, object, i);
 
-                       _print_atspi_tree_verify_maybe_r(indent_number + 1, child, check_integrity, length_limit, attributes_are_too_long, app_has_relations);
+                       _print_atspi_tree_verify_maybe_r(indent_number + 1, child, check_integrity, length_limit, attributes_are_too_long, app_has_relations, app_has_actions);
                }
        }
        return 0;
@@ -543,6 +557,61 @@ static void _print_relations_table(AtspiAccessible *node) {
        _print_relations_for_objects_in_tree(node);
 }
 
+static void _print_horizontal_line_in_actions_table() {
+       int size_factor = 1;
+       for (int i = 0; i < ACTIONS_TABLE_COLUMN_COUNT; i++) {
+               if (i == ACTIONS_TABLE_COLUMN_COUNT - 1)
+                       size_factor = 4;
+               for (int j = 0; j < ACTIONS_TABLE_BASE_COLUMN_WIDTH * size_factor; j++)
+                       printf("-");
+               printf("+");
+       }
+       printf("\n");
+}
+
+static void _print_actions_for_object(AtspiAccessible *node) {
+       char *unique_id = atspi_accessible_get_unique_id(node, NULL);
+       AtspiAction* action_if = atspi_accessible_get_action_iface (node);
+       if (action_if) {
+               gint no_actions = atspi_action_get_n_actions (action_if, NULL);
+               for (int i=0; i< no_actions; i++) {
+                       gchar * ith_action = atspi_action_get_action_name (action_if, i, NULL);
+                       printf("%*s|", ACTIONS_TABLE_BASE_COLUMN_WIDTH, unique_id ? unique_id : "");
+                       printf("%*s|\n", ACTIONS_TABLE_BASE_COLUMN_WIDTH * 4, ith_action ? (char *) ith_action : "");
+                       g_free(ith_action);
+               }
+               _print_horizontal_line_in_actions_table();
+       }
+       free(unique_id);
+}
+
+static void _print_actions_for_objects_in_tree(AtspiAccessible *node) {
+       _iterate_over_tree(_print_actions_for_object, node);
+}
+
+static void _print_header_for_actions_table() {
+       char *table[] = {"OBJECT", "SUPPORTED ACTION"};
+       assert(ARRAY_SIZE(table) == ACTIONS_TABLE_COLUMN_COUNT);
+
+       _print_horizontal_line_in_actions_table();
+
+       int size_factor = 1;
+       for (int i = 0; i < ACTIONS_TABLE_COLUMN_COUNT; i++) {
+               if (i == ACTIONS_TABLE_COLUMN_COUNT - 1)
+                        size_factor = 4;
+               printf("%*s|", ACTIONS_TABLE_BASE_COLUMN_WIDTH * size_factor , table[i]);
+        }
+
+       printf("\n");
+       _print_horizontal_line_in_actions_table();
+}
+
+static void _print_actions_table(AtspiAccessible *node) {
+       printf("\nSUPPPORTED ACTIONS TABLE\n");
+       _print_header_for_actions_table();
+       _print_actions_for_objects_in_tree(node);
+}
+
 static void _print_horizontal_line_in_attributes_table() {
        int size_factor = 1;
        for (int i = 0; i < ATTRIBUTE_TABLE_COLUMN_COUNT; i++) {
@@ -629,6 +698,7 @@ static void _atspi_tree_traverse(const char *app_name, bool dump, bool check, bo
                char *name = atspi_accessible_get_name(child, NULL);
                bool attributes_are_too_long = false;
                bool app_has_relations = false;
+               bool app_has_actions = false;
 
                if (!dump && !check)
                        printf("%s\n", name);
@@ -641,7 +711,7 @@ static void _atspi_tree_traverse(const char *app_name, bool dump, bool check, bo
                        if (check)
                                _test_atspi_parent_child_relation(child, desktop, i);
 
-                       _print_atspi_tree_verify_maybe_r(0, child, check, length_limit, &attributes_are_too_long, &app_has_relations);
+                       _print_atspi_tree_verify_maybe_r(0, child, check, length_limit, &attributes_are_too_long, &app_has_relations, &app_has_actions);
 
                        if (app_has_relations)
                                _print_relations_table(child);
@@ -649,6 +719,9 @@ static void _atspi_tree_traverse(const char *app_name, bool dump, bool check, bo
                        if (attributes_are_too_long)
                                _print_attributes_table(child);
 
+                       if (app_has_actions)
+                               _print_actions_table(child);
+
                        if (first_match) {
                                free(name);
                                break;