[librest/wip/teuf/gtask: 26/37] Revert "tests/custom-serialize: Port to GTest api"



commit 346e9430c80a91135ab2e58bd2431d8c29895ae8
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Wed Jun 15 18:20:45 2016 +0200

    Revert "tests/custom-serialize: Port to GTest api"
    
    This reverts commit f74bab5bbde109ef94c74c81817288c8fb5cfdb4.

 tests/custom-serialize.c |   54 ++++++++++++++++++++-------------------------
 1 files changed, 24 insertions(+), 30 deletions(-)
---
diff --git a/tests/custom-serialize.c b/tests/custom-serialize.c
index c3fde93..5cdf6d8 100644
--- a/tests/custom-serialize.c
+++ b/tests/custom-serialize.c
@@ -27,7 +27,8 @@
 #include <libsoup/soup.h>
 #include <rest/rest-proxy.h>
 
-#define PORT 8080
+static volatile int errors = 0;
+static const gboolean verbose = FALSE;
 
 #define REST_TYPE_CUSTOM_PROXY_CALL custom_proxy_call_get_type()
 
@@ -107,52 +108,45 @@ server_callback (SoupServer *server, SoupMessage *msg,
   }
 }
 
-static void *
-server_func (gpointer data)
-{
-  GMainLoop *loop = g_main_loop_new (NULL, FALSE);
-  SoupServer *server = soup_server_new (NULL, NULL);
-  GSocketAddress *address = g_inet_socket_address_new_from_string ("127.0.0.1", PORT);
-
-  soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
-  soup_server_listen (server, address, 0, NULL);
-
-  g_main_loop_run (loop);
-  return NULL;
-}
-
-static void
-test_custom_serialize ()
+int
+main (int argc, char **argv)
 {
+  SoupServer *server;
   RestProxy *proxy;
   RestProxyCall *call;
   char *url;
   GError *error = NULL;
 
-  url = g_strdup_printf ("http://127.0.0.1:%d/";, PORT);
+  server = soup_server_new (NULL);
+  soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
+  url = g_strdup_printf ("http://127.0.0.1:%d/";, soup_server_get_port (server));
 
-  g_thread_new ("Server Thread", server_func, NULL);
+  g_thread_create ((GThreadFunc)soup_server_run, server, FALSE, NULL);
 
   proxy = rest_proxy_new (url, FALSE);
   call = g_object_new (REST_TYPE_CUSTOM_PROXY_CALL, "proxy", proxy, NULL);
 
   rest_proxy_call_set_function (call, "wrong-function");
 
-  rest_proxy_call_sync (call, &error);
-  g_assert_no_error (error);
+  if (!rest_proxy_call_sync (call, &error)) {
+    g_printerr ("Call failed: %s\n", error->message);
+    g_error_free (error);
+    g_atomic_int_add (&errors, 1);
+    goto done;
+  }
 
-  g_assert_cmpint (rest_proxy_call_get_status_code (call), ==, SOUP_STATUS_OK);
+  if (rest_proxy_call_get_status_code (call) != SOUP_STATUS_OK) {
+    g_printerr ("Wrong response code, got %d\n", rest_proxy_call_get_status_code (call));
+    g_atomic_int_add (&errors, 1);
+    goto done;
+  }
+
+  done:
 
   g_object_unref (call);
   g_object_unref (proxy);
+  soup_server_quit (server);
   g_free (url);
-}
-
-int
-main (int argc, char **argv)
-{
-  g_test_init (&argc, &argv, NULL);
-  g_test_add_func ("/custom-serialize/custom-serialize", test_custom_serialize);
 
-  return g_test_run ();
+  return errors != 0;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]