From: Matthias Clasen Date: Thu, 28 Nov 2013 06:12:26 +0000 (-0500) Subject: Test some more GSubProcess api X-Git-Tag: 2.39.2~67 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4a687ed7237143be0e6c38c970aef0603793fc71;p=platform%2Fupstream%2Fglib.git Test some more GSubProcess api This covers g_subprocess_set_environ, g_subprocess_setenv, g_subprocess_getenv, and g_subprocess_set_flags. --- diff --git a/gio/tests/gsubprocess-testprog.c b/gio/tests/gsubprocess-testprog.c index df865f626..45c7d93d6 100644 --- a/gio/tests/gsubprocess-testprog.c +++ b/gio/tests/gsubprocess-testprog.c @@ -147,6 +147,22 @@ write_to_fds (int argc, char **argv) return 0; } +static int +env_mode (int argc, char **argv) +{ + char **env; + int i; + + env = g_get_environ (); + + for (i = 0; env[i]; i++) + g_print ("%s\n", env[i]); + + g_strfreev (env); + + return 0; +} + int main (int argc, char **argv) { @@ -190,6 +206,8 @@ main (int argc, char **argv) return sleep_forever_mode (argc, argv); else if (strcmp (mode, "write-to-fds") == 0) return write_to_fds (argc, argv); + else if (strcmp (mode, "env") == 0) + return env_mode (argc, argv); else { g_printerr ("Unknown MODE %s\n", argv[1]); diff --git a/gio/tests/gsubprocess.c b/gio/tests/gsubprocess.c index 4e70c4d2e..3dcabc631 100644 --- a/gio/tests/gsubprocess.c +++ b/gio/tests/gsubprocess.c @@ -756,6 +756,47 @@ test_terminate (void) g_object_unref (proc); } +static void +test_env (void) +{ + GError *local_error = NULL; + GError **error = &local_error; + GSubprocessLauncher *launcher; + GSubprocess *proc; + GPtrArray *args; + GInputStream *stdout; + gchar *result; + gchar *envp[] = { "ONE=1", "TWO=1", "THREE=3", "FOUR=1", NULL }; + gchar **split; + + args = get_test_subprocess_args ("env", NULL); + launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE); + g_subprocess_launcher_set_flags (launcher, G_SUBPROCESS_FLAGS_STDOUT_PIPE); + g_subprocess_launcher_set_environ (launcher, envp); + g_subprocess_launcher_setenv (launcher, "TWO", "2", TRUE); + g_subprocess_launcher_setenv (launcher, "THREE", "1", FALSE); + g_subprocess_launcher_unsetenv (launcher, "FOUR"); + + g_assert_null (g_subprocess_launcher_getenv (launcher, "FOUR")); + + proc = g_subprocess_launcher_spawnv (launcher, (const gchar * const *) args->pdata, error); + g_ptr_array_free (args, TRUE); + g_assert_no_error (local_error); + + stdout = g_subprocess_get_stdout_pipe (proc); + + result = splice_to_string (stdout, error); + split = g_strsplit (result, "\n", -1); + g_assert_cmpstr (g_environ_getenv (split, "ONE"), ==, "1"); + g_assert_cmpstr (g_environ_getenv (split, "TWO"), ==, "2"); + g_assert_cmpstr (g_environ_getenv (split, "THREE"), ==, "3"); + g_assert_null (g_environ_getenv (split, "FOUR")); + + g_strfreev (split); + g_free (result); + g_object_unref (proc); +} + #ifdef G_OS_UNIX static void test_stdout_file (void) @@ -1002,6 +1043,7 @@ main (int argc, char **argv) g_test_add_func ("/gsubprocess/communicate-utf8", test_communicate_utf8); g_test_add_func ("/gsubprocess/communicate-utf8-invalid", test_communicate_utf8_invalid); g_test_add_func ("/gsubprocess/terminate", test_terminate); + g_test_add_func ("/gsubprocess/env", test_env); #ifdef G_OS_UNIX g_test_add_func ("/gsubprocess/stdout-file", test_stdout_file); g_test_add_func ("/gsubprocess/stdout-fd", test_stdout_fd);