[librest/wip/teuf/gtask: 12/28] tests/oauth2: Convert to GTest api
- From: Christophe Fergeau <teuf src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librest/wip/teuf/gtask: 12/28] tests/oauth2: Convert to GTest api
- Date: Mon, 20 Jun 2016 10:42:10 +0000 (UTC)
commit ef8530b0a3557e15b5cea8d12c5557dde7fad1f8
Author: Timm Bäder <mail baedert org>
Date: Sat Apr 23 16:16:38 2016 +0200
tests/oauth2: Convert to GTest api
tests/oauth2.c | 47 ++++++++++++++++++++++++++++++-----------------
1 files changed, 30 insertions(+), 17 deletions(-)
---
diff --git a/tests/oauth2.c b/tests/oauth2.c
index 292ace3..23e609f 100644
--- a/tests/oauth2.c
+++ b/tests/oauth2.c
@@ -22,32 +22,45 @@
#include <rest/oauth2-proxy.h>
#include <string.h>
-void
-test_extract_token ()
+static void
+test_url_no_fragment ()
{
- char *token;
+ char *token = oauth2_proxy_extract_access_token ("http://example.com");
- /* test a url without a fragment */
- token = oauth2_proxy_extract_access_token ("http://example.com/");
- g_assert (token == NULL);
+ g_assert_null (token);
+}
- /* test a url with a fragment but without an access_token parameter */
- token = oauth2_proxy_extract_access_token ("http://example.com/foo?foo=1#bar");
- g_assert (token == NULL);
+static void
+test_url_fragment_no_access_token ()
+{
+ char *token = oauth2_proxy_extract_access_token ("http://example.com/foo?foo=1#bar");
- /* test simple access_token */
- token = oauth2_proxy_extract_access_token
("http://example.com/foo?foo=1#access_token=1234567890_12.34561abcdefg&bar");
- g_assert (strcmp(token, "1234567890_12.34561abcdefg") == 0);
+ g_assert_null (token);
+}
+
+static void
+test_access_token_simple ()
+{
+ char *token = oauth2_proxy_extract_access_token
("http://example.com/foo?foo=1#access_token=1234567890_12.34561abcdefg&bar");
+
+ g_assert_cmpstr (token, ==, "1234567890_12.34561abcdefg");
+}
+
+static void test_url_encoding_access_token ()
+{
+ char *token = oauth2_proxy_extract_access_token
("http://example.com/foo?foo=1#access_token=1234567890%5F12%2E34561abcdefg&bar");
- /* test access_token with url encoding */
- token = oauth2_proxy_extract_access_token
("http://example.com/foo?foo=1#access_token=1234567890%5F12%2E34561abcdefg&bar");
- g_assert (strcmp(token, "1234567890_12.34561abcdefg") == 0);
+ g_assert_cmpstr (token, ==, "1234567890_12.34561abcdefg");
}
int
main (int argc, char **argv)
{
- test_extract_token ();
+ g_test_init (&argc, &argv, NULL);
+ g_test_add_func ("/oauth2/url-no-fragment", test_url_no_fragment);
+ g_test_add_func ("/oauth2/url-fragment-no-access-token", test_url_fragment_no_access_token);
+ g_test_add_func ("/oauth2/access-token-simple", test_access_token_simple);
+ g_test_add_func ("/oauth2/access-token-url-encoding", test_url_encoding_access_token);
- return 0;
+ return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]