summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/lib/libc/gen/t_vis.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/netbsd-tests/lib/libc/gen/t_vis.c')
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/t_vis.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/contrib/netbsd-tests/lib/libc/gen/t_vis.c b/contrib/netbsd-tests/lib/libc/gen/t_vis.c
index 525bafa..adb0930 100644
--- a/contrib/netbsd-tests/lib/libc/gen/t_vis.c
+++ b/contrib/netbsd-tests/lib/libc/gen/t_vis.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_vis.c,v 1.7 2014/09/08 19:01:03 christos Exp $ */
+/* $NetBSD: t_vis.c,v 1.9 2017/01/10 15:16:57 christos Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -32,6 +32,7 @@
#include <string.h>
#include <stdlib.h>
+#include <locale.h>
#include <err.h>
#include <vis.h>
@@ -143,6 +144,37 @@ ATF_TC_BODY(strunvis_hex, tc)
}
}
+#ifdef VIS_NOLOCALE
+ATF_TC(strvis_locale);
+ATF_TC_HEAD(strvis_locale, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test strvis(3) with locale");
+}
+
+ATF_TC_BODY(strvis_locale, tc)
+{
+ char s[256], cd[sizeof(s) * 4 + 1], jd[sizeof(cd)], *ol;
+ int jr, cr;
+
+ for (size_t i = 0; i < sizeof(s) - 1; i++)
+ s[i] = i + 1;
+ s[sizeof(s) - 1] = '\0';
+
+ ol = setlocale(LC_CTYPE, "ja_JP.UTF-8");
+ ATF_REQUIRE(ol != NULL);
+ jr = strvisx(jd, s, sizeof(s), VIS_WHITE | VIS_NOLOCALE);
+ ATF_REQUIRE(jr != -1);
+ ol = strdup(ol);
+ ATF_REQUIRE(ol != NULL);
+ ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL);
+ cr = strvisx(cd, s, sizeof(s), VIS_WHITE);
+ ATF_REQUIRE(jr == cr);
+ ATF_REQUIRE(memcmp(jd, cd, jr) == 0);
+ setlocale(LC_CTYPE, ol);
+ free(ol);
+}
+#endif /* VIS_NOLOCALE */
+
ATF_TP_ADD_TCS(tp)
{
@@ -150,6 +182,9 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, strvis_null);
ATF_TP_ADD_TC(tp, strvis_empty);
ATF_TP_ADD_TC(tp, strunvis_hex);
+#ifdef VIS_NOLOCALE
+ ATF_TP_ADD_TC(tp, strvis_locale);
+#endif /* VIS_NOLOCALE */
return atf_no_error();
}
OpenPOWER on IntegriCloud