mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-05-21 04:52:11 +02:00
win32: add pipe-io-cancel-test
Test that win32 streams can be cancelled. It can even be tested with wine on Linux! https://bugzilla.gnome.org/show_bug.cgi?id=679288
This commit is contained in:
parent
b9b2cf6a66
commit
d9f6314f57
@ -27,6 +27,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
@ -466,6 +467,60 @@ test_pipe_io_concurrent (void)
|
|||||||
close (writer_pipe[1]);
|
close (writer_pipe[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
readable_cancel (GObject *source, GAsyncResult *res, gpointer user_data)
|
||||||
|
{
|
||||||
|
GInputStream *in = G_INPUT_STREAM (source);
|
||||||
|
GError *err = NULL;
|
||||||
|
gssize len;
|
||||||
|
|
||||||
|
len = g_input_stream_read_finish (in, res, &err);
|
||||||
|
g_assert_cmpint (len, ==, -1);
|
||||||
|
g_assert_error (err, G_IO_ERROR, G_IO_ERROR_CANCELLED);
|
||||||
|
g_error_free (err);
|
||||||
|
|
||||||
|
g_main_loop_quit (loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_pipe_io_cancel (void)
|
||||||
|
{
|
||||||
|
GInputStream *in;
|
||||||
|
GOutputStream *out;
|
||||||
|
HANDLE in_handle, out_handle;
|
||||||
|
gchar name[256];
|
||||||
|
|
||||||
|
g_snprintf (name, sizeof (name),
|
||||||
|
"\\\\.\\pipe\\gtest-io-cancel-%u", (guint) getpid ());
|
||||||
|
|
||||||
|
in_handle = CreateNamedPipe (name,
|
||||||
|
PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
|
||||||
|
PIPE_READMODE_BYTE | PIPE_WAIT,
|
||||||
|
1, 0, 0, 0, NULL);
|
||||||
|
g_assert (in_handle != INVALID_HANDLE_VALUE);
|
||||||
|
|
||||||
|
out_handle = CreateFile (name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||||
|
g_assert (out_handle != INVALID_HANDLE_VALUE);
|
||||||
|
|
||||||
|
in = g_win32_input_stream_new (in_handle, TRUE);
|
||||||
|
out = g_win32_output_stream_new (out_handle, TRUE);
|
||||||
|
|
||||||
|
reader_cancel = g_cancellable_new ();
|
||||||
|
g_input_stream_read_async (in, main_buf, sizeof (main_buf),
|
||||||
|
G_PRIORITY_DEFAULT, reader_cancel,
|
||||||
|
readable_cancel, out);
|
||||||
|
|
||||||
|
g_timeout_add (500, timeout, reader_cancel);
|
||||||
|
|
||||||
|
loop = g_main_loop_new (NULL, TRUE);
|
||||||
|
g_main_loop_run (loop);
|
||||||
|
g_main_loop_unref (loop);
|
||||||
|
|
||||||
|
g_object_unref (reader_cancel);
|
||||||
|
g_object_unref (in);
|
||||||
|
g_object_unref (out);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
@ -474,6 +529,7 @@ main (int argc,
|
|||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
g_test_add_func ("/win32-streams/pipe-io-test", test_pipe_io);
|
g_test_add_func ("/win32-streams/pipe-io-test", test_pipe_io);
|
||||||
|
g_test_add_func ("/win32-streams/pipe-io-cancel-test", test_pipe_io_cancel);
|
||||||
g_test_add_func ("/win32-streams/pipe-io-overlap-test", test_pipe_io_overlap);
|
g_test_add_func ("/win32-streams/pipe-io-overlap-test", test_pipe_io_overlap);
|
||||||
g_test_add_func ("/win32-streams/pipe-io-concurrent-test", test_pipe_io_concurrent);
|
g_test_add_func ("/win32-streams/pipe-io-concurrent-test", test_pipe_io_concurrent);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user