You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by fu...@apache.org on 2013/05/11 20:22:01 UTC
svn commit: r1481387 - in /apr/apr/branches: 0.9.x/test/testtime.c
1.4.x/test/testtime.c 1.5.x/test/testtime.c
Author: fuankg
Date: Sat May 11 18:22:01 2013
New Revision: 1481387
URL: http://svn.apache.org/r1481387
Log:
Backport testcase for PR 53175 from trunk.
Modified:
apr/apr/branches/0.9.x/test/testtime.c
apr/apr/branches/1.4.x/test/testtime.c
apr/apr/branches/1.5.x/test/testtime.c
Modified: apr/apr/branches/0.9.x/test/testtime.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/0.9.x/test/testtime.c?rev=1481387&r1=1481386&r2=1481387&view=diff
==============================================================================
--- apr/apr/branches/0.9.x/test/testtime.c (original)
+++ apr/apr/branches/0.9.x/test/testtime.c Sat May 11 18:22:01 2013
@@ -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)
{
@@ -84,30 +86,38 @@ static void test_gmtstr(CuTest *tc)
static void test_exp_lt(CuTest *tc)
{
- 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) {
- CuNotImpl(tc, "apr_time_exp_lt");
- }
- CuAssertTrue(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) {
+ CuNotImpl(tc, "apr_time_exp_lt");
+ }
+ CuAssertTrue(tc, rv == APR_SUCCESS);
#define CHK_FIELD(f) \
- CuAssert(tc, "Mismatch in " #f, posix_exp->f == xt.f)
+ CuAssert(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);
+ 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(CuTest *tc)
Modified: apr/apr/branches/1.4.x/test/testtime.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/test/testtime.c?rev=1481387&r1=1481386&r2=1481387&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/test/testtime.c (original)
+++ apr/apr/branches/1.4.x/test/testtime.c Sat May 11 18:22:01 2013
@@ -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
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, v
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)
+ 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);
+ 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, v
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, voi
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));
}
Modified: apr/apr/branches/1.5.x/test/testtime.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/test/testtime.c?rev=1481387&r1=1481386&r2=1481387&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/test/testtime.c (original)
+++ apr/apr/branches/1.5.x/test/testtime.c Sat May 11 18:22:01 2013
@@ -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
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, v
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)
+ 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);
+ 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, v
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, voi
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));
}