diff options
author | Andrew Kroeger <andrew@id10ts.net> | 2009-09-04 16:45:01 -0500 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2009-09-05 10:06:29 +1000 |
commit | a32f4dd3cfd43022ab3224366e026664b238429e (patch) | |
tree | ee8b7ac490ca181e830a62bd05e6542f7d1c15a6 /lib/util | |
parent | 5afa115f2ad150563fdf8ba978e5f165d75eba4b (diff) | |
download | samba-a32f4dd3cfd43022ab3224366e026664b238429e.tar.gz samba-a32f4dd3cfd43022ab3224366e026664b238429e.tar.bz2 samba-a32f4dd3cfd43022ab3224366e026664b238429e.zip |
util:tests: Correct time tests for negative UTC offsets.
All:
Please find attached a patch to fix the timestring and http_timestring
tests on hosts that have a negative UTC offset (west of the Prime Meridian).
Sincerely,
Andrew Kroeger
>From 8a8ca35edccf64aa98f2f3ae1469c4c27db8215e Mon Sep 17 00:00:00 2001
From: Andrew Kroeger <andrew@id10ts.net>
Date: Fri, 4 Sep 2009 01:31:50 -0500
Subject: [PATCH] util:tests: Correct time tests for negative UTC offsets.
The timestring and http_timestring tests were failing on hosts with negative
offsets from UTC. Due to the timezone offset, the returned values were back in
the year 1969 (before the epoch) and did not match the test patterns.
The correction computes the offset from UTC, and if it is negative that offset
is added onto the value given to the timestring() and http_timestring() calls so
that the returned values fall on 01-Jan-1970 and match the test pattern.
Diffstat (limited to 'lib/util')
-rw-r--r-- | lib/util/tests/time.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/util/tests/time.c b/lib/util/tests/time.c index b7cb608611..d08a4e79d1 100644 --- a/lib/util/tests/time.c +++ b/lib/util/tests/time.c @@ -44,7 +44,17 @@ static bool test_http_timestring(struct torture_context *tctx) { const char *start = "Thu, 01 Jan 1970"; char *result; - result = http_timestring(tctx, 42); + /* + * Correct test for negative UTC offset. Without the correction, the + * test fails when run on hosts with negative UTC offsets, as the date + * returned is back in 1969 (pre-epoch). + */ + time_t now = time(NULL); + struct tm local = *localtime(&now); + struct tm gmt = *gmtime(&now); + time_t utc_offset = mktime(&local) - mktime(&gmt); + + result = http_timestring(tctx, 42 - (utc_offset < 0 ? utc_offset : 0)); torture_assert(tctx, !strncmp(start, result, strlen(start)), result); torture_assert_str_equal(tctx, "never", @@ -55,7 +65,18 @@ static bool test_http_timestring(struct torture_context *tctx) static bool test_timestring(struct torture_context *tctx) { const char *start = "Thu Jan 1"; - char *result = timestring(tctx, 42); + char *result; + /* + * Correct test for negative UTC offset. Without the correction, the + * test fails when run on hosts with negative UTC offsets, as the date + * returned is back in 1969 (pre-epoch). + */ + time_t now = time(NULL); + struct tm local = *localtime(&now); + struct tm gmt = *gmtime(&now); + time_t utc_offset = mktime(&local) - mktime(&gmt); + + result = timestring(tctx, 42 - (utc_offset < 0 ? utc_offset : 0)); torture_assert(tctx, !strncmp(start, result, strlen(start)), result); return true; |