|
|
1.1 ! root 1: /* The Plum Hall Validation Suite for C ! 2: * Unpublished copyright (c) 1986-1991, Chiron Systems Inc and Plum Hall Inc. ! 3: * VERSION: 4 ! 4: * DATE: 1993-01-01 ! 5: * The "ANSI" mode of this suite corresponds to official ANSI C, X3.159-1989. ! 6: * As per your license agreement, your distribution is not to be moved or copied outside the Designated Site ! 7: * without specific permission from Plum Hall Inc. ! 8: */ ! 9: ! 10: #define LIB_TEST 1 ! 11: #include "defs.h" ! 12: #if !ANSI ! 13: #define SKIP44 1 ! 14: #endif ! 15: ! 16: ! 17: #include "flags.h" ! 18: #ifndef SKIP44 ! 19: ! 20: /* ! 21: * 4.4 - Localization ! 22: * This file is not relevant to pre ANSI C compilers. ! 23: */ ! 24: #include <string.h> ! 25: void d4_4(); ! 26: void d4_4_1(); ! 27: void d4_4_2(); ! 28: #include <locale.h> ! 29: ! 30: void d4_4() ! 31: { ! 32: char *p; ! 33: ! 34: /* make sure that the required macros produce constant expressions */ ! 35: static int lc_all = LC_ALL; ! 36: static int lc_collate = LC_COLLATE; ! 37: static int lc_ctype = LC_CTYPE; ! 38: static int lc_numeric = LC_NUMERIC; ! 39: static int lc_time = LC_TIME; ! 40: #if ANSI8709 ! 41: static int lc_monetary = LC_MONETARY; ! 42: #if !defined(LC_MONETARY) ! 43: complain(__LINE__); ! 44: #endif /* LC_MONETARY */ ! 45: #endif /* ANSI8709 */ ! 46: ! 47: /* make sure that these are macros */ ! 48: #if !defined(LC_ALL) || !defined(LC_COLLATE) || !defined(LC_CTYPE) ! 49: complain(__LINE__); ! 50: #elif !defined(LC_NUMERIC) || !defined(LC_TIME) || !defined(NULL) ! 51: complain(__LINE__); ! 52: #endif /* defined macros */ ! 53: ! 54: Filename = "d44.c"; ! 55: d4_4_1(); ! 56: d4_4_2(); ! 57: ! 58: #if ANSI8712 ! 59: /* make sure that NULL is defined in this file */ ! 60: p = NULL; ! 61: #endif /* ANSI8712 */ ! 62: } ! 63: ! 64: /* ! 65: * 4.4.1 Locale Control ! 66: */ ! 67: void d4_4_1() ! 68: { ! 69: #if ANSI8709 ! 70: extern void check_locale(); ! 71: ! 72: /* 4.4.1.1 setlocale ! 73: * startup condition must be the "C" locale ! 74: */ ! 75: check_locale(__LINE__, LC_COLLATE); ! 76: check_locale(__LINE__, LC_CTYPE); ! 77: check_locale(__LINE__, LC_NUMERIC); ! 78: check_locale(__LINE__, LC_TIME); ! 79: check_locale(__LINE__, LC_MONETARY); ! 80: check_locale(__LINE__, LC_ALL); ! 81: #endif /* ANSI8709 */ ! 82: ! 83: /* Each successful call to setlocale returns the NEW locale string. ! 84: * Change to the "native" environment ! 85: * (empty string) and check that non-NULL is returned. ! 86: */ ! 87: checkthat(__LINE__, setlocale(LC_COLLATE, "") != NULL); ! 88: checkthat(__LINE__, setlocale(LC_CTYPE, "") != NULL); ! 89: checkthat(__LINE__, setlocale(LC_NUMERIC, "") != NULL); ! 90: checkthat(__LINE__, setlocale(LC_TIME, "") != NULL); ! 91: #if ANSI8709 ! 92: checkthat(__LINE__, setlocale(LC_MONETARY, "") != NULL); ! 93: #endif ! 94: checkthat(__LINE__, setlocale(LC_ALL, "") != NULL); ! 95: ! 96: /* now reset to the "C" environment for the rest of the tests */ ! 97: setlocale(LC_ALL, "C"); ! 98: check_locale(__LINE__, LC_COLLATE); ! 99: check_locale(__LINE__, LC_CTYPE); ! 100: check_locale(__LINE__, LC_NUMERIC); ! 101: check_locale(__LINE__, LC_TIME); ! 102: check_locale(__LINE__, LC_MONETARY); ! 103: check_locale(__LINE__, LC_ALL); ! 104: } ! 105: ! 106: #include <limits.h> /* to get CHAR_MAX for use below */ ! 107: /* ! 108: * 4.4.2 Locale Control ! 109: */ ! 110: void d4_4_2() ! 111: { ! 112: #if ANSI8709 ! 113: struct lconv *plc; ! 114: /* the default locale is "C" ... make sure that the values are correct */ ! 115: plc = localeconv(); ! 116: stequals(__LINE__, plc->decimal_point, "."); ! 117: stequals(__LINE__, plc->thousands_sep, ""); ! 118: stequals(__LINE__, plc->grouping, ""); ! 119: stequals(__LINE__, plc->int_curr_symbol, ""); ! 120: stequals(__LINE__, plc->currency_symbol, ""); ! 121: stequals(__LINE__, plc->mon_decimal_point, ""); ! 122: stequals(__LINE__, plc->mon_thousands_sep, ""); ! 123: stequals(__LINE__, plc->mon_grouping, ""); ! 124: stequals(__LINE__, plc->positive_sign, ""); ! 125: stequals(__LINE__, plc->negative_sign, ""); ! 126: iequals(__LINE__, plc->int_frac_digits, CHAR_MAX); ! 127: iequals(__LINE__, plc->frac_digits, CHAR_MAX); ! 128: iequals(__LINE__, plc->p_cs_precedes, CHAR_MAX); ! 129: iequals(__LINE__, plc->p_sep_by_space, CHAR_MAX); ! 130: iequals(__LINE__, plc->n_cs_precedes, CHAR_MAX); ! 131: iequals(__LINE__, plc->n_sep_by_space, CHAR_MAX); ! 132: iequals(__LINE__, plc->p_sign_posn, CHAR_MAX); ! 133: iequals(__LINE__, plc->n_sign_posn, CHAR_MAX); ! 134: #endif /* ANSI8709 */ ! 135: } ! 136: ! 137: ! 138: ! 139: ! 140: ! 141: ! 142: ! 143: ! 144: ! 145: ! 146: ! 147: ! 148: ! 149: ! 150: ! 151: ! 152: ! 153: /* ! 154: * check_locale - make sure that the initial locale ! 155: * is equivalent to the "C" locale. ! 156: */ ! 157: void check_locale(lineno, localenum) ! 158: int lineno; ! 159: int localenum; ! 160: { ! 161: char *p, buff[512]; ! 162: char *nolocale = "Unrecognized Locale String"; ! 163: ! 164: /* get the (non-NULL) inital value of the locale */ ! 165: p = setlocale(localenum, NULL); ! 166: if (p == NULL) ! 167: { ! 168: stequals(lineno, "initial locale", "C"); ! 169: return; ! 170: } ! 171: strncpy(buff, p, 512); ! 172: ! 173: /* this should be the same as setting to "C" locale */ ! 174: p = setlocale(localenum, "C"); ! 175: if (p == NULL) ! 176: { ! 177: stequals(lineno, "C locale", "C"); ! 178: return; ! 179: } ! 180: stequals(lineno, p, buff); ! 181: ! 182: /* now make sure that an unrecognized string returns ! 183: * NULL and leaves the locale unchanged. ! 184: */ ! 185: p = setlocale(localenum, nolocale); ! 186: if (p != NULL) ! 187: { ! 188: stequals(lineno, "unrecognized locale", "NULL"); ! 189: return; ! 190: } ! 191: ! 192: /* is it unchanged? */ ! 193: p = setlocale(localenum, NULL); ! 194: if (p == NULL) ! 195: { ! 196: stequals(lineno, "unchanged locale", "C"); ! 197: return; ! 198: } ! 199: stequals(lineno, p, buff); ! 200: } ! 201: ! 202: ! 203: ! 204: #else /* SKIP44 */ ! 205: void d4_4() { pr_skip("d4_4: SKIPPED ENTIRELY\n"); } ! 206: #endif /* SKIP44 */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.