[Freeswitch-svn] [commit] r12286 - in freeswitch/trunk/libs/sofia-sip: . libsofia-sip-ua/sresolv

FreeSWITCH SVN mikej at freeswitch.org
Wed Feb 25 11:40:22 PST 2009


Author: mikej
Date: Wed Feb 25 13:40:22 2009
New Revision: 12286

Log:
Wed Feb 25 13:11:19 CST 2009  Pekka Pessi <first.last at nokia.com>
  * check_sres_sip.c: added test cases for bad DNS server, timeout
  Ignore-this: f14a52817f3612c0b8b776761a12ef3e



Modified:
   freeswitch/trunk/libs/sofia-sip/.update
   freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sresolv/check_sres_sip.c

Modified: freeswitch/trunk/libs/sofia-sip/.update
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/.update	(original)
+++ freeswitch/trunk/libs/sofia-sip/.update	Wed Feb 25 13:40:22 2009
@@ -1 +1 @@
-Wed Feb 25 13:39:07 CST 2009
+Wed Feb 25 13:40:08 CST 2009

Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sresolv/check_sres_sip.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sresolv/check_sres_sip.c	(original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sresolv/check_sres_sip.c	Wed Feb 25 13:40:22 2009
@@ -215,6 +215,93 @@
 }
 END_TEST
 
+START_TEST(failure)
+{
+  sres_sip_t *srs;
+  su_addrinfo_t const *ai;
+
+  /* there is no server at all */
+  s2_dns_teardown();
+
+  srs = sres_sip_new(x->sres, (void *)"sip:timeout.example.net", NULL,
+		    1, 1,
+		    resolver_callback, x->root);
+  fail_if(srs == NULL);
+
+  while (sres_sip_next_step(srs))
+    su_root_run(x->root);
+
+  ai = sres_sip_results(srs);
+  fail_if(ai != NULL);
+
+  fail_if(sres_sip_error(srs) != SRES_SIP_ERR_AGAIN);
+
+  sres_sip_unref(srs);
+}
+END_TEST
+
+/* time() replacement */
+static time_t offset;
+
+time_t
+time(time_t *return_time)
+{
+  su_time_t tv;
+  time_t now;
+
+  su_time(&tv);
+
+  now = tv.tv_sec + offset - 2208988800UL; /* NTP_EPOCH */
+
+  if (return_time)
+    *return_time = now;
+
+  return now;
+}
+
+/* Drop packet */
+static int drop(void *data, size_t len, void *userdata)
+{
+  return 0;
+}
+
+/* Fast forward time, call resolver timer */
+static void wakeup(su_root_magic_t *magic,
+		   su_timer_t *timer,
+		   su_timer_arg_t *extra)
+{
+  offset++;
+  sres_resolver_timer(x->sres, 0);
+}
+
+START_TEST(timeout)
+{
+  sres_sip_t *srs;
+  su_addrinfo_t const *ai;
+  su_timer_t *faster = su_timer_create(su_root_task(x->root), 10);
+
+  su_timer_run(faster, wakeup, NULL);
+
+  s2_dns_set_filter(drop, NULL);
+
+  srs = sres_sip_new(x->sres, (void *)"sip:timeout.example.net", NULL,
+		    1, 1,
+		    resolver_callback, x->root);
+  fail_if(srs == NULL);
+
+  while (sres_sip_next_step(srs))
+    su_root_run(x->root);
+
+  ai = sres_sip_results(srs);
+  fail_if(ai != NULL);
+
+  fail_if(sres_sip_error(srs) != SRES_SIP_ERR_AGAIN);
+
+  sres_sip_unref(srs);
+
+  su_timer_destroy(faster);
+}
+END_TEST
 
 START_TEST(found_a)
 {
@@ -342,6 +429,10 @@
 		"", sres_type_cname, "a.example.com.",
 		NULL);
 
+  s2_dns_record("cname1.example.com", sres_type_aaaa,
+		"", sres_type_cname, "a.example.com.",
+		NULL);
+
   s2_dns_record("a.example.com", sres_type_a,
 		"", sres_type_a, "11.12.13.14",
 		NULL);
@@ -933,6 +1024,8 @@
 
   tcase_add_test(tc, invalid);
   tcase_add_test(tc, not_found);
+  tcase_add_test(tc, failure);
+  tcase_add_test(tc, timeout);
   tcase_add_test(tc, found_a);
   tcase_add_test(tc, found_cname);
   tcase_add_test(tc, found_ip);



More information about the Freeswitch-svn mailing list