summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoss Burton <ross@linux.intel.com>2009-04-15 12:46:18 +0100
committerRoss Burton <ross@linux.intel.com>2009-04-15 12:46:18 +0100
commitd7c8bf8266c784a7e1f7682ec5ee6e3e1082f1c0 (patch)
tree02523fe0ce300fb31262e9f0efe87747cd86ab57
parentafa2be35e554d5933520495481580eb7112125a2 (diff)
downloadlibrest-d7c8bf8266c784a7e1f7682ec5ee6e3e1082f1c0.tar.gz
Add test suite for encode_params
-rw-r--r--.gitignore1
-rw-r--r--rest/Makefile.am11
-rw-r--r--rest/oauth-proxy-call.c36
-rw-r--r--rest/test-runner.c35
4 files changed, 83 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index d040e1a..4fb87c4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,3 +28,4 @@ examples/test-xml
examples/dump-xml
tests/oauth
tests/proxy
+rest/test-runner
diff --git a/rest/Makefile.am b/rest/Makefile.am
index c74dbe0..efde06e 100644
--- a/rest/Makefile.am
+++ b/rest/Makefile.am
@@ -24,3 +24,14 @@ librest_la_HEADERS = rest-proxy.h \
oauth-proxy-call.h \
rest-xml-parser.h
librest_ladir = $(includedir)/rest/rest
+
+
+# Test suite
+TESTS = test-runner
+check_PROGRAMS = test-runner
+
+test_runner_SOURCES = test-runner.c test-runner.h $(librest_la_SOURCES)
+test_runner_CFLAGS = -DBUILD_TESTS $(librest_la_CFLAGS)
+test_runner_LDFLAGS = $(librest_la_LIBADD)
+
+# TODO: use gtester
diff --git a/rest/oauth-proxy-call.c b/rest/oauth-proxy-call.c
index 5a5f83d..4b4d798 100644
--- a/rest/oauth-proxy-call.c
+++ b/rest/oauth-proxy-call.c
@@ -174,3 +174,39 @@ static void
oauth_proxy_call_init (OAuthProxyCall *self)
{
}
+
+#if BUILD_TESTS
+/* Test cases from http://wiki.oauth.net/TestCases */
+void
+test_param_encoding (void)
+{
+ GHashTable *hash;
+ char *s;
+
+#define TEST(expected) \
+ s = encode_params (hash); \
+ g_assert_cmpstr (s, ==, expected); \
+ g_free (s); \
+ g_hash_table_remove_all (hash);
+
+ hash = g_hash_table_new (g_str_hash, g_str_equal);
+
+ g_hash_table_insert (hash, "name", NULL);
+ TEST("name=");
+
+ g_hash_table_insert (hash, "a", "b");
+ TEST("a=b");
+
+ g_hash_table_insert (hash, "a", "b");
+ g_hash_table_insert (hash, "c", "d");
+ TEST("a=b&c=d");
+
+ /* Because we don't (yet) support multiple parameters with the same key we've
+ changed this case slightly */
+ g_hash_table_insert (hash, "b", "x!y");
+ g_hash_table_insert (hash, "a", "x y");
+ TEST("a=x%20y&b=x%21y");
+
+#undef TEST
+}
+#endif
diff --git a/rest/test-runner.c b/rest/test-runner.c
new file mode 100644
index 0000000..0baa243
--- /dev/null
+++ b/rest/test-runner.c
@@ -0,0 +1,35 @@
+/*
+ * librest - RESTful web services access
+ * Copyright (C) 2009 Intel Corporation.
+ *
+ * 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 <config.h>
+#include <glib-object.h>
+
+#define test_add(unit_name, func) G_STMT_START { \
+ extern void func (void); \
+ g_test_add_func (unit_name, func); } G_STMT_END
+
+int
+main (int argc, char *argv[])
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ test_add ("/oauth/param-encoding", test_param_encoding);
+
+ return g_test_run ();
+}