[glib] Improve test coverage for GSubprocess
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Improve test coverage for GSubprocess
- Date: Fri, 29 Nov 2013 02:56:18 +0000 (UTC)
commit a688b2a9c0192a8373407fb53636d0e2c6d3ecbd
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Nov 28 12:59:11 2013 -0500
Improve test coverage for GSubprocess
gio/tests/gsubprocess-testprog.c | 14 ++++++++++++++
gio/tests/gsubprocess.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/gio/tests/gsubprocess-testprog.c b/gio/tests/gsubprocess-testprog.c
index 45c7d93..fbb0c83 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 73fa715..6dfc6b3 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]