summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2013-11-28 12:59:11 -0500
committerMatthias Clasen <mclasen@redhat.com>2013-11-28 16:01:23 -0500
commita688b2a9c0192a8373407fb53636d0e2c6d3ecbd (patch)
treea9dd93ff79ee4fe255cfe9f8f8f8bfca8d442914
parentf18138a9cf4b43c527636688ac87d03385c9664a (diff)
downloadglib-a688b2a9c0192a8373407fb53636d0e2c6d3ecbd.tar.gz
Improve test coverage for GSubprocess
-rw-r--r--gio/tests/gsubprocess-testprog.c14
-rw-r--r--gio/tests/gsubprocess.c30
2 files changed, 44 insertions, 0 deletions
diff --git a/gio/tests/gsubprocess-testprog.c b/gio/tests/gsubprocess-testprog.c
index 45c7d93d6..fbb0c835d 100644
--- a/gio/tests/gsubprocess-testprog.c
+++ b/gio/tests/gsubprocess-testprog.c
@@ -163,6 +163,18 @@ env_mode (int argc, char **argv)
return 0;
}
+static int
+cwd_mode (int argc, char **argv)
+{
+ char *cwd;
+
+ cwd = g_get_current_dir ();
+ g_print ("%s\n", cwd);
+ g_free (cwd);
+
+ return 0;
+}
+
int
main (int argc, char **argv)
{
@@ -208,6 +220,8 @@ main (int argc, char **argv)
return write_to_fds (argc, argv);
else if (strcmp (mode, "env") == 0)
return env_mode (argc, argv);
+ else if (strcmp (mode, "cwd") == 0)
+ return cwd_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 73fa715e6..6dfc6b302 100644
--- a/gio/tests/gsubprocess.c
+++ b/gio/tests/gsubprocess.c
@@ -797,6 +797,35 @@ test_env (void)
g_object_unref (proc);
}
+static void
+test_cwd (void)
+{
+ GError *local_error = NULL;
+ GError **error = &local_error;
+ GSubprocessLauncher *launcher;
+ GSubprocess *proc;
+ GPtrArray *args;
+ GInputStream *stdout;
+ gchar *result;
+
+ args = get_test_subprocess_args ("cwd", NULL);
+ launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE);
+ g_subprocess_launcher_set_flags (launcher, G_SUBPROCESS_FLAGS_STDOUT_PIPE);
+ g_subprocess_launcher_set_cwd (launcher, "/tmp");
+
+ proc = g_subprocess_launcher_spawnv (launcher, (const char * 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);
+
+ g_assert_cmpstr (result, ==, "/tmp" LINEEND);
+
+ g_free (result);
+ g_object_unref (proc);
+}
#ifdef G_OS_UNIX
static void
test_stdout_file (void)
@@ -1044,6 +1073,7 @@ main (int argc, char **argv)
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);
+ g_test_add_func ("/gsubprocess/cwd", test_cwd);
#ifdef G_OS_UNIX
g_test_add_func ("/gsubprocess/stdout-file", test_stdout_file);
g_test_add_func ("/gsubprocess/stdout-fd", test_stdout_fd);