2001-12-10 Michael Meeks <michael@ximian.com>
[platform/core/uifw/at-spi2-atk.git] / test / test-simple.c
index 24957af..bd55cde 100644 (file)
  * ******** 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>
@@ -65,7 +63,6 @@ focus_me (GtkWidget *widget)
        
        g_object_unref (G_OBJECT (aobject));
 
-       /* Pull focus away and then back - thus sucks */
        return FALSE;
 }
 
@@ -132,6 +129,7 @@ test_desktop (void)
 
        application = Accessible_getChildAtIndex (desktop, 0);
        g_assert (application != NULL);
+       AccessibleApplication_unref (application);
 
        Accessible_unref (desktop);
 }
@@ -211,6 +209,41 @@ test_text (AccessibleText *text)
 }
 
 static void
+test_value (AccessibleValue *value)
+{
+       char *str;
+       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;
@@ -274,7 +307,7 @@ validate_tree (Accessible *accessible,
                g_assert (parent != NULL);
 
                index = Accessible_getIndexInParent (accessible);
-               g_assert (index >= 0);
+               g_assert (index >= 0); 
 
                child_at_index = Accessible_getChildAtIndex (parent, index);
 
@@ -411,6 +444,16 @@ validate_accessible (Accessible *accessible,
                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);
 
@@ -430,65 +473,6 @@ test_misc (void)
        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)
@@ -502,8 +486,6 @@ global_listener_cb (AccessibleEvent     *event,
 
        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);
@@ -524,18 +506,20 @@ global_listener_cb (AccessibleEvent     *event,
 int
 main (int argc, char **argv)
 {
+       int leaked;
        TestWindow *win;
+       const char *modules, *tmp;
        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'");
-       }
+       gtk_init (&argc, &argv);
 
-       g_assert (!SPI_init (TRUE));
-       g_assert (SPI_init (TRUE));
+       g_assert (!SPI_init ());
+       g_assert (SPI_init ());
        g_assert (getDesktopCount () == 1);
 
        test_roles ();
@@ -550,18 +534,24 @@ main (int argc, char **argv)
        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;
 }