[librest/wip/baedert/fixes: 7/7] tests/threaded: Use GTest
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librest/wip/baedert/fixes: 7/7] tests/threaded: Use GTest
- Date: Tue, 19 Jul 2016 10:44:54 +0000 (UTC)
commit 6ed51db19e130eb0c102b11879c904bd338ce4a2
Author: Timm Bäder <mail baedert org>
Date: Mon Jul 18 13:54:36 2016 +0200
tests/threaded: Use GTest
tests/threaded.c | 37 ++++++++++++++++---------------------
1 files changed, 16 insertions(+), 21 deletions(-)
---
diff --git a/tests/threaded.c b/tests/threaded.c
index 7050bb4..a336287 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;
@@ -66,18 +65,10 @@ 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 ());
@@ -85,11 +76,12 @@ func (gpointer data)
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;
@@ -100,12 +92,7 @@ main (int argc, char **argv)
server = soup_server_new (NULL);
soup_server_listen_all (server, 0, 0, &error);
-
- if (error)
- {
- g_critical ("listen failed: %s", error->message);
- return -1;
- }
+ g_assert_no_error (error);
soup_server_add_handler (server, "/ping", server_callback,
NULL, NULL);
@@ -128,6 +115,14 @@ main (int argc, char **argv)
g_free (url);
g_slist_free_full (uris, (GDestroyNotify)soup_uri_free);
g_object_unref (server);
+}
+
+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 ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]