Bump GLib requirement to >= 2.62
[platform/upstream/gstreamer.git] / subprojects / gstreamer / tests / check / gst / gsturi.c
1 /* GStreamer unit tests for GstURI
2  *
3  * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #ifndef GST_REMOVE_DEPRECATED
25 #undef GST_DISABLE_DEPRECATED
26 #endif
27
28 #include <gst/check/gstcheck.h>
29
30 GST_START_TEST (test_protocol_case)
31 {
32   GstElement *element;
33   GError *err = NULL;
34
35   element = gst_element_make_from_uri (GST_URI_SRC, "file:///foo/bar", NULL,
36       &err);
37
38   /* no element? probably no registry, bail out */
39   if (element == NULL && err->code == GST_URI_ERROR_UNSUPPORTED_PROTOCOL) {
40     g_error_free (err);
41     return;
42   }
43
44   gst_object_unref (element);
45   element = gst_element_make_from_uri (GST_URI_SRC, "FILE:///foo/bar", NULL,
46       NULL);
47   fail_unless (element != NULL,
48       "Got source for 'file://' URI but not for 'FILE://' URI");
49   gst_object_unref (element);
50 }
51
52 GST_END_TEST;
53
54 GST_START_TEST (test_uri_get_location)
55 {
56   gchar *l;
57
58   /* URI with no location should return empty string */
59   l = gst_uri_get_location ("dvd://");
60   fail_unless (l != NULL);
61   fail_unless_equals_string (l, "");
62   g_free (l);
63
64   /* URI with hostname */
65   l = gst_uri_get_location ("smb://supercomputer/path/to/file");
66   fail_unless (l != NULL);
67   fail_unless_equals_string (l, "supercomputer/path/to/file");
68   g_free (l);
69
70   /* URI */
71   l = gst_uri_get_location ("file:///path/to/file");
72   fail_unless (l != NULL);
73   fail_unless_equals_string (l, "/path/to/file");
74   g_free (l);
75
76   /* unescaping */
77   l = gst_uri_get_location ("file:///path/to/some%20file");
78   fail_unless (l != NULL);
79   fail_unless_equals_string (l, "/path/to/some file");
80   g_free (l);
81 }
82
83 GST_END_TEST;
84
85 #ifndef GST_REMOVE_DEPRECATED
86 GST_START_TEST (test_gst_uri_construct)
87 {
88   gchar *l = NULL;
89
90   /* URI with no protocol or empty protocol should return empty string */
91   ASSERT_CRITICAL (l = gst_uri_construct (NULL, "/path/to/file"));
92   fail_unless (l == NULL);
93   ASSERT_CRITICAL (l = gst_uri_construct ("", "/path/to/file"));
94   fail_unless (l == NULL);
95
96   /* URI with no location should return empty string */
97   ASSERT_CRITICAL (l = gst_uri_construct ("protocol", NULL));
98   fail_unless (l == NULL);
99
100   /* check the protocol for validity */
101   l = gst_uri_construct ("protocol1234567890+-.", "somefile");
102   fail_unless (l != NULL);
103   fail_unless_equals_string (l, "protocol1234567890+-.://somefile");
104   g_free (l);
105
106   /* check the location for correct handling */
107   l = gst_uri_construct ("aprotocol",
108       "/path+ to/some/file%d?akey=aval&key2=val2");
109   fail_unless (l != NULL);
110   fail_unless_equals_string (l,
111       "aprotocol:///path%2B%20to/some/file%25d?akey=aval&key2=val2");
112   g_free (l);
113 }
114
115 GST_END_TEST;
116 #endif
117
118 #ifdef G_OS_WIN32
119
120 GST_START_TEST (test_win32_uri)
121 {
122   gchar *uri, *l;
123
124   uri = g_strdup ("file:///c:/my%20music/foo.ogg");
125   l = gst_uri_get_location (uri);
126   fail_unless (l != NULL);
127   /* fail_unless_equals_string will screw up here in the failure case
128    * because the string constant will be appended to the printf format
129    * message string and contains a '%', that's why we use fail_unless here */
130   fail_unless (g_str_equal (l, "c:/my music/foo.ogg"),
131       "wrong location '%s' returned for URI '%s'", l, uri);
132   g_free (l);
133   g_free (uri);
134
135   /* make sure the other variant with two slashes before the C: (which was
136    * needed before because of a bug in _get_location()) still works */
137   uri = g_strdup ("file://c:/my%20music/foo.ogg");
138   l = gst_uri_get_location (uri);
139   fail_unless (l != NULL);
140   /* fail_unless_equals_string will screw up here in the failure case
141    * because the string constant will be appended to the printf format
142    * message string and contains a '%', that's why we use fail_unless here */
143   fail_unless (g_str_equal (l, "c:/my music/foo.ogg"),
144       "wrong location '%s' returned for URI '%s'", l, uri);
145   g_free (l);
146   g_free (uri);
147 }
148
149 GST_END_TEST;
150
151 #endif /* G_OS_WIN32 */
152
153 GST_START_TEST (test_uri_misc)
154 {
155   /* require at least two characters for the protocol */
156   fail_if (gst_uri_is_valid ("B:\\foo.txt"));
157   fail_if (gst_uri_is_valid ("B:/foo.txt"));
158   fail_if (gst_uri_is_valid ("B://foo.txt"));
159   fail_if (gst_uri_is_valid ("B:foo.txt"));
160
161   fail_unless (gst_uri_is_valid ("fd://0"));
162   fail_unless (gst_uri_is_valid ("AB:\\foo.txt"));
163   fail_unless (gst_uri_is_valid ("AB:/foo.txt"));
164   fail_unless (gst_uri_is_valid ("AB://foo.txt"));
165   fail_unless (gst_uri_is_valid ("AB:foo.txt"));
166
167   fail_unless (gst_uri_is_valid ("ABC:/foo.txt"));
168   fail_unless (gst_uri_is_valid ("ABC://foo.txt"));
169   fail_unless (gst_uri_is_valid ("ABC:foo.txt"));
170
171   fail_unless (gst_uri_is_valid ("ABCD:/foo.txt"));
172   fail_unless (gst_uri_is_valid ("ABCD://foo.txt"));
173   fail_unless (gst_uri_is_valid ("ABCD:foo.txt"));
174 }
175
176 GST_END_TEST;
177
178 GST_START_TEST (test_element_make_from_uri)
179 {
180   GstElement *element;
181   GError *err = NULL;
182
183   element = gst_element_make_from_uri (GST_URI_SRC, "foo://", NULL, NULL);
184   fail_unless (element == NULL);
185
186   element = gst_element_make_from_uri (GST_URI_SRC, "foo://", NULL, &err);
187   fail_unless (element == NULL);
188   fail_unless (err != NULL);
189   fail_unless (err->code == GST_URI_ERROR_UNSUPPORTED_PROTOCOL);
190   g_error_free (err);
191   err = NULL;
192
193   if (gst_registry_check_feature_version (gst_registry_get (), "filesrc",
194           GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO)) {
195     element = gst_element_make_from_uri (GST_URI_SRC, "file://host/foo", NULL,
196         &err);
197     fail_unless (element == NULL);
198     fail_unless (err != NULL);
199     fail_unless (err->code == GST_URI_ERROR_BAD_URI);
200     g_error_free (err);
201     err = NULL;
202   }
203 }
204
205 GST_END_TEST;
206
207 /* Taken from the GNet unit test and extended with other URIs:
208  * https://git.gnome.org/browse/archive/gnet/plain/tests/check/gnet/gneturi.c
209  */
210 struct QueryValue
211 {
212   const gchar *key;
213   const gchar *value;
214 };
215
216 struct URITest
217 {
218   const gchar *str;
219   struct
220   {
221     const gchar *scheme;
222     const gchar *userinfo;
223     const gchar *host;
224     gint port;
225     const gchar *path;
226     /* needs to be updated if more than 10 */
227     struct QueryValue query[10];
228     const gchar *fragment;
229   } uri;
230 };
231
232 #define COMMON_URI_TESTS \
233   /* VALID URIS.  PARSING AND PRINTING OF THESE SHOULD NOT CHANGE */ \
234   /* scheme/path */ \
235   {"scheme:", \
236       {"scheme", NULL, NULL, GST_URI_NO_PORT, NULL, {{NULL, NULL}}, NULL}}, \
237   {"scheme:path", \
238       {"scheme", NULL, NULL, GST_URI_NO_PORT, "path", {{NULL, NULL}}, NULL}}, \
239   {"path", \
240       {NULL, NULL, NULL, GST_URI_NO_PORT, "path", {{NULL, NULL}}, NULL}}, \
241   {"/path", \
242       {NULL, NULL, NULL, GST_URI_NO_PORT, "/path", {{NULL, NULL}}, NULL}}, \
243   /* hostname/port */ \
244   {"scheme://hostname/path", \
245         {"scheme", NULL, "hostname", GST_URI_NO_PORT, "/path", {{NULL, NULL}}, \
246           NULL}}, \
247   {"scheme://hostname:123/path", \
248       {"scheme", NULL, "hostname", 123, "/path", {{NULL, NULL}}, NULL}}, \
249   /* ipv6 hostname/port */ \
250   {"scheme://[01:23:45:67:89:ab:cd:ef]/path", \
251         {"scheme", NULL, "01:23:45:67:89:ab:cd:ef", GST_URI_NO_PORT, "/path", \
252           {{NULL, NULL}}, NULL}}, \
253   {"scheme://[01:23:45:67:89:ab:cd:ef]:123/path", \
254         {"scheme", NULL, "01:23:45:67:89:ab:cd:ef", 123, "/path", {{NULL, \
255                   NULL}}, NULL}}, \
256   /* query/fragment */ \
257   {"path?query", \
258         {NULL, NULL, NULL, GST_URI_NO_PORT, "path", {{"query", NULL}, {NULL, \
259                   NULL}}, NULL}}, \
260   {"path?query=value", \
261         {NULL, NULL, NULL, GST_URI_NO_PORT, "path", {{"query", "value"}, {NULL, \
262                   NULL}}, NULL}}, \
263   {"path?query#fragment", \
264         {NULL, NULL, NULL, GST_URI_NO_PORT, "path", {{"query", NULL}, {NULL, \
265                   NULL}}, "fragment"}}, \
266   {"path?query=value#fragment", \
267         {NULL, NULL, NULL, GST_URI_NO_PORT, "path", {{"query", "value"}, {NULL, \
268                   NULL}}, "fragment"}}, \
269   {"scheme:path?query#fragment", \
270         {"scheme", NULL, NULL, GST_URI_NO_PORT, "path", {{"query", NULL}, {NULL, \
271                   NULL}}, "fragment"}}, \
272   /* full */ \
273   {"scheme://hostname:123/path?query#fragment", \
274         {"scheme", NULL, "hostname", 123, "/path", {{"query", NULL}, {NULL, \
275                   NULL}}, "fragment"}}, \
276   {"scheme://hostname:123/path?query=value#fragment", \
277         {"scheme", NULL, "hostname", 123, "/path", {{"query", "value"}, {NULL, \
278                   NULL}}, "fragment"}}, \
279   {"scheme://hostname:123?query", \
280         {"scheme", NULL, "hostname", 123, NULL, {{"query", NULL}, {NULL, \
281                   NULL}}, NULL}}, \
282   {"scheme://hostname:123?query=value", \
283         {"scheme", NULL, "hostname", 123, NULL, {{"query", "value"}, {NULL, \
284                   NULL}}, NULL}}, \
285   {"scheme://hostname:123?query#fragment", \
286         {"scheme", NULL, "hostname", 123, NULL, {{"query", NULL}, {NULL, \
287                   NULL}}, "fragment"}}, \
288   {"scheme://hostname:123?query=value#fragment", \
289         {"scheme", NULL, "hostname", 123, NULL, {{"query", "value"}, {NULL, \
290                   NULL}}, "fragment"}}, \
291   /* user/pass */ \
292   {"scheme://userinfo@hostname", \
293         {"scheme", "userinfo", "hostname", GST_URI_NO_PORT, NULL, {{NULL, \
294                   NULL}}, NULL}}, \
295   {"scheme://userinfo@hostname:123/path?query#fragment", \
296         {"scheme", "userinfo", "hostname", 123, "/path", {{"query", NULL}, \
297               {NULL, NULL}}, "fragment"}}, \
298   {"scheme://user:pass@hostname", \
299         {"scheme", "user:pass", "hostname", GST_URI_NO_PORT, NULL, {{NULL, \
300                   NULL}}, NULL}}, \
301   {"scheme://user:pass@hostname:123/path?query#fragment", \
302         {"scheme", "user:pass", "hostname", 123, "/path", {{"query", NULL}, \
303               {NULL, NULL}}, "fragment"}}, \
304   /* FUNNY URIS.  PARSING AND PRINTING OF THESE MAY CHANGE */ \
305   {"scheme:hostname:123/path?query#fragment", \
306         {"scheme", NULL, NULL, GST_URI_NO_PORT, "hostname:123/path", {{"query", \
307                   NULL}, {NULL, NULL}}, "fragment"}}, \
308   {"scheme://:pass@hostname:123/path?query#fragment", \
309         {"scheme", ":pass", "hostname", 123, "/path", {{"query", NULL}, {NULL, \
310                   NULL}}, "fragment"}}, \
311   /* Skip initial white space */ \
312   {" \f\n\r\t\vscheme:", \
313       {"scheme", NULL, NULL, GST_URI_NO_PORT, NULL, {{NULL, NULL}}, NULL}}, \
314   {" \f\n\r\t\vpath", \
315       {NULL, NULL, NULL, GST_URI_NO_PORT, "path", {{NULL, NULL}}, NULL}}, \
316   /* file URI */ \
317   {"file://host/home/joe/foo.txt", \
318         {"file", NULL, "host", GST_URI_NO_PORT, "/home/joe/foo.txt", {{NULL, \
319                   NULL}}, NULL}}, \
320   {"file:///home/joe/foo.txt", \
321         {"file", NULL, NULL, GST_URI_NO_PORT, "/home/joe/foo.txt", {{NULL, \
322                   NULL}}, NULL}},
323
324 #define UNESCAPED_URI_TESTS \
325   /* Test cases for gst_uri_from_string */ \
326   {"scheme://user%20info@hostname", \
327         {"scheme", "user info", "hostname", GST_URI_NO_PORT, NULL, {{NULL, \
328                   NULL}}, NULL}}, \
329   {"scheme://userinfo@hostname:123/path?query#frag%23ment", \
330         {"scheme", "userinfo", "hostname", 123, "/path", {{"query", NULL}, \
331               {NULL, NULL}}, "frag#ment"}}, \
332   {"scheme://us%3Aer:pass@hostname", \
333         {"scheme", "us:er:pass", "hostname", GST_URI_NO_PORT, NULL, {{NULL, \
334                   NULL}}, NULL}}, \
335   {"scheme://us%3Aer:pa%3Ass@hostname:123/path?query#frag%23ment", \
336         {"scheme", "us:er:pa:ss", "hostname", 123, "/path", {{"query", NULL}, \
337               {NULL, NULL}}, "frag#ment"}},
338
339 #define ESCAPED_URI_TESTS \
340   /* Test cases for gst_uri_from_string_escaped */ \
341   {"scheme://user%20info@hostname", \
342         {"scheme", "user%20info", "hostname", GST_URI_NO_PORT, NULL, {{NULL, \
343                   NULL}}, NULL}}, \
344   {"scheme://userinfo@hostname:123/path?query#frag%23ment", \
345         {"scheme", "userinfo", "hostname", 123, "/path", {{"query", NULL}, \
346               {NULL, NULL}}, "frag%23ment"}}, \
347   {"scheme://us%3Aer:pass@hostname", \
348         {"scheme", "us%3Aer:pass", "hostname", GST_URI_NO_PORT, NULL, {{NULL, \
349                   NULL}}, NULL}}, \
350   {"scheme://us%3Aer:pa%3Ass@hostname:123/path?query#frag%23ment", \
351         {"scheme", "us%3Aer:pa%3Ass", "hostname", 123, "/path", {{"query", NULL}, \
352               {NULL, NULL}}, "frag%23ment"}},
353
354
355 static const struct URITest tests[] = {
356   COMMON_URI_TESTS UNESCAPED_URI_TESTS
357 };
358
359 static const gchar *unparsable_uri_tests[] = {
360   /* Path not started correctly */
361   "scheme://hostname:123path?query#fragment",
362
363   /* Brackets that don't close */
364   "scheme://[01:23:45:67:89:ab:cd:ef:123/path",
365
366   /* IPv6 hostname without brackets */
367   "scheme://01:23:45:67:89:ab:cd:ef:123/path",
368 };
369
370 GST_START_TEST (test_url_parsing)
371 {
372   GstUri *uri;
373   GList *list;
374   gchar *tmp_str;
375   guint i, j;
376
377   for (i = 0; i < G_N_ELEMENTS (tests); i++) {
378     GST_DEBUG ("Testing URI '%s'", tests[i].str);
379
380     uri = gst_uri_from_string (tests[i].str);
381     fail_unless (uri != NULL);
382     fail_unless_equals_string (gst_uri_get_scheme (uri), tests[i].uri.scheme);
383     fail_unless_equals_string (gst_uri_get_userinfo (uri),
384         tests[i].uri.userinfo);
385     fail_unless_equals_string (gst_uri_get_host (uri), tests[i].uri.host);
386     fail_unless_equals_int (gst_uri_get_port (uri), tests[i].uri.port);
387     tmp_str = gst_uri_get_path (uri);
388     fail_unless_equals_string (tmp_str, tests[i].uri.path);
389     g_free (tmp_str);
390
391     for (j = 0; j < 10; j++) {
392       if (!tests[i].uri.query[j].key)
393         break;
394
395       if (tests[i].uri.query[j].value) {
396         fail_unless_equals_string (gst_uri_get_query_value (uri,
397                 tests[i].uri.query[j].key), tests[i].uri.query[j].value);
398       } else {
399         fail_unless (gst_uri_query_has_key (uri, tests[i].uri.query[j].key));
400       }
401     }
402     list = gst_uri_get_query_keys (uri);
403     fail_unless_equals_int (j, g_list_length (list));
404     g_list_free (list);
405     gst_uri_unref (uri);
406   }
407
408   for (i = 0; i < G_N_ELEMENTS (unparsable_uri_tests); i++) {
409     GST_DEBUG ("Testing unparsable URI '%s'", unparsable_uri_tests[i]);
410
411     uri = gst_uri_from_string (unparsable_uri_tests[i]);
412     fail_unless (uri == NULL);
413   }
414 }
415
416 GST_END_TEST;
417
418
419 static const struct URITest escaped_tests[] = {
420   COMMON_URI_TESTS ESCAPED_URI_TESTS
421 };
422
423 GST_START_TEST (test_url_parsing_escaped)
424 {
425   GstUri *uri;
426   GList *list;
427   gchar *tmp_str;
428   guint i, j;
429
430   for (i = 0; i < G_N_ELEMENTS (escaped_tests); i++) {
431     GST_DEBUG ("Testing URI '%s'", escaped_tests[i].str);
432
433     uri = gst_uri_from_string_escaped (escaped_tests[i].str);
434     fail_unless (uri != NULL);
435     fail_unless_equals_string (gst_uri_get_scheme (uri),
436         escaped_tests[i].uri.scheme);
437     fail_unless_equals_string (gst_uri_get_userinfo (uri),
438         escaped_tests[i].uri.userinfo);
439     fail_unless_equals_string (gst_uri_get_host (uri),
440         escaped_tests[i].uri.host);
441     fail_unless_equals_int (gst_uri_get_port (uri), escaped_tests[i].uri.port);
442     tmp_str = gst_uri_get_path (uri);
443     fail_unless_equals_string (tmp_str, escaped_tests[i].uri.path);
444     g_free (tmp_str);
445
446     for (j = 0; j < 10; j++) {
447       if (!escaped_tests[i].uri.query[j].key)
448         break;
449
450       if (escaped_tests[i].uri.query[j].value) {
451         fail_unless_equals_string (gst_uri_get_query_value (uri,
452                 escaped_tests[i].uri.query[j].key),
453             escaped_tests[i].uri.query[j].value);
454       } else {
455         fail_unless (gst_uri_query_has_key (uri,
456                 escaped_tests[i].uri.query[j].key));
457       }
458     }
459     list = gst_uri_get_query_keys (uri);
460     fail_unless_equals_int (j, g_list_length (list));
461     g_list_free (list);
462     gst_uri_unref (uri);
463   }
464
465   for (i = 0; i < G_N_ELEMENTS (unparsable_uri_tests); i++) {
466     GST_DEBUG ("Testing unparsable URI '%s'", unparsable_uri_tests[i]);
467
468     uri = gst_uri_from_string (unparsable_uri_tests[i]);
469     fail_unless (uri == NULL);
470   }
471 }
472
473 GST_END_TEST;
474
475 static const struct URITest url_presenting_tests[] = {
476   /* check all URI elements present */
477   {.uri = {"scheme", "user:pass", "host", 1234, "/path/to/dir",
478           {{"query", NULL}, {"key", "value"}}, "fragment"},
479       .str =
480       "scheme://user:pass@host:1234/path/to/dir?key=value&query#fragment"},
481   /* IPv6 literal should render in square brackets */
482   {.uri = {"scheme", "user:pass", "12:34:56:78:9a:bc:de:f0", 1234,
483           "/path/to/dir", {{"query", "value"}}, "fragment"},
484       .str =
485       "scheme://user:pass@[12:34:56:78:9a:bc:de:f0]:1234/path/to/dir?query=value#fragment"},
486 };
487
488 GST_START_TEST (test_url_presenting)
489 {
490   GstUri *uri;
491   gchar *result;
492   guint i, j;
493
494   for (i = 0; i < G_N_ELEMENTS (url_presenting_tests); i++) {
495     uri = gst_uri_new (url_presenting_tests[i].uri.scheme,
496         url_presenting_tests[i].uri.userinfo,
497         url_presenting_tests[i].uri.host,
498         url_presenting_tests[i].uri.port,
499         url_presenting_tests[i].uri.path,
500         NULL, url_presenting_tests[i].uri.fragment);
501     fail_unless (uri != NULL);
502     for (j = 0; j < 10; j++) {
503       if (!url_presenting_tests[i].uri.query[j].key)
504         break;
505
506       fail_unless (gst_uri_set_query_value (uri,
507               url_presenting_tests[i].uri.query[j].key,
508               url_presenting_tests[i].uri.query[j].value));
509     }
510
511     result = gst_uri_to_string (uri);
512     fail_unless_equals_string (result, url_presenting_tests[i].str);
513     g_free (result);
514     gst_uri_unref (uri);
515   }
516 }
517
518 GST_END_TEST;
519
520 GST_START_TEST (test_url_normalization)
521 {
522   GstUri *url;
523   gchar *tmp_str;
524
525   url =
526       gst_uri_from_string
527       ("ScHeMe://User:P%61ss@HOST.%63om:1234/path/./from/../to%7d/item%2dobj?qu%65ry=something#fr%61gment");
528   fail_unless (gst_uri_normalize (url));
529   fail_unless_equals_string (gst_uri_get_scheme (url), "scheme");
530   fail_unless_equals_string (gst_uri_get_userinfo (url), "User:Pass");
531   fail_unless_equals_string (gst_uri_get_host (url), "host.com");
532   tmp_str = gst_uri_get_path (url);
533   fail_unless_equals_string (tmp_str, "/path/to}/item-obj");
534   g_free (tmp_str);
535   fail_unless (gst_uri_query_has_key (url, "query"));
536   fail_unless_equals_string (gst_uri_get_query_value (url, "query"),
537       "something");
538   fail_unless_equals_string (gst_uri_get_fragment (url), "fragment");
539   gst_uri_unref (url);
540 }
541
542 GST_END_TEST;
543
544 GST_START_TEST (test_url_joining)
545 {
546   GstUri *base, *rel, *joined;
547   gchar *l;
548
549   base =
550       gst_uri_from_string
551       ("http://example.com/path/to/dir/filename.html#fragment");
552
553   /* test change of fragment only */
554   rel = gst_uri_from_string ("#new_frag");
555   joined = gst_uri_join (base, rel);
556   l = gst_uri_to_string (joined);
557   fail_unless_equals_string (l,
558       "http://example.com/path/to/dir/filename.html#new_frag");
559   g_free (l);
560   gst_uri_unref (joined);
561   gst_uri_unref (rel);
562
563   /* test addition of new query string */
564   rel = gst_uri_from_string ("?key=val");
565   joined = gst_uri_join (base, rel);
566   l = gst_uri_to_string (joined);
567   fail_unless_equals_string (l,
568       "http://example.com/path/to/dir/filename.html?key=val");
569   g_free (l);
570   gst_uri_unref (joined);
571   gst_uri_unref (rel);
572
573   /* test new base filename */
574   rel = gst_uri_from_string ("new_filename.xml");
575   joined = gst_uri_join (base, rel);
576   l = gst_uri_to_string (joined);
577   fail_unless_equals_string (l,
578       "http://example.com/path/to/dir/new_filename.xml");
579   g_free (l);
580   gst_uri_unref (joined);
581   gst_uri_unref (rel);
582
583   /* test relative file same directory */
584   rel = gst_uri_from_string ("./new_filename.xml");
585   joined = gst_uri_join (base, rel);
586   l = gst_uri_to_string (joined);
587   fail_unless_equals_string (l,
588       "http://example.com/path/to/dir/new_filename.xml");
589   g_free (l);
590   gst_uri_unref (joined);
591   gst_uri_unref (rel);
592
593   /* test relative file parent directory */
594   rel = gst_uri_from_string ("../new_filename.xml");
595   joined = gst_uri_join (base, rel);
596   l = gst_uri_to_string (joined);
597   fail_unless_equals_string (l, "http://example.com/path/to/new_filename.xml");
598   g_free (l);
599   gst_uri_unref (joined);
600   gst_uri_unref (rel);
601
602   /* test relative file grandparent directory */
603   rel = gst_uri_from_string ("../../new_filename.xml");
604   joined = gst_uri_join (base, rel);
605   l = gst_uri_to_string (joined);
606   fail_unless_equals_string (l, "http://example.com/path/new_filename.xml");
607   g_free (l);
608   gst_uri_unref (joined);
609   gst_uri_unref (rel);
610
611   /* test relative file root directory */
612   rel = gst_uri_from_string ("../../../new_filename.xml");
613   joined = gst_uri_join (base, rel);
614   l = gst_uri_to_string (joined);
615   fail_unless_equals_string (l, "http://example.com/new_filename.xml");
616   g_free (l);
617   gst_uri_unref (joined);
618   gst_uri_unref (rel);
619
620   /* test relative file beyond root directory */
621   rel = gst_uri_from_string ("../../../../new_filename.xml");
622   joined = gst_uri_join (base, rel);
623   l = gst_uri_to_string (joined);
624   fail_unless_equals_string (l, "http://example.com/new_filename.xml");
625   g_free (l);
626   gst_uri_unref (joined);
627   gst_uri_unref (rel);
628
629   /* test add subdirectory */
630   rel = gst_uri_from_string ("subdir/new_filename.xml");
631   joined = gst_uri_join (base, rel);
632   l = gst_uri_to_string (joined);
633   fail_unless_equals_string (l,
634       "http://example.com/path/to/dir/subdir/new_filename.xml");
635   g_free (l);
636   gst_uri_unref (joined);
637   gst_uri_unref (rel);
638
639   /* test change directory */
640   rel = gst_uri_from_string ("../subdir/new_filename.xml");
641   joined = gst_uri_join (base, rel);
642   l = gst_uri_to_string (joined);
643   fail_unless_equals_string (l,
644       "http://example.com/path/to/subdir/new_filename.xml");
645   g_free (l);
646   gst_uri_unref (joined);
647   gst_uri_unref (rel);
648
649   gst_uri_unref (base);
650
651   /* change base for path ending in directory */
652   base = gst_uri_from_string ("http://example.com/path/to/dir/");
653
654   /* test adding file to directory */
655   rel = gst_uri_from_string ("new_filename.xml");
656   joined = gst_uri_join (base, rel);
657   l = gst_uri_to_string (joined);
658   fail_unless_equals_string (l,
659       "http://example.com/path/to/dir/new_filename.xml");
660   g_free (l);
661   gst_uri_unref (joined);
662   gst_uri_unref (rel);
663
664   /* test adding file to directory using relative path */
665   rel = gst_uri_from_string ("./new_filename.xml");
666   joined = gst_uri_join (base, rel);
667   l = gst_uri_to_string (joined);
668   fail_unless_equals_string (l,
669       "http://example.com/path/to/dir/new_filename.xml");
670   g_free (l);
671   gst_uri_unref (joined);
672   gst_uri_unref (rel);
673
674   /* test filename in parent directory */
675   rel = gst_uri_from_string ("../new_filename.xml");
676   joined = gst_uri_join (base, rel);
677   l = gst_uri_to_string (joined);
678   fail_unless_equals_string (l, "http://example.com/path/to/new_filename.xml");
679   g_free (l);
680   gst_uri_unref (joined);
681   gst_uri_unref (rel);
682
683   /* test path ending in '../' */
684   rel = gst_uri_from_string ("one/two/../");
685   joined = gst_uri_join (base, rel);
686   l = gst_uri_to_string (joined);
687   fail_unless_equals_string (l, "http://example.com/path/to/dir/one/");
688   g_free (l);
689   gst_uri_unref (joined);
690   gst_uri_unref (rel);
691
692   /* test path ending in '..' Result should be the same as when ending in '../' */
693   rel = gst_uri_from_string ("one/two/..");
694   joined = gst_uri_join (base, rel);
695   l = gst_uri_to_string (joined);
696   fail_unless_equals_string (l, "http://example.com/path/to/dir/one/");
697   g_free (l);
698   gst_uri_unref (joined);
699   gst_uri_unref (rel);
700
701   /* test replace with absolute */
702   rel = gst_uri_from_string ("https://ssl.example.com/new_filename.xml");
703   joined = gst_uri_join (base, rel);
704   l = gst_uri_to_string (joined);
705   fail_unless_equals_string (l, "https://ssl.example.com/new_filename.xml");
706   g_free (l);
707   gst_uri_unref (joined);
708   gst_uri_unref (rel);
709
710   gst_uri_unref (base);
711 }
712
713 GST_END_TEST;
714
715 GST_START_TEST (test_url_equality)
716 {
717   GstUri *url1, *url2;
718
719   url1 =
720       gst_uri_from_string
721       ("ScHeMe://User:Pass@HOST.com:1234/path/./from/../to%7d/item%2dobj?query=something#fragment");
722
723   /* equal */
724   url2 =
725       gst_uri_from_string
726       ("scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=something#fragment");
727   fail_unless (gst_uri_equal (url1, url2));
728   fail_unless (gst_uri_equal (url2, url1));
729   gst_uri_unref (url2);
730
731   /* different fragment */
732   url2 =
733       gst_uri_from_string
734       ("scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=something#different-fragment");
735   fail_unless (!gst_uri_equal (url1, url2));
736   gst_uri_unref (url2);
737
738   /* different query */
739   url2 =
740       gst_uri_from_string
741       ("scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=different-something#fragment");
742   fail_unless (!gst_uri_equal (url1, url2));
743   gst_uri_unref (url2);
744
745   /* different path */
746   url2 =
747       gst_uri_from_string
748       ("scheme://User:Pass@host.com:1234/path/to%7D/different-item-obj?query=something#fragment");
749   fail_unless (!gst_uri_equal (url1, url2));
750   gst_uri_unref (url2);
751
752   /* different port */
753   url2 =
754       gst_uri_from_string
755       ("scheme://User:Pass@host.com:4321/path/to%7D/item-obj?query=something#fragment");
756   fail_unless (!gst_uri_equal (url1, url2));
757   gst_uri_unref (url2);
758
759   /* different host */
760   url2 =
761       gst_uri_from_string
762       ("scheme://User:Pass@different-host.com:1234/path/to%7D/item-obj?query=something#fragment");
763   fail_unless (!gst_uri_equal (url1, url2));
764   gst_uri_unref (url2);
765
766   /* different userinfo */
767   url2 =
768       gst_uri_from_string
769       ("scheme://Different-User:Pass@host.com:1234/path/to%7D/item-obj?query=something#fragment");
770   fail_unless (!gst_uri_equal (url1, url2));
771   gst_uri_unref (url2);
772
773   /* different scheme */
774   url2 =
775       gst_uri_from_string
776       ("different+scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=something#fragment");
777   fail_unless (!gst_uri_equal (url1, url2));
778   gst_uri_unref (url2);
779
780   /* different (no scheme) */
781   url2 =
782       gst_uri_from_string
783       ("//User:Pass@host.com:1234/path/to%7D/item-obj?query=something#fragment");
784   fail_unless (!gst_uri_equal (url1, url2));
785   gst_uri_unref (url2);
786
787   /* different (no userinfo) */
788   url2 =
789       gst_uri_from_string
790       ("scheme://host.com:1234/path/to%7D/item-obj?query=something#fragment");
791   fail_unless (!gst_uri_equal (url1, url2));
792   gst_uri_unref (url2);
793
794   /* different (no host) */
795   url2 =
796       gst_uri_from_string
797       ("scheme://User:Pass@:1234/path/to%7D/item-obj?query=something#fragment");
798   fail_unless (!gst_uri_equal (url1, url2));
799   gst_uri_unref (url2);
800
801   /* different (no port) */
802   url2 =
803       gst_uri_from_string
804       ("scheme://User:Pass@host.com/path/to%7D/item-obj?query=something#fragment");
805   fail_unless (!gst_uri_equal (url1, url2));
806   gst_uri_unref (url2);
807
808   /* different (no path) */
809   url2 =
810       gst_uri_from_string
811       ("scheme://User:Pass@host.com:1234?query=something#fragment");
812   fail_unless (!gst_uri_equal (url1, url2));
813   gst_uri_unref (url2);
814
815   /* different (no query) */
816   url2 =
817       gst_uri_from_string
818       ("scheme://User:Pass@host.com:1234/path/to%7D/item-obj#fragment");
819   fail_unless (!gst_uri_equal (url1, url2));
820   gst_uri_unref (url2);
821
822   /* different (no fragment) */
823   url2 =
824       gst_uri_from_string
825       ("scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=something");
826   fail_unless (!gst_uri_equal (url1, url2));
827   gst_uri_unref (url2);
828
829   /* compare two NULL uris */
830   fail_unless (gst_uri_equal (NULL, NULL));
831
832   /* compare same object */
833   fail_unless (gst_uri_equal (url1, url1));
834
835   /* compare one NULL and one non-NULL uri */
836   fail_unless (!gst_uri_equal (url1, NULL));
837   fail_unless (!gst_uri_equal (NULL, url1));
838
839   gst_uri_unref (url1);
840 }
841
842 GST_END_TEST;
843
844 GST_START_TEST (test_url_constructors)
845 {
846   GstUri *url1, *url2;
847   gchar *tmp_str;
848   GHashTable *tmp_table;
849
850   url1 =
851       gst_uri_new ("scheme", "userinfo", "hostname", 1234, "/path/to/file",
852       "query", "fragment");
853   fail_unless_equals_string (gst_uri_get_scheme (url1), "scheme");
854   fail_unless_equals_string (gst_uri_get_userinfo (url1), "userinfo");
855   fail_unless_equals_string (gst_uri_get_host (url1), "hostname");
856   fail_unless (gst_uri_get_port (url1) == 1234);
857   tmp_str = gst_uri_get_path (url1);
858   fail_unless_equals_string (tmp_str, "/path/to/file");
859   g_free (tmp_str);
860   tmp_table = gst_uri_get_query_table (url1);
861   fail_unless (g_hash_table_size (tmp_table) == 1);
862   fail_unless (g_hash_table_contains (tmp_table, "query"));
863   fail_unless (g_hash_table_lookup (tmp_table, "query") == NULL);
864   g_hash_table_unref (tmp_table);
865   fail_unless_equals_string (gst_uri_get_fragment (url1), "fragment");
866   tmp_str = gst_uri_to_string (url1);
867   fail_unless_equals_string (tmp_str,
868       "scheme://userinfo@hostname:1234/path/to/file?query#fragment");
869   g_free (tmp_str);
870
871   url2 =
872       gst_uri_new_with_base (url1, NULL, NULL, NULL, GST_URI_NO_PORT,
873       "new_file", NULL, NULL);
874   fail_unless_equals_string (gst_uri_get_scheme (url2), "scheme");
875   fail_unless_equals_string (gst_uri_get_userinfo (url2), "userinfo");
876   fail_unless_equals_string (gst_uri_get_host (url2), "hostname");
877   fail_unless (gst_uri_get_port (url2) == 1234);
878   tmp_str = gst_uri_get_path (url2);
879   fail_unless_equals_string (tmp_str, "/path/to/new_file");
880   g_free (tmp_str);
881   fail_unless (gst_uri_get_query_table (url2) == NULL);
882   fail_unless (gst_uri_get_fragment (url2) == NULL);
883   tmp_str = gst_uri_to_string (url2);
884   fail_unless_equals_string (tmp_str,
885       "scheme://userinfo@hostname:1234/path/to/new_file");
886   g_free (tmp_str);
887   gst_uri_unref (url2);
888
889   url2 = gst_uri_from_string_with_base (url1, "/a/new/path/to/file");
890   fail_unless_equals_string (gst_uri_get_scheme (url2), "scheme");
891   fail_unless_equals_string (gst_uri_get_userinfo (url2), "userinfo");
892   fail_unless_equals_string (gst_uri_get_host (url2), "hostname");
893   fail_unless (gst_uri_get_port (url2) == 1234);
894   tmp_str = gst_uri_get_path (url2);
895   fail_unless_equals_string (tmp_str, "/a/new/path/to/file");
896   g_free (tmp_str);
897   fail_unless (gst_uri_get_query_table (url2) == NULL);
898   fail_unless (gst_uri_get_fragment (url2) == NULL);
899   tmp_str = gst_uri_to_string (url2);
900   fail_unless_equals_string (tmp_str,
901       "scheme://userinfo@hostname:1234/a/new/path/to/file");
902   g_free (tmp_str);
903   gst_uri_unref (url2);
904
905   url2 = gst_uri_from_string_with_base (url1, "http://foobar.com/bla");
906   fail_unless_equals_string (gst_uri_get_scheme (url2), "http");
907   fail_unless_equals_string (gst_uri_get_host (url2), "foobar.com");
908   fail_unless (gst_uri_get_port (url2) == 0);
909   tmp_str = gst_uri_get_path (url2);
910   fail_unless_equals_string (tmp_str, "/bla");
911   g_free (tmp_str);
912   fail_unless (gst_uri_get_query_table (url2) == NULL);
913   fail_unless (gst_uri_get_fragment (url2) == NULL);
914   tmp_str = gst_uri_to_string (url2);
915   fail_unless_equals_string (tmp_str, "http://foobar.com/bla");
916   g_free (tmp_str);
917   gst_uri_unref (url2);
918
919   url2 = gst_uri_copy (url1);
920   fail_unless (gst_uri_equal (url1, url2));
921   fail_unless (gst_uri_set_query_value (url2, "key", "value"));
922   fail_unless (!gst_uri_equal (url1, url2));
923   gst_uri_unref (url2);
924
925   gst_uri_unref (url1);
926 }
927
928 GST_END_TEST;
929
930 GST_START_TEST (test_url_get_set)
931 {
932   GstUri *url;
933   gchar *tmp_str;
934   GList *tmp_list;
935
936   url = gst_uri_from_string ("scheme://hostname/path/to/file?query#fragment");
937
938   fail_unless (gst_uri_set_scheme (url, "new+scheme"));
939   fail_unless_equals_string (gst_uri_get_scheme (url), "new+scheme");
940   tmp_str = gst_uri_to_string (url);
941   fail_unless_equals_string (tmp_str,
942       "new+scheme://hostname/path/to/file?query#fragment");
943   g_free (tmp_str);
944
945   fail_unless (gst_uri_set_scheme (url, NULL));
946   fail_unless (gst_uri_get_scheme (url) == NULL);
947   tmp_str = gst_uri_to_string (url);
948   fail_unless_equals_string (tmp_str, "//hostname/path/to/file?query#fragment");
949   g_free (tmp_str);
950
951   fail_unless (!gst_uri_set_scheme (NULL, "fail"));
952   fail_unless (gst_uri_set_scheme (NULL, NULL));
953
954   fail_unless (gst_uri_set_userinfo (url, "username:password"));
955   fail_unless_equals_string (gst_uri_get_userinfo (url), "username:password");
956   tmp_str = gst_uri_to_string (url);
957   fail_unless_equals_string (tmp_str,
958       "//username:password@hostname/path/to/file?query#fragment");
959   g_free (tmp_str);
960
961   fail_unless (gst_uri_set_userinfo (url, NULL));
962   fail_unless (gst_uri_get_userinfo (url) == NULL);
963   tmp_str = gst_uri_to_string (url);
964   fail_unless_equals_string (tmp_str, "//hostname/path/to/file?query#fragment");
965   g_free (tmp_str);
966
967   fail_unless (!gst_uri_set_userinfo (NULL, "fail"));
968   fail_unless (gst_uri_set_userinfo (NULL, NULL));
969
970   fail_unless (gst_uri_set_host (url, NULL));
971   fail_unless (gst_uri_get_host (url) == NULL);
972   tmp_str = gst_uri_to_string (url);
973   fail_unless_equals_string (tmp_str, "/path/to/file?query#fragment");
974   g_free (tmp_str);
975
976   fail_unless (gst_uri_set_host (url, "example.com"));
977   fail_unless_equals_string (gst_uri_get_host (url), "example.com");
978   tmp_str = gst_uri_to_string (url);
979   fail_unless_equals_string (tmp_str,
980       "//example.com/path/to/file?query#fragment");
981   g_free (tmp_str);
982
983   fail_unless (!gst_uri_set_host (NULL, "fail"));
984   fail_unless (gst_uri_set_host (NULL, NULL));
985
986   fail_unless (gst_uri_set_port (url, 12345));
987   fail_unless (gst_uri_get_port (url) == 12345);
988   tmp_str = gst_uri_to_string (url);
989   fail_unless_equals_string (tmp_str,
990       "//example.com:12345/path/to/file?query#fragment");
991   g_free (tmp_str);
992
993   fail_unless (gst_uri_set_port (url, GST_URI_NO_PORT));
994   fail_unless (gst_uri_get_port (url) == GST_URI_NO_PORT);
995   tmp_str = gst_uri_to_string (url);
996   fail_unless_equals_string (tmp_str,
997       "//example.com/path/to/file?query#fragment");
998   g_free (tmp_str);
999
1000   fail_unless (!gst_uri_set_port (NULL, 1234));
1001   fail_unless (gst_uri_set_port (NULL, GST_URI_NO_PORT));
1002
1003   fail_unless (gst_uri_append_path_segment (url, "here"));
1004   tmp_str = gst_uri_to_string (url);
1005   fail_unless_equals_string (tmp_str,
1006       "//example.com/path/to/file/here?query#fragment");
1007   g_free (tmp_str);
1008
1009   fail_unless (!gst_uri_append_path_segment (NULL, "fail"));
1010   fail_unless (gst_uri_append_path_segment (NULL, NULL));
1011
1012   fail_unless (gst_uri_append_path (url, "../there"));
1013   tmp_str = gst_uri_to_string (url);
1014   fail_unless_equals_string (tmp_str,
1015       "//example.com/path/to/file/here/../there?query#fragment");
1016   g_free (tmp_str);
1017
1018   fail_unless (!gst_uri_append_path (NULL, "fail"));
1019   fail_unless (gst_uri_append_path (NULL, NULL));
1020
1021   gst_uri_normalize (url);
1022
1023   tmp_list = gst_uri_get_path_segments (url);
1024   fail_unless (tmp_list != NULL);
1025   tmp_list = g_list_append (tmp_list, g_strdup ("segment"));
1026   tmp_str = gst_uri_to_string (url);
1027   fail_unless_equals_string (tmp_str,
1028       "//example.com/path/to/file/there?query#fragment");
1029   g_free (tmp_str);
1030   fail_unless (gst_uri_set_path_segments (url, tmp_list));
1031   tmp_str = gst_uri_to_string (url);
1032   fail_unless_equals_string (tmp_str,
1033       "//example.com/path/to/file/there/segment?query#fragment");
1034   g_free (tmp_str);
1035
1036   tmp_list = g_list_append (NULL, g_strdup ("test"));
1037   fail_unless (!gst_uri_set_path_segments (NULL, tmp_list));
1038   fail_unless (gst_uri_set_path_segments (NULL, NULL));
1039
1040   fail_unless (gst_uri_set_query_value (url, "key", "value"));
1041   tmp_str = gst_uri_to_string (url);
1042   fail_unless_equals_string (tmp_str,
1043       "//example.com/path/to/file/there/segment?key=value&query#fragment");
1044   g_free (tmp_str);
1045
1046   fail_unless (gst_uri_set_query_value (url, "key", NULL));
1047   tmp_str = gst_uri_to_string (url);
1048   fail_unless_equals_string (tmp_str,
1049       "//example.com/path/to/file/there/segment?key&query#fragment");
1050   g_free (tmp_str);
1051
1052   fail_unless (!gst_uri_set_query_value (NULL, "key", "value"));
1053
1054   fail_unless (gst_uri_remove_query_key (url, "key"));
1055   tmp_str = gst_uri_to_string (url);
1056   fail_unless_equals_string (tmp_str,
1057       "//example.com/path/to/file/there/segment?query#fragment");
1058   g_free (tmp_str);
1059
1060   fail_unless (!gst_uri_remove_query_key (url, "key"));
1061   fail_unless (!gst_uri_remove_query_key (NULL, "key"));
1062
1063   fail_unless (gst_uri_set_fragment (url, NULL));
1064   fail_unless (gst_uri_get_fragment (url) == NULL);
1065   tmp_str = gst_uri_to_string (url);
1066   fail_unless_equals_string (tmp_str,
1067       "//example.com/path/to/file/there/segment?query");
1068   g_free (tmp_str);
1069
1070   fail_unless (gst_uri_set_fragment (url, "tag"));
1071   fail_unless_equals_string (gst_uri_get_fragment (url), "tag");
1072   tmp_str = gst_uri_to_string (url);
1073   fail_unless_equals_string (tmp_str,
1074       "//example.com/path/to/file/there/segment?query#tag");
1075   g_free (tmp_str);
1076
1077   fail_unless (!gst_uri_set_fragment (NULL, "can't set if no URI"));
1078   fail_unless (gst_uri_set_fragment (NULL, NULL));
1079
1080   gst_uri_unref (url);
1081 }
1082
1083 GST_END_TEST;
1084
1085 GST_START_TEST (test_url_get_media_fragment_table)
1086 {
1087   GstUri *url;
1088   gchar *val;
1089   GHashTable *table;
1090
1091   /* Examples at https://www.w3.org/TR/media-frags/#processing-media-fragment-uri */
1092
1093   /* TEST "t=1" */
1094   url = gst_uri_from_string ("http://foo/var/file#t=1");
1095   table = gst_uri_get_media_fragment_table (url);
1096   fail_unless (table);
1097   fail_unless (g_hash_table_size (table) == 1);
1098   fail_unless (g_hash_table_lookup_extended (table, "t", NULL,
1099           (gpointer) & val));
1100   fail_unless_equals_string ("1", val);
1101   g_hash_table_unref (table);
1102   gst_uri_unref (url);
1103
1104   /* NOTE: Media Fragments URI 1.0 (W3C) is saying that
1105    * "Multiple occurrences of the same dimension: only the last valid occurrence
1106    *  of a dimension (e.g. t=10 in #t=2&t=10) is interpreted and all previous
1107    *  occurrences (valid or invalid) SHOULD be ignored by the user agent"
1108    */
1109   /* TEST "t=1&t=2" */
1110   url = gst_uri_from_string ("http://foo/var/file#t=1&t=2");
1111   table = gst_uri_get_media_fragment_table (url);
1112   fail_unless (table);
1113   fail_unless (g_hash_table_size (table) == 1);
1114   fail_unless (g_hash_table_lookup_extended (table, "t", NULL,
1115           (gpointer) & val));
1116   fail_unless_equals_string ("2", val);
1117   g_hash_table_unref (table);
1118   gst_uri_unref (url);
1119
1120   /* TEST "a=b=c" */
1121   url = gst_uri_from_string ("http://foo/var/file#a=b=c");
1122   table = gst_uri_get_media_fragment_table (url);
1123   fail_unless (table);
1124   fail_unless (g_hash_table_size (table) == 1);
1125   fail_unless (g_hash_table_lookup_extended (table, "a", NULL,
1126           (gpointer) & val));
1127   fail_unless_equals_string ("b=c", val);
1128   g_hash_table_unref (table);
1129   gst_uri_unref (url);
1130
1131   /* TEST "a&b=c" */
1132   url = gst_uri_from_string ("http://foo/var/file#a&b=c");
1133   table = gst_uri_get_media_fragment_table (url);
1134   fail_unless (table);
1135   fail_unless (g_hash_table_size (table) == 2);
1136   fail_unless (g_hash_table_lookup_extended (table, "a", NULL,
1137           (gpointer) & val));
1138   fail_unless (val == NULL);
1139   fail_unless (g_hash_table_lookup_extended (table, "b", NULL,
1140           (gpointer) & val));
1141   fail_unless_equals_string ("c", val);
1142   g_hash_table_unref (table);
1143   gst_uri_unref (url);
1144
1145   /* TEST "%74=%6ept%3A%310" */
1146   url = gst_uri_from_string ("http://foo/var/file#%74=%6ept%3A%310");
1147   table = gst_uri_get_media_fragment_table (url);
1148   fail_unless (table);
1149   fail_unless (g_hash_table_size (table) == 1);
1150   fail_unless (g_hash_table_lookup_extended (table, "t", NULL,
1151           (gpointer) & val));
1152   fail_unless_equals_string ("npt:10", val);
1153   g_hash_table_unref (table);
1154   gst_uri_unref (url);
1155 }
1156
1157 GST_END_TEST;
1158
1159 GST_START_TEST (test_url_unescape_equals_in_http_query)
1160 {
1161   GstUri *url;
1162   gchar *query_string;
1163
1164   url =
1165       gst_uri_from_string
1166       ("http://abc.manifest?token=exp=123~acl=/QualityLevels(*~hmac=0cb");
1167
1168   fail_unless_equals_string (gst_uri_get_scheme (url), "http");
1169   query_string = gst_uri_get_query_string (url);
1170   fail_unless_equals_string (query_string,
1171       "token=exp=123~acl=/QualityLevels(*~hmac=0cb");
1172   g_free (query_string);
1173   fail_unless (gst_uri_query_has_key (url, "token"));
1174   fail_unless_equals_string (gst_uri_get_query_value (url, "token"),
1175       "exp=123~acl=/QualityLevels(*~hmac=0cb");
1176   gst_uri_unref (url);
1177 }
1178
1179 GST_END_TEST;
1180
1181 static Suite *
1182 gst_uri_suite (void)
1183 {
1184   Suite *s = suite_create ("GstURI");
1185   TCase *tc_chain = tcase_create ("uri");
1186
1187   tcase_set_timeout (tc_chain, 20);
1188
1189   suite_add_tcase (s, tc_chain);
1190   tcase_add_test (tc_chain, test_protocol_case);
1191   tcase_add_test (tc_chain, test_uri_get_location);
1192 #ifndef GST_REMOVE_DEPRECATED
1193   tcase_add_test (tc_chain, test_gst_uri_construct);
1194 #endif
1195   tcase_add_test (tc_chain, test_uri_misc);
1196   tcase_add_test (tc_chain, test_element_make_from_uri);
1197 #ifdef G_OS_WIN32
1198   tcase_add_test (tc_chain, test_win32_uri);
1199 #endif
1200   tcase_add_test (tc_chain, test_url_parsing);
1201   tcase_add_test (tc_chain, test_url_parsing_escaped);
1202   tcase_add_test (tc_chain, test_url_presenting);
1203   tcase_add_test (tc_chain, test_url_normalization);
1204   tcase_add_test (tc_chain, test_url_joining);
1205   tcase_add_test (tc_chain, test_url_equality);
1206   tcase_add_test (tc_chain, test_url_constructors);
1207   tcase_add_test (tc_chain, test_url_get_set);
1208   tcase_add_test (tc_chain, test_url_get_media_fragment_table);
1209   tcase_add_test (tc_chain, test_url_unescape_equals_in_http_query);
1210
1211   return s;
1212 }
1213
1214 GST_CHECK_MAIN (gst_uri);