summaryrefslogtreecommitdiff
path: root/usr/src/test/libc-tests/tests/printf-9511.c
diff options
context:
space:
mode:
authorYuri Pankov <yuri.pankov@nexenta.com>2018-04-29 21:28:12 +0300
committerHans Rosenfeld <hans.rosenfeld@joyent.com>2018-05-16 12:03:43 +0200
commit804635d7bfa86d5f677fada06cb30420313f1159 (patch)
tree06785df23dd5e2ac2febed8901c51a4403067b85 /usr/src/test/libc-tests/tests/printf-9511.c
parent4540c8e2f029ecd3f040b27b7489b1c9f2d920c0 (diff)
downloadillumos-joyent-804635d7bfa86d5f677fada06cb30420313f1159.tar.gz
9511 printf family isn't aware of multibyte decimal point characters
Reviewed by: Dan McDonald <danmcd@joyent.com> Approved by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
Diffstat (limited to 'usr/src/test/libc-tests/tests/printf-9511.c')
-rw-r--r--usr/src/test/libc-tests/tests/printf-9511.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/usr/src/test/libc-tests/tests/printf-9511.c b/usr/src/test/libc-tests/tests/printf-9511.c
new file mode 100644
index 0000000000..98823f0d10
--- /dev/null
+++ b/usr/src/test/libc-tests/tests/printf-9511.c
@@ -0,0 +1,70 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2018 Nexenta Systems, Inc.
+ */
+
+/*
+ * Note that this file is easiest edited with a UTF-8 capable editor,
+ * as there are embedded UTF-8 symbols in some of the strings.
+ */
+
+#include <err.h>
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+
+struct {
+ const char *locale;
+ const char *convspec;
+ const float fp;
+ const char *expected;
+} fpconv[] = {
+ "C", "%a", 3.2, "0x1.99999a0000000p+1",
+ "C", "%e", 3.2, "3.200000e+00",
+ "C", "%f", 3.2, "3.200000",
+ "C", "%g", 3.2, "3.2",
+ "ar_AE.UTF-8", "%a", 3.2, "0x1٫99999a0000000p+1",
+ "ar_AE.UTF-8", "%e", 3.2, "3٫200000e+00",
+ "ar_AE.UTF-8", "%f", 3.2, "3٫200000",
+ "ar_AE.UTF-8", "%g", 3.2, "3٫2",
+ "en_US.UTF-8", "%a", 3.2, "0x1.99999a0000000p+1",
+ "en_US.UTF-8", "%e", 3.2, "3.200000e+00",
+ "en_US.UTF-8", "%f", 3.2, "3.200000",
+ "en_US.UTF-8", "%g", 3.2, "3.2",
+ "ru_RU.UTF-8", "%a", 3.2, "0x1,99999a0000000p+1",
+ "ru_RU.UTF-8", "%e", 3.2, "3,200000e+00",
+ "ru_RU.UTF-8", "%f", 3.2, "3,200000",
+ "ru_RU.UTF-8", "%g", 3.2, "3,2",
+ NULL, NULL, 0, NULL
+};
+
+int
+main(void)
+{
+ char buf[100];
+ int i;
+
+ for (i = 0; fpconv[i].locale != NULL; i++) {
+ if (setlocale(LC_ALL, fpconv[i].locale) == NULL)
+ err(1, "failed to set locale to %s", fpconv[i].locale);
+
+ (void) sprintf(buf, fpconv[i].convspec, fpconv[i].fp);
+ if (strcmp(fpconv[i].expected, buf) != 0) {
+ errx(1, "locale=%s, convspec=%s, expected=%s, got=%s",
+ fpconv[i].locale, fpconv[i].convspec,
+ fpconv[i].expected, buf);
+ }
+ }
+
+ return (0);
+}