caps: improve _do_simplify
[platform/upstream/gstreamer.git] / 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., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include <gst/check/gstcheck.h>
22
23 GST_START_TEST (test_protocol_case)
24 {
25   GstElement *element;
26
27   element = gst_element_make_from_uri (GST_URI_SRC, "file:///foo/bar", NULL);
28
29   /* no element? probably no registry, bail out */
30   if (element == NULL)
31     return;
32
33   gst_object_unref (element);
34   element = gst_element_make_from_uri (GST_URI_SRC, "FILE:///foo/bar", NULL);
35   fail_unless (element != NULL,
36       "Got source for 'file://' URI but not for 'FILE://' URI");
37   gst_object_unref (element);
38 }
39
40 GST_END_TEST;
41
42 GST_START_TEST (test_uri_get_location)
43 {
44   gchar *l;
45
46   /* URI with no location should return empty string */
47   l = gst_uri_get_location ("dvd://");
48   fail_unless (l != NULL);
49   fail_unless_equals_string (l, "");
50   g_free (l);
51
52   /* URI with hostname */
53   l = gst_uri_get_location ("smb://supercomputer/path/to/file");
54   fail_unless (l != NULL);
55   fail_unless_equals_string (l, "supercomputer/path/to/file");
56   g_free (l);
57
58   /* URI */
59   l = gst_uri_get_location ("file:///path/to/file");
60   fail_unless (l != NULL);
61   fail_unless_equals_string (l, "/path/to/file");
62   g_free (l);
63
64   /* unescaping */
65   l = gst_uri_get_location ("file:///path/to/some%20file");
66   fail_unless (l != NULL);
67   fail_unless_equals_string (l, "/path/to/some file");
68   g_free (l);
69 }
70
71 GST_END_TEST;
72
73 #ifdef G_OS_WIN32
74
75 GST_START_TEST (test_win32_uri)
76 {
77   gchar *uri, *l;
78
79   uri = g_strdup ("file:///c:/my%20music/foo.ogg");
80   l = gst_uri_get_location (uri);
81   fail_unless (l != NULL);
82   /* fail_unless_equals_string will screw up here in the failure case
83    * because the string constant will be appended to the printf format
84    * message string and contains a '%', that's why we use fail_unless here */
85   fail_unless (g_str_equal (l, "c:/my music/foo.ogg"),
86       "wrong location '%s' returned for URI '%s'", l, uri);
87   g_free (l);
88   g_free (uri);
89
90   /* make sure the other variant with two slashes before the C: (which was
91    * needed before because of a bug in _get_location()) still works */
92   uri = g_strdup ("file://c:/my%20music/foo.ogg");
93   l = gst_uri_get_location (uri);
94   fail_unless (l != NULL);
95   /* fail_unless_equals_string will screw up here in the failure case
96    * because the string constant will be appended to the printf format
97    * message string and contains a '%', that's why we use fail_unless here */
98   fail_unless (g_str_equal (l, "c:/my music/foo.ogg"),
99       "wrong location '%s' returned for URI '%s'", l, uri);
100   g_free (l);
101   g_free (uri);
102 }
103
104 GST_END_TEST;
105
106 #endif /* G_OS_WIN32 */
107
108 static Suite *
109 gst_uri_suite (void)
110 {
111   Suite *s = suite_create ("GstURI");
112   TCase *tc_chain = tcase_create ("uri");
113
114   tcase_set_timeout (tc_chain, 20);
115
116   suite_add_tcase (s, tc_chain);
117   tcase_add_test (tc_chain, test_protocol_case);
118   tcase_add_test (tc_chain, test_uri_get_location);
119 #ifdef G_OS_WIN32
120   tcase_add_test (tc_chain, test_win32_uri);
121 #endif
122
123   return s;
124 }
125
126 GST_CHECK_MAIN (gst_uri);