summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2016-07-18 13:54:36 +0200
committerChristophe Fergeau <cfergeau@redhat.com>2016-07-19 14:25:08 +0200
commita78ba79200af84e44ad53cf4581047108909b90e (patch)
treecb404b108822f7d1f4a82d4600ecc1ca18c4aab3
parentc6be11cd8ccf8aaae8c448dc9b2436cd3d888a91 (diff)
downloadlibrest-a78ba79200af84e44ad53cf4581047108909b90e.tar.gz
tests/threaded: Use GTest
-rw-r--r--tests/threaded.c57
1 files changed, 24 insertions, 33 deletions
diff --git a/tests/threaded.c b/tests/threaded.c
index 1519b67..a251900 100644
--- a/tests/threaded.c
+++ b/tests/threaded.c
@@ -29,7 +29,6 @@
const int N_THREADS = 10;
-static volatile int errors = 0;
static volatile int threads_done = 0;
static const gboolean verbose = FALSE;
@@ -41,15 +40,13 @@ server_callback (SoupServer *server, SoupMessage *msg,
const char *path, GHashTable *query,
SoupClientContext *client, gpointer user_data)
{
- if (g_str_equal (path, "/ping")) {
- soup_message_set_status (msg, SOUP_STATUS_OK);
- g_atomic_int_add (&threads_done, 1);
-
- if (threads_done == N_THREADS) {
- g_main_loop_quit (main_loop);
- }
- } else {
- soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);
+ g_assert_cmpstr (path, ==, "/ping");
+
+ soup_message_set_status (msg, SOUP_STATUS_OK);
+ g_atomic_int_add (&threads_done, 1);
+
+ if (threads_done == N_THREADS) {
+ g_main_loop_quit (main_loop);
}
}
@@ -66,46 +63,32 @@ func (gpointer data)
call = rest_proxy_new_call (proxy);
rest_proxy_call_set_function (call, "ping");
- 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 (rest_proxy_call_sync (call, &error));
+ g_assert_no_error (error);
- 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;
- }
+ g_assert_cmpint (rest_proxy_call_get_status_code (call), ==, SOUP_STATUS_OK);
if (verbose)
g_print ("Thread %p done\n", g_thread_self ());
- done:
g_object_unref (call);
g_object_unref (proxy);
+
return NULL;
}
-int
-main (int argc, char **argv)
+
+static void ping ()
{
GThread *threads[N_THREADS];
GError *error = NULL;
char *url;
int i;
GSList *uris;
- GSocketAddress *address;
server = soup_server_new (NULL);
- soup_server_listen_all (server, 0, 0, &error);
-
- if (error)
- {
- g_critical ("listen failed: %s", error->message);
- return -1;
- }
+ soup_server_listen_local (server, 0, 0, &error);
+ g_assert_no_error (error);
soup_server_add_handler (server, "/ping", server_callback,
NULL, NULL);
@@ -129,6 +112,14 @@ main (int argc, char **argv)
g_slist_free_full (uris, (GDestroyNotify)soup_uri_free);
g_object_unref (server);
g_main_loop_unref (main_loop);
+}
+
+int
+main (int argc, char **argv)
+{
+
+ g_test_init (&argc, &argv, NULL);
+ g_test_add_func ("/threaded/ping", ping);
- return errors != 0;
+ return g_test_run ();
}