VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/tests/timetest.c@ 55761

最後變更 在這個檔案從55761是 1,由 vboxsync 提交於 55 年 前

import

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 22.7 KB
 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/*
39 * file: timetest.c
40 * description: test time and date routines
41 */
42/***********************************************************************
43** Includes
44***********************************************************************/
45/* Used to get the command line option */
46#include "plgetopt.h"
47
48#include "prinit.h"
49#include "prtime.h"
50#include "prprf.h"
51
52#include <stdio.h>
53#include <stdlib.h>
54#include <string.h>
55
56#ifdef XP_MAC
57#include "prlog.h"
58#include "macstdlibextras.h"
59extern void SetupMacPrintfLog(char *logFile);
60#endif
61
62int failed_already=0;
63PRBool debug_mode = PR_FALSE;
64
65static char *dayOfWeek[] =
66 { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
67static char *month[] =
68 { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
69 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???" };
70
71static void PrintExplodedTime(const PRExplodedTime *et) {
72 PRInt32 totalOffset;
73 PRInt32 hourOffset, minOffset;
74 const char *sign;
75
76 /* Print day of the week, month, day, hour, minute, and second */
77 if (debug_mode) printf("%s %s %ld %02ld:%02ld:%02ld ",
78 dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
79 et->tm_hour, et->tm_min, et->tm_sec);
80
81 /* Print time zone */
82 totalOffset = et->tm_params.tp_gmt_offset + et->tm_params.tp_dst_offset;
83 if (totalOffset == 0) {
84 if (debug_mode) printf("UTC ");
85 } else {
86 sign = "+";
87 if (totalOffset < 0) {
88 totalOffset = -totalOffset;
89 sign = "-";
90 }
91 hourOffset = totalOffset / 3600;
92 minOffset = (totalOffset % 3600) / 60;
93 if (debug_mode)
94 printf("%s%02ld%02ld ", sign, hourOffset, minOffset);
95 }
96
97 /* Print year */
98 if (debug_mode) printf("%hd", et->tm_year);
99}
100
101static int ExplodedTimeIsEqual(const PRExplodedTime *et1,
102 const PRExplodedTime *et2)
103{
104 if (et1->tm_usec == et2->tm_usec &&
105 et1->tm_sec == et2->tm_sec &&
106 et1->tm_min == et2->tm_min &&
107 et1->tm_hour == et2->tm_hour &&
108 et1->tm_mday == et2->tm_mday &&
109 et1->tm_month == et2->tm_month &&
110 et1->tm_year == et2->tm_year &&
111 et1->tm_wday == et2->tm_wday &&
112 et1->tm_yday == et2->tm_yday &&
113 et1->tm_params.tp_gmt_offset == et2->tm_params.tp_gmt_offset &&
114 et1->tm_params.tp_dst_offset == et2->tm_params.tp_dst_offset) {
115 return 1;
116 } else {
117 return 0;
118 }
119}
120
121static void
122testParseTimeString(PRTime t)
123{
124 PRExplodedTime et;
125 PRTime t2;
126 char timeString[128];
127 char buf[128];
128 PRInt32 totalOffset;
129 PRInt32 hourOffset, minOffset;
130 const char *sign;
131 PRInt64 usec_per_sec;
132
133 /* Truncate the microsecond part of PRTime */
134 LL_I2L(usec_per_sec, PR_USEC_PER_SEC);
135 LL_DIV(t, t, usec_per_sec);
136 LL_MUL(t, t, usec_per_sec);
137
138 PR_ExplodeTime(t, PR_LocalTimeParameters, &et);
139
140 /* Print day of the week, month, day, hour, minute, and second */
141 PR_snprintf(timeString, 128, "%s %s %ld %02ld:%02ld:%02ld ",
142 dayOfWeek[et.tm_wday], month[et.tm_month], et.tm_mday,
143 et.tm_hour, et.tm_min, et.tm_sec);
144 /* Print time zone */
145 totalOffset = et.tm_params.tp_gmt_offset + et.tm_params.tp_dst_offset;
146 if (totalOffset == 0) {
147 strcat(timeString, "GMT "); /* I wanted to use "UTC" here, but
148 * PR_ParseTimeString doesn't
149 * understand "UTC". */
150 } else {
151 sign = "+";
152 if (totalOffset < 0) {
153 totalOffset = -totalOffset;
154 sign = "-";
155 }
156 hourOffset = totalOffset / 3600;
157 minOffset = (totalOffset % 3600) / 60;
158 PR_snprintf(buf, 128, "%s%02ld%02ld ", sign, hourOffset, minOffset);
159 strcat(timeString, buf);
160 }
161 /* Print year */
162 PR_snprintf(buf, 128, "%hd", et.tm_year);
163 strcat(timeString, buf);
164
165 if (PR_ParseTimeString(timeString, PR_FALSE, &t2) == PR_FAILURE) {
166 fprintf(stderr, "PR_ParseTimeString() failed\n");
167 exit(1);
168 }
169 if (LL_NE(t, t2)) {
170 fprintf(stderr, "PR_ParseTimeString() incorrect\n");
171 PR_snprintf(buf, 128, "t is %lld, t2 is %lld, time string is %s\n",
172 t, t2, timeString);
173 fprintf(stderr, "%s\n", buf);
174 exit(1);
175 }
176}
177
178int main(int argc, char** argv)
179{
180 /* The command line argument: -d is used to determine if the test is being run
181 in debug mode. The regress tool requires only one line output:PASS or FAIL.
182 All of the printfs associated with this test has been handled with a if (debug_mode)
183 test.
184 Usage: test_name -d
185 */
186 PLOptStatus os;
187 PLOptState *opt;
188
189 PR_STDIO_INIT();
190 opt = PL_CreateOptState(argc, argv, "d");
191 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
192 {
193 if (PL_OPT_BAD == os) continue;
194 switch (opt->option)
195 {
196 case 'd': /* debug mode */
197 debug_mode = PR_TRUE;
198 break;
199 default:
200 break;
201 }
202 }
203 PL_DestroyOptState(opt);
204
205 /* main test */
206
207 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
208
209#ifdef XP_MAC
210 /* Set up the console */
211 InitializeSIOUX(true);
212 debug_mode = PR_TRUE;
213#endif
214 /* Testing zero PRTime (the epoch) */
215 {
216 PRTime t;
217 PRExplodedTime et;
218
219 LL_I2L(t, 0);
220 if (debug_mode) printf("The NSPR epoch is:\n");
221 PR_ExplodeTime(t, PR_LocalTimeParameters, &et);
222 PrintExplodedTime(&et);
223 if (debug_mode) printf("\n");
224 PR_ExplodeTime(t, PR_GMTParameters, &et);
225 PrintExplodedTime(&et);
226 if (debug_mode) printf("\n\n");
227 testParseTimeString(t);
228 }
229
230 /*
231 *************************************************************
232 **
233 ** Testing PR_Now(), PR_ExplodeTime, and PR_ImplodeTime
234 ** on the current time
235 **
236 *************************************************************
237 */
238
239 {
240 PRTime t1, t2;
241 PRExplodedTime et;
242
243 if (debug_mode) {
244 printf("*********************************************\n");
245 printf("** **\n");
246 printf("** Testing PR_Now(), PR_ExplodeTime, and **\n");
247 printf("** PR_ImplodeTime on the current time **\n");
248 printf("** **\n");
249 printf("*********************************************\n\n");
250 }
251 t1 = PR_Now();
252
253 /* First try converting to UTC */
254
255 PR_ExplodeTime(t1, PR_GMTParameters, &et);
256 if (et.tm_params.tp_gmt_offset || et.tm_params.tp_dst_offset) {
257 if (debug_mode) printf("ERROR: UTC has nonzero gmt or dst offset.\n");
258 else failed_already=1;
259 return 1;
260 }
261 if (debug_mode) printf("Current UTC is ");
262 PrintExplodedTime(&et);
263 if (debug_mode) printf("\n");
264
265 t2 = PR_ImplodeTime(&et);
266 if (LL_NE(t1, t2)) {
267 if (debug_mode) printf("ERROR: Explode and implode are NOT inverse.\n");
268 else printf("FAIL\n");
269 return 1;
270 }
271
272 /* Next, try converting to local (US Pacific) time */
273
274 PR_ExplodeTime(t1, PR_LocalTimeParameters, &et);
275 if (debug_mode) printf("Current local time is ");
276 PrintExplodedTime(&et);
277 if (debug_mode) printf("\n");
278 if (debug_mode) printf("GMT offset is %ld, DST offset is %ld\n",
279 et.tm_params.tp_gmt_offset, et.tm_params.tp_dst_offset);
280 t2 = PR_ImplodeTime(&et);
281 if (LL_NE(t1, t2)) {
282 if (debug_mode) printf("ERROR: Explode and implode are NOT inverse.\n");
283 return 1;
284 }
285
286 if (debug_mode) printf("Please examine the results\n");
287 testParseTimeString(t1);
288 }
289
290
291 /*
292 *******************************************
293 **
294 ** Testing PR_NormalizeTime()
295 **
296 *******************************************
297 */
298
299 /* July 4, 2001 is Wednesday */
300 {
301 PRExplodedTime et;
302
303 if (debug_mode) {
304 printf("\n");
305 printf("**********************************\n");
306 printf("** **\n");
307 printf("** Testing PR_NormalizeTime() **\n");
308 printf("** **\n");
309 printf("**********************************\n\n");
310 }
311 et.tm_year = 2001;
312 et.tm_month = 7 - 1;
313 et.tm_mday = 4;
314 et.tm_hour = 0;
315 et.tm_min = 0;
316 et.tm_sec = 0;
317 et.tm_usec = 0;
318 et.tm_params = PR_GMTParameters(&et);
319
320 PR_NormalizeTime(&et, PR_GMTParameters);
321
322 if (debug_mode) printf("July 4, 2001 is %s.\n", dayOfWeek[et.tm_wday]);
323 if (et.tm_wday == 3) {
324 if (debug_mode) printf("PASS\n");
325 } else {
326 if (debug_mode) printf("ERROR: It should be Wednesday\n");
327 else failed_already=1;
328 return 1;
329 }
330 testParseTimeString(PR_ImplodeTime(&et));
331
332 /* June 12, 1997 23:00 PST == June 13, 1997 00:00 PDT */
333 et.tm_year = 1997;
334 et.tm_month = 6 - 1;
335 et.tm_mday = 12;
336 et.tm_hour = 23;
337 et.tm_min = 0;
338 et.tm_sec = 0;
339 et.tm_usec = 0;
340 et.tm_params.tp_gmt_offset = -8 * 3600;
341 et.tm_params.tp_dst_offset = 0;
342
343 PR_NormalizeTime(&et, PR_USPacificTimeParameters);
344
345 if (debug_mode) {
346 printf("Thu Jun 12, 1997 23:00:00 PST is ");
347 }
348 PrintExplodedTime(&et);
349 if (debug_mode) printf(".\n");
350 if (et.tm_wday == 5) {
351 if (debug_mode) printf("PASS\n");
352 } else {
353 if (debug_mode) printf("ERROR: It should be Friday\n");
354 else failed_already=1;
355 return 1;
356 }
357 testParseTimeString(PR_ImplodeTime(&et));
358
359 /* Feb 14, 1997 00:00:00 PDT == Feb 13, 1997 23:00:00 PST */
360 et.tm_year = 1997;
361 et.tm_month = 2 - 1;
362 et.tm_mday = 14;
363 et.tm_hour = 0;
364 et.tm_min = 0;
365 et.tm_sec = 0;
366 et.tm_usec = 0;
367 et.tm_params.tp_gmt_offset = -8 * 3600;
368 et.tm_params.tp_dst_offset = 3600;
369
370 PR_NormalizeTime(&et, PR_USPacificTimeParameters);
371
372 if (debug_mode) {
373 printf("Fri Feb 14, 1997 00:00:00 PDT is ");
374 }
375 PrintExplodedTime(&et);
376 if (debug_mode) printf(".\n");
377 if (et.tm_wday == 4) {
378 if (debug_mode) printf("PASS\n");
379 } else {
380 if (debug_mode) printf("ERROR: It should be Thursday\n");
381 else failed_already=1;
382 return 1;
383 }
384 testParseTimeString(PR_ImplodeTime(&et));
385
386 /* What time is Nov. 7, 1996, 18:29:23 PDT? */
387 et.tm_year = 1996;
388 et.tm_month = 11 - 1;
389 et.tm_mday = 7;
390 et.tm_hour = 18;
391 et.tm_min = 29;
392 et.tm_sec = 23;
393 et.tm_usec = 0;
394 et.tm_params.tp_gmt_offset = -8 * 3600; /* PDT */
395 et.tm_params.tp_dst_offset = 3600;
396
397 PR_NormalizeTime(&et, PR_LocalTimeParameters);
398 if (debug_mode) printf("Nov 7 18:29:23 PDT 1996 is ");
399 PrintExplodedTime(&et);
400 if (debug_mode) printf(".\n");
401 testParseTimeString(PR_ImplodeTime(&et));
402
403 /* What time is Oct. 7, 1995, 18:29:23 PST? */
404 et.tm_year = 1995;
405 et.tm_month = 10 - 1;
406 et.tm_mday = 7;
407 et.tm_hour = 18;
408 et.tm_min = 29;
409 et.tm_sec = 23;
410 et.tm_params.tp_gmt_offset = -8 * 3600; /* PST */
411 et.tm_params.tp_dst_offset = 0;
412
413 PR_NormalizeTime(&et, PR_LocalTimeParameters);
414 if (debug_mode) printf("Oct 7 18:29:23 PST 1995 is ");
415 PrintExplodedTime(&et);
416 if (debug_mode) printf(".\n");
417 testParseTimeString(PR_ImplodeTime(&et));
418
419 if (debug_mode) printf("Please examine the results\n");
420 }
421
422 /*
423 **************************************************************
424 **
425 ** Testing range of years
426 **
427 **************************************************************
428 */
429
430 {
431 PRExplodedTime et1, et2;
432 PRTime ttt;
433 PRTime secs;
434
435 if (debug_mode) {
436 printf("\n");
437 printf("***************************************\n");
438 printf("** **\n");
439 printf("** Testing range of years **\n");
440 printf("** **\n");
441 printf("***************************************\n\n");
442 }
443 /* April 4, 1917 GMT */
444 et1.tm_usec = 0;
445 et1.tm_sec = 0;
446 et1.tm_min = 0;
447 et1.tm_hour = 0;
448 et1.tm_mday = 4;
449 et1.tm_month = 4 - 1;
450 et1.tm_year = 1917;
451 et1.tm_params = PR_GMTParameters(&et1);
452 PR_NormalizeTime(&et1, PR_LocalTimeParameters);
453 secs = PR_ImplodeTime(&et1);
454 if (LL_GE_ZERO(secs)) {
455 if (debug_mode)
456 printf("ERROR: April 4, 1917 GMT returns a nonnegative second count\n");
457 failed_already = 1;
458 return 1;
459 }
460 PR_ExplodeTime(secs, PR_LocalTimeParameters, &et2);
461 if (!ExplodedTimeIsEqual(&et1, &et2)) {
462 if (debug_mode)
463 printf("ERROR: PR_ImplodeTime and PR_ExplodeTime are not inverse for April 4, 1917 GMT\n");
464 failed_already=1;
465 return 1;
466 }
467 ttt = PR_ImplodeTime(&et1);
468 testParseTimeString( ttt );
469
470 if (debug_mode) printf("Test passed for April 4, 1917\n");
471
472 /* July 4, 2050 */
473 et1.tm_usec = 0;
474 et1.tm_sec = 0;
475 et1.tm_min = 0;
476 et1.tm_hour = 0;
477 et1.tm_mday = 4;
478 et1.tm_month = 7 - 1;
479 et1.tm_year = 2050;
480 et1.tm_params = PR_GMTParameters(&et1);
481 PR_NormalizeTime(&et1, PR_LocalTimeParameters);
482 secs = PR_ImplodeTime(&et1);
483 if (!LL_GE_ZERO(secs)) {
484 if (debug_mode)
485 printf("ERROR: July 4, 2050 GMT returns a negative second count\n");
486 failed_already = 1;
487 return 1;
488 }
489 PR_ExplodeTime(secs, PR_LocalTimeParameters, &et2);
490 if (!ExplodedTimeIsEqual(&et1, &et2)) {
491 if (debug_mode)
492 printf("ERROR: PR_ImplodeTime and PR_ExplodeTime are not inverse for July 4, 2050 GMT\n");
493 failed_already=1;
494 return 1;
495 }
496 testParseTimeString(PR_ImplodeTime(&et1));
497
498 if (debug_mode) printf("Test passed for July 4, 2050\n");
499
500 }
501
502 /*
503 **************************************************************
504 **
505 ** Stress test
506 *
507 ** Go through four years, starting from
508 ** 00:00:00 PST Jan. 1, 1993, incrementing
509 ** every 10 minutes.
510 **
511 **************************************************************
512 */
513
514 {
515 PRExplodedTime et, et1, et2;
516 PRInt64 usecPer10Min;
517 int day, hour, min;
518 PRTime usecs;
519 int dstInEffect = 0;
520
521 if (debug_mode) {
522 printf("\n");
523 printf("*******************************************************\n");
524 printf("** **\n");
525 printf("** Stress test **\n");
526 printf("** Starting from midnight Jan. 1, 1993 PST, **\n");
527 printf("** going through four years in 10-minute increment **\n");
528 printf("** **\n");
529 printf("*******************************************************\n\n");
530 }
531 LL_I2L(usecPer10Min, 600000000L);
532
533 /* 00:00:00 PST Jan. 1, 1993 */
534 et.tm_usec = 0;
535 et.tm_sec = 0;
536 et.tm_min = 0;
537 et.tm_hour = 0;
538 et.tm_mday = 1;
539 et.tm_month = 0;
540 et.tm_year = 1993;
541 et.tm_params.tp_gmt_offset = -8 * 3600;
542 et.tm_params.tp_dst_offset = 0;
543 usecs = PR_ImplodeTime(&et);
544
545 for (day = 0; day < 4 * 365 + 1; day++) {
546 for (hour = 0; hour < 24; hour++) {
547 for (min = 0; min < 60; min += 10) {
548 LL_ADD(usecs, usecs, usecPer10Min);
549 PR_ExplodeTime(usecs, PR_USPacificTimeParameters, &et1);
550
551 et2 = et;
552 et2.tm_usec += 600000000L;
553 PR_NormalizeTime(&et2, PR_USPacificTimeParameters);
554
555 if (!ExplodedTimeIsEqual(&et1, &et2)) {
556 if (debug_mode) printf("ERROR: componentwise comparison failed\n");
557 PrintExplodedTime(&et1);
558 if (debug_mode) printf("\n");
559 PrintExplodedTime(&et2);
560 if (debug_mode) printf("\n");
561 failed_already=1;
562 return 1;
563 }
564
565 if (LL_NE(usecs, PR_ImplodeTime(&et1))) {
566 if (debug_mode)
567 printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
568 PrintExplodedTime(&et1);
569 if (debug_mode) printf("\n");
570 failed_already=1;
571 return 1;
572 }
573 testParseTimeString(usecs);
574
575 if (!dstInEffect && et1.tm_params.tp_dst_offset) {
576 dstInEffect = 1;
577 if (debug_mode) printf("DST changeover from ");
578 PrintExplodedTime(&et);
579 if (debug_mode) printf(" to ");
580 PrintExplodedTime(&et1);
581 if (debug_mode) printf(".\n");
582 } else if (dstInEffect && !et1.tm_params.tp_dst_offset) {
583 dstInEffect = 0;
584 if (debug_mode) printf("DST changeover from ");
585 PrintExplodedTime(&et);
586 if (debug_mode) printf(" to ");
587 PrintExplodedTime(&et1);
588 if (debug_mode) printf(".\n");
589 }
590
591 et = et1;
592 }
593 }
594 }
595 if (debug_mode) printf("Test passed\n");
596 }
597
598
599 /* Same stress test, but with PR_LocalTimeParameters */
600
601 {
602 PRExplodedTime et, et1, et2;
603 PRInt64 usecPer10Min;
604 int day, hour, min;
605 PRTime usecs;
606 int dstInEffect = 0;
607
608 if (debug_mode) {
609 printf("\n");
610 printf("*******************************************************\n");
611 printf("** **\n");
612 printf("** Stress test **\n");
613 printf("** Starting from midnight Jan. 1, 1993 PST, **\n");
614 printf("** going through four years in 10-minute increment **\n");
615 printf("** **\n");
616 printf("*******************************************************\n\n");
617 }
618
619 LL_I2L(usecPer10Min, 600000000L);
620
621 /* 00:00:00 PST Jan. 1, 1993 */
622 et.tm_usec = 0;
623 et.tm_sec = 0;
624 et.tm_min = 0;
625 et.tm_hour = 0;
626 et.tm_mday = 1;
627 et.tm_month = 0;
628 et.tm_year = 1993;
629 et.tm_params.tp_gmt_offset = -8 * 3600;
630 et.tm_params.tp_dst_offset = 0;
631 usecs = PR_ImplodeTime(&et);
632
633 for (day = 0; day < 4 * 365 + 1; day++) {
634 for (hour = 0; hour < 24; hour++) {
635 for (min = 0; min < 60; min += 10) {
636 LL_ADD(usecs, usecs, usecPer10Min);
637 PR_ExplodeTime(usecs, PR_LocalTimeParameters, &et1);
638
639 et2 = et;
640 et2.tm_usec += 600000000L;
641 PR_NormalizeTime(&et2, PR_LocalTimeParameters);
642
643 if (!ExplodedTimeIsEqual(&et1, &et2)) {
644 if (debug_mode) printf("ERROR: componentwise comparison failed\n");
645 PrintExplodedTime(&et1);
646 if (debug_mode) printf("\n");
647 PrintExplodedTime(&et2);
648 if (debug_mode) printf("\n");
649 return 1;
650 }
651
652 if (LL_NE(usecs, PR_ImplodeTime(&et1))) {
653 printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
654 PrintExplodedTime(&et1);
655 if (debug_mode) printf("\n");
656 failed_already=1;
657 return 1;
658 }
659 testParseTimeString(usecs);
660
661 if (!dstInEffect && et1.tm_params.tp_dst_offset) {
662 dstInEffect = 1;
663 if (debug_mode) printf("DST changeover from ");
664 PrintExplodedTime(&et);
665 if (debug_mode) printf(" to ");
666 PrintExplodedTime(&et1);
667 if (debug_mode) printf(".\n");
668 } else if (dstInEffect && !et1.tm_params.tp_dst_offset) {
669 dstInEffect = 0;
670 if (debug_mode) printf("DST changeover from ");
671 PrintExplodedTime(&et);
672 if (debug_mode) printf(" to ");
673 PrintExplodedTime(&et1);
674 if (debug_mode) printf(".\n");
675 }
676
677 et = et1;
678 }
679 }
680 }
681 if (debug_mode) printf("Test passed\n");
682 }
683
684 /* Same stress test, but with PR_LocalTimeParameters and going backward */
685
686 {
687 PRExplodedTime et, et1, et2;
688 PRInt64 usecPer10Min;
689 int day, hour, min;
690 PRTime usecs;
691 int dstInEffect = 0;
692
693 if (debug_mode) {
694 printf("\n");
695 printf("*******************************************************\n");
696 printf("** **\n");
697 printf("** Stress test **\n");
698 printf("** Starting from midnight Jan. 1, 1997 PST, **\n");
699 printf("** going back four years in 10-minute increment **\n");
700 printf("** **\n");
701 printf("*******************************************************\n\n");
702 }
703
704 LL_I2L(usecPer10Min, 600000000L);
705
706 /* 00:00:00 PST Jan. 1, 1997 */
707 et.tm_usec = 0;
708 et.tm_sec = 0;
709 et.tm_min = 0;
710 et.tm_hour = 0;
711 et.tm_mday = 1;
712 et.tm_month = 0;
713 et.tm_year = 1997;
714 et.tm_params.tp_gmt_offset = -8 * 3600;
715 et.tm_params.tp_dst_offset = 0;
716 usecs = PR_ImplodeTime(&et);
717
718 for (day = 0; day < 4 * 365 + 1; day++) {
719 for (hour = 0; hour < 24; hour++) {
720 for (min = 0; min < 60; min += 10) {
721 LL_SUB(usecs, usecs, usecPer10Min);
722 PR_ExplodeTime(usecs, PR_LocalTimeParameters, &et1);
723
724 et2 = et;
725 et2.tm_usec -= 600000000L;
726 PR_NormalizeTime(&et2, PR_LocalTimeParameters);
727
728 if (!ExplodedTimeIsEqual(&et1, &et2)) {
729 if (debug_mode) printf("ERROR: componentwise comparison failed\n");
730 PrintExplodedTime(&et1);
731 if (debug_mode) printf("\n");
732 PrintExplodedTime(&et2);
733 if (debug_mode) printf("\n");
734 return 1;
735 }
736
737 if (LL_NE(usecs, PR_ImplodeTime(&et1))) {
738 if (debug_mode)
739 printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
740 PrintExplodedTime(&et1);
741 if (debug_mode) printf("\n");
742 failed_already=1;
743 return 1;
744 }
745 testParseTimeString(usecs);
746
747 if (!dstInEffect && et1.tm_params.tp_dst_offset) {
748 dstInEffect = 1;
749 if (debug_mode) printf("DST changeover from ");
750 PrintExplodedTime(&et);
751 if (debug_mode) printf(" to ");
752 PrintExplodedTime(&et1);
753 if (debug_mode) printf(".\n");
754 } else if (dstInEffect && !et1.tm_params.tp_dst_offset) {
755 dstInEffect = 0;
756 if (debug_mode) printf("DST changeover from ");
757 PrintExplodedTime(&et);
758 if (debug_mode) printf(" to ");
759 PrintExplodedTime(&et1);
760 if (debug_mode) printf(".\n");
761 }
762
763 et = et1;
764 }
765 }
766 }
767 }
768
769#ifdef XP_MAC
770 if (1)
771 {
772 char dummyChar;
773
774 printf("Press return to exit\n\n");
775 scanf("%c", &dummyChar);
776 }
777#endif
778
779 if (failed_already) return 1;
780 else return 0;
781
782}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette