Changeset 901


Ignore:
Timestamp:
Dec 15, 2003, 6:42:26 AM (22 years ago)
Author:
bird
Message:

#625: wrote real testcase.

Location:
trunk/testcase
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/testcase/625.gmk

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r900 r901  
    1414
    1515TESTCASE= 625
    16 CFLAGS  = -Zomf
     16CFLAGS  = -Zomf -g
    1717O               = .obj
    1818A           = .lib
  • trunk/testcase/625main.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r900 r901  
    1414#include <stdio.h>
    1515#include <stdlib.h>
     16#include <string.h>
     17
     18static struct times
     19{
     20    time_t   time;
     21}   aTimes[7] =
     22{
     23   0,                                       /* 1970-01-01 00:00:00 */
     24   13046400,                                /* 1970-06-01 00:00:00 */
     25   -(10*365+3-31-29)*24*3600 - 12*3600,     /* 1960-03-01 12:00:00 */
     26   -0x7fffffff + (365*24*60*60),            /* 1901-12-14 20:45:52 */
     27   0x7fffffff - (24*60*60),                 /* 2038-01-18 03:14:07 */
     28   31*365*24*3600 + 132,                    /* 2000-12-23 16:01:12 */
     29   (33*365 + 172)*24*3600 + 132,            /* 2000-12-23 16:01:12 */
     30};
     31
     32static struct testcase
     33{
     34    const char *pszTZ;
     35    const char *pszTZRes;
     36    const char *apszRes[9];
     37}   aTests[] =
     38{
     39    {
     40        "TZ=PST8",
     41        "timezone=28800  daylight=0  tzname='PST','",
     42        {
     43            "1969-12-31 16:00:00  3  364  not-dst(0)",
     44            "1970-05-31 16:00:00  0  150  not-dst(0)",
     45            "1960-02-29 04:00:00  1   59  not-dst(0)",
     46            "1902-12-13 12:45:53  6  346  not-dst(0)",
     47            "2038-01-17 19:14:07  0   16  not-dst(0)",
     48            "2000-12-23 16:02:12  6  357  not-dst(0)",
     49            "2003-06-13 16:02:12  5  163  not-dst(0)",
     50        }
     51    },
     52    {
     53        "TZ=UCT0",
     54        "timezone=0      daylight=0  tzname='UCT','",
     55        {
     56            "1970-01-01 00:00:00  4    0  not-dst(0)",
     57            "1970-06-01 00:00:00  1  151  not-dst(0)",
     58            "1960-02-29 12:00:00  1   59  not-dst(0)",
     59            "1902-12-13 20:45:53  6  346  not-dst(0)",
     60            "2038-01-18 03:14:07  1   17  not-dst(0)",
     61            "2000-12-24 00:02:12  0  358  not-dst(0)",
     62            "2003-06-14 00:02:12  6  164  not-dst(0)",
     63        }
     64    },
     65    {
     66        "TZ=PST8PDT",
     67        "timezone=28800  daylight=1  tzname='PST','PDT'",
     68        {
     69            "1969-12-31 16:00:00  3  364  not-dst(0)",
     70            "1970-05-31 17:00:00  0  150  dst(1)",
     71            "1960-02-29 04:00:00  1   59  not-dst(0)",
     72            "1902-12-13 12:45:53  6  346  not-dst(0)",
     73            "2038-01-17 19:14:07  0   16  not-dst(0)",
     74            "2000-12-23 16:02:12  6  357  not-dst(0)",
     75            "2003-06-13 17:02:12  5  163  dst(1)",
     76        }
     77    },
     78    {
     79        "TZ=CET-1CDT",
     80        "timezone=-3600  daylight=1  tzname='CET','CDT'",
     81        {
     82            "1970-01-01 01:00:00  4    0  not-dst(0)",
     83            "1970-06-01 02:00:00  1  151  dst(1)",
     84            "1960-02-29 13:00:00  1   59  not-dst(0)",
     85            "1902-12-13 21:45:53  6  346  not-dst(0)",
     86            "2038-01-18 04:14:07  1   17  not-dst(0)",
     87            "2000-12-24 01:02:12  0  358  not-dst(0)",
     88            "2003-06-14 02:02:12  6  164  dst(1)",
     89        }
     90    },
     91    {
     92#ifndef UNIX_TZ
     93        "TZ=CET-1CEDT,3,-1,0,7200,10,-1,0,10800,3600",
     94#else
     95        "TZ=CET-1CEDT,M3.-1.0/2,M10.-1.0/3",
     96#endif
     97        "timezone=-3600  daylight=1  tzname='CET','CEDT'",
     98        {
     99            "1970-01-01 01:00:00  4    0  not-dst(0)",
     100            "1970-06-01 02:00:00  1  151  dst(1)",
     101            "1960-02-29 13:00:00  1   59  not-dst(0)",
     102            "1902-12-13 21:45:53  6  346  not-dst(0)",
     103            "2038-01-18 04:14:07  1   17  not-dst(0)",
     104            "2000-12-24 01:02:12  0  358  not-dst(0)",
     105            "2003-06-14 02:02:12  6  164  dst(1)",
     106        }
     107    },
     108    {
     109#ifndef UNIX_TZ
     110        "TZ=AEST-10AEDT,10,-1,0,7200,3,-1,0,7200,3600",
     111#else
     112        "TZ=AEST-10AEDT,M10.-1.0/2,M3.-1.0/2",
     113#endif
     114        "timezone=-36000  daylight=1  tzname='AEST','AEDT'",
     115        {
     116            "1970-01-01 11:00:00  4    0  dst(1)",
     117            "1970-06-01 10:00:00  1  151  not-dst(0)",
     118            "1960-02-29 23:00:00  1   59  dst(1)",
     119            "1902-12-14 07:45:53  0  347  dst(1)",
     120            "2038-01-18 14:14:07  1   17  dst(1)",
     121            "2000-12-24 11:02:12  0  358  dst(1)",
     122            "2003-06-14 10:02:12  6  164  not-dst(0)",
     123        }
     124    }
     125};
     126
     127int doTests(void)
     128{
     129    int i;
     130    int rc;
     131    char sz[512];
     132
     133    for (rc = i = 0; i < sizeof(aTests) / sizeof(aTests[0]); i++)
     134    {
     135        int j;
     136        putenv(aTests[i].pszTZ);
     137        tzset();
     138        sprintf(sz, "timezone=%-5d  daylight=%d  tzname='%s','%s'",
     139#ifdef __IBMC__
     140                _timezone,
     141#else
     142                timezone,
     143#endif
     144                daylight,
     145                tzname[0],
     146                tzname[1]);
     147        if (!strncmp(sz, aTests[i].pszTZRes, strlen(aTests[i].pszTZRes)))
     148            printf("%s\n  %s - ok\n", aTests[i].pszTZ, sz);
     149        else
     150        {
     151            printf("%s\n  %s - mismatch!!! %s\n", aTests[i].pszTZ, sz, aTests[i].pszTZRes);
     152            rc++;
     153        }
     154
     155        for (j = 0; j < sizeof(aTimes) / sizeof(aTimes[0]); j++)
     156        {
     157            struct tm  *pTm = localtime(&aTimes[j].time);
     158            sprintf(sz, "%04d-%02d-%02d %02d:%02d:%02d  %d  %3d  %s(%d)",
     159                   pTm->tm_year + 1900, pTm->tm_mon + 1, pTm->tm_mday,
     160                   pTm->tm_hour, pTm->tm_min, pTm->tm_sec, pTm->tm_wday, pTm->tm_yday,
     161                   pTm->tm_isdst ? "dst" : "not-dst", pTm->tm_isdst);
     162            if (!strcmp(sz, aTests[i].apszRes[j]))
     163                printf("%12d: %s - ok\n", aTimes[j].time, sz);
     164            else
     165            {
     166                printf("%12d: %s - mismatch!! %s\n", aTimes[j].time, sz, aTests[i].apszRes[j]);
     167                rc++;
     168            }
     169        }
     170    }
     171    return rc;
     172}
    16173
    17174void printtz(void)
    18175{
    19176    const char *pszTZ = getenv("TZ");
     177    int         i;
     178
    20179    tzset();
    21     printf("TZ=%s\n\ttimezone=%d\t daylight=%d\ttzname='%s','%s'\n",
     180    printf("TZ=%s\n    timezone=%-5d\t daylight=%d\ttzname='%s','%s'\n",
    22181           pszTZ,
    23182    #ifdef __IBMC__
     
    29188           tzname[0],
    30189           tzname[1]);
     190    for (i = 0; i < sizeof(aTimes) / sizeof(aTimes[0]); i++)
     191    {
     192        struct tm  *pTm = localtime(&aTimes[i].time);
     193        printf("%12d: %04d-%02d-%02d %02d:%02d:%02d  %d  %3d  %s(%d)\n",
     194               (int)aTimes[i].time, pTm->tm_year + 1900, pTm->tm_mon + 1, pTm->tm_mday,
     195               pTm->tm_hour, pTm->tm_min, pTm->tm_sec, pTm->tm_wday, pTm->tm_yday,
     196               pTm->tm_isdst ? "dst" : "not-dst", pTm->tm_isdst);
     197    }
    31198}
    32199
    33200int main()
    34201{
    35     printtz();
    36     putenv("TZ=PST8PDT");
    37     printtz();
    38     putenv("TZ=CET-1CDT,3,-1,0,7200,10,-1,0,10800,3600");
    39     printtz();
    40     putenv("TZ=CET-1CEST,3,-1,0,7200,10,-1,0,10800,3600");
     202    int rcRet;
     203
    41204    printtz();
    42205    putenv("TZ=");
    43206    printtz();
    44     return 0;
     207
     208    /* execute testcases. */
     209    rcRet = doTests();
     210
     211    /* results */
     212    if (!rcRet)
     213        printf("Successfully executed return struct testcase (#625).\n");
     214    else
     215        printf("625main: %d failures.\n", rcRet);
     216    return rcRet;
    45217}
    46218
Note: See TracChangeset for help on using the changeset viewer.