[gtksourceview/wip/loader-saver] test-file-saver: use subprocesses for async functions



commit cf358bb7b5f256eaa6e81fd111c24ce32848dec5
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Dec 20 19:04:42 2013 +0100

    test-file-saver: use subprocesses for async functions
    
    All tests call the generic function test_saver(). gtk_main() is called
    at the end of test_saver(), and gtk_main_quit() is called at the end of
    the operation.

 tests/test-file-saver.c |   96 +++++++++++++++++++++++++++++++++++++----------
 1 files changed, 76 insertions(+), 20 deletions(-)
---
diff --git a/tests/test-file-saver.c b/tests/test-file-saver.c
index 84d5fd2..7149215 100644
--- a/tests/test-file-saver.c
+++ b/tests/test-file-saver.c
@@ -109,9 +109,7 @@ save_file_cb (GtkSourceFile *file,
        }
 
        /* finished */
-       g_object_unref (data->file);
-       g_object_unref (data->location);
-       g_slice_free (SaverTestData, data);
+       gtk_main_quit ();
 }
 
 static void
@@ -211,6 +209,11 @@ test_saver (const gchar            *filename_or_uri,
        data->userdata = userdata;
 
        check_mounted (data);
+       gtk_main ();
+
+       g_object_unref (data->file);
+       g_object_unref (data->location);
+       g_slice_free (SaverTestData, data);
 }
 
 typedef struct
@@ -660,53 +663,106 @@ check_unowned_group (void)
        return TRUE;
 }
 
-gint
-main (gint   argc,
-      gchar *argv[])
+static void
+all_tests (void)
 {
        gboolean have_unowned;
        gboolean have_unowned_group;
 
-       g_test_init (&argc, &argv, NULL);
-       gtk_init (&argc, &argv);
-
        g_printf ("\n***\n");
        have_unowned = check_unowned_directory ();
        have_unowned_group = check_unowned_group ();
        g_printf ("***\n\n");
 
-       g_test_add_func ("/file-saver/local", test_local);
-       g_test_add_func ("/file-saver/local-new-line", test_local_newline);
+       g_test_trap_subprocess ("/file-saver/subprocess/local",
+                               0,
+                               G_TEST_SUBPROCESS_INHERIT_STDERR);
+       g_test_trap_assert_passed ();
+
+       g_test_trap_subprocess ("/file-saver/subprocess/local-new-line",
+                               0,
+                               G_TEST_SUBPROCESS_INHERIT_STDERR);
+       g_test_trap_assert_passed ();
 
        if (have_unowned)
        {
-               g_test_add_func ("/file-saver/local-unowned-directory", test_local_unowned_directory);
+               g_test_trap_subprocess ("/file-saver/subprocess/local-unowned-directory",
+                                       0,
+                                       G_TEST_SUBPROCESS_INHERIT_STDERR);
+               g_test_trap_assert_passed ();
        }
 
-       g_test_add_func ("/file-saver/remote", test_remote);
-       g_test_add_func ("/file-saver/remote-new-line", test_remote_newline);
+       g_test_trap_subprocess ("/file-saver/subprocess/remote",
+                               0,
+                               G_TEST_SUBPROCESS_INHERIT_STDERR);
+       g_test_trap_assert_passed ();
 
+       g_test_trap_subprocess ("/file-saver/subprocess/remote-new-line",
+                               0,
+                               G_TEST_SUBPROCESS_INHERIT_STDERR);
+       g_test_trap_assert_passed ();
 
        if (have_unowned)
        {
-               g_test_add_func ("/file-saver/remote-unowned-directory", test_remote_unowned_directory);
+               g_test_trap_subprocess ("/file-saver/subprocess/remote-unowned-directory",
+                                       0,
+                                       G_TEST_SUBPROCESS_INHERIT_STDERR);
+               g_test_trap_assert_passed ();
        }
 
+#if 0
        if (have_unowned_group)
        {
-               /* FIXME: there is a bug in gvfs sftp which doesn't pass this test */
-               /* g_test_add_func ("/file-saver/remote-unowned-group", test_remote_unowned_group); */
+               g_test_trap_subprocess ("/file-saver/subprocess/remote-unowned-group",
+                                       0,
+                                       G_TEST_SUBPROCESS_INHERIT_STDERR);
+               g_test_trap_assert_passed ();
        }
+#endif
 
 #ifndef G_OS_WIN32
-       g_test_add_func ("/file-saver/local-permissions", test_local_permissions);
+       g_test_trap_subprocess ("/file-saver/subprocess/local-permissions",
+                               0,
+                               G_TEST_SUBPROCESS_INHERIT_STDERR);
+       g_test_trap_assert_passed ();
 
        if (have_unowned_group)
        {
-               g_test_add_func ("/file-saver/local-unowned-group", test_local_unowned_group);
+               g_test_trap_subprocess ("/file-saver/subprocess/local-unowned-group",
+                                       0,
+                                       G_TEST_SUBPROCESS_INHERIT_STDERR);
+               g_test_trap_assert_passed ();
        }
 
-       g_test_add_func ("/file-saver/remote-permissions", test_remote_permissions);
+       g_test_trap_subprocess ("/file-saver/subprocess/remote-permissions",
+                               0,
+                               G_TEST_SUBPROCESS_INHERIT_STDERR);
+       g_test_trap_assert_passed ();
+#endif
+}
+
+gint
+main (gint   argc,
+      gchar *argv[])
+{
+       gtk_test_init (&argc, &argv);
+
+       g_test_add_func ("/file-saver", all_tests);
+
+       g_test_add_func ("/file-saver/subprocess/local", test_local);
+       g_test_add_func ("/file-saver/subprocess/local-new-line", test_local_newline);
+       g_test_add_func ("/file-saver/subprocess/local-unowned-directory", test_local_unowned_directory);
+       g_test_add_func ("/file-saver/subprocess/remote", test_remote);
+       g_test_add_func ("/file-saver/subprocess/remote-new-line", test_remote_newline);
+       g_test_add_func ("/file-saver/subprocess/remote-unowned-directory", test_remote_unowned_directory);
+
+       /* FIXME: there is a bug in gvfs sftp which doesn't pass this test */
+       /* g_test_add_func ("/file-saver/subprocess/remote-unowned-group", test_remote_unowned_group); */
+
+#ifndef G_OS_WIN32
+       g_test_add_func ("/file-saver/subprocess/local-permissions", test_local_permissions);
+       g_test_add_func ("/file-saver/subprocess/local-unowned-group", test_local_unowned_group);
+       g_test_add_func ("/file-saver/subprocess/remote-permissions", test_remote_permissions);
 #endif
 
        return g_test_run ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]