summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Toso <victortoso@redhat.com>2016-05-23 10:32:33 +0200
committerVictor Toso <victortoso@redhat.com>2016-05-30 13:20:07 +0200
commit33761c28a8ebb87102e3461bf9229cf372561d60 (patch)
treeccc67597db92d363802676eb90b4beda39c67ff4
parenta78771b28b09d80606fb6c9e5f94ad1830d032e5 (diff)
tests: file-transfer agent send error/cancelmove-xfer
Agent only can only send error or cancel from a transfer operation after it was initialized. In the context of SpiceFileTransferTask, it means that we need to test only after file-info was emitted.
-rw-r--r--tests/file-transfer.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/file-transfer.c b/tests/file-transfer.c
index 2efaba8..1e25cac 100644
--- a/tests/file-transfer.c
+++ b/tests/file-transfer.c
@@ -252,6 +252,80 @@ test_cancel_on_read_file(Fixture *f, gconstpointer user_data)
g_main_loop_run (f->loop);
}
+/*******************************************************************************
+ * TEST AGENT CANCEL ON READ
+ ******************************************************************************/
+
+static void
+transfer_flush_callback_agent_cancel(SpiceFileTransferTask *xfer_task,
+ void *buffer,
+ gssize count,
+ gpointer user_data)
+{
+ gint i;
+ Fixture *f = user_data;
+ spice_file_transfer_task_flush_done(xfer_task, NULL);
+ agent_send_cancel_async(xfer_task);
+}
+
+static void
+test_agent_cancel_on_read(Fixture *f, gconstpointer user_data)
+{
+ GList *it;
+
+ f->tasks = spice_file_transfer_task_create_tasks(NULL,
+ f->files,
+ G_FILE_COPY_NONE,
+ f->cancellable,
+ transfer_flush_callback_agent_cancel,
+ f,
+ transfer_done,
+ f);
+ for (it = f->tasks; it != NULL; it = it->next) {
+ SpiceFileTransferTask *xfer_task = SPICE_FILE_TRANSFER_TASK(it->data);
+ g_signal_connect(xfer_task, "file-info", G_CALLBACK(transfer_task_on_file_info), f);
+ spice_file_transfer_task_start_task(xfer_task);
+ }
+ g_main_loop_run (f->loop);
+}
+
+/*******************************************************************************
+ * TEST AGENT ERROR ON READ
+ ******************************************************************************/
+
+static void
+transfer_flush_callback_agent_error(SpiceFileTransferTask *xfer_task,
+ void *buffer,
+ gssize count,
+ gpointer user_data)
+{
+ gint i;
+ Fixture *f = user_data;
+ spice_file_transfer_task_flush_done(xfer_task, NULL);
+ agent_send_error_async(xfer_task);
+}
+
+static void
+test_agent_error_on_read(Fixture *f, gconstpointer user_data)
+{
+ GList *it;
+
+ f->tasks = spice_file_transfer_task_create_tasks(NULL,
+ f->files,
+ G_FILE_COPY_NONE,
+ f->cancellable,
+ transfer_flush_callback_agent_error,
+ f,
+ transfer_done,
+ f);
+ for (it = f->tasks; it != NULL; it = it->next) {
+ SpiceFileTransferTask *xfer_task = SPICE_FILE_TRANSFER_TASK(it->data);
+ g_signal_connect(xfer_task, "file-info", G_CALLBACK(transfer_task_on_file_info), f);
+ spice_file_transfer_task_start_task(xfer_task);
+ }
+ g_main_loop_run (f->loop);
+}
+
/* Tests summary:
*
* This tests are specific to SpiceFileTransferTask and how it handles the
@@ -302,6 +376,14 @@ int main(int argc, char* argv[])
Fixture, GUINT_TO_POINTER(SINGLE_FILE),
f_setup, test_cancel_on_read_file, f_teardown);
+ g_test_add("/spice-file-transfer-task/single/agent/cancel",
+ Fixture, GUINT_TO_POINTER(SINGLE_FILE),
+ f_setup, test_agent_cancel_on_read, f_teardown);
+
+ g_test_add("/spice-file-transfer-task/single/agent/error",
+ Fixture, GUINT_TO_POINTER(SINGLE_FILE),
+ f_setup, test_agent_error_on_read, 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);
@@ -318,5 +400,13 @@ int main(int argc, char* argv[])
Fixture, GUINT_TO_POINTER(MULTIPLE_FILES),
f_setup, test_cancel_on_read_file, f_teardown);
+ g_test_add("/spice-file-transfer-task/multiple/agent/cancel",
+ Fixture, GUINT_TO_POINTER(MULTIPLE_FILES),
+ f_setup, test_agent_cancel_on_read, f_teardown);
+
+ g_test_add("/spice-file-transfer-task/multiple/agent/error",
+ Fixture, GUINT_TO_POINTER(MULTIPLE_FILES),
+ f_setup, test_agent_error_on_read, f_teardown);
+
return g_test_run();
}