Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Nov 2015 04:33:15 +0000 (UTC)
From:      Garrett Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r290843 - head/lib/libc/tests/locale
Message-ID:  <201511150433.tAF4XFg1093999@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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-c.h>
 
-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-c.h>
 
-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());
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201511150433.tAF4XFg1093999>