Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
y2k.c File Reference
#include "plgetopt.h"
#include "prinit.h"
#include "prtime.h"
#include "prprf.h"
#include "prlog.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  time_increment
struct  normalize_test_data
struct  ParseTest

Defines

#define PRINT_DETAILS

Typedefs

typedef struct time_increment time_increment_t
typedef struct normalize_test_data normalize_test_data_t
typedef struct ParseTest ParseTest

Functions

static void PrintExplodedTime (const PRExplodedTime *et)
static int ExplodedTimeIsEqual (const PRExplodedTime *et1, const PRExplodedTime *et2)
static PRStatus TestExplodeImplodeTime (void)
void add_time_increment (PRExplodedTime *et1, time_increment_t *it)
PRStatus TestNormalizeTime (void)
static PRStatus TestParseTime (void)
int main (int argc, char **argv)
 The Xalan testcases app.

Variables

int failed_already = 0
PRBool debug_mode = PR_FALSE
static char * dayOfWeek []
static char * month []
PRLogModuleInfolm
static PRTime prt []
static PRExplodedTime gmt []
static PRExplodedTime uspt []
static PRExplodedTime localt []
normalize_test_data_t normalize_test_array []
static ParseTest parseArray []

Class Documentation

struct time_increment

Definition at line 367 of file y2k.c.

Class Members
PRInt32 ti_hour
PRInt32 ti_min
PRInt32 ti_sec
PRInt32 ti_usec
struct normalize_test_data

Definition at line 379 of file y2k.c.

Collaboration diagram for normalize_test_data:
Class Members
PRExplodedTime base_time
PRExplodedTime expected_gmt_time
PRExplodedTime expected_uspt_time
time_increment_t increment
struct ParseTest

Definition at line 534 of file y2k.c.

Collaboration diagram for ParseTest:
Class Members
PRExplodedTime et
char * sDate

Define Documentation

Definition at line 65 of file y2k.c.


Typedef Documentation

typedef struct ParseTest ParseTest

Function Documentation

Definition at line 464 of file y2k.c.

{
       et1->tm_usec += it->ti_usec;
       et1->tm_sec   += it->ti_sec;
       et1->tm_min += it->ti_min;
       et1->tm_hour += it->ti_hour;
}

Here is the caller graph for this function:

static int ExplodedTimeIsEqual ( const PRExplodedTime et1,
const PRExplodedTime et2 
) [static]

Definition at line 120 of file y2k.c.

{
    if (et1->tm_usec == et2->tm_usec &&
           et1->tm_sec == et2->tm_sec &&
           et1->tm_min == et2->tm_min &&
           et1->tm_hour == et2->tm_hour &&
           et1->tm_mday == et2->tm_mday &&
           et1->tm_month == et2->tm_month &&
           et1->tm_year == et2->tm_year &&
           et1->tm_wday == et2->tm_wday &&
           et1->tm_yday == et2->tm_yday &&
           et1->tm_params.tp_gmt_offset == et2->tm_params.tp_gmt_offset &&
           et1->tm_params.tp_dst_offset == et2->tm_params.tp_dst_offset) {
        return 1;
    } else {
       return 0;
    }
}

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

The Xalan testcases app.

Definition at line 763 of file y2k.c.

{
       /* 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
       */
       PLOptStatus os;
       PLOptState *opt;
    
    PR_STDIO_INIT();
       opt = PL_CreateOptState(argc, argv, "d");
       while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    {
              if (PL_OPT_BAD == os) continue;
        switch (opt->option)
        {
        case 'd':  /* debug mode */
                     debug_mode = PR_TRUE;
            break;
         default:
            break;
        }
    }
       PL_DestroyOptState(opt);

 /* main test */
       
    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
    lm = PR_NewLogModule("test");

#ifdef XP_MAC
       /* Set up the console */
       InitializeSIOUX(true);
       debug_mode = PR_TRUE;
#endif

    if ( PR_FAILURE == TestExplodeImplodeTime())
    {
        PR_LOG( lm, PR_LOG_ERROR,
            ("TestExplodeImplodeTime() failed"));
    }
    else
       printf("Test 1: Calendar Time Test passed\n");

    if ( PR_FAILURE == TestNormalizeTime())
    {
        PR_LOG( lm, PR_LOG_ERROR,
            ("TestNormalizeTime() failed"));
    }
    else
       printf("Test 2: Normalize Time Test passed\n");

    if ( PR_FAILURE == TestParseTime())
    {
        PR_LOG( lm, PR_LOG_ERROR,
            ("TestParseTime() failed"));
    }
    else
       printf("Test 3: Parse Time Test passed\n");

#ifdef XP_MAC
       if (1)
       {
              char dummyChar;
              
              printf("Press return to exit\n\n");
              scanf("%c", &dummyChar);
       }
#endif

       if (failed_already) 
           return 1;
       else 
           return 0;
} /* end main() y2k.c */

Here is the call graph for this function:

static void PrintExplodedTime ( const PRExplodedTime et) [static]

Definition at line 78 of file y2k.c.

                                                        {
    PRInt32 totalOffset;
    PRInt32 hourOffset, minOffset;
    const char *sign;

    /* Print day of the week, month, day, hour, minute, and second */
    printf("%s %s %2ld %02ld:%02ld:%02ld ",
           dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
           et->tm_hour, et->tm_min, et->tm_sec);

    /* Print year */
    printf("%hd ", et->tm_year);

    /* Print time zone */
    totalOffset = et->tm_params.tp_gmt_offset + et->tm_params.tp_dst_offset;
    if (totalOffset == 0) {
       printf("UTC ");
    } else {
        sign = "+";
        if (totalOffset < 0) {
           totalOffset = -totalOffset;
           sign = "-";
        }
        hourOffset = totalOffset / 3600;
        minOffset = (totalOffset % 3600) / 60;
        printf("%s%02ld%02ld ", sign, hourOffset, minOffset);
    }
#ifdef PRINT_DETAILS
       printf("{%d, %d, %d, %d, %d, %d, %d, %d, %d, { %d, %d}}\n",et->tm_usec,
                                                                             et->tm_sec,
                                                                             et->tm_min,
                                                                             et->tm_hour,
                                                                             et->tm_mday,
                                                                             et->tm_month,
                                                                             et->tm_year,
                                                                             et->tm_wday,
                                                                             et->tm_yday,
                                                                             et->tm_params.tp_gmt_offset,
                                                                             et->tm_params.tp_dst_offset);
#endif
}

Here is the caller graph for this function:

static PRStatus TestExplodeImplodeTime ( void  ) [static]

Definition at line 258 of file y2k.c.

{
    PRTime prt_tmp;
    PRTime now;
    int idx;
    int array_size = sizeof(prt) / sizeof(PRTime);
    PRExplodedTime et_tmp;
    char buf[1024];

    for (idx = 0; idx < array_size; idx++) {
        PR_snprintf(buf, sizeof(buf), "%lld", prt[idx]);
        if (debug_mode) printf("Time stamp %s\n", buf); 
        PR_ExplodeTime(prt[idx], PR_GMTParameters, &et_tmp);
        if (!ExplodedTimeIsEqual(&et_tmp, &gmt[idx])) {
            fprintf(stderr, "GMT not equal\n");
            PrintExplodedTime(&et_tmp);
            PrintExplodedTime(&gmt[idx]);
            exit(1);
        }
        prt_tmp = PR_ImplodeTime(&et_tmp);
        if (LL_NE(prt_tmp, prt[idx])) {
            fprintf(stderr, "PRTime not equal\n");
            exit(1);
        }
        if (debug_mode) {
            printf("GMT: ");
            PrintExplodedTime(&et_tmp);
            printf("\n");
        }

        PR_ExplodeTime(prt[idx], PR_USPacificTimeParameters, &et_tmp);
        if (!ExplodedTimeIsEqual(&et_tmp, &uspt[idx])) {
            fprintf(stderr, "US Pacific Time not equal\n");
            PrintExplodedTime(&et_tmp);
            PrintExplodedTime(&uspt[idx]);
            exit(1);
        }
        prt_tmp = PR_ImplodeTime(&et_tmp);
        if (LL_NE(prt_tmp, prt[idx])) {
            fprintf(stderr, "PRTime not equal\n");
            exit(1);
        }
        if (debug_mode) {
            printf("US Pacific Time: ");
            PrintExplodedTime(&et_tmp);
            printf("\n");
        }

        PR_ExplodeTime(prt[idx], PR_LocalTimeParameters, &et_tmp);
        if (!ExplodedTimeIsEqual(&et_tmp, &localt[idx])) {
            fprintf(stderr, "not equal\n");
            PrintExplodedTime(&et_tmp);
            PrintExplodedTime(&localt[idx]);
            exit(1);
        }
        prt_tmp = PR_ImplodeTime(&et_tmp);
        if (LL_NE(prt_tmp, prt[idx])) {
            fprintf(stderr, "not equal\n");
            exit(1);
        }
        if (debug_mode) {
            printf("Local time:");
            PrintExplodedTime(&et_tmp);
            printf("\n\n");
        }
    }

    now = PR_Now();
    PR_ExplodeTime(now, PR_GMTParameters, &et_tmp);
    printf("Current GMT is ");
    PrintExplodedTime(&et_tmp);
    printf("\n");
    prt_tmp = PR_ImplodeTime(&et_tmp);
    if (LL_NE(prt_tmp, now)) {
        fprintf(stderr, "not equal\n");
        exit(1);
    }
    PR_ExplodeTime(now, PR_USPacificTimeParameters, &et_tmp);
    printf("Current US Pacific Time is ");
    PrintExplodedTime(&et_tmp);
    printf("\n");
    prt_tmp = PR_ImplodeTime(&et_tmp);
    if (LL_NE(prt_tmp, now)) {
        fprintf(stderr, "not equal\n");
        exit(1);
    }
    PR_ExplodeTime(now, PR_LocalTimeParameters, &et_tmp);
    printf("Current local time is ");
    PrintExplodedTime(&et_tmp);
    printf("\n");
    prt_tmp = PR_ImplodeTime(&et_tmp);
    if (LL_NE(prt_tmp, now)) {
        fprintf(stderr, "not equal\n");
        exit(1);
    }
    printf("Please verify the results\n\n");

    if (debug_mode) printf("Test 1 passed\n");
    return PR_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 480 of file y2k.c.

{
int idx, count;
normalize_test_data_t *itemp;
time_increment_t *itp;

       count = sizeof(normalize_test_array)/sizeof(normalize_test_array[0]);
       for (idx = 0; idx < count; idx++) {
              itemp = &normalize_test_array[idx];
              if (debug_mode) {
                     printf("%2d. %15s",idx +1,"Base time: ");
                     PrintExplodedTime(&itemp->base_time);
                     printf("\n");
              }
              itp = &itemp->increment;
              if (debug_mode) {
                     printf("%20s %2d hrs %2d min %3d sec\n","Add",itp->ti_hour,
                                                                                    itp->ti_min, itp->ti_sec);
              }
              add_time_increment(&itemp->base_time, &itemp->increment);
              PR_NormalizeTime(&itemp->base_time, PR_LocalTimeParameters);
              if (debug_mode) {
                     printf("%19s","PST time: ");
                     PrintExplodedTime(&itemp->base_time);
                     printf("\n");
              }
              if (!ExplodedTimeIsEqual(&itemp->base_time,
                                                               &itemp->expected_uspt_time)) {
                     printf("PR_NormalizeTime failed\n");
                     if (debug_mode)
                            PrintExplodedTime(&itemp->expected_uspt_time);
                     return PR_FAILURE;
              }
              PR_NormalizeTime(&itemp->base_time, PR_GMTParameters);
              if (debug_mode) {
                     printf("%19s","GMT time: ");
                     PrintExplodedTime(&itemp->base_time);
                     printf("\n");
              }

              if (!ExplodedTimeIsEqual(&itemp->base_time,
                                                               &itemp->expected_gmt_time)) {
                     printf("PR_NormalizeTime failed\n");
                     return PR_FAILURE;
              }
       }
       return PR_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRStatus TestParseTime ( void  ) [static]

Definition at line 717 of file y2k.c.

{
    ParseTest       *ptp = parseArray;
    PRTime          ct;
    PRExplodedTime  cet;
    char            *sp = ptp->sDate;
    PRStatus        rc;
    PRStatus        rv = PR_SUCCESS;

    while ( sp != NULL)
    {
        rc = PR_ParseTimeString( sp, PR_FALSE, &ct );
        if ( PR_FAILURE == rc )
        {
            printf("TestParseTime(): PR_ParseTimeString() failed to convert: %s\n", sp );
            rv = PR_FAILURE;
            failed_already = 1;
        }
        else
        {
            PR_ExplodeTime( ct, PR_LocalTimeParameters , &cet );

            if ( !ExplodedTimeIsEqual( &cet, &ptp->et ))
            {
                printf("TestParseTime(): Exploded time compare failed: %s\n", sp );
                if ( debug_mode )
                {
                    PrintExplodedTime( &cet );
                    printf("\n");
                    PrintExplodedTime( &ptp->et );
                    printf("\n");
                }
                
                rv = PR_FAILURE;
                failed_already = 1;
            }
        }
                
        /* point to next element in array, keep going */
        ptp++;
        sp = ptp->sDate;
    } /* end while() */

    return( rv );
} /* end TestParseTime() */

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char* dayOfWeek[] [static]
Initial value:
       { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" }

Definition at line 70 of file y2k.c.

Definition at line 68 of file y2k.c.

Definition at line 67 of file y2k.c.

PRExplodedTime gmt[] [static]
Initial value:
 {
    { 0, 0, 0, 10, 31, 11, 1999, 5, 364, {0, 0}}, 
    { 0, 0, 0, 10, 1, 0, 2000, 6, 0, {0, 0}}, 
    { 0, 0, 0, 10, 29, 1, 2000, 2, 59, {0, 0}}, 
    { 0, 0, 0, 10, 1, 2, 2001, 4, 59, {0, 0}}, 
    { 0, 0, 0, 10, 1, 2, 2005, 2, 59, {0, 0}}, 
    { 0, 0, 0, 10, 9, 8, 1999, 4, 251, {0, 0}},  
    
    { 0, 0, 0, 10, 31, 11, 1998, 4, 364, {0, 0}},  
    { 0, 0, 0, 10, 10, 8, 1999, 5, 252, {0, 0}},  
    { 0, 0, 0, 10, 28, 1, 2000, 1, 58, {0, 0}},  
    { 0, 0, 0, 10, 31, 11, 2000, 0, 365, {0, 0}},  
    { 0, 0, 0, 10, 1, 0, 2001, 1, 0, {0, 0}}  
}

Definition at line 189 of file y2k.c.

Definition at line 76 of file y2k.c.

PRExplodedTime localt[] [static]
Initial value:
 {
{ 0, 0, 0, 2, 31, 11, 1999, 5, 364, {-28800, 0}}, 
{ 0, 0, 0, 2, 1, 0, 2000, 6, 0, {-28800, 0}}, 
{ 0, 0, 0, 2, 29, 1, 2000, 2, 59, {-28800, 0}}, 
{ 0, 0, 0, 2, 1, 2, 2001, 4, 59, {-28800, 0}}, 
{ 0, 0, 0, 2, 1, 2, 2005, 2, 59, {-28800, 0}}, 
{ 0, 0, 0, 3, 9, 8, 1999, 4, 251, {-28800, 3600}},  
    
    { 0, 0, 0, 2, 31, 11, 1998, 4, 364, {-28800, 0}},  
    { 0, 0, 0, 3, 10, 8, 1999, 5, 252, {-28800, 3600}},  
    { 0, 0, 0, 2, 28, 1, 2000, 1, 58, {-28800, 0}},  
    { 0, 0, 0, 2, 31, 11, 2000, 0, 365, {-28800, 0}},  
    { 0, 0, 0, 2, 1, 0, 2001, 1, 0, {-28800, 0}}  
}

Definition at line 226 of file y2k.c.

char* month[] [static]
Initial value:
       { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???" }

Definition at line 72 of file y2k.c.

Definition at line 392 of file y2k.c.

ParseTest parseArray[] [static]

Definition at line 540 of file y2k.c.

PRTime prt[] [static]
Initial value:
 {
    LL_INIT(220405, 2133125120),  
    LL_INIT(220425, 2633779200),  
    LL_INIT(221612, 2107598848),  
    LL_INIT(228975, 663398400),  
    LL_INIT(258365, 1974568960),  
    LL_INIT(218132, 1393788928),  
    
    LL_INIT( 213062, 4077979648 ), 
    LL_INIT( 218152, 1894443008 ), 
    LL_INIT( 221592, 1606944768 ), 
    LL_INIT( 227768, 688924672 ), 
    LL_INIT( 227788, 1189578752 ), 
}

Definition at line 174 of file y2k.c.

PRExplodedTime uspt[] [static]
Initial value:
 {
{ 0, 0, 0, 2, 31, 11, 1999, 5, 364, {-28800, 0}}, 
{ 0, 0, 0, 2, 1, 0, 2000, 6, 0, {-28800, 0}}, 
{ 0, 0, 0, 2, 29, 1, 2000, 2, 59, {-28800, 0}}, 
{ 0, 0, 0, 2, 1, 2, 2001, 4, 59, {-28800, 0}}, 
{ 0, 0, 0, 2, 1, 2, 2005, 2, 59, {-28800, 0}}, 
{ 0, 0, 0, 3, 9, 8, 1999, 4, 251, {-28800, 3600}},  
    
    { 0, 0, 0, 2, 31, 11, 1998, 4, 364, {-28800, 0}},  
    { 0, 0, 0, 3, 10, 8, 1999, 5, 252, {-28800, 3600}},  
    { 0, 0, 0, 2, 28, 1, 2000, 1, 58, {-28800, 0}},  
    { 0, 0, 0, 2, 31, 11, 2000, 0, 365, {-28800, 0}},  
    { 0, 0, 0, 2, 1, 0, 2001, 1, 0, {-28800, 0}}  
}

Definition at line 204 of file y2k.c.