Blame SOURCES/0001-tests-proxy-continuous-Server-chunks-can-be-differen.patch

406fd2
From 5af733210438aef493008b92ef5857a27e952596 Mon Sep 17 00:00:00 2001
406fd2
From: Debarshi Ray <debarshir@gnome.org>
406fd2
Date: Wed, 16 Sep 2015 18:40:59 +0200
406fd2
Subject: [PATCH] tests/proxy-continuous: Server chunks can be different from
406fd2
 client ones
406fd2
406fd2
https://bugzilla.gnome.org/show_bug.cgi?id=755124
406fd2
---
406fd2
 tests/proxy-continuous.c | 52 ++++++++++++++++++++++--------------------------
406fd2
 1 file changed, 24 insertions(+), 28 deletions(-)
406fd2
406fd2
diff --git a/tests/proxy-continuous.c b/tests/proxy-continuous.c
406fd2
index 9395cd28cc8f..5be64fa696b5 100644
406fd2
--- a/tests/proxy-continuous.c
406fd2
+++ b/tests/proxy-continuous.c
406fd2
@@ -32,26 +32,31 @@ static int errors = 0;
406fd2
 static GMainLoop *loop = NULL;
406fd2
 
406fd2
 #define NUM_CHUNKS 20
406fd2
-static int server_count = 0;
406fd2
-static gint client_count = 0;
406fd2
+#define SIZE_CHUNK 4
406fd2
+static guint8 server_count = 0;
406fd2
+static guint8 client_count = 0;
406fd2
 static SoupServer *server;
406fd2
 
406fd2
 static gboolean
406fd2
 send_chunks (gpointer user_data)
406fd2
 {
406fd2
   SoupMessage *msg = SOUP_MESSAGE (user_data);
406fd2
-  char *s;
406fd2
   SoupBuffer *buf;
406fd2
+  guint i;
406fd2
+  guint8 data[SIZE_CHUNK];
406fd2
 
406fd2
-  s = g_strdup_printf ("%d %d %d %d\n",
406fd2
-                       server_count, server_count,
406fd2
-                       server_count, server_count);
406fd2
-  buf = soup_buffer_new (SOUP_MEMORY_TAKE, s, strlen (s));
406fd2
+  for (i = 0; i < SIZE_CHUNK; i++)
406fd2
+  {
406fd2
+    data[i] = server_count;
406fd2
+    server_count++;
406fd2
+  }
406fd2
+
406fd2
+  buf = soup_buffer_new (SOUP_MEMORY_COPY, data, SIZE_CHUNK);
406fd2
 
406fd2
   soup_message_body_append_buffer (msg->response_body, buf);
406fd2
   soup_server_unpause_message (server, msg);
406fd2
 
406fd2
-  if (++server_count == NUM_CHUNKS)
406fd2
+  if (server_count == NUM_CHUNKS * SIZE_CHUNK)
406fd2
   {
406fd2
     soup_message_body_complete (msg->response_body);
406fd2
     return FALSE;
406fd2
@@ -71,7 +76,6 @@ server_callback (SoupServer *server, SoupMessage *msg,
406fd2
                                        SOUP_ENCODING_CHUNKED);
406fd2
     soup_server_pause_message (server, msg);
406fd2
 
406fd2
-    server_count = 1;
406fd2
     g_idle_add (send_chunks, msg);
406fd2
   }
406fd2
 }
406fd2
@@ -84,7 +88,7 @@ _call_continuous_cb (RestProxyCall *call,
406fd2
                      GObject       *weak_object,
406fd2
                      gpointer       userdata)
406fd2
 {
406fd2
-  gint a = 0, b = 0, c = 0, d = 0;
406fd2
+  guint i;
406fd2
 
406fd2
   if (error)
406fd2
   {
406fd2
@@ -102,7 +106,7 @@ _call_continuous_cb (RestProxyCall *call,
406fd2
 
406fd2
   if (buf == NULL && len == 0)
406fd2
   {
406fd2
-    if (client_count != NUM_CHUNKS)
406fd2
+    if (client_count < NUM_CHUNKS * SIZE_CHUNK)
406fd2
     {
406fd2
       g_printerr ("stream ended prematurely\n");
406fd2
       errors++;
406fd2
@@ -110,25 +114,19 @@ _call_continuous_cb (RestProxyCall *call,
406fd2
     goto out;
406fd2
   }
406fd2
 
406fd2
-  if (sscanf (buf, "%d %d %d %d\n", &a, &b, &c, &d) != 4)
406fd2
+  for (i = 0; i < len; i++)
406fd2
   {
406fd2
-    g_printerr ("stream data not formatted as expected\n");
406fd2
-    errors++;
406fd2
-    goto out;
406fd2
-  }
406fd2
+    if (buf[i] != client_count)
406fd2
+    {
406fd2
+      g_printerr ("stream data not as expected (got %d, expected %d)\n",
406fd2
+                  (gint) buf[i], client_count);
406fd2
+      errors++;
406fd2
+      goto out;
406fd2
+    }
406fd2
 
406fd2
-  if (a != client_count ||
406fd2
-      b != client_count ||
406fd2
-      c != client_count ||
406fd2
-      d != client_count)
406fd2
-  {
406fd2
-    g_printerr ("stream data not as expected (got %d %d %d %d, expected %d)\n",
406fd2
-                a, b, c, d, client_count);
406fd2
-    errors++;
406fd2
-    goto out;
406fd2
+    client_count++;
406fd2
   }
406fd2
 
406fd2
-  client_count++;
406fd2
   return;
406fd2
 out:
406fd2
   g_main_loop_quit (loop);
406fd2
@@ -141,8 +139,6 @@ stream_test (RestProxy *proxy)
406fd2
   RestProxyCall *call;
406fd2
   GError *error;
406fd2
 
406fd2
-  client_count = 1;
406fd2
-
406fd2
   call = rest_proxy_new_call (proxy);
406fd2
   rest_proxy_call_set_function (call, "stream");
406fd2
 
406fd2
-- 
406fd2
2.1.0
406fd2