[glib: 3/4] gsubprocess: Add a missing test for invalid UTF-8 output
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 3/4] gsubprocess: Add a missing test for invalid UTF-8 output
- Date: Wed, 19 Dec 2018 13:15:32 +0000 (UTC)
commit 19c7a7bb233fbe7138d535ac4a2354772edc6486
Author: Philip Withnall <withnall endlessm com>
Date: Thu Oct 11 11:29:17 2018 +1300
gsubprocess: Add a missing test for invalid UTF-8 output
There were tests for invalid UTF-8 output when asynchronously
communicating with a subprocess, but nothing for synchronous
communication. Add such a test, and refine the code as a result.
Signed-off-by: Philip Withnall <withnall endlessm com>
gio/tests/gsubprocess.c | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
---
diff --git a/gio/tests/gsubprocess.c b/gio/tests/gsubprocess.c
index f617bc599..431828384 100644
--- a/gio/tests/gsubprocess.c
+++ b/gio/tests/gsubprocess.c
@@ -1190,7 +1190,7 @@ test_communicate_nothing (void)
}
static void
-test_communicate_utf8_invalid (void)
+test_communicate_utf8_async_invalid (void)
{
GSubprocessFlags flags = G_SUBPROCESS_FLAGS_STDOUT_PIPE;
GError *error = NULL;
@@ -1222,6 +1222,37 @@ test_communicate_utf8_invalid (void)
g_object_unref (proc);
}
+/* Test that invalid UTF-8 received using g_subprocess_communicate_utf8()
+ * results in an error. */
+static void
+test_communicate_utf8_invalid (void)
+{
+ GSubprocessFlags flags = G_SUBPROCESS_FLAGS_STDOUT_PIPE;
+ GError *local_error = NULL;
+ gboolean ret;
+ GPtrArray *args;
+ gchar *stdout_str = NULL, *stderr_str = NULL;
+ GSubprocess *proc;
+
+ args = get_test_subprocess_args ("cat", NULL);
+ proc = g_subprocess_newv ((const gchar* const*)args->pdata,
+ G_SUBPROCESS_FLAGS_STDIN_PIPE | flags,
+ &local_error);
+ g_assert_no_error (local_error);
+ g_ptr_array_free (args, TRUE);
+
+ ret = g_subprocess_communicate_utf8 (proc, "\xFF\xFF", NULL,
+ &stdout_str, &stderr_str, &local_error);
+ g_assert_error (local_error, G_IO_ERROR, G_IO_ERROR_FAILED);
+ g_error_free (local_error);
+ g_assert_false (ret);
+
+ g_assert_null (stdout_str);
+ g_assert_null (stderr_str);
+
+ g_object_unref (proc);
+}
+
static gboolean
send_terminate (gpointer user_data)
{
@@ -1783,6 +1814,7 @@ main (int argc, char **argv)
g_free (test_path);
}
+ g_test_add_func ("/gsubprocess/communicate/utf8/async/invalid", test_communicate_utf8_async_invalid);
g_test_add_func ("/gsubprocess/communicate/utf8/invalid", test_communicate_utf8_invalid);
g_test_add_func ("/gsubprocess/communicate/nothing", test_communicate_nothing);
g_test_add_func ("/gsubprocess/terminate", test_terminate);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]