gio: Annotate GDBusObjectManagerClient signal appropriately
[glib.git] / gio / tests / gsubprocess.c
blob39f748bf45d8b55798d78670cd022c9335f76328
1 #include <gio/gio.h>
2 #include <string.h>
4 #ifdef G_OS_UNIX
5 #include <sys/wait.h>
6 #include <glib-unix.h>
7 #include <gio/gunixinputstream.h>
8 #include <gio/gfiledescriptorbased.h>
9 #endif
11 #ifdef G_OS_WIN32
12 #define LINEEND "\r\n"
13 #define EXEEXT ".exe"
14 #else
15 #define LINEEND "\n"
16 #define EXEEXT
17 #endif
19 static GPtrArray *
20 get_test_subprocess_args (const char *mode,
21 ...) G_GNUC_NULL_TERMINATED;
23 static GPtrArray *
24 get_test_subprocess_args (const char *mode,
25 ...)
27 GPtrArray *ret;
28 char *path;
29 const char *binname;
30 va_list args;
31 gpointer arg;
33 ret = g_ptr_array_new_with_free_func (g_free);
35 #ifdef G_OS_WIN32
36 binname = "gsubprocess-testprog.exe";
37 #else
38 binname = "gsubprocess-testprog";
39 #endif
41 path = g_test_build_filename (G_TEST_BUILT, binname, NULL);
42 g_ptr_array_add (ret, path);
43 g_ptr_array_add (ret, g_strdup (mode));
45 va_start (args, mode);
46 while ((arg = va_arg (args, gpointer)) != NULL)
47 g_ptr_array_add (ret, g_strdup (arg));
48 va_end (args);
50 g_ptr_array_add (ret, NULL);
51 return ret;
54 static void
55 test_noop (void)
57 GError *local_error = NULL;
58 GError **error = &local_error;
59 GPtrArray *args;
60 GSubprocess *proc;
61 const gchar *id;
63 args = get_test_subprocess_args ("noop", NULL);
64 proc = g_subprocess_newv ((const gchar * const *) args->pdata, G_SUBPROCESS_FLAGS_NONE, error);
65 g_ptr_array_free (args, TRUE);
66 g_assert_no_error (local_error);
67 id = g_subprocess_get_identifier (proc);
68 g_assert (id != NULL);
70 g_subprocess_wait_check (proc, NULL, error);
71 g_assert_no_error (local_error);
72 g_assert (g_subprocess_get_successful (proc));
74 g_object_unref (proc);
77 static void
78 check_ready (GObject *source,
79 GAsyncResult *res,
80 gpointer user_data)
82 gboolean ret;
83 GError *error = NULL;
85 ret = g_subprocess_wait_check_finish (G_SUBPROCESS (source),
86 res,
87 &error);
88 g_assert (ret);
89 g_assert_no_error (error);
91 g_object_unref (source);
94 static void
95 test_noop_all_to_null (void)
97 GError *local_error = NULL;
98 GError **error = &local_error;
99 GPtrArray *args;
100 GSubprocess *proc;
102 args = get_test_subprocess_args ("noop", NULL);
103 proc = g_subprocess_newv ((const gchar * const *) args->pdata,
104 G_SUBPROCESS_FLAGS_STDOUT_SILENCE | G_SUBPROCESS_FLAGS_STDERR_SILENCE,
105 error);
106 g_ptr_array_free (args, TRUE);
107 g_assert_no_error (local_error);
109 g_subprocess_wait_check_async (proc, NULL, check_ready, NULL);
112 static void
113 test_noop_no_wait (void)
115 GError *local_error = NULL;
116 GError **error = &local_error;
117 GPtrArray *args;
118 GSubprocess *proc;
120 args = get_test_subprocess_args ("noop", NULL);
121 proc = g_subprocess_newv ((const gchar * const *) args->pdata, G_SUBPROCESS_FLAGS_NONE, error);
122 g_ptr_array_free (args, TRUE);
123 g_assert_no_error (local_error);
125 g_object_unref (proc);
128 static void
129 test_noop_stdin_inherit (void)
131 GError *local_error = NULL;
132 GError **error = &local_error;
133 GPtrArray *args;
134 GSubprocess *proc;
136 args = get_test_subprocess_args ("noop", NULL);
137 proc = g_subprocess_newv ((const gchar * const *) args->pdata, G_SUBPROCESS_FLAGS_STDIN_INHERIT, error);
138 g_ptr_array_free (args, TRUE);
139 g_assert_no_error (local_error);
141 g_subprocess_wait_check (proc, NULL, error);
142 g_assert_no_error (local_error);
144 g_object_unref (proc);
147 #ifdef G_OS_UNIX
148 static void
149 test_search_path (void)
151 GError *local_error = NULL;
152 GError **error = &local_error;
153 GSubprocess *proc;
155 proc = g_subprocess_new (G_SUBPROCESS_FLAGS_NONE, error, "true", NULL);
156 g_assert_no_error (local_error);
158 g_subprocess_wait_check (proc, NULL, error);
159 g_assert_no_error (local_error);
161 g_object_unref (proc);
163 #endif
165 static void
166 test_exit1 (void)
168 GError *local_error = NULL;
169 GError **error = &local_error;
170 GPtrArray *args;
171 GSubprocess *proc;
173 args = get_test_subprocess_args ("exit1", NULL);
174 proc = g_subprocess_newv ((const gchar * const *) args->pdata, G_SUBPROCESS_FLAGS_NONE, error);
175 g_ptr_array_free (args, TRUE);
176 g_assert_no_error (local_error);
178 g_subprocess_wait_check (proc, NULL, error);
179 g_assert_error (local_error, G_SPAWN_EXIT_ERROR, 1);
180 g_clear_error (error);
182 g_object_unref (proc);
185 typedef struct {
186 GMainLoop *loop;
187 GCancellable *cancellable;
188 gboolean cb_called;
189 } TestExit1CancelData;
191 static gboolean
192 test_exit1_cancel_idle_quit_cb (gpointer user_data)
194 GMainLoop *loop = user_data;
195 g_main_loop_quit (loop);
196 return G_SOURCE_REMOVE;
199 static void
200 test_exit1_cancel_wait_check_cb (GObject *source,
201 GAsyncResult *result,
202 gpointer user_data)
204 GSubprocess *subprocess = G_SUBPROCESS (source);
205 TestExit1CancelData *data = user_data;
206 gboolean ret;
207 GError *error = NULL;
209 g_assert_false (data->cb_called);
210 data->cb_called = TRUE;
212 ret = g_subprocess_wait_check_finish (subprocess, result, &error);
213 g_assert (!ret);
214 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
215 g_clear_error (&error);
217 g_idle_add (test_exit1_cancel_idle_quit_cb, data->loop);
220 static void
221 test_exit1_cancel (void)
223 GError *local_error = NULL;
224 GError **error = &local_error;
225 GPtrArray *args;
226 GSubprocess *proc;
227 TestExit1CancelData data = { 0 };
229 g_test_bug ("786456");
231 args = get_test_subprocess_args ("exit1", NULL);
232 proc = g_subprocess_newv ((const gchar * const *) args->pdata, G_SUBPROCESS_FLAGS_NONE, error);
233 g_ptr_array_free (args, TRUE);
234 g_assert_no_error (local_error);
236 data.loop = g_main_loop_new (NULL, FALSE);
237 data.cancellable = g_cancellable_new ();
238 g_subprocess_wait_check_async (proc, data.cancellable, test_exit1_cancel_wait_check_cb, &data);
240 g_subprocess_wait_check (proc, NULL, error);
241 g_assert_error (local_error, G_SPAWN_EXIT_ERROR, 1);
242 g_clear_error (error);
244 g_cancellable_cancel (data.cancellable);
245 g_main_loop_run (data.loop);
247 g_object_unref (proc);
248 g_main_loop_unref (data.loop);
249 g_clear_object (&data.cancellable);
252 static void
253 test_exit1_cancel_in_cb_wait_check_cb (GObject *source,
254 GAsyncResult *result,
255 gpointer user_data)
257 GSubprocess *subprocess = G_SUBPROCESS (source);
258 TestExit1CancelData *data = user_data;
259 gboolean ret;
260 GError *error = NULL;
262 g_assert_false (data->cb_called);
263 data->cb_called = TRUE;
265 ret = g_subprocess_wait_check_finish (subprocess, result, &error);
266 g_assert (!ret);
267 g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
268 g_clear_error (&error);
270 g_cancellable_cancel (data->cancellable);
272 g_idle_add (test_exit1_cancel_idle_quit_cb, data->loop);
275 static void
276 test_exit1_cancel_in_cb (void)
278 GError *local_error = NULL;
279 GError **error = &local_error;
280 GPtrArray *args;
281 GSubprocess *proc;
282 TestExit1CancelData data = { 0 };
284 g_test_bug ("786456");
286 args = get_test_subprocess_args ("exit1", NULL);
287 proc = g_subprocess_newv ((const gchar * const *) args->pdata, G_SUBPROCESS_FLAGS_NONE, error);
288 g_ptr_array_free (args, TRUE);
289 g_assert_no_error (local_error);
291 data.loop = g_main_loop_new (NULL, FALSE);
292 data.cancellable = g_cancellable_new ();
293 g_subprocess_wait_check_async (proc, data.cancellable, test_exit1_cancel_in_cb_wait_check_cb, &data);
295 g_subprocess_wait_check (proc, NULL, error);
296 g_assert_error (local_error, G_SPAWN_EXIT_ERROR, 1);
297 g_clear_error (error);
299 g_main_loop_run (data.loop);
301 g_object_unref (proc);
302 g_main_loop_unref (data.loop);
303 g_clear_object (&data.cancellable);
306 static gchar *
307 splice_to_string (GInputStream *stream,
308 GError **error)
310 GMemoryOutputStream *buffer = NULL;
311 char *ret = NULL;
313 buffer = (GMemoryOutputStream*)g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
314 if (g_output_stream_splice ((GOutputStream*)buffer, stream, 0, NULL, error) < 0)
315 goto out;
317 if (!g_output_stream_write ((GOutputStream*)buffer, "\0", 1, NULL, error))
318 goto out;
320 if (!g_output_stream_close ((GOutputStream*)buffer, NULL, error))
321 goto out;
323 ret = g_memory_output_stream_steal_data (buffer);
324 out:
325 g_clear_object (&buffer);
326 return ret;
329 static void
330 test_echo1 (void)
332 GError *local_error = NULL;
333 GError **error = &local_error;
334 GSubprocess *proc;
335 GPtrArray *args;
336 GInputStream *stdout;
337 gchar *result;
339 args = get_test_subprocess_args ("echo", "hello", "world!", NULL);
340 proc = g_subprocess_newv ((const gchar * const *) args->pdata, G_SUBPROCESS_FLAGS_STDOUT_PIPE, error);
341 g_ptr_array_free (args, TRUE);
342 g_assert_no_error (local_error);
344 stdout = g_subprocess_get_stdout_pipe (proc);
346 result = splice_to_string (stdout, error);
347 g_assert_no_error (local_error);
349 g_assert_cmpstr (result, ==, "hello" LINEEND "world!" LINEEND);
351 g_free (result);
352 g_object_unref (proc);
355 #ifdef G_OS_UNIX
356 static void
357 test_echo_merged (void)
359 GError *local_error = NULL;
360 GError **error = &local_error;
361 GSubprocess *proc;
362 GPtrArray *args;
363 GInputStream *stdout;
364 gchar *result;
366 args = get_test_subprocess_args ("echo-stdout-and-stderr", "merge", "this", NULL);
367 proc = g_subprocess_newv ((const gchar * const *) args->pdata,
368 G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_MERGE,
369 error);
370 g_ptr_array_free (args, TRUE);
371 g_assert_no_error (local_error);
373 stdout = g_subprocess_get_stdout_pipe (proc);
374 result = splice_to_string (stdout, error);
375 g_assert_no_error (local_error);
377 g_assert_cmpstr (result, ==, "merge\nmerge\nthis\nthis\n");
379 g_free (result);
380 g_object_unref (proc);
382 #endif
384 typedef struct {
385 guint events_pending;
386 GMainLoop *loop;
387 } TestCatData;
389 static void
390 test_cat_on_input_splice_complete (GObject *object,
391 GAsyncResult *result,
392 gpointer user_data)
394 TestCatData *data = user_data;
395 GError *error = NULL;
397 (void)g_output_stream_splice_finish ((GOutputStream*)object, result, &error);
398 g_assert_no_error (error);
400 data->events_pending--;
401 if (data->events_pending == 0)
402 g_main_loop_quit (data->loop);
405 static void
406 test_cat_utf8 (void)
408 GError *local_error = NULL;
409 GError **error = &local_error;
410 GSubprocess *proc;
411 GPtrArray *args;
412 GBytes *input_buf;
413 GBytes *output_buf;
414 GInputStream *input_buf_stream = NULL;
415 GOutputStream *output_buf_stream = NULL;
416 GOutputStream *stdin_stream = NULL;
417 GInputStream *stdout_stream = NULL;
418 TestCatData data;
420 memset (&data, 0, sizeof (data));
421 data.loop = g_main_loop_new (NULL, TRUE);
423 args = get_test_subprocess_args ("cat", NULL);
424 proc = g_subprocess_newv ((const gchar * const *) args->pdata,
425 G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE,
426 error);
427 g_ptr_array_free (args, TRUE);
428 g_assert_no_error (local_error);
430 stdin_stream = g_subprocess_get_stdin_pipe (proc);
431 stdout_stream = g_subprocess_get_stdout_pipe (proc);
433 input_buf = g_bytes_new_static ("hello, world!", strlen ("hello, world!"));
434 input_buf_stream = g_memory_input_stream_new_from_bytes (input_buf);
435 g_bytes_unref (input_buf);
437 output_buf_stream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
439 g_output_stream_splice_async (stdin_stream, input_buf_stream, G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
440 G_PRIORITY_DEFAULT, NULL, test_cat_on_input_splice_complete,
441 &data);
442 data.events_pending++;
443 g_output_stream_splice_async (output_buf_stream, stdout_stream, G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
444 G_PRIORITY_DEFAULT, NULL, test_cat_on_input_splice_complete,
445 &data);
446 data.events_pending++;
448 g_main_loop_run (data.loop);
450 g_subprocess_wait_check (proc, NULL, error);
451 g_assert_no_error (local_error);
453 output_buf = g_memory_output_stream_steal_as_bytes ((GMemoryOutputStream*)output_buf_stream);
455 g_assert_cmpmem (g_bytes_get_data (output_buf, NULL),
456 g_bytes_get_size (output_buf),
457 "hello, world!", 13);
459 g_bytes_unref (output_buf);
460 g_main_loop_unref (data.loop);
461 g_object_unref (input_buf_stream);
462 g_object_unref (output_buf_stream);
463 g_object_unref (proc);
466 static gpointer
467 cancel_soon (gpointer user_data)
469 GCancellable *cancellable = user_data;
471 g_usleep (G_TIME_SPAN_SECOND);
472 g_cancellable_cancel (cancellable);
473 g_object_unref (cancellable);
475 return NULL;
478 static void
479 test_cat_eof (void)
481 GCancellable *cancellable;
482 GError *error = NULL;
483 GSubprocess *cat;
484 gboolean result;
485 gchar buffer;
486 gssize s;
488 #ifdef G_OS_WIN32
489 g_test_skip ("This test has not been ported to Win32");
490 return;
491 #endif
493 /* Spawn 'cat' */
494 cat = g_subprocess_new (G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE, &error, "cat", NULL);
495 g_assert_no_error (error);
496 g_assert (cat);
498 /* Make sure that reading stdout blocks (until we cancel) */
499 cancellable = g_cancellable_new ();
500 g_thread_unref (g_thread_new ("cancel thread", cancel_soon, g_object_ref (cancellable)));
501 s = g_input_stream_read (g_subprocess_get_stdout_pipe (cat), &buffer, sizeof buffer, cancellable, &error);
502 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
503 g_assert_cmpint (s, ==, -1);
504 g_object_unref (cancellable);
505 g_clear_error (&error);
507 /* Close the stream (EOF on cat's stdin) */
508 result = g_output_stream_close (g_subprocess_get_stdin_pipe (cat), NULL, &error);
509 g_assert_no_error (error);
510 g_assert (result);
512 /* Now check that reading cat's stdout gets us an EOF (since it quit) */
513 s = g_input_stream_read (g_subprocess_get_stdout_pipe (cat), &buffer, sizeof buffer, NULL, &error);
514 g_assert_no_error (error);
515 g_assert (!s);
517 /* Check that the process has exited as a result of the EOF */
518 result = g_subprocess_wait (cat, NULL, &error);
519 g_assert_no_error (error);
520 g_assert (g_subprocess_get_if_exited (cat));
521 g_assert_cmpint (g_subprocess_get_exit_status (cat), ==, 0);
522 g_assert (result);
524 g_object_unref (cat);
527 typedef struct {
528 guint events_pending;
529 gboolean caught_error;
530 GError *error;
531 GMainLoop *loop;
533 gint counter;
534 GOutputStream *first_stdin;
535 } TestMultiSpliceData;
537 static void
538 on_one_multi_splice_done (GObject *obj,
539 GAsyncResult *res,
540 gpointer user_data)
542 TestMultiSpliceData *data = user_data;
544 if (!data->caught_error)
546 if (g_output_stream_splice_finish ((GOutputStream*)obj, res, &data->error) < 0)
547 data->caught_error = TRUE;
550 data->events_pending--;
551 if (data->events_pending == 0)
552 g_main_loop_quit (data->loop);
555 static gboolean
556 on_idle_multisplice (gpointer user_data)
558 TestMultiSpliceData *data = user_data;
560 /* We write 2^1 + 2^2 ... + 2^10 or 2047 copies of "Hello World!\n"
561 * ultimately
563 if (data->counter >= 2047 || data->caught_error)
565 if (!g_output_stream_close (data->first_stdin, NULL, &data->error))
566 data->caught_error = TRUE;
567 data->events_pending--;
568 if (data->events_pending == 0)
570 g_main_loop_quit (data->loop);
572 return FALSE;
574 else
576 int i;
577 for (i = 0; i < data->counter; i++)
579 gsize bytes_written;
580 if (!g_output_stream_write_all (data->first_stdin, "hello world!\n",
581 strlen ("hello world!\n"), &bytes_written,
582 NULL, &data->error))
584 data->caught_error = TRUE;
585 return FALSE;
588 data->counter *= 2;
589 return TRUE;
593 static void
594 on_subprocess_exited (GObject *object,
595 GAsyncResult *result,
596 gpointer user_data)
598 GSubprocess *subprocess = G_SUBPROCESS (object);
599 TestMultiSpliceData *data = user_data;
600 GError *error = NULL;
602 if (!g_subprocess_wait_finish (subprocess, result, &error))
604 if (!data->caught_error)
606 data->caught_error = TRUE;
607 g_propagate_error (&data->error, error);
610 g_spawn_check_exit_status (g_subprocess_get_exit_status (subprocess), &error);
611 g_assert_no_error (error);
612 data->events_pending--;
613 if (data->events_pending == 0)
614 g_main_loop_quit (data->loop);
617 static void
618 test_multi_1 (void)
620 GError *local_error = NULL;
621 GError **error = &local_error;
622 GPtrArray *args;
623 GSubprocessLauncher *launcher;
624 GSubprocess *first;
625 GSubprocess *second;
626 GSubprocess *third;
627 GOutputStream *first_stdin;
628 GInputStream *first_stdout;
629 GOutputStream *second_stdin;
630 GInputStream *second_stdout;
631 GOutputStream *third_stdin;
632 GInputStream *third_stdout;
633 GOutputStream *membuf;
634 TestMultiSpliceData data;
635 int splice_flags = G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET;
637 args = get_test_subprocess_args ("cat", NULL);
638 launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE);
639 first = g_subprocess_launcher_spawnv (launcher, (const gchar * const *) args->pdata, error);
640 g_assert_no_error (local_error);
641 second = g_subprocess_launcher_spawnv (launcher, (const gchar * const *) args->pdata, error);
642 g_assert_no_error (local_error);
643 third = g_subprocess_launcher_spawnv (launcher, (const gchar * const *) args->pdata, error);
644 g_assert_no_error (local_error);
646 g_ptr_array_free (args, TRUE);
648 membuf = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
650 first_stdin = g_subprocess_get_stdin_pipe (first);
651 first_stdout = g_subprocess_get_stdout_pipe (first);
652 second_stdin = g_subprocess_get_stdin_pipe (second);
653 second_stdout = g_subprocess_get_stdout_pipe (second);
654 third_stdin = g_subprocess_get_stdin_pipe (third);
655 third_stdout = g_subprocess_get_stdout_pipe (third);
657 memset (&data, 0, sizeof (data));
658 data.loop = g_main_loop_new (NULL, TRUE);
659 data.counter = 1;
660 data.first_stdin = first_stdin;
662 data.events_pending++;
663 g_output_stream_splice_async (second_stdin, first_stdout, splice_flags, G_PRIORITY_DEFAULT,
664 NULL, on_one_multi_splice_done, &data);
665 data.events_pending++;
666 g_output_stream_splice_async (third_stdin, second_stdout, splice_flags, G_PRIORITY_DEFAULT,
667 NULL, on_one_multi_splice_done, &data);
668 data.events_pending++;
669 g_output_stream_splice_async (membuf, third_stdout, splice_flags, G_PRIORITY_DEFAULT,
670 NULL, on_one_multi_splice_done, &data);
672 data.events_pending++;
673 g_timeout_add (250, on_idle_multisplice, &data);
675 data.events_pending++;
676 g_subprocess_wait_async (first, NULL, on_subprocess_exited, &data);
677 data.events_pending++;
678 g_subprocess_wait_async (second, NULL, on_subprocess_exited, &data);
679 data.events_pending++;
680 g_subprocess_wait_async (third, NULL, on_subprocess_exited, &data);
682 g_main_loop_run (data.loop);
684 g_assert (!data.caught_error);
685 g_assert_no_error (data.error);
687 g_assert_cmpint (g_memory_output_stream_get_data_size ((GMemoryOutputStream*)membuf), ==, 26611);
689 g_main_loop_unref (data.loop);
690 g_object_unref (membuf);
691 g_object_unref (launcher);
692 g_object_unref (first);
693 g_object_unref (second);
694 g_object_unref (third);
697 typedef struct {
698 gboolean is_utf8;
699 gboolean running;
700 GError *error;
701 } TestAsyncCommunicateData;
703 static void
704 on_communicate_complete (GObject *proc,
705 GAsyncResult *result,
706 gpointer user_data)
708 TestAsyncCommunicateData *data = user_data;
709 GBytes *stdout = NULL;
710 char *stdout_str = NULL;
711 const guint8 *stdout_data;
712 gsize stdout_len;
714 data->running = FALSE;
715 if (data->is_utf8)
716 (void) g_subprocess_communicate_utf8_finish ((GSubprocess*)proc, result,
717 &stdout_str, NULL, &data->error);
718 else
719 (void) g_subprocess_communicate_finish ((GSubprocess*)proc, result,
720 &stdout, NULL, &data->error);
721 if (data->error)
722 return;
724 if (!data->is_utf8)
726 g_assert (stdout != NULL);
727 stdout_data = g_bytes_get_data (stdout, &stdout_len);
729 else
731 g_assert (stdout_str != NULL);
732 stdout_data = (guint8*)stdout_str;
733 stdout_len = strlen (stdout_str);
736 g_assert_cmpmem (stdout_data, stdout_len, "hello world", 11);
737 if (stdout)
738 g_bytes_unref (stdout);
739 g_free (stdout_str);
742 static void
743 test_communicate_async (void)
745 GError *error = NULL;
746 GPtrArray *args;
747 TestAsyncCommunicateData data = { 0, };
748 GSubprocess *proc;
749 GCancellable *cancellable = NULL;
750 GBytes *input;
751 const char *hellostring;
753 args = get_test_subprocess_args ("cat", NULL);
754 proc = g_subprocess_newv ((const gchar* const*)args->pdata,
755 G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE,
756 &error);
757 g_assert_no_error (error);
758 g_ptr_array_free (args, TRUE);
760 hellostring = "hello world";
761 input = g_bytes_new_static (hellostring, strlen (hellostring));
763 g_subprocess_communicate_async (proc, input,
764 cancellable,
765 on_communicate_complete,
766 &data);
768 data.running = TRUE;
769 while (data.running)
770 g_main_context_iteration (NULL, TRUE);
772 g_assert_no_error (data.error);
774 g_bytes_unref (input);
775 g_object_unref (proc);
778 static void
779 test_communicate (void)
781 GError *error = NULL;
782 GPtrArray *args;
783 GSubprocess *proc;
784 GCancellable *cancellable = NULL;
785 GBytes *input;
786 const gchar *hellostring;
787 GBytes *stdout;
788 const gchar *stdout_data;
789 gsize stdout_len;
791 args = get_test_subprocess_args ("cat", NULL);
792 proc = g_subprocess_newv ((const gchar* const*)args->pdata,
793 G_SUBPROCESS_FLAGS_STDIN_PIPE
794 | G_SUBPROCESS_FLAGS_STDOUT_PIPE
795 | G_SUBPROCESS_FLAGS_STDERR_MERGE,
796 &error);
797 g_assert_no_error (error);
798 g_ptr_array_free (args, TRUE);
800 hellostring = "hello world";
801 input = g_bytes_new_static (hellostring, strlen (hellostring));
803 g_subprocess_communicate (proc, input, cancellable, &stdout, NULL, &error);
804 g_assert_no_error (error);
805 stdout_data = g_bytes_get_data (stdout, &stdout_len);
807 g_assert_cmpmem (stdout_data, stdout_len, "hello world", 11);
809 g_bytes_unref (input);
810 g_bytes_unref (stdout);
811 g_object_unref (proc);
814 static void
815 test_communicate_utf8_async (void)
817 GError *error = NULL;
818 GPtrArray *args;
819 TestAsyncCommunicateData data = { 0, };
820 GSubprocess *proc;
821 GCancellable *cancellable = NULL;
823 args = get_test_subprocess_args ("cat", NULL);
824 proc = g_subprocess_newv ((const gchar* const*)args->pdata,
825 G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE,
826 &error);
827 g_assert_no_error (error);
828 g_ptr_array_free (args, TRUE);
830 data.is_utf8 = TRUE;
831 g_subprocess_communicate_utf8_async (proc, "hello world",
832 cancellable,
833 on_communicate_complete,
834 &data);
836 data.running = TRUE;
837 while (data.running)
838 g_main_context_iteration (NULL, TRUE);
840 g_assert_no_error (data.error);
842 g_object_unref (proc);
845 static void
846 test_communicate_utf8 (void)
848 GError *error = NULL;
849 GPtrArray *args;
850 GSubprocess *proc;
851 GCancellable *cancellable = NULL;
852 const gchar *stdin_buf;
853 gchar *stdout_buf;
855 args = get_test_subprocess_args ("cat", NULL);
856 proc = g_subprocess_newv ((const gchar* const*)args->pdata,
857 G_SUBPROCESS_FLAGS_STDIN_PIPE
858 | G_SUBPROCESS_FLAGS_STDOUT_PIPE
859 | G_SUBPROCESS_FLAGS_STDERR_MERGE,
860 &error);
861 g_assert_no_error (error);
862 g_ptr_array_free (args, TRUE);
864 stdin_buf = "hello world";
866 g_subprocess_communicate_utf8 (proc, stdin_buf, cancellable, &stdout_buf, NULL, &error);
867 g_assert_no_error (error);
869 g_assert (strcmp (stdout_buf, "hello world") == 0);
870 g_free (stdout_buf);
872 g_object_unref (proc);
875 static void
876 test_communicate_nothing (void)
878 GError *error = NULL;
879 GPtrArray *args;
880 GSubprocess *proc;
881 GCancellable *cancellable = NULL;
882 gchar *stdout_buf;
884 args = get_test_subprocess_args ("cat", NULL);
885 proc = g_subprocess_newv ((const gchar* const*)args->pdata,
886 G_SUBPROCESS_FLAGS_STDIN_PIPE
887 | G_SUBPROCESS_FLAGS_STDOUT_PIPE
888 | G_SUBPROCESS_FLAGS_STDERR_MERGE,
889 &error);
890 g_assert_no_error (error);
891 g_ptr_array_free (args, TRUE);
893 g_subprocess_communicate_utf8 (proc, "", cancellable, &stdout_buf, NULL, &error);
894 g_assert_no_error (error);
896 g_assert_cmpstr (stdout_buf, ==, "");
898 g_free (stdout_buf);
900 g_object_unref (proc);
903 static void
904 test_communicate_utf8_invalid (void)
906 GError *error = NULL;
907 GPtrArray *args;
908 TestAsyncCommunicateData data = { 0, };
909 GSubprocess *proc;
910 GCancellable *cancellable = NULL;
912 args = get_test_subprocess_args ("cat", NULL);
913 proc = g_subprocess_newv ((const gchar* const*)args->pdata,
914 G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE,
915 &error);
916 g_assert_no_error (error);
917 g_ptr_array_free (args, TRUE);
919 data.is_utf8 = TRUE;
920 g_subprocess_communicate_utf8_async (proc, "\xFF\xFF",
921 cancellable,
922 on_communicate_complete,
923 &data);
925 data.running = TRUE;
926 while (data.running)
927 g_main_context_iteration (NULL, TRUE);
929 g_assert_error (data.error, G_IO_ERROR, G_IO_ERROR_FAILED);
930 g_error_free (data.error);
932 g_object_unref (proc);
935 static gboolean
936 send_terminate (gpointer user_data)
938 GSubprocess *proc = user_data;
940 g_subprocess_force_exit (proc);
942 return FALSE;
945 static void
946 on_request_quit_exited (GObject *object,
947 GAsyncResult *result,
948 gpointer user_data)
950 GSubprocess *subprocess = G_SUBPROCESS (object);
951 GError *error = NULL;
953 g_subprocess_wait_finish (subprocess, result, &error);
954 g_assert_no_error (error);
955 #ifdef G_OS_UNIX
956 g_assert (g_subprocess_get_if_signaled (subprocess));
957 g_assert (g_subprocess_get_term_sig (subprocess) == 9);
958 #endif
959 g_spawn_check_exit_status (g_subprocess_get_status (subprocess), &error);
960 g_assert (error != NULL);
961 g_clear_error (&error);
963 g_main_loop_quit ((GMainLoop*)user_data);
966 static void
967 test_terminate (void)
969 GError *local_error = NULL;
970 GError **error = &local_error;
971 GSubprocess *proc;
972 GPtrArray *args;
973 GMainLoop *loop;
975 args = get_test_subprocess_args ("sleep-forever", NULL);
976 proc = g_subprocess_newv ((const gchar * const *) args->pdata, G_SUBPROCESS_FLAGS_NONE, error);
977 g_ptr_array_free (args, TRUE);
978 g_assert_no_error (local_error);
980 loop = g_main_loop_new (NULL, TRUE);
982 g_subprocess_wait_async (proc, NULL, on_request_quit_exited, loop);
984 g_timeout_add_seconds (3, send_terminate, proc);
986 g_main_loop_run (loop);
988 g_main_loop_unref (loop);
989 g_object_unref (proc);
992 #ifdef G_OS_UNIX
993 static gboolean
994 send_signal (gpointer user_data)
996 GSubprocess *proc = user_data;
998 g_subprocess_send_signal (proc, SIGKILL);
1000 return FALSE;
1003 static void
1004 test_signal (void)
1006 GError *local_error = NULL;
1007 GError **error = &local_error;
1008 GSubprocess *proc;
1009 GPtrArray *args;
1010 GMainLoop *loop;
1012 args = get_test_subprocess_args ("sleep-forever", NULL);
1013 proc = g_subprocess_newv ((const gchar * const *) args->pdata, G_SUBPROCESS_FLAGS_NONE, error);
1014 g_ptr_array_free (args, TRUE);
1015 g_assert_no_error (local_error);
1017 loop = g_main_loop_new (NULL, TRUE);
1019 g_subprocess_wait_async (proc, NULL, on_request_quit_exited, loop);
1021 g_timeout_add_seconds (3, send_signal, proc);
1023 g_main_loop_run (loop);
1025 g_main_loop_unref (loop);
1026 g_object_unref (proc);
1028 #endif
1030 static void
1031 test_env (void)
1033 GError *local_error = NULL;
1034 GError **error = &local_error;
1035 GSubprocessLauncher *launcher;
1036 GSubprocess *proc;
1037 GPtrArray *args;
1038 GInputStream *stdout;
1039 gchar *result;
1040 gchar *envp[] = { "ONE=1", "TWO=1", "THREE=3", "FOUR=1", NULL };
1041 gchar **split;
1043 args = get_test_subprocess_args ("env", NULL);
1044 launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE);
1045 g_subprocess_launcher_set_flags (launcher, G_SUBPROCESS_FLAGS_STDOUT_PIPE);
1046 g_subprocess_launcher_set_environ (launcher, envp);
1047 g_subprocess_launcher_setenv (launcher, "TWO", "2", TRUE);
1048 g_subprocess_launcher_setenv (launcher, "THREE", "1", FALSE);
1049 g_subprocess_launcher_unsetenv (launcher, "FOUR");
1051 g_assert_null (g_subprocess_launcher_getenv (launcher, "FOUR"));
1053 proc = g_subprocess_launcher_spawn (launcher, error, args->pdata[0], "env", NULL);
1054 g_ptr_array_free (args, TRUE);
1055 g_assert_no_error (local_error);
1057 stdout = g_subprocess_get_stdout_pipe (proc);
1059 result = splice_to_string (stdout, error);
1060 split = g_strsplit (result, "\n", -1);
1061 g_assert_cmpstr (g_environ_getenv (split, "ONE"), ==, "1");
1062 g_assert_cmpstr (g_environ_getenv (split, "TWO"), ==, "2");
1063 g_assert_cmpstr (g_environ_getenv (split, "THREE"), ==, "3");
1064 g_assert_null (g_environ_getenv (split, "FOUR"));
1066 g_strfreev (split);
1067 g_free (result);
1068 g_object_unref (proc);
1069 g_object_unref (launcher);
1072 /* Test that explicitly inheriting and modifying the parent process’
1073 * environment works. */
1074 static void
1075 test_env_inherit (void)
1077 GError *local_error = NULL;
1078 GError **error = &local_error;
1079 GSubprocessLauncher *launcher;
1080 GSubprocess *proc;
1081 GPtrArray *args;
1082 GInputStream *stdout;
1083 gchar *result;
1084 gchar **split;
1086 g_setenv ("TEST_ENV_INHERIT1", "1", TRUE);
1087 g_setenv ("TEST_ENV_INHERIT2", "2", TRUE);
1089 args = get_test_subprocess_args ("env", NULL);
1090 launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE);
1091 g_subprocess_launcher_set_flags (launcher, G_SUBPROCESS_FLAGS_STDOUT_PIPE);
1092 g_subprocess_launcher_set_environ (launcher, NULL);
1093 g_subprocess_launcher_setenv (launcher, "TWO", "2", TRUE);
1094 g_subprocess_launcher_unsetenv (launcher, "TEST_ENV_INHERIT1");
1096 g_assert_null (g_subprocess_launcher_getenv (launcher, "TEST_ENV_INHERIT1"));
1097 g_assert_cmpstr (g_subprocess_launcher_getenv (launcher, "TEST_ENV_INHERIT2"), ==, "2");
1098 g_assert_cmpstr (g_subprocess_launcher_getenv (launcher, "TWO"), ==, "2");
1100 proc = g_subprocess_launcher_spawn (launcher, error, args->pdata[0], "env", NULL);
1101 g_ptr_array_free (args, TRUE);
1102 g_assert_no_error (local_error);
1104 stdout = g_subprocess_get_stdout_pipe (proc);
1106 result = splice_to_string (stdout, error);
1107 split = g_strsplit (result, "\n", -1);
1108 g_assert_null (g_environ_getenv (split, "TEST_ENV_INHERIT1"));
1109 g_assert_cmpstr (g_environ_getenv (split, "TEST_ENV_INHERIT2"), ==, "2");
1110 g_assert_cmpstr (g_environ_getenv (split, "TWO"), ==, "2");
1112 g_strfreev (split);
1113 g_free (result);
1114 g_object_unref (proc);
1115 g_object_unref (launcher);
1118 static void
1119 test_cwd (void)
1121 GError *local_error = NULL;
1122 GError **error = &local_error;
1123 GSubprocessLauncher *launcher;
1124 GSubprocess *proc;
1125 GPtrArray *args;
1126 GInputStream *stdout;
1127 gchar *result;
1128 const char *basename;
1130 args = get_test_subprocess_args ("cwd", NULL);
1131 launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE);
1132 g_subprocess_launcher_set_flags (launcher, G_SUBPROCESS_FLAGS_STDOUT_PIPE);
1133 g_subprocess_launcher_set_cwd (launcher, "/tmp");
1135 proc = g_subprocess_launcher_spawnv (launcher, (const char * const *)args->pdata, error);
1136 g_ptr_array_free (args, TRUE);
1137 g_assert_no_error (local_error);
1139 stdout = g_subprocess_get_stdout_pipe (proc);
1141 result = splice_to_string (stdout, error);
1143 basename = g_strrstr (result, "/");
1144 g_assert (basename != NULL);
1145 g_assert_cmpstr (basename, ==, "/tmp" LINEEND);
1147 g_free (result);
1148 g_object_unref (proc);
1149 g_object_unref (launcher);
1151 #ifdef G_OS_UNIX
1152 static void
1153 test_stdout_file (void)
1155 GError *local_error = NULL;
1156 GError **error = &local_error;
1157 GSubprocessLauncher *launcher;
1158 GSubprocess *proc;
1159 GPtrArray *args;
1160 GFile *tmpfile;
1161 GFileIOStream *iostream;
1162 GOutputStream *stdin;
1163 const char *test_data = "this is some test data\n";
1164 char *tmp_contents;
1165 char *tmp_file_path;
1167 tmpfile = g_file_new_tmp ("gsubprocessXXXXXX", &iostream, error);
1168 g_assert_no_error (local_error);
1169 g_clear_object (&iostream);
1171 tmp_file_path = g_file_get_path (tmpfile);
1173 args = get_test_subprocess_args ("cat", NULL);
1174 launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDIN_PIPE);
1175 g_subprocess_launcher_set_stdout_file_path (launcher, tmp_file_path);
1176 proc = g_subprocess_launcher_spawnv (launcher, (const gchar * const *) args->pdata, error);
1177 g_ptr_array_free (args, TRUE);
1178 g_assert_no_error (local_error);
1180 stdin = g_subprocess_get_stdin_pipe (proc);
1182 g_output_stream_write_all (stdin, test_data, strlen (test_data), NULL, NULL, error);
1183 g_assert_no_error (local_error);
1185 g_output_stream_close (stdin, NULL, error);
1186 g_assert_no_error (local_error);
1188 g_subprocess_wait_check (proc, NULL, error);
1190 g_object_unref (launcher);
1191 g_object_unref (proc);
1193 g_file_load_contents (tmpfile, NULL, &tmp_contents, NULL, NULL, error);
1194 g_assert_no_error (local_error);
1196 g_assert_cmpstr (test_data, ==, tmp_contents);
1197 g_free (tmp_contents);
1199 (void) g_file_delete (tmpfile, NULL, NULL);
1200 g_object_unref (tmpfile);
1201 g_free (tmp_file_path);
1204 static void
1205 test_stdout_fd (void)
1207 GError *local_error = NULL;
1208 GError **error = &local_error;
1209 GSubprocessLauncher *launcher;
1210 GSubprocess *proc;
1211 GPtrArray *args;
1212 GFile *tmpfile;
1213 GFileIOStream *iostream;
1214 GFileDescriptorBased *descriptor_stream;
1215 GOutputStream *stdin;
1216 const char *test_data = "this is some test data\n";
1217 char *tmp_contents;
1219 tmpfile = g_file_new_tmp ("gsubprocessXXXXXX", &iostream, error);
1220 g_assert_no_error (local_error);
1222 args = get_test_subprocess_args ("cat", NULL);
1223 launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDIN_PIPE);
1224 descriptor_stream = G_FILE_DESCRIPTOR_BASED (g_io_stream_get_output_stream (G_IO_STREAM (iostream)));
1225 g_subprocess_launcher_take_stdout_fd (launcher, dup (g_file_descriptor_based_get_fd (descriptor_stream)));
1226 proc = g_subprocess_launcher_spawnv (launcher, (const gchar * const *) args->pdata, error);
1227 g_ptr_array_free (args, TRUE);
1228 g_assert_no_error (local_error);
1230 g_clear_object (&iostream);
1232 stdin = g_subprocess_get_stdin_pipe (proc);
1234 g_output_stream_write_all (stdin, test_data, strlen (test_data), NULL, NULL, error);
1235 g_assert_no_error (local_error);
1237 g_output_stream_close (stdin, NULL, error);
1238 g_assert_no_error (local_error);
1240 g_subprocess_wait_check (proc, NULL, error);
1242 g_object_unref (launcher);
1243 g_object_unref (proc);
1245 g_file_load_contents (tmpfile, NULL, &tmp_contents, NULL, NULL, error);
1246 g_assert_no_error (local_error);
1248 g_assert_cmpstr (test_data, ==, tmp_contents);
1249 g_free (tmp_contents);
1251 (void) g_file_delete (tmpfile, NULL, NULL);
1252 g_object_unref (tmpfile);
1255 static void
1256 child_setup (gpointer user_data)
1258 dup2 (GPOINTER_TO_INT (user_data), 1);
1261 static void
1262 test_child_setup (void)
1264 GError *local_error = NULL;
1265 GError **error = &local_error;
1266 GSubprocessLauncher *launcher;
1267 GSubprocess *proc;
1268 GPtrArray *args;
1269 GFile *tmpfile;
1270 GFileIOStream *iostream;
1271 GOutputStream *stdin;
1272 const char *test_data = "this is some test data\n";
1273 char *tmp_contents;
1274 int fd;
1276 tmpfile = g_file_new_tmp ("gsubprocessXXXXXX", &iostream, error);
1277 g_assert_no_error (local_error);
1279 fd = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (g_io_stream_get_output_stream (G_IO_STREAM (iostream))));
1281 args = get_test_subprocess_args ("cat", NULL);
1282 launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDIN_PIPE);
1283 g_subprocess_launcher_set_child_setup (launcher, child_setup, GINT_TO_POINTER (fd), NULL);
1284 proc = g_subprocess_launcher_spawnv (launcher, (const gchar * const *) args->pdata, error);
1285 g_ptr_array_free (args, TRUE);
1286 g_assert_no_error (local_error);
1288 g_clear_object (&iostream);
1290 stdin = g_subprocess_get_stdin_pipe (proc);
1292 g_output_stream_write_all (stdin, test_data, strlen (test_data), NULL, NULL, error);
1293 g_assert_no_error (local_error);
1295 g_output_stream_close (stdin, NULL, error);
1296 g_assert_no_error (local_error);
1298 g_subprocess_wait_check (proc, NULL, error);
1300 g_object_unref (launcher);
1301 g_object_unref (proc);
1303 g_file_load_contents (tmpfile, NULL, &tmp_contents, NULL, NULL, error);
1304 g_assert_no_error (local_error);
1306 g_assert_cmpstr (test_data, ==, tmp_contents);
1307 g_free (tmp_contents);
1309 (void) g_file_delete (tmpfile, NULL, NULL);
1310 g_object_unref (tmpfile);
1313 static void
1314 test_pass_fd (void)
1316 GError *local_error = NULL;
1317 GError **error = &local_error;
1318 GInputStream *child_input;
1319 GDataInputStream *child_datainput;
1320 GSubprocessLauncher *launcher;
1321 GSubprocess *proc;
1322 GPtrArray *args;
1323 int basic_pipefds[2];
1324 int needdup_pipefds[2];
1325 char *buf;
1326 gsize len;
1327 char *basic_fd_str;
1328 char *needdup_fd_str;
1330 g_unix_open_pipe (basic_pipefds, FD_CLOEXEC, error);
1331 g_assert_no_error (local_error);
1332 g_unix_open_pipe (needdup_pipefds, FD_CLOEXEC, error);
1333 g_assert_no_error (local_error);
1335 basic_fd_str = g_strdup_printf ("%d", basic_pipefds[1]);
1336 needdup_fd_str = g_strdup_printf ("%d", needdup_pipefds[1] + 1);
1338 args = get_test_subprocess_args ("write-to-fds", basic_fd_str, needdup_fd_str, NULL);
1339 launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE);
1340 g_subprocess_launcher_take_fd (launcher, basic_pipefds[1], basic_pipefds[1]);
1341 g_subprocess_launcher_take_fd (launcher, needdup_pipefds[1], needdup_pipefds[1] + 1);
1342 proc = g_subprocess_launcher_spawnv (launcher, (const gchar * const *) args->pdata, error);
1343 g_ptr_array_free (args, TRUE);
1344 g_assert_no_error (local_error);
1346 g_free (basic_fd_str);
1347 g_free (needdup_fd_str);
1349 child_input = g_unix_input_stream_new (basic_pipefds[0], TRUE);
1350 child_datainput = g_data_input_stream_new (child_input);
1351 buf = g_data_input_stream_read_line_utf8 (child_datainput, &len, NULL, error);
1352 g_assert_no_error (local_error);
1353 g_assert_cmpstr (buf, ==, "hello world");
1354 g_object_unref (child_datainput);
1355 g_object_unref (child_input);
1356 g_free (buf);
1358 child_input = g_unix_input_stream_new (needdup_pipefds[0], TRUE);
1359 child_datainput = g_data_input_stream_new (child_input);
1360 buf = g_data_input_stream_read_line_utf8 (child_datainput, &len, NULL, error);
1361 g_assert_no_error (local_error);
1362 g_assert_cmpstr (buf, ==, "hello world");
1363 g_free (buf);
1364 g_object_unref (child_datainput);
1365 g_object_unref (child_input);
1367 g_object_unref (launcher);
1368 g_object_unref (proc);
1371 #endif
1373 static void
1374 test_launcher_environment (void)
1376 GSubprocessLauncher *launcher;
1377 GError *error = NULL;
1378 GSubprocess *proc;
1379 GPtrArray *args;
1380 gchar *out;
1382 g_setenv ("A", "B", TRUE);
1383 g_setenv ("C", "D", TRUE);
1385 launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE);
1387 /* unset a variable */
1388 g_subprocess_launcher_unsetenv (launcher, "A");
1390 /* and set a diffferent one */
1391 g_subprocess_launcher_setenv (launcher, "E", "F", TRUE);
1393 args = get_test_subprocess_args ("printenv", "A", "C", "E", NULL);
1394 proc = g_subprocess_launcher_spawnv (launcher, (const gchar **) args->pdata, &error);
1395 g_assert_no_error (error);
1396 g_assert (proc);
1398 g_subprocess_communicate_utf8 (proc, NULL, NULL, &out, NULL, &error);
1399 g_assert_no_error (error);
1401 g_assert_cmpstr (out, ==, "C=D\nE=F\n");
1402 g_free (out);
1404 g_object_unref (proc);
1405 g_object_unref (launcher);
1406 g_ptr_array_unref (args);
1410 main (int argc, char **argv)
1412 g_test_init (&argc, &argv, NULL);
1413 g_test_bug_base ("https://bugzilla.gnome.org/");
1415 g_test_add_func ("/gsubprocess/noop", test_noop);
1416 g_test_add_func ("/gsubprocess/noop-all-to-null", test_noop_all_to_null);
1417 g_test_add_func ("/gsubprocess/noop-no-wait", test_noop_no_wait);
1418 g_test_add_func ("/gsubprocess/noop-stdin-inherit", test_noop_stdin_inherit);
1419 #ifdef G_OS_UNIX
1420 g_test_add_func ("/gsubprocess/search-path", test_search_path);
1421 g_test_add_func ("/gsubprocess/signal", test_signal);
1422 #endif
1423 g_test_add_func ("/gsubprocess/exit1", test_exit1);
1424 g_test_add_func ("/gsubprocess/exit1/cancel", test_exit1_cancel);
1425 g_test_add_func ("/gsubprocess/exit1/cancel_in_cb", test_exit1_cancel_in_cb);
1426 g_test_add_func ("/gsubprocess/echo1", test_echo1);
1427 #ifdef G_OS_UNIX
1428 g_test_add_func ("/gsubprocess/echo-merged", test_echo_merged);
1429 #endif
1430 g_test_add_func ("/gsubprocess/cat-utf8", test_cat_utf8);
1431 g_test_add_func ("/gsubprocess/cat-eof", test_cat_eof);
1432 g_test_add_func ("/gsubprocess/multi1", test_multi_1);
1433 g_test_add_func ("/gsubprocess/communicate", test_communicate);
1434 g_test_add_func ("/gsubprocess/communicate-async", test_communicate_async);
1435 g_test_add_func ("/gsubprocess/communicate-utf8", test_communicate_utf8);
1436 g_test_add_func ("/gsubprocess/communicate-utf8-async", test_communicate_utf8_async);
1437 g_test_add_func ("/gsubprocess/communicate-utf8-invalid", test_communicate_utf8_invalid);
1438 g_test_add_func ("/gsubprocess/communicate-nothing", test_communicate_nothing);
1439 g_test_add_func ("/gsubprocess/terminate", test_terminate);
1440 g_test_add_func ("/gsubprocess/env", test_env);
1441 g_test_add_func ("/gsubprocess/env/inherit", test_env_inherit);
1442 g_test_add_func ("/gsubprocess/cwd", test_cwd);
1443 #ifdef G_OS_UNIX
1444 g_test_add_func ("/gsubprocess/stdout-file", test_stdout_file);
1445 g_test_add_func ("/gsubprocess/stdout-fd", test_stdout_fd);
1446 g_test_add_func ("/gsubprocess/child-setup", test_child_setup);
1447 g_test_add_func ("/gsubprocess/pass-fd", test_pass_fd);
1448 #endif
1449 g_test_add_func ("/gsubprocess/launcher-environment", test_launcher_environment);
1451 return g_test_run ();