Initial release including wifi display based on gst-rtsp-server-1.4.1
[platform/upstream/gstreamer.git] / tests / check / gst / mediafactory.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-media-factory.h>
23
24 GST_START_TEST (test_parse_error)
25 {
26   GstRTSPMediaFactory *factory;
27   GstRTSPUrl *url;
28
29   factory = gst_rtsp_media_factory_new ();
30
31   gst_rtsp_media_factory_set_launch (factory, "foo");
32   fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
33           &url) == GST_RTSP_OK);
34   ASSERT_CRITICAL (gst_rtsp_media_factory_create_element (factory, url));
35   ASSERT_CRITICAL (gst_rtsp_media_factory_construct (factory, url));
36
37   gst_rtsp_url_free (url);
38   g_object_unref (factory);
39 }
40
41 GST_END_TEST;
42
43 GST_START_TEST (test_launch)
44 {
45   GstRTSPMediaFactory *factory;
46   GstElement *element;
47   GstRTSPUrl *url;
48
49   factory = gst_rtsp_media_factory_new ();
50   fail_if (gst_rtsp_media_factory_is_shared (factory));
51   fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
52           &url) == GST_RTSP_OK);
53
54   gst_rtsp_media_factory_set_launch (factory,
55       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
56
57   element = gst_rtsp_media_factory_create_element (factory, url);
58   fail_unless (GST_IS_BIN (element));
59   fail_if (GST_IS_PIPELINE (element));
60   gst_object_unref (element);
61
62   gst_rtsp_url_free (url);
63   g_object_unref (factory);
64 }
65
66 GST_END_TEST;
67
68 GST_START_TEST (test_launch_construct)
69 {
70   GstRTSPMediaFactory *factory;
71   GstRTSPMedia *media, *media2;
72   GstRTSPUrl *url;
73
74   factory = gst_rtsp_media_factory_new ();
75   fail_if (gst_rtsp_media_factory_is_shared (factory));
76   fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
77           &url) == GST_RTSP_OK);
78
79   gst_rtsp_media_factory_set_launch (factory,
80       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
81
82   media = gst_rtsp_media_factory_construct (factory, url);
83   fail_unless (GST_IS_RTSP_MEDIA (media));
84
85   media2 = gst_rtsp_media_factory_construct (factory, url);
86   fail_unless (GST_IS_RTSP_MEDIA (media2));
87   fail_if (media == media2);
88
89   g_object_unref (media);
90   g_object_unref (media2);
91
92   gst_rtsp_url_free (url);
93   g_object_unref (factory);
94 }
95
96 GST_END_TEST;
97
98 GST_START_TEST (test_shared)
99 {
100   GstRTSPMediaFactory *factory;
101   GstElement *element;
102   GstRTSPMedia *media, *media2;
103   GstRTSPUrl *url;
104
105   factory = gst_rtsp_media_factory_new ();
106   gst_rtsp_media_factory_set_shared (factory, TRUE);
107   fail_unless (gst_rtsp_media_factory_is_shared (factory));
108
109   fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
110           &url) == GST_RTSP_OK);
111
112   gst_rtsp_media_factory_set_launch (factory,
113       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
114
115   element = gst_rtsp_media_factory_create_element (factory, url);
116   fail_unless (GST_IS_BIN (element));
117   fail_if (GST_IS_PIPELINE (element));
118   gst_object_unref (element);
119
120   media = gst_rtsp_media_factory_construct (factory, url);
121   fail_unless (GST_IS_RTSP_MEDIA (media));
122
123   media2 = gst_rtsp_media_factory_construct (factory, url);
124   fail_unless (GST_IS_RTSP_MEDIA (media2));
125   fail_unless (media == media2);
126
127   g_object_unref (media);
128   g_object_unref (media2);
129
130   gst_rtsp_url_free (url);
131   g_object_unref (factory);
132 }
133
134 GST_END_TEST;
135
136 GST_START_TEST (test_addresspool)
137 {
138   GstRTSPMediaFactory *factory;
139   GstElement *element;
140   GstRTSPMedia *media;
141   GstRTSPUrl *url;
142   GstRTSPAddressPool *pool, *tmppool;
143   GstRTSPStream *stream;
144   GstRTSPAddress *addr;
145
146   factory = gst_rtsp_media_factory_new ();
147   gst_rtsp_media_factory_set_shared (factory, TRUE);
148   fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
149           &url) == GST_RTSP_OK);
150
151   gst_rtsp_media_factory_set_launch (factory,
152       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 "
153       " audiotestsrc ! audioconvert ! rtpL16pay name=pay1 )");
154
155   pool = gst_rtsp_address_pool_new ();
156   fail_unless (gst_rtsp_address_pool_add_range (pool,
157           "233.252.0.1", "233.252.0.1", 5000, 5001, 3));
158
159   gst_rtsp_media_factory_set_address_pool (factory, pool);
160
161   tmppool = gst_rtsp_media_factory_get_address_pool (factory);
162   fail_unless (pool == tmppool);
163   g_object_unref (tmppool);
164
165   element = gst_rtsp_media_factory_create_element (factory, url);
166   fail_unless (GST_IS_BIN (element));
167   fail_if (GST_IS_PIPELINE (element));
168   gst_object_unref (element);
169
170   media = gst_rtsp_media_factory_construct (factory, url);
171   fail_unless (GST_IS_RTSP_MEDIA (media));
172
173   tmppool = gst_rtsp_media_get_address_pool (media);
174   fail_unless (pool == tmppool);
175   g_object_unref (tmppool);
176
177   fail_unless (gst_rtsp_media_n_streams (media) == 2);
178
179   stream = gst_rtsp_media_get_stream (media, 0);
180   fail_unless (stream != NULL);
181
182   tmppool = gst_rtsp_stream_get_address_pool (stream);
183   fail_unless (pool == tmppool);
184   g_object_unref (tmppool);
185
186   addr = gst_rtsp_stream_get_multicast_address (stream, G_SOCKET_FAMILY_IPV4);
187   fail_unless (addr != NULL);
188   fail_unless (addr->port == 5000);
189   fail_unless (addr->n_ports == 2);
190   fail_unless (addr->ttl == 3);
191   gst_rtsp_address_free (addr);
192
193   stream = gst_rtsp_media_get_stream (media, 1);
194   fail_unless (stream != NULL);
195
196   tmppool = gst_rtsp_stream_get_address_pool (stream);
197   fail_unless (pool == tmppool);
198   g_object_unref (tmppool);
199
200   addr = gst_rtsp_stream_get_multicast_address (stream, G_SOCKET_FAMILY_IPV4);
201   fail_unless (addr == NULL);
202
203
204   g_object_unref (media);
205
206   g_object_unref (pool);
207   gst_rtsp_url_free (url);
208   g_object_unref (factory);
209 }
210
211 GST_END_TEST;
212
213 GST_START_TEST (test_permissions)
214 {
215   GstRTSPMediaFactory *factory;
216   GstRTSPPermissions *perms;
217   GstRTSPMedia *media;
218   GstRTSPUrl *url;
219
220   factory = gst_rtsp_media_factory_new ();
221   fail_if (gst_rtsp_media_factory_is_shared (factory));
222   fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
223           &url) == GST_RTSP_OK);
224
225   gst_rtsp_media_factory_set_launch (factory,
226       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
227
228   gst_rtsp_media_factory_add_role (factory, "admin",
229       "media.factory.access", G_TYPE_BOOLEAN, TRUE,
230       "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL);
231
232   perms = gst_rtsp_media_factory_get_permissions (factory);
233   fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin",
234           "media.factory.access"));
235   fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin",
236           "media.factory.construct"));
237   fail_if (gst_rtsp_permissions_is_allowed (perms, "missing",
238           "media.factory.access"));
239   gst_rtsp_permissions_unref (perms);
240
241   perms = gst_rtsp_permissions_new ();
242   gst_rtsp_permissions_add_role (perms, "user",
243       "media.factory.access", G_TYPE_BOOLEAN, TRUE,
244       "media.factory.construct", G_TYPE_BOOLEAN, FALSE, NULL);
245   gst_rtsp_media_factory_set_permissions (factory, perms);
246   gst_rtsp_permissions_unref (perms);
247
248   perms = gst_rtsp_media_factory_get_permissions (factory);
249   fail_if (gst_rtsp_permissions_is_allowed (perms, "admin",
250           "media.factory.access"));
251   fail_if (gst_rtsp_permissions_is_allowed (perms, "admin",
252           "media.factory.construct"));
253   fail_unless (gst_rtsp_permissions_is_allowed (perms, "user",
254           "media.factory.access"));
255   fail_if (gst_rtsp_permissions_is_allowed (perms, "user",
256           "media.factory.construct"));
257   fail_if (gst_rtsp_permissions_is_allowed (perms, "missing",
258           "media.factory.access"));
259   gst_rtsp_permissions_unref (perms);
260
261   media = gst_rtsp_media_factory_construct (factory, url);
262   fail_unless (GST_IS_RTSP_MEDIA (media));
263   perms = gst_rtsp_media_get_permissions (media);
264   fail_if (gst_rtsp_permissions_is_allowed (perms, "admin",
265           "media.factory.access"));
266   fail_if (gst_rtsp_permissions_is_allowed (perms, "admin",
267           "media.factory.construct"));
268   fail_unless (gst_rtsp_permissions_is_allowed (perms, "user",
269           "media.factory.access"));
270   fail_if (gst_rtsp_permissions_is_allowed (perms, "user",
271           "media.factory.construct"));
272   fail_if (gst_rtsp_permissions_is_allowed (perms, "missing",
273           "media.factory.access"));
274   gst_rtsp_permissions_unref (perms);
275   g_object_unref (media);
276
277   gst_rtsp_url_free (url);
278   g_object_unref (factory);
279 }
280
281 GST_END_TEST;
282
283 GST_START_TEST (test_reset)
284 {
285   GstRTSPMediaFactory *factory;
286   GstRTSPMedia *media;
287   GstRTSPUrl *url;
288
289   factory = gst_rtsp_media_factory_new ();
290   fail_if (gst_rtsp_media_factory_is_shared (factory));
291   gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
292
293   gst_rtsp_media_factory_set_launch (factory,
294       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
295
296   media = gst_rtsp_media_factory_construct (factory, url);
297   fail_unless (GST_IS_RTSP_MEDIA (media));
298   fail_if (gst_rtsp_media_get_suspend_mode (media) !=
299       GST_RTSP_SUSPEND_MODE_NONE);
300   g_object_unref (media);
301
302   gst_rtsp_media_factory_set_suspend_mode (factory,
303       GST_RTSP_SUSPEND_MODE_RESET);
304
305   media = gst_rtsp_media_factory_construct (factory, url);
306   fail_unless (GST_IS_RTSP_MEDIA (media));
307   fail_if (gst_rtsp_media_get_suspend_mode (media) !=
308       GST_RTSP_SUSPEND_MODE_RESET);
309   g_object_unref (media);
310
311   gst_rtsp_url_free (url);
312   g_object_unref (factory);
313 }
314
315 GST_END_TEST;
316
317 static Suite *
318 rtspmediafactory_suite (void)
319 {
320   Suite *s = suite_create ("rtspmediafactory");
321   TCase *tc = tcase_create ("general");
322
323   suite_add_tcase (s, tc);
324   tcase_set_timeout (tc, 20);
325   tcase_add_test (tc, test_parse_error);
326   tcase_add_test (tc, test_launch);
327   tcase_add_test (tc, test_launch_construct);
328   tcase_add_test (tc, test_shared);
329   tcase_add_test (tc, test_addresspool);
330   tcase_add_test (tc, test_permissions);
331   tcase_add_test (tc, test_reset);
332
333   return s;
334 }
335
336 GST_CHECK_MAIN (rtspmediafactory);