stream: Added a list of multicast client addresses
[platform/upstream/gst-rtsp-server.git] / tests / check / gst / stream.c
1 /* GStreamer
2  * Copyright (C) 2013 Axis Communications AB <dev-gstreamer at axis dot 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-stream.h>
23 #include <rtsp-address-pool.h>
24
25 static void
26 get_sockets (GstRTSPLowerTrans lower_transport, GSocketFamily socket_family)
27 {
28   GstPad *srcpad;
29   GstElement *pay;
30   GstRTSPStream *stream;
31   GstBin *bin;
32   GstElement *rtpbin;
33   GstRTSPAddressPool *pool;
34   GSocket *socket;
35   gboolean have_ipv4;
36   gboolean have_ipv6;
37   GstRTSPTransport *transport;
38
39   srcpad = gst_pad_new ("testsrcpad", GST_PAD_SRC);
40   fail_unless (srcpad != NULL);
41   gst_pad_set_active (srcpad, TRUE);
42   pay = gst_element_factory_make ("rtpgstpay", "testpayloader");
43   fail_unless (pay != NULL);
44   stream = gst_rtsp_stream_new (0, pay, srcpad);
45   fail_unless (stream != NULL);
46   gst_object_unref (pay);
47   gst_object_unref (srcpad);
48   rtpbin = gst_element_factory_make ("rtpbin", "testrtpbin");
49   fail_unless (rtpbin != NULL);
50   bin = GST_BIN (gst_bin_new ("testbin"));
51   fail_unless (bin != NULL);
52   fail_unless (gst_bin_add (bin, rtpbin));
53
54   /* configure address pool for IPv4 and IPv6 unicast addresses */
55   pool = gst_rtsp_address_pool_new ();
56   fail_unless (gst_rtsp_address_pool_add_range (pool,
57           GST_RTSP_ADDRESS_POOL_ANY_IPV4, GST_RTSP_ADDRESS_POOL_ANY_IPV4, 50000,
58           60000, 0));
59   fail_unless (gst_rtsp_address_pool_add_range (pool,
60           GST_RTSP_ADDRESS_POOL_ANY_IPV6, GST_RTSP_ADDRESS_POOL_ANY_IPV6, 50000,
61           60000, 0));
62   fail_unless (gst_rtsp_address_pool_add_range (pool, "233.252.0.0",
63           "233.252.0.0", 50000, 60000, 1));
64   fail_unless (gst_rtsp_address_pool_add_range (pool, "FF11:DB8::1",
65           "FF11:DB8::1", 50000, 60000, 1));
66   gst_rtsp_stream_set_address_pool (stream, pool);
67
68   fail_unless (gst_rtsp_stream_join_bin (stream, bin, rtpbin, GST_STATE_NULL));
69
70   /* allocate udp ports first */
71   fail_unless (gst_rtsp_transport_new (&transport) == GST_RTSP_OK);
72   transport->lower_transport = lower_transport;
73
74   /* no ports allocated, complete stream should fail */
75   fail_if (gst_rtsp_stream_complete_stream (stream, transport));
76
77   /* allocate ports */
78   fail_unless (gst_rtsp_stream_allocate_udp_sockets (stream,
79           socket_family, transport, FALSE));
80
81   fail_unless (gst_rtsp_stream_complete_stream (stream, transport));
82   fail_unless (gst_rtsp_transport_free (transport) == GST_RTSP_OK);
83
84   if (lower_transport == GST_RTSP_LOWER_TRANS_UDP)
85     socket = gst_rtsp_stream_get_rtp_socket (stream, G_SOCKET_FAMILY_IPV4);
86   else
87     socket = gst_rtsp_stream_get_rtp_multicast_socket (stream,
88         G_SOCKET_FAMILY_IPV4);
89   have_ipv4 = (socket != NULL);
90   if (have_ipv4) {
91     fail_unless (g_socket_get_fd (socket) >= 0);
92     g_object_unref (socket);
93   }
94
95   if (lower_transport == GST_RTSP_LOWER_TRANS_UDP)
96     socket = gst_rtsp_stream_get_rtcp_socket (stream, G_SOCKET_FAMILY_IPV4);
97   else
98     socket = gst_rtsp_stream_get_rtcp_multicast_socket (stream,
99         G_SOCKET_FAMILY_IPV4);
100   if (have_ipv4) {
101     fail_unless (socket != NULL);
102     fail_unless (g_socket_get_fd (socket) >= 0);
103     g_object_unref (socket);
104   } else {
105     fail_unless (socket == NULL);
106   }
107
108   if (lower_transport == GST_RTSP_LOWER_TRANS_UDP)
109     socket = gst_rtsp_stream_get_rtp_socket (stream, G_SOCKET_FAMILY_IPV6);
110   else
111     socket = gst_rtsp_stream_get_rtp_multicast_socket (stream,
112         G_SOCKET_FAMILY_IPV6);
113   have_ipv6 = (socket != NULL);
114   if (have_ipv6) {
115     fail_unless (g_socket_get_fd (socket) >= 0);
116     g_object_unref (socket);
117   }
118
119   if (lower_transport == GST_RTSP_LOWER_TRANS_UDP)
120     socket = gst_rtsp_stream_get_rtcp_socket (stream, G_SOCKET_FAMILY_IPV6);
121   else
122     socket = gst_rtsp_stream_get_rtcp_multicast_socket (stream,
123         G_SOCKET_FAMILY_IPV6);
124   if (have_ipv6) {
125     fail_unless (socket != NULL);
126     fail_unless (g_socket_get_fd (socket) >= 0);
127     g_object_unref (socket);
128   } else {
129     fail_unless (socket == NULL);
130   }
131
132   /* check that at least one family is available */
133   fail_unless (have_ipv4 || have_ipv6);
134
135   g_object_unref (pool);
136
137   fail_unless (gst_rtsp_stream_leave_bin (stream, bin, rtpbin));
138
139   gst_object_unref (bin);
140   gst_object_unref (stream);
141 }
142
143 GST_START_TEST (test_get_sockets_udp)
144 {
145   get_sockets (GST_RTSP_LOWER_TRANS_UDP, G_SOCKET_FAMILY_IPV4);
146   get_sockets (GST_RTSP_LOWER_TRANS_UDP, G_SOCKET_FAMILY_IPV6);
147 }
148
149 GST_END_TEST;
150
151 GST_START_TEST (test_get_sockets_mcast)
152 {
153   get_sockets (GST_RTSP_LOWER_TRANS_UDP_MCAST, G_SOCKET_FAMILY_IPV4);
154   get_sockets (GST_RTSP_LOWER_TRANS_UDP_MCAST, G_SOCKET_FAMILY_IPV6);
155 }
156
157 GST_END_TEST;
158
159 /* The purpose of this test is to make sure that it's not possible to allocate
160  * multicast UDP ports if the address pool does not contain multicast UDP
161  * addresses. */
162 GST_START_TEST (test_allocate_udp_ports_fail)
163 {
164   GstPad *srcpad;
165   GstElement *pay;
166   GstRTSPStream *stream;
167   GstBin *bin;
168   GstElement *rtpbin;
169   GstRTSPAddressPool *pool;
170   GstRTSPTransport *transport;
171
172   srcpad = gst_pad_new ("testsrcpad", GST_PAD_SRC);
173   fail_unless (srcpad != NULL);
174   gst_pad_set_active (srcpad, TRUE);
175   pay = gst_element_factory_make ("rtpgstpay", "testpayloader");
176   fail_unless (pay != NULL);
177   stream = gst_rtsp_stream_new (0, pay, srcpad);
178   fail_unless (stream != NULL);
179   gst_object_unref (pay);
180   gst_object_unref (srcpad);
181   rtpbin = gst_element_factory_make ("rtpbin", "testrtpbin");
182   fail_unless (rtpbin != NULL);
183   bin = GST_BIN (gst_bin_new ("testbin"));
184   fail_unless (bin != NULL);
185   fail_unless (gst_bin_add (bin, rtpbin));
186
187   pool = gst_rtsp_address_pool_new ();
188   fail_unless (gst_rtsp_address_pool_add_range (pool, "192.168.1.1",
189           "192.168.1.1", 6000, 6001, 0));
190   gst_rtsp_stream_set_address_pool (stream, pool);
191
192   fail_unless (gst_rtsp_stream_join_bin (stream, bin, rtpbin, GST_STATE_NULL));
193
194   fail_unless (gst_rtsp_transport_new (&transport) == GST_RTSP_OK);
195   transport->lower_transport = GST_RTSP_LOWER_TRANS_UDP_MCAST;
196   fail_if (gst_rtsp_stream_allocate_udp_sockets (stream, G_SOCKET_FAMILY_IPV4,
197           transport, FALSE));
198   fail_unless (gst_rtsp_transport_free (transport) == GST_RTSP_OK);
199
200   g_object_unref (pool);
201   fail_unless (gst_rtsp_stream_leave_bin (stream, bin, rtpbin));
202   gst_object_unref (bin);
203   gst_object_unref (stream);
204 }
205
206 GST_END_TEST;
207
208 GST_START_TEST (test_get_multicast_address)
209 {
210   GstPad *srcpad;
211   GstElement *pay;
212   GstRTSPStream *stream;
213   GstRTSPAddressPool *pool;
214   GstRTSPAddress *addr1;
215   GstRTSPAddress *addr2;
216
217   srcpad = gst_pad_new ("testsrcpad", GST_PAD_SRC);
218   fail_unless (srcpad != NULL);
219   gst_pad_set_active (srcpad, TRUE);
220   pay = gst_element_factory_make ("rtpgstpay", "testpayloader");
221   fail_unless (pay != NULL);
222   stream = gst_rtsp_stream_new (0, pay, srcpad);
223   fail_unless (stream != NULL);
224   gst_object_unref (pay);
225   gst_object_unref (srcpad);
226
227   pool = gst_rtsp_address_pool_new ();
228   fail_unless (gst_rtsp_address_pool_add_range (pool,
229           "233.252.0.0", "233.252.0.0", 5100, 5101, 1));
230   fail_unless (gst_rtsp_address_pool_add_range (pool,
231           "FF11:DB8::1", "FF11:DB8::1", 5102, 5103, 1));
232   gst_rtsp_stream_set_address_pool (stream, pool);
233
234   addr1 = gst_rtsp_stream_get_multicast_address (stream, G_SOCKET_FAMILY_IPV4);
235   fail_unless (addr1 != NULL);
236   fail_unless_equals_string (addr1->address, "233.252.0.0");
237   fail_unless_equals_int (addr1->port, 5100);
238   fail_unless_equals_int (addr1->n_ports, 2);
239
240   addr2 = gst_rtsp_stream_get_multicast_address (stream, G_SOCKET_FAMILY_IPV4);
241   fail_unless (addr2 != NULL);
242   fail_unless_equals_string (addr2->address, "233.252.0.0");
243   fail_unless_equals_int (addr2->port, 5100);
244   fail_unless_equals_int (addr2->n_ports, 2);
245
246   gst_rtsp_address_free (addr1);
247   gst_rtsp_address_free (addr2);
248
249   addr1 = gst_rtsp_stream_get_multicast_address (stream, G_SOCKET_FAMILY_IPV6);
250   fail_unless (addr1 != NULL);
251   fail_unless (!g_ascii_strcasecmp (addr1->address, "FF11:DB8::1"));
252   fail_unless_equals_int (addr1->port, 5102);
253   fail_unless_equals_int (addr1->n_ports, 2);
254
255   addr2 = gst_rtsp_stream_get_multicast_address (stream, G_SOCKET_FAMILY_IPV6);
256   fail_unless (addr2 != NULL);
257   fail_unless (!g_ascii_strcasecmp (addr2->address, "FF11:DB8::1"));
258   fail_unless_equals_int (addr2->port, 5102);
259   fail_unless_equals_int (addr2->n_ports, 2);
260
261   gst_rtsp_address_free (addr1);
262   gst_rtsp_address_free (addr2);
263
264   g_object_unref (pool);
265
266   gst_object_unref (stream);
267 }
268
269 GST_END_TEST;
270
271 /*  test case: address pool only contains multicast addresses,
272  *  but the client is requesting unicast udp */
273 GST_START_TEST (test_multicast_address_and_unicast_udp)
274 {
275   GstPad *srcpad;
276   GstElement *pay;
277   GstRTSPStream *stream;
278   GstBin *bin;
279   GstElement *rtpbin;
280   GstRTSPAddressPool *pool;
281
282   srcpad = gst_pad_new ("testsrcpad", GST_PAD_SRC);
283   fail_unless (srcpad != NULL);
284   gst_pad_set_active (srcpad, TRUE);
285   pay = gst_element_factory_make ("rtpgstpay", "testpayloader");
286   fail_unless (pay != NULL);
287   stream = gst_rtsp_stream_new (0, pay, srcpad);
288   fail_unless (stream != NULL);
289   gst_object_unref (pay);
290   gst_object_unref (srcpad);
291   rtpbin = gst_element_factory_make ("rtpbin", "testrtpbin");
292   fail_unless (rtpbin != NULL);
293   bin = GST_BIN (gst_bin_new ("testbin"));
294   fail_unless (bin != NULL);
295   fail_unless (gst_bin_add (bin, rtpbin));
296
297   pool = gst_rtsp_address_pool_new ();
298   /* add a multicast addres to the address pool */
299   fail_unless (gst_rtsp_address_pool_add_range (pool,
300           "233.252.0.0", "233.252.0.0", 5200, 5201, 1));
301   gst_rtsp_stream_set_address_pool (stream, pool);
302
303   fail_unless (gst_rtsp_stream_join_bin (stream, bin, rtpbin, GST_STATE_NULL));
304
305   g_object_unref (pool);
306   fail_unless (gst_rtsp_stream_leave_bin (stream, bin, rtpbin));
307   gst_object_unref (bin);
308   gst_object_unref (stream);
309 }
310
311 GST_END_TEST;
312
313 GST_START_TEST (test_allocate_udp_ports_multicast)
314 {
315   GstPad *srcpad;
316   GstElement *pay;
317   GstRTSPStream *stream;
318   GstBin *bin;
319   GstElement *rtpbin;
320   GstRTSPAddressPool *pool;
321   GstRTSPAddress *addr;
322
323   srcpad = gst_pad_new ("testsrcpad", GST_PAD_SRC);
324   fail_unless (srcpad != NULL);
325   gst_pad_set_active (srcpad, TRUE);
326   pay = gst_element_factory_make ("rtpgstpay", "testpayloader");
327   fail_unless (pay != NULL);
328   stream = gst_rtsp_stream_new (0, pay, srcpad);
329   fail_unless (stream != NULL);
330   gst_object_unref (pay);
331   gst_object_unref (srcpad);
332   rtpbin = gst_element_factory_make ("rtpbin", "testrtpbin");
333   fail_unless (rtpbin != NULL);
334   bin = GST_BIN (gst_bin_new ("testbin"));
335   fail_unless (bin != NULL);
336   fail_unless (gst_bin_add (bin, rtpbin));
337
338   pool = gst_rtsp_address_pool_new ();
339   /* add multicast addresses to the address pool */
340   fail_unless (gst_rtsp_address_pool_add_range (pool,
341           "233.252.0.1", "233.252.0.1", 6000, 6001, 1));
342   fail_unless (gst_rtsp_address_pool_add_range (pool,
343           "FF11:DB8::1", "FF11:DB8::1", 6002, 6003, 1));
344   gst_rtsp_stream_set_address_pool (stream, pool);
345
346   fail_unless (gst_rtsp_stream_join_bin (stream, bin, rtpbin, GST_STATE_NULL));
347
348   /* check the multicast address and ports for IPv4 */
349   addr = gst_rtsp_stream_get_multicast_address (stream, G_SOCKET_FAMILY_IPV4);
350   fail_unless (addr != NULL);
351   fail_unless_equals_string (addr->address, "233.252.0.1");
352   fail_unless_equals_int (addr->port, 6000);
353   fail_unless_equals_int (addr->n_ports, 2);
354   gst_rtsp_address_free (addr);
355
356   /* check the multicast address and ports for IPv6 */
357   addr = gst_rtsp_stream_get_multicast_address (stream, G_SOCKET_FAMILY_IPV6);
358   fail_unless (addr != NULL);
359   fail_unless (!g_ascii_strcasecmp (addr->address, "FF11:DB8::1"));
360   fail_unless_equals_int (addr->port, 6002);
361   fail_unless_equals_int (addr->n_ports, 2);
362   gst_rtsp_address_free (addr);
363
364   g_object_unref (pool);
365   fail_unless (gst_rtsp_stream_leave_bin (stream, bin, rtpbin));
366   gst_object_unref (bin);
367   gst_object_unref (stream);
368 }
369
370 GST_END_TEST;
371
372 GST_START_TEST (test_allocate_udp_ports_client_settings)
373 {
374   GstPad *srcpad;
375   GstElement *pay;
376   GstRTSPStream *stream;
377   GstBin *bin;
378   GstElement *rtpbin;
379   GstRTSPAddressPool *pool;
380   GstRTSPAddress *addr;
381
382   srcpad = gst_pad_new ("testsrcpad", GST_PAD_SRC);
383   fail_unless (srcpad != NULL);
384   gst_pad_set_active (srcpad, TRUE);
385   pay = gst_element_factory_make ("rtpgstpay", "testpayloader");
386   fail_unless (pay != NULL);
387   stream = gst_rtsp_stream_new (0, pay, srcpad);
388   fail_unless (stream != NULL);
389   gst_object_unref (pay);
390   gst_object_unref (srcpad);
391   rtpbin = gst_element_factory_make ("rtpbin", "testrtpbin");
392   fail_unless (rtpbin != NULL);
393   bin = GST_BIN (gst_bin_new ("testbin"));
394   fail_unless (bin != NULL);
395   fail_unless (gst_bin_add (bin, rtpbin));
396
397   pool = gst_rtsp_address_pool_new ();
398   /* add multicast addresses to the address pool */
399   fail_unless (gst_rtsp_address_pool_add_range (pool,
400           "233.252.0.1", "233.252.0.1", 6000, 6001, 1));
401   fail_unless (gst_rtsp_address_pool_add_range (pool,
402           "FF11:DB7::1", "FF11:DB7::1", 6004, 6005, 1));
403   /* multicast address specified by the client */
404   fail_unless (gst_rtsp_address_pool_add_range (pool,
405           "233.252.0.2", "233.252.0.2", 6002, 6003, 1));
406   fail_unless (gst_rtsp_address_pool_add_range (pool,
407           "FF11:DB8::1", "FF11:DB8::1", 6006, 6007, 1));
408   gst_rtsp_stream_set_address_pool (stream, pool);
409
410   fail_unless (gst_rtsp_stream_join_bin (stream, bin, rtpbin, GST_STATE_NULL));
411
412   /* Reserve IPV4 mcast address */
413   addr = gst_rtsp_stream_reserve_address (stream, "233.252.0.2", 6002, 2, 1);
414   fail_unless (addr != NULL);
415   gst_rtsp_address_free (addr);
416
417   /* verify that the multicast address and ports correspond to the requested client
418    * transport information for IPv4 */
419   addr = gst_rtsp_stream_get_multicast_address (stream, G_SOCKET_FAMILY_IPV4);
420   fail_unless (addr != NULL);
421   fail_unless_equals_string (addr->address, "233.252.0.2");
422   fail_unless_equals_int (addr->port, 6002);
423   fail_unless_equals_int (addr->n_ports, 2);
424   gst_rtsp_address_free (addr);
425
426   /* Reserve IPV6 mcast address */
427   addr = gst_rtsp_stream_reserve_address (stream, "FF11:DB8::1", 6006, 2, 1);
428   fail_unless (addr != NULL);
429   gst_rtsp_address_free (addr);
430
431   /* verify that the multicast address and ports correspond to the requested client
432    * transport information for IPv6 */
433   addr = gst_rtsp_stream_get_multicast_address (stream, G_SOCKET_FAMILY_IPV6);
434   fail_unless (addr != NULL);
435   fail_unless (!g_ascii_strcasecmp (addr->address, "FF11:DB8::1"));
436   fail_unless_equals_int (addr->port, 6006);
437   fail_unless_equals_int (addr->n_ports, 2);
438   gst_rtsp_address_free (addr);
439
440   g_object_unref (pool);
441   fail_unless (gst_rtsp_stream_leave_bin (stream, bin, rtpbin));
442   gst_object_unref (bin);
443   gst_object_unref (stream);
444 }
445
446 GST_END_TEST;
447
448 GST_START_TEST (test_tcp_transport)
449 {
450   GstPad *srcpad;
451   GstElement *pay;
452   GstRTSPStream *stream;
453   GstBin *bin;
454   GstElement *rtpbin;
455   GstRTSPRange server_port;
456
457   srcpad = gst_pad_new ("testsrcpad", GST_PAD_SRC);
458   fail_unless (srcpad != NULL);
459   gst_pad_set_active (srcpad, TRUE);
460   pay = gst_element_factory_make ("rtpgstpay", "testpayloader");
461   fail_unless (pay != NULL);
462   stream = gst_rtsp_stream_new (0, pay, srcpad);
463   fail_unless (stream != NULL);
464   gst_object_unref (pay);
465   gst_object_unref (srcpad);
466   rtpbin = gst_element_factory_make ("rtpbin", "testrtpbin");
467   fail_unless (rtpbin != NULL);
468   bin = GST_BIN (gst_bin_new ("testbin"));
469   fail_unless (bin != NULL);
470   fail_unless (gst_bin_add (bin, rtpbin));
471
472   /* TCP transport */
473   gst_rtsp_stream_set_protocols (stream, GST_RTSP_LOWER_TRANS_TCP);
474   fail_unless (gst_rtsp_stream_join_bin (stream, bin, rtpbin, GST_STATE_NULL));
475
476   /* port that the server will use to receive RTCP makes only sense in the UDP
477    * case so verify that the received server port is 0 in the TCP case */
478   gst_rtsp_stream_get_server_port (stream, &server_port, G_SOCKET_FAMILY_IPV4);
479   fail_unless_equals_int (server_port.min, 0);
480   fail_unless_equals_int (server_port.max, 0);
481
482   fail_unless (gst_rtsp_stream_leave_bin (stream, bin, rtpbin));
483   gst_object_unref (bin);
484   gst_object_unref (stream);
485 }
486
487 GST_END_TEST;
488
489 static void
490 check_multicast_client_address (const gchar * destination, guint port,
491     const gchar * expected_addr_str, gboolean expected_res)
492 {
493   GstPad *srcpad;
494   GstElement *pay;
495   GstRTSPStream *stream;
496   GstBin *bin;
497   GstElement *rtpbin;
498   GstRTSPTransport *transport;
499   GstRTSPRange ports = { 0 };
500   gchar *addr_str = NULL;
501
502   srcpad = gst_pad_new ("testsrcpad", GST_PAD_SRC);
503   fail_unless (srcpad != NULL);
504   gst_pad_set_active (srcpad, TRUE);
505   pay = gst_element_factory_make ("rtpgstpay", "testpayloader");
506   fail_unless (pay != NULL);
507   stream = gst_rtsp_stream_new (0, pay, srcpad);
508   fail_unless (stream != NULL);
509   gst_object_unref (pay);
510   gst_object_unref (srcpad);
511   rtpbin = gst_element_factory_make ("rtpbin", "testrtpbin");
512   fail_unless (rtpbin != NULL);
513   bin = GST_BIN (gst_bin_new ("testbin"));
514   fail_unless (bin != NULL);
515   fail_unless (gst_bin_add (bin, rtpbin));
516
517   fail_unless (gst_rtsp_stream_join_bin (stream, bin, rtpbin, GST_STATE_NULL));
518
519   fail_unless (gst_rtsp_transport_new (&transport) == GST_RTSP_OK);
520   transport->lower_transport = GST_RTSP_LOWER_TRANS_UDP_MCAST;
521   transport->destination = g_strdup (destination);
522   transport->ttl = 1;
523   ports.min = port;
524   ports.max = port + 1;
525   transport->port = ports;
526
527   /* allocate ports */
528   fail_unless (gst_rtsp_stream_allocate_udp_sockets (stream,
529           G_SOCKET_FAMILY_IPV4, transport, TRUE) == expected_res);
530
531   fail_unless (gst_rtsp_stream_add_multicast_client_address (stream,
532           destination, ports.min, ports.max, G_SOCKET_FAMILY_IPV4) == expected_res);
533
534   fail_unless (gst_rtsp_stream_complete_stream (stream, transport) == expected_res);
535
536   fail_unless (gst_rtsp_transport_free (transport) == GST_RTSP_OK);
537   addr_str = gst_rtsp_stream_get_multicast_client_addresses (stream);
538
539   fail_unless (g_str_equal (addr_str, expected_addr_str));
540   g_free (addr_str);
541
542   fail_unless (gst_rtsp_stream_leave_bin (stream, bin, rtpbin));
543
544   gst_object_unref (bin);
545   gst_object_unref (stream);
546 }
547
548 /* test if the provided transport destination is correct.
549  * CASE: valid multicast address */
550 GST_START_TEST (test_multicast_client_address)
551 {
552   const gchar *addr = "233.252.0.1";
553   guint port = 50000;
554   const gchar *expected_addr_str = "233.252.0.1:50000";
555   gboolean expected_res = TRUE;
556
557   check_multicast_client_address (addr, port, expected_addr_str, expected_res);
558 }
559
560 GST_END_TEST;
561
562 /* test if the provided transport destination is correct.
563  * CASE: invalid multicast address */
564 GST_START_TEST (test_multicast_client_address_invalid)
565 {
566   const gchar *addr = "1.2.3.4";
567   guint port = 50000;
568   const gchar *expected_addr_str = "";
569   gboolean expected_res = FALSE;
570
571   check_multicast_client_address (addr, port, expected_addr_str, expected_res);
572 }
573
574 GST_END_TEST;
575
576 static Suite *
577 rtspstream_suite (void)
578 {
579   Suite *s = suite_create ("rtspstream");
580   TCase *tc = tcase_create ("general");
581
582   suite_add_tcase (s, tc);
583   tcase_add_test (tc, test_get_sockets_udp);
584   tcase_add_test (tc, test_get_sockets_mcast);
585   tcase_add_test (tc, test_allocate_udp_ports_fail);
586   tcase_add_test (tc, test_get_multicast_address);
587   tcase_add_test (tc, test_multicast_address_and_unicast_udp);
588   tcase_add_test (tc, test_allocate_udp_ports_multicast);
589   tcase_add_test (tc, test_allocate_udp_ports_client_settings);
590   tcase_add_test (tc, test_tcp_transport);
591   tcase_add_test (tc, test_multicast_client_address);
592   tcase_add_test (tc, test_multicast_client_address_invalid);
593
594   return s;
595 }
596
597 GST_CHECK_MAIN (rtspstream);