at_spi2_tool: return node pointer, relation flow to/from information accepted/tizen/common/20170102.152347 accepted/tizen/ivi/20170103.051302 accepted/tizen/mobile/20170103.051027 accepted/tizen/tv/20170103.051135 accepted/tizen/wearable/20170103.051206 submit/tizen/20170102.091821 submit/tizen/20170103.012719
authorShinwoo Kim <cinoo.kim@samsung.com>
Tue, 13 Dec 2016 10:00:35 +0000 (19:00 +0900)
committerJEONGHYUN YUN <jh0506.yun@samsung.com>
Thu, 29 Dec 2016 10:35:30 +0000 (19:35 +0900)
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

index 7a7b9a5..b8f051f 100644 (file)
@@ -6,7 +6,7 @@
 #include <stdbool.h>
 
 #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);