From 21d493d78b5e2d16a757fcc05f33c78264f2d609 Mon Sep 17 00:00:00 2001 From: Patryk Kaczmarek Date: Tue, 29 Sep 2015 12:33:07 +0200 Subject: Next tests for accessible interfaces * New tested interfaces: - Collection - EditableText - Image - Text - Value * Commented tests for depricated function in Component tests deleted * Unused variables deleted * Added compilation flag -Wall --- tests/Makefile.am | 19 +- tests/README | 45 ++++ tests/atk-object-xml-loader.c | 158 +++++++++-- tests/atk_suite.c | 42 ++- tests/atk_suite.h | 10 + tests/atk_test_collection.c | 169 ++++++++++++ tests/atk_test_component.c | 74 ------ tests/atk_test_editable_text.c | 128 +++++++++ tests/atk_test_image.c | 128 +++++++++ tests/atk_test_text.c | 481 ++++++++++++++++++++++++++++++++++ tests/atk_test_util.c | 1 - tests/atk_test_value.c | 119 +++++++++ tests/data/test-collection.xml | 20 ++ tests/data/test-editable-text.xml | 9 + tests/data/test-image.xml | 7 + tests/data/test-text.xml | 9 + tests/data/test-value.xml | 6 + tests/dummyatk/Makefile.am | 11 +- tests/dummyatk/my-atk-action.c | 6 - tests/dummyatk/my-atk-editable-text.c | 138 ++++++++++ tests/dummyatk/my-atk-editable-text.h | 57 ++++ tests/dummyatk/my-atk-image.c | 157 +++++++++++ tests/dummyatk/my-atk-image.h | 68 +++++ tests/dummyatk/my-atk-object.h | 1 + tests/dummyatk/my-atk-text.c | 441 +++++++++++++++++++++++++++++++ tests/dummyatk/my-atk-text.h | 71 +++++ tests/dummyatk/my-atk-value.c | 138 ++++++++++ tests/dummyatk/my-atk-value.h | 55 ++++ tests/dummyatk/my-atk.h | 4 + 29 files changed, 2461 insertions(+), 111 deletions(-) create mode 100644 tests/atk_test_collection.c create mode 100644 tests/atk_test_editable_text.c create mode 100644 tests/atk_test_image.c create mode 100644 tests/atk_test_text.c create mode 100644 tests/atk_test_value.c create mode 100644 tests/data/test-collection.xml create mode 100644 tests/data/test-editable-text.xml create mode 100644 tests/data/test-image.xml create mode 100644 tests/data/test-text.xml create mode 100644 tests/data/test-value.xml create mode 100644 tests/dummyatk/my-atk-editable-text.c create mode 100644 tests/dummyatk/my-atk-editable-text.h create mode 100644 tests/dummyatk/my-atk-image.c create mode 100644 tests/dummyatk/my-atk-image.h create mode 100644 tests/dummyatk/my-atk-text.c create mode 100644 tests/dummyatk/my-atk-text.h create mode 100644 tests/dummyatk/my-atk-value.c create mode 100644 tests/dummyatk/my-atk-value.h (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 66edcf9..0ac1ca7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -11,7 +11,8 @@ atk_test_CFLAGS = $(DBUS_CFLAGS) \ -I$(top_srcdir)/tests/dummyatk/ \ -I$(top_builddir)/tests/dummyatk/.libs \ -I$(top_builddir)/tests/dummyatk/.deps \ - -I$(top_srcdir) + -I$(top_srcdir) \ + -Wall atk_test_LDADD = libxmlloader.la \ libtestutils.la \ @@ -27,13 +28,19 @@ atk_test_SOURCES = atk_suite.c \ atk_suite.h \ atk_test_accessible.c \ atk_test_action.c \ - atk_test_component.c + atk_test_component.c \ + atk_test_collection.c \ + atk_test_editable_text.c \ + atk_test_image.c \ + atk_test_text.c \ + atk_test_value.c app_test_CFLAGS = -I$(top_builddir) \ $(GLIB_CFLAGS) \ $(ATK_CFLAGS) \ -I$(top_srcdir)/tests/dummyatk \ - -I$(top_srcdir)/atk-adaptor + -I$(top_srcdir)/atk-adaptor \ + -Wall app_test_LDADD = libxmlloader.la \ libtestutils.la \ @@ -48,7 +55,8 @@ libxmlloader_la_CFLAGS = $(GLIB_CFLAGS) \ $(GOBJ_CFLAGS) \ $(XML_CFLAGS) \ $(ATK_CFLAGS) \ - -I$(top_srcdir)/tests/dummyatk/ + -I$(top_srcdir)/tests/dummyatk/ \ + -Wall libxmlloader_la_LIBADD = $(GLIB_LIBS) \ $(XML_LIBS) \ @@ -61,7 +69,8 @@ libxmlloader_la_SOURCES = atk-object-xml-loader.c\ libtestutils_la_CFLAGS = -I$(top_builddir) \ $(GLIB_CFLAGS) \ - $(ATSPI_CFLAGS) + $(ATSPI_CFLAGS) \ + -Wall libtestutils_la_LIBADD = $(GLIB_LIBS) \ $(ATSPI_LIBS) diff --git a/tests/README b/tests/README index 109cb18..b7e141d 100644 --- a/tests/README +++ b/tests/README @@ -89,3 +89,48 @@ AVAILABLE TESTS: -component_grab_focus -component_get_alpha -component_set_extents +- Collection + -get_collection_iface + -get_matches + -get_matches_to + -get_matches_from +- EditableText: + -get_editable_text_iface + -editable_text_set_attributes + -editable_text_insert_text + -editable_text_copy_text + -editable_text_cut_text + -editable_text_delete_text + -editable_text_paste_text +- Image: + -get_image_iface + -image_get_image_size + -image_get_image_position + -image_get_image_extents + -image_get_image_locale +- Text: + -text_get_character_count + -text_get_text + -text_get_caret_offset + -text_get_text_attributes + -text_get_attribute_run + -text_get_get_text_attribute_value + -text_get_defualt_attributes + -text_set_caret_offset + -text_get_string_at_offset + -text_get_character_at_offset + -text_get_character_extents + -text_get_offset_at_point + -text_get_range_extents + -text_get_bounded_ranges + -text_get_n_selections + -text_get_selection + -text_add_selection + -text_remove_selection + -text_set_selection +- Value + -value_get_minimum_value + -value_get_current_value + -value_get_maximum_value + -value_set_current_value + -value_get_minimum_increment diff --git a/tests/atk-object-xml-loader.c b/tests/atk-object-xml-loader.c index 6f34ecd..f0d4f88 100644 --- a/tests/atk-object-xml-loader.c +++ b/tests/atk-object-xml-loader.c @@ -31,16 +31,25 @@ #define ACCESSIBLE_NODE ((const xmlChar *) "accessible") #define ACC_ACTION_NODE ((const xmlChar *) "accessible_action") #define ACC_COMPONENT_NODE ((const xmlChar *) "accessible_component") +#define ACC_IMAGE_NODE ((const xmlChar *) "accessible_image") +#define ACC_EDIT_TEXT_NODE ((const xmlChar *) "accessible_editable_text") +#define ACC_TEXT_NODE ((const xmlChar *) "accessible_text") +#define ACC_VALUE_NODE ((const xmlChar *) "accessible_value") #define ACTION_NODE ((const xmlChar *) "action") -#define INTERFACE_NODE ((const xmlChar *) "interface") #define RELATION_NODE ((const xmlChar *) "relation") #define STATE_NODE ((const xmlChar *) "state") #define COMPONENT_NODE ((const xmlChar *) "component") +#define IMAGE_NODE ((const xmlChar *) "image") +#define TEXT_NODE ((const xmlChar *) "text_node") +#define VALUE_NODE ((const xmlChar *) "value_node") #define NAME_ATTR ((const xmlChar *) "name") #define DESC_ATTR ((const xmlChar *) "description") #define ROLE_ATTR ((const xmlChar *) "role") -#define TYPE_ATTR ((const xmlChar *) "type") +#define MIN_ATTR ((const xmlChar *) "min") +#define MAX_ATTR ((const xmlChar *) "max") +#define CURRENT_ATTR ((const xmlChar *) "current") +#define STEP_ATTR ((const xmlChar *) "step") #define RELATION_TYPE_ATTR ((const xmlChar *) "relation_type") #define RELATION_TARGET_NAME_ATTR ((const xmlChar *) "target_name") #define STATE_TYPE_ATTR ((const xmlChar *) "state_enum") @@ -54,9 +63,56 @@ #define COMP_LAYER_ATTR ((const xmlChar *) "layer") #define COMP_ZORDER_ATTR ((const xmlChar *) "zorder") #define COMP_ALPHA_ATTR ((const xmlChar *) "alpha") +#define IMAGE_DES_ATTR ((const xmlChar *) "image_description") +#define IMAGE_LOCALE_ATTR ((const xmlChar *) "image_locale") +#define TEXT_TEXT_ATTR ((const xmlChar *) "text") +#define TEXT_BOLD_ATTR ((const xmlChar *) "bold_text") +#define TEXT_UNDERLINE_ATTR ((const xmlChar *) "underline_text") +#define TEXT_DUMMY_ATTR ((const xmlChar *) "dummy_text") MyAtkObject *relation_target = NULL; +static double atof_get_prop (xmlNode *node, const xmlChar *attr) +{ + double ret; + xmlChar *str = xmlGetProp (node, attr); + if (!str) + return 0; + ret = atof ((const char *)str); + xmlFree(str); + + return ret; +} + +static int atoi_get_prop (xmlNode *node, const xmlChar *attr) +{ + int ret; + xmlChar *str = xmlGetProp (node, attr); + if (!str) + return 0; + ret = atoi ((const char *)str); + xmlFree(str); + + return ret; +} + +static AtkAttribute * +get_atk_attribute (xmlNode *node, const xmlChar *attr) +{ + xmlChar *str; + AtkAttribute *tmp = g_malloc (sizeof (AtkAttribute)); + + if (!tmp) + return NULL; + + str = xmlGetProp (node, attr); + tmp->name = g_strdup ((const char *)attr); + tmp->value = g_strdup ((const char *)str); + + free (str); + return tmp; +} + static gpointer create_atk_object_from_element (xmlNode *element) { @@ -64,19 +120,15 @@ create_atk_object_from_element (xmlNode *element) xmlNode *child_node2; gpointer obj; - gpointer child_obj; - gpointer child_obj2; + gpointer child_obj = NULL; AtkRelationSet *relation_set = NULL; AtkObject *array[1]; AtkRelation *relation; AtkStateSet *state_set = NULL; AtkStateType state_type; - AtkAction *action; xmlChar *name; xmlChar *description; - xmlChar *type_text; - xmlChar *relation_type_text; xmlChar *state_enum; xmlChar *role; gint relation_type; @@ -84,11 +136,15 @@ create_atk_object_from_element (xmlNode *element) xmlChar *action_name; xmlChar *action_des; xmlChar *action_key_bind; + xmlChar *image_des; + xmlChar *image_locale; + xmlChar *text; + gint x_size, y_size; + gint width, height; gint x_extent, y_extent, w_extent, h_extent; name = xmlGetProp (element, NAME_ATTR); description = xmlGetProp (element, DESC_ATTR); role = xmlGetProp (element, ROLE_ATTR); - type_text = xmlGetProp (element, TYPE_ATTR); GType type = MY_TYPE_ATK_OBJECT; gint layer; gint zorder; @@ -103,25 +159,39 @@ create_atk_object_from_element (xmlNode *element) if (!xmlStrcmp (element->name, ACC_COMPONENT_NODE)) type = MY_TYPE_ATK_COMPONENT; + if (!xmlStrcmp (element->name, ACC_EDIT_TEXT_NODE)) + type = MY_TYPE_ATK_EDITABLE_TEXT; + + if (!xmlStrcmp (element->name, ACC_IMAGE_NODE)) + type = MY_TYPE_ATK_IMAGE; + + if (!xmlStrcmp (element->name, ACC_TEXT_NODE)) + type = MY_TYPE_ATK_TEXT; + + if (!xmlStrcmp (element->name, ACC_VALUE_NODE)) + type = MY_TYPE_ATK_VALUE; + obj = g_object_new (type, "accessible-name", name, "accessible-description", description, - "accessible-role", atk_role_for_name (role), + "accessible-role", atk_role_for_name ((const gchar *)role), NULL); - child_node = element->xmlChildrenNode; while (child_node != NULL) { if (!xmlStrcmp (child_node->name, ACCESSIBLE_NODE) || !xmlStrcmp (child_node->name, ACC_ACTION_NODE) || - !xmlStrcmp (child_node->name, ACC_COMPONENT_NODE)) { + !xmlStrcmp (child_node->name, ACC_COMPONENT_NODE) || + !xmlStrcmp (child_node->name, ACC_EDIT_TEXT_NODE) || + !xmlStrcmp (child_node->name, ACC_IMAGE_NODE) || + !xmlStrcmp (child_node->name, ACC_TEXT_NODE) || + !xmlStrcmp (child_node->name, ACC_VALUE_NODE)) { child_obj = create_atk_object_from_element (child_node); my_atk_object_add_child (obj, child_obj); } child_node2 = child_node->xmlChildrenNode; while (child_node2 != NULL) { if (!xmlStrcmp (child_node2->name, RELATION_NODE)) { - relation_type_text = xmlGetProp (child_node2, RELATION_TYPE_ATTR); - relation_type = atoi (relation_type_text); + relation_type = atoi_get_prop (child_node2, RELATION_TYPE_ATTR); relation_target_name = xmlGetProp (child_node2, RELATION_TARGET_NAME_ATTR); relation_set = atk_object_ref_relation_set (ATK_OBJECT (child_obj)); array[0] = ATK_OBJECT (obj); @@ -131,12 +201,11 @@ create_atk_object_from_element (xmlNode *element) g_object_unref (relation); g_object_unref (relation_set); xmlFree (relation_target_name); - xmlFree (relation_type_text); } if (!xmlStrcmp (child_node2->name, STATE_NODE)) { state_set = atk_object_ref_state_set (ATK_OBJECT (child_obj)); state_enum = xmlGetProp (child_node2, STATE_TYPE_ATTR); - state_type = atk_state_type_for_name (state_enum); + state_type = atk_state_type_for_name ((const gchar *)state_enum); atk_state_set_add_state (state_set, state_type); g_object_unref (state_set); xmlFree (state_enum); @@ -145,16 +214,18 @@ create_atk_object_from_element (xmlNode *element) action_name = xmlGetProp (child_node2, ACTION_NAME_ATTR); action_des = xmlGetProp (child_node2, ACTION_DES_ATTR); action_key_bind = xmlGetProp (child_node2, ACTION_KEY_BIND_ATTR); - my_atk_action_add_action (child_obj, action_name, action_des, action_key_bind); + my_atk_action_add_action (child_obj, (const gchar *)action_name, + (const gchar *)action_des, + (const gchar *)action_key_bind); } if (!xmlStrcmp (child_node2->name, COMPONENT_NODE)) { - x_extent = atoi (xmlGetProp (child_node2, COMP_X_ATTR)); - y_extent = atoi (xmlGetProp (child_node2, COMP_Y_ATTR)); - w_extent = atoi (xmlGetProp (child_node2, COMP_WIDTH_ATTR)); - h_extent = atoi (xmlGetProp (child_node2, COMP_HEIGHT_ATTR)); - layer = atoi (xmlGetProp (child_node2, COMP_LAYER_ATTR)); - zorder = atoi (xmlGetProp (child_node2, COMP_ZORDER_ATTR)); - alpha = atof (xmlGetProp (child_node2, COMP_ALPHA_ATTR)); + x_extent = atoi_get_prop (child_node2, COMP_X_ATTR); + y_extent = atoi_get_prop (child_node2, COMP_Y_ATTR); + w_extent = atoi_get_prop (child_node2, COMP_WIDTH_ATTR); + h_extent = atoi_get_prop (child_node2, COMP_HEIGHT_ATTR); + layer = atoi_get_prop (child_node2, COMP_LAYER_ATTR); + zorder = atoi_get_prop (child_node2, COMP_ZORDER_ATTR); + alpha = atof_get_prop (child_node2, COMP_ALPHA_ATTR); atk_component_set_extents (ATK_COMPONENT (child_obj), x_extent, y_extent, @@ -165,6 +236,47 @@ create_atk_object_from_element (xmlNode *element) my_atk_component_set_mdi_zorder (ATK_COMPONENT (child_obj), zorder); my_atk_component_set_alpha (ATK_COMPONENT (child_obj), alpha); } + if (!xmlStrcmp (child_node2->name, IMAGE_NODE)) { + image_des = xmlGetProp (child_node2, IMAGE_DES_ATTR); + x_size = atoi_get_prop (child_node2, COMP_X_ATTR); + y_size = atoi_get_prop (child_node2, COMP_Y_ATTR); + width = atoi_get_prop (child_node2, COMP_WIDTH_ATTR); + height = atoi_get_prop (child_node2, COMP_HEIGHT_ATTR); + image_locale = xmlGetProp (child_node2, IMAGE_LOCALE_ATTR); + + my_atk_set_image (ATK_IMAGE (child_obj), + (const gchar *)image_des, + x_size, + y_size, + width, + height, + (const gchar *)image_locale); + } + if (!xmlStrcmp (child_node2->name, TEXT_NODE)) { + text = xmlGetProp (child_node2, TEXT_TEXT_ATTR); + AtkAttributeSet *attrSet = NULL; + AtkAttribute *a1 = get_atk_attribute (child_node2, TEXT_BOLD_ATTR); + AtkAttribute *a2 = get_atk_attribute (child_node2, TEXT_UNDERLINE_ATTR); + AtkAttribute *a3 = get_atk_attribute (child_node2, TEXT_DUMMY_ATTR); + attrSet = g_slist_append(NULL, a1); + attrSet = g_slist_append(attrSet, a2); + attrSet = g_slist_append(attrSet, a3); + my_atk_set_text (ATK_TEXT (child_obj), + (const gchar *)text, + atoi_get_prop (child_node2, COMP_X_ATTR), + atoi_get_prop (child_node2, COMP_Y_ATTR), + atoi_get_prop (child_node2, COMP_WIDTH_ATTR), + atoi_get_prop (child_node2, COMP_HEIGHT_ATTR), + attrSet); + } + if (!xmlStrcmp (child_node2->name, VALUE_NODE)) { + + my_atk_set_value (ATK_VALUE(child_obj), + atof_get_prop (child_node2, MIN_ATTR), + atof_get_prop (child_node2, CURRENT_ATTR), + atof_get_prop (child_node2, MAX_ATTR), + atof_get_prop (child_node2, STEP_ATTR)); + } child_node2 = child_node2->next; } child_node = child_node->next; diff --git a/tests/atk_suite.c b/tests/atk_suite.c index 8b12d9a..82d6a73 100644 --- a/tests/atk_suite.c +++ b/tests/atk_suite.c @@ -43,6 +43,11 @@ static const Atk_Test_Case atc[] = { { ATK_TEST_PATH_ACCESSIBLE, atk_test_accessible }, { ATK_TEST_PATH_ACTION, atk_test_action }, { ATK_TEST_PATH_COMP, atk_test_component }, + { ATK_TEST_PATH_COLLECTION, atk_test_collection }, + { ATK_TEST_PATH_EDIT_TEXT, atk_test_editable_text }, + { ATK_TEST_PATH_IMAGE, atk_test_image }, + { ATK_TEST_PATH_TEXT, atk_test_text }, + { ATK_TEST_PATH_VALUE, atk_test_value }, { NULL, NULL} }; @@ -64,6 +69,11 @@ atk_suite_build (int argc, char **argv ) atk_test_accessible (); atk_test_action (); atk_test_component (); + atk_test_collection (); + atk_test_editable_text (); + atk_test_image (); + atk_test_text (); + atk_test_value (); } static GOptionEntry optentries[] = { @@ -105,12 +115,42 @@ main(int argc, char **argv) test_result = g_test_run (); return (test_result == 0 ) ? 0 : 255; } - if (!g_strcmp0(one_test, "Component")) { + if (!g_strcmp0 (one_test, "Component")) { g_test_init (&argc, &argv, NULL); atk_test_component (); test_result = g_test_run (); return ( test_result == 0 ) ? 0 : 255; } + if (!g_strcmp0 (one_test, "Collection")) { + g_test_init (&argc, &argv, NULL); + atk_test_collection (); + test_result = g_test_run (); + return ( test_result == 0 ) ? 0 : 255; + } + if (!g_strcmp0 (one_test, "Editable_Text")) { + g_test_init (&argc, &argv, NULL); + atk_test_editable_text (); + test_result = g_test_run (); + return ( test_result == 0 ) ? 0 : 255; + } + if (!g_strcmp0 (one_test, "Image")) { + g_test_init (&argc, &argv, NULL); + atk_test_image (); + test_result = g_test_run (); + return ( test_result == 0 ) ? 0 : 255; + } + if (!g_strcmp0 (one_test, "Text")) { + g_test_init (&argc, &argv, NULL); + atk_test_text (); + test_result = g_test_run (); + return ( test_result == 0 ) ? 0 : 255; + } + if (!g_strcmp0 (one_test, "Value")) { + g_test_init (&argc, &argv, NULL); + atk_test_value (); + test_result = g_test_run (); + return ( test_result == 0 ) ? 0 : 255; + } g_print ("Unknown test name\n"); _list_tests (); return EXIT_SUCCESS; diff --git a/tests/atk_suite.h b/tests/atk_suite.h index 17aefcd..9734b5e 100644 --- a/tests/atk_suite.h +++ b/tests/atk_suite.h @@ -28,9 +28,19 @@ #define ATK_TEST_PATH_ACCESSIBLE (const char *)"/Accessible" #define ATK_TEST_PATH_ACTION (const char *)"/Action" #define ATK_TEST_PATH_COMP (const char *)"/Component" +#define ATK_TEST_PATH_COLLECTION (const char *)"/Collection" +#define ATK_TEST_PATH_EDIT_TEXT (const char *)"/Editable_Text" +#define ATK_TEST_PATH_IMAGE (const char *)"/Image" +#define ATK_TEST_PATH_TEXT (const char *)"/Text" +#define ATK_TEST_PATH_VALUE (const char *)"/Value" void atk_test_accessible (void); void atk_test_action (void); void atk_test_component (void); +void atk_test_collection (void); +void atk_test_editable_text (void); +void atk_test_image (void); +void atk_test_text (void); +void atk_test_value (void); #endif /* _ATK_SUITE_H */ diff --git a/tests/atk_test_collection.c b/tests/atk_test_collection.c new file mode 100644 index 0000000..9ac69d7 --- /dev/null +++ b/tests/atk_test_collection.c @@ -0,0 +1,169 @@ +/* + * AT-SPI - Assistive Technology Service Provider Interface + * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility) + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#include "atk_suite.h" +#include "atk_test_util.h" + +#define DATA_FILE TESTS_DATA_DIR"/test-collection.xml" + +static void +teardown_collection_test (gpointer fixture, gconstpointer user_data) +{ + kill (child_pid, SIGTERM); +} + +static void +atk_test_collection_get_collection_iface (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + AtspiCollection *iface = atspi_accessible_get_collection_iface (obj); + g_assert (iface); +} + +static void +atk_test_collection_get_matches (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + AtspiCollection *iface = atspi_accessible_get_collection_iface (obj); + g_assert (iface); + + AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL); + + AtspiMatchRule *rule = NULL; + AtspiStateSet *ss = atspi_accessible_get_state_set (child); + + rule = atspi_match_rule_new (ss, + ATSPI_Collection_MATCH_ALL, + NULL, + ATSPI_Collection_MATCH_ALL, + NULL, + ATSPI_Collection_MATCH_ALL, + NULL, + ATSPI_Collection_MATCH_ALL, + FALSE); + GArray *ret = atspi_collection_get_matches (iface, + rule, + ATSPI_Collection_SORT_ORDER_CANONICAL, + 0, + FALSE, + NULL); + g_assert_cmpint (2, ==, ret->len); + + AtspiAccessible *get = NULL; + get = g_array_index (ret, AtspiAccessible *, 0); + g_assert_cmpstr("obj1", ==, atspi_accessible_get_name (get, NULL)); + get = g_array_index (ret, AtspiAccessible *, 1); + g_assert_cmpstr("obj3", ==, atspi_accessible_get_name (get, NULL)); +} + +static void +atk_test_collection_get_matches_to (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + AtspiCollection *iface = atspi_accessible_get_collection_iface (obj); + g_assert (iface); + + AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL); + AtspiAccessible *child1 = atspi_accessible_get_child_at_index (obj, 1, NULL); + + AtspiMatchRule *rule = NULL; + AtspiStateSet *ss = atspi_accessible_get_state_set (child); + + rule = atspi_match_rule_new (ss, + ATSPI_Collection_MATCH_ALL, + NULL, + ATSPI_Collection_MATCH_ALL, + NULL, + ATSPI_Collection_MATCH_ALL, + NULL, + ATSPI_Collection_MATCH_ALL, + FALSE); + GArray *ret = atspi_collection_get_matches_to (iface, + child1, + rule, + ATSPI_Collection_SORT_ORDER_CANONICAL, + ATSPI_Collection_TREE_INORDER, + TRUE, + 0, + FALSE, + NULL); + g_assert_cmpint (1, ==, ret->len); + AtspiAccessible *get = NULL; + get = g_array_index (ret, AtspiAccessible *, 0); + g_assert_cmpstr("obj1", ==, atspi_accessible_get_name (get, NULL)); +} + +static void +atk_test_collection_get_matches_from (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + AtspiCollection *iface = atspi_accessible_get_collection_iface (obj); + g_assert (iface); + + AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL); + AtspiAccessible *child1 = atspi_accessible_get_child_at_index (obj, 1, NULL); + + AtspiMatchRule *rule = NULL; + AtspiStateSet *ss = atspi_accessible_get_state_set (child); + + rule = atspi_match_rule_new (ss, + ATSPI_Collection_MATCH_ALL, + NULL, + ATSPI_Collection_MATCH_ALL, + NULL, + ATSPI_Collection_MATCH_ALL, + NULL, + ATSPI_Collection_MATCH_ALL, + FALSE); + GArray *ret = atspi_collection_get_matches_from (iface, + child1, + rule, + ATSPI_Collection_SORT_ORDER_CANONICAL, + ATSPI_Collection_TREE_INORDER, + 0, + FALSE, + NULL); + g_assert_cmpint (3, ==, ret->len); + AtspiAccessible *get = NULL; + get = g_array_index (ret, AtspiAccessible *, 0); + g_assert_cmpstr("obj2/1", ==, atspi_accessible_get_name (get, NULL)); + get = g_array_index (ret, AtspiAccessible *, 1); + g_assert_cmpstr("obj3", ==, atspi_accessible_get_name (get, NULL)); + get = g_array_index (ret, AtspiAccessible *, 2); + g_assert_cmpstr("obj3", ==, atspi_accessible_get_name (get, NULL)); +} + + +void +atk_test_collection (void ) +{ + g_test_add_vtable (ATK_TEST_PATH_COLLECTION "/atk_test_collection_get_collection_iface", + 0, NULL, NULL, atk_test_collection_get_collection_iface, teardown_collection_test ); + g_test_add_vtable (ATK_TEST_PATH_COLLECTION "/atk_test_collection_get_matches", + 0, NULL, NULL, atk_test_collection_get_matches, teardown_collection_test ); + g_test_add_vtable (ATK_TEST_PATH_COLLECTION "/atk_test_collection_get_matches_to", + 0, NULL, NULL, atk_test_collection_get_matches_to, teardown_collection_test ); + g_test_add_vtable (ATK_TEST_PATH_COLLECTION "/atk_test_collection_get_matches_from", + 0, NULL, NULL, atk_test_collection_get_matches_from, teardown_collection_test ); +} + diff --git a/tests/atk_test_component.c b/tests/atk_test_component.c index 8b85f5b..f3ea30b 100644 --- a/tests/atk_test_component.c +++ b/tests/atk_test_component.c @@ -85,35 +85,6 @@ atk_test_component_get_extents (gpointer fixture, gconstpointer user_data) g_free (r); } -static void -atk_test_component_get_position (gpointer fixture, gconstpointer user_data) -{ - AtspiAccessible *obj = get_root_obj (DATA_FILE); - AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,1, NULL); - AtspiComponent *iface = atspi_accessible_get_component_iface (child); - g_assert (iface != NULL); - - AtspiPoint *p = atspi_component_get_position (iface, ATSPI_COORD_TYPE_SCREEN, NULL); - g_assert_cmpint (p->x, ==, 350); - g_assert_cmpint (p->y, ==, 200); - g_free (p); -} - -static void -atk_test_component_get_size (gpointer fixture, gconstpointer user_data) -{ - AtspiAccessible *obj = get_root_obj (DATA_FILE); - AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL); - AtspiComponent *iface = atspi_accessible_get_component_iface (child); - g_assert (iface != NULL); - - AtspiPoint *p = atspi_component_get_size (iface, NULL); - g_assert (p != NULL); - g_assert_cmpint (p->x, ==, 350); - g_assert_cmpint (p->y, ==, 200); - g_free (p); -} - static void atk_test_component_get_layer (gpointer fixture, gconstpointer user_data) { @@ -188,42 +159,6 @@ atk_test_component_set_extents (gpointer fixture, gconstpointer user_data) g_free (r); } -static void -atk_test_component_set_position (gpointer fixture, gconstpointer user_data) -{ - AtspiAccessible *obj = get_root_obj (DATA_FILE); - AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL); - AtspiComponent *iface = atspi_accessible_get_component_iface (child); - g_assert (iface != NULL); - - gboolean ret = atspi_component_set_position (iface, 350, 250, ATSPI_COORD_TYPE_SCREEN, NULL); - g_assert (ret != FALSE); - - AtspiPoint *p = atspi_component_get_position (iface, ATSPI_COORD_TYPE_SCREEN, NULL); - g_assert (p != NULL ); - g_assert_cmpint (p->x, ==, 350); - g_assert_cmpint (p->y, ==, 200); - g_free (p); -} - -static void -atk_test_component_set_size (gpointer fixture, gconstpointer user_data) -{ - AtspiAccessible *obj = get_root_obj (DATA_FILE); - AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL); - AtspiComponent *iface = atspi_accessible_get_component_iface (child); - g_assert (iface != NULL); - - gboolean ret = atspi_component_set_size (iface, 350, 250, NULL); - g_assert (ret != FALSE); - - AtspiPoint *p = atspi_component_get_size (iface, NULL); - g_assert (p != NULL); - g_assert_cmpint (p->x, ==, 350); - g_assert_cmpint (p->y, ==, 200); - g_free (p); -} - void atk_test_component (void) { @@ -245,13 +180,4 @@ atk_test_component (void) 0, NULL, NULL, atk_test_component_get_alpha, teardown_component_test); g_test_add_vtable (ATK_TEST_PATH_COMP "/atk_test_component_set_extents", 0, NULL, NULL, atk_test_component_set_extents, teardown_component_test); -// DEPRICATED -// g_test_add_vtable (ATK_TEST_PATH_COMP "/atk_test_component_get_position", -// 0, NULL, NULL, atk_test_component_get_position, teardown_component_test); -// g_test_add_vtable (ATK_TEST_PATH_COMP "/atk_test_component_get_size", -// 0, NULL, NULL, atk_test_component_get_size, teardown_component_test); -// g_test_add_vtable (ATK_TEST_PATH_COMP "/atk_test_component_set_position", -// 0, NULL, NULL, atk_test_component_set_position, teardown_component_test); -// g_test_add_vtable (ATK_TEST_PATH_COMP "/atk_test_component_set_size", -// 0, NULL, NULL, atk_test_component_set_size, teardown_component_test); } diff --git a/tests/atk_test_editable_text.c b/tests/atk_test_editable_text.c new file mode 100644 index 0000000..e0c0701 --- /dev/null +++ b/tests/atk_test_editable_text.c @@ -0,0 +1,128 @@ +/* + * AT-SPI - Assistive Technology Service Provider Interface + * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility) + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "atk_suite.h" +#include "atk_test_util.h" + +#define DATA_FILE TESTS_DATA_DIR"/test-editable-text.xml" + +static void +teardown_editable_text_test (gpointer fixture, gconstpointer user_data) +{ + kill (child_pid, SIGTERM); +} + +static void +atk_test_editable_text_get_editable_text_iface (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL); + AtspiEditableText *iface = atspi_accessible_get_editable_text_iface (child); + g_assert (iface != NULL); +} + +#if 0 +/* Function is in docs but not implemented */ +static void +atk_test_editable_text_set_attributes (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL); + AtspiEditableText *iface = atspi_accessible_get_editable_text_iface (child); + g_assert (iface != NULL); + + g_assert (atspi_editable_text_set_attributes (iface, "attribute", 1, 2, NULL)); +} +#endif + +static void +atk_test_editable_text_insert_text (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL); + AtspiEditableText *iface = atspi_accessible_get_editable_text_iface (child); + g_assert (iface != NULL); + g_assert (atspi_editable_text_insert_text (iface, 0, "test_text", 9, NULL)); +} + +static void +atk_test_editable_text_copy_text (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL); + AtspiEditableText *iface = atspi_accessible_get_editable_text_iface (child); + g_assert (iface != NULL); + g_assert (atspi_editable_text_copy_text (iface, 1, 2, NULL)); +} + +static void +atk_test_editable_text_cut_text (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL); + AtspiEditableText *iface = atspi_accessible_get_editable_text_iface (child); + g_assert (iface != NULL); + g_assert (atspi_editable_text_cut_text (iface, 1, 2, NULL)); +} + +static void +atk_test_editable_text_delete_text (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL); + AtspiEditableText *iface = atspi_accessible_get_editable_text_iface (child); + g_assert (iface != NULL); + + g_assert (atspi_editable_text_delete_text (iface, 1, 2, NULL)); +} + +static void +atk_test_editable_text_paste_text (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL); + AtspiEditableText *iface = atspi_accessible_get_editable_text_iface (child); + g_assert (iface != NULL); + + g_assert (atspi_editable_text_paste_text (iface, 2, NULL)); +} + +void +atk_test_editable_text(void ) +{ + g_test_add_vtable (ATK_TEST_PATH_EDIT_TEXT "/atk_test_editable_text_get_editable_text_iface", + 0, NULL, NULL, atk_test_editable_text_get_editable_text_iface, teardown_editable_text_test); +#if 0 + g_test_add_vtable (ATK_TEST_PATH_EDIT_TEXT "/atk_test_editable_text_set_attributes", + 0, NULL, NULL, atk_test_editable_text_set_attributes, teardown_editable_text_test); +#endif + g_test_add_vtable (ATK_TEST_PATH_EDIT_TEXT "/atk_test_editable_text_insert_text", + 0, NULL, NULL, atk_test_editable_text_insert_text, teardown_editable_text_test); + g_test_add_vtable (ATK_TEST_PATH_EDIT_TEXT "/atk_test_editable_text_copy_text", + 0, NULL, NULL, atk_test_editable_text_copy_text, teardown_editable_text_test); + g_test_add_vtable (ATK_TEST_PATH_EDIT_TEXT "/atk_test_editable_text_cut_text", + 0, NULL, NULL, atk_test_editable_text_cut_text, teardown_editable_text_test); + g_test_add_vtable (ATK_TEST_PATH_EDIT_TEXT "/atk_test_editable_text_delete_text", + 0, NULL, NULL, atk_test_editable_text_delete_text, teardown_editable_text_test); + g_test_add_vtable (ATK_TEST_PATH_EDIT_TEXT "/atk_test_editable_text_paste_text", + 0, NULL, NULL, atk_test_editable_text_paste_text, teardown_editable_text_test); +} diff --git a/tests/atk_test_image.c b/tests/atk_test_image.c new file mode 100644 index 0000000..ce3bc3e --- /dev/null +++ b/tests/atk_test_image.c @@ -0,0 +1,128 @@ +/* + * AT-SPI - Assistive Technology Service Provider Interface + * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility) + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "atk_suite.h" +#include "atk_test_util.h" + +#define DATA_FILE TESTS_DATA_DIR"/test-image.xml" + +static void +teardown_image_test (gpointer fixture, gconstpointer user_data) +{ + kill (child_pid, SIGTERM); +} + +static void +atk_test_image_sample_get_interface (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + g_assert_cmpstr (atspi_accessible_get_name (obj, NULL), ==, "root_object"); + AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,1, NULL); + AtspiImage *iface = atspi_accessible_get_image_iface (child); + g_assert (iface != NULL); +} + +static void +atk_test_image_get_image_description (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,1, NULL); + AtspiImage *image = atspi_accessible_get_image_iface (child); + gchar *desc = atspi_image_get_image_description (image, NULL); + g_assert (desc); + g_assert_cmpstr (desc, == ,"image description"); + g_free (desc); +} + +static void +atk_test_image_get_image_size (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,1, NULL); + AtspiImage *image = atspi_accessible_get_image_iface (child); + AtspiPoint *p = atspi_image_get_image_size (image, NULL); + g_assert (p); + + g_assert_cmpint (p->x,==,100); + g_assert_cmpint (p->y,==,50); + g_free (p); +} + +static void +atk_test_image_get_image_position (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,1, NULL); + AtspiImage *image = atspi_accessible_get_image_iface (child); + AtspiPoint *p = atspi_image_get_image_position (image, ATSPI_COORD_TYPE_SCREEN, NULL); + g_assert (p); + g_assert_cmpint (p->x,==,500); + g_assert_cmpint (p->y,==,50); + g_free (p); +} + +static void +atk_test_image_get_image_extents (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,1, NULL); + AtspiImage *image = atspi_accessible_get_image_iface (child); + AtspiRect *r = atspi_image_get_image_extents (image, ATSPI_COORD_TYPE_SCREEN, NULL); + g_assert (r); + + g_assert_cmpint (r->x, ==, 500); + g_assert_cmpint (r->y, ==, 50); + g_assert_cmpint (r->width, ==, 100); + g_assert_cmpint (r->height, ==, 50); + + g_free (r); +} + +static void +atk_test_image_get_image_locale (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *obj = get_root_obj (DATA_FILE); + AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,1, NULL); + AtspiImage *image = atspi_accessible_get_image_iface (child); + gchar *locale = atspi_image_get_image_locale (image, NULL); + + g_assert (locale); + g_assert_cmpstr (locale, ==,"image_locale"); + g_free (locale); +} + +void +atk_test_image (void) +{ + g_test_add_vtable (ATK_TEST_PATH_IMAGE "/atk_test_image_sample_get_interface", + 0, NULL, NULL, atk_test_image_sample_get_interface, teardown_image_test); + g_test_add_vtable (ATK_TEST_PATH_IMAGE "/atk_test_image_get_image_description", + 0, NULL, NULL, atk_test_image_get_image_description, teardown_image_test); + g_test_add_vtable (ATK_TEST_PATH_IMAGE "/atk_test_image_get_image_size", + 0, NULL, NULL, atk_test_image_get_image_size, teardown_image_test); + g_test_add_vtable (ATK_TEST_PATH_IMAGE "/atk_test_image_get_image_position", + 0, NULL, NULL, atk_test_image_get_image_position, teardown_image_test); + g_test_add_vtable (ATK_TEST_PATH_IMAGE "/atk_test_image_get_image_extents", + 0, NULL, NULL, atk_test_image_get_image_extents, teardown_image_test); + g_test_add_vtable (ATK_TEST_PATH_IMAGE "/atk_test_image_get_image_locale", + 0, NULL, NULL, atk_test_image_get_image_locale, teardown_image_test); +} diff --git a/tests/atk_test_text.c b/tests/atk_test_text.c new file mode 100644 index 0000000..b9e29dc --- /dev/null +++ b/tests/atk_test_text.c @@ -0,0 +1,481 @@ +/* + * AT-SPI - Assistive Technology Service Provider Interface + * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility) + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "atk_test_util.h" +#include "atk_suite.h" + +#define DATA_FILE TESTS_DATA_DIR"/test-text.xml" + +static gboolean GHRunc_find (gpointer key, gpointer value, gpointer user_data) +{ + if (!g_strcmp0 (key, user_data)) { + return TRUE; + } + return FALSE; +} + +static void +atk_test_text_get_character_count (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + gint count = atspi_text_get_character_count (obj, NULL); + g_assert_cmpint (count, ==, 16); +} + +static void +atk_test_text_get_text (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + gchar *text = atspi_text_get_text (obj, 9, 14, NULL); + g_assert_cmpstr (text, ==, "works"); + g_free (text); +} + +static void +atk_test_text_get_caret_offset (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + gint pos = atspi_text_get_caret_offset (obj, NULL); + g_assert_cmpint (pos,==,-1); +} + +static void +atk_test_text_set_caret_offset (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + g_assert_true (atspi_text_set_caret_offset (obj, 5, NULL)); + g_assert_false (atspi_text_set_caret_offset (obj, -1, NULL)); + gint pos = atspi_text_get_caret_offset (obj, NULL); + g_assert_cmpint (pos, ==, 5); +} +static void +atk_test_text_get_character_at_offset (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + guint chr = atspi_text_get_character_at_offset (obj, 5, NULL); + g_assert_cmpint (chr, ==, 32); +} + +static void +atk_test_text_get_character_extents (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + AtspiRect *rec = atspi_text_get_character_extents (obj, 6, ATSPI_COORD_TYPE_SCREEN, NULL); + g_assert_cmpint (rec->x, ==, 100); + g_assert_cmpint (rec->y, ==, 33); + g_assert_cmpint (rec->width, ==, 110); + g_assert_cmpint (rec->height, ==, 30); + + g_free (rec); +} + +static void +atk_test_text_get_range_extents (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + AtspiRect *rec = atspi_text_get_range_extents (obj, 0, 1, ATSPI_COORD_TYPE_SCREEN, NULL); + + g_assert_cmpint (rec->x, ==, 100); + g_assert_cmpint (rec->y, ==, 33); + g_assert_cmpint (rec->width, ==, 110); + g_assert_cmpint (rec->height, ==, 30); + + g_free (rec); +} + +static void +atk_test_text_add_selection (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + g_assert_true (atspi_text_add_selection (obj, 9, 14, NULL)); +} + +static void +atk_test_text_get_n_selections (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + gint n = atspi_text_get_n_selections (obj, NULL); + g_assert_cmpint (n, ==, 0); + g_assert_true (atspi_text_add_selection (obj, 9, 14, NULL)); + g_assert_true (atspi_text_add_selection (obj, 9, 14, NULL)); + g_assert_true (atspi_text_add_selection (obj, 9, 14, NULL)); + n = atspi_text_get_n_selections (obj, NULL); + g_assert_cmpint (n, ==, 3); +} + +static void +atk_test_text_get_selection (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + g_assert_true (atspi_text_add_selection (obj, 9, 14, NULL)); + g_assert_true (atspi_text_add_selection (obj, 14, 15, NULL)); + + AtspiRange *range = atspi_text_get_selection (obj, 0, NULL); + g_assert (range); + g_assert_cmpint (range->start_offset, ==, 9); + g_assert_cmpint (range->end_offset, ==, 14); + g_free (range); + + range = atspi_text_get_selection (obj, 1, NULL); + g_assert (range); + g_assert_cmpint (range->start_offset, ==, 14); + g_assert_cmpint (range->end_offset, ==, 15); + g_free (range); +} + +static void +atk_test_text_set_selection (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + g_assert_true(atspi_text_add_selection (obj, 9, 14, NULL)); + g_assert_true(atspi_text_add_selection (obj, 14, 15, NULL)); + g_assert_true(atspi_text_set_selection (obj, 0, 1, 2, NULL)); + g_assert_true(atspi_text_set_selection (obj, 1, 3, 4, NULL)); + + AtspiRange *range = atspi_text_get_selection (obj, 0, NULL); + g_assert (range); + g_assert_cmpint (range->start_offset, ==, 1); + g_assert_cmpint (range->end_offset, ==, 2); + g_free (range); + + range = atspi_text_get_selection (obj, 1, NULL); + g_assert (range); + g_assert_cmpint (range->start_offset, ==, 3); + g_assert_cmpint (range->end_offset, ==, 4); + g_free (range); +} + +static void +atk_test_text_remove_selection (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + gint n = atspi_text_get_n_selections (obj, NULL); + g_assert_cmpint (n, ==, 0); + + g_assert_true (atspi_text_add_selection (obj, 9, 14, NULL)); + g_assert_true (atspi_text_add_selection (obj, 14, 15, NULL)); + n = atspi_text_get_n_selections (obj, NULL); + g_assert_cmpint (n, ==, 2); + + g_assert_true (atspi_text_remove_selection (obj, 1, NULL)); + n = atspi_text_get_n_selections (obj, NULL); + g_assert_cmpint (n, ==, 1); + + g_assert_true (atspi_text_remove_selection (obj, 0, NULL)); + n = atspi_text_get_n_selections (obj, NULL); + g_assert_cmpint (n, ==, 0); +} + +static void +atk_test_text_get_offset_at_point (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + gint n = atspi_text_get_offset_at_point (obj, 0, 0, ATSPI_COORD_TYPE_SCREEN, NULL); + g_assert_cmpint (n, ==, 5); +} + +static void +atk_test_text_get_text_attribute_value (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + GError *err = NULL; + gchar *str = atspi_text_get_text_attribute_value (obj, 0, "text_test_attr1", &err); + if (err) + g_print ("error msg:%s\n", err->message); + g_assert (str); + g_assert_cmpstr (str, ==, "on"); + g_free (str); + + str = atspi_text_get_text_attribute_value (obj, 0, "text_test_attr2", NULL); + g_assert (str); + g_assert_cmpstr (str, ==, "off"); + g_free (str); +} + +static void +atk_test_text_get_attribute_run (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + gint start_offset = 0; + gint end_offset = 0; + GHashTable *tab = atspi_text_get_attribute_run (obj, 0, FALSE, &start_offset, &end_offset , NULL); + + g_assert (tab); + + g_assert_cmpstr ((const char*) g_hash_table_find (tab, GHRunc_find, "text_test_attr1"), ==, "on"); + g_assert_cmpstr ((const char*) g_hash_table_find (tab, GHRunc_find, "text_test_attr2"), ==, "off"); + g_assert_cmpint (start_offset, == , 5); + g_assert_cmpint (end_offset, == , 10); + g_hash_table_destroy (tab); +} + +static void +atk_test_text_get_defualt_attributes (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + GHashTable *tab = atspi_text_get_default_attributes (obj, NULL); + g_assert (tab); + + g_assert_cmpstr ((const char*) g_hash_table_find (tab, GHRunc_find, "bold_text"), ==, "on"); + g_assert_cmpstr ((const char*) g_hash_table_find (tab, GHRunc_find, "underline_text"), ==, "off"); + g_assert_cmpstr ((const char*) g_hash_table_find (tab, GHRunc_find, "dummy_text"), ==, ""); + g_hash_table_destroy (tab); +} + +static void +atk_test_text_get_text_attributes (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + gint start_offset = 0; + gint end_offset = 0; + GHashTable *tab = atspi_text_get_text_attributes (obj, 0, &start_offset, &end_offset, NULL); + + g_assert (tab); + + g_assert_cmpstr ((const char*) g_hash_table_find (tab, GHRunc_find, "text_test_attr1"), ==, "on"); + g_assert_cmpstr ((const char*) g_hash_table_find (tab, GHRunc_find, "text_test_attr2"), ==, "off"); + g_assert_cmpint (start_offset, == , 5); + g_assert_cmpint (end_offset, == , 10); + g_hash_table_destroy (tab); +} + +static void +atk_test_text_get_string_at_offset_s1 (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + AtspiTextRange *range = atspi_text_get_string_at_offset (obj, 0, ATSPI_TEXT_GRANULARITY_CHAR, NULL); + + g_assert_cmpint (range->start_offset, ==, 0); + g_assert_cmpint (range->end_offset, ==, 1); + g_assert_cmpstr (range->content, ==, "t"); + + g_free (range); + + range = atspi_text_get_string_at_offset (obj, 5, ATSPI_TEXT_GRANULARITY_WORD, NULL); + + g_assert_cmpint (range->start_offset, ==, 6); + g_assert_cmpint (range->end_offset, ==, 7); + g_assert_cmpstr (range->content, ==, "it"); + + g_free (range); +} +static void +atk_test_text_get_string_at_offset_s2 (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 1, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + AtspiTextRange *range = atspi_text_get_string_at_offset (obj, 20, ATSPI_TEXT_GRANULARITY_SENTENCE, NULL); + + g_assert_cmpint (range->start_offset, ==, 18); + g_assert_cmpint (range->end_offset, ==, 34); + g_assert_cmpstr (range->content, ==, "Second sentence."); + + g_free (range); + + range = atspi_text_get_string_at_offset (obj, 21, ATSPI_TEXT_GRANULARITY_LINE, NULL); + + g_assert_cmpint (range->start_offset, ==, 18); + g_assert_cmpint (range->end_offset, ==, 34); + g_assert_cmpstr (range->content, ==, "Second sentence."); + + g_free (range); + + range = atspi_text_get_string_at_offset (obj, 0, ATSPI_TEXT_GRANULARITY_PARAGRAPH, NULL); + + g_assert_cmpint (range->start_offset, ==, 0); + g_assert_cmpint (range->end_offset, ==, 0); + g_assert_cmpstr (range->content, ==, ""); + + g_free (range); +} + +static void +atk_test_text_get_bounded_ranges (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiText *obj = atspi_accessible_get_text_iface (child); + + GArray *array = atspi_text_get_bounded_ranges (obj, 15, 21, 100, 50, ATSPI_COORD_TYPE_SCREEN, ATSPI_TEXT_CLIP_MAX, ATSPI_TEXT_CLIP_MIN, NULL); + g_assert (array); + + AtspiTextRange *range = &g_array_index (array, AtspiTextRange, 0); + g_assert_cmpint (g_array_get_element_size (array), ==, sizeof (AtspiTextRange)); + g_assert_cmpint (range->start_offset, ==, 0); + g_assert_cmpint (range->end_offset, ==, 5); + g_assert_cmpstr (range->content, ==, "text0"); + + range = &g_array_index (array, AtspiTextRange, 1); + g_assert_cmpint (g_array_get_element_size (array), ==, sizeof (AtspiTextRange)); + g_assert_cmpint (range->start_offset, ==, 6); + g_assert_cmpint (range->end_offset, ==, 10); + g_assert_cmpstr (range->content, ==, "it w"); + + g_array_free (array,TRUE); +} + +static void +teardown_text_test (gpointer fixture, gconstpointer user_data) +{ + kill (child_pid, SIGTERM); +} + +void +atk_test_text (void) +{ + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_character_count", + 0, NULL, NULL, atk_test_text_get_character_count, teardown_text_test); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_text", + 0, NULL, NULL, atk_test_text_get_text, teardown_text_test); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_caret_offset", + 0, NULL, NULL, atk_test_text_get_caret_offset, teardown_text_test); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_text_attributes", + 0, NULL, NULL, atk_test_text_get_text_attributes, teardown_text_test); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_attribute_run", + 0, NULL, NULL, atk_test_text_get_attribute_run, teardown_text_test); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_text_attribute_value", + 0, NULL, NULL, atk_test_text_get_text_attribute_value, teardown_text_test); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_defualt_attributes", + 0, NULL, NULL, atk_test_text_get_defualt_attributes, teardown_text_test); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_set_caret_offset", + 0, NULL, NULL, atk_test_text_set_caret_offset, teardown_text_test); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_string_at_offset_s1", + 0, NULL, NULL, atk_test_text_get_string_at_offset_s1, teardown_text_test ); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_string_at_offset_s2", + 0, NULL, NULL, atk_test_text_get_string_at_offset_s2, teardown_text_test ); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_character_at_offset", + 0, NULL, NULL, atk_test_text_get_character_at_offset, teardown_text_test); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_character_extents", + 0, NULL, NULL, atk_test_text_get_character_extents, teardown_text_test); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_offset_at_point", + 0, NULL, NULL, atk_test_text_get_offset_at_point, teardown_text_test); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_range_extents", + 0, NULL, NULL, atk_test_text_get_range_extents, teardown_text_test); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_bounded_ranges", + 0, NULL, NULL, atk_test_text_get_bounded_ranges, teardown_text_test); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_n_selections", + 0, NULL, NULL, atk_test_text_get_n_selections, teardown_text_test); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_selection", + 0, NULL, NULL, atk_test_text_get_selection, teardown_text_test); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_add_selection", + 0, NULL, NULL, atk_test_text_add_selection, teardown_text_test ); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_remove_selection", + 0, NULL, NULL, atk_test_text_remove_selection, teardown_text_test ); + g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_set_selection", + 0, NULL, NULL, atk_test_text_set_selection, teardown_text_test); +} diff --git a/tests/atk_test_util.c b/tests/atk_test_util.c index 22c791d..c776ae1 100644 --- a/tests/atk_test_util.c +++ b/tests/atk_test_util.c @@ -36,7 +36,6 @@ void clean_exit_on_fail () void run_app (const char *file_name) { - int i=0; child_pid = fork (); if (child_pid == 0) { execlp ("./app-test", diff --git a/tests/atk_test_value.c b/tests/atk_test_value.c new file mode 100644 index 0000000..c5f2c06 --- /dev/null +++ b/tests/atk_test_value.c @@ -0,0 +1,119 @@ +/* + * Copyright 2008 Codethink Ltd. + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "atk_test_util.h" +#include "atk_suite.h" + +#define DATA_FILE TESTS_DATA_DIR"/test-value.xml" + +static void +atk_test_value_get_value_iface (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiValue *obj = atspi_accessible_get_value_iface (child); + g_assert (obj); +} + +static void +atk_test_value_get_minimum_value (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiValue *obj = atspi_accessible_get_value_iface (child); + gdouble val = atspi_value_get_minimum_value (obj, NULL); + g_assert_cmpfloat (val, ==, 1.1); +} + +static void +atk_test_value_get_current_value (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiValue *obj = atspi_accessible_get_value_iface (child); + gdouble val = atspi_value_get_current_value (obj, NULL); + g_assert_cmpfloat (val, ==, 2.1); +} + +static void +atk_test_value_get_maximum_value (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiValue *obj = atspi_accessible_get_value_iface (child); + gdouble val = atspi_value_get_maximum_value (obj, NULL); + g_assert_cmpfloat (val, ==, 3.1); +} + +static void +atk_test_value_set_current_value (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiValue *obj = atspi_accessible_get_value_iface (child); + g_assert (atspi_value_set_current_value (obj, 2.5, NULL)); + gdouble val = atspi_value_get_current_value (obj, NULL); + g_assert_cmpfloat (val, ==, 2.5); +} + +static void +atk_test_value_get_minimum_increment (gpointer fixture, gconstpointer user_data) +{ + AtspiAccessible *_obj = get_root_obj (DATA_FILE); + g_assert (_obj); + AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL); + g_assert (child); + AtspiValue *obj = atspi_accessible_get_value_iface (child); + gdouble val = atspi_value_get_minimum_increment (obj, NULL); + g_assert_cmpfloat (val, ==, 0.1); +} + +static void +teardown_value_test (gpointer fixture, gconstpointer user_data) +{ + kill (child_pid, SIGTERM); +} + +void +atk_test_value (void) +{ + g_test_add_vtable (ATK_TEST_PATH_VALUE "/atk_test_value_get_value_iface", + 0, NULL, NULL, atk_test_value_get_value_iface, teardown_value_test ); + g_test_add_vtable (ATK_TEST_PATH_VALUE "/atk_test_value_get_minimum_value", + 0, NULL, NULL, atk_test_value_get_minimum_value, teardown_value_test ); + g_test_add_vtable (ATK_TEST_PATH_VALUE "/atk_test_value_get_current_value", + 0, NULL, NULL, atk_test_value_get_current_value, teardown_value_test ); + g_test_add_vtable (ATK_TEST_PATH_VALUE "/atk_test_value_get_maximum_value", + 0, NULL, NULL, atk_test_value_get_maximum_value, teardown_value_test ); + g_test_add_vtable (ATK_TEST_PATH_VALUE "/atk_test_value_set_current_value", + 0, NULL, NULL, atk_test_value_set_current_value, teardown_value_test ); + g_test_add_vtable (ATK_TEST_PATH_VALUE "/atk_test_value_get_minimum_increment", + 0, NULL, NULL, atk_test_value_get_minimum_increment, teardown_value_test ); +} diff --git a/tests/data/test-collection.xml b/tests/data/test-collection.xml new file mode 100644 index 0000000..7086ede --- /dev/null +++ b/tests/data/test-collection.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-editable-text.xml b/tests/data/test-editable-text.xml new file mode 100644 index 0000000..ae8084c --- /dev/null +++ b/tests/data/test-editable-text.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/data/test-image.xml b/tests/data/test-image.xml new file mode 100644 index 0000000..b678ac2 --- /dev/null +++ b/tests/data/test-image.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tests/data/test-text.xml b/tests/data/test-text.xml new file mode 100644 index 0000000..ab72522 --- /dev/null +++ b/tests/data/test-text.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/data/test-value.xml b/tests/data/test-value.xml new file mode 100644 index 0000000..83172d5 --- /dev/null +++ b/tests/data/test-value.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/dummyatk/Makefile.am b/tests/dummyatk/Makefile.am index 32c9849..e8049b6 100644 --- a/tests/dummyatk/Makefile.am +++ b/tests/dummyatk/Makefile.am @@ -3,7 +3,8 @@ lib_LTLIBRARIES = libdummyatk.la libdummyatk_la_CFLAGS = $(ATK_CFLAGS) \ $(GLIB_CFLAGS) \ $(GOBJ_CFLAGS) \ - -I$(top_srcdir) + -I$(top_srcdir) \ + -Wall libdummyatk_la_LDFLAGS = -no-undefined @@ -16,6 +17,14 @@ libdummyatk_la_SOURCES = \ my-atk-action.h \ my-atk-component.c \ my-atk-component.h \ + my-atk-editable-text.c \ + my-atk-editable-text.h \ + my-atk-image.c \ + my-atk-image.h \ + my-atk-text.c \ + my-atk-text.h \ my-atk-object.c \ my-atk-object.h \ + my-atk-value.c \ + my-atk-value.h \ my-atk.h diff --git a/tests/dummyatk/my-atk-action.c b/tests/dummyatk/my-atk-action.c index fec73d2..8d688cb 100644 --- a/tests/dummyatk/my-atk-action.c +++ b/tests/dummyatk/my-atk-action.c @@ -220,12 +220,6 @@ my_atk_action_do_action (AtkAction *action, gint i) { g_return_val_if_fail (MY_IS_ATK_ACTION (action), NULL); - MyAtkAction *my_action = NULL; - MyAtkActionPrivate *priv = NULL; - - my_action = MY_ATK_ACTION (action); - priv = my_action->priv; - perform_action (ATK_OBJECT (action)); return FALSE; diff --git a/tests/dummyatk/my-atk-editable-text.c b/tests/dummyatk/my-atk-editable-text.c new file mode 100644 index 0000000..3af2a41 --- /dev/null +++ b/tests/dummyatk/my-atk-editable-text.c @@ -0,0 +1,138 @@ +/* + * AT-SPI - Assistive Technology Service Provider Interface + * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility) + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include + +#include "my-atk-object.h" +#include "my-atk-editable-text.h" + +typedef struct _MyAtkEditableTextInfo MyAtkEditableTextInfo; + +static void atk_editable_text_interface_init (AtkEditableTextIface *iface); + +G_DEFINE_TYPE_WITH_CODE (MyAtkEditableText, + my_atk_editable_text, + MY_TYPE_ATK_OBJECT, + G_IMPLEMENT_INTERFACE (ATK_TYPE_EDITABLE_TEXT, + atk_editable_text_interface_init)); + +guint +my_atk_set_editable_text (AtkEditableText *editable_text, const gchar *text) +{ + g_return_val_if_fail (MY_IS_ATK_EDITABLE_TEXT (editable_text), -1); + + return 0; +} + +static void +my_atk_editable_text_init (MyAtkEditableText *obj) +{ + obj->text = NULL; +} + +static gboolean +my_atk_set_editable_text_set_run_attributes (AtkEditableText *text, + AtkAttributeSet *attrib_set, + gint start_offset, + gint end_offset) +{ + return FALSE; +} + +static void +my_atk_set_editable_text_set_text_contents (AtkEditableText *text, + const gchar *string) +{ +} + +static void +my_atk_set_editable_text_insert_text (AtkEditableText *text, + const gchar *string, + gint length, + gint *position) +{ +} + +static void +my_atk_set_editable_text_copy_text (AtkEditableText *text, + gint start_pos, + gint end_pos) +{ +} + +static void +my_atk_set_editable_text_cut_text (AtkEditableText *text, + gint start_pos, + gint end_pos) +{ +} + +static void +my_atk_set_editable_text_delete_text (AtkEditableText *text, + gint start_pos, + gint end_pos) +{ +} + +static void +my_atk_set_editable_text_paste_text (AtkEditableText *text, + gint position) +{ +} + + +static void +atk_editable_text_interface_init (AtkEditableTextIface *iface) +{ + if (!iface) return; + iface->set_run_attributes = my_atk_set_editable_text_set_run_attributes; + iface->set_text_contents = my_atk_set_editable_text_set_text_contents; + iface->insert_text = my_atk_set_editable_text_insert_text; + iface->copy_text = my_atk_set_editable_text_copy_text; + iface->cut_text = my_atk_set_editable_text_cut_text; + iface->delete_text = my_atk_set_editable_text_delete_text; + iface->paste_text = my_atk_set_editable_text_paste_text; +} + +static void +my_atk_editable_text_initialize (AtkObject *obj, gpointer data) +{ +} + +static void +my_atk_editable_text_finalize (GObject *object) +{ +} + +static void +my_atk_editable_text_class_init (MyAtkEditableTextClass *my_class) +{ + AtkObjectClass *atk_class = ATK_OBJECT_CLASS (my_class); + GObjectClass *gobject_class = G_OBJECT_CLASS (my_class); + + gobject_class->finalize = my_atk_editable_text_finalize; + + atk_class->initialize = my_atk_editable_text_initialize; +} diff --git a/tests/dummyatk/my-atk-editable-text.h b/tests/dummyatk/my-atk-editable-text.h new file mode 100644 index 0000000..3b3e432 --- /dev/null +++ b/tests/dummyatk/my-atk-editable-text.h @@ -0,0 +1,57 @@ +/* + * AT-SPI - Assistive Technology Service Provider Interface + * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility) + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef MY_ATK_EDITABLE_TEXT_H_ +#define MY_ATK_EDITABLE_TEXT_H_ + +#include +#include +#include + +#include "my-atk-object.h" + +#define MY_TYPE_ATK_EDITABLE_TEXT (my_atk_editable_text_get_type ()) +#define MY_ATK_EDITABLE_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MY_TYPE_ATK_EDITABLE_TEXT, MyAtkEditableText)) +#define MY_ATK_EDITABLE_TEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), MY_TYPE_ATK_EDITABLE_TEXT, MyAtkEditableTextClass)) +#define MY_IS_ATK_EDITABLE_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MY_TYPE_ATK_EDITABLE_TEXT)) +#define MY_IS_ATK_EDITABLE_TEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), MY_TYPE_ATK_EDITABLE_TEXT)) +#define MY_ATK_EDITABLE_TEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), MY_TYPE_ATK_EDITABLE_TEXT, MyAtkEditableTextClass)) + +typedef struct _MyAtkEditableText MyAtkEditableText; +typedef struct _MyAtkEditableTextClass MyAtkEditableTextClass; + +typedef void (* MyAtkEditableTextFunc) (MyAtkEditableText *editable_text); + +struct _MyAtkEditableText { + MyAtkObject parent; + gchar *text; +}; + +struct _MyAtkEditableTextClass { + MyAtkObjectClass parent; +}; + +GType my_atk_editable_text_get_type (void); + +guint my_atk_set_editable_text (AtkEditableText *editable_text, const gchar *text); + +#endif /* MY_ATK_EDITABLE_TEXT_H_ */ diff --git a/tests/dummyatk/my-atk-image.c b/tests/dummyatk/my-atk-image.c new file mode 100644 index 0000000..c714a45 --- /dev/null +++ b/tests/dummyatk/my-atk-image.c @@ -0,0 +1,157 @@ +/* + * AT-SPI - Assistive Technology Service Provider Interface + * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility) + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#include +#include +#include + +#include "my-atk-object.h" +#include "my-atk-image.h" + +typedef struct _MyAtkImageInfo MyAtkImageInfo; + +static void atk_image_interface_init (AtkImageIface *iface); + +G_DEFINE_TYPE_WITH_CODE (MyAtkImage, + my_atk_image, + MY_TYPE_ATK_OBJECT, + G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, + atk_image_interface_init)); + +guint +my_atk_set_image (AtkImage *image, + const gchar *desc, + const gint x, + const gint y, + const gint width, + const gint height, + const gchar *locale) +{ + g_return_val_if_fail (MY_IS_ATK_IMAGE (image), FALSE); + + MyAtkImage *self = MY_ATK_IMAGE (image); + + self->description = g_strdup (desc); + self->x = x; + self->y = y; + self->width = width; + self->height = height; + self->locale = g_strdup (locale); + + return 0; +} + +static void +my_atk_image_init (MyAtkImage *obj) +{ + MyAtkImage *self = MY_ATK_IMAGE (obj); + self->description = NULL; + self->x = -1; + self->y = -1; + self->width = -1; + self->height = -1; + self->locale = NULL; +} + +void my_atk_image_get_image_position (AtkImage *obj, gint *x, gint *y, AtkCoordType coord_type) +{ + g_return_if_fail (MY_IS_ATK_IMAGE (obj)); + + MyAtkImage *self = MY_ATK_IMAGE (obj); + *x = self->x; + *y = self->y; +} + +const gchar* +my_atk_image_get_image_description (AtkImage *obj) +{ + g_return_val_if_fail (MY_IS_ATK_IMAGE (obj), NULL); + + MyAtkImage *self = MY_ATK_IMAGE (obj); + + return g_strdup (self->description); +} + +void my_atk_image_get_image_size (AtkImage *obj, gint *width, gint *height) +{ + g_return_if_fail (MY_IS_ATK_IMAGE (obj)); + + MyAtkImage *self = MY_ATK_IMAGE (obj); + *width = self->width; + *height = self->height; +} + +gboolean +my_atk_image_set_image_description (AtkImage *obj, const gchar * desc) +{ + g_return_val_if_fail (MY_IS_ATK_IMAGE (obj), FALSE); + + MyAtkImage *self = MY_ATK_IMAGE (obj); + + g_free (self->description); + self->description = g_strdup (desc); + + return TRUE; +} + +const gchar* +my_atk_image_get_image_locale (AtkImage *obj) +{ + g_return_val_if_fail (MY_IS_ATK_IMAGE (obj), NULL); + + MyAtkImage *self = MY_ATK_IMAGE (obj); + + return self->locale; +} + +static void +atk_image_interface_init (AtkImageIface *iface) +{ + if (!iface) return; + iface->get_image_position = my_atk_image_get_image_position; + iface->set_image_description = my_atk_image_set_image_description; + iface->get_image_description = my_atk_image_get_image_description; + iface->get_image_size = my_atk_image_get_image_size; + iface->get_image_locale = my_atk_image_get_image_locale; +} + +static void +my_atk_image_initialize (AtkObject *obj, gpointer data) +{ +} + +static void +my_atk_image_finalize (GObject *object) +{ +} + +static void +my_atk_image_class_init (MyAtkImageClass *my_class) +{ + AtkObjectClass *atk_class = ATK_OBJECT_CLASS (my_class); + GObjectClass *gobject_class = G_OBJECT_CLASS (my_class); + + gobject_class->finalize = my_atk_image_finalize; + + atk_class->initialize = my_atk_image_initialize; +} diff --git a/tests/dummyatk/my-atk-image.h b/tests/dummyatk/my-atk-image.h new file mode 100644 index 0000000..d8a91c8 --- /dev/null +++ b/tests/dummyatk/my-atk-image.h @@ -0,0 +1,68 @@ +/* + * AT-SPI - Assistive Technology Service Provider Interface + * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility) + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef MY_ATK_IMAGE_H_ +#define MY_ATK_IMAGE_H_ + +#include +#include +#include + +#include "my-atk-object.h" + +#define MY_TYPE_ATK_IMAGE (my_atk_image_get_type ()) +#define MY_ATK_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MY_TYPE_ATK_IMAGE, MyAtkImage)) +#define MY_ATK_IMAGE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), MY_TYPE_ATK_IMAGE, MyAtkImageClass)) +#define MY_IS_ATK_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MY_TYPE_ATK_IMAGE)) +#define MY_IS_ATK_IMAGE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), MY_TYPE_ATK_IMAGE)) +#define MY_ATK_IMAGE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), MY_TYPE_ATK_IMAGE, MyAtkImageClass)) + +typedef struct _MyAtkImage MyAtkImage; +typedef struct _MyAtkImageClass MyAtkImageClass; + +typedef void (* MyAtkImageFunc) (MyAtkImage *image); + +struct _MyAtkImage { + MyAtkObject parent; + gchar *description; + gint x; + gint y; + gint width; + gint height; + gchar *locale; +}; + +struct _MyAtkImageClass { + MyAtkObjectClass parent; +}; + +GType my_atk_image_get_type (void); + +guint my_atk_set_image (AtkImage *image, + const gchar *desc, + const gint x, + const gint y, + const gint width, + const gint height, + const gchar *locale); + +#endif /* MY_ATK_IMAGE_H_ */ diff --git a/tests/dummyatk/my-atk-object.h b/tests/dummyatk/my-atk-object.h index d4a1eec..54f65ac 100644 --- a/tests/dummyatk/my-atk-object.h +++ b/tests/dummyatk/my-atk-object.h @@ -42,6 +42,7 @@ struct _MyAtkObject { AtkRelationSet *relation_set; GPtrArray* children; gint id; + gboolean selected; }; struct _MyAtkObjectClass { diff --git a/tests/dummyatk/my-atk-text.c b/tests/dummyatk/my-atk-text.c new file mode 100644 index 0000000..54d7a2f --- /dev/null +++ b/tests/dummyatk/my-atk-text.c @@ -0,0 +1,441 @@ +/* + * AT-SPI - Assistive Technology Service Provider Interface + * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility) + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include + +#include "my-atk-object.h" +#include "my-atk-text.h" + +typedef struct _MyAtkTextInfo MyAtkTextInfo; + +static void atk_text_interface_init (AtkTextIface *iface); + +typedef struct _MyAtkTextSelection MyAtkTextSelection; + +struct _MyAtkTextSelection { + gint start; + gint end; +}; + +G_DEFINE_TYPE_WITH_CODE (MyAtkText, + my_atk_text, + MY_TYPE_ATK_OBJECT, + G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT, + atk_text_interface_init)); + +guint +my_atk_set_text (AtkText *obj, + const gchar *text, + const gint x, + const gint y, + const gint width, + const gint height, + AtkAttributeSet *attrSet) +{ + g_return_val_if_fail (MY_IS_ATK_TEXT (obj), -1); + + MyAtkText *self = MY_ATK_TEXT (obj); + self->text = g_strdup (text); + self->x = x; + self->y = y; + self->width = width; + self->height = height; + self->attributes = g_slist_copy (attrSet); + + return 0; +} + +MyAtkText * +my_atk_text_new (void) +{ + return g_object_new (MY_TYPE_ATK_TEXT, NULL); +} + +static gchar * +my_atk_text_get_text (AtkText *obj, gint start_offset, gint end_offset) +{ + g_return_val_if_fail (MY_IS_ATK_TEXT (obj), NULL); + gchar *str = MY_ATK_TEXT (obj)->text; + + if ((end_offset < start_offset) || start_offset < 0 || !str) + return NULL; + if (strlen (str) < end_offset) + return NULL; + + return g_strndup (str + start_offset, end_offset - start_offset); +} + +static gint +my_atk_text_get_character_count (AtkText *obj) +{ + g_return_val_if_fail (MY_IS_ATK_TEXT (obj), -1); + gchar *str = MY_ATK_TEXT (obj)->text; + if (!str) return 0; + return (gint) strlen (str); +} + +static int +my_atk_text_get_caret_offset (AtkText *obj) +{ + g_return_val_if_fail (MY_IS_ATK_TEXT (obj), -1); + return MY_ATK_TEXT (obj)->caret_offset; +} + +static gboolean +my_atk_text_set_caret_offset (AtkText *obj, gint offset) +{ + g_return_val_if_fail (MY_IS_ATK_TEXT (obj), FALSE); + MyAtkText *self = MY_ATK_TEXT (obj); + if (offset < 0 && strlen (self->text) <= offset) + return FALSE; + self->caret_offset = offset; + return TRUE; +} + +static gunichar +my_atk_text_get_character_at_offset (AtkText *obj, gint offset) +{ + g_return_val_if_fail (MY_IS_ATK_TEXT (obj), 255); + return MY_ATK_TEXT (obj)->text[offset]; +} + +static void +my_atk_text_get_character_extents (AtkText *obj, gint offset, gint *x, gint *y, gint *width, gint *height, AtkCoordType coords) +{ + g_return_if_fail (MY_IS_ATK_TEXT (obj)); + MyAtkText *self = MY_ATK_TEXT (obj); + *x = self->x; + *y = self->y; + *width = self->width; + *height = self->height; +} + +static void +my_atk_text_get_range_extents (AtkText *obj, gint start_offset, gint stop_offset, AtkCoordType coords, AtkTextRectangle *rect) +{ + g_return_if_fail (MY_IS_ATK_TEXT (obj)); + MyAtkText *self = MY_ATK_TEXT (obj); + rect->x = self->x; + rect->y = self->y; + rect->width = self->width; + rect->height = self->height; +} + +static gint +my_atk_text_get_n_selections (AtkText *obj) +{ + g_return_val_if_fail (MY_IS_ATK_TEXT (obj), -1); + return g_list_length (MY_ATK_TEXT (obj)->selection); +} + +static gboolean +my_atk_text_add_selection (AtkText *obj, gint start_offset, gint end_offset) +{ + MyAtkText *self = MY_ATK_TEXT (obj); + g_return_val_if_fail (MY_IS_ATK_TEXT (obj), FALSE); + + MyAtkTextSelection *node = g_malloc (sizeof (MyAtkTextSelection)); + + node->start = start_offset; + node->end = end_offset; + + self->selection = g_list_append (self->selection, node); + + return TRUE; +} + +static gchar * +my_atk_text_get_selection (AtkText *obj, gint selection_num, gint *start_offset, gint *end_offset) +{ + MyAtkText *self = MY_ATK_TEXT (obj); + gchar *str = NULL; + GList *it; + g_return_val_if_fail (MY_IS_ATK_TEXT (obj), NULL); + + if (selection_num < 0) + return NULL; + + it = g_list_nth (self->selection, selection_num); + if (!it) + return NULL; + + str = my_atk_text_get_text (obj, ((MyAtkTextSelection *)it->data)->start, ((MyAtkTextSelection *)it->data)->end); + if (!str) + return NULL; + *start_offset = ((MyAtkTextSelection *)it->data)->start; + *end_offset = ((MyAtkTextSelection *)it->data)->end; + + return str; +} + +static gboolean +my_atk_text_set_selection (AtkText *obj, gint selection_num, gint start_offset, gint end_offset) +{ + MyAtkText *self = MY_ATK_TEXT (obj); + g_return_val_if_fail (MY_IS_ATK_TEXT (obj), FALSE); + + GList *it; + + if (selection_num < 0) + return FALSE; + + it = g_list_nth (self->selection, selection_num); + if (!it) + return FALSE; + + ((MyAtkTextSelection *)it->data)->start = start_offset; + ((MyAtkTextSelection *)it->data)->end = end_offset; + + return TRUE; +} + +static gboolean +my_atk_text_remove_selection (AtkText *obj, gint selection_num) +{ + MyAtkText *self = MY_ATK_TEXT (obj); + GList *it; + g_return_val_if_fail (MY_IS_ATK_TEXT (obj), FALSE); + + if (selection_num < 0) + return FALSE; + + it = g_list_nth (self->selection, selection_num); + if (!it) + return FALSE; + + self->selection = g_list_delete_link (self->selection, it); + return TRUE; +} + +static gint +my_atk_text_get_offset_at_point (AtkText *obj, gint x, gint y, AtkCoordType coords) +{ + g_return_val_if_fail (MY_IS_ATK_TEXT (obj), -1); + return 5; +} + +static AtkAttributeSet * +my_atk_text_get_default_attributes (AtkText *obj) +{ + g_return_val_if_fail (MY_IS_ATK_TEXT (obj), NULL); + return MY_ATK_TEXT (obj)->attributes; +} + +static AtkAttributeSet * +my_atk_text_get_run_attributes (AtkText *obj, gint offset, gint *start_offset, gint *end_offset) +{ + g_return_val_if_fail (MY_IS_ATK_TEXT (obj), NULL); + AtkAttributeSet *attributes; + AtkAttribute *attr; + + attr = g_malloc (sizeof (AtkAttribute)); + attr->name = g_strdup ("text_test_attr1"); + attr->value = g_strdup ("on"); + attributes = g_slist_append (NULL, attr); + + attr = g_malloc (sizeof (AtkAttribute)); + attr->name = g_strdup ("text_test_attr2"); + attr->value = g_strdup ("off"); + attributes = g_slist_append (attributes, attr); + + *start_offset = 5; + *end_offset = 10; + + return attributes; +} + +static void setSentenceStartEnd (MyAtkText *self,gint *_offset, gint *start_offset, gint*end_offset, const gchar *fstr) +{ + gchar *p_str_begin = NULL; + gchar *p_str_end = NULL; + const gint length = strlen (self->text); + gint offset = *_offset; + gint star_correction = 1; + /* + * In case if offset is in the middle of the word rewind to 1 character before. + */ + for (; g_ascii_isalpha (self->text[offset]) && 0 < offset; offset--); + /* + * if [char] rewind to word after by passing none alpha + * else try to find last [string] in range [0,offset] + * if found then correct position + * else not found so this is first sentence find first word + */ + if (self->text[offset] == fstr[0]) { + for (; !g_ascii_isalpha (self->text[offset]) && offset < length; offset++); + p_str_begin = self->text + offset; + } else { + p_str_begin = g_strrstr_len (self->text, offset, fstr); + if (p_str_begin) { + for (; !g_ascii_isalpha (self->text[offset]) && length < offset; offset++); + } else { + for (offset = 0; !g_ascii_isalpha (self->text[offset]) && length < offset; offset++); + star_correction = 0; + } + p_str_begin = self->text + offset; + } + /* + * try find ending + * if not found set ending at text end. + * */ + p_str_end = g_strstr_len (self->text + offset, length - offset, fstr); + if (!p_str_end) { + p_str_end = self->text + (length -1); + } + if (p_str_begin && p_str_end) { + *start_offset = p_str_begin - self->text + star_correction; + *end_offset = p_str_end - self->text + 1; + *_offset = offset; + } +} + +static gchar * +my_atk_text_get_string_at_offset (AtkText *obj, gint offset, AtkTextGranularity granularity, gint *start_offset, gint *end_offset) +{ + g_return_val_if_fail (MY_IS_ATK_TEXT (obj), NULL); + MyAtkText *self = MY_ATK_TEXT (obj); + gint cnt; + gint length; + gint myoffset = 0; + *start_offset = -1; + *end_offset = -1; + + switch (granularity) { + case ATK_TEXT_GRANULARITY_CHAR: + *start_offset = offset; + *end_offset = *start_offset + 1; + break; + case ATK_TEXT_GRANULARITY_WORD: + length = strlen (self->text); + for (; !g_ascii_isalpha (self->text[offset]) && offset < length ; offset++); + for (cnt = offset; cnt < length; cnt++) { + if (!g_ascii_isalpha (self->text[cnt])) { + *start_offset = offset; + *end_offset = cnt - 1; + myoffset = 1; + break; + } + } + for (cnt = offset; 0 < cnt; cnt--) { + if (!g_ascii_isalpha (self->text[cnt])) { + *start_offset = cnt + 1; + break; + } + } + break; + case ATK_TEXT_GRANULARITY_SENTENCE: + setSentenceStartEnd (self, &offset, start_offset, end_offset, "."); + break; + case ATK_TEXT_GRANULARITY_LINE: + setSentenceStartEnd (self, &offset, start_offset, end_offset, "/n"); + break; + case ATK_TEXT_GRANULARITY_PARAGRAPH: + /* Not implemented */ + *start_offset = 0; + *end_offset = 0; + break; + default: + break; + } + return my_atk_text_get_text (obj, *start_offset, *end_offset + myoffset); +} + +AtkTextRange ** +my_atk_get_bounded_ranges (AtkText *obj, AtkTextRectangle *rect, AtkCoordType ctype, AtkTextClipType xclip, AtkTextClipType yclip) +{ + g_return_val_if_fail (MY_IS_ATK_TEXT (obj), NULL); + AtkTextRange **range = g_new (AtkTextRange *, 3); + + *range = g_new (AtkTextRange, 1); + (*range)->start_offset = 0; + (*range)->end_offset = 5; + (*range)->content = my_atk_text_get_text (obj, (*range)->start_offset, (*range)->end_offset); + + *(range+1) = g_new (AtkTextRange, 1); + (*(range+1))->start_offset = 6; + (*(range+1))->end_offset = 10; + (*(range+1))->content = my_atk_text_get_text (obj, (*(range+1))->start_offset, (*(range+1))->end_offset); + + *(range+2) = NULL; + + return range; +} + +static void +atk_text_interface_init (AtkTextIface *iface) +{ + if (!iface) return; + + iface->get_text = my_atk_text_get_text; + iface->get_character_count = my_atk_text_get_character_count; + iface->get_caret_offset = my_atk_text_get_caret_offset; + iface->set_caret_offset = my_atk_text_set_caret_offset; + iface->get_character_at_offset = my_atk_text_get_character_at_offset; + iface->get_character_extents = my_atk_text_get_character_extents; + iface->get_range_extents = my_atk_text_get_range_extents; + iface->get_n_selections = my_atk_text_get_n_selections; + iface->add_selection = my_atk_text_add_selection; + iface->get_selection = my_atk_text_get_selection; + iface->set_selection = my_atk_text_set_selection; + iface->remove_selection = my_atk_text_remove_selection; + iface->get_offset_at_point = my_atk_text_get_offset_at_point; + iface->get_default_attributes = my_atk_text_get_default_attributes; + iface->get_string_at_offset = my_atk_text_get_string_at_offset; + iface->get_bounded_ranges = my_atk_get_bounded_ranges; + iface->get_run_attributes = my_atk_text_get_run_attributes; +} + +static void +my_atk_text_init (MyAtkText *self) +{ + self->text = NULL; + self->caret_offset = -1; + self->x =-1; + self->y = -1; + self->width = -1; + self->height = -1; + self->selection = NULL; + self->attributes = NULL; +} + +static void +my_atk_text_class_initialize (AtkObject *obj, gpointer data) +{ +} + +static void +my_atk_text_class_finalize (GObject *obj) +{ +} + +static void +my_atk_text_class_init (MyAtkTextClass *my_class) +{ + AtkObjectClass *atk_class = ATK_OBJECT_CLASS (my_class); + GObjectClass *gobject_class = G_OBJECT_CLASS (my_class); + + gobject_class->finalize = my_atk_text_class_finalize; + atk_class->initialize = my_atk_text_class_initialize; +} diff --git a/tests/dummyatk/my-atk-text.h b/tests/dummyatk/my-atk-text.h new file mode 100644 index 0000000..cb221a1 --- /dev/null +++ b/tests/dummyatk/my-atk-text.h @@ -0,0 +1,71 @@ +/* + * AT-SPI - Assistive Technology Service Provider Interface + * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility) + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef MY_ATK_TEXT_H_ +#define MY_ATK_TEXT_H_ + +#include +#include +#include + +#include "my-atk-object.h" +#define MY_TYPE_ATK_TEXT (my_atk_text_get_type ()) +#define MY_ATK_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MY_TYPE_ATK_TEXT, MyAtkText)) +#define MY_ATK_TEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), MY_TYPE_ATK_TEXT, MyAtkTextClass)) +#define MY_IS_ATK_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MY_TYPE_ATK_TEXT)) +#define MY_IS_ATK_TEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), MY_TYPE_ATK_TEXT)) +#define MY_ATK_TEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), MY_TYPE_ATK_TEXT, MyAtkTextClass)) + +typedef struct _MyAtkText MyAtkText; +typedef struct _MyAtkTextClass MyAtkTextClass; + +typedef void (* MyAtkTextFunc) (MyAtkText *obj); + +struct _MyAtkText { + MyAtkObject parent; + gchar *text; + gint caret_offset; + gint x; + gint y; + gint width; + gint height; + GList *selection; + AtkAttributeSet *attributes; +}; + +struct _MyAtkTextClass { + MyAtkObjectClass parent; +}; + +GType my_atk_text_get_type (void); + +guint my_atk_set_text (AtkText *obj, + const gchar *text, + const gint x, + const gint y, + const gint width, + const gint height, + AtkAttributeSet *attrSet); + +MyAtkText *my_atk_text_new (void); + +#endif /* MY_ATK_TEXT_H_ */ diff --git a/tests/dummyatk/my-atk-value.c b/tests/dummyatk/my-atk-value.c new file mode 100644 index 0000000..5fce30a --- /dev/null +++ b/tests/dummyatk/my-atk-value.c @@ -0,0 +1,138 @@ +/* + * Copyright 2008 Codethink Ltd. + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include + +#include "my-atk-object.h" +#include "my-atk-value.h" + +typedef struct _MyAtkValueInfo MyAtkValueInfo; + +static void atk_value_interface_init (AtkValueIface *iface); + +G_DEFINE_TYPE_WITH_CODE (MyAtkValue, + my_atk_value, + MY_TYPE_ATK_OBJECT, + G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, + atk_value_interface_init)); + +guint +my_atk_set_value (AtkValue *obj, gdouble min, gdouble cur, gdouble max, gdouble step) +{ + MyAtkValue *self = MY_ATK_VALUE (obj); + g_return_val_if_fail (MY_IS_ATK_VALUE (obj), -1); + + self->min = min; + self->cur = cur; + self->max = max; + self->step = step; + + return 0; +} + +static void +my_atk_value_get_value_and_text (AtkValue *obj, gdouble *value, gchar **text) +{ + MyAtkValue *self = MY_ATK_VALUE (obj); + g_return_if_fail (MY_IS_ATK_VALUE (obj)); + + *value = self->cur; + *text = g_strdup_printf ("%f", self->cur); +} + +static AtkRange* +my_atk_value_get_range (AtkValue *obj) +{ + MyAtkValue *self = MY_ATK_VALUE (obj); + g_return_val_if_fail (MY_IS_ATK_VALUE (obj), NULL); + + return atk_range_new (self->min, self->max, NULL); +} + +static gdouble +my_atk_value_get_increment (AtkValue *obj) +{ + MyAtkValue *self = MY_ATK_VALUE (obj); + g_return_val_if_fail (MY_IS_ATK_VALUE (obj), 0); + return self->step; +} + +static GSList* +my_atk_value_get_sub_ranges (AtkValue *obj) +{ + g_return_val_if_fail (MY_IS_ATK_VALUE (obj), NULL); + + return NULL; +} + +static void +my_atk_value_set_value (AtkValue *obj, const gdouble val) +{ + MyAtkValue *self = MY_ATK_VALUE (obj); + g_return_if_fail (MY_IS_ATK_VALUE (obj)); + + if ( self->min < val && val < self->max ) + self->cur = val; + return; +} + +static void +atk_value_interface_init (AtkValueIface *iface) +{ + if (!iface) return; + iface->get_value_and_text = my_atk_value_get_value_and_text; + iface->get_range = my_atk_value_get_range; + iface->get_increment = my_atk_value_get_increment; + iface->get_sub_ranges = my_atk_value_get_sub_ranges; + iface->set_value = my_atk_value_set_value; +} + +static void +my_atk_value_init (MyAtkValue *self) +{ + self->min = 0; + self->cur = 0; + self->max = 0; + self->step = 0; +} + +static void +my_atk_value_class_initialize (AtkObject *obj, gpointer data) +{ +} + +static void +my_atk_value_class_finalize (GObject *obj) +{ +} + +static void +my_atk_value_class_init(MyAtkValueClass *my_class) +{ + AtkObjectClass *atk_class = ATK_OBJECT_CLASS(my_class); + GObjectClass *gobject_class = G_OBJECT_CLASS(my_class); + + gobject_class->finalize = my_atk_value_class_finalize; + + atk_class->initialize = my_atk_value_class_initialize; +} diff --git a/tests/dummyatk/my-atk-value.h b/tests/dummyatk/my-atk-value.h new file mode 100644 index 0000000..eb69b90 --- /dev/null +++ b/tests/dummyatk/my-atk-value.h @@ -0,0 +1,55 @@ +/* + * Copyright 2008 Codethink Ltd. + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef MY_ATK_VALUE_H_ +#define MY_ATK_VALUE_H_ + +#include +#include +#include + +#include "my-atk-object.h" +#define MY_TYPE_ATK_VALUE (my_atk_value_get_type ()) +#define MY_ATK_VALUE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MY_TYPE_ATK_VALUE, MyAtkValue)) +#define MY_ATK_VALUE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), MY_TYPE_ATK_VALUE, MyAtkValueClass)) +#define MY_IS_ATK_VALUE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MY_TYPE_ATK_VALUE)) +#define MY_IS_ATK_VALUE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), MY_TYPE_ATK_VALUE)) +#define MY_ATK_VALUE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), MY_TYPE_ATK_VALUE, MyAtkValueClass)) + +typedef struct _MyAtkValue MyAtkValue; +typedef struct _MyAtkValueClass MyAtkValueClass; + +struct _MyAtkValue { + MyAtkObject parent; + gdouble min; + gdouble cur; + gdouble max; + gdouble step; +}; + +struct _MyAtkValueClass { + MyAtkObjectClass parent; +}; + +GType my_atk_value_get_type (void); + +guint my_atk_set_value (AtkValue *obj, gdouble min, gdouble cur, gdouble max, gdouble step); + +#endif /* MY_ATK_VALUE_H_ */ diff --git a/tests/dummyatk/my-atk.h b/tests/dummyatk/my-atk.h index 91fe29d..eab8b8f 100644 --- a/tests/dummyatk/my-atk.h +++ b/tests/dummyatk/my-atk.h @@ -26,5 +26,9 @@ #include "my-atk-action.h" #include "my-atk-object.h" #include "my-atk-component.h" +#include "my-atk-editable-text.h" +#include "my-atk-image.h" +#include "my-atk-text.h" +#include "my-atk-value.h" #endif /*MY_ATK_H*/ -- cgit v1.2.1