X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=test%2Ftest-simple.c;h=814d0514646284d9db21be86d5c8fa7f0defae76;hb=f30bb8aabc762c6ea46942a8155db2dde061e8fc;hp=b64ee9602f13da373c821b8072a623ef87b9cf9b;hpb=05d0a8cfed1bd502794ba482cf4d4e7e1a0ff37a;p=platform%2Fupstream%2Fat-spi2-core.git diff --git a/test/test-simple.c b/test/test-simple.c index b64ee96..814d051 100644 --- a/test/test-simple.c +++ b/test/test-simple.c @@ -31,6 +31,11 @@ #include #include + +/* Known bugs */ +#undef KEY_IMPL_WORKS +#define WHOLE_STRING -1 + static void validate_accessible (Accessible *accessible, gboolean has_parent, gboolean recurse_down); @@ -122,7 +127,7 @@ create_test_window (void) widget = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_LARGE_TOOLBAR); test_window_add_and_show (GTK_CONTAINER (vbox), widget); - + widget = g_object_new (GTK_TYPE_RANGE, NULL); gtk_range_set_range (GTK_RANGE (widget), 0.0, 100.0); test_window_add_and_show (GTK_CONTAINER (vbox), widget); @@ -158,17 +163,45 @@ test_roles (void) } static void +test_action (AccessibleAction *action) +{ + gint n_actions, i; + gchar *s, *sd; + g_assert ((n_actions = AccessibleAction_getNActions (action)) >= 0); + + fprintf (stderr, "Testing actions..."); + for (i = 0; i < n_actions; ++i) + { + s = AccessibleAction_getName (action, i); + g_assert (s); + sd = AccessibleAction_getDescription (action, i); + g_assert (sd); + fprintf (stderr, "%d: %s (%s); ", i, s, sd); + SPI_freeString (s); + SPI_freeString (sd); + g_assert (AccessibleAction_doAction (action, i)); + } + fprintf (stderr, "\n"); +} + +static void test_desktop (void) { - Accessible *desktop; - Accessible *application; + Accessible *desktop; + Accessible *application; + int length; + Accessible **list; fprintf (stderr, "Testing desktop...\n"); - g_assert (getDesktop (-1) == NULL); - desktop = getDesktop (0); + g_assert (SPI_getDesktop (-1) == NULL); + desktop = SPI_getDesktop (0); g_assert (desktop != NULL); + g_assert ((length = SPI_getDesktopList (&list)) > 0); + g_assert (list[0] == desktop); + SPI_freeDesktopList (list); + validate_accessible (desktop, FALSE, FALSE); application = Accessible_getChildAtIndex (desktop, 0); @@ -215,7 +248,7 @@ test_editable_text (AccessibleEditableText *etext) AccessibleEditableText_setTextContents ( etext, TEST_STRING_B); - str = AccessibleText_getText (text, 0, -1); + str = AccessibleText_getText (text, 0, WHOLE_STRING); g_assert (!strcmp (str, TEST_STRING_B)); SPI_freeString (str); @@ -267,7 +300,7 @@ test_text (AccessibleText *text) g_assert (AccessibleText_getCharacterCount (text) == strlen (TEST_STRING_A)); - str = AccessibleText_getText (text, 0, -1); + str = AccessibleText_getText (text, 0, WHOLE_STRING); g_assert (!strcmp (str, TEST_STRING_A)); SPI_freeString (str); @@ -286,8 +319,6 @@ test_value (AccessibleValue *value) { float original_value; - /* Note: test_value assertions are known not to work as of Dec 09 */ - fprintf (stderr, "Testing value ...\n"); original_value = AccessibleValue_getCurrentValue (value); @@ -433,10 +464,13 @@ validate_accessible (Accessible *accessible, gboolean has_parent, gboolean recurse_down) { - Accessible *tmp; - char *name, *descr; - const char *role; - GString *item_str = g_string_new (""); + Accessible *tmp; + char *name, *descr; + AccessibleRole role; + AccessibleRelation **relations; + char *role_name; + GString *item_str = g_string_new (""); + int i; name = Accessible_getName (accessible); g_assert (name != NULL); @@ -445,7 +479,29 @@ validate_accessible (Accessible *accessible, g_assert (descr != NULL); role = Accessible_getRole (accessible); - g_assert (role != NULL); + g_assert (role != SPI_ROLE_INVALID); + role_name = Accessible_getRoleName (accessible); + g_assert (role_name != NULL); + + relations = Accessible_getRelationSet (accessible); + g_assert (relations != NULL); + + for (i = 0; relations [i]; i++) { + AccessibleRelationType type; + int targets; + + fprintf (stderr, "relation %d\n", i); + + type = AccessibleRelation_getRelationType (relations [i]); + g_assert (type != SPI_RELATION_NULL); + + targets = AccessibleRelation_getNTargets (relations [i]); + g_assert (targets != -1); + + AccessibleRelation_unref (relations [i]); + relations [i] = NULL; + } + free (relations); if (print_tree) { int i; @@ -460,6 +516,8 @@ validate_accessible (Accessible *accessible, g_assert (tmp != NULL); if (print_tree) fprintf (stderr, "At"); + else + test_action (tmp); AccessibleAction_unref (tmp); } @@ -558,10 +616,11 @@ validate_accessible (Accessible *accessible, if (print_tree) fprintf (stderr, " ] '%s' (%s) - %s: %s\n", - name, descr, role, item_str->str); + name, descr, role_name, item_str->str); SPI_freeString (name); SPI_freeString (descr); + SPI_freeString (role_name); g_string_free (item_str, TRUE); validate_tree (accessible, has_parent, recurse_down); @@ -578,8 +637,8 @@ test_misc (void) } static void -global_listener_cb (AccessibleEvent *event, - void *user_data) +global_listener_cb (const AccessibleEvent *event, + void *user_data) { TestWindow *win = user_data; Accessible *desktop; @@ -591,7 +650,7 @@ global_listener_cb (AccessibleEvent *event, fprintf (stderr, "Fielded focus event ...\n"); if (!do_poke) { - desktop = getDesktop (0); + desktop = SPI_getDesktop (0); application = Accessible_getChildAtIndex (desktop, 0); g_assert (application != NULL); Accessible_unref (desktop); @@ -610,6 +669,71 @@ global_listener_cb (AccessibleEvent *event, validate_accessible (event->source, TRUE, TRUE); } +#ifdef KEY_IMPL_WORKS +static SPIBoolean +key_listener_cb (const AccessibleKeystroke *stroke, + void *user_data) +{ + AccessibleKeystroke *s = user_data; + + *s = *stroke; + + return TRUE; +} +#endif + +static void +test_keylisteners (void) +{ +#ifdef KEY_IMPL_WORKS + int i; + AccessibleKeystroke stroke; + AccessibleKeystrokeListener *key_listener; + AccessibleKeySet *test_keyset; +#endif + + fprintf (stderr, "Testing keyboard listeners ...\n"); + +#ifdef KEY_IMPL_WORKS + key_listener = SPI_createAccessibleKeystrokeListener ( + key_listener_cb, &stroke); + + test_keyset = SPI_createAccessibleKeySet (1, "=", NULL, NULL); + + g_assert (SPI_registerAccessibleKeystrokeListener ( + key_listener, + test_keyset, + 0, + SPI_KEY_PRESSED | SPI_KEY_RELEASED, + SPI_KEYLISTENER_CANCONSUME | SPI_KEYLISTENER_ALL_WINDOWS)); + + for (i = 0; i < 3; i++) { + memset (&stroke, 0, sizeof (AccessibleKeystroke)); + g_assert (SPI_generateKeyboardEvent ('=', NULL, SPI_KEY_SYM)); + while (!(stroke.type & SPI_KEY_PRESSED)) + g_main_context_iteration (NULL, TRUE); + fprintf (stderr, "p"); + g_assert (!strcmp (stroke.keystring, "=")); + while (!(stroke.type & SPI_KEY_RELEASED)) + g_main_context_iteration (NULL, TRUE); + fprintf (stderr, "r "); + } + g_assert (SPI_deregisterAccessibleKeystrokeListener (key_listener, 0)); + SPI_freeAccessibleKeySet (test_keyset); + + fprintf (stderr, "\n"); + + AccessibleKeystrokeListener_unref (key_listener); +#else + fprintf (stderr, " key impl. impossibly broken\n"); +#endif + + g_assert (SPI_generateMouseEvent (100, 100, "rel")); + g_assert (SPI_generateMouseEvent (-50, -50, "rel")); + g_assert (SPI_generateMouseEvent (-50, -50, "rel")); + g_assert (SPI_generateMouseEvent (-1, -1, "b1c")); +} + int main (int argc, char **argv) { @@ -620,7 +744,7 @@ main (int argc, char **argv) modules = g_getenv ("GTK_MODULES"); if (!modules || modules [0] == '\0') - putenv ("GTK_MODULES=gail:at-bridge"); + putenv ("GTK_MODULES=gail:atk-bridge"); modules = NULL; for (i = 1; i < argc; i++) { @@ -632,25 +756,31 @@ main (int argc, char **argv) g_assert (!SPI_init ()); g_assert (SPI_init ()); - g_assert (getDesktopCount () == 1); + g_assert (SPI_getDesktopCount () == 1); test_roles (); test_misc (); test_desktop (); + test_keylisteners (); win = create_test_window (); - global_listener = createAccessibleEventListener (global_listener_cb, win); - g_assert (registerGlobalEventListener (global_listener, "focus:")); + global_listener = SPI_createAccessibleEventListener (global_listener_cb, win); + g_assert (SPI_registerGlobalEventListener (global_listener, "focus:")); fprintf (stderr, "Waiting for focus event ...\n"); gtk_main (); - g_assert (deregisterGlobalEventListenerAll (global_listener)); + g_assert (SPI_deregisterGlobalEventListenerAll (global_listener)); AccessibleEventListener_unref (global_listener); test_window_destroy (win); + /* Wait for any pending events from the registry */ + g_usleep (500*1000); + for (i = 0; i < 100; i++) + linc_main_iteration (FALSE); + if ((leaked = SPI_exit ())) g_error ("Leaked %d SPI handles", leaked);