summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfuankg <fuankg@13f79535-47bb-0310-9956-ffa450edef68>2013-05-11 18:22:01 +0000
committerfuankg <fuankg@13f79535-47bb-0310-9956-ffa450edef68>2013-05-11 18:22:01 +0000
commit66d444cd19094bfa0cfced38e08db0aa6e32d08a (patch)
tree5c85a066db5a064e98e3bcabb95bf6152690dcda
parent5fbd15b3a15baee7f7cc519ebcc81531763e7eb6 (diff)
downloadlibapr-66d444cd19094bfa0cfced38e08db0aa6e32d08a.tar.gz
Backport testcase for PR 53175 from trunk.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/1.4.x@1481387 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--test/testtime.c62
1 files changed, 36 insertions, 26 deletions
diff --git a/test/testtime.c b/test/testtime.c
index 654c1f95c..fadef97c4 100644
--- a/test/testtime.c
+++ b/test/testtime.c
@@ -31,6 +31,8 @@
* Which happens to be when I wrote the new tests.
*/
static apr_time_t now = APR_INT64_C(1032030336186711);
+/* 2012-08-11 16:00:55.151600 -14400 [224 Sat] DST */
+static apr_time_t leap_year_now = APR_INT64_C(1344715255151600);
static char* print_time (apr_pool_t *pool, const apr_time_exp_t *xt)
{
@@ -59,12 +61,12 @@ static void test_now(abts_case *tc, void *data)
current = apr_time_now();
time(&os_now);
- timediff = os_now - (current / APR_USEC_PER_SEC);
+ timediff = os_now - (current / APR_USEC_PER_SEC);
/* Even though these are called so close together, there is the chance
* that the time will be slightly off, so accept anything between -1 and
* 1 second.
*/
- ABTS_ASSERT(tc, "apr_time and OS time do not agree",
+ ABTS_ASSERT(tc, "apr_time and OS time do not agree",
(timediff > -2) && (timediff < 2));
}
@@ -78,36 +80,44 @@ static void test_gmtstr(abts_case *tc, void *data)
ABTS_NOT_IMPL(tc, "apr_time_exp_gmt");
}
ABTS_TRUE(tc, rv == APR_SUCCESS);
- ABTS_STR_EQUAL(tc, "2002-09-14 19:05:36.186711 +0000 [257 Sat]",
+ ABTS_STR_EQUAL(tc, "2002-09-14 19:05:36.186711 +0000 [257 Sat]",
print_time(p, &xt));
}
static void test_exp_lt(abts_case *tc, void *data)
{
- apr_status_t rv;
- apr_time_exp_t xt;
- time_t posix_secs = (time_t)apr_time_sec(now);
- struct tm *posix_exp = localtime(&posix_secs);
+ apr_time_t test_times[] = {0, 0, 0};
+ int i;
- rv = apr_time_exp_lt(&xt, now);
- if (rv == APR_ENOTIMPL) {
- ABTS_NOT_IMPL(tc, "apr_time_exp_lt");
- }
- ABTS_TRUE(tc, rv == APR_SUCCESS);
+ test_times[0] = now;
+ test_times[1] = leap_year_now;
+
+ for (i = 0; test_times[i] != 0; i++) {
+ apr_status_t rv;
+ apr_time_exp_t xt;
+ time_t posix_secs = (time_t)apr_time_sec(test_times[i]);
+ struct tm *posix_exp = localtime(&posix_secs);
+
+ rv = apr_time_exp_lt(&xt, test_times[i]);
+ if (rv == APR_ENOTIMPL) {
+ ABTS_NOT_IMPL(tc, "apr_time_exp_lt");
+ }
+ ABTS_TRUE(tc, rv == APR_SUCCESS);
#define CHK_FIELD(f) \
- ABTS_ASSERT(tc, "Mismatch in " #f, posix_exp->f == xt.f)
-
- CHK_FIELD(tm_sec);
- CHK_FIELD(tm_min);
- CHK_FIELD(tm_hour);
- CHK_FIELD(tm_mday);
- CHK_FIELD(tm_mon);
- CHK_FIELD(tm_year);
- CHK_FIELD(tm_wday);
- CHK_FIELD(tm_yday);
- CHK_FIELD(tm_isdst);
+ ABTS_ASSERT(tc, "Mismatch in " #f, posix_exp->f == xt.f)
+
+ CHK_FIELD(tm_sec);
+ CHK_FIELD(tm_min);
+ CHK_FIELD(tm_hour);
+ CHK_FIELD(tm_mday);
+ CHK_FIELD(tm_mon);
+ CHK_FIELD(tm_year);
+ CHK_FIELD(tm_wday);
+ CHK_FIELD(tm_yday);
+ CHK_FIELD(tm_isdst);
#undef CHK_FIELD
+ }
}
static void test_exp_get_gmt(abts_case *tc, void *data)
@@ -238,9 +248,9 @@ static void test_exp_tz(abts_case *tc, void *data)
ABTS_NOT_IMPL(tc, "apr_time_exp_tz");
}
ABTS_TRUE(tc, rv == APR_SUCCESS);
- ABTS_TRUE(tc, (xt.tm_usec == 186711) &&
+ ABTS_TRUE(tc, (xt.tm_usec == 186711) &&
(xt.tm_sec == 36) &&
- (xt.tm_min == 5) &&
+ (xt.tm_min == 5) &&
(xt.tm_hour == 14) &&
(xt.tm_mday == 14) &&
(xt.tm_mon == 8) &&
@@ -278,7 +288,7 @@ static void test_2038(abts_case *tc, void *data)
xt.tm_hour = 3;
xt.tm_min = 14;
xt.tm_sec = 7;
-
+
APR_ASSERT_SUCCESS(tc, "explode January 19th, 2038",
apr_time_exp_get(&t, &xt));
}