summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoss Burton <ross@linux.intel.com>2009-05-20 15:02:31 +0100
committerRoss Burton <ross@linux.intel.com>2009-05-20 15:02:31 +0100
commit31705edd0da9c3a718717926dea4bfd47a7a7c12 (patch)
tree1d6ab640f68c4423ac2351dcd556d43aa1a2dba5 /tests
parent292cbd5b025963734a337d38a1a20cfc9a6f6f4f (diff)
downloadlibrest-31705edd0da9c3a718717926dea4bfd47a7a7c12.tar.gz
Add a Flickr test suite
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am5
-rw-r--r--tests/flickr.c100
2 files changed, 103 insertions, 2 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 320234a..7a930d9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,9 +1,10 @@
-TESTS = proxy oauth
+TESTS = proxy oauth flickr
AM_CPPFLAGS = $(SOUP_CFLAGS) -I$(top_srcdir)
AM_LDFLAGS = $(SOUP_LIBS) ../rest/librest.la
-check_PROGRAMS = proxy oauth
+check_PROGRAMS = $(TESTS)
proxy_SOURCES = proxy.c
oauth_SOURCES = oauth.c
+flickr_SOURCES = flickr.c
diff --git a/tests/flickr.c b/tests/flickr.c
new file mode 100644
index 0000000..56e9c86
--- /dev/null
+++ b/tests/flickr.c
@@ -0,0 +1,100 @@
+/*
+ * librest - RESTful web services access
+ * Copyright (c) 2008, 2009, Intel Corporation.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <rest/flickr-proxy.h>
+#include <rest/rest-xml-parser.h>
+#include <stdio.h>
+
+#define ROSS_ID "35468147630@N01"
+int
+main (int argc, char **argv)
+{
+ RestProxy *proxy;
+ RestProxyCall *call;
+ GError *error = NULL;
+ RestXmlParser *parser;
+ RestXmlNode *root, *node;
+
+ g_thread_init (NULL);
+ g_type_init ();
+
+ /* Create the proxy */
+ proxy = flickr_proxy_new ("cf4e02fc57240a9b07346ad26e291080", "cdfa2329cb206e50");
+
+ /*
+ * Sadly can't unit test authentication.
+ */
+
+ /*
+ * Test a call which just requires an API key but no signature.
+ */
+
+ 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))
+ g_error ("Cannot make call: %s", error->message);
+
+ parser = rest_xml_parser_new ();
+ root = rest_xml_parser_parse_from_data (parser,
+ rest_proxy_call_get_payload (call),
+ rest_proxy_call_get_payload_length (call));
+ g_assert (root);
+ g_assert_cmpstr (root->name, ==, "rsp");
+ g_assert_cmpstr (rest_xml_node_get_attr (root, "stat"), ==, "ok");
+
+ node = rest_xml_node_find (root, "person");
+ g_assert (node);
+ g_assert_cmpstr (rest_xml_node_get_attr (node, "nsid"), ==, ROSS_ID);
+
+ node = rest_xml_node_find (node, "username");
+ g_assert (node);
+ g_assert_cmpstr (node->content, ==, "Ross Burton");
+
+ rest_xml_node_unref (root);
+ g_object_unref (call);
+
+ /*
+ * Test a call which requires a signature.
+ */
+
+ call = rest_proxy_new_call (proxy);
+ rest_proxy_call_set_function (call, "flickr.auth.getFrob");
+ if (!rest_proxy_call_run (call, NULL, &error))
+ g_error ("Cannot make call: %s", error->message);
+
+ parser = rest_xml_parser_new ();
+ root = rest_xml_parser_parse_from_data (parser,
+ rest_proxy_call_get_payload (call),
+ rest_proxy_call_get_payload_length (call));
+ g_assert (root);
+ g_assert_cmpstr (root->name, ==, "rsp");
+ g_assert_cmpstr (rest_xml_node_get_attr (root, "stat"), ==, "ok");
+
+ node = rest_xml_node_find (root, "frob");
+ g_assert (node);
+ g_assert (node->content);
+ g_assert_cmpstr (node->content, !=, "");
+
+ g_object_unref (proxy);
+ return 0;
+}