mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 22:16:16 +01:00
gsubprocess: Fix error detection logic in tests
Various tests were depending on local_error being set by a callback when it could never have been the case. Simplify async error detection logic in those cases, and fix leak of GError. https://bugzilla.gnome.org/show_bug.cgi?id=711802
This commit is contained in:
parent
78ad171da9
commit
fe3c878c53
@ -543,7 +543,6 @@ test_multi_1 (void)
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
gboolean is_utf8;
|
gboolean is_utf8;
|
||||||
gboolean is_invalid_utf8;
|
|
||||||
gboolean running;
|
gboolean running;
|
||||||
GError *error;
|
GError *error;
|
||||||
} TestAsyncCommunicateData;
|
} TestAsyncCommunicateData;
|
||||||
@ -566,13 +565,8 @@ on_communicate_complete (GObject *proc,
|
|||||||
else
|
else
|
||||||
(void) g_subprocess_communicate_finish ((GSubprocess*)proc, result,
|
(void) g_subprocess_communicate_finish ((GSubprocess*)proc, result,
|
||||||
&stdout, NULL, &data->error);
|
&stdout, NULL, &data->error);
|
||||||
if (data->is_invalid_utf8)
|
if (data->error)
|
||||||
{
|
|
||||||
g_assert_error (data->error, G_IO_ERROR, G_IO_ERROR_FAILED);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
g_assert_no_error (data->error);
|
|
||||||
|
|
||||||
if (!data->is_utf8)
|
if (!data->is_utf8)
|
||||||
{
|
{
|
||||||
@ -594,8 +588,7 @@ on_communicate_complete (GObject *proc,
|
|||||||
static void
|
static void
|
||||||
test_communicate (void)
|
test_communicate (void)
|
||||||
{
|
{
|
||||||
GError *local_error = NULL;
|
GError *error = NULL;
|
||||||
GError **error = &local_error;
|
|
||||||
GPtrArray *args;
|
GPtrArray *args;
|
||||||
TestAsyncCommunicateData data = { 0, };
|
TestAsyncCommunicateData data = { 0, };
|
||||||
GSubprocess *proc;
|
GSubprocess *proc;
|
||||||
@ -606,14 +599,13 @@ test_communicate (void)
|
|||||||
args = get_test_subprocess_args ("cat", NULL);
|
args = get_test_subprocess_args ("cat", NULL);
|
||||||
proc = g_subprocess_newv ((const gchar* const*)args->pdata,
|
proc = g_subprocess_newv ((const gchar* const*)args->pdata,
|
||||||
G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE,
|
G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE,
|
||||||
error);
|
&error);
|
||||||
g_assert_no_error (local_error);
|
g_assert_no_error (error);
|
||||||
g_ptr_array_free (args, TRUE);
|
g_ptr_array_free (args, TRUE);
|
||||||
|
|
||||||
hellostring = "hello world";
|
hellostring = "hello world";
|
||||||
input = g_bytes_new_static (hellostring, strlen (hellostring));
|
input = g_bytes_new_static (hellostring, strlen (hellostring));
|
||||||
|
|
||||||
data.error = local_error;
|
|
||||||
g_subprocess_communicate_async (proc, input,
|
g_subprocess_communicate_async (proc, input,
|
||||||
cancellable,
|
cancellable,
|
||||||
on_communicate_complete,
|
on_communicate_complete,
|
||||||
@ -623,7 +615,7 @@ test_communicate (void)
|
|||||||
while (data.running)
|
while (data.running)
|
||||||
g_main_context_iteration (NULL, TRUE);
|
g_main_context_iteration (NULL, TRUE);
|
||||||
|
|
||||||
g_assert_no_error (local_error);
|
g_assert_no_error (data.error);
|
||||||
|
|
||||||
g_object_unref (proc);
|
g_object_unref (proc);
|
||||||
}
|
}
|
||||||
@ -631,8 +623,7 @@ test_communicate (void)
|
|||||||
static void
|
static void
|
||||||
test_communicate_utf8 (void)
|
test_communicate_utf8 (void)
|
||||||
{
|
{
|
||||||
GError *local_error = NULL;
|
GError *error = NULL;
|
||||||
GError **error = &local_error;
|
|
||||||
GPtrArray *args;
|
GPtrArray *args;
|
||||||
TestAsyncCommunicateData data = { 0, };
|
TestAsyncCommunicateData data = { 0, };
|
||||||
GSubprocess *proc;
|
GSubprocess *proc;
|
||||||
@ -641,11 +632,10 @@ test_communicate_utf8 (void)
|
|||||||
args = get_test_subprocess_args ("cat", NULL);
|
args = get_test_subprocess_args ("cat", NULL);
|
||||||
proc = g_subprocess_newv ((const gchar* const*)args->pdata,
|
proc = g_subprocess_newv ((const gchar* const*)args->pdata,
|
||||||
G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE,
|
G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE,
|
||||||
error);
|
&error);
|
||||||
g_assert_no_error (local_error);
|
g_assert_no_error (error);
|
||||||
g_ptr_array_free (args, TRUE);
|
g_ptr_array_free (args, TRUE);
|
||||||
|
|
||||||
data.error = local_error;
|
|
||||||
data.is_utf8 = TRUE;
|
data.is_utf8 = TRUE;
|
||||||
g_subprocess_communicate_utf8_async (proc, "hello world",
|
g_subprocess_communicate_utf8_async (proc, "hello world",
|
||||||
cancellable,
|
cancellable,
|
||||||
@ -656,7 +646,7 @@ test_communicate_utf8 (void)
|
|||||||
while (data.running)
|
while (data.running)
|
||||||
g_main_context_iteration (NULL, TRUE);
|
g_main_context_iteration (NULL, TRUE);
|
||||||
|
|
||||||
g_assert_no_error (local_error);
|
g_assert_no_error (data.error);
|
||||||
|
|
||||||
g_object_unref (proc);
|
g_object_unref (proc);
|
||||||
}
|
}
|
||||||
@ -664,8 +654,7 @@ test_communicate_utf8 (void)
|
|||||||
static void
|
static void
|
||||||
test_communicate_utf8_invalid (void)
|
test_communicate_utf8_invalid (void)
|
||||||
{
|
{
|
||||||
GError *local_error = NULL;
|
GError *error = NULL;
|
||||||
GError **error = &local_error;
|
|
||||||
GPtrArray *args;
|
GPtrArray *args;
|
||||||
TestAsyncCommunicateData data = { 0, };
|
TestAsyncCommunicateData data = { 0, };
|
||||||
GSubprocess *proc;
|
GSubprocess *proc;
|
||||||
@ -674,13 +663,11 @@ test_communicate_utf8_invalid (void)
|
|||||||
args = get_test_subprocess_args ("cat", NULL);
|
args = get_test_subprocess_args ("cat", NULL);
|
||||||
proc = g_subprocess_newv ((const gchar* const*)args->pdata,
|
proc = g_subprocess_newv ((const gchar* const*)args->pdata,
|
||||||
G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE,
|
G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE,
|
||||||
error);
|
&error);
|
||||||
g_assert_no_error (local_error);
|
g_assert_no_error (error);
|
||||||
g_ptr_array_free (args, TRUE);
|
g_ptr_array_free (args, TRUE);
|
||||||
|
|
||||||
data.error = local_error;
|
|
||||||
data.is_utf8 = TRUE;
|
data.is_utf8 = TRUE;
|
||||||
data.is_invalid_utf8 = TRUE;
|
|
||||||
g_subprocess_communicate_utf8_async (proc, "\xFF\xFF",
|
g_subprocess_communicate_utf8_async (proc, "\xFF\xFF",
|
||||||
cancellable,
|
cancellable,
|
||||||
on_communicate_complete,
|
on_communicate_complete,
|
||||||
@ -690,7 +677,8 @@ test_communicate_utf8_invalid (void)
|
|||||||
while (data.running)
|
while (data.running)
|
||||||
g_main_context_iteration (NULL, TRUE);
|
g_main_context_iteration (NULL, TRUE);
|
||||||
|
|
||||||
g_assert_no_error (local_error);
|
g_assert_error (data.error, G_IO_ERROR, G_IO_ERROR_FAILED);
|
||||||
|
g_error_free (data.error);
|
||||||
|
|
||||||
g_object_unref (proc);
|
g_object_unref (proc);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user