docs: Fix broken gtk-doc formatting
[platform/upstream/glib.git] / gio / tests / gdbus-connection-slow.c
index 39a9eb8..9c2f59a 100644 (file)
@@ -13,9 +13,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser 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.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  *
  * Author: David Zeuthen <davidz@redhat.com>
  */
@@ -25,7 +23,6 @@
 #include <string.h>
 
 #include <sys/types.h>
-#include <sys/wait.h>
 
 #include "gdbus-tests.h"
 
@@ -62,6 +59,7 @@ test_connection_flush (void)
   GError *error;
   guint n;
   guint signal_handler_id;
+  const gchar *flush_helper;
 
   session_bus_up ();
 
@@ -82,6 +80,7 @@ test_connection_flush (void)
                                                           NULL);
   g_assert_cmpint (signal_handler_id, !=, 0);
 
+  flush_helper = g_test_get_filename (G_TEST_BUILT, "gdbus-connection-flush-helper", NULL);
   for (n = 0; n < 50; n++)
     {
       gboolean ret;
@@ -89,14 +88,14 @@ test_connection_flush (void)
       guint timeout_mainloop_id;
 
       error = NULL;
-      ret = g_spawn_command_line_sync ("./gdbus-connection-flush-helper",
+      ret = g_spawn_command_line_sync (flush_helper,
                                        NULL, /* stdout */
                                        NULL, /* stderr */
                                        &exit_status,
                                        &error);
       g_assert_no_error (error);
-      g_assert (WIFEXITED (exit_status));
-      g_assert_cmpint (WEXITSTATUS (exit_status), ==, 0);
+      g_spawn_check_exit_status (exit_status, &error);
+      g_assert_no_error (error);
       g_assert (ret);
 
       timeout_mainloop_id = g_timeout_add (1000, test_connection_flush_on_timeout, GUINT_TO_POINTER (n));
@@ -105,7 +104,6 @@ test_connection_flush (void)
     }
 
   g_dbus_connection_signal_unsubscribe (connection, signal_handler_id);
-  _g_object_wait_for_single_ref (connection);
   g_object_unref (connection);
 
   session_bus_down ();
@@ -117,6 +115,18 @@ test_connection_flush (void)
  * is fragmented when shoved across any transport
  */
 #define LARGE_MESSAGE_STRING_LENGTH (20*1024*1024)
+/* the test will fail if the service name has not appeared after this amount of seconds */
+#define LARGE_MESSAGE_TIMEOUT_SECONDS 10
+
+static gboolean
+large_message_timeout_cb (gpointer data)
+{
+  (void)data;
+
+  g_error ("Error: timeout waiting for dbus name to appear\n");
+
+  return FALSE;
+}
 
 static void
 large_message_on_name_appeared (GDBusConnection *connection,
@@ -130,6 +140,8 @@ large_message_on_name_appeared (GDBusConnection *connection,
   GVariant *result;
   guint n;
 
+  g_assert (g_source_remove (GPOINTER_TO_UINT (user_data)));
+
   request = g_new (gchar, LARGE_MESSAGE_STRING_LENGTH + 1);
   for (n = 0; n < LARGE_MESSAGE_STRING_LENGTH; n++)
     request[n] = '0' + (n%10);
@@ -171,18 +183,23 @@ static void
 test_connection_large_message (void)
 {
   guint watcher_id;
+  guint timeout_id;
 
   session_bus_up ();
 
   /* this is safe; testserver will exit once the bus goes away */
-  g_assert (g_spawn_command_line_async (SRCDIR "/gdbus-testserver.py", NULL));
+  g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL));
+
+  timeout_id = g_timeout_add_seconds (LARGE_MESSAGE_TIMEOUT_SECONDS,
+                                      large_message_timeout_cb,
+                                      NULL);
 
   watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
                                  "com.example.TestService",
                                  G_BUS_NAME_WATCHER_FLAGS_NONE,
                                  large_message_on_name_appeared,
                                  large_message_on_name_vanished,
-                                 NULL,  /* user_data */
+                                 GUINT_TO_POINTER (timeout_id),  /* user_data */
                                  NULL); /* GDestroyNotify */
   g_main_loop_run (loop);
   g_bus_unwatch_name (watcher_id);
@@ -196,19 +213,19 @@ int
 main (int   argc,
       char *argv[])
 {
-  g_type_init ();
+  gint ret;
+
   g_test_init (&argc, &argv, NULL);
 
   /* all the tests rely on a shared main loop */
   loop = g_main_loop_new (NULL, FALSE);
 
-  /* all the tests use a session bus with a well-known address that we can bring up and down
-   * using session_bus_up() and session_bus_down().
-   */
-  g_unsetenv ("DISPLAY");
-  g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
+  g_test_dbus_unset ();
 
   g_test_add_func ("/gdbus/connection/flush", test_connection_flush);
   g_test_add_func ("/gdbus/connection/large_message", test_connection_large_message);
-  return g_test_run();
+
+  ret = g_test_run();
+  g_main_loop_unref (loop);
+  return ret;
 }