Print this page
4964 nl_langinfo(CRNCYSTR) returns wrong alignment character
4999 libc test suite enhancements
Reviewed by: Jason King <jason.brian.king@gmail.com>
Reviewed by: Dan McDonald <danmcd@omniti.com>
Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com>
Approved by: TBD

*** 56,66 **** static void test_start(const char *testName, const char *format, ...) { va_list args; ! (void) printf("TEST STARTING %s: ", testName); va_start(args, format); (void) vprintf(format, args); va_end(args); (void) fflush(stdout); --- 56,66 ---- static void test_start(const char *testName, const char *format, ...) { va_list args; ! (void) printf("TEST STARTING %s (%s): ", testName, ARCH); va_start(args, format); (void) vprintf(format, args); va_end(args); (void) fflush(stdout);
*** 69,96 **** static void test_failed(const char *testName, const char *format, ...) { va_list args; ! (void) printf("TEST FAILED %s: ", testName); va_start(args, format); (void) vprintf(format, args); va_end(args); (void) exit(-1); } static void test_passed(const char *testName) { ! (void) printf("TEST PASS: %s\n", testName); (void) fflush(stdout); } void * ! testlocale_thr(void *ptr) { locale_t cloc, loc; struct lconv *lc; char *day; char *tname = ptr; --- 69,97 ---- static void test_failed(const char *testName, const char *format, ...) { va_list args; ! (void) printf("TEST FAILED %s (%s): ", testName, ARCH); va_start(args, format); (void) vprintf(format, args); va_end(args); + (void) printf("\n"); (void) exit(-1); } static void test_passed(const char *testName) { ! (void) printf("TEST PASS: %s (%s)\n", testName, ARCH); (void) fflush(stdout); } void * ! testlocale_thr_one(void *ptr) { locale_t cloc, loc; struct lconv *lc; char *day; char *tname = ptr;
*** 154,180 **** return (NULL); } void ! testlocale(void) { ! char *tname = "newlocale/uselocale"; pthread_t tid[NUMTHR]; test_start(tname, "running %d threads %d iterations\n", NUMTHR, NUMITR); for (int i = 0; i < NUMTHR; i++) { ! (void) pthread_create(&tid[i], NULL, testlocale_thr, tname); } for (int i = 0; i < NUMTHR; i++) { (void) pthread_join(tid[i], NULL); } test_passed(tname); } int main(int argc, char **argv) { int optc; --- 155,277 ---- return (NULL); } void ! test_newlocale_threaded(void) { ! char *tname = "newlocale_threaded"; pthread_t tid[NUMTHR]; test_start(tname, "running %d threads %d iterations\n", NUMTHR, NUMITR); for (int i = 0; i < NUMTHR; i++) { ! (void) pthread_create(&tid[i], NULL, testlocale_thr_one, tname); } for (int i = 0; i < NUMTHR; i++) { (void) pthread_join(tid[i], NULL); } test_passed(tname); } + void + test_newlocale_negative(void) + { + + locale_t loc, bad; + char *day; + char *tname = "newlocale_negative"; + + test_start(tname, "verify proper failure handling\n"); + loc = newlocale(LC_ALL_MASK, "de_DE.UTF-8", NULL); + if (loc == NULL) { + test_failed(tname, "cannot set de_DE.UTF-8"); + } + day = nl_langinfo_l(DAY_1, loc); + if (strcmp(day, "Sonntag") != 0) { + test_failed(tname, "incorrect Sonntag != %s", day); + } + + bad = newlocale(LC_ALL_MASK, "cn_US.BIZRRE", loc); + if (bad != NULL) { + test_failed(tname, "passed setting bogus locale"); + } + day = nl_langinfo_l(DAY_1, loc); + if (strcmp(day, "Sonntag") != 0) { + test_failed(tname, "incorrect Sonntag != %s", day); + } + test_passed(tname); + } + + void + test_newlocale_categories(void) + { + locale_t loc; + char *day, *cur, *yes; + char *tname = "newlocale_categories"; + + test_start(tname, "verify different category behavior\n"); + + loc = NULL; + loc = newlocale(LC_TIME_MASK, "de_DE.UTF-8", loc); + loc = newlocale(LC_MESSAGES_MASK, "ru_RU.UTF-8", loc); + loc = newlocale(LC_MONETARY_MASK, "en_US.UTF-8", loc); + + if (loc == NULL) { + test_failed(tname, "failed to set locale"); + } + + day = nl_langinfo_l(DAY_1, loc); + if ((day == NULL) || (strcmp(day, "Sonntag") != 0)) { + test_failed(tname, "day1 mismatch %s != %s", day, "Sonntag"); + } + yes = nl_langinfo_l(YESSTR, loc); + if ((yes == NULL) || (strcmp(yes, "да") != 0)) { + test_failed(tname, "currency mismatch"); + } + cur = nl_langinfo_l(CRNCYSTR, loc); + if ((cur == NULL) || (strcmp(cur, "-$") != 0)) { + test_failed(tname, "currency mismatch [%s] != [%s]", cur, "-$"); + } + + test_passed(tname); + } + + void + test_newlocale_composite(void) + { + locale_t loc; + char *day, *cur, *yes; + char *tname = "newlocale_composite"; + + test_start(tname, "verify composite locale behavior\n"); + + /* order: CTYPE/NUMERIC/TIME/COLLATE/MONETARY/MESSAGES */ + loc = newlocale(LC_ALL_MASK, + "C/C/de_DE.UTF-8/C/en_US.UTF-8/ru_RU.UTF-8", NULL); + + if (loc == NULL) { + test_failed(tname, "failed to set composite locale"); + } + + day = nl_langinfo_l(DAY_1, loc); + if ((day == NULL) || (strcmp(day, "Sonntag") != 0)) { + test_failed(tname, "day1 mismatch %s != %s", day, "Sonntag"); + } + yes = nl_langinfo_l(YESSTR, loc); + if ((yes == NULL) || (strcmp(yes, "да") != 0)) { + test_failed(tname, "currency mismatch"); + } + cur = nl_langinfo_l(CRNCYSTR, loc); + if ((cur == NULL) || (strcmp(cur, "-$") != 0)) { + test_failed(tname, "currency mismatch [%s] != [%s]", cur, "-$"); + } + + test_passed(tname); + } + int main(int argc, char **argv) { int optc;
*** 187,195 **** (void) fprintf(stderr, "Usage: %s [-d]\n", argv[0]); exit(1); } } ! testlocale(); exit(0); } --- 284,295 ---- (void) fprintf(stderr, "Usage: %s [-d]\n", argv[0]); exit(1); } } ! test_newlocale_threaded(); ! test_newlocale_negative(); ! test_newlocale_categories(); ! test_newlocale_composite(); exit(0); }