[Spice-devel] [spice-gtk v3 16/16] tests: file-transfer agent send error/cancel

Victor Toso victortoso at redhat.com
Mon May 30 09:55:12 UTC 2016


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.
---
 tests/file-transfer.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/tests/file-transfer.c b/tests/file-transfer.c
index be4d585..23f7d42 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();
 }
-- 
2.5.5



More information about the Spice-devel mailing list