summaryrefslogtreecommitdiff
path: root/tests/uri-parsing-test.c
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2020-11-16 14:21:13 +0100
committerCarlos Garcia Campos <cgarcia@igalia.com>2020-11-20 11:09:23 +0100
commit3fb38248dd90de2eac95e6f24416466105ddd682 (patch)
tree9a42878f6e5aa192d714c9e9298cbb79d679e1de /tests/uri-parsing-test.c
parent9f262586f4425721721cbbc7d2feae27642b2213 (diff)
downloadlibsoup-3fb38248dd90de2eac95e6f24416466105ddd682.tar.gz
uri-utils: add soup_uri_copy()
It's a generic API to copy a GUri, but updating the given components.
Diffstat (limited to 'tests/uri-parsing-test.c')
-rw-r--r--tests/uri-parsing-test.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/uri-parsing-test.c b/tests/uri-parsing-test.c
index 8d5c0109..a8dd91c5 100644
--- a/tests/uri-parsing-test.c
+++ b/tests/uri-parsing-test.c
@@ -46,6 +46,75 @@ do_equality_tests (void)
}
}
+static void
+do_copy_tests (void)
+{
+ GUri *uri;
+ GUri *copy;
+ char *str;
+
+ uri = g_uri_parse ("http://127.0.0.1:1234/foo#bar", SOUP_HTTP_URI_FLAGS, NULL);
+
+ /* Exact copy */
+ copy = soup_uri_copy (uri, SOUP_URI_NONE);
+ str = g_uri_to_string (copy);
+ g_assert_cmpstr (str, ==, "http://127.0.0.1:1234/foo#bar");
+ g_free (str);
+ g_uri_unref (copy);
+
+ /* Update the path */
+ copy = soup_uri_copy (uri, SOUP_URI_PATH, "/baz", SOUP_URI_NONE);
+ str = g_uri_to_string (copy);
+ g_assert_cmpstr (str, ==, "http://127.0.0.1:1234/baz#bar");
+ g_free (str);
+ g_uri_unref (copy);
+
+ /* Add credentials */
+ copy = soup_uri_copy (uri, SOUP_URI_USER, "user", SOUP_URI_PASSWORD, "password", SOUP_URI_NONE);
+ str = g_uri_to_string (copy);
+ g_assert_cmpstr (str, ==, "http://user:password@127.0.0.1:1234/foo#bar");
+ g_free (str);
+ g_uri_unref (copy);
+
+ /* Remove the fragment and add a query */
+ copy = soup_uri_copy (uri, SOUP_URI_FRAGMENT, NULL, SOUP_URI_QUERY, "baz=1", SOUP_URI_NONE);
+ str = g_uri_to_string (copy);
+ g_assert_cmpstr (str, ==, "http://127.0.0.1:1234/foo?baz=1");
+ g_free (str);
+ g_uri_unref (copy);
+
+ /* Update host and port */
+ copy = soup_uri_copy (uri, SOUP_URI_HOST, "localhost", SOUP_URI_PORT, -1, SOUP_URI_NONE);
+ str = g_uri_to_string (copy);
+ g_assert_cmpstr (str, ==, "http://localhost/foo#bar");
+ g_free (str);
+ g_uri_unref (copy);
+
+ /* Update everything */
+ copy = soup_uri_copy (uri,
+ SOUP_URI_SCHEME, "https",
+ SOUP_URI_USER, "user",
+ SOUP_URI_PASSWORD, "password",
+ SOUP_URI_HOST, "localhost",
+ SOUP_URI_PORT, 4321,
+ SOUP_URI_PATH, "/baz",
+ SOUP_URI_FRAGMENT, "foo",
+ SOUP_URI_NONE);
+ str = g_uri_to_string (copy);
+ g_assert_cmpstr (str, ==, "https://user:password@localhost:4321/baz#foo");
+ g_free (str);
+ g_uri_unref (copy);
+
+ /* Convert to file */
+ copy = soup_uri_copy (uri, SOUP_URI_SCHEME, "file", SOUP_URI_HOST, "", SOUP_URI_PORT, -1, SOUP_URI_FRAGMENT, NULL, SOUP_URI_NONE);
+ str = g_uri_to_string (copy);
+ g_assert_cmpstr (str, ==, "file:///foo");
+ g_free (str);
+ g_uri_unref (copy);
+
+ g_uri_unref (uri);
+}
+
int
main (int argc, char **argv)
{
@@ -54,6 +123,7 @@ main (int argc, char **argv)
test_init (argc, argv, NULL);
g_test_add_func ("/uri/equality", do_equality_tests);
+ g_test_add_func ("/uri/copy", do_copy_tests);
ret = g_test_run ();