2 * Copyright (C) 2012 Wim Taymans <wim.taymans@gmail.com>
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.
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.
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.
20 #include <gst/check/gstcheck.h>
22 #include <rtsp-address-pool.h>
24 GST_START_TEST (test_pool)
26 GstRTSPAddressPool *pool;
27 GstRTSPAddress *addr, *addr2;
29 pool = gst_rtsp_address_pool_new ();
31 fail_if (gst_rtsp_address_pool_add_range (pool,
32 "233.252.0.1", "233.252.0.0", 5000, 5010, 1));
33 fail_if (gst_rtsp_address_pool_add_range (pool,
34 "233.252.0.1", "::1", 5000, 5010, 1));
35 fail_if (gst_rtsp_address_pool_add_range (pool,
36 "233.252.0.1.1", "233.252.0.1", 5000, 5010, 1));
37 fail_if (gst_rtsp_address_pool_add_range (pool,
38 "233.252.0.1", "233.252.0.1.1", 5000, 5010, 1));
39 ASSERT_CRITICAL (gst_rtsp_address_pool_add_range (pool,
40 "233.252.0.0", "233.252.0.1", 5010, 5000, 1));
42 fail_unless (gst_rtsp_address_pool_add_range (pool,
43 "233.252.0.0", "233.252.0.255", 5000, 5010, 1));
44 fail_unless (gst_rtsp_address_pool_add_range (pool,
45 "233.255.0.0", "233.255.0.0", 5000, 5010, 1));
46 fail_unless (gst_rtsp_address_pool_add_range (pool,
47 "233.255.0.0", "233.255.0.0", 5020, 5020, 1));
49 /* should fail, we can't allocate a block of 256 ports */
50 addr = gst_rtsp_address_pool_acquire_address (pool, 0, 256);
51 fail_unless (addr == NULL);
53 addr = gst_rtsp_address_pool_acquire_address (pool, 0, 2);
54 fail_unless (addr != NULL);
56 addr2 = gst_rtsp_address_copy (addr);
58 gst_rtsp_address_free (addr2);
59 gst_rtsp_address_free (addr);
61 addr = gst_rtsp_address_pool_acquire_address (pool, 0, 4);
62 fail_unless (addr != NULL);
64 /* Will fail because pool is NULL */
65 ASSERT_CRITICAL (gst_rtsp_address_pool_clear (NULL));
67 /* will fail because an address is allocated */
68 ASSERT_CRITICAL (gst_rtsp_address_pool_clear (pool));
70 gst_rtsp_address_free (addr);
72 gst_rtsp_address_pool_clear (pool);
74 /* start with odd port to make sure we are allocated address
75 * starting with even port
77 fail_unless (gst_rtsp_address_pool_add_range (pool,
78 "2001:DB8::1", "2001:DB8::1", 5001, 5003, 1));
80 addr = gst_rtsp_address_pool_acquire_address (pool,
81 GST_RTSP_ADDRESS_FLAG_IPV6 | GST_RTSP_ADDRESS_FLAG_EVEN_PORT, 2);
82 fail_unless (addr != NULL);
83 fail_unless (addr->port == 5002);
85 /* Will fail becuse there is only one IPv6 address left */
86 addr2 = gst_rtsp_address_pool_acquire_address (pool,
87 GST_RTSP_ADDRESS_FLAG_IPV6, 2);
88 fail_unless (addr2 == NULL);
90 /* Will fail because the only IPv6 address left has an odd port */
91 addr2 = gst_rtsp_address_pool_acquire_address (pool,
92 GST_RTSP_ADDRESS_FLAG_IPV6 | GST_RTSP_ADDRESS_FLAG_EVEN_PORT, 1);
93 fail_unless (addr2 == NULL);
95 gst_rtsp_address_free (addr);
97 gst_rtsp_address_pool_clear (pool);
99 fail_unless (gst_rtsp_address_pool_add_range (pool,
100 "233.252.0.0", "233.252.0.255", 5000, 5002, 1));
102 addr = gst_rtsp_address_pool_acquire_address (pool,
103 GST_RTSP_ADDRESS_FLAG_EVEN_PORT, 2);
104 fail_unless (addr != NULL);
105 fail_unless (addr->port == 5000);
107 addr2 = gst_rtsp_address_pool_acquire_address (pool,
108 GST_RTSP_ADDRESS_FLAG_EVEN_PORT, 2);
109 fail_unless (addr2 != NULL);
110 fail_unless (addr2->port == 5000);
112 gst_rtsp_address_free (addr);
113 gst_rtsp_address_free (addr2);
115 g_object_unref (pool);
121 rtspaddresspool_suite (void)
123 Suite *s = suite_create ("rtspaddresspool");
124 TCase *tc = tcase_create ("general");
126 suite_add_tcase (s, tc);
127 tcase_set_timeout (tc, 20);
128 tcase_add_test (tc, test_pool);
133 GST_CHECK_MAIN (rtspaddresspool);