Changeset 3016


Ignore:
Timestamp:
Apr 7, 2007, 7:33:15 AM (18 years ago)
Author:
bird
Message:

A toupper/lower testcase.

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

Legend:

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

    r3008 r3016  
    9090        smoketests/tempnam-1.c \
    9191        smoketests/tmpfile-1.c \
     92        smoketests/toupperlower-1.c \
     93        smoketests/toupperlower-2.c \
    9294        smoketests/usleep-1.c \
    9395        smoketests/waitpid-1.c \
  • branches/libc-0.6/src/libctests/libc/smoketests/toupperlower-1.c

    r3010 r3016  
     1/* this file is used as template for toupperlower-2. */
     2#ifndef _USE_CTYPE_INLINE_
     3# define _DONT_USE_CTYPE_INLINE_
     4#endif
     5#ifndef TESTCASENAME
     6# define TESTCASENAME    "toupperlower-1"
     7#endif
     8
    19#include <stdio.h>
     10#include <locale.h>
     11#include <ctype.h>
    212#include <errno.h>
    313#include <string.h>
    414
    5 #define TESTCASENAME    "tempnam-1"
     15static int tst(const char *pszLocale)
     16{
     17    static const char s_szLower[] = "abcdefghijklmnopqrstuvwxyz";
     18    static const char s_szUpper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     19    unsigned cErrors = 0;
     20    unsigned i;
     21
     22    if (pszLocale)
     23    {
     24        const char *psz = setlocale(LC_ALL, pszLocale);
     25        if (!psz)
     26        {
     27            printf(TESTCASENAME ": FAILURE: setlocale(LC_ALL, %s) -> %s errno=%d\n", pszLocale, psz, errno);
     28            return 1;
     29        }
     30    }
     31
     32#define CHECK(expr) \
     33    do { \
     34        if (!(expr)) \
     35        { \
     36            printf(TESTCASENAME ": FAILURE: %s (i=%d '%c' locale=%s)\n", #expr, i, s_szLower[i], pszLocale); \
     37            cErrors++; \
     38        } \
     39    } while (0)
     40
     41    /* simple upper/lower test */
     42    for (i = 0; i < sizeof(s_szLower) / sizeof(s_szLower[0]) - 1; i++)
     43    {
     44        CHECK(tolower(s_szLower[i]) == s_szLower[i]);
     45        CHECK(toupper(s_szUpper[i]) == s_szUpper[i]);
     46        CHECK(tolower(s_szUpper[i]) == s_szLower[i]);
     47        CHECK(toupper(s_szLower[i]) == s_szUpper[i]);
     48        CHECK(!isupper(s_szLower[i]));
     49        CHECK(isupper(s_szUpper[i]));
     50        CHECK(!islower(s_szUpper[i]));
     51        CHECK(islower(s_szLower[i]));
     52    }
     53
     54#define CHECK2(expr, rcExpected) \
     55    do { \
     56        const int rc = expr; \
     57        if (rc != (rcExpected)) \
     58        { \
     59            printf(TESTCASENAME ": FAILURE: %s (rc=%d rcExpected=%d locale=%s)\n", #expr, rc, rcExpected, pszLocale); \
     60            cErrors++; \
     61        } \
     62    } while (0)
     63
     64    /* some high values. */
     65    CHECK2(toupper(255), 255);
     66    CHECK2(tolower(255), 255);
     67
     68#define CHECK3(expr) \
     69    do { \
     70        if (!(expr)) \
     71        { \
     72            printf(TESTCASENAME ": FAILURE: %s (i=%d locale=%s)\n", #expr, i, pszLocale); \
     73            cErrors++; \
     74        } \
     75    } while (0)
     76
     77    /* match tolower/toupper with isupper/islower. */
     78    for (i = -128; i < 255; i++)
     79    {
     80        CHECK3(!isupper(i) || tolower(i) != i);
     81        CHECK3(!islower(i) || toupper(i) != i);
     82        CHECK3(toupper(i) == i || islower(i));
     83        CHECK3(tolower(i) == i || isupper(i));
     84        CHECK3(tolower(toupper(i)) == i);
     85        CHECK3(toupper(tolower(i)) == i);
     86    }
     87
     88    return cErrors;
     89}
    690
    791
     
    993{
    1094    int rc = 0;
    11     char *psz;
    1295
    13     errno = 0;
    14     psz = tempnam(NULL, NULL);
    15     if (psz && *psz)
    16         printf(TESTCASENAME ": tempnam(NULL, NULL) -> %s (errno=%d)\n", psz, errno);
    17     else
    18     {
    19         printf(TESTCASENAME ": FAILURE: tempnam(NULL, NULL) -> %p (%s) errno=%d\n", psz, psz, errno);
    20         rc++;
    21     }
     96    rc += tst(NULL);
     97    rc += tst("POSIX");
     98    rc += tst("C");
     99#ifdef OTHER
     100    rc += tst("en_US.IBM850");
     101#else
     102    rc += tst("en_US.ISO8859-1");
     103#endif
     104    rc += tst("C");
     105    rc += tst("en_US");
     106    rc += tst("de_DE");
     107    rc += tst("no_NO");
    22108
    23109    /* .. done .. */
Note: See TracChangeset for help on using the changeset viewer.