dreid 01/04/12 09:53:11
Modified: . CHANGES
test testtime.c
Log:
I actually remembered to add an entry to the CHANGES file and here is a
modified time test that exercises more of the time functions and some simple
timezone tests.
Revision Changes Path
1.93 +3 -0 apr/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apr/CHANGES,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -r1.92 -r1.93
--- CHANGES 2001/04/12 07:05:45 1.92
+++ CHANGES 2001/04/12 16:53:11 1.93
@@ -1,5 +1,8 @@
Changes with APR b1
+ *) Amend the time code to better deal with time zones.
+ [David Reid]
+
*) Carefully select an appropriate native type for apr_int64_t and
define its format as APR_INT64_T_FMT and literal using APR_INT64_C().
[Justin Erenkrantz, William Rowe]
1.18 +41 -33 apr/test/testtime.c
Index: testtime.c
===================================================================
RCS file: /home/cvs/apr/test/testtime.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- testtime.c 2001/04/05 00:58:25 1.17
+++ testtime.c 2001/04/12 16:53:11 1.18
@@ -67,12 +67,12 @@
int main(void)
{
apr_time_t now;
- apr_exploded_time_t xt;
+ apr_exploded_time_t xt, xt2;
apr_time_t imp;
apr_pool_t *p;
char *str, *str2;
apr_size_t sz;
- apr_interval_time_t hr_off = 5 * 3600; /* 5 hours in seconds */
+ apr_interval_time_t hr_off = -5 * 3600; /* 5 hours in seconds */
fprintf(stdout, "Testing Time functions.\n");
@@ -81,42 +81,47 @@
exit (-1);
}
- fprintf(stdout, "\tapr_time_now..............................");
+ printf("\tapr_time_now....................................");
now = apr_time_now();
- fprintf(stdout, "OK\n");
+ printf("OK\n");
- fprintf(stdout, "\tapr_explode_localtime.....................");
- if (apr_explode_localtime(&xt, now) != APR_SUCCESS) {
- fprintf(stderr, "Couldn't explode the time\n");
+ printf("\tapr_explode_gmt.................................");
+ if (apr_explode_gmt(&xt, now) != APR_SUCCESS) {
+ printf("Couldn't explode the time\n");
exit(-1);
}
- fprintf(stdout, "OK\n");
+ printf("OK\n");
- fprintf(stdout, "\tapr_explode_gmt...........................");
- if (apr_explode_gmt(&xt, now) != APR_SUCCESS) {
- fprintf(stderr, "Couldn't explode the time\n");
+ printf("\tapr_explode_localtime...........................");
+ if (apr_explode_localtime(&xt2, now) != APR_SUCCESS) {
+ printf("Couldn't explode the time\n");
exit(-1);
}
- fprintf(stdout, "OK\n");
+ printf("OK\n");
- fprintf(stdout, "\tapr_implode_time..........................");
+ printf("\tapr_implode_time................................");
if (apr_implode_time(&imp, &xt) != APR_SUCCESS) {
- fprintf(stderr, "Couldn't implode the time\n");
+ printf("Couldn't implode the time\n");
exit(-1);
}
- if (imp != now) {
- fprintf(stderr, "implode/explode mismatch\n"
- "apr_explode of apr_now() %lld\n"
- "apr_implode() returned %15I64d\n"
- "error delta was %15I64d\n",
+ printf("OK\n");
+
+ printf("\tchecking the explode/implode (GMT)..............");
+ if (imp != now) {
+ printf("mismatch\n"
+ "\tapr_now() %lld\n"
+ "\tapr_implode() returned %lld\n"
+ "\terror delta was %lld\n",
now, imp, imp-now);
exit(-1);
}
- fprintf(stdout, "OK\n");
+ printf("OK\n");
+
str = apr_pcalloc(p, sizeof(char) * STR_SIZE);
str2 = apr_pcalloc(p, sizeof(char) * STR_SIZE);
+ imp = 0;
- printf("\tapr_rfc822_date.(GMT)...........");
+ printf("\tapr_rfc822_date.................");
if (apr_rfc822_date(str, now) != APR_SUCCESS){
printf("Failed!\n");
exit (-1);
@@ -142,35 +147,38 @@
}
printf("%s\n", str);
- printf("\tCurrent time (GMT).......................");
- if (apr_strftime(str, &sz, STR_SIZE, "%T %Z", &xt) != APR_SUCCESS){
+ printf("\tCurrent time (GMT)..............................");
+ if (apr_strftime(str, &sz, STR_SIZE, "%T ", &xt) != APR_SUCCESS){
printf("Failed!\n");
exit (-1);
}
printf ("%s\n", str);
+
+ printf("\tTrying to explode time with 5 hour offset.......");
+ if (apr_explode_time(&xt2, now, hr_off) != APR_SUCCESS){
+ printf("Failed.\n");
+ exit(-1);
+ }
+ printf("OK\n");
- xt.tm_gmtoff = hr_off; /* 5 hour offset */
- printf("\tOffset Time Zone -5 hours.................");
- if (apr_strftime(str2, &sz, STR_SIZE, "%T %Z", &xt) != APR_SUCCESS){
+ printf("\tOffset Time Zone -5 hours.......................");
+ if (apr_strftime(str2, &sz, STR_SIZE, "%T (%z)", &xt2) != APR_SUCCESS){
printf("Failed!\n");
exit(-1);
}
printf("%s\n", str2);
- /* We just check and report, but this isn't a hanging offense
- as it currently doesn't work
- */
- printf("\tComparing the created times...............");
+ printf("\tComparing the created times.....................");
if (! strcmp(str,str2)){
printf("Failed\n");
} else {
printf("OK\n");
}
- printf("\tChecking imploded time after offset.......");
- apr_implode_time(&imp, &xt);
+ printf("\tChecking imploded time after offset.............");
+ apr_implode_time(&imp, &xt2);
hr_off *= APR_USEC_PER_SEC; /* microseconds */
- if (imp != now - hr_off){
+ if (imp != now + hr_off){
printf("Failed! :(\n");
printf("Difference is %lld (should be %lld)\n", imp - now, hr_off);
exit(-1);