/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* file: timetest.c
* description: test time and date routines
*/
/***********************************************************************
** Includes
***********************************************************************/
/* Used to get the command line option */
#include "plgetopt.h"
#include "prinit.h"
#include "prtime.h"
#include "prprf.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef XP_MAC
#include "prlog.h"
#include "macstdlibextras.h"
extern void SetupMacPrintfLog(char *logFile);
#endif
int failed_already=0;
static char *dayOfWeek[] =
{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
static char *month[] =
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???" };
const char *sign;
/* Print day of the week, month, day, hour, minute, and second */
/* Print time zone */
if (totalOffset == 0) {
} else {
sign = "+";
if (totalOffset < 0) {
sign = "-";
}
if (debug_mode)
}
/* Print year */
}
const PRExplodedTime *et2)
{
return 1;
} else {
return 0;
}
}
static void
{
const char *sign;
/* Truncate the microsecond part of PRTime */
LL_DIV(t, t, usec_per_sec);
LL_MUL(t, t, usec_per_sec);
/* Print day of the week, month, day, hour, minute, and second */
/* Print time zone */
if (totalOffset == 0) {
* PR_ParseTimeString doesn't
* understand "UTC". */
} else {
sign = "+";
if (totalOffset < 0) {
sign = "-";
}
}
/* Print year */
exit(1);
}
t, t2, timeString);
exit(1);
}
}
{
/* The command line argument: -d is used to determine if the test is being run
in debug mode. The regress tool requires only one line output:PASS or FAIL.
All of the printfs associated with this test has been handled with a if (debug_mode)
test.
Usage: test_name -d
*/
{
if (PL_OPT_BAD == os) continue;
{
case 'd': /* debug mode */
break;
default:
break;
}
}
/* main test */
#ifdef XP_MAC
/* Set up the console */
InitializeSIOUX(true);
#endif
/* Testing zero PRTime (the epoch) */
{
PRTime t;
LL_I2L(t, 0);
}
/*
*************************************************************
**
** Testing PR_Now(), PR_ExplodeTime, and PR_ImplodeTime
** on the current time
**
*************************************************************
*/
{
if (debug_mode) {
printf("*********************************************\n");
printf("** **\n");
printf("** Testing PR_Now(), PR_ExplodeTime, and **\n");
printf("** PR_ImplodeTime on the current time **\n");
printf("** **\n");
printf("*********************************************\n\n");
}
/* First try converting to UTC */
else failed_already=1;
return 1;
}
else printf("FAIL\n");
return 1;
}
/* Next, try converting to local (US Pacific) time */
return 1;
}
}
/*
*******************************************
**
** Testing PR_NormalizeTime()
**
*******************************************
*/
/* July 4, 2001 is Wednesday */
{
if (debug_mode) {
printf("\n");
printf("**********************************\n");
printf("** **\n");
printf("** Testing PR_NormalizeTime() **\n");
printf("** **\n");
printf("**********************************\n\n");
}
} else {
else failed_already=1;
return 1;
}
/* June 12, 1997 23:00 PST == June 13, 1997 00:00 PDT */
if (debug_mode) {
printf("Thu Jun 12, 1997 23:00:00 PST is ");
}
} else {
else failed_already=1;
return 1;
}
/* Feb 14, 1997 00:00:00 PDT == Feb 13, 1997 23:00:00 PST */
if (debug_mode) {
printf("Fri Feb 14, 1997 00:00:00 PDT is ");
}
} else {
else failed_already=1;
return 1;
}
/* What time is Nov. 7, 1996, 18:29:23 PDT? */
/* What time is Oct. 7, 1995, 18:29:23 PST? */
}
/*
**************************************************************
**
** Testing range of years
**
**************************************************************
*/
{
if (debug_mode) {
printf("\n");
printf("***************************************\n");
printf("** **\n");
printf("** Testing range of years **\n");
printf("** **\n");
printf("***************************************\n\n");
}
/* April 4, 1917 GMT */
if (LL_GE_ZERO(secs)) {
if (debug_mode)
printf("ERROR: April 4, 1917 GMT returns a nonnegative second count\n");
failed_already = 1;
return 1;
}
if (debug_mode)
printf("ERROR: PR_ImplodeTime and PR_ExplodeTime are not inverse for April 4, 1917 GMT\n");
return 1;
}
/* July 4, 2050 */
if (!LL_GE_ZERO(secs)) {
if (debug_mode)
printf("ERROR: July 4, 2050 GMT returns a negative second count\n");
failed_already = 1;
return 1;
}
if (debug_mode)
printf("ERROR: PR_ImplodeTime and PR_ExplodeTime are not inverse for July 4, 2050 GMT\n");
return 1;
}
}
/*
**************************************************************
**
** Stress test
*
** Go through four years, starting from
** 00:00:00 PST Jan. 1, 1993, incrementing
** every 10 minutes.
**
**************************************************************
*/
{
int dstInEffect = 0;
if (debug_mode) {
printf("\n");
printf("*******************************************************\n");
printf("** **\n");
printf("** Stress test **\n");
printf("** Starting from midnight Jan. 1, 1993 PST, **\n");
printf("** going through four years in 10-minute increment **\n");
printf("** **\n");
printf("*******************************************************\n\n");
}
/* 00:00:00 PST Jan. 1, 1993 */
return 1;
}
if (debug_mode)
printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
return 1;
}
dstInEffect = 1;
dstInEffect = 0;
}
}
}
}
}
/* Same stress test, but with PR_LocalTimeParameters */
{
int dstInEffect = 0;
if (debug_mode) {
printf("\n");
printf("*******************************************************\n");
printf("** **\n");
printf("** Stress test **\n");
printf("** Starting from midnight Jan. 1, 1993 PST, **\n");
printf("** going through four years in 10-minute increment **\n");
printf("** **\n");
printf("*******************************************************\n\n");
}
/* 00:00:00 PST Jan. 1, 1993 */
return 1;
}
printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
return 1;
}
dstInEffect = 1;
dstInEffect = 0;
}
}
}
}
}
/* Same stress test, but with PR_LocalTimeParameters and going backward */
{
int dstInEffect = 0;
if (debug_mode) {
printf("\n");
printf("*******************************************************\n");
printf("** **\n");
printf("** Stress test **\n");
printf("** Starting from midnight Jan. 1, 1997 PST, **\n");
printf("** going back four years in 10-minute increment **\n");
printf("** **\n");
printf("*******************************************************\n\n");
}
/* 00:00:00 PST Jan. 1, 1997 */
return 1;
}
if (debug_mode)
printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
return 1;
}
dstInEffect = 1;
dstInEffect = 0;
}
}
}
}
}
#ifdef XP_MAC
if (1)
{
char dummyChar;
printf("Press return to exit\n\n");
}
#endif
if (failed_already) return 1;
else return 0;
}