summaryrefslogtreecommitdiff
path: root/src/test/test_util.c
diff options
context:
space:
mode:
authorEsteban Manchado Velázquez <emanchado@demiurgo.org>2012-02-20 13:19:03 +0100
committerNick Mathewson <nickm@torproject.org>2012-03-08 21:16:45 -0500
commit03258529d8216e7454227b166be159e70f993e90 (patch)
tree13e7fdfcd7398664f590fb1e14ad722b7128d2f0 /src/test/test_util.c
parenta3679d30c050c96b43c17e8a8be4dc56490afe52 (diff)
downloadtor-03258529d8216e7454227b166be159e70f993e90.tar.gz
tor-03258529d8216e7454227b166be159e70f993e90.zip
Improve coverage in time-related unit tests
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r--src/test/test_util.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 3860f156a9..1305e2f087 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 */