Back to index

lightning-sunbird  0.9+nobinonly
y2k.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039  * file: y2k.c
00040  * description: Test for y2k compliance for NSPR.
00041  *
00042  * Sep 1999. lth. Added "Sun" specified dates to the test data.
00043  */
00044 /***********************************************************************
00045 ** Includes
00046 ***********************************************************************/
00047 /* Used to get the command line option */
00048 #include "plgetopt.h"
00049 
00050 #include "prinit.h"
00051 #include "prtime.h"
00052 #include "prprf.h"
00053 #include "prlog.h"
00054 
00055 #include <stdio.h>
00056 #include <stdlib.h>
00057 #include <string.h>
00058 
00059 #ifdef XP_MAC
00060 #include "prlog.h"
00061 #include "macstdlibextras.h"
00062 extern void SetupMacPrintfLog(char *logFile);
00063 #endif
00064 
00065 #define PRINT_DETAILS
00066 
00067 int failed_already=0;
00068 PRBool debug_mode = PR_FALSE;
00069 
00070 static char *dayOfWeek[] =
00071        { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
00072 static char *month[] =
00073        { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
00074          "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???" };
00075 
00076 PRLogModuleInfo *lm;
00077 
00078 static void PrintExplodedTime(const PRExplodedTime *et) {
00079     PRInt32 totalOffset;
00080     PRInt32 hourOffset, minOffset;
00081     const char *sign;
00082 
00083     /* Print day of the week, month, day, hour, minute, and second */
00084     printf("%s %s %2ld %02ld:%02ld:%02ld ",
00085            dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
00086            et->tm_hour, et->tm_min, et->tm_sec);
00087 
00088     /* Print year */
00089     printf("%hd ", et->tm_year);
00090 
00091     /* Print time zone */
00092     totalOffset = et->tm_params.tp_gmt_offset + et->tm_params.tp_dst_offset;
00093     if (totalOffset == 0) {
00094        printf("UTC ");
00095     } else {
00096         sign = "+";
00097         if (totalOffset < 0) {
00098            totalOffset = -totalOffset;
00099            sign = "-";
00100         }
00101         hourOffset = totalOffset / 3600;
00102         minOffset = (totalOffset % 3600) / 60;
00103         printf("%s%02ld%02ld ", sign, hourOffset, minOffset);
00104     }
00105 #ifdef PRINT_DETAILS
00106        printf("{%d, %d, %d, %d, %d, %d, %d, %d, %d, { %d, %d}}\n",et->tm_usec,
00107                                                                              et->tm_sec,
00108                                                                              et->tm_min,
00109                                                                              et->tm_hour,
00110                                                                              et->tm_mday,
00111                                                                              et->tm_month,
00112                                                                              et->tm_year,
00113                                                                              et->tm_wday,
00114                                                                              et->tm_yday,
00115                                                                              et->tm_params.tp_gmt_offset,
00116                                                                              et->tm_params.tp_dst_offset);
00117 #endif
00118 }
00119 
00120 static int ExplodedTimeIsEqual(const PRExplodedTime *et1,
00121        const PRExplodedTime *et2)
00122 {
00123     if (et1->tm_usec == et2->tm_usec &&
00124            et1->tm_sec == et2->tm_sec &&
00125            et1->tm_min == et2->tm_min &&
00126            et1->tm_hour == et2->tm_hour &&
00127            et1->tm_mday == et2->tm_mday &&
00128            et1->tm_month == et2->tm_month &&
00129            et1->tm_year == et2->tm_year &&
00130            et1->tm_wday == et2->tm_wday &&
00131            et1->tm_yday == et2->tm_yday &&
00132            et1->tm_params.tp_gmt_offset == et2->tm_params.tp_gmt_offset &&
00133            et1->tm_params.tp_dst_offset == et2->tm_params.tp_dst_offset) {
00134         return 1;
00135     } else {
00136        return 0;
00137     }
00138 }
00139 
00140 /*
00141  * TEST 1: TestExplodeImplodeTime
00142  * Description:
00143  * For each given timestamp T (a PRTime value), call PR_ExplodeTime
00144  * with GMT, US Pacific, and local time parameters.  Compare the
00145  * resulting calendar (exploded) time values with the expected
00146  * values.
00147  *
00148  * Note: the expected local time values depend on the local time
00149  * zone.  The local time values stored in this test are for the US
00150  * Pacific Time Zone.  If you are running this test in a different
00151  * time zone, you need to modify the values in the localt array.
00152  * An example is provided below.
00153  *
00154  * Call PR_ImplodeTime for each of the exploded values and compare
00155  * the resulting PRTime values with the original input.
00156  * 
00157  * This test is run for the values of time T corresponding to the
00158  * following dates:
00159  * - 12/31/99 - before 2000 
00160  * - 01/01/00 - after 2000 
00161  * - Leap year - Feb 29, 2000 
00162  * - March 1st, 2001 (after 1 year) 
00163  * - March 1st, 2005 (after second leap year) 
00164  * - 09/09/99 (used by some programs as an end of file marker)
00165  *
00166  * Call PR_Now, convert to calendar time using PR_ExplodeTime and
00167  * manually check the result for correctness. The time should match
00168  * the system clock.
00169  *
00170  * Tested functions: PR_Now, PR_ExplodeTime, PR_ImplodeTime,
00171  * PR_LocalTimeParameters, PR_GMTParameters. 
00172  */
00173 
00174 static PRTime prt[] = {
00175     LL_INIT(220405, 2133125120),  /* 946634400000000 */
00176     LL_INIT(220425, 2633779200),  /* 946720800000000 */
00177     LL_INIT(221612, 2107598848),  /* 951818400000000 */
00178     LL_INIT(228975, 663398400),  /* 983440800000000 */
00179     LL_INIT(258365, 1974568960),  /* 1109671200000000 */
00180     LL_INIT(218132, 1393788928),  /* 936871200000000 */
00181     /* Sun's dates follow */
00182     LL_INIT( 213062, 4077979648 ), /* Dec 31 1998 10:00:00 */
00183     LL_INIT( 218152, 1894443008 ), /* Sep 10 1999 10:00:00 */
00184     LL_INIT( 221592, 1606944768 ), /* Feb 28 2000 10:00:00 */
00185     LL_INIT( 227768, 688924672 ), /* Dec 31 2000 10:00:00 */
00186     LL_INIT( 227788, 1189578752 ), /* Jan 1  2001 10:00:00 */
00187 };
00188 
00189 static PRExplodedTime gmt[] = {
00190     { 0, 0, 0, 10, 31, 11, 1999, 5, 364, {0, 0}}, /* 1999/12/31 10:00:00 GMT */
00191     { 0, 0, 0, 10, 1, 0, 2000, 6, 0, {0, 0}}, /* 2000/01/01 10:00:00 GMT */
00192     { 0, 0, 0, 10, 29, 1, 2000, 2, 59, {0, 0}}, /* 2000/02/29 10:00:00 GMT */
00193     { 0, 0, 0, 10, 1, 2, 2001, 4, 59, {0, 0}}, /* 2001/3/1 10:00:00 GMT */
00194     { 0, 0, 0, 10, 1, 2, 2005, 2, 59, {0, 0}}, /* 2005/3/1 10:00:00 GMT */
00195     { 0, 0, 0, 10, 9, 8, 1999, 4, 251, {0, 0}},  /* 1999/9/9 10:00:00 GMT */
00196     /* Sun's dates follow */
00197     { 0, 0, 0, 10, 31, 11, 1998, 4, 364, {0, 0}},  /* 12/31/1998 10:00:00 GMT */
00198     { 0, 0, 0, 10, 10, 8, 1999, 5, 252, {0, 0}},  /* 9/10/1999 10:00:00 GMT */
00199     { 0, 0, 0, 10, 28, 1, 2000, 1, 58, {0, 0}},  /* 2/28/2000 10:00:00 GMT */
00200     { 0, 0, 0, 10, 31, 11, 2000, 0, 365, {0, 0}},  /* 12/31/2000 10:00:00 GMT */
00201     { 0, 0, 0, 10, 1, 0, 2001, 1, 0, {0, 0}}  /* 1/1/2001 10:00:00 GMT */
00202 };
00203 
00204 static PRExplodedTime uspt[] = {
00205 { 0, 0, 0, 2, 31, 11, 1999, 5, 364, {-28800, 0}}, /* 1999/12/31 2:00:00 PST */
00206 { 0, 0, 0, 2, 1, 0, 2000, 6, 0, {-28800, 0}}, /* 2000/01/01 2:00:00 PST */
00207 { 0, 0, 0, 2, 29, 1, 2000, 2, 59, {-28800, 0}}, /* 2000/02/29 2:00:00 PST */
00208 { 0, 0, 0, 2, 1, 2, 2001, 4, 59, {-28800, 0}}, /* 2001/3/1 2:00:00 PST */
00209 { 0, 0, 0, 2, 1, 2, 2005, 2, 59, {-28800, 0}}, /* 2005/3/1 2:00:00 PST */
00210 { 0, 0, 0, 3, 9, 8, 1999, 4, 251, {-28800, 3600}},  /* 1999/9/9 3:00:00 PDT */
00211     /* Sun's dates follow */
00212     { 0, 0, 0, 2, 31, 11, 1998, 4, 364, {-28800, 0}},  /* 12/31/1998 00:00:00 GMT */
00213     { 0, 0, 0, 3, 10, 8, 1999, 5, 252, {-28800, 3600}},  /* 9/10/1999 00:00:00 GMT */
00214     { 0, 0, 0, 2, 28, 1, 2000, 1, 58, {-28800, 0}},  /* 2/28/2000 00:00:00 GMT */
00215     { 0, 0, 0, 2, 31, 11, 2000, 0, 365, {-28800, 0}},  /* 12/31/2000 00:00:00 GMT */
00216     { 0, 0, 0, 2, 1, 0, 2001, 1, 0, {-28800, 0}}  /* 1/1/2001 00:00:00 GMT */
00217 };
00218 
00219 /*
00220  * This test assumes that we are in US Pacific Time Zone.
00221  * If you are running this test in a different time zone,
00222  * you need to modify the localt array and fill in the
00223  * expected results.  The localt array for US Eastern Time
00224  * Zone is provided as an example.
00225  */
00226 static PRExplodedTime localt[] = {
00227 { 0, 0, 0, 2, 31, 11, 1999, 5, 364, {-28800, 0}}, /* 1999/12/31 2:00:00 PST */
00228 { 0, 0, 0, 2, 1, 0, 2000, 6, 0, {-28800, 0}}, /* 2000/01/01 2:00:00 PST */
00229 { 0, 0, 0, 2, 29, 1, 2000, 2, 59, {-28800, 0}}, /* 2000/02/29 2:00:00 PST */
00230 { 0, 0, 0, 2, 1, 2, 2001, 4, 59, {-28800, 0}}, /* 2001/3/1 2:00:00 PST */
00231 { 0, 0, 0, 2, 1, 2, 2005, 2, 59, {-28800, 0}}, /* 2005/3/1 2:00:00 PST */
00232 { 0, 0, 0, 3, 9, 8, 1999, 4, 251, {-28800, 3600}},  /* 1999/9/9 3:00:00 PDT */
00233     /* Sun's dates follow */
00234     { 0, 0, 0, 2, 31, 11, 1998, 4, 364, {-28800, 0}},  /* 12/31/1998 00:00:00 GMT */
00235     { 0, 0, 0, 3, 10, 8, 1999, 5, 252, {-28800, 3600}},  /* 9/10/1999 00:00:00 GMT */
00236     { 0, 0, 0, 2, 28, 1, 2000, 1, 58, {-28800, 0}},  /* 2/28/2000 00:00:00 GMT */
00237     { 0, 0, 0, 2, 31, 11, 2000, 0, 365, {-28800, 0}},  /* 12/31/2000 00:00:00 GMT */
00238     { 0, 0, 0, 2, 1, 0, 2001, 1, 0, {-28800, 0}}  /* 1/1/2001 00:00:00 GMT */
00239 };
00240 
00241 #ifdef US_EASTERN_TIME
00242 static PRExplodedTime localt[] = {
00243 { 0, 0, 0, 5, 31, 11, 1999, 5, 364, {-18000, 0}}, /* 1999/12/31 2:00:00 EST */
00244 { 0, 0, 0, 5, 1, 0, 2000, 6, 0, {-18000, 0}}, /* 2000/01/01 2:00:00 EST */
00245 { 0, 0, 0, 5, 29, 1, 2000, 2, 59, {-18000, 0}}, /* 2000/02/29 2:00:00 EST */
00246 { 0, 0, 0, 5, 1, 2, 2001, 4, 59, {-18000, 0}}, /* 2001/3/1 2:00:00 EST */
00247 { 0, 0, 0, 5, 1, 2, 2005, 2, 59, {-18000, 0}}, /* 2005/3/1 2:00:00 EST */
00248 { 0, 0, 0, 6, 9, 8, 1999, 4, 251, {-18000, 3600}},  /* 1999/9/9 3:00:00 EDT */
00249     /* Sun's dates follow */
00250     { 0, 0, 0, 5, 31, 11, 1998, 4, 364, {-18000 0}},  /* 12/31/1998 00:00:00 GMT */
00251     { 0, 0, 0, 6, 10, 8, 1999, 5, 252, {-18000 3600}},  /* 9/10/1999 00:00:00 GMT */
00252     { 0, 0, 0, 5, 28, 1, 2000, 1, 58, {-18000 0}},  /* 2/28/2000 00:00:00 GMT */
00253     { 0, 0, 0, 5, 31, 11, 2000, 0, 365, {-18000 0}},  /* 12/31/2000 00:00:00 GMT */
00254     { 0, 0, 0, 5, 1, 0, 2001, 1, 0, {-18000 0}}  /* 1/1/2001 00:00:00 GMT */
00255 };
00256 #endif
00257 
00258 static PRStatus TestExplodeImplodeTime(void)
00259 {
00260     PRTime prt_tmp;
00261     PRTime now;
00262     int idx;
00263     int array_size = sizeof(prt) / sizeof(PRTime);
00264     PRExplodedTime et_tmp;
00265     char buf[1024];
00266 
00267     for (idx = 0; idx < array_size; idx++) {
00268         PR_snprintf(buf, sizeof(buf), "%lld", prt[idx]);
00269         if (debug_mode) printf("Time stamp %s\n", buf); 
00270         PR_ExplodeTime(prt[idx], PR_GMTParameters, &et_tmp);
00271         if (!ExplodedTimeIsEqual(&et_tmp, &gmt[idx])) {
00272             fprintf(stderr, "GMT not equal\n");
00273             PrintExplodedTime(&et_tmp);
00274             PrintExplodedTime(&gmt[idx]);
00275             exit(1);
00276         }
00277         prt_tmp = PR_ImplodeTime(&et_tmp);
00278         if (LL_NE(prt_tmp, prt[idx])) {
00279             fprintf(stderr, "PRTime not equal\n");
00280             exit(1);
00281         }
00282         if (debug_mode) {
00283             printf("GMT: ");
00284             PrintExplodedTime(&et_tmp);
00285             printf("\n");
00286         }
00287 
00288         PR_ExplodeTime(prt[idx], PR_USPacificTimeParameters, &et_tmp);
00289         if (!ExplodedTimeIsEqual(&et_tmp, &uspt[idx])) {
00290             fprintf(stderr, "US Pacific Time not equal\n");
00291             PrintExplodedTime(&et_tmp);
00292             PrintExplodedTime(&uspt[idx]);
00293             exit(1);
00294         }
00295         prt_tmp = PR_ImplodeTime(&et_tmp);
00296         if (LL_NE(prt_tmp, prt[idx])) {
00297             fprintf(stderr, "PRTime not equal\n");
00298             exit(1);
00299         }
00300         if (debug_mode) {
00301             printf("US Pacific Time: ");
00302             PrintExplodedTime(&et_tmp);
00303             printf("\n");
00304         }
00305 
00306         PR_ExplodeTime(prt[idx], PR_LocalTimeParameters, &et_tmp);
00307         if (!ExplodedTimeIsEqual(&et_tmp, &localt[idx])) {
00308             fprintf(stderr, "not equal\n");
00309             PrintExplodedTime(&et_tmp);
00310             PrintExplodedTime(&localt[idx]);
00311             exit(1);
00312         }
00313         prt_tmp = PR_ImplodeTime(&et_tmp);
00314         if (LL_NE(prt_tmp, prt[idx])) {
00315             fprintf(stderr, "not equal\n");
00316             exit(1);
00317         }
00318         if (debug_mode) {
00319             printf("Local time:");
00320             PrintExplodedTime(&et_tmp);
00321             printf("\n\n");
00322         }
00323     }
00324 
00325     now = PR_Now();
00326     PR_ExplodeTime(now, PR_GMTParameters, &et_tmp);
00327     printf("Current GMT is ");
00328     PrintExplodedTime(&et_tmp);
00329     printf("\n");
00330     prt_tmp = PR_ImplodeTime(&et_tmp);
00331     if (LL_NE(prt_tmp, now)) {
00332         fprintf(stderr, "not equal\n");
00333         exit(1);
00334     }
00335     PR_ExplodeTime(now, PR_USPacificTimeParameters, &et_tmp);
00336     printf("Current US Pacific Time is ");
00337     PrintExplodedTime(&et_tmp);
00338     printf("\n");
00339     prt_tmp = PR_ImplodeTime(&et_tmp);
00340     if (LL_NE(prt_tmp, now)) {
00341         fprintf(stderr, "not equal\n");
00342         exit(1);
00343     }
00344     PR_ExplodeTime(now, PR_LocalTimeParameters, &et_tmp);
00345     printf("Current local time is ");
00346     PrintExplodedTime(&et_tmp);
00347     printf("\n");
00348     prt_tmp = PR_ImplodeTime(&et_tmp);
00349     if (LL_NE(prt_tmp, now)) {
00350         fprintf(stderr, "not equal\n");
00351         exit(1);
00352     }
00353     printf("Please verify the results\n\n");
00354 
00355     if (debug_mode) printf("Test 1 passed\n");
00356     return PR_SUCCESS;
00357 }
00358 /* End of Test 1: TestExplodeImplodeTime */
00359 
00360 /*
00361  * Test 2: Normalize Time
00362  */
00363 
00364 /*
00365  * time increment for addition to PRExplodeTime
00366  */
00367 typedef struct time_increment {
00368        PRInt32 ti_usec;
00369        PRInt32 ti_sec;
00370        PRInt32 ti_min;
00371        PRInt32 ti_hour;
00372 } time_increment_t;
00373 
00374 /*
00375  * Data for testing PR_Normalize
00376  *            Add the increment to base_time, normalize it to GMT and US Pacific
00377  *            Time zone.
00378  */
00379 typedef struct normalize_test_data {
00380     PRExplodedTime          base_time; 
00381     time_increment_t        increment;
00382     PRExplodedTime          expected_gmt_time;
00383     PRExplodedTime          expected_uspt_time;
00384 } normalize_test_data_t;
00385 
00386 
00387 /*
00388  * Test data -       the base time values cover dates of interest including y2k - 1,
00389  *                          y2k + 1, y2k leap year, y2k leap date + 1year,
00390  *                          y2k leap date + 4 years
00391  */
00392 normalize_test_data_t normalize_test_array[] = {
00393   /*usec sec min hour  mday  mo  year  wday yday {gmtoff, dstoff }*/
00394 
00395        /* Fri 12/31/1999 19:32:48 PST */
00396        {{0, 48, 32, 19, 31, 11, 1999, 5, 364, { -28800, 0}},
00397     {0, 0, 30, 20},
00398        {0, 48, 2, 0, 2, 0, 2000, 0, 1, { 0, 0}}, /*Sun Jan 2 00:02:48 UTC 2000*/
00399        {0, 48, 2, 16, 1, 0, 2000, 6, 0, { -28800, 0}},/* Sat Jan 1 16:02:48
00400                                                                                                   PST 2000*/
00401        },
00402        /* Fri 99-12-31 23:59:02 GMT */
00403        {{0, 2, 59, 23, 31, 11, 1999, 5, 364, { 0, 0}},
00404     {0, 0, 45, 0},
00405        {0, 2, 44, 0, 1, 0, 2000, 6, 0, { 0, 0}},/* Sat Jan 1 00:44:02 UTC 2000*/
00406        {0, 2, 44, 16, 31, 11, 1999, 5, 364, { -28800, 0}}/*Fri Dec 31 16:44:02
00407                                                                                                   PST 1999*/
00408        },
00409        /* 99-12-25 12:00:00 GMT */
00410        {{0, 0, 0, 12, 25, 11, 1999, 6, 358, { 0, 0}},
00411     {0, 0, 0, 364 * 24},
00412        {0, 0, 0, 12, 23, 11, 2000, 6, 357, { 0, 0}},/*Sat Dec 23 12:00:00
00413                                                                                            2000 UTC*/
00414        {0, 0, 0, 4, 23, 11, 2000, 6, 357, { -28800, 0}}/*Sat Dec 23 04:00:00
00415                                                                                                   2000 -0800*/
00416        },
00417        /* 00-01-1 00:00:00 PST */
00418     {{0, 0, 0, 0, 1, 0, 2000, 6, 0, { -28800, 0}},
00419     {0, 0, 0, 48},
00420     {0, 0, 0, 8, 3, 0, 2000, 1, 2, { 0, 0}},/*Mon Jan  3 08:00:00 2000 UTC*/
00421     {0, 0, 0, 0, 3, 0, 2000, 1, 2, { -28800, 0}}/*Mon Jan  3 00:00:00 2000
00422                                                                                                                 -0800*/
00423        },
00424        /* 00-01-10 12:00:00 PST */
00425     {{0, 0, 0, 12, 10, 0, 2000, 1, 9, { -28800, 0}},
00426     {0, 0, 0, 364 * 5 * 24},
00427     {0, 0, 0, 20, 3, 0, 2005, 1, 2, { 0, 0}},/*Mon Jan  3 20:00:00 2005 UTC */
00428     {0, 0, 0, 12, 3, 0, 2005, 1, 2, { -28800, 0}}/*Mon Jan  3 12:00:00
00429                                                                                                   2005 -0800*/
00430        },
00431        /* 00-02-28 15:39 GMT */
00432        {{0, 0, 39, 15, 28, 1, 2000, 1, 58, { 0, 0}},
00433     {0,  0, 0, 24},
00434        {0, 0, 39, 15, 29, 1, 2000, 2, 59, { 0, 0}}, /*Tue Feb 29 15:39:00 2000
00435                                                                                                   UTC*/
00436        {0, 0, 39, 7, 29, 1, 2000, 2, 59, { -28800, 0}}/*Tue Feb 29 07:39:00
00437                                                                                                   2000 -0800*/
00438        },
00439        /* 01-03-01 12:00 PST */
00440     {{0, 0, 0, 12, 3, 0, 2001, 3, 2, { -28800, 0}},/*Wed Jan 3 12:00:00
00441                                                                                            -0800 2001*/
00442     {0, 30, 30,45},
00443     {0, 30, 30, 17, 5, 0, 2001, 5, 4, { 0, 0}}, /*Fri Jan  5 17:30:30 2001
00444                                                                                            UTC*/
00445     {0, 30, 30, 9, 5, 0, 2001, 5, 4, { -28800, 0}} /*Fri Jan  5 09:30:30
00446                                                                                                   2001 -0800*/
00447        },
00448        /* 2004-04-26 12:00 GMT */
00449        {{0, 0, 0, 20, 3, 0, 2001, 3, 2, { 0, 0}},
00450     {0, 0, 30,0},
00451        {0, 0, 30, 20, 3, 0, 2001, 3, 2, { 0, 0}},/*Wed Jan  3 20:30:00 2001 UTC*/ 
00452     {0, 0, 30, 12, 3, 0, 2001, 3, 2, { -28800, 0}}/*Wed Jan  3 12:30:00
00453                                                                                                   2001 -0800*/
00454        },
00455        /* 99-09-09 00:00 GMT */
00456        {{0, 0, 0, 0, 9, 8, 1999, 4, 251, { 0, 0}},
00457     {0, 0, 0, 12},
00458     {0, 0, 0, 12, 9, 8, 1999, 4, 251, { 0, 0}},/*Thu Sep  9 12:00:00 1999 UTC*/
00459     {0, 0, 0, 5, 9, 8, 1999, 4, 251, { -28800, 3600}}/*Thu Sep  9 05:00:00
00460                                                                                                   1999 -0700*/
00461        }
00462 };
00463 
00464 void add_time_increment(PRExplodedTime *et1, time_increment_t *it)
00465 {
00466        et1->tm_usec += it->ti_usec;
00467        et1->tm_sec   += it->ti_sec;
00468        et1->tm_min += it->ti_min;
00469        et1->tm_hour += it->ti_hour;
00470 }
00471 
00472 /*
00473 ** TestNormalizeTime() -- Test PR_NormalizeTime()
00474 **            For each data item, add the time increment to the base_time and then
00475 **            normalize it for GMT and local time zones. This test assumes that
00476 **            the local time zone is the Pacific Time Zone. The normalized values
00477 **            should match the expected values in the data item.
00478 **
00479 */
00480 PRStatus TestNormalizeTime(void)
00481 {
00482 int idx, count;
00483 normalize_test_data_t *itemp;
00484 time_increment_t *itp;
00485 
00486        count = sizeof(normalize_test_array)/sizeof(normalize_test_array[0]);
00487        for (idx = 0; idx < count; idx++) {
00488               itemp = &normalize_test_array[idx];
00489               if (debug_mode) {
00490                      printf("%2d. %15s",idx +1,"Base time: ");
00491                      PrintExplodedTime(&itemp->base_time);
00492                      printf("\n");
00493               }
00494               itp = &itemp->increment;
00495               if (debug_mode) {
00496                      printf("%20s %2d hrs %2d min %3d sec\n","Add",itp->ti_hour,
00497                                                                                     itp->ti_min, itp->ti_sec);
00498               }
00499               add_time_increment(&itemp->base_time, &itemp->increment);
00500               PR_NormalizeTime(&itemp->base_time, PR_LocalTimeParameters);
00501               if (debug_mode) {
00502                      printf("%19s","PST time: ");
00503                      PrintExplodedTime(&itemp->base_time);
00504                      printf("\n");
00505               }
00506               if (!ExplodedTimeIsEqual(&itemp->base_time,
00507                                                                &itemp->expected_uspt_time)) {
00508                      printf("PR_NormalizeTime failed\n");
00509                      if (debug_mode)
00510                             PrintExplodedTime(&itemp->expected_uspt_time);
00511                      return PR_FAILURE;
00512               }
00513               PR_NormalizeTime(&itemp->base_time, PR_GMTParameters);
00514               if (debug_mode) {
00515                      printf("%19s","GMT time: ");
00516                      PrintExplodedTime(&itemp->base_time);
00517                      printf("\n");
00518               }
00519 
00520               if (!ExplodedTimeIsEqual(&itemp->base_time,
00521                                                                &itemp->expected_gmt_time)) {
00522                      printf("PR_NormalizeTime failed\n");
00523                      return PR_FAILURE;
00524               }
00525        }
00526        return PR_SUCCESS;
00527 }
00528 
00529 
00530 /*
00531 ** ParseTest. Structure defining a string time and a matching exploded time
00532 **
00533 */
00534 typedef struct ParseTest
00535 {
00536     char            *sDate;     /* string to be converted using PR_ParseTimeString() */
00537     PRExplodedTime  et;         /* expected result of the conversion */
00538 } ParseTest;
00539 
00540 static ParseTest parseArray[] = 
00541 {
00542     /*                                  |<----- expected result ------------------------------------------->| */
00543     /* "string to test"                   usec     sec min hour   day  mo  year  wday julian {gmtoff, dstoff }*/
00544     { "Thursday 1 Jan 1970 00:00:00",   { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00545     { "1 Jan 1970 00:00:00",            { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00546     { "1-Jan-1970 00:00:00",            { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00547     { "01-Jan-1970 00:00:00",           { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00548     { "January 1, 1970",                { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00549     { "January 1, 1970 00:00",          { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00550     { "January 01, 1970 00:00",         { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00551     { "January 01 1970 00:00",          { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00552     { "January 01 1970 00:00:00",       { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00553     { "01-01-1970",                     { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00554     { "01/01/1970",                     { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00555     { "01/01/70",                       { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00556     { "01/01/70 00:00:00",              { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00557     { "70/01/01 00:00:00",              { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00558     { "70/1/1 00:00:",                  { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00559     { "00:00 Thursday, January 1, 1970",{ 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00560     { "1-Jan-70 00:00:00",              { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00561     { "70-01-01 00:00:00",              { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00562     { "70/01/01 00:00:00",              { 000000,  00, 00, 00,     1,   0, 1970, 4,     0,   {-28800, 0 }}},
00563 
00564     /* 31-Dec-1969 */
00565     { "Wed 31 Dec 1969 00:00:00",       { 000000,  00, 00, 00,    31,  11, 1969, 3,   364,   {-28800, 0 }}},
00566     { "31 Dec 1969 00:00:00",           { 000000,  00, 00, 00,    31,  11, 1969, 3,   364,   {-28800, 0 }}},
00567     { "12/31/69    00:00:00",           { 000000,  00, 00, 00,    31,  11, 2069, 2,   364,   {-28800, 0 }}},
00568     { "12/31/1969  00:00:00",           { 000000,  00, 00, 00,    31,  11, 1969, 3,   364,   {-28800, 0 }}},
00569     { "12-31-69    00:00:00",           { 000000,  00, 00, 00,    31,  11, 2069, 2,   364,   {-28800, 0 }}},
00570     { "12-31-1969  00:00:00",           { 000000,  00, 00, 00,    31,  11, 1969, 3,   364,   {-28800, 0 }}},
00571     { "69-12-31    00:00:00",           { 000000,  00, 00, 00,    31,  11, 2069, 2,   364,   {-28800, 0 }}},
00572     { "69/12/31    00:00:00",           { 000000,  00, 00, 00,    31,  11, 2069, 2,   364,   {-28800, 0 }}},
00573 
00574     /* "Sun". 31-Dec-1998 (?) */ 
00575     { "Thu 31 Dec 1998 00:00:00",        { 00000,  00, 00, 00,    31,  11, 1998, 4,   364,    {-28800, 0 }}},
00576     { "12/31/98    00:00:00",            { 00000,  00, 00, 00,    31,  11, 1998, 4,   364,    {-28800, 0 }}},
00577     { "12/31/1998  00:00:00",            { 00000,  00, 00, 00,    31,  11, 1998, 4,   364,    {-28800, 0 }}},
00578     { "12-31-98    00:00:00",            { 00000,  00, 00, 00,    31,  11, 1998, 4,   364,    {-28800, 0 }}},
00579     { "12-31-1998  00:00:00",            { 00000,  00, 00, 00,    31,  11, 1998, 4,   364,    {-28800, 0 }}},
00580     { "98-12-31    00:00:00",            { 00000,  00, 00, 00,    31,  11, 1998, 4,   364,    {-28800, 0 }}},
00581     { "98/12/31    00:00:00",            { 00000,  00, 00, 00,    31,  11, 1998, 4,   364,    {-28800, 0 }}},
00582 
00583     /* 09-Sep-1999. Interesting because of its use as an eof marker? */
00584     { "09 Sep 1999 00:00:00",           { 000000,  00, 00, 00,     9,   8, 1999, 4,   251,   {-28800, 3600 }}},
00585     { "9/9/99      00:00:00",           { 000000,  00, 00, 00,     9,   8, 1999, 4,   251,   {-28800, 3600 }}},
00586     { "9/9/1999    00:00:00",           { 000000,  00, 00, 00,     9,   8, 1999, 4,   251,   {-28800, 3600 }}},
00587     { "9-9-99      00:00:00",           { 000000,  00, 00, 00,     9,   8, 1999, 4,   251,   {-28800, 3600 }}},
00588     { "9-9-1999    00:00:00",           { 000000,  00, 00, 00,     9,   8, 1999, 4,   251,   {-28800, 3600 }}},
00589     { "09-09-99    00:00:00",           { 000000,  00, 00, 00,     9,   8, 1999, 4,   251,   {-28800, 3600 }}},
00590     { "09-09-1999  00:00:00",           { 000000,  00, 00, 00,     9,   8, 1999, 4,   251,   {-28800, 3600 }}},
00591     { "99-09-09    00:00:00",           { 000000,  00, 00, 00,     9,   8, 1999, 4,   251,   {-28800, 3600 }}},
00592     
00593     /* "Sun". 10-Sep-1999. Because Sun said so. */
00594     { "10 Sep 1999 00:00:00",           { 000000,  00, 00, 00,    10,   8, 1999, 5,   252,   {-28800, 3600 }}},
00595     { "9/10/99     00:00:00",           { 000000,  00, 00, 00,    10,   8, 1999, 5,   252,   {-28800, 3600 }}},
00596     { "9/10/1999   00:00:00",           { 000000,  00, 00, 00,    10,   8, 1999, 5,   252,   {-28800, 3600 }}},
00597     { "9-10-99     00:00:00",           { 000000,  00, 00, 00,    10,   8, 1999, 5,   252,   {-28800, 3600 }}},
00598     { "9-10-1999   00:00:00",           { 000000,  00, 00, 00,    10,   8, 1999, 5,   252,   {-28800, 3600 }}},
00599     { "09-10-99    00:00:00",           { 000000,  00, 00, 00,    10,   8, 1999, 5,   252,   {-28800, 3600 }}},
00600     { "09-10-1999  00:00:00",           { 000000,  00, 00, 00,    10,   8, 1999, 5,   252,   {-28800, 3600 }}},
00601     { "99-09-10    00:00:00",           { 000000,  00, 00, 00,    10,   8, 1999, 5,   252,   {-28800, 3600 }}},
00602 
00603     /* 31-Dec-1999 */
00604     { "31 Dec 1999 00:00:00",           { 000000,  00, 00, 00,    31,  11, 1999, 5,   364,   {-28800, 0 }}},
00605     { "12/31/99    00:00:00",           { 000000,  00, 00, 00,    31,  11, 1999, 5,   364,   {-28800, 0 }}},
00606     { "12/31/1999  00:00:00",           { 000000,  00, 00, 00,    31,  11, 1999, 5,   364,   {-28800, 0 }}},
00607     { "12-31-99    00:00:00",           { 000000,  00, 00, 00,    31,  11, 1999, 5,   364,   {-28800, 0 }}},
00608     { "12-31-1999  00:00:00",           { 000000,  00, 00, 00,    31,  11, 1999, 5,   364,   {-28800, 0 }}},
00609     { "99-12-31    00:00:00",           { 000000,  00, 00, 00,    31,  11, 1999, 5,   364,   {-28800, 0 }}},
00610     { "99/12/31    00:00:00",           { 000000,  00, 00, 00,    31,  11, 1999, 5,   364,   {-28800, 0 }}},
00611 
00612     /* 01-Jan-2000 */
00613     { "01 Jan 2000 00:00:00",           { 000000,  00, 00, 00,     1,   0, 2000, 6,     0,   {-28800, 0 }}},
00614     { "1/1/00      00:00:00",           { 000000,  00, 00, 00,     1,   0, 2000, 6,     0,   {-28800, 0 }}},
00615     { "1/1/2000    00:00:00",           { 000000,  00, 00, 00,     1,   0, 2000, 6,     0,   {-28800, 0 }}},
00616     { "1-1-00      00:00:00",           { 000000,  00, 00, 00,     1,   0, 2000, 6,     0,   {-28800, 0 }}},
00617     { "1-1-2000    00:00:00",           { 000000,  00, 00, 00,     1,   0, 2000, 6,     0,   {-28800, 0 }}},
00618     { "01-01-00    00:00:00",           { 000000,  00, 00, 00,     1,   0, 2000, 6,     0,   {-28800, 0 }}},
00619     { "Saturday 01-01-2000  00:00:00",  { 000000,  00, 00, 00,     1,   0, 2000, 6,     0,   {-28800, 0 }}},
00620 
00621     /* "Sun". 28-Feb-2000 */
00622     { "28 Feb 2000 00:00:00",           { 000000,  00, 00, 00,    28,   1, 2000, 1,    58,   {-28800, 0 }}},
00623     { "2/28/00     00:00:00",           { 000000,  00, 00, 00,    28,   1, 2000, 1,    58,   {-28800, 0 }}},
00624     { "2/28/2000   00:00:00",           { 000000,  00, 00, 00,    28,   1, 2000, 1,    58,   {-28800, 0 }}},
00625     { "2-28-00     00:00:00",           { 000000,  00, 00, 00,    28,   1, 2000, 1,    58,   {-28800, 0 }}},
00626     { "2-28-2000   00:00:00",           { 000000,  00, 00, 00,    28,   1, 2000, 1,    58,   {-28800, 0 }}},
00627     { "02-28-00    00:00:00",           { 000000,  00, 00, 00,    28,   1, 2000, 1,    58,   {-28800, 0 }}},
00628     { "02-28-2000  00:00:00",           { 000000,  00, 00, 00,    28,   1, 2000, 1,    58,   {-28800, 0 }}},
00629 
00630     /* 29-Feb-2000 */
00631     { "29 Feb 2000 00:00:00",           { 000000,  00, 00, 00,    29,   1, 2000, 2,    59,   {-28800, 0 }}},
00632     { "2/29/00     00:00:00",           { 000000,  00, 00, 00,    29,   1, 2000, 2,    59,   {-28800, 0 }}},
00633     { "2/29/2000   00:00:00",           { 000000,  00, 00, 00,    29,   1, 2000, 2,    59,   {-28800, 0 }}},
00634     { "2-29-00     00:00:00",           { 000000,  00, 00, 00,    29,   1, 2000, 2,    59,   {-28800, 0 }}},
00635     { "2-29-2000   00:00:00",           { 000000,  00, 00, 00,    29,   1, 2000, 2,    59,   {-28800, 0 }}},
00636     { "02-29-00    00:00:00",           { 000000,  00, 00, 00,    29,   1, 2000, 2,    59,   {-28800, 0 }}},
00637     { "02-29-2000  00:00:00",           { 000000,  00, 00, 00,    29,   1, 2000, 2,    59,   {-28800, 0 }}},
00638 
00639     /* 01-Mar-2000 */
00640     { "01 Mar 2000 00:00:00",           { 000000,  00, 00, 00,     1,   2, 2000, 3,    60,   {-28800, 0 }}},
00641     { "3/1/00      00:00:00",           { 000000,  00, 00, 00,     1,   2, 2000, 3,    60,   {-28800, 0 }}},
00642     { "3/1/2000    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2000, 3,    60,   {-28800, 0 }}},
00643     { "3-1-00      00:00:00",           { 000000,  00, 00, 00,     1,   2, 2000, 3,    60,   {-28800, 0 }}},
00644     { "03-01-00    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2000, 3,    60,   {-28800, 0 }}},
00645     { "03-01-2000  00:00:00",           { 000000,  00, 00, 00,     1,   2, 2000, 3,    60,   {-28800, 0 }}},
00646 
00647     /* "Sun". 31-Dec-2000 */
00648     { "31 Dec 2000 00:00:00",           { 000000,  00, 00, 00,    31,  11, 2000, 0,   365,   {-28800, 0 }}},
00649     { "12/31/00    00:00:00",           { 000000,  00, 00, 00,    31,  11, 2000, 0,   365,   {-28800, 0 }}},
00650     { "12/31/2000  00:00:00",           { 000000,  00, 00, 00,    31,  11, 2000, 0,   365,   {-28800, 0 }}},
00651     { "12-31-00    00:00:00",           { 000000,  00, 00, 00,    31,  11, 2000, 0,   365,   {-28800, 0 }}},
00652     { "12-31-2000  00:00:00",           { 000000,  00, 00, 00,    31,  11, 2000, 0,   365,   {-28800, 0 }}},
00653     { "00-12-31    00:00:00",           { 000000,  00, 00, 00,    31,  11, 2000, 0,   365,   {-28800, 0 }}},
00654     { "00/12/31    00:00:00",           { 000000,  00, 00, 00,    31,  11, 2000, 0,   365,   {-28800, 0 }}},
00655 
00656     /* "Sun". 01-Jan-2001 */
00657     { "01 Jan 2001 00:00:00",           { 000000,  00, 00, 00,     1,   0, 2001, 1,     0,   {-28800, 0 }}},
00658     { "1/1/01      00:00:00",           { 000000,  00, 00, 00,     1,   0, 2001, 1,     0,   {-28800, 0 }}},
00659     { "1/1/2001    00:00:00",           { 000000,  00, 00, 00,     1,   0, 2001, 1,     0,   {-28800, 0 }}},
00660     { "1-1-01      00:00:00",           { 000000,  00, 00, 00,     1,   0, 2001, 1,     0,   {-28800, 0 }}},
00661     { "1-1-2001    00:00:00",           { 000000,  00, 00, 00,     1,   0, 2001, 1,     0,   {-28800, 0 }}},
00662     { "01-01-01    00:00:00",           { 000000,  00, 00, 00,     1,   0, 2001, 1,     0,   {-28800, 0 }}},
00663     { "Saturday 01-01-2001  00:00:00",  { 000000,  00, 00, 00,     1,   0, 2001, 1,     0,   {-28800, 0 }}},
00664 
00665     /* 01-Mar-2001 */
00666     { "01 Mar 2001 00:00:00",           { 000000,  00, 00, 00,     1,   2, 2001, 4,    59,   {-28800, 0 }}},
00667     { "3/1/01      00:00:00",           { 000000,  00, 00, 00,     1,   2, 2001, 4,    59,   {-28800, 0 }}},
00668     { "3/1/2001    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2001, 4,    59,   {-28800, 0 }}},
00669     { "3-1-01      00:00:00",           { 000000,  00, 00, 00,     1,   2, 2001, 4,    59,   {-28800, 0 }}},
00670     { "3-1-2001    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2001, 4,    59,   {-28800, 0 }}},
00671     { "03-01-01    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2001, 4,    59,   {-28800, 0 }}},
00672     { "03-01-2001  00:00:00",           { 000000,  00, 00, 00,     1,   2, 2001, 4,    59,   {-28800, 0 }}},
00673 
00674     /* 29-Feb-2004 */
00675     { "29 Feb 2004 00:00:00",           { 000000,  00, 00, 00,    29,   1, 2004, 0,    59,   {-28800, 0 }}},
00676     { "2/29/04     00:00:00",           { 000000,  00, 00, 00,    29,   1, 2004, 0,    59,   {-28800, 0 }}},
00677     { "2/29/2004   00:00:00",           { 000000,  00, 00, 00,    29,   1, 2004, 0,    59,   {-28800, 0 }}},
00678     { "2-29-04     00:00:00",           { 000000,  00, 00, 00,    29,   1, 2004, 0,    59,   {-28800, 0 }}},
00679     { "2-29-2004   00:00:00",           { 000000,  00, 00, 00,    29,   1, 2004, 0,    59,   {-28800, 0 }}},
00680 
00681     /* 01-Mar-2004 */
00682     { "01 Mar 2004 00:00:00",           { 000000,  00, 00, 00,     1,   2, 2004, 1,    60,   {-28800, 0 }}},
00683     { "3/1/04      00:00:00",           { 000000,  00, 00, 00,     1,   2, 2004, 1,    60,   {-28800, 0 }}},
00684     { "3/1/2004    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2004, 1,    60,   {-28800, 0 }}},
00685     { "3-1-04      00:00:00",           { 000000,  00, 00, 00,     1,   2, 2004, 1,    60,   {-28800, 0 }}},
00686     { "3-1-2004    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2004, 1,    60,   {-28800, 0 }}},
00687     { "03-01-04    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2004, 1,    60,   {-28800, 0 }}},
00688     { "03-01-2004  00:00:00",           { 000000,  00, 00, 00,     1,   2, 2004, 1,    60,   {-28800, 0 }}},
00689 
00690     /* 01-Mar-2005 */
00691     { "01 Mar 2005 00:00:00",           { 000000,  00, 00, 00,     1,   2, 2005, 2,    59,   {-28800, 0 }}},
00692     { "3/1/05      00:00:00",           { 000000,  00, 00, 00,     1,   2, 2005, 2,    59,   {-28800, 0 }}},
00693     { "3/1/2005    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2005, 2,    59,   {-28800, 0 }}},
00694     { "3-1-05      00:00:00",           { 000000,  00, 00, 00,     1,   2, 2005, 2,    59,   {-28800, 0 }}},
00695     { "3-1-2005    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2005, 2,    59,   {-28800, 0 }}},
00696     { "03-01-05    00:00:00",           { 000000,  00, 00, 00,     1,   2, 2005, 2,    59,   {-28800, 0 }}},
00697     { "03-01-2005  00:00:00",           { 000000,  00, 00, 00,     1,   2, 2005, 2,    59,   {-28800, 0 }}},
00698 
00699     /* last element. string must be null */
00700     { NULL }        
00701 }; /* end array of ParseTest */
00702 
00703 /*
00704 ** TestParseTime() -- Test PR_ParseTimeString() for y2k compliance
00705 **
00706 ** TestParseTime() loops thru the array parseArray. For each element in
00707 ** the array, he calls PR_ParseTimeString() with sDate as the conversion
00708 ** argument. The result (ct) is then converted to a PRExplodedTime structure
00709 ** and compared with the exploded time value (parseArray[n].et) in the
00710 ** array element; if equal, the element passes the test.
00711 **
00712 ** The array parseArray[] contains entries that are interesting to the
00713 ** y2k problem.
00714 **
00715 **
00716 */
00717 static PRStatus TestParseTime( void )
00718 {
00719     ParseTest       *ptp = parseArray;
00720     PRTime          ct;
00721     PRExplodedTime  cet;
00722     char            *sp = ptp->sDate;
00723     PRStatus        rc;
00724     PRStatus        rv = PR_SUCCESS;
00725 
00726     while ( sp != NULL)
00727     {
00728         rc = PR_ParseTimeString( sp, PR_FALSE, &ct );
00729         if ( PR_FAILURE == rc )
00730         {
00731             printf("TestParseTime(): PR_ParseTimeString() failed to convert: %s\n", sp );
00732             rv = PR_FAILURE;
00733             failed_already = 1;
00734         }
00735         else
00736         {
00737             PR_ExplodeTime( ct, PR_LocalTimeParameters , &cet );
00738 
00739             if ( !ExplodedTimeIsEqual( &cet, &ptp->et ))
00740             {
00741                 printf("TestParseTime(): Exploded time compare failed: %s\n", sp );
00742                 if ( debug_mode )
00743                 {
00744                     PrintExplodedTime( &cet );
00745                     printf("\n");
00746                     PrintExplodedTime( &ptp->et );
00747                     printf("\n");
00748                 }
00749                 
00750                 rv = PR_FAILURE;
00751                 failed_already = 1;
00752             }
00753         }
00754                 
00755         /* point to next element in array, keep going */
00756         ptp++;
00757         sp = ptp->sDate;
00758     } /* end while() */
00759 
00760     return( rv );
00761 } /* end TestParseTime() */
00762 
00763 int main(int argc, char** argv)
00764 {
00765        /* The command line argument: -d is used to determine if the test is being run
00766        in debug mode. The regress tool requires only one line output:PASS or FAIL.
00767        All of the printfs associated with this test has been handled with a if (debug_mode)
00768        test.
00769        Usage: test_name -d
00770        */
00771        PLOptStatus os;
00772        PLOptState *opt;
00773     
00774     PR_STDIO_INIT();
00775        opt = PL_CreateOptState(argc, argv, "d");
00776        while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
00777     {
00778               if (PL_OPT_BAD == os) continue;
00779         switch (opt->option)
00780         {
00781         case 'd':  /* debug mode */
00782                      debug_mode = PR_TRUE;
00783             break;
00784          default:
00785             break;
00786         }
00787     }
00788        PL_DestroyOptState(opt);
00789 
00790  /* main test */
00791        
00792     PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
00793     lm = PR_NewLogModule("test");
00794 
00795 #ifdef XP_MAC
00796        /* Set up the console */
00797        InitializeSIOUX(true);
00798        debug_mode = PR_TRUE;
00799 #endif
00800 
00801     if ( PR_FAILURE == TestExplodeImplodeTime())
00802     {
00803         PR_LOG( lm, PR_LOG_ERROR,
00804             ("TestExplodeImplodeTime() failed"));
00805     }
00806     else
00807        printf("Test 1: Calendar Time Test passed\n");
00808 
00809     if ( PR_FAILURE == TestNormalizeTime())
00810     {
00811         PR_LOG( lm, PR_LOG_ERROR,
00812             ("TestNormalizeTime() failed"));
00813     }
00814     else
00815        printf("Test 2: Normalize Time Test passed\n");
00816 
00817     if ( PR_FAILURE == TestParseTime())
00818     {
00819         PR_LOG( lm, PR_LOG_ERROR,
00820             ("TestParseTime() failed"));
00821     }
00822     else
00823        printf("Test 3: Parse Time Test passed\n");
00824 
00825 #ifdef XP_MAC
00826        if (1)
00827        {
00828               char dummyChar;
00829               
00830               printf("Press return to exit\n\n");
00831               scanf("%c", &dummyChar);
00832        }
00833 #endif
00834 
00835        if (failed_already) 
00836            return 1;
00837        else 
00838            return 0;
00839 } /* end main() y2k.c */
00840