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