summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2016-07-19 13:57:19 +0200
committerTimm Bäder <mail@baedert.org>2016-07-19 14:01:22 +0200
commit75b95592688fb9f2d0ff7b518732b16c5ef18898 (patch)
tree0f114252c12ebd9b6c9a70b1669d1e105f503741
parentdfaefa74582a43ed16b7258edfbf17f5ce2b5afb (diff)
downloadlibrest-wip/baedert/fixes.tar.gz
tests/proxy-continuous: Use GTest APIwip/baedert/fixes
Use assert macros instead of error counting and drop deprecated libsoup API
-rw-r--r--tests/proxy-continuous.c102
1 files changed, 48 insertions, 54 deletions
diff --git a/tests/proxy-continuous.c b/tests/proxy-continuous.c
index 6245181..abcf78f 100644
--- a/tests/proxy-continuous.c
+++ b/tests/proxy-continuous.c
@@ -28,7 +28,6 @@
#include <libsoup/soup.h>
#include <rest/rest-proxy.h>
-static int errors = 0;
static GMainLoop *loop = NULL;
#define NUM_CHUNKS 20
@@ -87,47 +86,21 @@ _call_continuous_cb (RestProxyCall *call,
{
guint i;
- if (error)
- {
- g_printerr ("Error: %s\n", error->message);
- errors++;
- goto out;
- }
-
- if (!REST_IS_PROXY (weak_object))
- {
- g_printerr ("weak object not as expected\n");
- errors++;
- goto out;
- }
+ g_assert_no_error (error);
+ g_assert (REST_IS_PROXY (weak_object));
if (buf == NULL && len == 0)
- {
- if (client_count < NUM_CHUNKS * SIZE_CHUNK)
- {
- g_printerr ("stream ended prematurely\n");
- errors++;
- }
- goto out;
- }
+ g_assert (client_count == NUM_CHUNKS * SIZE_CHUNK);
for (i = 0; i < len; i++)
{
- if (buf[i] != client_count)
- {
- g_printerr ("stream data not as expected (got %d, expected %d)\n",
- (gint) buf[i], client_count);
- errors++;
- goto out;
- }
-
+ g_assert_cmpint (buf[i], ==, client_count);
client_count++;
}
- return;
-out:
- g_main_loop_quit (loop);
- return;
+
+ if (client_count == NUM_CHUNKS * SIZE_CHUNK)
+ g_main_loop_quit (loop);
}
static void
@@ -135,43 +108,64 @@ stream_test (RestProxy *proxy)
{
RestProxyCall *call;
GError *error = NULL;
+ gboolean result;
call = rest_proxy_new_call (proxy);
rest_proxy_call_set_function (call, "stream");
- if (!rest_proxy_call_continuous (call,
- _call_continuous_cb,
- (GObject *)proxy,
- NULL,
- &error))
- {
- g_printerr ("Making stream failed: %s", error->message);
- g_error_free (error);
- errors++;
- return;
- }
+ result = rest_proxy_call_continuous (call,
+ _call_continuous_cb,
+ (GObject *)proxy,
+ NULL,
+ &error);
+
+ g_assert_no_error (error);
+ g_assert (result);
g_object_unref (call);
}
-int
-main (int argc, char **argv)
+static void
+continuous ()
{
char *url;
RestProxy *proxy;
+ GError *error = NULL;
+ GSList *uris;
- loop = g_main_loop_new (NULL, FALSE);
- server = soup_server_new (NULL);
+ server = soup_server_new (NULL, NULL);
+ soup_server_listen_all (server, 0, 0, &error);
+ g_assert_no_error (error);
+
soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
- soup_server_run_async (server);
+ soup_server_add_handler (server, "/ping", server_callback,
+ NULL, NULL);
- url = g_strdup_printf ("http://127.0.0.1:%d/", soup_server_get_port (server));
- proxy = rest_proxy_new (url, FALSE);
- g_free (url);
+ uris = soup_server_get_uris (server);
+ g_assert (g_slist_length (uris) > 0);
+ url = soup_uri_to_string (uris->data, FALSE);
+
+ loop = g_main_loop_new (NULL, FALSE);
+
+ proxy = rest_proxy_new (url, FALSE);
stream_test (proxy);
+
g_main_loop_run (loop);
- return errors != 0;
+
+ g_slist_free_full (uris, (GDestroyNotify)soup_uri_free);
+ g_main_loop_run (loop);
+ g_free (url);
+ g_main_loop_unref (loop);
+}
+
+int
+main (int argc, char **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_add_func ("/proxy/continuous", continuous);
+
+ return g_test_run ();
}