diff options
author | Timm Bäder <mail@baedert.org> | 2016-04-22 14:01:09 +0200 |
---|---|---|
committer | Christophe Fergeau <cfergeau@redhat.com> | 2016-06-20 12:39:44 +0200 |
commit | f8c2ab720de6f7741f4af10f43b95d27c27ecc8e (patch) | |
tree | cb9654e290547d4a832da37a5db6e884ef5b5467 | |
parent | 9cca799e77aaf60561c303dbb0dac3ce9d78a3dc (diff) | |
download | librest-f8c2ab720de6f7741f4af10f43b95d27c27ecc8e.tar.gz |
Adapt tests and examples to API change
-rw-r--r-- | examples/test-raw.c | 23 | ||||
-rw-r--r-- | examples/test-xml.c | 42 | ||||
-rw-r--r-- | tests/flickr.c | 4 | ||||
-rw-r--r-- | tests/lastfm.c | 2 | ||||
-rw-r--r-- | tests/proxy.c | 53 | ||||
-rw-r--r-- | tests/threaded.c | 2 |
6 files changed, 70 insertions, 56 deletions
diff --git a/examples/test-raw.c b/examples/test-raw.c index d8daa93..3e6a437 100644 --- a/examples/test-raw.c +++ b/examples/test-raw.c @@ -4,7 +4,7 @@ * * Authors: Rob Bradford <rob@linux.intel.com> * Ross Burton <ross@linux.intel.com> - * + * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU Lesser General Public License, * version 2.1, as published by the Free Software Foundation. @@ -24,18 +24,18 @@ #include <unistd.h> static void -proxy_call_async_cb (RestProxyCall *call, - const GError *error, - GObject *weak_object, - gpointer userdata) +proxy_call_async_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { + RestProxyCall *call = REST_PROXY_CALL (source_object); const gchar *payload; goffset len; payload = rest_proxy_call_get_payload (call); len = rest_proxy_call_get_payload_length (call); write (1, payload, len); - g_main_loop_quit ((GMainLoop *)userdata); + g_main_loop_quit ((GMainLoop *)user_data); } gint @@ -56,15 +56,14 @@ main (gint argc, gchar **argv) "api_key", "314691be2e63a4d58994b2be01faacfb", "format", "json", NULL); - rest_proxy_call_async (call, - proxy_call_async_cb, - NULL, - loop, - NULL); + rest_proxy_call_invoke_async (call, + NULL, + proxy_call_async_cb, + loop); g_main_loop_run (loop); - rest_proxy_call_run (call, NULL, NULL); + rest_proxy_call_sync (call, NULL); payload = rest_proxy_call_get_payload (call); len = rest_proxy_call_get_payload_length (call); diff --git a/examples/test-xml.c b/examples/test-xml.c index 79f76aa..e3833de 100644 --- a/examples/test-xml.c +++ b/examples/test-xml.c @@ -4,7 +4,7 @@ * * Authors: Rob Bradford <rob@linux.intel.com> * Ross Burton <ross@linux.intel.com> - * + * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU Lesser General Public License, * version 2.1, as published by the Free Software Foundation. @@ -64,11 +64,11 @@ _rest_xml_node_output (RestXmlNode *node, gint depth) do { attrs_output = _generate_attrs_output (node->attrs); - g_print ("%*s[%s, %s, %s]\n", - depth, - "", - node->name, - node->content, + g_print ("%*s[%s, %s, %s]\n", + depth, + "", + node->name, + node->content, attrs_output); g_free (attrs_output); values = g_hash_table_get_values (node->children); @@ -83,11 +83,11 @@ _rest_xml_node_output (RestXmlNode *node, gint depth) } static void -proxy_call_raw_async_cb (RestProxyCall *call, - const GError *error, - GObject *weak_object, - gpointer userdata) +proxy_call_raw_async_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { + RestProxyCall *call = REST_PROXY_CALL (source_object); RestXmlParser *parser; RestXmlNode *node; const gchar *payload; @@ -103,7 +103,7 @@ proxy_call_raw_async_cb (RestProxyCall *call, _rest_xml_node_output (node, 0); rest_xml_node_unref (node); g_object_unref (parser); - g_main_loop_quit ((GMainLoop *)userdata); + g_main_loop_quit ((GMainLoop *)user_data); } gint @@ -123,11 +123,10 @@ main (gint argc, gchar **argv) "api_key", "314691be2e63a4d58994b2be01faacfb", "photo_id", "2658808091", NULL); - rest_proxy_call_async (call, - proxy_call_raw_async_cb, - NULL, - loop, - NULL); + rest_proxy_call_invoke_async (call, + NULL, + proxy_call_raw_async_cb, + loop); g_main_loop_run (loop); g_object_unref (call); @@ -137,13 +136,12 @@ main (gint argc, gchar **argv) rest_proxy_call_add_params (call, "method", "flickr.people.getPublicPhotos", "api_key", "314691be2e63a4d58994b2be01faacfb", - "user_id","66598853@N00", + "user_id","66598853@N00", NULL); - rest_proxy_call_async (call, - proxy_call_raw_async_cb, - NULL, - loop, - NULL); + rest_proxy_call_invoke_async (call, + NULL, + proxy_call_raw_async_cb, + loop); g_main_loop_run (loop); g_object_unref (call); diff --git a/tests/flickr.c b/tests/flickr.c index 08a55cb..4b2b8ac 100644 --- a/tests/flickr.c +++ b/tests/flickr.c @@ -55,7 +55,7 @@ main (int argc, char **argv) call = rest_proxy_new_call (proxy); rest_proxy_call_set_function (call, "flickr.people.getInfo"); rest_proxy_call_add_param (call, "user_id", ROSS_ID); - if (!rest_proxy_call_run (call, NULL, &error)) + if (!rest_proxy_call_sync (call, &error)) g_error ("Cannot make call: %s", error->message); parser = rest_xml_parser_new (); @@ -83,7 +83,7 @@ main (int argc, char **argv) call = rest_proxy_new_call (proxy); rest_proxy_call_set_function (call, "flickr.auth.getFrob"); - if (!rest_proxy_call_run (call, NULL, &error)) + if (!rest_proxy_call_sync (call, &error)) g_error ("Cannot make call: %s", error->message); parser = rest_xml_parser_new (); diff --git a/tests/lastfm.c b/tests/lastfm.c index 4addb58..12e10d4 100644 --- a/tests/lastfm.c +++ b/tests/lastfm.c @@ -68,7 +68,7 @@ main (int argc, char **argv) node = rest_xml_node_find (u_node, "id"); if (node != NULL) - g_assert_cmpstr (node->content, ==, "17038"); + g_assert_cmpstr (node->content, ==, "17038"); node = rest_xml_node_find (u_node, "name"); g_assert (node); diff --git a/tests/proxy.c b/tests/proxy.c index 8ea54f0..89a9325 100644 --- a/tests/proxy.c +++ b/tests/proxy.c @@ -41,8 +41,13 @@ #define soup_message_headers_get soup_message_headers_get_one #endif +#define PORT 8080 + static int errors = 0; +SoupServer *server; +GMainLoop *server_loop; + static void server_callback (SoupServer *server, SoupMessage *msg, const char *path, GHashTable *query, @@ -108,8 +113,8 @@ ping_test (RestProxy *proxy) call = rest_proxy_new_call (proxy); rest_proxy_call_set_function (call, "ping"); - if (!rest_proxy_call_run (call, NULL, &error)) { - g_printerr ("Call failed: %s\n", error->message); + if (!rest_proxy_call_sync (call, &error)) { + g_printerr ("2: Call failed: %s\n", error->message); g_error_free (error); errors++; g_object_unref (call); @@ -142,8 +147,8 @@ echo_test (RestProxy *proxy) rest_proxy_call_set_function (call, "echo"); rest_proxy_call_add_param (call, "value", "echome"); - if (!rest_proxy_call_run (call, NULL, &error)) { - g_printerr ("Call failed: %s\n", error->message); + if (!rest_proxy_call_sync (call, &error)) { + g_printerr ("3: Call failed: %s\n", error->message); g_error_free (error); errors++; g_object_unref (call); @@ -182,8 +187,8 @@ reverse_test (RestProxy *proxy) rest_proxy_call_set_function (call, "reverse"); rest_proxy_call_add_param (call, "value", "reverseme"); - if (!rest_proxy_call_run (call, NULL, &error)) { - g_printerr ("Call failed: %s\n", error->message); + if (!rest_proxy_call_sync (call, &error)) { + g_printerr ("4: Call failed: %s\n", error->message); g_error_free (error); errors++; g_object_unref (call); @@ -213,7 +218,7 @@ reverse_test (RestProxy *proxy) } static void -status_ok_test (RestProxy *proxy, int status) +status_ok_test (RestProxy *proxy, guint status) { RestProxyCall *call; GError *error = NULL; @@ -225,8 +230,8 @@ status_ok_test (RestProxy *proxy, int status) rest_proxy_call_add_param (call, "status", status_str); g_free (status_str); - if (!rest_proxy_call_run (call, NULL, &error)) { - g_printerr ("Call failed: %s\n", error->message); + if (!rest_proxy_call_sync (call, &error)) { + g_printerr ("1: Call failed: %s\n", error->message); g_error_free (error); errors++; g_object_unref (call); @@ -244,7 +249,7 @@ status_ok_test (RestProxy *proxy, int status) } static void -status_error_test (RestProxy *proxy, int status) +status_error_test (RestProxy *proxy, guint status) { RestProxyCall *call; GError *error = NULL; @@ -256,7 +261,7 @@ status_error_test (RestProxy *proxy, int status) rest_proxy_call_add_param (call, "status", status_str); g_free (status_str); - if (rest_proxy_call_run (call, NULL, &error)) { + if (rest_proxy_call_sync (call, &error)) { g_printerr ("Call succeeded should have failed"); errors++; g_object_unref (call); @@ -282,7 +287,7 @@ test_status_ok (RestProxy *proxy, const char *function) call = rest_proxy_new_call (proxy); rest_proxy_call_set_function (call, function); - if (!rest_proxy_call_run (call, NULL, &error)) { + if (!rest_proxy_call_sync (call, &error)) { g_printerr ("%s call failed: %s\n", function, error->message); g_error_free (error); errors++; @@ -300,18 +305,30 @@ test_status_ok (RestProxy *proxy, const char *function) g_object_unref (call); } +static void * +server_thread_func (gpointer data) +{ + GSocketAddress *address = g_inet_socket_address_new_from_string ("127.0.0.1", 8080); + server_loop = g_main_loop_new (NULL, TRUE); + /*SoupServer *server = soup_server_new (NULL);*/ + soup_server_add_handler (server, NULL, server_callback, NULL, NULL); + + soup_server_listen (server, address, 0, NULL); + g_main_loop_run (server_loop); + + return NULL; +} + int main (int argc, char **argv) { - SoupServer *server; char *url; RestProxy *proxy; - server = soup_server_new (NULL); - soup_server_add_handler (server, NULL, server_callback, NULL, NULL); - soup_server_run_async (server); + server = soup_server_new ("", NULL); + g_thread_new ("Server Thread", server_thread_func, NULL); - url = g_strdup_printf ("http://127.0.0.1:%d/", soup_server_get_port (server)); + url = g_strdup_printf ("http://127.0.0.1:%d/", PORT); proxy = rest_proxy_new (url, FALSE); g_free (url); @@ -320,7 +337,6 @@ main (int argc, char **argv) reverse_test (proxy); status_ok_test (proxy, SOUP_STATUS_OK); status_ok_test (proxy, SOUP_STATUS_NO_CONTENT); - /* status_ok_test (proxy, SOUP_STATUS_MULTIPLE_CHOICES); */ status_error_test (proxy, SOUP_STATUS_BAD_REQUEST); status_error_test (proxy, SOUP_STATUS_NOT_IMPLEMENTED); @@ -328,5 +344,6 @@ main (int argc, char **argv) rest_proxy_set_user_agent (proxy, "TestSuite-1.0"); test_status_ok (proxy, "useragent/testsuite"); + g_main_loop_quit (server_loop); return errors != 0; } diff --git a/tests/threaded.c b/tests/threaded.c index b684896..e3fed70 100644 --- a/tests/threaded.c +++ b/tests/threaded.c @@ -28,7 +28,7 @@ #include <rest/rest-proxy.h> static volatile int errors = 0; -static const gboolean verbose = FALSE; +static const gboolean verbose = TRUE; static void server_callback (SoupServer *server, SoupMessage *msg, |