2012-11-14 14:50:42 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2012 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gst/check/gstcheck.h>
|
|
|
|
|
|
|
|
#include <rtsp-address-pool.h>
|
|
|
|
|
|
|
|
GST_START_TEST (test_pool)
|
|
|
|
{
|
|
|
|
GstRTSPAddressPool *pool;
|
2013-02-13 23:01:43 +00:00
|
|
|
GstRTSPAddress *addr, *addr2, *addr3;
|
2012-11-14 14:50:42 +00:00
|
|
|
|
|
|
|
pool = gst_rtsp_address_pool_new ();
|
|
|
|
|
|
|
|
fail_if (gst_rtsp_address_pool_add_range (pool,
|
|
|
|
"233.252.0.1", "233.252.0.0", 5000, 5010, 1));
|
2013-02-12 21:34:37 +00:00
|
|
|
fail_if (gst_rtsp_address_pool_add_range (pool,
|
|
|
|
"233.252.0.1", "::1", 5000, 5010, 1));
|
|
|
|
fail_if (gst_rtsp_address_pool_add_range (pool,
|
|
|
|
"233.252.0.1.1", "233.252.0.1", 5000, 5010, 1));
|
|
|
|
fail_if (gst_rtsp_address_pool_add_range (pool,
|
|
|
|
"233.252.0.1", "233.252.0.1.1", 5000, 5010, 1));
|
2012-11-14 14:50:42 +00:00
|
|
|
ASSERT_CRITICAL (gst_rtsp_address_pool_add_range (pool,
|
|
|
|
"233.252.0.0", "233.252.0.1", 5010, 5000, 1));
|
|
|
|
|
|
|
|
fail_unless (gst_rtsp_address_pool_add_range (pool,
|
|
|
|
"233.252.0.0", "233.252.0.255", 5000, 5010, 1));
|
|
|
|
fail_unless (gst_rtsp_address_pool_add_range (pool,
|
|
|
|
"233.255.0.0", "233.255.0.0", 5000, 5010, 1));
|
|
|
|
fail_unless (gst_rtsp_address_pool_add_range (pool,
|
|
|
|
"233.255.0.0", "233.255.0.0", 5020, 5020, 1));
|
|
|
|
|
|
|
|
/* should fail, we can't allocate a block of 256 ports */
|
2013-02-19 21:34:16 +00:00
|
|
|
addr = gst_rtsp_address_pool_acquire_address (pool,
|
|
|
|
GST_RTSP_ADDRESS_FLAG_MULTICAST, 256);
|
2012-11-15 12:25:14 +00:00
|
|
|
fail_unless (addr == NULL);
|
2012-11-14 14:50:42 +00:00
|
|
|
|
2013-02-19 21:34:16 +00:00
|
|
|
addr = gst_rtsp_address_pool_acquire_address (pool,
|
|
|
|
GST_RTSP_ADDRESS_FLAG_MULTICAST, 2);
|
2012-11-15 12:25:14 +00:00
|
|
|
fail_unless (addr != NULL);
|
2012-11-14 14:50:42 +00:00
|
|
|
|
2013-02-12 21:34:37 +00:00
|
|
|
addr2 = gst_rtsp_address_copy (addr);
|
|
|
|
|
|
|
|
gst_rtsp_address_free (addr2);
|
2012-11-15 12:25:14 +00:00
|
|
|
gst_rtsp_address_free (addr);
|
2012-11-14 14:50:42 +00:00
|
|
|
|
2013-02-19 21:34:16 +00:00
|
|
|
addr = gst_rtsp_address_pool_acquire_address (pool,
|
|
|
|
GST_RTSP_ADDRESS_FLAG_MULTICAST, 4);
|
2012-11-15 12:25:14 +00:00
|
|
|
fail_unless (addr != NULL);
|
2012-11-14 14:50:42 +00:00
|
|
|
|
2013-02-12 21:34:37 +00:00
|
|
|
/* Will fail because pool is NULL */
|
|
|
|
ASSERT_CRITICAL (gst_rtsp_address_pool_clear (NULL));
|
|
|
|
|
|
|
|
/* will fail because an address is allocated */
|
|
|
|
ASSERT_CRITICAL (gst_rtsp_address_pool_clear (pool));
|
|
|
|
|
|
|
|
gst_rtsp_address_free (addr);
|
|
|
|
|
|
|
|
gst_rtsp_address_pool_clear (pool);
|
|
|
|
|
|
|
|
/* start with odd port to make sure we are allocated address
|
|
|
|
* starting with even port
|
|
|
|
*/
|
|
|
|
fail_unless (gst_rtsp_address_pool_add_range (pool,
|
2013-02-20 19:26:03 +00:00
|
|
|
"FF11:DB8::1", "FF11:DB8::1", 5001, 5003, 1));
|
2013-02-12 21:34:37 +00:00
|
|
|
|
|
|
|
addr = gst_rtsp_address_pool_acquire_address (pool,
|
2013-02-19 21:34:16 +00:00
|
|
|
GST_RTSP_ADDRESS_FLAG_IPV6 | GST_RTSP_ADDRESS_FLAG_EVEN_PORT |
|
|
|
|
GST_RTSP_ADDRESS_FLAG_MULTICAST, 2);
|
2013-02-12 21:34:37 +00:00
|
|
|
fail_unless (addr != NULL);
|
|
|
|
fail_unless (addr->port == 5002);
|
2013-02-20 19:26:03 +00:00
|
|
|
fail_unless (!g_ascii_strcasecmp (addr->address, "FF11:DB8::1"));
|
2013-02-12 21:34:37 +00:00
|
|
|
|
|
|
|
/* Will fail becuse there is only one IPv6 address left */
|
|
|
|
addr2 = gst_rtsp_address_pool_acquire_address (pool,
|
2013-02-19 21:34:16 +00:00
|
|
|
GST_RTSP_ADDRESS_FLAG_IPV6 | GST_RTSP_ADDRESS_FLAG_MULTICAST, 2);
|
2013-02-12 21:34:37 +00:00
|
|
|
fail_unless (addr2 == NULL);
|
|
|
|
|
|
|
|
/* Will fail because the only IPv6 address left has an odd port */
|
|
|
|
addr2 = gst_rtsp_address_pool_acquire_address (pool,
|
2013-02-19 21:34:16 +00:00
|
|
|
GST_RTSP_ADDRESS_FLAG_IPV6 | GST_RTSP_ADDRESS_FLAG_EVEN_PORT |
|
|
|
|
GST_RTSP_ADDRESS_FLAG_MULTICAST, 1);
|
2013-02-12 21:34:37 +00:00
|
|
|
fail_unless (addr2 == NULL);
|
|
|
|
|
|
|
|
gst_rtsp_address_free (addr);
|
|
|
|
|
|
|
|
gst_rtsp_address_pool_clear (pool);
|
|
|
|
|
|
|
|
fail_unless (gst_rtsp_address_pool_add_range (pool,
|
|
|
|
"233.252.0.0", "233.252.0.255", 5000, 5002, 1));
|
|
|
|
|
|
|
|
addr = gst_rtsp_address_pool_acquire_address (pool,
|
2013-02-19 21:34:16 +00:00
|
|
|
GST_RTSP_ADDRESS_FLAG_EVEN_PORT | GST_RTSP_ADDRESS_FLAG_MULTICAST, 2);
|
2013-02-12 21:34:37 +00:00
|
|
|
fail_unless (addr != NULL);
|
|
|
|
fail_unless (addr->port == 5000);
|
2013-02-13 23:01:43 +00:00
|
|
|
fail_unless (!strcmp (addr->address, "233.252.0.0"));
|
2013-02-12 21:34:37 +00:00
|
|
|
|
|
|
|
addr2 = gst_rtsp_address_pool_acquire_address (pool,
|
2013-02-19 21:34:16 +00:00
|
|
|
GST_RTSP_ADDRESS_FLAG_EVEN_PORT | GST_RTSP_ADDRESS_FLAG_MULTICAST, 2);
|
2013-02-12 21:34:37 +00:00
|
|
|
fail_unless (addr2 != NULL);
|
|
|
|
fail_unless (addr2->port == 5000);
|
2013-02-13 23:01:43 +00:00
|
|
|
fail_unless (!strcmp (addr2->address, "233.252.0.1"));
|
2013-02-12 21:34:37 +00:00
|
|
|
|
2012-11-15 12:25:14 +00:00
|
|
|
gst_rtsp_address_free (addr);
|
2013-02-12 21:34:37 +00:00
|
|
|
gst_rtsp_address_free (addr2);
|
2012-11-14 14:50:42 +00:00
|
|
|
|
2013-02-13 23:01:43 +00:00
|
|
|
gst_rtsp_address_pool_clear (pool);
|
|
|
|
|
|
|
|
|
|
|
|
fail_unless (gst_rtsp_address_pool_add_range (pool,
|
|
|
|
"233.252.1.1", "233.252.1.1", 5000, 5001, 1));
|
|
|
|
|
|
|
|
addr = gst_rtsp_address_pool_reserve_address (pool, "233.252.1.1", 5000, 3,
|
|
|
|
1);
|
|
|
|
fail_unless (addr == NULL);
|
|
|
|
|
|
|
|
addr = gst_rtsp_address_pool_reserve_address (pool, "233.252.1.2", 5000, 2,
|
|
|
|
1);
|
|
|
|
fail_unless (addr == NULL);
|
|
|
|
|
|
|
|
addr = gst_rtsp_address_pool_reserve_address (pool, "233.252.1.1", 500, 2, 1);
|
|
|
|
fail_unless (addr == NULL);
|
|
|
|
|
|
|
|
addr = gst_rtsp_address_pool_reserve_address (pool, "233.252.1.1", 5000, 2,
|
|
|
|
2);
|
|
|
|
fail_unless (addr == NULL);
|
|
|
|
|
|
|
|
addr = gst_rtsp_address_pool_reserve_address (pool, "2000::1", 5000, 2, 2);
|
|
|
|
fail_unless (addr == NULL);
|
|
|
|
|
|
|
|
addr = gst_rtsp_address_pool_reserve_address (pool, "1.1", 5000, 2, 2);
|
|
|
|
fail_unless (addr == NULL);
|
|
|
|
|
|
|
|
addr = gst_rtsp_address_pool_reserve_address (pool, "233.252.1.1", 5000, 2,
|
|
|
|
1);
|
|
|
|
fail_unless (addr != NULL);
|
|
|
|
fail_unless (addr->port == 5000);
|
|
|
|
fail_unless (!strcmp (addr->address, "233.252.1.1"));
|
|
|
|
|
|
|
|
gst_rtsp_address_free (addr);
|
|
|
|
gst_rtsp_address_pool_clear (pool);
|
|
|
|
|
|
|
|
fail_unless (gst_rtsp_address_pool_add_range (pool,
|
|
|
|
"233.252.1.1", "233.252.1.3", 5000, 5001, 1));
|
|
|
|
|
|
|
|
addr = gst_rtsp_address_pool_reserve_address (pool, "233.252.1.1", 5000, 2,
|
|
|
|
1);
|
|
|
|
fail_unless (addr != NULL);
|
|
|
|
fail_unless (addr->port == 5000);
|
|
|
|
fail_unless (!strcmp (addr->address, "233.252.1.1"));
|
|
|
|
|
|
|
|
addr2 = gst_rtsp_address_pool_reserve_address (pool, "233.252.1.3", 5000, 2,
|
|
|
|
1);
|
|
|
|
fail_unless (addr2 != NULL);
|
|
|
|
fail_unless (addr2->port == 5000);
|
|
|
|
fail_unless (!strcmp (addr2->address, "233.252.1.3"));
|
|
|
|
|
|
|
|
addr3 = gst_rtsp_address_pool_acquire_address (pool,
|
2013-02-19 21:34:16 +00:00
|
|
|
GST_RTSP_ADDRESS_FLAG_EVEN_PORT | GST_RTSP_ADDRESS_FLAG_MULTICAST, 2);
|
2013-02-13 23:01:43 +00:00
|
|
|
fail_unless (addr3 != NULL);
|
|
|
|
fail_unless (addr3->port == 5000);
|
|
|
|
fail_unless (!strcmp (addr3->address, "233.252.1.2"));
|
|
|
|
|
|
|
|
fail_unless (gst_rtsp_address_pool_acquire_address (pool,
|
2013-02-19 21:34:16 +00:00
|
|
|
GST_RTSP_ADDRESS_FLAG_EVEN_PORT | GST_RTSP_ADDRESS_FLAG_MULTICAST, 2)
|
|
|
|
== NULL);
|
2013-02-13 23:01:43 +00:00
|
|
|
|
|
|
|
gst_rtsp_address_free (addr);
|
|
|
|
gst_rtsp_address_free (addr2);
|
|
|
|
gst_rtsp_address_free (addr3);
|
2013-02-19 21:36:20 +00:00
|
|
|
gst_rtsp_address_pool_clear (pool);
|
|
|
|
|
|
|
|
fail_unless (gst_rtsp_address_pool_add_range (pool,
|
|
|
|
"233.252.1.1", "233.252.1.1", 5000, 5001, 1));
|
|
|
|
fail_unless (gst_rtsp_address_pool_add_range_unicast (pool,
|
|
|
|
"192.168.1.1", "192.168.1.1", 6000, 6001));
|
|
|
|
|
|
|
|
addr = gst_rtsp_address_pool_acquire_address (pool,
|
|
|
|
GST_RTSP_ADDRESS_FLAG_EVEN_PORT | GST_RTSP_ADDRESS_FLAG_MULTICAST, 2);
|
|
|
|
fail_unless (addr != NULL);
|
|
|
|
fail_unless (addr->port == 5000);
|
|
|
|
fail_unless (!strcmp (addr->address, "233.252.1.1"));
|
|
|
|
gst_rtsp_address_free (addr);
|
|
|
|
|
|
|
|
addr = gst_rtsp_address_pool_acquire_address (pool,
|
|
|
|
GST_RTSP_ADDRESS_FLAG_EVEN_PORT | GST_RTSP_ADDRESS_FLAG_UNICAST, 2);
|
|
|
|
fail_unless (addr != NULL);
|
|
|
|
fail_unless (addr->port == 6000);
|
|
|
|
fail_unless (!strcmp (addr->address, "192.168.1.1"));
|
|
|
|
gst_rtsp_address_free (addr);
|
|
|
|
|
2013-02-13 23:01:43 +00:00
|
|
|
|
2012-11-14 14:50:42 +00:00
|
|
|
g_object_unref (pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
static Suite *
|
|
|
|
rtspaddresspool_suite (void)
|
|
|
|
{
|
|
|
|
Suite *s = suite_create ("rtspaddresspool");
|
|
|
|
TCase *tc = tcase_create ("general");
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc);
|
|
|
|
tcase_set_timeout (tc, 20);
|
|
|
|
tcase_add_test (tc, test_pool);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_CHECK_MAIN (rtspaddresspool);
|