aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/tests/locale
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/tests/locale')
-rw-r--r--lib/libc/tests/locale/Makefile3
-rw-r--r--lib/libc/tests/locale/Makefile.depend1
-rw-r--r--lib/libc/tests/locale/btowc_test.c3
-rw-r--r--lib/libc/tests/locale/c16rtomb_test.c3
-rw-r--r--lib/libc/tests/locale/iswctype_test.c3
-rw-r--r--lib/libc/tests/locale/mblen_test.c3
-rw-r--r--lib/libc/tests/locale/mbrlen_test.c3
-rw-r--r--lib/libc/tests/locale/mbrtoc16_test.c3
-rw-r--r--lib/libc/tests/locale/mbrtowc_test.c3
-rw-r--r--lib/libc/tests/locale/mbsnrtowcs_test.c3
-rw-r--r--lib/libc/tests/locale/mbsrtowcs_test.c3
-rw-r--r--lib/libc/tests/locale/mbstowcs_test.c3
-rw-r--r--lib/libc/tests/locale/mbtowc_test.c3
-rw-r--r--lib/libc/tests/locale/newlocale_test.c111
-rw-r--r--lib/libc/tests/locale/towctrans_test.c3
-rw-r--r--lib/libc/tests/locale/wcrtomb_test.c3
-rw-r--r--lib/libc/tests/locale/wcsnrtombs_test.c3
-rw-r--r--lib/libc/tests/locale/wcsrtombs_test.c3
-rw-r--r--lib/libc/tests/locale/wcstombs_test.c3
-rw-r--r--lib/libc/tests/locale/wctomb_test.c16
20 files changed, 125 insertions, 54 deletions
diff --git a/lib/libc/tests/locale/Makefile b/lib/libc/tests/locale/Makefile
index 83caf8cb3bd3..70905cc58d24 100644
--- a/lib/libc/tests/locale/Makefile
+++ b/lib/libc/tests/locale/Makefile
@@ -1,5 +1,3 @@
-# $FreeBSD$
-
.include <bsd.own.mk>
ATF_TESTS_C+= btowc_test
@@ -13,6 +11,7 @@ ATF_TESTS_C+= mbsnrtowcs_2_test
ATF_TESTS_C+= mbsrtowcs_test
ATF_TESTS_C+= mbstowcs_2_test
ATF_TESTS_C+= mbtowc_2_test
+ATF_TESTS_C+= newlocale_test
ATF_TESTS_C+= towctrans_test
ATF_TESTS_C+= wcrtomb_test
ATF_TESTS_C+= wcsnrtombs_test
diff --git a/lib/libc/tests/locale/Makefile.depend b/lib/libc/tests/locale/Makefile.depend
index 45823695c1bb..e5ddbc552be2 100644
--- a/lib/libc/tests/locale/Makefile.depend
+++ b/lib/libc/tests/locale/Makefile.depend
@@ -1,4 +1,3 @@
-# $FreeBSD$
# Autogenerated - do NOT edit!
DIRDEPS = \
diff --git a/lib/libc/tests/locale/btowc_test.c b/lib/libc/tests/locale/btowc_test.c
index 01a1133e89d5..27e6ff533621 100644
--- a/lib/libc/tests/locale/btowc_test.c
+++ b/lib/libc/tests/locale/btowc_test.c
@@ -31,9 +31,6 @@
* The function is tested in the "C" and "ja_JP.eucJP" locales.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <limits.h>
#include <locale.h>
#include <stdio.h>
diff --git a/lib/libc/tests/locale/c16rtomb_test.c b/lib/libc/tests/locale/c16rtomb_test.c
index ea1f64f7d308..6812fbbc5164 100644
--- a/lib/libc/tests/locale/c16rtomb_test.c
+++ b/lib/libc/tests/locale/c16rtomb_test.c
@@ -30,9 +30,6 @@
* Test program for c16rtomb() as specified by ISO/IEC 9899:2011.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <limits.h>
#include <locale.h>
diff --git a/lib/libc/tests/locale/iswctype_test.c b/lib/libc/tests/locale/iswctype_test.c
index 14e57b4e29a3..79b941522d2b 100644
--- a/lib/libc/tests/locale/iswctype_test.c
+++ b/lib/libc/tests/locale/iswctype_test.c
@@ -31,9 +31,6 @@
* The functions are tested in the "C" and "ja_JP.eucJP" locales.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <errno.h>
#include <locale.h>
diff --git a/lib/libc/tests/locale/mblen_test.c b/lib/libc/tests/locale/mblen_test.c
index fbb938d3e5a6..e081b0d4246a 100644
--- a/lib/libc/tests/locale/mblen_test.c
+++ b/lib/libc/tests/locale/mblen_test.c
@@ -32,9 +32,6 @@
* "ja_JP.eucJP". Other encodings are not tested.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <limits.h>
#include <locale.h>
#include <stdio.h>
diff --git a/lib/libc/tests/locale/mbrlen_test.c b/lib/libc/tests/locale/mbrlen_test.c
index c2bc54832156..50088596fc89 100644
--- a/lib/libc/tests/locale/mbrlen_test.c
+++ b/lib/libc/tests/locale/mbrlen_test.c
@@ -32,9 +32,6 @@
* "ja_JP.eucJP". Other encodings are not tested.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <limits.h>
#include <locale.h>
diff --git a/lib/libc/tests/locale/mbrtoc16_test.c b/lib/libc/tests/locale/mbrtoc16_test.c
index a6289e1004ca..98a140c56fc0 100644
--- a/lib/libc/tests/locale/mbrtoc16_test.c
+++ b/lib/libc/tests/locale/mbrtoc16_test.c
@@ -30,9 +30,6 @@
* Test program for mbrtoc16() as specified by ISO/IEC 9899:2011.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <limits.h>
#include <locale.h>
diff --git a/lib/libc/tests/locale/mbrtowc_test.c b/lib/libc/tests/locale/mbrtowc_test.c
index 37e0bfd6fbaa..df611a7df573 100644
--- a/lib/libc/tests/locale/mbrtowc_test.c
+++ b/lib/libc/tests/locale/mbrtowc_test.c
@@ -32,9 +32,6 @@
* "ja_JP.eucJP". Other encodings are not tested.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <limits.h>
#include <locale.h>
diff --git a/lib/libc/tests/locale/mbsnrtowcs_test.c b/lib/libc/tests/locale/mbsnrtowcs_test.c
index 4012b7e99720..a355bc7d7a6a 100644
--- a/lib/libc/tests/locale/mbsnrtowcs_test.c
+++ b/lib/libc/tests/locale/mbsnrtowcs_test.c
@@ -31,9 +31,6 @@
* "ja_JP.eucJP". Other encodings are not tested.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <limits.h>
#include <locale.h>
diff --git a/lib/libc/tests/locale/mbsrtowcs_test.c b/lib/libc/tests/locale/mbsrtowcs_test.c
index 1b9d5c933af1..d8d215fda2ad 100644
--- a/lib/libc/tests/locale/mbsrtowcs_test.c
+++ b/lib/libc/tests/locale/mbsrtowcs_test.c
@@ -32,9 +32,6 @@
* "ja_JP.eucJP". Other encodings are not tested.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <limits.h>
#include <locale.h>
diff --git a/lib/libc/tests/locale/mbstowcs_test.c b/lib/libc/tests/locale/mbstowcs_test.c
index 77b0e9e52f35..404adfd7b19a 100644
--- a/lib/libc/tests/locale/mbstowcs_test.c
+++ b/lib/libc/tests/locale/mbstowcs_test.c
@@ -32,9 +32,6 @@
* "ja_JP.eucJP". Other encodings are not tested.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <limits.h>
#include <locale.h>
diff --git a/lib/libc/tests/locale/mbtowc_test.c b/lib/libc/tests/locale/mbtowc_test.c
index 7c7f80eb5cc4..e5ff276b4610 100644
--- a/lib/libc/tests/locale/mbtowc_test.c
+++ b/lib/libc/tests/locale/mbtowc_test.c
@@ -32,9 +32,6 @@
* "ja_JP.eucJP". Other encodings are not tested.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <limits.h>
#include <locale.h>
#include <stdio.h>
diff --git a/lib/libc/tests/locale/newlocale_test.c b/lib/libc/tests/locale/newlocale_test.c
new file mode 100644
index 000000000000..cb0ebb323a42
--- /dev/null
+++ b/lib/libc/tests/locale/newlocale_test.c
@@ -0,0 +1,111 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright 2023 Yuri Pankov <yuripv@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+
+#include <locale.h>
+
+#include <atf-c.h>
+
+struct {
+ int lpmask;
+ const char *lpname;
+} lparts[] = {
+ { LC_COLLATE_MASK, "LC_COLLATE" },
+ { LC_CTYPE_MASK, "LC_CTYPE" },
+ { LC_MONETARY_MASK, "LC_MONETARY" },
+ { LC_NUMERIC_MASK, "LC_NUMERIC" },
+ { LC_TIME_MASK, "LC_TIME" },
+ { LC_MESSAGES_MASK, "LC_MESSAGES" },
+};
+
+static void
+check_lparts(const char *expected)
+{
+ int i;
+
+ for (i = 0; i < nitems(lparts); i++) {
+ const char *actual;
+
+ actual = querylocale(lparts[i].lpmask, uselocale(NULL));
+ ATF_CHECK_STREQ_MSG(expected, actual, "wrong value for %s",
+ lparts[i].lpname);
+ }
+}
+
+static void
+do_locale_switch(const char *loc1, const char *loc2)
+{
+ locale_t l1, l2;
+
+ /* Create and use the first locale */
+ l1 = newlocale(LC_ALL_MASK, loc1, NULL);
+ ATF_REQUIRE(l1 != NULL);
+ ATF_REQUIRE(uselocale(l1) != NULL);
+ check_lparts(loc1);
+ /*
+ * Create and use second locale, creation deliberately done only after
+ * the first locale check as newlocale() call would previously clobber
+ * the first locale contents.
+ */
+ l2 = newlocale(LC_ALL_MASK, loc2, NULL);
+ ATF_REQUIRE(l2 != NULL);
+ ATF_REQUIRE(uselocale(l2) != NULL);
+ check_lparts(loc2);
+ /* Switch back to first locale */
+ ATF_REQUIRE(uselocale(l1) != NULL);
+ check_lparts(loc1);
+
+ freelocale(l1);
+ freelocale(l2);
+}
+
+/*
+ * PR 255646, 269375: Check that newlocale()/uselocale() used to switch between
+ * C, POSIX, and C.UTF-8 locales (and only these) do not stomp on other locale
+ * contents (collate part specifically).
+ * The issue is cosmetic only as all three have empty collate parts, but we need
+ * to correctly report the one in use in any case.
+ */
+
+ATF_TC_WITHOUT_HEAD(newlocale_c_posix_cu8_test);
+ATF_TC_BODY(newlocale_c_posix_cu8_test, tc)
+{
+ do_locale_switch("C", "POSIX");
+ do_locale_switch("C", "C.UTF-8");
+ do_locale_switch("POSIX", "C");
+ do_locale_switch("POSIX", "C.UTF-8");
+ do_locale_switch("C.UTF-8", "C");
+ do_locale_switch("C.UTF-8", "POSIX");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, newlocale_c_posix_cu8_test);
+
+ return (atf_no_error());
+}
diff --git a/lib/libc/tests/locale/towctrans_test.c b/lib/libc/tests/locale/towctrans_test.c
index bb9d97ca2e54..f34eb554f283 100644
--- a/lib/libc/tests/locale/towctrans_test.c
+++ b/lib/libc/tests/locale/towctrans_test.c
@@ -31,9 +31,6 @@
* The functions are tested in the "C" and "ja_JP.eucJP" locales.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <locale.h>
#include <stdio.h>
#include <string.h>
diff --git a/lib/libc/tests/locale/wcrtomb_test.c b/lib/libc/tests/locale/wcrtomb_test.c
index 09199ba97c99..2bc7cbc2365f 100644
--- a/lib/libc/tests/locale/wcrtomb_test.c
+++ b/lib/libc/tests/locale/wcrtomb_test.c
@@ -32,9 +32,6 @@
* "ja_JP.eucJP". Other encodings are not tested.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <limits.h>
#include <locale.h>
diff --git a/lib/libc/tests/locale/wcsnrtombs_test.c b/lib/libc/tests/locale/wcsnrtombs_test.c
index 2e330a10ad83..8764c1567066 100644
--- a/lib/libc/tests/locale/wcsnrtombs_test.c
+++ b/lib/libc/tests/locale/wcsnrtombs_test.c
@@ -31,9 +31,6 @@
* "ja_JP.eucJP". Other encodings are not tested.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <limits.h>
#include <locale.h>
diff --git a/lib/libc/tests/locale/wcsrtombs_test.c b/lib/libc/tests/locale/wcsrtombs_test.c
index 4c3455a87769..dcb111dfd87c 100644
--- a/lib/libc/tests/locale/wcsrtombs_test.c
+++ b/lib/libc/tests/locale/wcsrtombs_test.c
@@ -32,9 +32,6 @@
* "ja_JP.eucJP". Other encodings are not tested.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <limits.h>
#include <locale.h>
diff --git a/lib/libc/tests/locale/wcstombs_test.c b/lib/libc/tests/locale/wcstombs_test.c
index f3fcd81001f1..2506be2806f6 100644
--- a/lib/libc/tests/locale/wcstombs_test.c
+++ b/lib/libc/tests/locale/wcstombs_test.c
@@ -32,9 +32,6 @@
* "ja_JP.eucJP". Other encodings are not tested.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <limits.h>
#include <locale.h>
diff --git a/lib/libc/tests/locale/wctomb_test.c b/lib/libc/tests/locale/wctomb_test.c
index 255cda432d7d..ef2a6dcbe1e3 100644
--- a/lib/libc/tests/locale/wctomb_test.c
+++ b/lib/libc/tests/locale/wctomb_test.c
@@ -32,9 +32,6 @@
* "ja_JP.eucJP". Other encodings are not tested.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <limits.h>
#include <locale.h>
@@ -44,6 +41,18 @@ __FBSDID("$FreeBSD$");
#include <atf-c.h>
+ATF_TC_WITHOUT_HEAD(euccs1_test);
+ATF_TC_BODY(euccs1_test, tc)
+{
+ wchar_t wc = 0x8e000000;
+ char buf[MB_LEN_MAX];
+
+ ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "zh_CN.eucCN"),
+ "zh_CN.eucCN") == 0);
+
+ ATF_REQUIRE(wctomb(&buf[0], wc) == 4);
+}
+
ATF_TC_WITHOUT_HEAD(wctomb_test);
ATF_TC_BODY(wctomb_test, tc)
{
@@ -107,6 +116,7 @@ ATF_TC_BODY(wctomb_test, tc)
ATF_TP_ADD_TCS(tp)
{
+ ATF_TP_ADD_TC(tp, euccs1_test);
ATF_TP_ADD_TC(tp, wctomb_test);
return (atf_no_error());