Initial release including wifi display based on gst-rtsp-server-1.4.1
[platform/upstream/gstreamer.git] / tests / check / gst / mountpoints.c
1 /* GStreamer
2  * Copyright (C) 2012 Wim Taymans <wim.taymans@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include <gst/check/gstcheck.h>
21
22 #include <rtsp-mount-points.h>
23
24 GST_START_TEST (test_create)
25 {
26   GstRTSPMountPoints *mounts;
27   GstRTSPUrl *url, *url2;
28   GstRTSPMediaFactory *factory;
29
30   mounts = gst_rtsp_mount_points_new ();
31
32   fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
33           &url) == GST_RTSP_OK);
34   fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test2",
35           &url2) == GST_RTSP_OK);
36
37   fail_unless (gst_rtsp_mount_points_match (mounts, url->abspath,
38           NULL) == NULL);
39
40   factory = gst_rtsp_media_factory_new ();
41   gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
42
43   fail_unless (gst_rtsp_mount_points_match (mounts, url->abspath,
44           NULL) == factory);
45   g_object_unref (factory);
46   fail_unless (gst_rtsp_mount_points_match (mounts, url2->abspath,
47           NULL) == NULL);
48
49   gst_rtsp_mount_points_remove_factory (mounts, "/test");
50
51   fail_unless (gst_rtsp_mount_points_match (mounts, url->abspath,
52           NULL) == NULL);
53   fail_unless (gst_rtsp_mount_points_match (mounts, url2->abspath,
54           NULL) == NULL);
55
56   gst_rtsp_url_free (url);
57   gst_rtsp_url_free (url2);
58
59   g_object_unref (mounts);
60 }
61
62 GST_END_TEST;
63
64 static const gchar *paths[] = {
65   "/test",
66   "/booz/fooz",
67   "/booz/foo/zoop",
68   "/tark/bar",
69   "/tark/bar/baz",
70   "/tark/bar/baz/t",
71   "/boozop",
72 };
73
74 GST_START_TEST (test_match)
75 {
76   GstRTSPMountPoints *mounts;
77   GstRTSPMediaFactory *f[G_N_ELEMENTS (paths)], *tmp;
78   gint i, matched;
79
80   mounts = gst_rtsp_mount_points_new ();
81
82   for (i = 0; i < G_N_ELEMENTS (paths); i++) {
83     f[i] = gst_rtsp_media_factory_new ();
84     gst_rtsp_mount_points_add_factory (mounts, paths[i], f[i]);
85   }
86
87   tmp = gst_rtsp_mount_points_match (mounts, "/test", &matched);
88   fail_unless (tmp == f[0]);
89   fail_unless (matched == 5);
90   g_object_unref (tmp);
91   tmp = gst_rtsp_mount_points_match (mounts, "/test/stream=1", &matched);
92   fail_unless (tmp == f[0]);
93   fail_unless (matched == 5);
94   g_object_unref (tmp);
95   tmp = gst_rtsp_mount_points_match (mounts, "/booz", &matched);
96   fail_unless (tmp == NULL);
97   tmp = gst_rtsp_mount_points_match (mounts, "/booz/foo", &matched);
98   fail_unless (tmp == NULL);
99   tmp = gst_rtsp_mount_points_match (mounts, "/booz/fooz", &matched);
100   fail_unless (tmp == f[1]);
101   fail_unless (matched == 10);
102   g_object_unref (tmp);
103   tmp = gst_rtsp_mount_points_match (mounts, "/booz/fooz/zoo", &matched);
104   fail_unless (tmp == f[1]);
105   fail_unless (matched == 10);
106   g_object_unref (tmp);
107   tmp = gst_rtsp_mount_points_match (mounts, "/booz/foo/zoop", &matched);
108   fail_unless (tmp == f[2]);
109   fail_unless (matched == 14);
110   g_object_unref (tmp);
111   tmp = gst_rtsp_mount_points_match (mounts, "/tark/bar", &matched);
112   fail_unless (tmp == f[3]);
113   fail_unless (matched == 9);
114   g_object_unref (tmp);
115   tmp = gst_rtsp_mount_points_match (mounts, "/tark/bar/boo", &matched);
116   fail_unless (tmp == f[3]);
117   fail_unless (matched == 9);
118   g_object_unref (tmp);
119   tmp = gst_rtsp_mount_points_match (mounts, "/tark/bar/ba", &matched);
120   fail_unless (tmp == f[3]);
121   fail_unless (matched == 9);
122   g_object_unref (tmp);
123   tmp = gst_rtsp_mount_points_match (mounts, "/tark/bar/baz", &matched);
124   fail_unless (tmp == f[4]);
125   fail_unless (matched == 13);
126   g_object_unref (tmp);
127
128   g_object_unref (mounts);
129 }
130
131 GST_END_TEST;
132
133 static Suite *
134 rtspmountpoints_suite (void)
135 {
136   Suite *s = suite_create ("rtspmountpoints");
137   TCase *tc = tcase_create ("general");
138
139   suite_add_tcase (s, tc);
140   tcase_set_timeout (tc, 20);
141   tcase_add_test (tc, test_create);
142   tcase_add_test (tc, test_match);
143
144   return s;
145 }
146
147 GST_CHECK_MAIN (rtspmountpoints);