mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
GSubprocess test: Use LINEEND more
Windows \r\n EOLs strike again. The test already knows about LINEEND, so make it use LINEEND more (instead of swithcing pipes to binary mode). This also applies to counting the bytes read.
This commit is contained in:
parent
16dc979d0e
commit
01642d6db5
@ -8,12 +8,20 @@
|
||||
#include <gio/gfiledescriptorbased.h>
|
||||
#endif
|
||||
|
||||
/* We write 2^1 + 2^2 ... + 2^10 or 2047 copies of "Hello World!\n"
|
||||
* ultimately
|
||||
*/
|
||||
#define TOTAL_HELLOS 2047
|
||||
#define HELLO_WORLD "hello world!\n"
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
#define LINEEND "\r\n"
|
||||
#define EXEEXT ".exe"
|
||||
#define SPLICELEN (TOTAL_HELLOS * (strlen (HELLO_WORLD) + 1)) /* because \r */
|
||||
#else
|
||||
#define LINEEND "\n"
|
||||
#define EXEEXT
|
||||
#define SPLICELEN (TOTAL_HELLOS * strlen (HELLO_WORLD))
|
||||
#endif
|
||||
|
||||
static GPtrArray *
|
||||
@ -557,10 +565,7 @@ on_idle_multisplice (gpointer user_data)
|
||||
{
|
||||
TestMultiSpliceData *data = user_data;
|
||||
|
||||
/* We write 2^1 + 2^2 ... + 2^10 or 2047 copies of "Hello World!\n"
|
||||
* ultimately
|
||||
*/
|
||||
if (data->counter >= 2047 || data->caught_error)
|
||||
if (data->counter >= TOTAL_HELLOS || data->caught_error)
|
||||
{
|
||||
if (!g_output_stream_close (data->first_stdin, NULL, &data->error))
|
||||
data->caught_error = TRUE;
|
||||
@ -577,8 +582,8 @@ on_idle_multisplice (gpointer user_data)
|
||||
for (i = 0; i < data->counter; i++)
|
||||
{
|
||||
gsize bytes_written;
|
||||
if (!g_output_stream_write_all (data->first_stdin, "hello world!\n",
|
||||
strlen ("hello world!\n"), &bytes_written,
|
||||
if (!g_output_stream_write_all (data->first_stdin, HELLO_WORLD,
|
||||
strlen (HELLO_WORLD), &bytes_written,
|
||||
NULL, &data->error))
|
||||
{
|
||||
data->caught_error = TRUE;
|
||||
@ -684,7 +689,7 @@ test_multi_1 (void)
|
||||
g_assert (!data.caught_error);
|
||||
g_assert_no_error (data.error);
|
||||
|
||||
g_assert_cmpint (g_memory_output_stream_get_data_size ((GMemoryOutputStream*)membuf), ==, 26611);
|
||||
g_assert_cmpint (g_memory_output_stream_get_data_size ((GMemoryOutputStream*)membuf), ==, SPLICELEN);
|
||||
|
||||
g_main_loop_unref (data.loop);
|
||||
g_object_unref (membuf);
|
||||
@ -732,7 +737,7 @@ on_communicate_complete (GObject *proc,
|
||||
else
|
||||
stdout_data = g_bytes_get_data (stdout_bytes, &stdout_len);
|
||||
|
||||
g_assert_cmpmem (stdout_data, stdout_len, "# hello world\n", 14);
|
||||
g_assert_cmpmem (stdout_data, stdout_len, "# hello world" LINEEND, 13 + strlen (LINEEND));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -834,7 +839,7 @@ test_communicate (gconstpointer test_data)
|
||||
if (flags & G_SUBPROCESS_FLAGS_STDOUT_PIPE)
|
||||
{
|
||||
stdout_data = g_bytes_get_data (stdout_bytes, &stdout_len);
|
||||
g_assert_cmpmem (stdout_data, stdout_len, "# hello world\n", 14);
|
||||
g_assert_cmpmem (stdout_data, stdout_len, "# hello world" LINEEND, 13 + strlen (LINEEND));
|
||||
}
|
||||
else
|
||||
g_assert_null (stdout_bytes);
|
||||
@ -1110,7 +1115,7 @@ test_communicate_utf8 (gconstpointer test_data)
|
||||
g_assert_no_error (error);
|
||||
|
||||
if (flags & G_SUBPROCESS_FLAGS_STDOUT_PIPE)
|
||||
g_assert_cmpstr (stdout_buf, ==, "# hello world\n");
|
||||
g_assert_cmpstr (stdout_buf, ==, "# hello world" LINEEND);
|
||||
else
|
||||
g_assert_null (stdout_buf);
|
||||
if (flags & G_SUBPROCESS_FLAGS_STDERR_PIPE)
|
||||
@ -1378,7 +1383,7 @@ test_env (void)
|
||||
stdout_stream = g_subprocess_get_stdout_pipe (proc);
|
||||
|
||||
result = splice_to_string (stdout_stream, error);
|
||||
split = g_strsplit (result, "\n", -1);
|
||||
split = g_strsplit (result, LINEEND, -1);
|
||||
g_assert_cmpstr (g_environ_getenv (split, "ONE"), ==, "1");
|
||||
g_assert_cmpstr (g_environ_getenv (split, "TWO"), ==, "2");
|
||||
g_assert_cmpstr (g_environ_getenv (split, "THREE"), ==, "3");
|
||||
@ -1425,7 +1430,7 @@ test_env_inherit (void)
|
||||
stdout_stream = g_subprocess_get_stdout_pipe (proc);
|
||||
|
||||
result = splice_to_string (stdout_stream, error);
|
||||
split = g_strsplit (result, "\n", -1);
|
||||
split = g_strsplit (result, LINEEND, -1);
|
||||
g_assert_null (g_environ_getenv (split, "TEST_ENV_INHERIT1"));
|
||||
g_assert_cmpstr (g_environ_getenv (split, "TEST_ENV_INHERIT2"), ==, "2");
|
||||
g_assert_cmpstr (g_environ_getenv (split, "TWO"), ==, "2");
|
||||
@ -1719,7 +1724,7 @@ test_launcher_environment (void)
|
||||
g_subprocess_communicate_utf8 (proc, NULL, NULL, &out, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
g_assert_cmpstr (out, ==, "C=D\nE=F\n");
|
||||
g_assert_cmpstr (out, ==, "C=D" LINEEND "E=F" LINEEND);
|
||||
g_free (out);
|
||||
|
||||
g_object_unref (proc);
|
||||
|
Loading…
Reference in New Issue
Block a user