From owner-svn-src-all@freebsd.org Sun Nov 15 04:33:16 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 58616A2F792; Sun, 15 Nov 2015 04:33:16 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2FE0A17E8; Sun, 15 Nov 2015 04:33:16 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tAF4XF4M094001; Sun, 15 Nov 2015 04:33:15 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tAF4XFg1093999; Sun, 15 Nov 2015 04:33:15 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201511150433.tAF4XFg1093999@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Garrett Cooper Date: Sun, 15 Nov 2015 04:33:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r290843 - head/lib/libc/tests/locale X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Nov 2015 04:33:16 -0000 Author: ngie Date: Sun Nov 15 04:33:14 2015 New Revision: 290843 URL: https://svnweb.freebsd.org/changeset/base/290843 Log: Polish up the tests a bit more after projects/collation was merged to head Provide more meaningful diagnostic messages if LC_CTYPE can't be set properly instead of segfaulting, because setlocale returns NULL and strcmp(NULL, b) will always segfault Split up the testcases so one failing (in this case en_US.ISO8859-15) won't cause the rest of the testcases to be skipped Remove some unused variables MFC after: 1 week X-MFC with: r290532 Sponsored by: EMC / Isilon Storage Division Modified: head/lib/libc/tests/locale/c16rtomb_test.c head/lib/libc/tests/locale/mbrtoc16_test.c Modified: head/lib/libc/tests/locale/c16rtomb_test.c ============================================================================== --- head/lib/libc/tests/locale/c16rtomb_test.c Sun Nov 15 03:56:09 2015 (r290842) +++ head/lib/libc/tests/locale/c16rtomb_test.c Sun Nov 15 04:33:14 2015 (r290843) @@ -42,13 +42,27 @@ __FBSDID("$FreeBSD$"); #include -ATF_TC_WITHOUT_HEAD(c16rtomb_test); -ATF_TC_BODY(c16rtomb_test, tc) +static void +require_lc_ctype(const char *locale_name) { - mbstate_t s; - char buf[MB_LEN_MAX + 1]; + char *lc_ctype_set; - /* C/POSIX locale. */ + lc_ctype_set = setlocale(LC_CTYPE, locale_name); + if (lc_ctype_set == NULL) + atf_tc_fail("setlocale(LC_CTYPE, \"%s\") failed; errno=%d", + locale_name, errno); + + ATF_REQUIRE(strcmp(lc_ctype_set, locale_name) == 0); +} + +static mbstate_t s; +static char buf[MB_LEN_MAX + 1]; + +ATF_TC_WITHOUT_HEAD(c16rtomb_c_locale_test); +ATF_TC_BODY(c16rtomb_c_locale_test, tc) +{ + + require_lc_ctype("C"); /* * If the buffer argument is NULL, c16 is implicitly 0, @@ -80,11 +94,13 @@ ATF_TC_BODY(c16rtomb_test, tc) ATF_REQUIRE(c16rtomb(buf, 0xdca9, &s) == (size_t)-1); ATF_REQUIRE(errno == EILSEQ); ATF_REQUIRE((unsigned char)buf[0] == 0xcc); +} - /* ISO8859-1. */ +ATF_TC_WITHOUT_HEAD(c16rtomb_iso_8859_1_test); +ATF_TC_BODY(c16rtomb_iso_8859_1_test, tc) +{ - ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "en_US.ISO8859-1"), - "en_US.ISO8859-1") == 0); + require_lc_ctype("en_US.ISO8859-1"); /* Unicode character 'Euro sign'. */ memset(&s, 0, sizeof(s)); @@ -92,21 +108,26 @@ ATF_TC_BODY(c16rtomb_test, tc) ATF_REQUIRE(c16rtomb(buf, 0x20ac, &s) == (size_t)-1); ATF_REQUIRE(errno == EILSEQ); ATF_REQUIRE((unsigned char)buf[0] == 0xcc); +} - /* ISO8859-15. */ +ATF_TC_WITHOUT_HEAD(c16rtomb_iso_8859_15_test); +ATF_TC_BODY(c16rtomb_iso_8859_15_test, tc) +{ - ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "en_US.ISO8859-15"), - "en_US.ISO8859-15") == 0); + require_lc_ctype("en_US.ISO8859-15"); /* Unicode character 'Euro sign'. */ memset(&s, 0, sizeof(s)); memset(buf, 0xcc, sizeof(buf)); ATF_REQUIRE(c16rtomb(buf, 0x20ac, &s) == 1); ATF_REQUIRE((unsigned char)buf[0] == 0xa4 && (unsigned char)buf[1] == 0xcc); +} - /* UTF-8. */ +ATF_TC_WITHOUT_HEAD(c16rtomb_utf_8_test); +ATF_TC_BODY(c16rtomb_utf_8_test, tc) +{ - ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "en_US.UTF-8"), "en_US.UTF-8") == 0); + require_lc_ctype("en_US.UTF-8"); /* Unicode character 'Pile of poo'. */ memset(&s, 0, sizeof(s)); @@ -136,7 +157,10 @@ ATF_TC_BODY(c16rtomb_test, tc) ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, c16rtomb_test); + ATF_TP_ADD_TC(tp, c16rtomb_c_locale_test); + ATF_TP_ADD_TC(tp, c16rtomb_iso_8859_1_test); + ATF_TP_ADD_TC(tp, c16rtomb_iso_8859_15_test); + ATF_TP_ADD_TC(tp, c16rtomb_utf_8_test); return (atf_no_error()); } Modified: head/lib/libc/tests/locale/mbrtoc16_test.c ============================================================================== --- head/lib/libc/tests/locale/mbrtoc16_test.c Sun Nov 15 03:56:09 2015 (r290842) +++ head/lib/libc/tests/locale/mbrtoc16_test.c Sun Nov 15 04:33:14 2015 (r290843) @@ -42,16 +42,27 @@ __FBSDID("$FreeBSD$"); #include -ATF_TC_WITHOUT_HEAD(mbrtoc16_test); -ATF_TC_BODY(mbrtoc16_test, tc) +static void +require_lc_ctype(const char *locale_name) { - mbstate_t s; - size_t len; - char16_t c16; - - /* - * C/POSIX locale. - */ + char *lc_ctype_set; + + lc_ctype_set = setlocale(LC_CTYPE, locale_name); + if (lc_ctype_set == NULL) + atf_tc_fail("setlocale(LC_CTYPE, \"%s\") failed; errno=%d", + locale_name, errno); + + ATF_REQUIRE(strcmp(lc_ctype_set, locale_name) == 0); +} + +static mbstate_t s; +static char16_t c16; + +ATF_TC_WITHOUT_HEAD(mbrtoc16_c_locale_test); +ATF_TC_BODY(mbrtoc16_c_locale_test, tc) +{ + + require_lc_ctype("C"); /* Null wide character, internal state. */ ATF_REQUIRE(mbrtoc16(&c16, "", 1, NULL) == 0); @@ -91,35 +102,37 @@ ATF_TC_BODY(mbrtoc16_test, tc) ATF_REQUIRE(mbrtoc16(&c16, "C", 1, &s) == 1); ATF_REQUIRE(c16 == L'C'); - /* - * ISO-8859-1. - */ +} + +ATF_TC_WITHOUT_HEAD(mbrtoc16_iso_8859_1_test); +ATF_TC_BODY(mbrtoc16_iso_8859_1_test, tc) +{ - ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "en_US.ISO8859-1"), - "en_US.ISO8859-1") == 0); + require_lc_ctype("en_US.ISO8859-1"); /* Currency sign. */ memset(&s, 0, sizeof(s)); ATF_REQUIRE(mbrtoc16(&c16, "\xa4", 1, &s) == 1); ATF_REQUIRE(c16 == 0xa4); +} - /* - * ISO-8859-15. - */ +ATF_TC_WITHOUT_HEAD(mbrtoc16_iso_8859_15_test); +ATF_TC_BODY(mbrtoc16_iso_8859_15_test, tc) +{ - ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "en_US.ISO8859-15"), - "en_US.ISO8859-15") == 0); + require_lc_ctype("en_US.ISO8859-15"); /* Euro sign. */ memset(&s, 0, sizeof(s)); ATF_REQUIRE(mbrtoc16(&c16, "\xa4", 1, &s) == 1); ATF_REQUIRE(c16 == 0x20ac); +} - /* - * UTF-8. - */ +ATF_TC_WITHOUT_HEAD(mbrtoc16_utf_8_test); +ATF_TC_BODY(mbrtoc16_utf_8_test, tc) +{ - ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "en_US.UTF-8"), "en_US.UTF-8") == 0); + require_lc_ctype("en_US.UTF-8"); /* Null wide character, internal state. */ ATF_REQUIRE(mbrtoc16(NULL, 0, 0, NULL) == 0); @@ -192,7 +205,10 @@ ATF_TC_BODY(mbrtoc16_test, tc) ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, mbrtoc16_test); + ATF_TP_ADD_TC(tp, mbrtoc16_c_locale_test); + ATF_TP_ADD_TC(tp, mbrtoc16_iso_8859_1_test); + ATF_TP_ADD_TC(tp, mbrtoc16_iso_8859_15_test); + ATF_TP_ADD_TC(tp, mbrtoc16_utf_8_test); return (atf_no_error()); }