y2k.c 36 KB

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