X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=glib%2Ftests%2Fspawn-singlethread.c;h=7985eef7f04db7123fd1a8313d1865ab8ddef10b;hb=49b59e5ac4428a6a99a85d699c3662f96efc4e9d;hp=f29ecb8ab207c61cce25ca27a6a12bdb99742753;hpb=a9a1c97904aeed96bcb248e16cb495e6907b7126;p=platform%2Fupstream%2Fglib.git diff --git a/glib/tests/spawn-singlethread.c b/glib/tests/spawn-singlethread.c index f29ecb8..7985eef 100644 --- a/glib/tests/spawn-singlethread.c +++ b/glib/tests/spawn-singlethread.c @@ -26,7 +26,24 @@ #include #include +#ifdef G_OS_WIN32 +#define LINEEND "\r\n" +#else +#define LINEEND "\n" +#endif + +/* MinGW builds are likely done using a BASH-style shell, so run the + * normal script there, as on non-Windows builds, as it is more likely + * that one will run 'make check' in such shells to test the code + */ +#if defined (G_OS_WIN32) && defined (_MSC_VER) +#define SCRIPT_EXT ".bat" +#else +#define SCRIPT_EXT +#endif + static char *echo_prog_path; +static char *echo_script_path; typedef struct { GMainLoop *loop; @@ -46,7 +63,7 @@ on_child_exited (GPid pid, if (data->child_exited && data->stdout_done) g_main_loop_quit (data->loop); - return FALSE; + return G_SOURCE_REMOVE; } static gboolean @@ -164,27 +181,60 @@ test_spawn_sync (void) g_ptr_array_free (argv, TRUE); } +static void +test_spawn_script (void) +{ + GError *error = NULL; + GPtrArray *argv; + char *stdout_str; + int estatus; + + argv = g_ptr_array_new (); + g_ptr_array_add (argv, echo_script_path); + g_ptr_array_add (argv, NULL); + + g_spawn_sync (NULL, (char**)argv->pdata, NULL, 0, NULL, NULL, &stdout_str, NULL, &estatus, &error); + g_assert_no_error (error); + g_assert_cmpstr ("echo" LINEEND, ==, stdout_str); + g_free (stdout_str); + g_ptr_array_free (argv, TRUE); +} + int main (int argc, char *argv[]) { char *dirname; + int ret; g_test_init (&argc, &argv, NULL); dirname = g_path_get_dirname (argv[0]); - echo_prog_path = g_build_filename (dirname, "test-spawn-echo", NULL); + echo_prog_path = g_build_filename (dirname, "test-spawn-echo" EXEEXT, NULL); if (!g_file_test (echo_prog_path, G_FILE_TEST_EXISTS)) { g_free (echo_prog_path); - echo_prog_path = g_build_filename (dirname, "lt-test-spawn-echo", NULL); + echo_prog_path = g_build_filename (dirname, "lt-test-spawn-echo" EXEEXT, NULL); + } + echo_script_path = g_build_filename (dirname, "echo-script" SCRIPT_EXT, NULL); + if (!g_file_test (echo_script_path, G_FILE_TEST_EXISTS)) + { + g_free (echo_script_path); + echo_script_path = g_test_build_filename (G_TEST_DIST, "echo-script" SCRIPT_EXT, NULL); } g_free (dirname); g_assert (g_file_test (echo_prog_path, G_FILE_TEST_EXISTS)); + g_assert (g_file_test (echo_script_path, G_FILE_TEST_EXISTS)); g_test_add_func ("/gthread/spawn-single-sync", test_spawn_sync); g_test_add_func ("/gthread/spawn-single-async", test_spawn_async); + g_test_add_func ("/gthread/spawn-script", test_spawn_script); + + ret = g_test_run(); + + g_free (echo_script_path); + g_free (echo_prog_path); - return g_test_run(); + return ret; }