tests: Add more tests for the address pool
authorOlivier CrĂȘte <olivier.crete@collabora.com>
Tue, 12 Feb 2013 21:34:37 +0000 (16:34 -0500)
committerWim Taymans <wim.taymans@collabora.co.uk>
Mon, 11 Mar 2013 10:07:19 +0000 (11:07 +0100)
tests/check/gst/addresspool.c

index b05e973..9df35c7 100644 (file)
 GST_START_TEST (test_pool)
 {
   GstRTSPAddressPool *pool;
-  GstRTSPAddress *addr;
+  GstRTSPAddress *addr, *addr2;
 
   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));
+  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));
   ASSERT_CRITICAL (gst_rtsp_address_pool_add_range (pool,
           "233.252.0.0", "233.252.0.1", 5010, 5000, 1));
 
@@ -47,12 +53,64 @@ GST_START_TEST (test_pool)
   addr = gst_rtsp_address_pool_acquire_address (pool, 0, 2);
   fail_unless (addr != NULL);
 
+  addr2 = gst_rtsp_address_copy (addr);
+
+  gst_rtsp_address_free (addr2);
   gst_rtsp_address_free (addr);
 
   addr = gst_rtsp_address_pool_acquire_address (pool, 0, 4);
   fail_unless (addr != NULL);
 
+  /* 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,
+          "2001:DB8::1", "2001:DB8::1", 5001, 5003, 1));
+
+  addr = gst_rtsp_address_pool_acquire_address (pool,
+      GST_RTSP_ADDRESS_FLAG_IPV6 | GST_RTSP_ADDRESS_FLAG_EVEN_PORT, 2);
+  fail_unless (addr != NULL);
+  fail_unless (addr->port == 5002);
+
+  /* Will fail becuse there is only one IPv6 address left */
+  addr2 = gst_rtsp_address_pool_acquire_address (pool,
+      GST_RTSP_ADDRESS_FLAG_IPV6, 2);
+  fail_unless (addr2 == NULL);
+
+  /* Will fail because the only IPv6 address left has an odd port */
+  addr2 = gst_rtsp_address_pool_acquire_address (pool,
+      GST_RTSP_ADDRESS_FLAG_IPV6 | GST_RTSP_ADDRESS_FLAG_EVEN_PORT, 1);
+  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,
+      GST_RTSP_ADDRESS_FLAG_EVEN_PORT, 2);
+  fail_unless (addr != NULL);
+  fail_unless (addr->port == 5000);
+
+  addr2 = gst_rtsp_address_pool_acquire_address (pool,
+      GST_RTSP_ADDRESS_FLAG_EVEN_PORT, 2);
+  fail_unless (addr2 != NULL);
+  fail_unless (addr2->port == 5000);
+
   gst_rtsp_address_free (addr);
+  gst_rtsp_address_free (addr2);
 
   g_object_unref (pool);
 }