nsprpub/pr/tests/y2k.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 * file: y2k.c
michael@0 8 * description: Test for y2k compliance for NSPR.
michael@0 9 *
michael@0 10 * Sep 1999. lth. Added "Sun" specified dates to the test data.
michael@0 11 */
michael@0 12 /***********************************************************************
michael@0 13 ** Includes
michael@0 14 ***********************************************************************/
michael@0 15 /* Used to get the command line option */
michael@0 16 #include "plgetopt.h"
michael@0 17
michael@0 18 #include "prinit.h"
michael@0 19 #include "prtime.h"
michael@0 20 #include "prprf.h"
michael@0 21 #include "prlog.h"
michael@0 22
michael@0 23 #include <stdio.h>
michael@0 24 #include <stdlib.h>
michael@0 25 #include <string.h>
michael@0 26
michael@0 27 #define PRINT_DETAILS
michael@0 28
michael@0 29 int failed_already=0;
michael@0 30 PRBool debug_mode = PR_FALSE;
michael@0 31
michael@0 32 static char *dayOfWeek[] =
michael@0 33 { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
michael@0 34 static char *month[] =
michael@0 35 { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
michael@0 36 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???" };
michael@0 37
michael@0 38 PRLogModuleInfo *lm;
michael@0 39
michael@0 40 static void PrintExplodedTime(const PRExplodedTime *et) {
michael@0 41 PRInt32 totalOffset;
michael@0 42 PRInt32 hourOffset, minOffset;
michael@0 43 const char *sign;
michael@0 44
michael@0 45 /* Print day of the week, month, day, hour, minute, and second */
michael@0 46 printf("%s %s %2ld %02ld:%02ld:%02ld ",
michael@0 47 dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
michael@0 48 et->tm_hour, et->tm_min, et->tm_sec);
michael@0 49
michael@0 50 /* Print year */
michael@0 51 printf("%hd ", et->tm_year);
michael@0 52
michael@0 53 /* Print time zone */
michael@0 54 totalOffset = et->tm_params.tp_gmt_offset + et->tm_params.tp_dst_offset;
michael@0 55 if (totalOffset == 0) {
michael@0 56 printf("UTC ");
michael@0 57 } else {
michael@0 58 sign = "+";
michael@0 59 if (totalOffset < 0) {
michael@0 60 totalOffset = -totalOffset;
michael@0 61 sign = "-";
michael@0 62 }
michael@0 63 hourOffset = totalOffset / 3600;
michael@0 64 minOffset = (totalOffset % 3600) / 60;
michael@0 65 printf("%s%02ld%02ld ", sign, hourOffset, minOffset);
michael@0 66 }
michael@0 67 #ifdef PRINT_DETAILS
michael@0 68 printf("{%d, %d, %d, %d, %d, %d, %d, %d, %d, { %d, %d}}\n",et->tm_usec,
michael@0 69 et->tm_sec,
michael@0 70 et->tm_min,
michael@0 71 et->tm_hour,
michael@0 72 et->tm_mday,
michael@0 73 et->tm_month,
michael@0 74 et->tm_year,
michael@0 75 et->tm_wday,
michael@0 76 et->tm_yday,
michael@0 77 et->tm_params.tp_gmt_offset,
michael@0 78 et->tm_params.tp_dst_offset);
michael@0 79 #endif
michael@0 80 }
michael@0 81
michael@0 82 static int ExplodedTimeIsEqual(const PRExplodedTime *et1,
michael@0 83 const PRExplodedTime *et2)
michael@0 84 {
michael@0 85 if (et1->tm_usec == et2->tm_usec &&
michael@0 86 et1->tm_sec == et2->tm_sec &&
michael@0 87 et1->tm_min == et2->tm_min &&
michael@0 88 et1->tm_hour == et2->tm_hour &&
michael@0 89 et1->tm_mday == et2->tm_mday &&
michael@0 90 et1->tm_month == et2->tm_month &&
michael@0 91 et1->tm_year == et2->tm_year &&
michael@0 92 et1->tm_wday == et2->tm_wday &&
michael@0 93 et1->tm_yday == et2->tm_yday &&
michael@0 94 et1->tm_params.tp_gmt_offset == et2->tm_params.tp_gmt_offset &&
michael@0 95 et1->tm_params.tp_dst_offset == et2->tm_params.tp_dst_offset) {
michael@0 96 return 1;
michael@0 97 } else {
michael@0 98 return 0;
michael@0 99 }
michael@0 100 }
michael@0 101
michael@0 102 /*
michael@0 103 * TEST 1: TestExplodeImplodeTime
michael@0 104 * Description:
michael@0 105 * For each given timestamp T (a PRTime value), call PR_ExplodeTime
michael@0 106 * with GMT, US Pacific, and local time parameters. Compare the
michael@0 107 * resulting calendar (exploded) time values with the expected
michael@0 108 * values.
michael@0 109 *
michael@0 110 * Note: the expected local time values depend on the local time
michael@0 111 * zone. The local time values stored in this test are for the US
michael@0 112 * Pacific Time Zone. If you are running this test in a different
michael@0 113 * time zone, you need to modify the values in the localt array.
michael@0 114 * An example is provided below.
michael@0 115 *
michael@0 116 * Call PR_ImplodeTime for each of the exploded values and compare
michael@0 117 * the resulting PRTime values with the original input.
michael@0 118 *
michael@0 119 * This test is run for the values of time T corresponding to the
michael@0 120 * following dates:
michael@0 121 * - 12/31/99 - before 2000
michael@0 122 * - 01/01/00 - after 2000
michael@0 123 * - Leap year - Feb 29, 2000
michael@0 124 * - March 1st, 2001 (after 1 year)
michael@0 125 * - March 1st, 2005 (after second leap year)
michael@0 126 * - 09/09/99 (used by some programs as an end of file marker)
michael@0 127 *
michael@0 128 * Call PR_Now, convert to calendar time using PR_ExplodeTime and
michael@0 129 * manually check the result for correctness. The time should match
michael@0 130 * the system clock.
michael@0 131 *
michael@0 132 * Tested functions: PR_Now, PR_ExplodeTime, PR_ImplodeTime,
michael@0 133 * PR_LocalTimeParameters, PR_GMTParameters.
michael@0 134 */
michael@0 135
michael@0 136 static PRTime prt[] = {
michael@0 137 LL_INIT(220405, 2133125120), /* 946634400000000 */
michael@0 138 LL_INIT(220425, 2633779200), /* 946720800000000 */
michael@0 139 LL_INIT(221612, 2107598848), /* 951818400000000 */
michael@0 140 LL_INIT(228975, 663398400), /* 983440800000000 */
michael@0 141 LL_INIT(258365, 1974568960), /* 1109671200000000 */
michael@0 142 LL_INIT(218132, 1393788928), /* 936871200000000 */
michael@0 143 /* Sun's dates follow */
michael@0 144 LL_INIT( 213062, 4077979648 ), /* Dec 31 1998 10:00:00 */
michael@0 145 LL_INIT( 218152, 1894443008 ), /* Sep 10 1999 10:00:00 */
michael@0 146 LL_INIT( 221592, 1606944768 ), /* Feb 28 2000 10:00:00 */
michael@0 147 LL_INIT( 227768, 688924672 ), /* Dec 31 2000 10:00:00 */
michael@0 148 LL_INIT( 227788, 1189578752 ), /* Jan 1 2001 10:00:00 */
michael@0 149 };
michael@0 150
michael@0 151 static PRExplodedTime gmt[] = {
michael@0 152 { 0, 0, 0, 10, 31, 11, 1999, 5, 364, {0, 0}}, /* 1999/12/31 10:00:00 GMT */
michael@0 153 { 0, 0, 0, 10, 1, 0, 2000, 6, 0, {0, 0}}, /* 2000/01/01 10:00:00 GMT */
michael@0 154 { 0, 0, 0, 10, 29, 1, 2000, 2, 59, {0, 0}}, /* 2000/02/29 10:00:00 GMT */
michael@0 155 { 0, 0, 0, 10, 1, 2, 2001, 4, 59, {0, 0}}, /* 2001/3/1 10:00:00 GMT */
michael@0 156 { 0, 0, 0, 10, 1, 2, 2005, 2, 59, {0, 0}}, /* 2005/3/1 10:00:00 GMT */
michael@0 157 { 0, 0, 0, 10, 9, 8, 1999, 4, 251, {0, 0}}, /* 1999/9/9 10:00:00 GMT */
michael@0 158 /* Sun's dates follow */
michael@0 159 { 0, 0, 0, 10, 31, 11, 1998, 4, 364, {0, 0}}, /* 12/31/1998 10:00:00 GMT */
michael@0 160 { 0, 0, 0, 10, 10, 8, 1999, 5, 252, {0, 0}}, /* 9/10/1999 10:00:00 GMT */
michael@0 161 { 0, 0, 0, 10, 28, 1, 2000, 1, 58, {0, 0}}, /* 2/28/2000 10:00:00 GMT */
michael@0 162 { 0, 0, 0, 10, 31, 11, 2000, 0, 365, {0, 0}}, /* 12/31/2000 10:00:00 GMT */
michael@0 163 { 0, 0, 0, 10, 1, 0, 2001, 1, 0, {0, 0}} /* 1/1/2001 10:00:00 GMT */
michael@0 164 };
michael@0 165
michael@0 166 static PRExplodedTime uspt[] = {
michael@0 167 { 0, 0, 0, 2, 31, 11, 1999, 5, 364, {-28800, 0}}, /* 1999/12/31 2:00:00 PST */
michael@0 168 { 0, 0, 0, 2, 1, 0, 2000, 6, 0, {-28800, 0}}, /* 2000/01/01 2:00:00 PST */
michael@0 169 { 0, 0, 0, 2, 29, 1, 2000, 2, 59, {-28800, 0}}, /* 2000/02/29 2:00:00 PST */
michael@0 170 { 0, 0, 0, 2, 1, 2, 2001, 4, 59, {-28800, 0}}, /* 2001/3/1 2:00:00 PST */
michael@0 171 { 0, 0, 0, 2, 1, 2, 2005, 2, 59, {-28800, 0}}, /* 2005/3/1 2:00:00 PST */
michael@0 172 { 0, 0, 0, 3, 9, 8, 1999, 4, 251, {-28800, 3600}}, /* 1999/9/9 3:00:00 PDT */
michael@0 173 /* Sun's dates follow */
michael@0 174 { 0, 0, 0, 2, 31, 11, 1998, 4, 364, {-28800, 0}}, /* 12/31/1998 00:00:00 GMT */
michael@0 175 { 0, 0, 0, 3, 10, 8, 1999, 5, 252, {-28800, 3600}}, /* 9/10/1999 00:00:00 GMT */
michael@0 176 { 0, 0, 0, 2, 28, 1, 2000, 1, 58, {-28800, 0}}, /* 2/28/2000 00:00:00 GMT */
michael@0 177 { 0, 0, 0, 2, 31, 11, 2000, 0, 365, {-28800, 0}}, /* 12/31/2000 00:00:00 GMT */
michael@0 178 { 0, 0, 0, 2, 1, 0, 2001, 1, 0, {-28800, 0}} /* 1/1/2001 00:00:00 GMT */
michael@0 179 };
michael@0 180
michael@0 181 /*
michael@0 182 * This test assumes that we are in US Pacific Time Zone.
michael@0 183 * If you are running this test in a different time zone,
michael@0 184 * you need to modify the localt array and fill in the
michael@0 185 * expected results. The localt array for US Eastern Time
michael@0 186 * Zone is provided as an example.
michael@0 187 */
michael@0 188 static PRExplodedTime localt[] = {
michael@0 189 { 0, 0, 0, 2, 31, 11, 1999, 5, 364, {-28800, 0}}, /* 1999/12/31 2:00:00 PST */
michael@0 190 { 0, 0, 0, 2, 1, 0, 2000, 6, 0, {-28800, 0}}, /* 2000/01/01 2:00:00 PST */
michael@0 191 { 0, 0, 0, 2, 29, 1, 2000, 2, 59, {-28800, 0}}, /* 2000/02/29 2:00:00 PST */
michael@0 192 { 0, 0, 0, 2, 1, 2, 2001, 4, 59, {-28800, 0}}, /* 2001/3/1 2:00:00 PST */
michael@0 193 { 0, 0, 0, 2, 1, 2, 2005, 2, 59, {-28800, 0}}, /* 2005/3/1 2:00:00 PST */
michael@0 194 { 0, 0, 0, 3, 9, 8, 1999, 4, 251, {-28800, 3600}}, /* 1999/9/9 3:00:00 PDT */
michael@0 195 /* Sun's dates follow */
michael@0 196 { 0, 0, 0, 2, 31, 11, 1998, 4, 364, {-28800, 0}}, /* 12/31/1998 00:00:00 GMT */
michael@0 197 { 0, 0, 0, 3, 10, 8, 1999, 5, 252, {-28800, 3600}}, /* 9/10/1999 00:00:00 GMT */
michael@0 198 { 0, 0, 0, 2, 28, 1, 2000, 1, 58, {-28800, 0}}, /* 2/28/2000 00:00:00 GMT */
michael@0 199 { 0, 0, 0, 2, 31, 11, 2000, 0, 365, {-28800, 0}}, /* 12/31/2000 00:00:00 GMT */
michael@0 200 { 0, 0, 0, 2, 1, 0, 2001, 1, 0, {-28800, 0}} /* 1/1/2001 00:00:00 GMT */
michael@0 201 };
michael@0 202
michael@0 203 #ifdef US_EASTERN_TIME
michael@0 204 static PRExplodedTime localt[] = {
michael@0 205 { 0, 0, 0, 5, 31, 11, 1999, 5, 364, {-18000, 0}}, /* 1999/12/31 2:00:00 EST */
michael@0 206 { 0, 0, 0, 5, 1, 0, 2000, 6, 0, {-18000, 0}}, /* 2000/01/01 2:00:00 EST */
michael@0 207 { 0, 0, 0, 5, 29, 1, 2000, 2, 59, {-18000, 0}}, /* 2000/02/29 2:00:00 EST */
michael@0 208 { 0, 0, 0, 5, 1, 2, 2001, 4, 59, {-18000, 0}}, /* 2001/3/1 2:00:00 EST */
michael@0 209 { 0, 0, 0, 5, 1, 2, 2005, 2, 59, {-18000, 0}}, /* 2005/3/1 2:00:00 EST */
michael@0 210 { 0, 0, 0, 6, 9, 8, 1999, 4, 251, {-18000, 3600}}, /* 1999/9/9 3:00:00 EDT */
michael@0 211 /* Sun's dates follow */
michael@0 212 { 0, 0, 0, 5, 31, 11, 1998, 4, 364, {-18000 0}}, /* 12/31/1998 00:00:00 GMT */
michael@0 213 { 0, 0, 0, 6, 10, 8, 1999, 5, 252, {-18000 3600}}, /* 9/10/1999 00:00:00 GMT */
michael@0 214 { 0, 0, 0, 5, 28, 1, 2000, 1, 58, {-18000 0}}, /* 2/28/2000 00:00:00 GMT */
michael@0 215 { 0, 0, 0, 5, 31, 11, 2000, 0, 365, {-18000 0}}, /* 12/31/2000 00:00:00 GMT */
michael@0 216 { 0, 0, 0, 5, 1, 0, 2001, 1, 0, {-18000 0}} /* 1/1/2001 00:00:00 GMT */
michael@0 217 };
michael@0 218 #endif
michael@0 219
michael@0 220 static PRStatus TestExplodeImplodeTime(void)
michael@0 221 {
michael@0 222 PRTime prt_tmp;
michael@0 223 PRTime now;
michael@0 224 int idx;
michael@0 225 int array_size = sizeof(prt) / sizeof(PRTime);
michael@0 226 PRExplodedTime et_tmp;
michael@0 227 char buf[1024];
michael@0 228
michael@0 229 for (idx = 0; idx < array_size; idx++) {
michael@0 230 PR_snprintf(buf, sizeof(buf), "%lld", prt[idx]);
michael@0 231 if (debug_mode) printf("Time stamp %s\n", buf);
michael@0 232 PR_ExplodeTime(prt[idx], PR_GMTParameters, &et_tmp);
michael@0 233 if (!ExplodedTimeIsEqual(&et_tmp, &gmt[idx])) {
michael@0 234 fprintf(stderr, "GMT not equal\n");
michael@0 235 PrintExplodedTime(&et_tmp);
michael@0 236 PrintExplodedTime(&gmt[idx]);
michael@0 237 exit(1);
michael@0 238 }
michael@0 239 prt_tmp = PR_ImplodeTime(&et_tmp);
michael@0 240 if (LL_NE(prt_tmp, prt[idx])) {
michael@0 241 fprintf(stderr, "PRTime not equal\n");
michael@0 242 exit(1);
michael@0 243 }
michael@0 244 if (debug_mode) {
michael@0 245 printf("GMT: ");
michael@0 246 PrintExplodedTime(&et_tmp);
michael@0 247 printf("\n");
michael@0 248 }
michael@0 249
michael@0 250 PR_ExplodeTime(prt[idx], PR_USPacificTimeParameters, &et_tmp);
michael@0 251 if (!ExplodedTimeIsEqual(&et_tmp, &uspt[idx])) {
michael@0 252 fprintf(stderr, "US Pacific Time not equal\n");
michael@0 253 PrintExplodedTime(&et_tmp);
michael@0 254 PrintExplodedTime(&uspt[idx]);
michael@0 255 exit(1);
michael@0 256 }
michael@0 257 prt_tmp = PR_ImplodeTime(&et_tmp);
michael@0 258 if (LL_NE(prt_tmp, prt[idx])) {
michael@0 259 fprintf(stderr, "PRTime not equal\n");
michael@0 260 exit(1);
michael@0 261 }
michael@0 262 if (debug_mode) {
michael@0 263 printf("US Pacific Time: ");
michael@0 264 PrintExplodedTime(&et_tmp);
michael@0 265 printf("\n");
michael@0 266 }
michael@0 267
michael@0 268 PR_ExplodeTime(prt[idx], PR_LocalTimeParameters, &et_tmp);
michael@0 269 if (!ExplodedTimeIsEqual(&et_tmp, &localt[idx])) {
michael@0 270 fprintf(stderr, "not equal\n");
michael@0 271 PrintExplodedTime(&et_tmp);
michael@0 272 PrintExplodedTime(&localt[idx]);
michael@0 273 exit(1);
michael@0 274 }
michael@0 275 prt_tmp = PR_ImplodeTime(&et_tmp);
michael@0 276 if (LL_NE(prt_tmp, prt[idx])) {
michael@0 277 fprintf(stderr, "not equal\n");
michael@0 278 exit(1);
michael@0 279 }
michael@0 280 if (debug_mode) {
michael@0 281 printf("Local time:");
michael@0 282 PrintExplodedTime(&et_tmp);
michael@0 283 printf("\n\n");
michael@0 284 }
michael@0 285 }
michael@0 286
michael@0 287 now = PR_Now();
michael@0 288 PR_ExplodeTime(now, PR_GMTParameters, &et_tmp);
michael@0 289 printf("Current GMT is ");
michael@0 290 PrintExplodedTime(&et_tmp);
michael@0 291 printf("\n");
michael@0 292 prt_tmp = PR_ImplodeTime(&et_tmp);
michael@0 293 if (LL_NE(prt_tmp, now)) {
michael@0 294 fprintf(stderr, "not equal\n");
michael@0 295 exit(1);
michael@0 296 }
michael@0 297 PR_ExplodeTime(now, PR_USPacificTimeParameters, &et_tmp);
michael@0 298 printf("Current US Pacific Time is ");
michael@0 299 PrintExplodedTime(&et_tmp);
michael@0 300 printf("\n");
michael@0 301 prt_tmp = PR_ImplodeTime(&et_tmp);
michael@0 302 if (LL_NE(prt_tmp, now)) {
michael@0 303 fprintf(stderr, "not equal\n");
michael@0 304 exit(1);
michael@0 305 }
michael@0 306 PR_ExplodeTime(now, PR_LocalTimeParameters, &et_tmp);
michael@0 307 printf("Current local time is ");
michael@0 308 PrintExplodedTime(&et_tmp);
michael@0 309 printf("\n");
michael@0 310 prt_tmp = PR_ImplodeTime(&et_tmp);
michael@0 311 if (LL_NE(prt_tmp, now)) {
michael@0 312 fprintf(stderr, "not equal\n");
michael@0 313 exit(1);
michael@0 314 }
michael@0 315 printf("Please verify the results\n\n");
michael@0 316
michael@0 317 if (debug_mode) printf("Test 1 passed\n");
michael@0 318 return PR_SUCCESS;
michael@0 319 }
michael@0 320 /* End of Test 1: TestExplodeImplodeTime */
michael@0 321
michael@0 322 /*
michael@0 323 * Test 2: Normalize Time
michael@0 324 */
michael@0 325
michael@0 326 /*
michael@0 327 * time increment for addition to PRExplodeTime
michael@0 328 */
michael@0 329 typedef struct time_increment {
michael@0 330 PRInt32 ti_usec;
michael@0 331 PRInt32 ti_sec;
michael@0 332 PRInt32 ti_min;
michael@0 333 PRInt32 ti_hour;
michael@0 334 } time_increment_t;
michael@0 335
michael@0 336 /*
michael@0 337 * Data for testing PR_Normalize
michael@0 338 * Add the increment to base_time, normalize it to GMT and US Pacific
michael@0 339 * Time zone.
michael@0 340 */
michael@0 341 typedef struct normalize_test_data {
michael@0 342 PRExplodedTime base_time;
michael@0 343 time_increment_t increment;
michael@0 344 PRExplodedTime expected_gmt_time;
michael@0 345 PRExplodedTime expected_uspt_time;
michael@0 346 } normalize_test_data_t;
michael@0 347
michael@0 348
michael@0 349 /*
michael@0 350 * Test data - the base time values cover dates of interest including y2k - 1,
michael@0 351 * y2k + 1, y2k leap year, y2k leap date + 1year,
michael@0 352 * y2k leap date + 4 years
michael@0 353 */
michael@0 354 normalize_test_data_t normalize_test_array[] = {
michael@0 355 /*usec sec min hour mday mo year wday yday {gmtoff, dstoff }*/
michael@0 356
michael@0 357 /* Fri 12/31/1999 19:32:48 PST */
michael@0 358 {{0, 48, 32, 19, 31, 11, 1999, 5, 364, { -28800, 0}},
michael@0 359 {0, 0, 30, 20},
michael@0 360 {0, 48, 2, 0, 2, 0, 2000, 0, 1, { 0, 0}}, /*Sun Jan 2 00:02:48 UTC 2000*/
michael@0 361 {0, 48, 2, 16, 1, 0, 2000, 6, 0, { -28800, 0}},/* Sat Jan 1 16:02:48
michael@0 362 PST 2000*/
michael@0 363 },
michael@0 364 /* Fri 99-12-31 23:59:02 GMT */
michael@0 365 {{0, 2, 59, 23, 31, 11, 1999, 5, 364, { 0, 0}},
michael@0 366 {0, 0, 45, 0},
michael@0 367 {0, 2, 44, 0, 1, 0, 2000, 6, 0, { 0, 0}},/* Sat Jan 1 00:44:02 UTC 2000*/
michael@0 368 {0, 2, 44, 16, 31, 11, 1999, 5, 364, { -28800, 0}}/*Fri Dec 31 16:44:02
michael@0 369 PST 1999*/
michael@0 370 },
michael@0 371 /* 99-12-25 12:00:00 GMT */
michael@0 372 {{0, 0, 0, 12, 25, 11, 1999, 6, 358, { 0, 0}},
michael@0 373 {0, 0, 0, 364 * 24},
michael@0 374 {0, 0, 0, 12, 23, 11, 2000, 6, 357, { 0, 0}},/*Sat Dec 23 12:00:00
michael@0 375 2000 UTC*/
michael@0 376 {0, 0, 0, 4, 23, 11, 2000, 6, 357, { -28800, 0}}/*Sat Dec 23 04:00:00
michael@0 377 2000 -0800*/
michael@0 378 },
michael@0 379 /* 00-01-1 00:00:00 PST */
michael@0 380 {{0, 0, 0, 0, 1, 0, 2000, 6, 0, { -28800, 0}},
michael@0 381 {0, 0, 0, 48},
michael@0 382 {0, 0, 0, 8, 3, 0, 2000, 1, 2, { 0, 0}},/*Mon Jan 3 08:00:00 2000 UTC*/
michael@0 383 {0, 0, 0, 0, 3, 0, 2000, 1, 2, { -28800, 0}}/*Mon Jan 3 00:00:00 2000
michael@0 384 -0800*/
michael@0 385 },
michael@0 386 /* 00-01-10 12:00:00 PST */
michael@0 387 {{0, 0, 0, 12, 10, 0, 2000, 1, 9, { -28800, 0}},
michael@0 388 {0, 0, 0, 364 * 5 * 24},
michael@0 389 {0, 0, 0, 20, 3, 0, 2005, 1, 2, { 0, 0}},/*Mon Jan 3 20:00:00 2005 UTC */
michael@0 390 {0, 0, 0, 12, 3, 0, 2005, 1, 2, { -28800, 0}}/*Mon Jan 3 12:00:00
michael@0 391 2005 -0800*/
michael@0 392 },
michael@0 393 /* 00-02-28 15:39 GMT */
michael@0 394 {{0, 0, 39, 15, 28, 1, 2000, 1, 58, { 0, 0}},
michael@0 395 {0, 0, 0, 24},
michael@0 396 {0, 0, 39, 15, 29, 1, 2000, 2, 59, { 0, 0}}, /*Tue Feb 29 15:39:00 2000
michael@0 397 UTC*/
michael@0 398 {0, 0, 39, 7, 29, 1, 2000, 2, 59, { -28800, 0}}/*Tue Feb 29 07:39:00
michael@0 399 2000 -0800*/
michael@0 400 },
michael@0 401 /* 01-03-01 12:00 PST */
michael@0 402 {{0, 0, 0, 12, 3, 0, 2001, 3, 2, { -28800, 0}},/*Wed Jan 3 12:00:00
michael@0 403 -0800 2001*/
michael@0 404 {0, 30, 30,45},
michael@0 405 {0, 30, 30, 17, 5, 0, 2001, 5, 4, { 0, 0}}, /*Fri Jan 5 17:30:30 2001
michael@0 406 UTC*/
michael@0 407 {0, 30, 30, 9, 5, 0, 2001, 5, 4, { -28800, 0}} /*Fri Jan 5 09:30:30
michael@0 408 2001 -0800*/
michael@0 409 },
michael@0 410 /* 2004-04-26 12:00 GMT */
michael@0 411 {{0, 0, 0, 20, 3, 0, 2001, 3, 2, { 0, 0}},
michael@0 412 {0, 0, 30,0},
michael@0 413 {0, 0, 30, 20, 3, 0, 2001, 3, 2, { 0, 0}},/*Wed Jan 3 20:30:00 2001 UTC*/
michael@0 414 {0, 0, 30, 12, 3, 0, 2001, 3, 2, { -28800, 0}}/*Wed Jan 3 12:30:00
michael@0 415 2001 -0800*/
michael@0 416 },
michael@0 417 /* 99-09-09 00:00 GMT */
michael@0 418 {{0, 0, 0, 0, 9, 8, 1999, 4, 251, { 0, 0}},
michael@0 419 {0, 0, 0, 12},
michael@0 420 {0, 0, 0, 12, 9, 8, 1999, 4, 251, { 0, 0}},/*Thu Sep 9 12:00:00 1999 UTC*/
michael@0 421 {0, 0, 0, 5, 9, 8, 1999, 4, 251, { -28800, 3600}}/*Thu Sep 9 05:00:00
michael@0 422 1999 -0700*/
michael@0 423 }
michael@0 424 };
michael@0 425
michael@0 426 void add_time_increment(PRExplodedTime *et1, time_increment_t *it)
michael@0 427 {
michael@0 428 et1->tm_usec += it->ti_usec;
michael@0 429 et1->tm_sec += it->ti_sec;
michael@0 430 et1->tm_min += it->ti_min;
michael@0 431 et1->tm_hour += it->ti_hour;
michael@0 432 }
michael@0 433
michael@0 434 /*
michael@0 435 ** TestNormalizeTime() -- Test PR_NormalizeTime()
michael@0 436 ** For each data item, add the time increment to the base_time and then
michael@0 437 ** normalize it for GMT and local time zones. This test assumes that
michael@0 438 ** the local time zone is the Pacific Time Zone. The normalized values
michael@0 439 ** should match the expected values in the data item.
michael@0 440 **
michael@0 441 */
michael@0 442 PRStatus TestNormalizeTime(void)
michael@0 443 {
michael@0 444 int idx, count;
michael@0 445 normalize_test_data_t *itemp;
michael@0 446 time_increment_t *itp;
michael@0 447
michael@0 448 count = sizeof(normalize_test_array)/sizeof(normalize_test_array[0]);
michael@0 449 for (idx = 0; idx < count; idx++) {
michael@0 450 itemp = &normalize_test_array[idx];
michael@0 451 if (debug_mode) {
michael@0 452 printf("%2d. %15s",idx +1,"Base time: ");
michael@0 453 PrintExplodedTime(&itemp->base_time);
michael@0 454 printf("\n");
michael@0 455 }
michael@0 456 itp = &itemp->increment;
michael@0 457 if (debug_mode) {
michael@0 458 printf("%20s %2d hrs %2d min %3d sec\n","Add",itp->ti_hour,
michael@0 459 itp->ti_min, itp->ti_sec);
michael@0 460 }
michael@0 461 add_time_increment(&itemp->base_time, &itemp->increment);
michael@0 462 PR_NormalizeTime(&itemp->base_time, PR_LocalTimeParameters);
michael@0 463 if (debug_mode) {
michael@0 464 printf("%19s","PST time: ");
michael@0 465 PrintExplodedTime(&itemp->base_time);
michael@0 466 printf("\n");
michael@0 467 }
michael@0 468 if (!ExplodedTimeIsEqual(&itemp->base_time,
michael@0 469 &itemp->expected_uspt_time)) {
michael@0 470 printf("PR_NormalizeTime failed\n");
michael@0 471 if (debug_mode)
michael@0 472 PrintExplodedTime(&itemp->expected_uspt_time);
michael@0 473 return PR_FAILURE;
michael@0 474 }
michael@0 475 PR_NormalizeTime(&itemp->base_time, PR_GMTParameters);
michael@0 476 if (debug_mode) {
michael@0 477 printf("%19s","GMT time: ");
michael@0 478 PrintExplodedTime(&itemp->base_time);
michael@0 479 printf("\n");
michael@0 480 }
michael@0 481
michael@0 482 if (!ExplodedTimeIsEqual(&itemp->base_time,
michael@0 483 &itemp->expected_gmt_time)) {
michael@0 484 printf("PR_NormalizeTime failed\n");
michael@0 485 return PR_FAILURE;
michael@0 486 }
michael@0 487 }
michael@0 488 return PR_SUCCESS;
michael@0 489 }
michael@0 490
michael@0 491
michael@0 492 /*
michael@0 493 ** ParseTest. Structure defining a string time and a matching exploded time
michael@0 494 **
michael@0 495 */
michael@0 496 typedef struct ParseTest
michael@0 497 {
michael@0 498 char *sDate; /* string to be converted using PR_ParseTimeString() */
michael@0 499 PRExplodedTime et; /* expected result of the conversion */
michael@0 500 } ParseTest;
michael@0 501
michael@0 502 static ParseTest parseArray[] =
michael@0 503 {
michael@0 504 /* |<----- expected result ------------------------------------------->| */
michael@0 505 /* "string to test" usec sec min hour day mo year wday julian {gmtoff, dstoff }*/
michael@0 506 { "Thursday 1 Jan 1970 00:00:00", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 507 { "1 Jan 1970 00:00:00", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 508 { "1-Jan-1970 00:00:00", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 509 { "01-Jan-1970 00:00:00", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 510 { "January 1, 1970", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 511 { "January 1, 1970 00:00", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 512 { "January 01, 1970 00:00", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 513 { "January 01 1970 00:00", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 514 { "January 01 1970 00:00:00", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 515 { "01-01-1970", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 516 { "01/01/1970", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 517 { "01/01/70", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 518 { "01/01/70 00:00:00", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 519 { "70/01/01 00:00:00", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 520 { "70/1/1 00:00:", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 521 { "00:00 Thursday, January 1, 1970",{ 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 522 { "1-Jan-70 00:00:00", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 523 { "70-01-01 00:00:00", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 524 { "70/01/01 00:00:00", { 000000, 00, 00, 00, 1, 0, 1970, 4, 0, {-28800, 0 }}},
michael@0 525
michael@0 526 /* 31-Dec-1969 */
michael@0 527 { "Wed 31 Dec 1969 00:00:00", { 000000, 00, 00, 00, 31, 11, 1969, 3, 364, {-28800, 0 }}},
michael@0 528 { "31 Dec 1969 00:00:00", { 000000, 00, 00, 00, 31, 11, 1969, 3, 364, {-28800, 0 }}},
michael@0 529 { "12/31/69 00:00:00", { 000000, 00, 00, 00, 31, 11, 2069, 2, 364, {-28800, 0 }}},
michael@0 530 { "12/31/1969 00:00:00", { 000000, 00, 00, 00, 31, 11, 1969, 3, 364, {-28800, 0 }}},
michael@0 531 { "12-31-69 00:00:00", { 000000, 00, 00, 00, 31, 11, 2069, 2, 364, {-28800, 0 }}},
michael@0 532 { "12-31-1969 00:00:00", { 000000, 00, 00, 00, 31, 11, 1969, 3, 364, {-28800, 0 }}},
michael@0 533 { "69-12-31 00:00:00", { 000000, 00, 00, 00, 31, 11, 2069, 2, 364, {-28800, 0 }}},
michael@0 534 { "69/12/31 00:00:00", { 000000, 00, 00, 00, 31, 11, 2069, 2, 364, {-28800, 0 }}},
michael@0 535
michael@0 536 /* "Sun". 31-Dec-1998 (?) */
michael@0 537 { "Thu 31 Dec 1998 00:00:00", { 00000, 00, 00, 00, 31, 11, 1998, 4, 364, {-28800, 0 }}},
michael@0 538 { "12/31/98 00:00:00", { 00000, 00, 00, 00, 31, 11, 1998, 4, 364, {-28800, 0 }}},
michael@0 539 { "12/31/1998 00:00:00", { 00000, 00, 00, 00, 31, 11, 1998, 4, 364, {-28800, 0 }}},
michael@0 540 { "12-31-98 00:00:00", { 00000, 00, 00, 00, 31, 11, 1998, 4, 364, {-28800, 0 }}},
michael@0 541 { "12-31-1998 00:00:00", { 00000, 00, 00, 00, 31, 11, 1998, 4, 364, {-28800, 0 }}},
michael@0 542 { "98-12-31 00:00:00", { 00000, 00, 00, 00, 31, 11, 1998, 4, 364, {-28800, 0 }}},
michael@0 543 { "98/12/31 00:00:00", { 00000, 00, 00, 00, 31, 11, 1998, 4, 364, {-28800, 0 }}},
michael@0 544
michael@0 545 /* 09-Sep-1999. Interesting because of its use as an eof marker? */
michael@0 546 { "09 Sep 1999 00:00:00", { 000000, 00, 00, 00, 9, 8, 1999, 4, 251, {-28800, 3600 }}},
michael@0 547 { "9/9/99 00:00:00", { 000000, 00, 00, 00, 9, 8, 1999, 4, 251, {-28800, 3600 }}},
michael@0 548 { "9/9/1999 00:00:00", { 000000, 00, 00, 00, 9, 8, 1999, 4, 251, {-28800, 3600 }}},
michael@0 549 { "9-9-99 00:00:00", { 000000, 00, 00, 00, 9, 8, 1999, 4, 251, {-28800, 3600 }}},
michael@0 550 { "9-9-1999 00:00:00", { 000000, 00, 00, 00, 9, 8, 1999, 4, 251, {-28800, 3600 }}},
michael@0 551 { "09-09-99 00:00:00", { 000000, 00, 00, 00, 9, 8, 1999, 4, 251, {-28800, 3600 }}},
michael@0 552 { "09-09-1999 00:00:00", { 000000, 00, 00, 00, 9, 8, 1999, 4, 251, {-28800, 3600 }}},
michael@0 553 { "99-09-09 00:00:00", { 000000, 00, 00, 00, 9, 8, 1999, 4, 251, {-28800, 3600 }}},
michael@0 554
michael@0 555 /* "Sun". 10-Sep-1999. Because Sun said so. */
michael@0 556 { "10 Sep 1999 00:00:00", { 000000, 00, 00, 00, 10, 8, 1999, 5, 252, {-28800, 3600 }}},
michael@0 557 { "9/10/99 00:00:00", { 000000, 00, 00, 00, 10, 8, 1999, 5, 252, {-28800, 3600 }}},
michael@0 558 { "9/10/1999 00:00:00", { 000000, 00, 00, 00, 10, 8, 1999, 5, 252, {-28800, 3600 }}},
michael@0 559 { "9-10-99 00:00:00", { 000000, 00, 00, 00, 10, 8, 1999, 5, 252, {-28800, 3600 }}},
michael@0 560 { "9-10-1999 00:00:00", { 000000, 00, 00, 00, 10, 8, 1999, 5, 252, {-28800, 3600 }}},
michael@0 561 { "09-10-99 00:00:00", { 000000, 00, 00, 00, 10, 8, 1999, 5, 252, {-28800, 3600 }}},
michael@0 562 { "09-10-1999 00:00:00", { 000000, 00, 00, 00, 10, 8, 1999, 5, 252, {-28800, 3600 }}},
michael@0 563 { "99-09-10 00:00:00", { 000000, 00, 00, 00, 10, 8, 1999, 5, 252, {-28800, 3600 }}},
michael@0 564
michael@0 565 /* 31-Dec-1999 */
michael@0 566 { "31 Dec 1999 00:00:00", { 000000, 00, 00, 00, 31, 11, 1999, 5, 364, {-28800, 0 }}},
michael@0 567 { "12/31/99 00:00:00", { 000000, 00, 00, 00, 31, 11, 1999, 5, 364, {-28800, 0 }}},
michael@0 568 { "12/31/1999 00:00:00", { 000000, 00, 00, 00, 31, 11, 1999, 5, 364, {-28800, 0 }}},
michael@0 569 { "12-31-99 00:00:00", { 000000, 00, 00, 00, 31, 11, 1999, 5, 364, {-28800, 0 }}},
michael@0 570 { "12-31-1999 00:00:00", { 000000, 00, 00, 00, 31, 11, 1999, 5, 364, {-28800, 0 }}},
michael@0 571 { "99-12-31 00:00:00", { 000000, 00, 00, 00, 31, 11, 1999, 5, 364, {-28800, 0 }}},
michael@0 572 { "99/12/31 00:00:00", { 000000, 00, 00, 00, 31, 11, 1999, 5, 364, {-28800, 0 }}},
michael@0 573
michael@0 574 /* 01-Jan-2000 */
michael@0 575 { "01 Jan 2000 00:00:00", { 000000, 00, 00, 00, 1, 0, 2000, 6, 0, {-28800, 0 }}},
michael@0 576 { "1/1/00 00:00:00", { 000000, 00, 00, 00, 1, 0, 2000, 6, 0, {-28800, 0 }}},
michael@0 577 { "1/1/2000 00:00:00", { 000000, 00, 00, 00, 1, 0, 2000, 6, 0, {-28800, 0 }}},
michael@0 578 { "1-1-00 00:00:00", { 000000, 00, 00, 00, 1, 0, 2000, 6, 0, {-28800, 0 }}},
michael@0 579 { "1-1-2000 00:00:00", { 000000, 00, 00, 00, 1, 0, 2000, 6, 0, {-28800, 0 }}},
michael@0 580 { "01-01-00 00:00:00", { 000000, 00, 00, 00, 1, 0, 2000, 6, 0, {-28800, 0 }}},
michael@0 581 { "Saturday 01-01-2000 00:00:00", { 000000, 00, 00, 00, 1, 0, 2000, 6, 0, {-28800, 0 }}},
michael@0 582
michael@0 583 /* "Sun". 28-Feb-2000 */
michael@0 584 { "28 Feb 2000 00:00:00", { 000000, 00, 00, 00, 28, 1, 2000, 1, 58, {-28800, 0 }}},
michael@0 585 { "2/28/00 00:00:00", { 000000, 00, 00, 00, 28, 1, 2000, 1, 58, {-28800, 0 }}},
michael@0 586 { "2/28/2000 00:00:00", { 000000, 00, 00, 00, 28, 1, 2000, 1, 58, {-28800, 0 }}},
michael@0 587 { "2-28-00 00:00:00", { 000000, 00, 00, 00, 28, 1, 2000, 1, 58, {-28800, 0 }}},
michael@0 588 { "2-28-2000 00:00:00", { 000000, 00, 00, 00, 28, 1, 2000, 1, 58, {-28800, 0 }}},
michael@0 589 { "02-28-00 00:00:00", { 000000, 00, 00, 00, 28, 1, 2000, 1, 58, {-28800, 0 }}},
michael@0 590 { "02-28-2000 00:00:00", { 000000, 00, 00, 00, 28, 1, 2000, 1, 58, {-28800, 0 }}},
michael@0 591
michael@0 592 /* 29-Feb-2000 */
michael@0 593 { "29 Feb 2000 00:00:00", { 000000, 00, 00, 00, 29, 1, 2000, 2, 59, {-28800, 0 }}},
michael@0 594 { "2/29/00 00:00:00", { 000000, 00, 00, 00, 29, 1, 2000, 2, 59, {-28800, 0 }}},
michael@0 595 { "2/29/2000 00:00:00", { 000000, 00, 00, 00, 29, 1, 2000, 2, 59, {-28800, 0 }}},
michael@0 596 { "2-29-00 00:00:00", { 000000, 00, 00, 00, 29, 1, 2000, 2, 59, {-28800, 0 }}},
michael@0 597 { "2-29-2000 00:00:00", { 000000, 00, 00, 00, 29, 1, 2000, 2, 59, {-28800, 0 }}},
michael@0 598 { "02-29-00 00:00:00", { 000000, 00, 00, 00, 29, 1, 2000, 2, 59, {-28800, 0 }}},
michael@0 599 { "02-29-2000 00:00:00", { 000000, 00, 00, 00, 29, 1, 2000, 2, 59, {-28800, 0 }}},
michael@0 600
michael@0 601 /* 01-Mar-2000 */
michael@0 602 { "01 Mar 2000 00:00:00", { 000000, 00, 00, 00, 1, 2, 2000, 3, 60, {-28800, 0 }}},
michael@0 603 { "3/1/00 00:00:00", { 000000, 00, 00, 00, 1, 2, 2000, 3, 60, {-28800, 0 }}},
michael@0 604 { "3/1/2000 00:00:00", { 000000, 00, 00, 00, 1, 2, 2000, 3, 60, {-28800, 0 }}},
michael@0 605 { "3-1-00 00:00:00", { 000000, 00, 00, 00, 1, 2, 2000, 3, 60, {-28800, 0 }}},
michael@0 606 { "03-01-00 00:00:00", { 000000, 00, 00, 00, 1, 2, 2000, 3, 60, {-28800, 0 }}},
michael@0 607 { "03-01-2000 00:00:00", { 000000, 00, 00, 00, 1, 2, 2000, 3, 60, {-28800, 0 }}},
michael@0 608
michael@0 609 /* "Sun". 31-Dec-2000 */
michael@0 610 { "31 Dec 2000 00:00:00", { 000000, 00, 00, 00, 31, 11, 2000, 0, 365, {-28800, 0 }}},
michael@0 611 { "12/31/00 00:00:00", { 000000, 00, 00, 00, 31, 11, 2000, 0, 365, {-28800, 0 }}},
michael@0 612 { "12/31/2000 00:00:00", { 000000, 00, 00, 00, 31, 11, 2000, 0, 365, {-28800, 0 }}},
michael@0 613 { "12-31-00 00:00:00", { 000000, 00, 00, 00, 31, 11, 2000, 0, 365, {-28800, 0 }}},
michael@0 614 { "12-31-2000 00:00:00", { 000000, 00, 00, 00, 31, 11, 2000, 0, 365, {-28800, 0 }}},
michael@0 615 { "00-12-31 00:00:00", { 000000, 00, 00, 00, 31, 11, 2000, 0, 365, {-28800, 0 }}},
michael@0 616 { "00/12/31 00:00:00", { 000000, 00, 00, 00, 31, 11, 2000, 0, 365, {-28800, 0 }}},
michael@0 617
michael@0 618 /* "Sun". 01-Jan-2001 */
michael@0 619 { "01 Jan 2001 00:00:00", { 000000, 00, 00, 00, 1, 0, 2001, 1, 0, {-28800, 0 }}},
michael@0 620 { "1/1/01 00:00:00", { 000000, 00, 00, 00, 1, 0, 2001, 1, 0, {-28800, 0 }}},
michael@0 621 { "1/1/2001 00:00:00", { 000000, 00, 00, 00, 1, 0, 2001, 1, 0, {-28800, 0 }}},
michael@0 622 { "1-1-01 00:00:00", { 000000, 00, 00, 00, 1, 0, 2001, 1, 0, {-28800, 0 }}},
michael@0 623 { "1-1-2001 00:00:00", { 000000, 00, 00, 00, 1, 0, 2001, 1, 0, {-28800, 0 }}},
michael@0 624 { "01-01-01 00:00:00", { 000000, 00, 00, 00, 1, 0, 2001, 1, 0, {-28800, 0 }}},
michael@0 625 { "Saturday 01-01-2001 00:00:00", { 000000, 00, 00, 00, 1, 0, 2001, 1, 0, {-28800, 0 }}},
michael@0 626
michael@0 627 /* 01-Mar-2001 */
michael@0 628 { "01 Mar 2001 00:00:00", { 000000, 00, 00, 00, 1, 2, 2001, 4, 59, {-28800, 0 }}},
michael@0 629 { "3/1/01 00:00:00", { 000000, 00, 00, 00, 1, 2, 2001, 4, 59, {-28800, 0 }}},
michael@0 630 { "3/1/2001 00:00:00", { 000000, 00, 00, 00, 1, 2, 2001, 4, 59, {-28800, 0 }}},
michael@0 631 { "3-1-01 00:00:00", { 000000, 00, 00, 00, 1, 2, 2001, 4, 59, {-28800, 0 }}},
michael@0 632 { "3-1-2001 00:00:00", { 000000, 00, 00, 00, 1, 2, 2001, 4, 59, {-28800, 0 }}},
michael@0 633 { "03-01-01 00:00:00", { 000000, 00, 00, 00, 1, 2, 2001, 4, 59, {-28800, 0 }}},
michael@0 634 { "03-01-2001 00:00:00", { 000000, 00, 00, 00, 1, 2, 2001, 4, 59, {-28800, 0 }}},
michael@0 635
michael@0 636 /* 29-Feb-2004 */
michael@0 637 { "29 Feb 2004 00:00:00", { 000000, 00, 00, 00, 29, 1, 2004, 0, 59, {-28800, 0 }}},
michael@0 638 { "2/29/04 00:00:00", { 000000, 00, 00, 00, 29, 1, 2004, 0, 59, {-28800, 0 }}},
michael@0 639 { "2/29/2004 00:00:00", { 000000, 00, 00, 00, 29, 1, 2004, 0, 59, {-28800, 0 }}},
michael@0 640 { "2-29-04 00:00:00", { 000000, 00, 00, 00, 29, 1, 2004, 0, 59, {-28800, 0 }}},
michael@0 641 { "2-29-2004 00:00:00", { 000000, 00, 00, 00, 29, 1, 2004, 0, 59, {-28800, 0 }}},
michael@0 642
michael@0 643 /* 01-Mar-2004 */
michael@0 644 { "01 Mar 2004 00:00:00", { 000000, 00, 00, 00, 1, 2, 2004, 1, 60, {-28800, 0 }}},
michael@0 645 { "3/1/04 00:00:00", { 000000, 00, 00, 00, 1, 2, 2004, 1, 60, {-28800, 0 }}},
michael@0 646 { "3/1/2004 00:00:00", { 000000, 00, 00, 00, 1, 2, 2004, 1, 60, {-28800, 0 }}},
michael@0 647 { "3-1-04 00:00:00", { 000000, 00, 00, 00, 1, 2, 2004, 1, 60, {-28800, 0 }}},
michael@0 648 { "3-1-2004 00:00:00", { 000000, 00, 00, 00, 1, 2, 2004, 1, 60, {-28800, 0 }}},
michael@0 649 { "03-01-04 00:00:00", { 000000, 00, 00, 00, 1, 2, 2004, 1, 60, {-28800, 0 }}},
michael@0 650 { "03-01-2004 00:00:00", { 000000, 00, 00, 00, 1, 2, 2004, 1, 60, {-28800, 0 }}},
michael@0 651
michael@0 652 /* 01-Mar-2005 */
michael@0 653 { "01 Mar 2005 00:00:00", { 000000, 00, 00, 00, 1, 2, 2005, 2, 59, {-28800, 0 }}},
michael@0 654 { "3/1/05 00:00:00", { 000000, 00, 00, 00, 1, 2, 2005, 2, 59, {-28800, 0 }}},
michael@0 655 { "3/1/2005 00:00:00", { 000000, 00, 00, 00, 1, 2, 2005, 2, 59, {-28800, 0 }}},
michael@0 656 { "3-1-05 00:00:00", { 000000, 00, 00, 00, 1, 2, 2005, 2, 59, {-28800, 0 }}},
michael@0 657 { "3-1-2005 00:00:00", { 000000, 00, 00, 00, 1, 2, 2005, 2, 59, {-28800, 0 }}},
michael@0 658 { "03-01-05 00:00:00", { 000000, 00, 00, 00, 1, 2, 2005, 2, 59, {-28800, 0 }}},
michael@0 659 { "03-01-2005 00:00:00", { 000000, 00, 00, 00, 1, 2, 2005, 2, 59, {-28800, 0 }}},
michael@0 660
michael@0 661 /* last element. string must be null */
michael@0 662 { NULL }
michael@0 663 }; /* end array of ParseTest */
michael@0 664
michael@0 665 /*
michael@0 666 ** TestParseTime() -- Test PR_ParseTimeString() for y2k compliance
michael@0 667 **
michael@0 668 ** TestParseTime() loops thru the array parseArray. For each element in
michael@0 669 ** the array, he calls PR_ParseTimeString() with sDate as the conversion
michael@0 670 ** argument. The result (ct) is then converted to a PRExplodedTime structure
michael@0 671 ** and compared with the exploded time value (parseArray[n].et) in the
michael@0 672 ** array element; if equal, the element passes the test.
michael@0 673 **
michael@0 674 ** The array parseArray[] contains entries that are interesting to the
michael@0 675 ** y2k problem.
michael@0 676 **
michael@0 677 **
michael@0 678 */
michael@0 679 static PRStatus TestParseTime( void )
michael@0 680 {
michael@0 681 ParseTest *ptp = parseArray;
michael@0 682 PRTime ct;
michael@0 683 PRExplodedTime cet;
michael@0 684 char *sp = ptp->sDate;
michael@0 685 PRStatus rc;
michael@0 686 PRStatus rv = PR_SUCCESS;
michael@0 687
michael@0 688 while ( sp != NULL)
michael@0 689 {
michael@0 690 rc = PR_ParseTimeString( sp, PR_FALSE, &ct );
michael@0 691 if ( PR_FAILURE == rc )
michael@0 692 {
michael@0 693 printf("TestParseTime(): PR_ParseTimeString() failed to convert: %s\n", sp );
michael@0 694 rv = PR_FAILURE;
michael@0 695 failed_already = 1;
michael@0 696 }
michael@0 697 else
michael@0 698 {
michael@0 699 PR_ExplodeTime( ct, PR_LocalTimeParameters , &cet );
michael@0 700
michael@0 701 if ( !ExplodedTimeIsEqual( &cet, &ptp->et ))
michael@0 702 {
michael@0 703 printf("TestParseTime(): Exploded time compare failed: %s\n", sp );
michael@0 704 if ( debug_mode )
michael@0 705 {
michael@0 706 PrintExplodedTime( &cet );
michael@0 707 printf("\n");
michael@0 708 PrintExplodedTime( &ptp->et );
michael@0 709 printf("\n");
michael@0 710 }
michael@0 711
michael@0 712 rv = PR_FAILURE;
michael@0 713 failed_already = 1;
michael@0 714 }
michael@0 715 }
michael@0 716
michael@0 717 /* point to next element in array, keep going */
michael@0 718 ptp++;
michael@0 719 sp = ptp->sDate;
michael@0 720 } /* end while() */
michael@0 721
michael@0 722 return( rv );
michael@0 723 } /* end TestParseTime() */
michael@0 724
michael@0 725 int main(int argc, char** argv)
michael@0 726 {
michael@0 727 /* The command line argument: -d is used to determine if the test is being run
michael@0 728 in debug mode. The regress tool requires only one line output:PASS or FAIL.
michael@0 729 All of the printfs associated with this test has been handled with a if (debug_mode)
michael@0 730 test.
michael@0 731 Usage: test_name -d
michael@0 732 */
michael@0 733 PLOptStatus os;
michael@0 734 PLOptState *opt;
michael@0 735
michael@0 736 PR_STDIO_INIT();
michael@0 737 opt = PL_CreateOptState(argc, argv, "d");
michael@0 738 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
michael@0 739 {
michael@0 740 if (PL_OPT_BAD == os) continue;
michael@0 741 switch (opt->option)
michael@0 742 {
michael@0 743 case 'd': /* debug mode */
michael@0 744 debug_mode = PR_TRUE;
michael@0 745 break;
michael@0 746 default:
michael@0 747 break;
michael@0 748 }
michael@0 749 }
michael@0 750 PL_DestroyOptState(opt);
michael@0 751
michael@0 752 /* main test */
michael@0 753
michael@0 754 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
michael@0 755 lm = PR_NewLogModule("test");
michael@0 756
michael@0 757 if ( PR_FAILURE == TestExplodeImplodeTime())
michael@0 758 {
michael@0 759 PR_LOG( lm, PR_LOG_ERROR,
michael@0 760 ("TestExplodeImplodeTime() failed"));
michael@0 761 }
michael@0 762 else
michael@0 763 printf("Test 1: Calendar Time Test passed\n");
michael@0 764
michael@0 765 if ( PR_FAILURE == TestNormalizeTime())
michael@0 766 {
michael@0 767 PR_LOG( lm, PR_LOG_ERROR,
michael@0 768 ("TestNormalizeTime() failed"));
michael@0 769 }
michael@0 770 else
michael@0 771 printf("Test 2: Normalize Time Test passed\n");
michael@0 772
michael@0 773 if ( PR_FAILURE == TestParseTime())
michael@0 774 {
michael@0 775 PR_LOG( lm, PR_LOG_ERROR,
michael@0 776 ("TestParseTime() failed"));
michael@0 777 }
michael@0 778 else
michael@0 779 printf("Test 3: Parse Time Test passed\n");
michael@0 780
michael@0 781 if (failed_already)
michael@0 782 return 1;
michael@0 783 else
michael@0 784 return 0;
michael@0 785 } /* end main() y2k.c */
michael@0 786

mercurial