From 688544a3fc70c878b39ad0e5134e58291d2bffa8 Mon Sep 17 00:00:00 2001 From: Shinwoo Kim Date: Tue, 13 Dec 2016 19:00:35 +0900 Subject: [PATCH] at_spi2_tool: return node pointer, relation flow to/from information Do not abort even though the information is too long. It was not possilbe to get next launchpad-loader application. Change-Id: Ia7e5c6ad7a989bff3425b922ef4d80cf7667be1c --- test/at_spi2_tool.c | 54 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/test/at_spi2_tool.c b/test/at_spi2_tool.c index 7a7b9a5..b8f051f 100644 --- a/test/at_spi2_tool.c +++ b/test/at_spi2_tool.c @@ -6,7 +6,7 @@ #include #define ERROR_STATE -1 -#define SAFE_BUFFER_SIZE 255 +#define SAFE_BUFFER_SIZE 2048 #define CHECK_OUTPUT_WIDTH 42 #define MINIMAL_MODULE_WIDTH 3 #define ATTR_WIDTH 50 @@ -99,7 +99,7 @@ static char *_multiply_string(char c, unsigned number) static void _print_module_legend() { - printf("\n[[node role name],[attributes list],[x,y,width,height],[node name],[states list]]\n\n"); + printf("\n[[node],[node role name],[attributes list],[x,y,width,height],[node name],[states list][flow to node, flow from node]\n\n"); } static void _print_atspi_states_legend() @@ -277,7 +277,7 @@ static char *_get_attributes(AtspiAccessible *node) int ret = snprintf(attributes_string, ATTR_WIDTH, "(%s=%s)", (char*)attr_key, (char*)attr_value); if (ret >= ATTR_WIDTH) { fprintf(stderr, "_get_attributes: generated string is too long. Buffer overflow"); - abort(); + attributes_string[ATTR_WIDTH - 1] = '\n'; } _combine_strings(&result, attributes_string); } @@ -286,6 +286,31 @@ static char *_get_attributes(AtspiAccessible *node) return result; } +static AtspiAccessible *_get_object_in_relation(AtspiAccessible * source, AtspiRelationType search_type) +{ + GArray *relations; + AtspiAccessible *ret = NULL; + AtspiRelation *relation; + AtspiRelationType type; + int i; + if (source) { + relations = atspi_accessible_get_relation_set(source, NULL); + if (relations) { + for (i = 0; i < relations->len; i++) { + relation = g_array_index(relations, AtspiRelation *, i); + type = atspi_relation_get_relation_type(relation); + + if (type == search_type) { + ret = atspi_relation_get_target(relation, 0); + break; + } + } + g_array_free(relations, TRUE); + } + } + return ret; +} + static char *_get_info(AtspiAccessible *node, int length_limit) { if (!node) @@ -301,19 +326,22 @@ static char *_get_info(AtspiAccessible *node, int length_limit) _truncate_string(states, length_limit); char result[SAFE_BUFFER_SIZE]; - int ret = snprintf(result, SAFE_BUFFER_SIZE, "[[%s],[%s],[%s,%s,%s,%s],[%s],[%s]]", - node_role_name, - attributes, - box_size->x, - box_size->y, - box_size->width, - box_size->height, - node_name, - states); + int ret = snprintf(result, SAFE_BUFFER_SIZE, "[[%p],[%s],[%s],[%s,%s,%s,%s],[%s],[%s],[%p,%p]]", + node, + node_role_name, + attributes, + box_size->x, + box_size->y, + box_size->width, + box_size->height, + node_name, + states, + _get_object_in_relation(node, ATSPI_RELATION_FLOWS_TO), + _get_object_in_relation(node, ATSPI_RELATION_FLOWS_FROM)); if (ret >= SAFE_BUFFER_SIZE) { fprintf(stderr, "_get_info: generated string is too long. Buffer overflow"); - abort(); + result[SAFE_BUFFER_SIZE - 1] = '\n'; } free(node_name); -- 2.7.4