Move files from gstreamer into the "subprojects/gstreamer/" subdir
[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 #if GLIB_CHECK_VERSION(2, 59, 0)
481       "scheme://user:pass@host:1234/path/to/dir?key=value&query#fragment"},
482 #else
483       "scheme://user:pass@host:1234/path/to/dir?query&key=value#fragment"},
484 #endif
485
486   /* IPv6 literal should render in square brackets */
487   {.uri = {"scheme", "user:pass", "12:34:56:78:9a:bc:de:f0", 1234,
488           "/path/to/dir", {{"query", "value"}}, "fragment"},
489       .str =
490       "scheme://user:pass@[12:34:56:78:9a:bc:de:f0]:1234/path/to/dir?query=value#fragment"},
491 };
492
493 GST_START_TEST (test_url_presenting)
494 {
495   GstUri *uri;
496   gchar *result;
497   guint i, j;
498
499   for (i = 0; i < G_N_ELEMENTS (url_presenting_tests); i++) {
500     uri = gst_uri_new (url_presenting_tests[i].uri.scheme,
501         url_presenting_tests[i].uri.userinfo,
502         url_presenting_tests[i].uri.host,
503         url_presenting_tests[i].uri.port,
504         url_presenting_tests[i].uri.path,
505         NULL, url_presenting_tests[i].uri.fragment);
506     fail_unless (uri != NULL);
507     for (j = 0; j < 10; j++) {
508       if (!url_presenting_tests[i].uri.query[j].key)
509         break;
510
511       fail_unless (gst_uri_set_query_value (uri,
512               url_presenting_tests[i].uri.query[j].key,
513               url_presenting_tests[i].uri.query[j].value));
514     }
515
516     result = gst_uri_to_string (uri);
517     fail_unless_equals_string (result, url_presenting_tests[i].str);
518     g_free (result);
519     gst_uri_unref (uri);
520   }
521 }
522
523 GST_END_TEST;
524
525 GST_START_TEST (test_url_normalization)
526 {
527   GstUri *url;
528   gchar *tmp_str;
529
530   url =
531       gst_uri_from_string
532       ("ScHeMe://User:P%61ss@HOST.%63om:1234/path/./from/../to%7d/item%2dobj?qu%65ry=something#fr%61gment");
533   fail_unless (gst_uri_normalize (url));
534   fail_unless_equals_string (gst_uri_get_scheme (url), "scheme");
535   fail_unless_equals_string (gst_uri_get_userinfo (url), "User:Pass");
536   fail_unless_equals_string (gst_uri_get_host (url), "host.com");
537   tmp_str = gst_uri_get_path (url);
538   fail_unless_equals_string (tmp_str, "/path/to}/item-obj");
539   g_free (tmp_str);
540   fail_unless (gst_uri_query_has_key (url, "query"));
541   fail_unless_equals_string (gst_uri_get_query_value (url, "query"),
542       "something");
543   fail_unless_equals_string (gst_uri_get_fragment (url), "fragment");
544   gst_uri_unref (url);
545 }
546
547 GST_END_TEST;
548
549 GST_START_TEST (test_url_joining)
550 {
551   GstUri *base, *rel, *joined;
552   gchar *l;
553
554   base =
555       gst_uri_from_string
556       ("http://example.com/path/to/dir/filename.html#fragment");
557
558   /* test change of fragment only */
559   rel = gst_uri_from_string ("#new_frag");
560   joined = gst_uri_join (base, rel);
561   l = gst_uri_to_string (joined);
562   fail_unless_equals_string (l,
563       "http://example.com/path/to/dir/filename.html#new_frag");
564   g_free (l);
565   gst_uri_unref (joined);
566   gst_uri_unref (rel);
567
568   /* test addition of new query string */
569   rel = gst_uri_from_string ("?key=val");
570   joined = gst_uri_join (base, rel);
571   l = gst_uri_to_string (joined);
572   fail_unless_equals_string (l,
573       "http://example.com/path/to/dir/filename.html?key=val");
574   g_free (l);
575   gst_uri_unref (joined);
576   gst_uri_unref (rel);
577
578   /* test new base filename */
579   rel = gst_uri_from_string ("new_filename.xml");
580   joined = gst_uri_join (base, rel);
581   l = gst_uri_to_string (joined);
582   fail_unless_equals_string (l,
583       "http://example.com/path/to/dir/new_filename.xml");
584   g_free (l);
585   gst_uri_unref (joined);
586   gst_uri_unref (rel);
587
588   /* test relative file same directory */
589   rel = gst_uri_from_string ("./new_filename.xml");
590   joined = gst_uri_join (base, rel);
591   l = gst_uri_to_string (joined);
592   fail_unless_equals_string (l,
593       "http://example.com/path/to/dir/new_filename.xml");
594   g_free (l);
595   gst_uri_unref (joined);
596   gst_uri_unref (rel);
597
598   /* test relative file parent directory */
599   rel = gst_uri_from_string ("../new_filename.xml");
600   joined = gst_uri_join (base, rel);
601   l = gst_uri_to_string (joined);
602   fail_unless_equals_string (l, "http://example.com/path/to/new_filename.xml");
603   g_free (l);
604   gst_uri_unref (joined);
605   gst_uri_unref (rel);
606
607   /* test relative file grandparent directory */
608   rel = gst_uri_from_string ("../../new_filename.xml");
609   joined = gst_uri_join (base, rel);
610   l = gst_uri_to_string (joined);
611   fail_unless_equals_string (l, "http://example.com/path/new_filename.xml");
612   g_free (l);
613   gst_uri_unref (joined);
614   gst_uri_unref (rel);
615
616   /* test relative file root directory */
617   rel = gst_uri_from_string ("../../../new_filename.xml");
618   joined = gst_uri_join (base, rel);
619   l = gst_uri_to_string (joined);
620   fail_unless_equals_string (l, "http://example.com/new_filename.xml");
621   g_free (l);
622   gst_uri_unref (joined);
623   gst_uri_unref (rel);
624
625   /* test relative file beyond root directory */
626   rel = gst_uri_from_string ("../../../../new_filename.xml");
627   joined = gst_uri_join (base, rel);
628   l = gst_uri_to_string (joined);
629   fail_unless_equals_string (l, "http://example.com/new_filename.xml");
630   g_free (l);
631   gst_uri_unref (joined);
632   gst_uri_unref (rel);
633
634   /* test add subdirectory */
635   rel = gst_uri_from_string ("subdir/new_filename.xml");
636   joined = gst_uri_join (base, rel);
637   l = gst_uri_to_string (joined);
638   fail_unless_equals_string (l,
639       "http://example.com/path/to/dir/subdir/new_filename.xml");
640   g_free (l);
641   gst_uri_unref (joined);
642   gst_uri_unref (rel);
643
644   /* test change directory */
645   rel = gst_uri_from_string ("../subdir/new_filename.xml");
646   joined = gst_uri_join (base, rel);
647   l = gst_uri_to_string (joined);
648   fail_unless_equals_string (l,
649       "http://example.com/path/to/subdir/new_filename.xml");
650   g_free (l);
651   gst_uri_unref (joined);
652   gst_uri_unref (rel);
653
654   gst_uri_unref (base);
655
656   /* change base for path ending in directory */
657   base = gst_uri_from_string ("http://example.com/path/to/dir/");
658
659   /* test adding file to directory */
660   rel = gst_uri_from_string ("new_filename.xml");
661   joined = gst_uri_join (base, rel);
662   l = gst_uri_to_string (joined);
663   fail_unless_equals_string (l,
664       "http://example.com/path/to/dir/new_filename.xml");
665   g_free (l);
666   gst_uri_unref (joined);
667   gst_uri_unref (rel);
668
669   /* test adding file to directory using relative path */
670   rel = gst_uri_from_string ("./new_filename.xml");
671   joined = gst_uri_join (base, rel);
672   l = gst_uri_to_string (joined);
673   fail_unless_equals_string (l,
674       "http://example.com/path/to/dir/new_filename.xml");
675   g_free (l);
676   gst_uri_unref (joined);
677   gst_uri_unref (rel);
678
679   /* test filename in parent directory */
680   rel = gst_uri_from_string ("../new_filename.xml");
681   joined = gst_uri_join (base, rel);
682   l = gst_uri_to_string (joined);
683   fail_unless_equals_string (l, "http://example.com/path/to/new_filename.xml");
684   g_free (l);
685   gst_uri_unref (joined);
686   gst_uri_unref (rel);
687
688   /* test path ending in '../' */
689   rel = gst_uri_from_string ("one/two/../");
690   joined = gst_uri_join (base, rel);
691   l = gst_uri_to_string (joined);
692   fail_unless_equals_string (l, "http://example.com/path/to/dir/one/");
693   g_free (l);
694   gst_uri_unref (joined);
695   gst_uri_unref (rel);
696
697   /* test path ending in '..' Result should be the same as when ending in '../' */
698   rel = gst_uri_from_string ("one/two/..");
699   joined = gst_uri_join (base, rel);
700   l = gst_uri_to_string (joined);
701   fail_unless_equals_string (l, "http://example.com/path/to/dir/one/");
702   g_free (l);
703   gst_uri_unref (joined);
704   gst_uri_unref (rel);
705
706   /* test replace with absolute */
707   rel = gst_uri_from_string ("https://ssl.example.com/new_filename.xml");
708   joined = gst_uri_join (base, rel);
709   l = gst_uri_to_string (joined);
710   fail_unless_equals_string (l, "https://ssl.example.com/new_filename.xml");
711   g_free (l);
712   gst_uri_unref (joined);
713   gst_uri_unref (rel);
714
715   gst_uri_unref (base);
716 }
717
718 GST_END_TEST;
719
720 GST_START_TEST (test_url_equality)
721 {
722   GstUri *url1, *url2;
723
724   url1 =
725       gst_uri_from_string
726       ("ScHeMe://User:Pass@HOST.com:1234/path/./from/../to%7d/item%2dobj?query=something#fragment");
727
728   /* equal */
729   url2 =
730       gst_uri_from_string
731       ("scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=something#fragment");
732   fail_unless (gst_uri_equal (url1, url2));
733   fail_unless (gst_uri_equal (url2, url1));
734   gst_uri_unref (url2);
735
736   /* different fragment */
737   url2 =
738       gst_uri_from_string
739       ("scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=something#different-fragment");
740   fail_unless (!gst_uri_equal (url1, url2));
741   gst_uri_unref (url2);
742
743   /* different query */
744   url2 =
745       gst_uri_from_string
746       ("scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=different-something#fragment");
747   fail_unless (!gst_uri_equal (url1, url2));
748   gst_uri_unref (url2);
749
750   /* different path */
751   url2 =
752       gst_uri_from_string
753       ("scheme://User:Pass@host.com:1234/path/to%7D/different-item-obj?query=something#fragment");
754   fail_unless (!gst_uri_equal (url1, url2));
755   gst_uri_unref (url2);
756
757   /* different port */
758   url2 =
759       gst_uri_from_string
760       ("scheme://User:Pass@host.com:4321/path/to%7D/item-obj?query=something#fragment");
761   fail_unless (!gst_uri_equal (url1, url2));
762   gst_uri_unref (url2);
763
764   /* different host */
765   url2 =
766       gst_uri_from_string
767       ("scheme://User:Pass@different-host.com:1234/path/to%7D/item-obj?query=something#fragment");
768   fail_unless (!gst_uri_equal (url1, url2));
769   gst_uri_unref (url2);
770
771   /* different userinfo */
772   url2 =
773       gst_uri_from_string
774       ("scheme://Different-User:Pass@host.com:1234/path/to%7D/item-obj?query=something#fragment");
775   fail_unless (!gst_uri_equal (url1, url2));
776   gst_uri_unref (url2);
777
778   /* different scheme */
779   url2 =
780       gst_uri_from_string
781       ("different+scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=something#fragment");
782   fail_unless (!gst_uri_equal (url1, url2));
783   gst_uri_unref (url2);
784
785   /* different (no scheme) */
786   url2 =
787       gst_uri_from_string
788       ("//User:Pass@host.com:1234/path/to%7D/item-obj?query=something#fragment");
789   fail_unless (!gst_uri_equal (url1, url2));
790   gst_uri_unref (url2);
791
792   /* different (no userinfo) */
793   url2 =
794       gst_uri_from_string
795       ("scheme://host.com:1234/path/to%7D/item-obj?query=something#fragment");
796   fail_unless (!gst_uri_equal (url1, url2));
797   gst_uri_unref (url2);
798
799   /* different (no host) */
800   url2 =
801       gst_uri_from_string
802       ("scheme://User:Pass@:1234/path/to%7D/item-obj?query=something#fragment");
803   fail_unless (!gst_uri_equal (url1, url2));
804   gst_uri_unref (url2);
805
806   /* different (no port) */
807   url2 =
808       gst_uri_from_string
809       ("scheme://User:Pass@host.com/path/to%7D/item-obj?query=something#fragment");
810   fail_unless (!gst_uri_equal (url1, url2));
811   gst_uri_unref (url2);
812
813   /* different (no path) */
814   url2 =
815       gst_uri_from_string
816       ("scheme://User:Pass@host.com:1234?query=something#fragment");
817   fail_unless (!gst_uri_equal (url1, url2));
818   gst_uri_unref (url2);
819
820   /* different (no query) */
821   url2 =
822       gst_uri_from_string
823       ("scheme://User:Pass@host.com:1234/path/to%7D/item-obj#fragment");
824   fail_unless (!gst_uri_equal (url1, url2));
825   gst_uri_unref (url2);
826
827   /* different (no fragment) */
828   url2 =
829       gst_uri_from_string
830       ("scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=something");
831   fail_unless (!gst_uri_equal (url1, url2));
832   gst_uri_unref (url2);
833
834   /* compare two NULL uris */
835   fail_unless (gst_uri_equal (NULL, NULL));
836
837   /* compare same object */
838   fail_unless (gst_uri_equal (url1, url1));
839
840   /* compare one NULL and one non-NULL uri */
841   fail_unless (!gst_uri_equal (url1, NULL));
842   fail_unless (!gst_uri_equal (NULL, url1));
843
844   gst_uri_unref (url1);
845 }
846
847 GST_END_TEST;
848
849 GST_START_TEST (test_url_constructors)
850 {
851   GstUri *url1, *url2;
852   gchar *tmp_str;
853   GHashTable *tmp_table;
854
855   url1 =
856       gst_uri_new ("scheme", "userinfo", "hostname", 1234, "/path/to/file",
857       "query", "fragment");
858   fail_unless_equals_string (gst_uri_get_scheme (url1), "scheme");
859   fail_unless_equals_string (gst_uri_get_userinfo (url1), "userinfo");
860   fail_unless_equals_string (gst_uri_get_host (url1), "hostname");
861   fail_unless (gst_uri_get_port (url1) == 1234);
862   tmp_str = gst_uri_get_path (url1);
863   fail_unless_equals_string (tmp_str, "/path/to/file");
864   g_free (tmp_str);
865   tmp_table = gst_uri_get_query_table (url1);
866   fail_unless (g_hash_table_size (tmp_table) == 1);
867   fail_unless (g_hash_table_contains (tmp_table, "query"));
868   fail_unless (g_hash_table_lookup (tmp_table, "query") == NULL);
869   g_hash_table_unref (tmp_table);
870   fail_unless_equals_string (gst_uri_get_fragment (url1), "fragment");
871   tmp_str = gst_uri_to_string (url1);
872   fail_unless_equals_string (tmp_str,
873       "scheme://userinfo@hostname:1234/path/to/file?query#fragment");
874   g_free (tmp_str);
875
876   url2 =
877       gst_uri_new_with_base (url1, NULL, NULL, NULL, GST_URI_NO_PORT,
878       "new_file", NULL, NULL);
879   fail_unless_equals_string (gst_uri_get_scheme (url2), "scheme");
880   fail_unless_equals_string (gst_uri_get_userinfo (url2), "userinfo");
881   fail_unless_equals_string (gst_uri_get_host (url2), "hostname");
882   fail_unless (gst_uri_get_port (url2) == 1234);
883   tmp_str = gst_uri_get_path (url2);
884   fail_unless_equals_string (tmp_str, "/path/to/new_file");
885   g_free (tmp_str);
886   fail_unless (gst_uri_get_query_table (url2) == NULL);
887   fail_unless (gst_uri_get_fragment (url2) == NULL);
888   tmp_str = gst_uri_to_string (url2);
889   fail_unless_equals_string (tmp_str,
890       "scheme://userinfo@hostname:1234/path/to/new_file");
891   g_free (tmp_str);
892   gst_uri_unref (url2);
893
894   url2 = gst_uri_from_string_with_base (url1, "/a/new/path/to/file");
895   fail_unless_equals_string (gst_uri_get_scheme (url2), "scheme");
896   fail_unless_equals_string (gst_uri_get_userinfo (url2), "userinfo");
897   fail_unless_equals_string (gst_uri_get_host (url2), "hostname");
898   fail_unless (gst_uri_get_port (url2) == 1234);
899   tmp_str = gst_uri_get_path (url2);
900   fail_unless_equals_string (tmp_str, "/a/new/path/to/file");
901   g_free (tmp_str);
902   fail_unless (gst_uri_get_query_table (url2) == NULL);
903   fail_unless (gst_uri_get_fragment (url2) == NULL);
904   tmp_str = gst_uri_to_string (url2);
905   fail_unless_equals_string (tmp_str,
906       "scheme://userinfo@hostname:1234/a/new/path/to/file");
907   g_free (tmp_str);
908   gst_uri_unref (url2);
909
910   url2 = gst_uri_from_string_with_base (url1, "http://foobar.com/bla");
911   fail_unless_equals_string (gst_uri_get_scheme (url2), "http");
912   fail_unless_equals_string (gst_uri_get_host (url2), "foobar.com");
913   fail_unless (gst_uri_get_port (url2) == 0);
914   tmp_str = gst_uri_get_path (url2);
915   fail_unless_equals_string (tmp_str, "/bla");
916   g_free (tmp_str);
917   fail_unless (gst_uri_get_query_table (url2) == NULL);
918   fail_unless (gst_uri_get_fragment (url2) == NULL);
919   tmp_str = gst_uri_to_string (url2);
920   fail_unless_equals_string (tmp_str, "http://foobar.com/bla");
921   g_free (tmp_str);
922   gst_uri_unref (url2);
923
924   url2 = gst_uri_copy (url1);
925   fail_unless (gst_uri_equal (url1, url2));
926   fail_unless (gst_uri_set_query_value (url2, "key", "value"));
927   fail_unless (!gst_uri_equal (url1, url2));
928   gst_uri_unref (url2);
929
930   gst_uri_unref (url1);
931 }
932
933 GST_END_TEST;
934
935 GST_START_TEST (test_url_get_set)
936 {
937   GstUri *url;
938   gchar *tmp_str;
939   GList *tmp_list;
940
941   url = gst_uri_from_string ("scheme://hostname/path/to/file?query#fragment");
942
943   fail_unless (gst_uri_set_scheme (url, "new+scheme"));
944   fail_unless_equals_string (gst_uri_get_scheme (url), "new+scheme");
945   tmp_str = gst_uri_to_string (url);
946   fail_unless_equals_string (tmp_str,
947       "new+scheme://hostname/path/to/file?query#fragment");
948   g_free (tmp_str);
949
950   fail_unless (gst_uri_set_scheme (url, NULL));
951   fail_unless (gst_uri_get_scheme (url) == NULL);
952   tmp_str = gst_uri_to_string (url);
953   fail_unless_equals_string (tmp_str, "//hostname/path/to/file?query#fragment");
954   g_free (tmp_str);
955
956   fail_unless (!gst_uri_set_scheme (NULL, "fail"));
957   fail_unless (gst_uri_set_scheme (NULL, NULL));
958
959   fail_unless (gst_uri_set_userinfo (url, "username:password"));
960   fail_unless_equals_string (gst_uri_get_userinfo (url), "username:password");
961   tmp_str = gst_uri_to_string (url);
962   fail_unless_equals_string (tmp_str,
963       "//username:password@hostname/path/to/file?query#fragment");
964   g_free (tmp_str);
965
966   fail_unless (gst_uri_set_userinfo (url, NULL));
967   fail_unless (gst_uri_get_userinfo (url) == NULL);
968   tmp_str = gst_uri_to_string (url);
969   fail_unless_equals_string (tmp_str, "//hostname/path/to/file?query#fragment");
970   g_free (tmp_str);
971
972   fail_unless (!gst_uri_set_userinfo (NULL, "fail"));
973   fail_unless (gst_uri_set_userinfo (NULL, NULL));
974
975   fail_unless (gst_uri_set_host (url, NULL));
976   fail_unless (gst_uri_get_host (url) == NULL);
977   tmp_str = gst_uri_to_string (url);
978   fail_unless_equals_string (tmp_str, "/path/to/file?query#fragment");
979   g_free (tmp_str);
980
981   fail_unless (gst_uri_set_host (url, "example.com"));
982   fail_unless_equals_string (gst_uri_get_host (url), "example.com");
983   tmp_str = gst_uri_to_string (url);
984   fail_unless_equals_string (tmp_str,
985       "//example.com/path/to/file?query#fragment");
986   g_free (tmp_str);
987
988   fail_unless (!gst_uri_set_host (NULL, "fail"));
989   fail_unless (gst_uri_set_host (NULL, NULL));
990
991   fail_unless (gst_uri_set_port (url, 12345));
992   fail_unless (gst_uri_get_port (url) == 12345);
993   tmp_str = gst_uri_to_string (url);
994   fail_unless_equals_string (tmp_str,
995       "//example.com:12345/path/to/file?query#fragment");
996   g_free (tmp_str);
997
998   fail_unless (gst_uri_set_port (url, GST_URI_NO_PORT));
999   fail_unless (gst_uri_get_port (url) == GST_URI_NO_PORT);
1000   tmp_str = gst_uri_to_string (url);
1001   fail_unless_equals_string (tmp_str,
1002       "//example.com/path/to/file?query#fragment");
1003   g_free (tmp_str);
1004
1005   fail_unless (!gst_uri_set_port (NULL, 1234));
1006   fail_unless (gst_uri_set_port (NULL, GST_URI_NO_PORT));
1007
1008   fail_unless (gst_uri_append_path_segment (url, "here"));
1009   tmp_str = gst_uri_to_string (url);
1010   fail_unless_equals_string (tmp_str,
1011       "//example.com/path/to/file/here?query#fragment");
1012   g_free (tmp_str);
1013
1014   fail_unless (!gst_uri_append_path_segment (NULL, "fail"));
1015   fail_unless (gst_uri_append_path_segment (NULL, NULL));
1016
1017   fail_unless (gst_uri_append_path (url, "../there"));
1018   tmp_str = gst_uri_to_string (url);
1019   fail_unless_equals_string (tmp_str,
1020       "//example.com/path/to/file/here/../there?query#fragment");
1021   g_free (tmp_str);
1022
1023   fail_unless (!gst_uri_append_path (NULL, "fail"));
1024   fail_unless (gst_uri_append_path (NULL, NULL));
1025
1026   gst_uri_normalize (url);
1027
1028   tmp_list = gst_uri_get_path_segments (url);
1029   fail_unless (tmp_list != NULL);
1030   tmp_list = g_list_append (tmp_list, g_strdup ("segment"));
1031   tmp_str = gst_uri_to_string (url);
1032   fail_unless_equals_string (tmp_str,
1033       "//example.com/path/to/file/there?query#fragment");
1034   g_free (tmp_str);
1035   fail_unless (gst_uri_set_path_segments (url, tmp_list));
1036   tmp_str = gst_uri_to_string (url);
1037   fail_unless_equals_string (tmp_str,
1038       "//example.com/path/to/file/there/segment?query#fragment");
1039   g_free (tmp_str);
1040
1041   tmp_list = g_list_append (NULL, g_strdup ("test"));
1042   fail_unless (!gst_uri_set_path_segments (NULL, tmp_list));
1043   fail_unless (gst_uri_set_path_segments (NULL, NULL));
1044
1045   fail_unless (gst_uri_set_query_value (url, "key", "value"));
1046   tmp_str = gst_uri_to_string (url);
1047 #if GLIB_CHECK_VERSION(2, 59, 0)
1048   fail_unless_equals_string (tmp_str,
1049       "//example.com/path/to/file/there/segment?key=value&query#fragment");
1050 #else
1051   fail_unless_equals_string (tmp_str,
1052       "//example.com/path/to/file/there/segment?query&key=value#fragment");
1053 #endif
1054   g_free (tmp_str);
1055
1056   fail_unless (gst_uri_set_query_value (url, "key", NULL));
1057   tmp_str = gst_uri_to_string (url);
1058 #if GLIB_CHECK_VERSION(2, 59, 0)
1059   fail_unless_equals_string (tmp_str,
1060       "//example.com/path/to/file/there/segment?key&query#fragment");
1061 #else
1062   fail_unless_equals_string (tmp_str,
1063       "//example.com/path/to/file/there/segment?query&key#fragment");
1064 #endif
1065   g_free (tmp_str);
1066
1067   fail_unless (!gst_uri_set_query_value (NULL, "key", "value"));
1068
1069   fail_unless (gst_uri_remove_query_key (url, "key"));
1070   tmp_str = gst_uri_to_string (url);
1071   fail_unless_equals_string (tmp_str,
1072       "//example.com/path/to/file/there/segment?query#fragment");
1073   g_free (tmp_str);
1074
1075   fail_unless (!gst_uri_remove_query_key (url, "key"));
1076   fail_unless (!gst_uri_remove_query_key (NULL, "key"));
1077
1078   fail_unless (gst_uri_set_fragment (url, NULL));
1079   fail_unless (gst_uri_get_fragment (url) == NULL);
1080   tmp_str = gst_uri_to_string (url);
1081   fail_unless_equals_string (tmp_str,
1082       "//example.com/path/to/file/there/segment?query");
1083   g_free (tmp_str);
1084
1085   fail_unless (gst_uri_set_fragment (url, "tag"));
1086   fail_unless_equals_string (gst_uri_get_fragment (url), "tag");
1087   tmp_str = gst_uri_to_string (url);
1088   fail_unless_equals_string (tmp_str,
1089       "//example.com/path/to/file/there/segment?query#tag");
1090   g_free (tmp_str);
1091
1092   fail_unless (!gst_uri_set_fragment (NULL, "can't set if no URI"));
1093   fail_unless (gst_uri_set_fragment (NULL, NULL));
1094
1095   gst_uri_unref (url);
1096 }
1097
1098 GST_END_TEST;
1099
1100 GST_START_TEST (test_url_get_media_fragment_table)
1101 {
1102   GstUri *url;
1103   gchar *val;
1104   GHashTable *table;
1105
1106   /* Examples at https://www.w3.org/TR/media-frags/#processing-media-fragment-uri */
1107
1108   /* TEST "t=1" */
1109   url = gst_uri_from_string ("http://foo/var/file#t=1");
1110   table = gst_uri_get_media_fragment_table (url);
1111   fail_unless (table);
1112   fail_unless (g_hash_table_size (table) == 1);
1113   fail_unless (g_hash_table_lookup_extended (table, "t", NULL,
1114           (gpointer) & val));
1115   fail_unless_equals_string ("1", val);
1116   g_hash_table_unref (table);
1117   gst_uri_unref (url);
1118
1119   /* NOTE: Media Fragments URI 1.0 (W3C) is saying that
1120    * "Multiple occurrences of the same dimension: only the last valid occurrence
1121    *  of a dimension (e.g. t=10 in #t=2&t=10) is interpreted and all previous
1122    *  occurrences (valid or invalid) SHOULD be ignored by the user agent"
1123    */
1124   /* TEST "t=1&t=2" */
1125   url = gst_uri_from_string ("http://foo/var/file#t=1&t=2");
1126   table = gst_uri_get_media_fragment_table (url);
1127   fail_unless (table);
1128   fail_unless (g_hash_table_size (table) == 1);
1129   fail_unless (g_hash_table_lookup_extended (table, "t", NULL,
1130           (gpointer) & val));
1131   fail_unless_equals_string ("2", val);
1132   g_hash_table_unref (table);
1133   gst_uri_unref (url);
1134
1135   /* TEST "a=b=c" */
1136   url = gst_uri_from_string ("http://foo/var/file#a=b=c");
1137   table = gst_uri_get_media_fragment_table (url);
1138   fail_unless (table);
1139   fail_unless (g_hash_table_size (table) == 1);
1140   fail_unless (g_hash_table_lookup_extended (table, "a", NULL,
1141           (gpointer) & val));
1142   fail_unless_equals_string ("b=c", val);
1143   g_hash_table_unref (table);
1144   gst_uri_unref (url);
1145
1146   /* TEST "a&b=c" */
1147   url = gst_uri_from_string ("http://foo/var/file#a&b=c");
1148   table = gst_uri_get_media_fragment_table (url);
1149   fail_unless (table);
1150   fail_unless (g_hash_table_size (table) == 2);
1151   fail_unless (g_hash_table_lookup_extended (table, "a", NULL,
1152           (gpointer) & val));
1153   fail_unless (val == NULL);
1154   fail_unless (g_hash_table_lookup_extended (table, "b", NULL,
1155           (gpointer) & val));
1156   fail_unless_equals_string ("c", val);
1157   g_hash_table_unref (table);
1158   gst_uri_unref (url);
1159
1160   /* TEST "%74=%6ept%3A%310" */
1161   url = gst_uri_from_string ("http://foo/var/file#%74=%6ept%3A%310");
1162   table = gst_uri_get_media_fragment_table (url);
1163   fail_unless (table);
1164   fail_unless (g_hash_table_size (table) == 1);
1165   fail_unless (g_hash_table_lookup_extended (table, "t", NULL,
1166           (gpointer) & val));
1167   fail_unless_equals_string ("npt:10", val);
1168   g_hash_table_unref (table);
1169   gst_uri_unref (url);
1170 }
1171
1172 GST_END_TEST;
1173
1174 GST_START_TEST (test_url_unescape_equals_in_http_query)
1175 {
1176   GstUri *url;
1177   gchar *query_string;
1178
1179   url =
1180       gst_uri_from_string
1181       ("http://abc.manifest?token=exp=123~acl=/QualityLevels(*~hmac=0cb");
1182
1183   fail_unless_equals_string (gst_uri_get_scheme (url), "http");
1184   query_string = gst_uri_get_query_string (url);
1185   fail_unless_equals_string (query_string,
1186       "token=exp=123~acl=/QualityLevels(*~hmac=0cb");
1187   g_free (query_string);
1188   fail_unless (gst_uri_query_has_key (url, "token"));
1189   fail_unless_equals_string (gst_uri_get_query_value (url, "token"),
1190       "exp=123~acl=/QualityLevels(*~hmac=0cb");
1191   gst_uri_unref (url);
1192 }
1193
1194 GST_END_TEST;
1195
1196 static Suite *
1197 gst_uri_suite (void)
1198 {
1199   Suite *s = suite_create ("GstURI");
1200   TCase *tc_chain = tcase_create ("uri");
1201
1202   tcase_set_timeout (tc_chain, 20);
1203
1204   suite_add_tcase (s, tc_chain);
1205   tcase_add_test (tc_chain, test_protocol_case);
1206   tcase_add_test (tc_chain, test_uri_get_location);
1207 #ifndef GST_REMOVE_DEPRECATED
1208   tcase_add_test (tc_chain, test_gst_uri_construct);
1209 #endif
1210   tcase_add_test (tc_chain, test_uri_misc);
1211   tcase_add_test (tc_chain, test_element_make_from_uri);
1212 #ifdef G_OS_WIN32
1213   tcase_add_test (tc_chain, test_win32_uri);
1214 #endif
1215   tcase_add_test (tc_chain, test_url_parsing);
1216   tcase_add_test (tc_chain, test_url_parsing_escaped);
1217   tcase_add_test (tc_chain, test_url_presenting);
1218   tcase_add_test (tc_chain, test_url_normalization);
1219   tcase_add_test (tc_chain, test_url_joining);
1220   tcase_add_test (tc_chain, test_url_equality);
1221   tcase_add_test (tc_chain, test_url_constructors);
1222   tcase_add_test (tc_chain, test_url_get_set);
1223   tcase_add_test (tc_chain, test_url_get_media_fragment_table);
1224   tcase_add_test (tc_chain, test_url_unescape_equals_in_http_query);
1225
1226   return s;
1227 }
1228
1229 GST_CHECK_MAIN (gst_uri);