tests: Check the passing around of a RTSPAddressPool
[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   gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
33   ASSERT_CRITICAL (gst_rtsp_media_factory_create_element (factory, url));
34   ASSERT_CRITICAL (gst_rtsp_media_factory_construct (factory, url));
35
36   gst_rtsp_url_free (url);
37   g_object_unref (factory);
38 }
39
40 GST_END_TEST;
41
42 GST_START_TEST (test_launch)
43 {
44   GstRTSPMediaFactory *factory;
45   GstElement *element;
46   GstRTSPUrl *url;
47
48   factory = gst_rtsp_media_factory_new ();
49   fail_if (gst_rtsp_media_factory_is_shared (factory));
50   gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
51
52   gst_rtsp_media_factory_set_launch (factory,
53       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
54
55   element = gst_rtsp_media_factory_create_element (factory, url);
56   fail_unless (GST_IS_BIN (element));
57   fail_if (GST_IS_PIPELINE (element));
58   gst_object_unref (element);
59
60   gst_rtsp_url_free (url);
61   g_object_unref (factory);
62 }
63
64 GST_END_TEST;
65
66 GST_START_TEST (test_launch_construct)
67 {
68   GstRTSPMediaFactory *factory;
69   GstRTSPMedia *media, *media2;
70   GstRTSPUrl *url;
71
72   factory = gst_rtsp_media_factory_new ();
73   fail_if (gst_rtsp_media_factory_is_shared (factory));
74   gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
75
76   gst_rtsp_media_factory_set_launch (factory,
77       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
78
79   media = gst_rtsp_media_factory_construct (factory, url);
80   fail_unless (GST_IS_RTSP_MEDIA (media));
81   g_object_unref (media);
82
83   media2 = gst_rtsp_media_factory_construct (factory, url);
84   fail_unless (GST_IS_RTSP_MEDIA (media2));
85   fail_if (media == media2);
86   g_object_unref (media2);
87
88   gst_rtsp_url_free (url);
89   g_object_unref (factory);
90 }
91
92 GST_END_TEST;
93
94 GST_START_TEST (test_shared)
95 {
96   GstRTSPMediaFactory *factory;
97   GstElement *element;
98   GstRTSPMedia *media, *media2;
99   GstRTSPUrl *url;
100
101   factory = gst_rtsp_media_factory_new ();
102   gst_rtsp_media_factory_set_shared (factory, TRUE);
103   fail_unless (gst_rtsp_media_factory_is_shared (factory));
104
105   gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
106
107   gst_rtsp_media_factory_set_launch (factory,
108       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
109
110   element = gst_rtsp_media_factory_create_element (factory, url);
111   fail_unless (GST_IS_BIN (element));
112   fail_if (GST_IS_PIPELINE (element));
113   gst_object_unref (element);
114
115   media = gst_rtsp_media_factory_construct (factory, url);
116   fail_unless (GST_IS_RTSP_MEDIA (media));
117
118   media2 = gst_rtsp_media_factory_construct (factory, url);
119   fail_unless (GST_IS_RTSP_MEDIA (media2));
120   fail_unless (media == media2);
121
122   g_object_unref (media);
123   g_object_unref (media2);
124
125   gst_rtsp_url_free (url);
126   g_object_unref (factory);
127 }
128
129 GST_END_TEST;
130
131 GST_START_TEST (test_addresspool)
132 {
133   GstRTSPMediaFactory *factory;
134   GstElement *element;
135   GstRTSPMedia *media;
136   GstRTSPUrl *url;
137   GstRTSPAddressPool *pool, *tmppool;
138   GstRTSPStream *stream;
139   GstRTSPAddress *addr;
140
141   factory = gst_rtsp_media_factory_new ();
142   gst_rtsp_media_factory_set_shared (factory, TRUE);
143   gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
144
145   gst_rtsp_media_factory_set_launch (factory,
146       "( videotestsrc ! rtpvrawpay pt=96 name=pay0 "
147       " audiotestsrc ! audioconvert ! rtpL16pay name=pay1 )");
148
149   pool = gst_rtsp_address_pool_new ();
150   fail_unless (gst_rtsp_address_pool_add_range (pool,
151           "233.252.0.1", "233.252.0.1", 5000, 5001, 3));
152
153   gst_rtsp_media_factory_set_address_pool (factory, pool);
154
155   tmppool = gst_rtsp_media_factory_get_address_pool (factory);
156   fail_unless (pool == tmppool);
157   g_object_unref (tmppool);
158
159   element = gst_rtsp_media_factory_create_element (factory, url);
160   fail_unless (GST_IS_BIN (element));
161   fail_if (GST_IS_PIPELINE (element));
162   gst_object_unref (element);
163
164   media = gst_rtsp_media_factory_construct (factory, url);
165   fail_unless (GST_IS_RTSP_MEDIA (media));
166
167   tmppool = gst_rtsp_media_get_address_pool (media);
168   fail_unless (pool == tmppool);
169   g_object_unref (tmppool);
170
171   fail_unless (gst_rtsp_media_n_streams (media) == 2);
172
173   stream = gst_rtsp_media_get_stream (media, 0);
174   fail_unless (stream != NULL);
175
176   tmppool = gst_rtsp_stream_get_address_pool (stream);
177   fail_unless (pool == tmppool);
178   g_object_unref (tmppool);
179
180   addr = gst_rtsp_stream_get_address (stream);
181   fail_unless (addr != NULL);
182   fail_unless (addr->port == 5000);
183   fail_unless (addr->n_ports == 2);
184   fail_unless (addr->ttl == 3);
185   gst_rtsp_address_free (addr);
186
187   stream = gst_rtsp_media_get_stream (media, 1);
188   fail_unless (stream != NULL);
189
190   tmppool = gst_rtsp_stream_get_address_pool (stream);
191   fail_unless (pool == tmppool);
192   g_object_unref (tmppool);
193
194   addr = gst_rtsp_stream_get_address (stream);
195   fail_unless (addr == NULL);
196
197
198   g_object_unref (media);
199
200   g_object_unref (pool);
201   gst_rtsp_url_free (url);
202   g_object_unref (factory);
203 }
204
205 GST_END_TEST;
206
207 static Suite *
208 rtspmediafactory_suite (void)
209 {
210   Suite *s = suite_create ("rtspmediafactory");
211   TCase *tc = tcase_create ("general");
212
213   suite_add_tcase (s, tc);
214   tcase_set_timeout (tc, 20);
215   tcase_add_test (tc, test_parse_error);
216   tcase_add_test (tc, test_launch);
217   tcase_add_test (tc, test_launch_construct);
218   tcase_add_test (tc, test_shared);
219   tcase_add_test (tc, test_addresspool);
220
221   return s;
222 }
223
224 GST_CHECK_MAIN (rtspmediafactory);