[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Improve coverage in time-related unit tests



commit 03258529d8216e7454227b166be159e70f993e90
Author: Esteban Manchado Velázquez <emanchado@xxxxxxxxxxxx>
Date:   Mon Feb 20 13:19:03 2012 +0100

    Improve coverage in time-related unit tests
---
 src/test/test_util.c |   30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/src/test/test_util.c b/src/test/test_util.c
index 3860f15..1305e2f 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -67,6 +67,15 @@ test_util_time(void)
   a_time.tm_mon = 1;          /* Try a leap year, in feb. */
   a_time.tm_mday = 10;
   test_eq((time_t) 1076393695UL, tor_timegm(&a_time));
+  a_time.tm_mon = 0;
+  a_time.tm_mday = 10;
+  test_eq((time_t) 1073715295UL, tor_timegm(&a_time));
+  a_time.tm_mon = 12;          /* Wrong month, it's 0-based */
+  a_time.tm_mday = 10;
+  test_eq((time_t) -1, tor_timegm(&a_time));
+  a_time.tm_mon = -1;          /* Wrong month */
+  a_time.tm_mday = 10;
+  test_eq((time_t) -1, tor_timegm(&a_time));
 
 
   /* Test {format,parse}_rfc1123_time */
@@ -78,9 +87,28 @@ test_util_time(void)
 
   t_res = 0;
   i = parse_rfc1123_time(timestr, &t_res);
-  test_eq(i,0);
+  test_eq(0,i);
+  test_eq(t_res, (time_t)1091580502UL);
+  /* The timezone doesn't matter */
+  t_res = 0;
+  test_eq(0, parse_rfc1123_time("Wed, 04 Aug 2004 00:48:22 ZUL", &t_res));
   test_eq(t_res, (time_t)1091580502UL);
   test_eq(-1, parse_rfc1123_time("Wed, zz Aug 2004 99-99x99 GMT", &t_res));
+  test_eq(-1, parse_rfc1123_time("Wed, 32 Mar 2011 00:00:00 GMT", &t_res));
+  test_eq(-1, parse_rfc1123_time("Wed, 30 Mar 2011 24:00:00 GMT", &t_res));
+  test_eq(-1, parse_rfc1123_time("Wed, 30 Mar 2011 23:60:00 GMT", &t_res));
+  test_eq(-1, parse_rfc1123_time("Wed, 30 Mar 2011 23:59:62 GMT", &t_res));
+  test_eq(-1, parse_rfc1123_time("Wed, 30 Mar 1969 23:59:59 GMT", &t_res));
+  test_eq(-1, parse_rfc1123_time("Wed, 30 Ene 2011 23:59:59 GMT", &t_res));
+  test_eq(-1, parse_rfc1123_time("Wed, 30 Mar 2011 23:59:59 GM", &t_res));
+
+#if 0
+  /* This fails, I imagine it's important and should be fixed? */
+  test_eq(-1, parse_rfc1123_time("Wed, 29 Feb 2011 16:00:00 GMT", &t_res));
+  /* Why is this string valid (ie. the test fails because it doesn't
+     return -1)? */
+  test_eq(-1, parse_rfc1123_time("Wed, 30 Mar 2011 23:59:61 GMT", &t_res));
+#endif
 
 
   /* Test tor_gettimeofday */



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits