Changeset 3000 for branches/libc-0.6/src


Ignore:
Timestamp:
Apr 6, 2007, 11:48:24 PM (18 years ago)
Author:
bird
Message:

simple strcoll testcase.

Location:
branches/libc-0.6/src/libctests/libc
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/libc-0.6/src/libctests/libc/Makefile

    r2810 r3000  
    8181        smoketests/spm-1.c \
    8282        smoketests/stat-1.c \
     83        smoketests/strcoll-1.c \
    8384        smoketests/strnlen-1.c \
    8485        smoketests/strtof-1.c \
  • branches/libc-0.6/src/libctests/libc/smoketests/strcoll-1.c

    r2981 r3000  
    55#include <string.h>
    66
    7 #define TESTCASENAME    "setlocale"
     7#define TESTCASENAME    "strcoll-1"
    88
    99
    1010static int tst(const char *pszLocale)
    1111{
    12 #ifdef OTHER
    13     static char szTest[] = "‘›†\n’\n„Ž”™\n"; /* 850 */
    14 #else
    15     static char szTest[] =   "æøå\nÆØÅ\näÄöÖ\n"; /* 8859-1 */
    16 #endif
    17     char   *psz;
     12    char sz1[16];
     13    char sz2[16];
     14    unsigned i, j;
     15    int rc;
     16    int cErrors = 0;
    1817
    19     psz = setlocale(LC_ALL, pszLocale);
    20     printf("setlocale(LC_ALL, %s) -> %s  errno=%d\n", pszLocale, psz, errno);
    21     for (psz = szTest; *psz; psz++)
     18    if (pszLocale)
    2219    {
    23         if (*psz == '\n')
    24             printf("\n");
    25         else
     20        const char *psz = setlocale(LC_ALL, pszLocale);
     21        if (!psz)
    2622        {
    27             printf("'%c'(%02x): %d,%d,%d%s",
    28                    *psz, (unsigned char)*psz, !!isalpha(*psz), !!isupper(*psz), !!islower(*psz), psz[1] ? " " : "");
    29 
     23            printf(TESTCASENAME ": FAILURE: setlocale(LC_ALL, %s) -> %s errno=%d\n", pszLocale, psz, errno);
     24            return 1;
    3025        }
    3126    }
    32     return 0;
    33 }
    3427
    35 static int tst2(void)
    36 {
    37     char   *psz1;
    38     char   *psz2;
    39     int     rc = 0;
    40 
    41     printf(TESTCASENAME "\n");
    42 
    43     setlocale(LC_ALL, "en_US");
    44     setlocale(LC_CTYPE, "de_DE");
    45 
    46     psz1 = setlocale(LC_ALL, NULL);
    47     psz2 = setlocale(LC_CTYPE, NULL);
    48     if (psz1 && psz2 && strcmp(psz1, psz2))
    49         printf("LC_ALL != LC_CTYPE - ok (%s != %s) errno=%d\n", psz1, psz2, errno);
    50     else
     28    /* very basic test. */
     29    for (i = 0; i < 256; i++)
    5130    {
    52         printf("error: LC_ALL == LC_CTYPE - %s errno=%d\n", psz1, errno);
    53         rc++;
     31        sz1[0] = sz2[0] = i;
     32        sz1[1] = sz2[1] = '\0';
     33        rc = strcoll(sz1, sz2);
     34        if (rc)
     35        {
     36            printf(TESTCASENAME ": FAILURE: %d != %d; rc=%d (locale=%s)\n", i, i, rc, pszLocale);
     37            return 1;
     38        }
    5439    }
    5540
    56     return rc;
    57 }
     41    /*  basic test. */
     42    for (i = 'A'; i <= 'Z' && cErrors < 32; i++)
     43    {
     44        sz2[0] = i;
     45        sz2[1] = sz1[1] = '\0';
    5846
     47        /* smaller */
     48        for (j = 'A'; j < i && cErrors < 32; j++)
     49        {
     50            sz1[0] = j;
     51            rc = strcoll(sz1, sz2);
     52            if (rc >= 0)
     53            {
     54                printf(TESTCASENAME ": FAILURE: %s >= %s; rc=%d (locale=%s)\n", sz1, sz2, rc, pszLocale);
     55                cErrors++;
     56            }
     57        }
    5958
    60 static int tst3(void)
    61 {
    62     char   *psz1;
    63     char   *psz2;
    64     int     rc = 0;
     59        /* larger */
     60        for (j = i + 1; j <= 'Z' && cErrors < 32; j++)
     61        {
     62            sz1[0] = j;
     63            rc = strcoll(sz1, sz2);
     64            if (rc <= 0)
     65            {
     66                printf(TESTCASENAME ": FAILURE: %s <= %s; rc=%d (locale=%s)\n", sz1, sz2, rc, pszLocale);
     67                cErrors++;
     68            }
     69        }
    6570
    66     setlocale(LC_ALL, "en_US");
    67     psz1 = setlocale(LC_CTYPE, "de_DE");
    68     psz2 = setlocale(LC_CTYPE, "de_DE");
    69     if (psz1 && psz2 && !strcmp(psz1, psz2))
    70         printf("2nd setlocale returns the same. %s errno=%d\n", psz1, errno);
    71     else
    72     {
    73         printf("error: 2nd setlocale returns differntly. %s != %s errno=%d\n", psz1, psz2, errno);
    74         rc++;
    7571    }
    7672
    77     return rc;
     73    for (i = 'a'; i <= 'z' && cErrors < 32; i++)
     74    {
     75        sz2[0] = i;
     76        sz2[1] = sz1[1] = '\0';
     77
     78        /* smaller */
     79        for (j = 'a'; j < i && cErrors < 32; j++)
     80        {
     81            sz1[0] = j;
     82            rc = strcoll(sz1, sz2);
     83            if (rc >= 0)
     84            {
     85                printf(TESTCASENAME ": FAILURE: %s >= %s; rc=%d (locale=%s)\n", sz1, sz2, rc, pszLocale);
     86                cErrors++;
     87            }
     88        }
     89
     90        /* larger */
     91        for (j = i + 1; j <= 'z' && cErrors < 32; j++)
     92        {
     93            sz1[0] = j;
     94            rc = strcoll(sz1, sz2);
     95            if (rc <= 0)
     96            {
     97                printf(TESTCASENAME ": FAILURE: %s <= %s; rc=%d (locale=%s)\n", sz1, sz2, rc, pszLocale);
     98                cErrors++;
     99            }
     100        }
     101
     102    }
     103
     104    return cErrors;
    78105}
    79 
    80106
    81107int main()
     
    83109    int rc = 0;
    84110
    85     rc += tst("");
     111    rc += tst(NULL);
    86112    rc += tst("POSIX");
     113    rc += tst("C");
    87114#ifdef OTHER
    88115    rc += tst("en_US.IBM850");
     
    92119    rc += tst("C");
    93120    rc += tst("en_US");
    94     rc += tst2();
    95     rc += tst3();
    96121
    97122    /* .. done .. */
     
    99124        printf(TESTCASENAME ": testcase executed successfully.\n");
    100125    else
    101         printf(TESTCASENAME ": testcase failed. %d failed\n", rc);
     126        printf(TESTCASENAME ": testcase failed. %d errors\n", rc);
    102127    return !!rc;
    103128}
Note: See TracChangeset for help on using the changeset viewer.