Acked-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx> --- tests/file-transfer.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/tests/file-transfer.c b/tests/file-transfer.c index 67366d5..c1a7159 100644 --- a/tests/file-transfer.c +++ b/tests/file-transfer.c @@ -189,6 +189,96 @@ test_cancel_after_task_init(Fixture *f, gconstpointer user_data) g_main_loop_run (f->loop); } +/******************************************************************************* + * TEST CANCEL ON READ ASYNC + ******************************************************************************/ + +static void +transfer_cancelled_read_async_cb(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + SpiceFileTransferTask *xfer_task; + gssize count; + char *buffer; + GError *error = NULL; + + xfer_task = SPICE_FILE_TRANSFER_TASK(source_object); + count = spice_file_transfer_task_read_finish(xfer_task, res, &buffer, &error); + g_assert_error(error, G_IO_ERROR, G_IO_ERROR_CANCELLED); + g_assert_cmpint(count, ==, -1); + + transfer_xfer_task_on_finished(NULL, NULL, user_data); +} + +static void +transfer_on_init_async_cb_before_read_cancel(GObject *obj, GAsyncResult *res, gpointer data) +{ + GFileInfo *info; + SpiceFileTransferTask *xfer_task; + GError *error = NULL; + GCancellable *cancellable; + + xfer_task = SPICE_FILE_TRANSFER_TASK(obj); + info = spice_file_transfer_task_init_task_finish(xfer_task, res, &error); + g_assert_no_error(error); + g_assert_nonnull(info); + + cancellable = spice_file_transfer_task_get_cancellable(xfer_task); + g_cancellable_cancel(cancellable); + spice_file_transfer_task_read_async(xfer_task, transfer_cancelled_read_async_cb, data); +} + +static void +transfer_on_init_async_cb_after_read_cancel(GObject *obj, GAsyncResult *res, gpointer data) +{ + GFileInfo *info; + SpiceFileTransferTask *xfer_task; + GError *error = NULL; + GCancellable *cancellable; + + xfer_task = SPICE_FILE_TRANSFER_TASK(obj); + info = spice_file_transfer_task_init_task_finish(xfer_task, res, &error); + g_assert_no_error(error); + g_assert_nonnull(info); + + cancellable = spice_file_transfer_task_get_cancellable(xfer_task); + spice_file_transfer_task_read_async(xfer_task, transfer_cancelled_read_async_cb, data); + g_cancellable_cancel(cancellable); +} + +static void +test_cancel_before_read_async(Fixture *f, gconstpointer user_data) +{ + GHashTableIter iter; + gpointer key, value; + + f->xfer_tasks = spice_file_transfer_task_create_tasks(f->files, NULL, G_FILE_COPY_NONE, NULL); + g_hash_table_iter_init(&iter, f->xfer_tasks); + while (g_hash_table_iter_next(&iter, &key, &value)) { + SpiceFileTransferTask *xfer_task = SPICE_FILE_TRANSFER_TASK(value); + g_signal_connect(xfer_task, "finished", G_CALLBACK(transfer_xfer_task_on_finished), f); + spice_file_transfer_task_init_task_async(xfer_task, transfer_on_init_async_cb_before_read_cancel, f); + } + g_main_loop_run (f->loop); +} + +static void +test_cancel_after_read_async(Fixture *f, gconstpointer user_data) +{ + GHashTableIter iter; + gpointer key, value; + + f->xfer_tasks = spice_file_transfer_task_create_tasks(f->files, NULL, G_FILE_COPY_NONE, NULL); + g_hash_table_iter_init(&iter, f->xfer_tasks); + while (g_hash_table_iter_next(&iter, &key, &value)) { + SpiceFileTransferTask *xfer_task = SPICE_FILE_TRANSFER_TASK(value); + g_signal_connect(xfer_task, "finished", G_CALLBACK(transfer_xfer_task_on_finished), f); + spice_file_transfer_task_init_task_async(xfer_task, transfer_on_init_async_cb_after_read_cancel, f); + } + g_main_loop_run (f->loop); +} + /* Tests summary: * * This tests are specific to SpiceFileTransferTask in order to verify: @@ -242,6 +332,14 @@ int main(int argc, char* argv[]) Fixture, GUINT_TO_POINTER(SINGLE_FILE), f_setup, test_cancel_after_task_init, f_teardown); + g_test_add("/spice-file-transfer-task/single/cancel/before-read-async", + Fixture, GUINT_TO_POINTER(SINGLE_FILE), + f_setup, test_cancel_before_read_async, f_teardown); + + g_test_add("/spice-file-transfer-task/single/cancel/after-read-async", + Fixture, GUINT_TO_POINTER(SINGLE_FILE), + f_setup, test_cancel_after_read_async, f_teardown); + g_test_add("/spice-file-transfer-task/multiple/simple-transfer", Fixture, GUINT_TO_POINTER(MULTIPLE_FILES), f_setup, test_simple_transfer, f_teardown); @@ -254,5 +352,13 @@ int main(int argc, char* argv[]) Fixture, GUINT_TO_POINTER(MULTIPLE_FILES), f_setup, test_cancel_after_task_init, f_teardown); + g_test_add("/spice-file-transfer-task/multiple/cancel/before--read-async", + Fixture, GUINT_TO_POINTER(MULTIPLE_FILES), + f_setup, test_cancel_before_read_async, f_teardown); + + g_test_add("/spice-file-transfer-task/multiple/cancel/after-read-async", + Fixture, GUINT_TO_POINTER(MULTIPLE_FILES), + f_setup, test_cancel_after_read_async, f_teardown); + return g_test_run(); } -- 2.7.4 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel