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