[Spice-devel,12/18] server/tests: refactor Command

Submitted by Yonit Halperin on May 2, 2012, 2:01 p.m.

Details

Message ID 1335967313-24747-12-git-send-email-yhalperi@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Yonit Halperin May 2, 2012, 2:01 p.m.
From: Alon Levy <alevy@redhat.com>

---
 server/tests/test_display_base.c               |   10 +++----
 server/tests/test_display_base.h               |   33 ++++++++++++++++++++---
 server/tests/test_display_resolution_changes.c |   10 +++---
 3 files changed, 37 insertions(+), 16 deletions(-)

Patch hide | download patch | download mbox

diff --git a/server/tests/test_display_base.c b/server/tests/test_display_base.c
index fd9a37e..f7b85c1 100644
--- a/server/tests/test_display_base.c
+++ b/server/tests/test_display_base.c
@@ -453,7 +453,7 @@  static void produce_command(void)
 
     command = &g_commands[cmd_index];
     if (command->cb) {
-        command->cb(command->cb_opaque, &command->arg1, &command->arg2);
+        command->cb(command);
     }
     switch (command->command) {
         case PATH_PROGRESS:
@@ -511,15 +511,13 @@  static void produce_command(void)
             break;
         }
 
-        case DESTROY_PRIMARY: {
+        case DESTROY_PRIMARY:
             qxl_worker->destroy_primary_surface(qxl_worker, 0);
             break;
-        }
 
-        case CREATE_PRIMARY: {
-            create_primary_surface(qxl_worker, command->arg1, command->arg2);
+        case CREATE_PRIMARY:
+            create_primary_surface(qxl_worker, command->create_primary.width, command->create_primary.height);
             break;
-        }
     }
     cmd_index = (cmd_index + 1) % g_num_commands;
 }
diff --git a/server/tests/test_display_base.h b/server/tests/test_display_base.h
index 6922d9b..b769721 100644
--- a/server/tests/test_display_base.h
+++ b/server/tests/test_display_base.h
@@ -23,13 +23,36 @@  typedef enum {
     DESTROY_PRIMARY,
     CREATE_PRIMARY,
 } CommandType;
-typedef struct Command {
+
+typedef struct CommandCreatePrimary {
+    uint32_t width;
+    uint32_t height;
+} CommandCreatePrimary;
+
+typedef struct CommandDrawBitmap {
+    QXLRect bbox;
+    uint8_t *bitmap;
+    uint32_t surface_id;
+} CommandDrawBitmap;
+
+typedef struct CommandDrawSolid {
+    QXLRect bbox;
+    uint32_t color;
+    uint32_t surface_id;
+} CommandDrawSolid;
+
+typedef struct Command Command;
+
+struct Command {
     CommandType command;
-    uint64_t arg1;
-    uint64_t arg2;
-    void (*cb)(void *cb_opaque, uint64_t *arg1, uint64_t *arg2);
+    void (*cb)(Command *command);
     void *cb_opaque;
-} Command;
+    union {
+        CommandCreatePrimary create_primary;
+        CommandDrawBitmap bitmap;
+        CommandDrawSolid solid;
+    };
+};
 
 void test_set_simple_command_list(int *command, int num_commands);
 void test_set_command_list(Command *command, int num_commands);
diff --git a/server/tests/test_display_resolution_changes.c b/server/tests/test_display_resolution_changes.c
index edf7fb2..6db6e5e 100644
--- a/server/tests/test_display_resolution_changes.c
+++ b/server/tests/test_display_resolution_changes.c
@@ -23,7 +23,7 @@  void pinger(void *opaque)
     core->timer_start(ping_timer, ping_ms);
 }
 
-void set_primary_params(void *cb_opaque, uint64_t *arg1, uint64_t *arg2)
+void set_primary_params(Command *command)
 {
 #if 0
     static int toggle = 0;
@@ -39,14 +39,14 @@  void set_primary_params(void *cb_opaque, uint64_t *arg1, uint64_t *arg2)
 #endif
     static int count = 0;
 
-    *arg1 = 800 + sin((float)count / 6) * 200;
-    *arg2 = 600 + cos((float)count / 6) * 200;
+    command->create_primary.width = 800 + sin((float)count / 6) * 200;
+    command->create_primary.height = 600 + cos((float)count / 6) * 200;
     count++;
 }
 
 static Command commands[] = {
-    {DESTROY_PRIMARY, 0, 0, NULL, NULL},
-    {CREATE_PRIMARY, 0, 0, set_primary_params, NULL},
+    {DESTROY_PRIMARY, NULL},
+    {CREATE_PRIMARY, set_primary_params},
 };
 
 int main(void)