* ******** Do not copy this code as an example *********
*/
-/* UGLY HACK for (unutterable_horror) */
-#include <libspi/libspi.h>
-
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <cspi/spi.h>
static int print_tree_depth = 0;
static gboolean print_tree = FALSE;
+static gboolean do_poke = FALSE;
typedef struct {
gulong magic;
{
AtkObject *aobject = atk_implementor_ref_accessible (
ATK_IMPLEMENTOR (widget));
-
+
/* Force a focus event - even if the WM focused
* us before our at-bridge's idle handler registered
* our interest */
g_object_unref (G_OBJECT (aobject));
- /* Pull focus away and then back - thus sucks */
return FALSE;
}
+static void
+test_window_add_and_show (GtkContainer *container, GtkWidget *widget)
+{
+ gtk_container_add (container, widget);
+ gtk_widget_show (widget);
+}
+
+static GtkWidget *
+create_tree (void)
+{
+ GtkWidget *widget;
+ GtkTreeIter iter;
+ GtkListStore *store;
+ GtkTreeViewColumn *column;
+
+ store = gtk_list_store_new (1, G_TYPE_STRING);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter, 0, TEST_STRING_A, -1);
+ column = gtk_tree_view_column_new_with_attributes ("String",
+ gtk_cell_renderer_text_new (), "text", 0, NULL);
+ widget = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
+ g_object_unref (G_OBJECT (store));
+ gtk_tree_view_append_column (GTK_TREE_VIEW (widget), column);
+
+ return widget;
+}
+
static TestWindow *
create_test_window (void)
{
widget = gtk_entry_new ();
gtk_entry_set_text (GTK_ENTRY (widget), TEST_STRING_A);
- gtk_container_add (GTK_CONTAINER (vbox), widget);
- gtk_widget_show (widget);
+ test_window_add_and_show (GTK_CONTAINER (vbox), widget);
+
+ widget = gtk_button_new_with_label ("_Foobar");
+ test_window_add_and_show (GTK_CONTAINER (vbox), widget);
+
+ widget = gtk_hseparator_new ();
+ test_window_add_and_show (GTK_CONTAINER (vbox), widget);
+
+ 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);
+
+ widget = create_tree ();
+ test_window_add_and_show (GTK_CONTAINER (vbox), widget);
g_idle_add ((GSourceFunc) focus_me, win->window);
}
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;
application = Accessible_getChildAtIndex (desktop, 0);
g_assert (application != NULL);
+ AccessibleApplication_unref (application);
Accessible_unref (desktop);
}
}
static void
+test_table (AccessibleTable *table)
+{
+ Accessible *header;
+ gint index;
+ gint rows, columns;
+
+ fprintf (stderr, "Testing table ...\n");
+
+ rows = AccessibleTable_getNRows (table);
+ g_assert (rows > 0);
+
+ columns = AccessibleTable_getNColumns (table);
+ g_assert (columns > 0);
+
+ index = AccessibleTable_getIndexAt (table, rows - 1, columns - 1);
+
+ g_assert (AccessibleTable_getRowAtIndex (table, index) == rows - 1);
+
+ g_assert (AccessibleTable_getColumnAtIndex (table, index) == columns - 1);
+
+ g_assert ((header = AccessibleTable_getColumnHeader (table, 0)));
+ Accessible_unref (header);
+
+ AccessibleTable_isSelected (table, 0, 0);
+
+ /* FIXME: lots more tests */
+}
+
+static void
test_text (AccessibleText *text)
{
char *str;
}
static void
+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);
+
+ g_assert (AccessibleValue_getCurrentValue (value) <=
+ AccessibleValue_getMaximumValue (value));
+
+ g_assert (AccessibleValue_getCurrentValue (value) >=
+ AccessibleValue_getMinimumValue (value));
+
+ AccessibleValue_setCurrentValue (value,
+ AccessibleValue_getMinimumValue (value));
+
+ g_assert (AccessibleValue_getCurrentValue (value) ==
+ AccessibleValue_getMinimumValue (value));
+
+ AccessibleValue_setCurrentValue (value,
+ AccessibleValue_getMaximumValue (value));
+
+ g_assert (AccessibleValue_getCurrentValue (value) ==
+ AccessibleValue_getMaximumValue (value));
+
+ AccessibleValue_setCurrentValue (value, original_value);
+
+ g_assert (AccessibleValue_getCurrentValue (value) == original_value);
+}
+
+static void
test_component (AccessibleComponent *component)
{
long x, y, width, height;
}
static void
+test_image (AccessibleImage *image)
+{
+ char *desc;
+ long int x = -1, y = -1, width = -1, height = -1;
+
+ desc = AccessibleImage_getImageDescription (image);
+ g_assert (desc != NULL);
+ SPI_freeString (desc);
+
+ AccessibleImage_getImagePosition (image, &x, &y,
+ SPI_COORD_TYPE_SCREEN);
+ AccessibleImage_getImageSize (image, &width, &height);
+ AccessibleImage_getImageExtents (image, &x, &y, &width, &height,
+ SPI_COORD_TYPE_WINDOW);
+}
+
+static void
validate_tree (Accessible *accessible,
gboolean has_parent,
gboolean recurse_down)
g_assert (parent != NULL);
index = Accessible_getIndexInParent (accessible);
- g_assert (index >= 0);
+ g_assert (index >= 0);
child_at_index = Accessible_getChildAtIndex (parent, index);
gboolean has_parent,
gboolean recurse_down)
{
- Accessible *tmp;
- char *name, *descr;
- const char *role;
+ Accessible *tmp;
+ char *name, *descr;
+ AccessibleRole role;
+ char *role_name;
+ GString *item_str = g_string_new ("");
name = Accessible_getName (accessible);
g_assert (name != NULL);
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);
+
if (print_tree) {
int i;
g_assert (tmp != NULL);
if (print_tree)
fprintf (stderr, "At");
+ else
+ test_action (tmp);
AccessibleAction_unref (tmp);
}
if (Accessible_isImage (accessible)) {
tmp = Accessible_getImage (accessible);
g_assert (tmp != NULL);
- if (print_tree)
+ if (print_tree) {
+ char *desc;
+
fprintf (stderr, "Im");
- AccessibleImage_unref (accessible);
+
+ desc = AccessibleImage_getImageDescription (tmp);
+ g_string_append_printf (
+ item_str, " image descr: '%s'", desc);
+ SPI_freeString (desc);
+ } else
+ test_image (tmp);
+
+ AccessibleImage_unref (tmp);
}
if (Accessible_isSelection (accessible)) {
g_assert (tmp != NULL);
if (print_tree)
fprintf (stderr, "Ta");
+ else
+ test_table (tmp);
AccessibleTable_unref (tmp);
}
AccessibleText_unref (tmp);
}
+ if (Accessible_isValue (accessible)) {
+ tmp = Accessible_getValue (accessible);
+ g_assert (tmp != NULL);
+ if (print_tree)
+ fprintf (stderr, "Va");
+ else
+ test_value (tmp);
+ AccessibleValue_unref (tmp);
+ }
+
if (print_tree)
- fprintf (stderr, " ] '%s' (%s) - %s:\n", name, descr, role);
+ fprintf (stderr, " ] '%s' (%s) - %s: %s\n",
+ 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);
}
SPI_freeString (NULL);
}
-#ifdef UNUTTERABLY_HORRIFIC
-static void
-unutterable_horror (void)
-{
- /* Brutal ugliness to de-register ourself and exit cleanly */
- CORBA_Environment ev;
- Accessible *desktop;
- Accessible *app_access;
- Accessibility_Accessible app;
- Accessibility_Registry registry;
-
- fprintf (stderr, "Unutterable horror ...\n");
-
- /* First get the application ! - gack */
- desktop = getDesktop (0);
- app_access = Accessible_getChildAtIndex (desktop, 0);
-
- /* Good grief */
- app = *(Accessibility_Accessible *) app_access;
-
- CORBA_exception_init (&ev);
-
- registry = bonobo_activation_activate_from_id (
- "OAFIID:Accessibility_Registry:proto0.1", 0, NULL, &ev);
-
- Accessibility_Registry_deregisterApplication (
- registry, app, &ev);
-
- bonobo_object_release_unref (registry, &ev); /* the original ref */
- bonobo_object_release_unref (registry, &ev); /* taken by the bridge */
- bonobo_object_release_unref (registry, &ev); /* taken by spi_main.c */
-
- Accessible_unref (desktop);
- Accessible_unref (app_access);
-
- /* Urgh ! - get a pointer to app */
- bonobo_object_unref (bonobo_object (ORBit_small_get_servant (app)));
-}
-#endif
-
-static void
-utterable_normal_derefs (void)
-{
- /* Normal cleanup to exit cleanly */
- CORBA_Environment ev;
- Accessibility_Registry registry;
-
- CORBA_exception_init (&ev);
-
- registry = bonobo_activation_activate_from_id (
- "OAFIID:Accessibility_Registry:proto0.1", 0, NULL, &ev);
-
- bonobo_object_release_unref (registry, &ev); /* the ref above */
- bonobo_object_release_unref (registry, &ev); /* taken by spi_main.c */
-
- /* Yes, it would be nicer to have both SPI_main_quit and SPI_shutdown,
- then the above code could be dispensed with */
-}
-
static void
global_listener_cb (AccessibleEvent *event,
void *user_data)
fprintf (stderr, "Fielded focus event ...\n");
- /* The application is now registered - this happens idly */
-
- desktop = getDesktop (0);
- application = Accessible_getChildAtIndex (desktop, 0);
- g_assert (application != NULL);
- Accessible_unref (desktop);
-
- test_application (application);
-
- AccessibleApplication_unref (application);
+ if (!do_poke) {
+ desktop = getDesktop (0);
+ application = Accessible_getChildAtIndex (desktop, 0);
+ g_assert (application != NULL);
+ Accessible_unref (desktop);
+
+ test_application (application);
+
+ AccessibleApplication_unref (application);
+
+ print_tree = FALSE;
+ validate_accessible (event->source, TRUE, TRUE);
+
+ gtk_main_quit ();
+ }
print_tree = TRUE;
validate_accessible (event->source, TRUE, TRUE);
- print_tree = FALSE;
- validate_accessible (event->source, TRUE, TRUE);
-
- gtk_main_quit ();
}
int
main (int argc, char **argv)
{
+ int leaked, i;
TestWindow *win;
+ const char *modules;
AccessibleEventListener *global_listener;
- gtk_init (&argc, &argv);
+ modules = g_getenv ("GTK_MODULES");
+ if (!modules || modules [0] == '\0')
+ putenv ("GTK_MODULES=gail:at-bridge");
+ modules = NULL;
- if (!g_getenv ("GTK_MODULES") ||
- !strstr (g_getenv ("GTK_MODULES"), "gail:at-bridge")) {
- g_error ("You need to export GTK_MODULES='gail:at-bridge'");
+ for (i = 1; i < argc; i++) {
+ if (!g_strcasecmp (argv [i], "--poke"))
+ do_poke = TRUE;
}
- g_assert (!SPI_init (TRUE));
- g_assert (SPI_init (TRUE));
+ gtk_init (&argc, &argv);
+
+ g_assert (!SPI_init ());
+ g_assert (SPI_init ());
g_assert (getDesktopCount () == 1);
test_roles ();
fprintf (stderr, "Waiting for focus event ...\n");
gtk_main ();
- /* First de-register myself - we only want the toplevel of ourself */
g_assert (deregisterGlobalEventListenerAll (global_listener));
+ AccessibleEventListener_unref (global_listener);
test_window_destroy (win);
-/* FIXME: we need to resolve the exit / quit mainloop function */
-/* SPI_exit ();
- SPI_exit (); */
-/* unutterable_horror (); ! */
- utterable_normal_derefs ();
+ if ((leaked = SPI_exit ()))
+ g_error ("Leaked %d SPI handles", leaked);
+
+ g_assert (!SPI_exit ());
fprintf (stderr, "All tests passed\n");
- return bonobo_debug_shutdown ();
+ if (g_getenv ("_MEMPROF_SOCKET")) {
+ fprintf (stderr, "Waiting for memprof\n");
+ gtk_main ();
+ }
+
+ putenv ("AT_BRIDGE_SHUTDOWN=1");
+
+ return 0;
}