nsprpub/pr/tests/y2k.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/tests/y2k.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,786 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * file: y2k.c
    1.11 + * description: Test for y2k compliance for NSPR.
    1.12 + *
    1.13 + * Sep 1999. lth. Added "Sun" specified dates to the test data.
    1.14 + */
    1.15 +/***********************************************************************
    1.16 +** Includes
    1.17 +***********************************************************************/
    1.18 +/* Used to get the command line option */
    1.19 +#include "plgetopt.h"
    1.20 +
    1.21 +#include "prinit.h"
    1.22 +#include "prtime.h"
    1.23 +#include "prprf.h"
    1.24 +#include "prlog.h"
    1.25 +
    1.26 +#include <stdio.h>
    1.27 +#include <stdlib.h>
    1.28 +#include <string.h>
    1.29 +
    1.30 +#define PRINT_DETAILS
    1.31 +
    1.32 +int failed_already=0;
    1.33 +PRBool debug_mode = PR_FALSE;
    1.34 +
    1.35 +static char *dayOfWeek[] =
    1.36 +	{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
    1.37 +static char *month[] =
    1.38 +	{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
    1.39 +	  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???" };
    1.40 +
    1.41 +PRLogModuleInfo *lm;
    1.42 +
    1.43 +static void PrintExplodedTime(const PRExplodedTime *et) {
    1.44 +    PRInt32 totalOffset;
    1.45 +    PRInt32 hourOffset, minOffset;
    1.46 +    const char *sign;
    1.47 +
    1.48 +    /* Print day of the week, month, day, hour, minute, and second */
    1.49 +    printf("%s %s %2ld %02ld:%02ld:%02ld ",
    1.50 +	    dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
    1.51 +	    et->tm_hour, et->tm_min, et->tm_sec);
    1.52 +
    1.53 +    /* Print year */
    1.54 +    printf("%hd ", et->tm_year);
    1.55 +
    1.56 +    /* Print time zone */
    1.57 +    totalOffset = et->tm_params.tp_gmt_offset + et->tm_params.tp_dst_offset;
    1.58 +    if (totalOffset == 0) {
    1.59 +	printf("UTC ");
    1.60 +    } else {
    1.61 +        sign = "+";
    1.62 +        if (totalOffset < 0) {
    1.63 +	    totalOffset = -totalOffset;
    1.64 +	    sign = "-";
    1.65 +        }
    1.66 +        hourOffset = totalOffset / 3600;
    1.67 +        minOffset = (totalOffset % 3600) / 60;
    1.68 +        printf("%s%02ld%02ld ", sign, hourOffset, minOffset);
    1.69 +    }
    1.70 +#ifdef PRINT_DETAILS
    1.71 +	printf("{%d, %d, %d, %d, %d, %d, %d, %d, %d, { %d, %d}}\n",et->tm_usec,
    1.72 +											et->tm_sec,
    1.73 +											et->tm_min,
    1.74 +											et->tm_hour,
    1.75 +											et->tm_mday,
    1.76 +											et->tm_month,
    1.77 +											et->tm_year,
    1.78 +											et->tm_wday,
    1.79 +											et->tm_yday,
    1.80 +											et->tm_params.tp_gmt_offset,
    1.81 +											et->tm_params.tp_dst_offset);
    1.82 +#endif
    1.83 +}
    1.84 +
    1.85 +static int ExplodedTimeIsEqual(const PRExplodedTime *et1,
    1.86 +	const PRExplodedTime *et2)
    1.87 +{
    1.88 +    if (et1->tm_usec == et2->tm_usec &&
    1.89 +	    et1->tm_sec == et2->tm_sec &&
    1.90 +	    et1->tm_min == et2->tm_min &&
    1.91 +	    et1->tm_hour == et2->tm_hour &&
    1.92 +	    et1->tm_mday == et2->tm_mday &&
    1.93 +	    et1->tm_month == et2->tm_month &&
    1.94 +	    et1->tm_year == et2->tm_year &&
    1.95 +	    et1->tm_wday == et2->tm_wday &&
    1.96 +	    et1->tm_yday == et2->tm_yday &&
    1.97 +	    et1->tm_params.tp_gmt_offset == et2->tm_params.tp_gmt_offset &&
    1.98 +	    et1->tm_params.tp_dst_offset == et2->tm_params.tp_dst_offset) {
    1.99 +        return 1;
   1.100 +    } else {
   1.101 +	return 0;
   1.102 +    }
   1.103 +}
   1.104 +
   1.105 +/*
   1.106 + * TEST 1: TestExplodeImplodeTime
   1.107 + * Description:
   1.108 + * For each given timestamp T (a PRTime value), call PR_ExplodeTime
   1.109 + * with GMT, US Pacific, and local time parameters.  Compare the
   1.110 + * resulting calendar (exploded) time values with the expected
   1.111 + * values.
   1.112 + *
   1.113 + * Note: the expected local time values depend on the local time
   1.114 + * zone.  The local time values stored in this test are for the US
   1.115 + * Pacific Time Zone.  If you are running this test in a different
   1.116 + * time zone, you need to modify the values in the localt array.
   1.117 + * An example is provided below.
   1.118 + *
   1.119 + * Call PR_ImplodeTime for each of the exploded values and compare
   1.120 + * the resulting PRTime values with the original input.
   1.121 + * 
   1.122 + * This test is run for the values of time T corresponding to the
   1.123 + * following dates:
   1.124 + * - 12/31/99 - before 2000 
   1.125 + * - 01/01/00 - after 2000 
   1.126 + * - Leap year - Feb 29, 2000 
   1.127 + * - March 1st, 2001 (after 1 year) 
   1.128 + * - March 1st, 2005 (after second leap year) 
   1.129 + * - 09/09/99 (used by some programs as an end of file marker)
   1.130 + *
   1.131 + * Call PR_Now, convert to calendar time using PR_ExplodeTime and
   1.132 + * manually check the result for correctness. The time should match
   1.133 + * the system clock.
   1.134 + *
   1.135 + * Tested functions: PR_Now, PR_ExplodeTime, PR_ImplodeTime,
   1.136 + * PR_LocalTimeParameters, PR_GMTParameters. 
   1.137 + */
   1.138 +
   1.139 +static PRTime prt[] = {
   1.140 +    LL_INIT(220405, 2133125120),  /* 946634400000000 */
   1.141 +    LL_INIT(220425, 2633779200),  /* 946720800000000 */
   1.142 +    LL_INIT(221612, 2107598848),  /* 951818400000000 */
   1.143 +    LL_INIT(228975, 663398400),  /* 983440800000000 */
   1.144 +    LL_INIT(258365, 1974568960),  /* 1109671200000000 */
   1.145 +    LL_INIT(218132, 1393788928),  /* 936871200000000 */
   1.146 +    /* Sun's dates follow */
   1.147 +    LL_INIT( 213062, 4077979648 ), /* Dec 31 1998 10:00:00 */
   1.148 +    LL_INIT( 218152, 1894443008 ), /* Sep 10 1999 10:00:00 */
   1.149 +    LL_INIT( 221592, 1606944768 ), /* Feb 28 2000 10:00:00 */
   1.150 +    LL_INIT( 227768, 688924672 ), /* Dec 31 2000 10:00:00 */
   1.151 +    LL_INIT( 227788, 1189578752 ), /* Jan 1  2001 10:00:00 */
   1.152 +};
   1.153 +
   1.154 +static PRExplodedTime gmt[] = {
   1.155 +    { 0, 0, 0, 10, 31, 11, 1999, 5, 364, {0, 0}}, /* 1999/12/31 10:00:00 GMT */
   1.156 +    { 0, 0, 0, 10, 1, 0, 2000, 6, 0, {0, 0}}, /* 2000/01/01 10:00:00 GMT */
   1.157 +    { 0, 0, 0, 10, 29, 1, 2000, 2, 59, {0, 0}}, /* 2000/02/29 10:00:00 GMT */
   1.158 +    { 0, 0, 0, 10, 1, 2, 2001, 4, 59, {0, 0}}, /* 2001/3/1 10:00:00 GMT */
   1.159 +    { 0, 0, 0, 10, 1, 2, 2005, 2, 59, {0, 0}}, /* 2005/3/1 10:00:00 GMT */
   1.160 +    { 0, 0, 0, 10, 9, 8, 1999, 4, 251, {0, 0}},  /* 1999/9/9 10:00:00 GMT */
   1.161 +    /* Sun's dates follow */
   1.162 +    { 0, 0, 0, 10, 31, 11, 1998, 4, 364, {0, 0}},  /* 12/31/1998 10:00:00 GMT */
   1.163 +    { 0, 0, 0, 10, 10, 8, 1999, 5, 252, {0, 0}},  /* 9/10/1999 10:00:00 GMT */
   1.164 +    { 0, 0, 0, 10, 28, 1, 2000, 1, 58, {0, 0}},  /* 2/28/2000 10:00:00 GMT */
   1.165 +    { 0, 0, 0, 10, 31, 11, 2000, 0, 365, {0, 0}},  /* 12/31/2000 10:00:00 GMT */
   1.166 +    { 0, 0, 0, 10, 1, 0, 2001, 1, 0, {0, 0}}  /* 1/1/2001 10:00:00 GMT */
   1.167 +};
   1.168 +
   1.169 +static PRExplodedTime uspt[] = {
   1.170 +{ 0, 0, 0, 2, 31, 11, 1999, 5, 364, {-28800, 0}}, /* 1999/12/31 2:00:00 PST */
   1.171 +{ 0, 0, 0, 2, 1, 0, 2000, 6, 0, {-28800, 0}}, /* 2000/01/01 2:00:00 PST */
   1.172 +{ 0, 0, 0, 2, 29, 1, 2000, 2, 59, {-28800, 0}}, /* 2000/02/29 2:00:00 PST */
   1.173 +{ 0, 0, 0, 2, 1, 2, 2001, 4, 59, {-28800, 0}}, /* 2001/3/1 2:00:00 PST */
   1.174 +{ 0, 0, 0, 2, 1, 2, 2005, 2, 59, {-28800, 0}}, /* 2005/3/1 2:00:00 PST */
   1.175 +{ 0, 0, 0, 3, 9, 8, 1999, 4, 251, {-28800, 3600}},  /* 1999/9/9 3:00:00 PDT */
   1.176 +    /* Sun's dates follow */
   1.177 +    { 0, 0, 0, 2, 31, 11, 1998, 4, 364, {-28800, 0}},  /* 12/31/1998 00:00:00 GMT */
   1.178 +    { 0, 0, 0, 3, 10, 8, 1999, 5, 252, {-28800, 3600}},  /* 9/10/1999 00:00:00 GMT */
   1.179 +    { 0, 0, 0, 2, 28, 1, 2000, 1, 58, {-28800, 0}},  /* 2/28/2000 00:00:00 GMT */
   1.180 +    { 0, 0, 0, 2, 31, 11, 2000, 0, 365, {-28800, 0}},  /* 12/31/2000 00:00:00 GMT */
   1.181 +    { 0, 0, 0, 2, 1, 0, 2001, 1, 0, {-28800, 0}}  /* 1/1/2001 00:00:00 GMT */
   1.182 +};
   1.183 +
   1.184 +/*
   1.185 + * This test assumes that we are in US Pacific Time Zone.
   1.186 + * If you are running this test in a different time zone,
   1.187 + * you need to modify the localt array and fill in the
   1.188 + * expected results.  The localt array for US Eastern Time
   1.189 + * Zone is provided as an example.
   1.190 + */
   1.191 +static PRExplodedTime localt[] = {
   1.192 +{ 0, 0, 0, 2, 31, 11, 1999, 5, 364, {-28800, 0}}, /* 1999/12/31 2:00:00 PST */
   1.193 +{ 0, 0, 0, 2, 1, 0, 2000, 6, 0, {-28800, 0}}, /* 2000/01/01 2:00:00 PST */
   1.194 +{ 0, 0, 0, 2, 29, 1, 2000, 2, 59, {-28800, 0}}, /* 2000/02/29 2:00:00 PST */
   1.195 +{ 0, 0, 0, 2, 1, 2, 2001, 4, 59, {-28800, 0}}, /* 2001/3/1 2:00:00 PST */
   1.196 +{ 0, 0, 0, 2, 1, 2, 2005, 2, 59, {-28800, 0}}, /* 2005/3/1 2:00:00 PST */
   1.197 +{ 0, 0, 0, 3, 9, 8, 1999, 4, 251, {-28800, 3600}},  /* 1999/9/9 3:00:00 PDT */
   1.198 +    /* Sun's dates follow */
   1.199 +    { 0, 0, 0, 2, 31, 11, 1998, 4, 364, {-28800, 0}},  /* 12/31/1998 00:00:00 GMT */
   1.200 +    { 0, 0, 0, 3, 10, 8, 1999, 5, 252, {-28800, 3600}},  /* 9/10/1999 00:00:00 GMT */
   1.201 +    { 0, 0, 0, 2, 28, 1, 2000, 1, 58, {-28800, 0}},  /* 2/28/2000 00:00:00 GMT */
   1.202 +    { 0, 0, 0, 2, 31, 11, 2000, 0, 365, {-28800, 0}},  /* 12/31/2000 00:00:00 GMT */
   1.203 +    { 0, 0, 0, 2, 1, 0, 2001, 1, 0, {-28800, 0}}  /* 1/1/2001 00:00:00 GMT */
   1.204 +};
   1.205 +
   1.206 +#ifdef US_EASTERN_TIME
   1.207 +static PRExplodedTime localt[] = {
   1.208 +{ 0, 0, 0, 5, 31, 11, 1999, 5, 364, {-18000, 0}}, /* 1999/12/31 2:00:00 EST */
   1.209 +{ 0, 0, 0, 5, 1, 0, 2000, 6, 0, {-18000, 0}}, /* 2000/01/01 2:00:00 EST */
   1.210 +{ 0, 0, 0, 5, 29, 1, 2000, 2, 59, {-18000, 0}}, /* 2000/02/29 2:00:00 EST */
   1.211 +{ 0, 0, 0, 5, 1, 2, 2001, 4, 59, {-18000, 0}}, /* 2001/3/1 2:00:00 EST */
   1.212 +{ 0, 0, 0, 5, 1, 2, 2005, 2, 59, {-18000, 0}}, /* 2005/3/1 2:00:00 EST */
   1.213 +{ 0, 0, 0, 6, 9, 8, 1999, 4, 251, {-18000, 3600}},  /* 1999/9/9 3:00:00 EDT */
   1.214 +    /* Sun's dates follow */
   1.215 +    { 0, 0, 0, 5, 31, 11, 1998, 4, 364, {-18000 0}},  /* 12/31/1998 00:00:00 GMT */
   1.216 +    { 0, 0, 0, 6, 10, 8, 1999, 5, 252, {-18000 3600}},  /* 9/10/1999 00:00:00 GMT */
   1.217 +    { 0, 0, 0, 5, 28, 1, 2000, 1, 58, {-18000 0}},  /* 2/28/2000 00:00:00 GMT */
   1.218 +    { 0, 0, 0, 5, 31, 11, 2000, 0, 365, {-18000 0}},  /* 12/31/2000 00:00:00 GMT */
   1.219 +    { 0, 0, 0, 5, 1, 0, 2001, 1, 0, {-18000 0}}  /* 1/1/2001 00:00:00 GMT */
   1.220 +};
   1.221 +#endif
   1.222 +
   1.223 +static PRStatus TestExplodeImplodeTime(void)
   1.224 +{
   1.225 +    PRTime prt_tmp;
   1.226 +    PRTime now;
   1.227 +    int idx;
   1.228 +    int array_size = sizeof(prt) / sizeof(PRTime);
   1.229 +    PRExplodedTime et_tmp;
   1.230 +    char buf[1024];
   1.231 +
   1.232 +    for (idx = 0; idx < array_size; idx++) {
   1.233 +        PR_snprintf(buf, sizeof(buf), "%lld", prt[idx]);
   1.234 +        if (debug_mode) printf("Time stamp %s\n", buf); 
   1.235 +        PR_ExplodeTime(prt[idx], PR_GMTParameters, &et_tmp);
   1.236 +        if (!ExplodedTimeIsEqual(&et_tmp, &gmt[idx])) {
   1.237 +            fprintf(stderr, "GMT not equal\n");
   1.238 +            PrintExplodedTime(&et_tmp);
   1.239 +            PrintExplodedTime(&gmt[idx]);
   1.240 +            exit(1);
   1.241 +        }
   1.242 +        prt_tmp = PR_ImplodeTime(&et_tmp);
   1.243 +        if (LL_NE(prt_tmp, prt[idx])) {
   1.244 +            fprintf(stderr, "PRTime not equal\n");
   1.245 +            exit(1);
   1.246 +        }
   1.247 +        if (debug_mode) {
   1.248 +            printf("GMT: ");
   1.249 +            PrintExplodedTime(&et_tmp);
   1.250 +            printf("\n");
   1.251 +        }
   1.252 +
   1.253 +        PR_ExplodeTime(prt[idx], PR_USPacificTimeParameters, &et_tmp);
   1.254 +        if (!ExplodedTimeIsEqual(&et_tmp, &uspt[idx])) {
   1.255 +            fprintf(stderr, "US Pacific Time not equal\n");
   1.256 +            PrintExplodedTime(&et_tmp);
   1.257 +            PrintExplodedTime(&uspt[idx]);
   1.258 +            exit(1);
   1.259 +        }
   1.260 +        prt_tmp = PR_ImplodeTime(&et_tmp);
   1.261 +        if (LL_NE(prt_tmp, prt[idx])) {
   1.262 +            fprintf(stderr, "PRTime not equal\n");
   1.263 +            exit(1);
   1.264 +        }
   1.265 +        if (debug_mode) {
   1.266 +            printf("US Pacific Time: ");
   1.267 +            PrintExplodedTime(&et_tmp);
   1.268 +            printf("\n");
   1.269 +        }
   1.270 +
   1.271 +        PR_ExplodeTime(prt[idx], PR_LocalTimeParameters, &et_tmp);
   1.272 +        if (!ExplodedTimeIsEqual(&et_tmp, &localt[idx])) {
   1.273 +            fprintf(stderr, "not equal\n");
   1.274 +            PrintExplodedTime(&et_tmp);
   1.275 +            PrintExplodedTime(&localt[idx]);
   1.276 +            exit(1);
   1.277 +        }
   1.278 +        prt_tmp = PR_ImplodeTime(&et_tmp);
   1.279 +        if (LL_NE(prt_tmp, prt[idx])) {
   1.280 +            fprintf(stderr, "not equal\n");
   1.281 +            exit(1);
   1.282 +        }
   1.283 +        if (debug_mode) {
   1.284 +            printf("Local time:");
   1.285 +            PrintExplodedTime(&et_tmp);
   1.286 +            printf("\n\n");
   1.287 +        }
   1.288 +    }
   1.289 +
   1.290 +    now = PR_Now();
   1.291 +    PR_ExplodeTime(now, PR_GMTParameters, &et_tmp);
   1.292 +    printf("Current GMT is ");
   1.293 +    PrintExplodedTime(&et_tmp);
   1.294 +    printf("\n");
   1.295 +    prt_tmp = PR_ImplodeTime(&et_tmp);
   1.296 +    if (LL_NE(prt_tmp, now)) {
   1.297 +        fprintf(stderr, "not equal\n");
   1.298 +        exit(1);
   1.299 +    }
   1.300 +    PR_ExplodeTime(now, PR_USPacificTimeParameters, &et_tmp);
   1.301 +    printf("Current US Pacific Time is ");
   1.302 +    PrintExplodedTime(&et_tmp);
   1.303 +    printf("\n");
   1.304 +    prt_tmp = PR_ImplodeTime(&et_tmp);
   1.305 +    if (LL_NE(prt_tmp, now)) {
   1.306 +        fprintf(stderr, "not equal\n");
   1.307 +        exit(1);
   1.308 +    }
   1.309 +    PR_ExplodeTime(now, PR_LocalTimeParameters, &et_tmp);
   1.310 +    printf("Current local time is ");
   1.311 +    PrintExplodedTime(&et_tmp);
   1.312 +    printf("\n");
   1.313 +    prt_tmp = PR_ImplodeTime(&et_tmp);
   1.314 +    if (LL_NE(prt_tmp, now)) {
   1.315 +        fprintf(stderr, "not equal\n");
   1.316 +        exit(1);
   1.317 +    }
   1.318 +    printf("Please verify the results\n\n");
   1.319 +
   1.320 +    if (debug_mode) printf("Test 1 passed\n");
   1.321 +    return PR_SUCCESS;
   1.322 +}
   1.323 +/* End of Test 1: TestExplodeImplodeTime */
   1.324 +
   1.325 +/*
   1.326 + * Test 2: Normalize Time
   1.327 + */
   1.328 +
   1.329 +/*
   1.330 + * time increment for addition to PRExplodeTime
   1.331 + */
   1.332 +typedef struct time_increment {
   1.333 +	PRInt32 ti_usec;
   1.334 +	PRInt32 ti_sec;
   1.335 +	PRInt32 ti_min;
   1.336 +	PRInt32 ti_hour;
   1.337 +} time_increment_t;
   1.338 +
   1.339 +/*
   1.340 + * Data for testing PR_Normalize
   1.341 + *		Add the increment to base_time, normalize it to GMT and US Pacific
   1.342 + *		Time zone.
   1.343 + */
   1.344 +typedef struct normalize_test_data {
   1.345 +    PRExplodedTime		base_time; 
   1.346 +    time_increment_t  	increment;
   1.347 +    PRExplodedTime		expected_gmt_time;
   1.348 +    PRExplodedTime		expected_uspt_time;
   1.349 +} normalize_test_data_t;
   1.350 +
   1.351 +
   1.352 +/*
   1.353 + * Test data -	the base time values cover dates of interest including y2k - 1,
   1.354 + *				y2k + 1, y2k leap year, y2k leap date + 1year,
   1.355 + *				y2k leap date + 4 years
   1.356 + */
   1.357 +normalize_test_data_t normalize_test_array[] = {
   1.358 +  /*usec sec min hour  mday  mo  year  wday yday {gmtoff, dstoff }*/
   1.359 +
   1.360 +	/* Fri 12/31/1999 19:32:48 PST */
   1.361 +	{{0, 48, 32, 19, 31, 11, 1999, 5, 364, { -28800, 0}},
   1.362 +    {0, 0, 30, 20},
   1.363 +	{0, 48, 2, 0, 2, 0, 2000, 0, 1, { 0, 0}},	/*Sun Jan 2 00:02:48 UTC 2000*/
   1.364 +	{0, 48, 2, 16, 1, 0, 2000, 6, 0, { -28800, 0}},/* Sat Jan 1 16:02:48
   1.365 +														PST 2000*/
   1.366 +	},
   1.367 +	/* Fri 99-12-31 23:59:02 GMT */
   1.368 +	{{0, 2, 59, 23, 31, 11, 1999, 5, 364, { 0, 0}},
   1.369 +    {0, 0, 45, 0},
   1.370 +	{0, 2, 44, 0, 1, 0, 2000, 6, 0, { 0, 0}},/* Sat Jan 1 00:44:02 UTC 2000*/
   1.371 +	{0, 2, 44, 16, 31, 11, 1999, 5, 364, { -28800, 0}}/*Fri Dec 31 16:44:02
   1.372 +														PST 1999*/
   1.373 +	},
   1.374 +	/* 99-12-25 12:00:00 GMT */
   1.375 +	{{0, 0, 0, 12, 25, 11, 1999, 6, 358, { 0, 0}},
   1.376 +    {0, 0, 0, 364 * 24},
   1.377 +	{0, 0, 0, 12, 23, 11, 2000, 6, 357, { 0, 0}},/*Sat Dec 23 12:00:00
   1.378 +													2000 UTC*/
   1.379 +	{0, 0, 0, 4, 23, 11, 2000, 6, 357, { -28800, 0}}/*Sat Dec 23 04:00:00
   1.380 +														2000 -0800*/
   1.381 +	},
   1.382 +	/* 00-01-1 00:00:00 PST */
   1.383 +    {{0, 0, 0, 0, 1, 0, 2000, 6, 0, { -28800, 0}},
   1.384 +    {0, 0, 0, 48},
   1.385 +    {0, 0, 0, 8, 3, 0, 2000, 1, 2, { 0, 0}},/*Mon Jan  3 08:00:00 2000 UTC*/
   1.386 +    {0, 0, 0, 0, 3, 0, 2000, 1, 2, { -28800, 0}}/*Mon Jan  3 00:00:00 2000
   1.387 +																-0800*/
   1.388 +	},
   1.389 +	/* 00-01-10 12:00:00 PST */
   1.390 +    {{0, 0, 0, 12, 10, 0, 2000, 1, 9, { -28800, 0}},
   1.391 +    {0, 0, 0, 364 * 5 * 24},
   1.392 +    {0, 0, 0, 20, 3, 0, 2005, 1, 2, { 0, 0}},/*Mon Jan  3 20:00:00 2005 UTC */
   1.393 +    {0, 0, 0, 12, 3, 0, 2005, 1, 2, { -28800, 0}}/*Mon Jan  3 12:00:00
   1.394 +														2005 -0800*/
   1.395 +	},
   1.396 +	/* 00-02-28 15:39 GMT */
   1.397 +	{{0, 0, 39, 15, 28, 1, 2000, 1, 58, { 0, 0}},
   1.398 +    {0,  0, 0, 24},
   1.399 +	{0, 0, 39, 15, 29, 1, 2000, 2, 59, { 0, 0}}, /*Tue Feb 29 15:39:00 2000
   1.400 +														UTC*/
   1.401 +	{0, 0, 39, 7, 29, 1, 2000, 2, 59, { -28800, 0}}/*Tue Feb 29 07:39:00
   1.402 +														2000 -0800*/
   1.403 +	},
   1.404 +	/* 01-03-01 12:00 PST */
   1.405 +    {{0, 0, 0, 12, 3, 0, 2001, 3, 2, { -28800, 0}},/*Wed Jan 3 12:00:00
   1.406 +													-0800 2001*/
   1.407 +    {0, 30, 30,45},
   1.408 +    {0, 30, 30, 17, 5, 0, 2001, 5, 4, { 0, 0}}, /*Fri Jan  5 17:30:30 2001
   1.409 +													UTC*/
   1.410 +    {0, 30, 30, 9, 5, 0, 2001, 5, 4, { -28800, 0}} /*Fri Jan  5 09:30:30
   1.411 +														2001 -0800*/
   1.412 +	},
   1.413 +	/* 2004-04-26 12:00 GMT */
   1.414 +	{{0, 0, 0, 20, 3, 0, 2001, 3, 2, { 0, 0}},
   1.415 +    {0, 0, 30,0},
   1.416 +	{0, 0, 30, 20, 3, 0, 2001, 3, 2, { 0, 0}},/*Wed Jan  3 20:30:00 2001 UTC*/ 
   1.417 +    {0, 0, 30, 12, 3, 0, 2001, 3, 2, { -28800, 0}}/*Wed Jan  3 12:30:00
   1.418 +														2001 -0800*/
   1.419 +	},
   1.420 +	/* 99-09-09 00:00 GMT */
   1.421 +	{{0, 0, 0, 0, 9, 8, 1999, 4, 251, { 0, 0}},
   1.422 +    {0, 0, 0, 12},
   1.423 +    {0, 0, 0, 12, 9, 8, 1999, 4, 251, { 0, 0}},/*Thu Sep  9 12:00:00 1999 UTC*/
   1.424 +    {0, 0, 0, 5, 9, 8, 1999, 4, 251, { -28800, 3600}}/*Thu Sep  9 05:00:00
   1.425 +														1999 -0700*/
   1.426 +	}
   1.427 +};
   1.428 +
   1.429 +void add_time_increment(PRExplodedTime *et1, time_increment_t *it)
   1.430 +{
   1.431 +	et1->tm_usec += it->ti_usec;
   1.432 +	et1->tm_sec	+= it->ti_sec;
   1.433 +	et1->tm_min += it->ti_min;
   1.434 +	et1->tm_hour += it->ti_hour;
   1.435 +}
   1.436 +
   1.437 +/*
   1.438 +** TestNormalizeTime() -- Test PR_NormalizeTime()
   1.439 +**		For each data item, add the time increment to the base_time and then
   1.440 +**		normalize it for GMT and local time zones. This test assumes that
   1.441 +**		the local time zone is the Pacific Time Zone. The normalized values
   1.442 +**		should match the expected values in the data item.
   1.443 +**
   1.444 +*/
   1.445 +PRStatus TestNormalizeTime(void)
   1.446 +{
   1.447 +int idx, count;
   1.448 +normalize_test_data_t *itemp;
   1.449 +time_increment_t *itp;
   1.450 +
   1.451 +	count = sizeof(normalize_test_array)/sizeof(normalize_test_array[0]);
   1.452 +	for (idx = 0; idx < count; idx++) {
   1.453 +		itemp = &normalize_test_array[idx];
   1.454 +		if (debug_mode) {
   1.455 +			printf("%2d. %15s",idx +1,"Base time: ");
   1.456 +			PrintExplodedTime(&itemp->base_time);
   1.457 +			printf("\n");
   1.458 +		}
   1.459 +		itp = &itemp->increment;
   1.460 +		if (debug_mode) {
   1.461 +			printf("%20s %2d hrs %2d min %3d sec\n","Add",itp->ti_hour,
   1.462 +												itp->ti_min, itp->ti_sec);
   1.463 +		}
   1.464 +		add_time_increment(&itemp->base_time, &itemp->increment);
   1.465 +		PR_NormalizeTime(&itemp->base_time, PR_LocalTimeParameters);
   1.466 +		if (debug_mode) {
   1.467 +			printf("%19s","PST time: ");
   1.468 +			PrintExplodedTime(&itemp->base_time);
   1.469 +			printf("\n");
   1.470 +		}
   1.471 +		if (!ExplodedTimeIsEqual(&itemp->base_time,
   1.472 +									&itemp->expected_uspt_time)) {
   1.473 +			printf("PR_NormalizeTime failed\n");
   1.474 +			if (debug_mode)
   1.475 +				PrintExplodedTime(&itemp->expected_uspt_time);
   1.476 +			return PR_FAILURE;
   1.477 +		}
   1.478 +		PR_NormalizeTime(&itemp->base_time, PR_GMTParameters);
   1.479 +		if (debug_mode) {
   1.480 +			printf("%19s","GMT time: ");
   1.481 +			PrintExplodedTime(&itemp->base_time);
   1.482 +			printf("\n");
   1.483 +		}
   1.484 +
   1.485 +		if (!ExplodedTimeIsEqual(&itemp->base_time,
   1.486 +									&itemp->expected_gmt_time)) {
   1.487 +			printf("PR_NormalizeTime failed\n");
   1.488 +			return PR_FAILURE;
   1.489 +		}
   1.490 +	}
   1.491 +	return PR_SUCCESS;
   1.492 +}
   1.493 +
   1.494 +
   1.495 +/*
   1.496 +** ParseTest. Structure defining a string time and a matching exploded time
   1.497 +**
   1.498 +*/
   1.499 +typedef struct ParseTest
   1.500 +{
   1.501 +    char            *sDate;     /* string to be converted using PR_ParseTimeString() */
   1.502 +    PRExplodedTime  et;         /* expected result of the conversion */
   1.503 +} ParseTest;
   1.504 +
   1.505 +static ParseTest parseArray[] = 
   1.506 +{
   1.507 +    /*                                  |<----- expected result ------------------------------------------->| */
   1.508 +    /* "string to test"                   usec     sec min hour   day  mo  year  wday julian {gmtoff, dstoff }*/
   1.509 +    { "Thursday 1 Jan 1970 00:00:00",   { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.510 +    { "1 Jan 1970 00:00:00",            { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.511 +    { "1-Jan-1970 00:00:00",            { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.512 +    { "01-Jan-1970 00:00:00",           { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.513 +    { "January 1, 1970",                { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.514 +    { "January 1, 1970 00:00",          { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.515 +    { "January 01, 1970 00:00",         { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.516 +    { "January 01 1970 00:00",          { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.517 +    { "January 01 1970 00:00:00",       { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.518 +    { "01-01-1970",                     { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.519 +    { "01/01/1970",                     { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.520 +    { "01/01/70",                       { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.521 +    { "01/01/70 00:00:00",              { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.522 +    { "70/01/01 00:00:00",              { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.523 +    { "70/1/1 00:00:",                  { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.524 +    { "00:00 Thursday, January 1, 1970",{ 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.525 +    { "1-Jan-70 00:00:00",              { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.526 +    { "70-01-01 00:00:00",              { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.527 +    { "70/01/01 00:00:00",              { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
   1.528 +
   1.529 +    /* 31-Dec-1969 */
   1.530 +    { "Wed 31 Dec 1969 00:00:00",       { 000000,  00, 00, 00,    31,  11, 1969, 3,   364,   {-28800, 0 }}},
   1.531 +    { "31 Dec 1969 00:00:00",           { 000000,  00, 00, 00,    31,  11, 1969, 3,   364,   {-28800, 0 }}},
   1.532 +    { "12/31/69    00:00:00",           { 000000,  00, 00, 00,    31,  11, 2069, 2,   364,   {-28800, 0 }}},
   1.533 +    { "12/31/1969  00:00:00",           { 000000,  00, 00, 00,    31,  11, 1969, 3,   364,   {-28800, 0 }}},
   1.534 +    { "12-31-69    00:00:00",           { 000000,  00, 00, 00,    31,  11, 2069, 2,   364,   {-28800, 0 }}},
   1.535 +    { "12-31-1969  00:00:00",           { 000000,  00, 00, 00,    31,  11, 1969, 3,   364,   {-28800, 0 }}},
   1.536 +    { "69-12-31    00:00:00",           { 000000,  00, 00, 00,    31,  11, 2069, 2,   364,   {-28800, 0 }}},
   1.537 +    { "69/12/31    00:00:00",           { 000000,  00, 00, 00,    31,  11, 2069, 2,   364,   {-28800, 0 }}},
   1.538 +
   1.539 +    /* "Sun". 31-Dec-1998 (?) */ 
   1.540 +    { "Thu 31 Dec 1998 00:00:00",        { 00000,  00, 00, 00,    31,  11, 1998, 4,   364,    {-28800, 0 }}},
   1.541 +    { "12/31/98    00:00:00",            { 00000,  00, 00, 00,    31,  11, 1998, 4,   364,    {-28800, 0 }}},
   1.542 +    { "12/31/1998  00:00:00",            { 00000,  00, 00, 00,    31,  11, 1998, 4,   364,    {-28800, 0 }}},
   1.543 +    { "12-31-98    00:00:00",            { 00000,  00, 00, 00,    31,  11, 1998, 4,   364,    {-28800, 0 }}},
   1.544 +    { "12-31-1998  00:00:00",            { 00000,  00, 00, 00,    31,  11, 1998, 4,   364,    {-28800, 0 }}},
   1.545 +    { "98-12-31    00:00:00",            { 00000,  00, 00, 00,    31,  11, 1998, 4,   364,    {-28800, 0 }}},
   1.546 +    { "98/12/31    00:00:00",            { 00000,  00, 00, 00,    31,  11, 1998, 4,   364,    {-28800, 0 }}},
   1.547 +
   1.548 +    /* 09-Sep-1999. Interesting because of its use as an eof marker? */
   1.549 +    { "09 Sep 1999 00:00:00",           { 000000,  00, 00, 00,     9,   8, 1999, 4,   251,   {-28800, 3600 }}},
   1.550 +    { "9/9/99      00:00:00",           { 000000,  00, 00, 00,     9,   8, 1999, 4,   251,   {-28800, 3600 }}},
   1.551 +    { "9/9/1999    00:00:00",           { 000000,  00, 00, 00,     9,   8, 1999, 4,   251,   {-28800, 3600 }}},
   1.552 +    { "9-9-99      00:00:00",           { 000000,  00, 00, 00,     9,   8, 1999, 4,   251,   {-28800, 3600 }}},
   1.553 +    { "9-9-1999    00:00:00",           { 000000,  00, 00, 00,     9,   8, 1999, 4,   251,   {-28800, 3600 }}},
   1.554 +    { "09-09-99    00:00:00",           { 000000,  00, 00, 00,     9,   8, 1999, 4,   251,   {-28800, 3600 }}},
   1.555 +    { "09-09-1999  00:00:00",           { 000000,  00, 00, 00,     9,   8, 1999, 4,   251,   {-28800, 3600 }}},
   1.556 +    { "99-09-09    00:00:00",           { 000000,  00, 00, 00,     9,   8, 1999, 4,   251,   {-28800, 3600 }}},
   1.557 +    
   1.558 +    /* "Sun". 10-Sep-1999. Because Sun said so. */
   1.559 +    { "10 Sep 1999 00:00:00",           { 000000,  00, 00, 00,    10,   8, 1999, 5,   252,   {-28800, 3600 }}},
   1.560 +    { "9/10/99     00:00:00",           { 000000,  00, 00, 00,    10,   8, 1999, 5,   252,   {-28800, 3600 }}},
   1.561 +    { "9/10/1999   00:00:00",           { 000000,  00, 00, 00,    10,   8, 1999, 5,   252,   {-28800, 3600 }}},
   1.562 +    { "9-10-99     00:00:00",           { 000000,  00, 00, 00,    10,   8, 1999, 5,   252,   {-28800, 3600 }}},
   1.563 +    { "9-10-1999   00:00:00",           { 000000,  00, 00, 00,    10,   8, 1999, 5,   252,   {-28800, 3600 }}},
   1.564 +    { "09-10-99    00:00:00",           { 000000,  00, 00, 00,    10,   8, 1999, 5,   252,   {-28800, 3600 }}},
   1.565 +    { "09-10-1999  00:00:00",           { 000000,  00, 00, 00,    10,   8, 1999, 5,   252,   {-28800, 3600 }}},
   1.566 +    { "99-09-10    00:00:00",           { 000000,  00, 00, 00,    10,   8, 1999, 5,   252,   {-28800, 3600 }}},
   1.567 +
   1.568 +    /* 31-Dec-1999 */
   1.569 +    { "31 Dec 1999 00:00:00",           { 000000,  00, 00, 00,    31,  11, 1999, 5,   364,   {-28800, 0 }}},
   1.570 +    { "12/31/99    00:00:00",           { 000000,  00, 00, 00,    31,  11, 1999, 5,   364,   {-28800, 0 }}},
   1.571 +    { "12/31/1999  00:00:00",           { 000000,  00, 00, 00,    31,  11, 1999, 5,   364,   {-28800, 0 }}},
   1.572 +    { "12-31-99    00:00:00",           { 000000,  00, 00, 00,    31,  11, 1999, 5,   364,   {-28800, 0 }}},
   1.573 +    { "12-31-1999  00:00:00",           { 000000,  00, 00, 00,    31,  11, 1999, 5,   364,   {-28800, 0 }}},
   1.574 +    { "99-12-31    00:00:00",           { 000000,  00, 00, 00,    31,  11, 1999, 5,   364,   {-28800, 0 }}},
   1.575 +    { "99/12/31    00:00:00",           { 000000,  00, 00, 00,    31,  11, 1999, 5,   364,   {-28800, 0 }}},
   1.576 +
   1.577 +    /* 01-Jan-2000 */
   1.578 +    { "01 Jan 2000 00:00:00",           { 000000,  00, 00, 00,     1,   0, 2000, 6,     0,   {-28800, 0 }}},
   1.579 +    { "1/1/00      00:00:00",           { 000000,  00, 00, 00,     1,   0, 2000, 6,     0,   {-28800, 0 }}},
   1.580 +    { "1/1/2000    00:00:00",           { 000000,  00, 00, 00,     1,   0, 2000, 6,     0,   {-28800, 0 }}},
   1.581 +    { "1-1-00      00:00:00",           { 000000,  00, 00, 00,     1,   0, 2000, 6,     0,   {-28800, 0 }}},
   1.582 +    { "1-1-2000    00:00:00",           { 000000,  00, 00, 00,     1,   0, 2000, 6,     0,   {-28800, 0 }}},
   1.583 +    { "01-01-00    00:00:00",           { 000000,  00, 00, 00,     1,   0, 2000, 6,     0,   {-28800, 0 }}},
   1.584 +    { "Saturday 01-01-2000  00:00:00",  { 000000,  00, 00, 00,     1,   0, 2000, 6,     0,   {-28800, 0 }}},
   1.585 +
   1.586 +    /* "Sun". 28-Feb-2000 */
   1.587 +    { "28 Feb 2000 00:00:00",           { 000000,  00, 00, 00,    28,   1, 2000, 1,    58,   {-28800, 0 }}},
   1.588 +    { "2/28/00     00:00:00",           { 000000,  00, 00, 00,    28,   1, 2000, 1,    58,   {-28800, 0 }}},
   1.589 +    { "2/28/2000   00:00:00",           { 000000,  00, 00, 00,    28,   1, 2000, 1,    58,   {-28800, 0 }}},
   1.590 +    { "2-28-00     00:00:00",           { 000000,  00, 00, 00,    28,   1, 2000, 1,    58,   {-28800, 0 }}},
   1.591 +    { "2-28-2000   00:00:00",           { 000000,  00, 00, 00,    28,   1, 2000, 1,    58,   {-28800, 0 }}},
   1.592 +    { "02-28-00    00:00:00",           { 000000,  00, 00, 00,    28,   1, 2000, 1,    58,   {-28800, 0 }}},
   1.593 +    { "02-28-2000  00:00:00",           { 000000,  00, 00, 00,    28,   1, 2000, 1,    58,   {-28800, 0 }}},
   1.594 +
   1.595 +    /* 29-Feb-2000 */
   1.596 +    { "29 Feb 2000 00:00:00",           { 000000,  00, 00, 00,    29,   1, 2000, 2,    59,   {-28800, 0 }}},
   1.597 +    { "2/29/00     00:00:00",           { 000000,  00, 00, 00,    29,   1, 2000, 2,    59,   {-28800, 0 }}},
   1.598 +    { "2/29/2000   00:00:00",           { 000000,  00, 00, 00,    29,   1, 2000, 2,    59,   {-28800, 0 }}},
   1.599 +    { "2-29-00     00:00:00",           { 000000,  00, 00, 00,    29,   1, 2000, 2,    59,   {-28800, 0 }}},
   1.600 +    { "2-29-2000   00:00:00",           { 000000,  00, 00, 00,    29,   1, 2000, 2,    59,   {-28800, 0 }}},
   1.601 +    { "02-29-00    00:00:00",           { 000000,  00, 00, 00,    29,   1, 2000, 2,    59,   {-28800, 0 }}},
   1.602 +    { "02-29-2000  00:00:00",           { 000000,  00, 00, 00,    29,   1, 2000, 2,    59,   {-28800, 0 }}},
   1.603 +
   1.604 +    /* 01-Mar-2000 */
   1.605 +    { "01 Mar 2000 00:00:00",           { 000000,  00, 00, 00,     1,   2, 2000, 3,    60,   {-28800, 0 }}},
   1.606 +    { "3/1/00      00:00:00",           { 000000,  00, 00, 00,     1,   2, 2000, 3,    60,   {-28800, 0 }}},
   1.607 +    { "3/1/2000    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2000, 3,    60,   {-28800, 0 }}},
   1.608 +    { "3-1-00      00:00:00",           { 000000,  00, 00, 00,     1,   2, 2000, 3,    60,   {-28800, 0 }}},
   1.609 +    { "03-01-00    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2000, 3,    60,   {-28800, 0 }}},
   1.610 +    { "03-01-2000  00:00:00",           { 000000,  00, 00, 00,     1,   2, 2000, 3,    60,   {-28800, 0 }}},
   1.611 +
   1.612 +    /* "Sun". 31-Dec-2000 */
   1.613 +    { "31 Dec 2000 00:00:00",           { 000000,  00, 00, 00,    31,  11, 2000, 0,   365,   {-28800, 0 }}},
   1.614 +    { "12/31/00    00:00:00",           { 000000,  00, 00, 00,    31,  11, 2000, 0,   365,   {-28800, 0 }}},
   1.615 +    { "12/31/2000  00:00:00",           { 000000,  00, 00, 00,    31,  11, 2000, 0,   365,   {-28800, 0 }}},
   1.616 +    { "12-31-00    00:00:00",           { 000000,  00, 00, 00,    31,  11, 2000, 0,   365,   {-28800, 0 }}},
   1.617 +    { "12-31-2000  00:00:00",           { 000000,  00, 00, 00,    31,  11, 2000, 0,   365,   {-28800, 0 }}},
   1.618 +    { "00-12-31    00:00:00",           { 000000,  00, 00, 00,    31,  11, 2000, 0,   365,   {-28800, 0 }}},
   1.619 +    { "00/12/31    00:00:00",           { 000000,  00, 00, 00,    31,  11, 2000, 0,   365,   {-28800, 0 }}},
   1.620 +
   1.621 +    /* "Sun". 01-Jan-2001 */
   1.622 +    { "01 Jan 2001 00:00:00",           { 000000,  00, 00, 00,     1,   0, 2001, 1,     0,   {-28800, 0 }}},
   1.623 +    { "1/1/01      00:00:00",           { 000000,  00, 00, 00,     1,   0, 2001, 1,     0,   {-28800, 0 }}},
   1.624 +    { "1/1/2001    00:00:00",           { 000000,  00, 00, 00,     1,   0, 2001, 1,     0,   {-28800, 0 }}},
   1.625 +    { "1-1-01      00:00:00",           { 000000,  00, 00, 00,     1,   0, 2001, 1,     0,   {-28800, 0 }}},
   1.626 +    { "1-1-2001    00:00:00",           { 000000,  00, 00, 00,     1,   0, 2001, 1,     0,   {-28800, 0 }}},
   1.627 +    { "01-01-01    00:00:00",           { 000000,  00, 00, 00,     1,   0, 2001, 1,     0,   {-28800, 0 }}},
   1.628 +    { "Saturday 01-01-2001  00:00:00",  { 000000,  00, 00, 00,     1,   0, 2001, 1,     0,   {-28800, 0 }}},
   1.629 +
   1.630 +    /* 01-Mar-2001 */
   1.631 +    { "01 Mar 2001 00:00:00",           { 000000,  00, 00, 00,     1,   2, 2001, 4,    59,   {-28800, 0 }}},
   1.632 +    { "3/1/01      00:00:00",           { 000000,  00, 00, 00,     1,   2, 2001, 4,    59,   {-28800, 0 }}},
   1.633 +    { "3/1/2001    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2001, 4,    59,   {-28800, 0 }}},
   1.634 +    { "3-1-01      00:00:00",           { 000000,  00, 00, 00,     1,   2, 2001, 4,    59,   {-28800, 0 }}},
   1.635 +    { "3-1-2001    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2001, 4,    59,   {-28800, 0 }}},
   1.636 +    { "03-01-01    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2001, 4,    59,   {-28800, 0 }}},
   1.637 +    { "03-01-2001  00:00:00",           { 000000,  00, 00, 00,     1,   2, 2001, 4,    59,   {-28800, 0 }}},
   1.638 +
   1.639 +    /* 29-Feb-2004 */
   1.640 +    { "29 Feb 2004 00:00:00",           { 000000,  00, 00, 00,    29,   1, 2004, 0,    59,   {-28800, 0 }}},
   1.641 +    { "2/29/04     00:00:00",           { 000000,  00, 00, 00,    29,   1, 2004, 0,    59,   {-28800, 0 }}},
   1.642 +    { "2/29/2004   00:00:00",           { 000000,  00, 00, 00,    29,   1, 2004, 0,    59,   {-28800, 0 }}},
   1.643 +    { "2-29-04     00:00:00",           { 000000,  00, 00, 00,    29,   1, 2004, 0,    59,   {-28800, 0 }}},
   1.644 +    { "2-29-2004   00:00:00",           { 000000,  00, 00, 00,    29,   1, 2004, 0,    59,   {-28800, 0 }}},
   1.645 +
   1.646 +    /* 01-Mar-2004 */
   1.647 +    { "01 Mar 2004 00:00:00",           { 000000,  00, 00, 00,     1,   2, 2004, 1,    60,   {-28800, 0 }}},
   1.648 +    { "3/1/04      00:00:00",           { 000000,  00, 00, 00,     1,   2, 2004, 1,    60,   {-28800, 0 }}},
   1.649 +    { "3/1/2004    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2004, 1,    60,   {-28800, 0 }}},
   1.650 +    { "3-1-04      00:00:00",           { 000000,  00, 00, 00,     1,   2, 2004, 1,    60,   {-28800, 0 }}},
   1.651 +    { "3-1-2004    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2004, 1,    60,   {-28800, 0 }}},
   1.652 +    { "03-01-04    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2004, 1,    60,   {-28800, 0 }}},
   1.653 +    { "03-01-2004  00:00:00",           { 000000,  00, 00, 00,     1,   2, 2004, 1,    60,   {-28800, 0 }}},
   1.654 +
   1.655 +    /* 01-Mar-2005 */
   1.656 +    { "01 Mar 2005 00:00:00",           { 000000,  00, 00, 00,     1,   2, 2005, 2,    59,   {-28800, 0 }}},
   1.657 +    { "3/1/05      00:00:00",           { 000000,  00, 00, 00,     1,   2, 2005, 2,    59,   {-28800, 0 }}},
   1.658 +    { "3/1/2005    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2005, 2,    59,   {-28800, 0 }}},
   1.659 +    { "3-1-05      00:00:00",           { 000000,  00, 00, 00,     1,   2, 2005, 2,    59,   {-28800, 0 }}},
   1.660 +    { "3-1-2005    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2005, 2,    59,   {-28800, 0 }}},
   1.661 +    { "03-01-05    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2005, 2,    59,   {-28800, 0 }}},
   1.662 +    { "03-01-2005  00:00:00",           { 000000,  00, 00, 00,     1,   2, 2005, 2,    59,   {-28800, 0 }}},
   1.663 +
   1.664 +    /* last element. string must be null */
   1.665 +    { NULL }        
   1.666 +}; /* end array of ParseTest */
   1.667 +
   1.668 +/*
   1.669 +** TestParseTime() -- Test PR_ParseTimeString() for y2k compliance
   1.670 +**
   1.671 +** TestParseTime() loops thru the array parseArray. For each element in
   1.672 +** the array, he calls PR_ParseTimeString() with sDate as the conversion
   1.673 +** argument. The result (ct) is then converted to a PRExplodedTime structure
   1.674 +** and compared with the exploded time value (parseArray[n].et) in the
   1.675 +** array element; if equal, the element passes the test.
   1.676 +**
   1.677 +** The array parseArray[] contains entries that are interesting to the
   1.678 +** y2k problem.
   1.679 +**
   1.680 +**
   1.681 +*/
   1.682 +static PRStatus TestParseTime( void )
   1.683 +{
   1.684 +    ParseTest       *ptp = parseArray;
   1.685 +    PRTime          ct;
   1.686 +    PRExplodedTime  cet;
   1.687 +    char            *sp = ptp->sDate;
   1.688 +    PRStatus        rc;
   1.689 +    PRStatus        rv = PR_SUCCESS;
   1.690 +
   1.691 +    while ( sp != NULL)
   1.692 +    {
   1.693 +        rc = PR_ParseTimeString( sp, PR_FALSE, &ct );
   1.694 +        if ( PR_FAILURE == rc )
   1.695 +        {
   1.696 +            printf("TestParseTime(): PR_ParseTimeString() failed to convert: %s\n", sp );
   1.697 +            rv = PR_FAILURE;
   1.698 +            failed_already = 1;
   1.699 +        }
   1.700 +        else
   1.701 +        {
   1.702 +            PR_ExplodeTime( ct, PR_LocalTimeParameters , &cet );
   1.703 +
   1.704 +            if ( !ExplodedTimeIsEqual( &cet, &ptp->et ))
   1.705 +            {
   1.706 +                printf("TestParseTime(): Exploded time compare failed: %s\n", sp );
   1.707 +                if ( debug_mode )
   1.708 +                {
   1.709 +                    PrintExplodedTime( &cet );
   1.710 +                    printf("\n");
   1.711 +                    PrintExplodedTime( &ptp->et );
   1.712 +                    printf("\n");
   1.713 +                }
   1.714 +                
   1.715 +                rv = PR_FAILURE;
   1.716 +                failed_already = 1;
   1.717 +            }
   1.718 +        }
   1.719 +                
   1.720 +        /* point to next element in array, keep going */
   1.721 +        ptp++;
   1.722 +        sp = ptp->sDate;
   1.723 +    } /* end while() */
   1.724 +
   1.725 +    return( rv );
   1.726 +} /* end TestParseTime() */
   1.727 +
   1.728 +int main(int argc, char** argv)
   1.729 +{
   1.730 +	/* The command line argument: -d is used to determine if the test is being run
   1.731 +	in debug mode. The regress tool requires only one line output:PASS or FAIL.
   1.732 +	All of the printfs associated with this test has been handled with a if (debug_mode)
   1.733 +	test.
   1.734 +	Usage: test_name -d
   1.735 +	*/
   1.736 +	PLOptStatus os;
   1.737 +	PLOptState *opt;
   1.738 +    
   1.739 +    PR_STDIO_INIT();
   1.740 +	opt = PL_CreateOptState(argc, argv, "d");
   1.741 +	while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
   1.742 +    {
   1.743 +		if (PL_OPT_BAD == os) continue;
   1.744 +        switch (opt->option)
   1.745 +        {
   1.746 +        case 'd':  /* debug mode */
   1.747 +			debug_mode = PR_TRUE;
   1.748 +            break;
   1.749 +         default:
   1.750 +            break;
   1.751 +        }
   1.752 +    }
   1.753 +	PL_DestroyOptState(opt);
   1.754 +
   1.755 + /* main test */
   1.756 +	
   1.757 +    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
   1.758 +    lm = PR_NewLogModule("test");
   1.759 +
   1.760 +    if ( PR_FAILURE == TestExplodeImplodeTime())
   1.761 +    {
   1.762 +        PR_LOG( lm, PR_LOG_ERROR,
   1.763 +            ("TestExplodeImplodeTime() failed"));
   1.764 +    }
   1.765 +    else
   1.766 +    	printf("Test 1: Calendar Time Test passed\n");
   1.767 +
   1.768 +    if ( PR_FAILURE == TestNormalizeTime())
   1.769 +    {
   1.770 +        PR_LOG( lm, PR_LOG_ERROR,
   1.771 +            ("TestNormalizeTime() failed"));
   1.772 +    }
   1.773 +    else
   1.774 +    	printf("Test 2: Normalize Time Test passed\n");
   1.775 +
   1.776 +    if ( PR_FAILURE == TestParseTime())
   1.777 +    {
   1.778 +        PR_LOG( lm, PR_LOG_ERROR,
   1.779 +            ("TestParseTime() failed"));
   1.780 +    }
   1.781 +    else
   1.782 +    	printf("Test 3: Parse Time Test passed\n");
   1.783 +
   1.784 +	if (failed_already) 
   1.785 +	    return 1;
   1.786 +	else 
   1.787 +	    return 0;
   1.788 +} /* end main() y2k.c */
   1.789 +

mercurial