summaryrefslogtreecommitdiff
path: root/regress/usr.bin/ssh
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2016-05-26 19:14:26 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2016-05-26 19:14:26 +0000
commit4912d086a88088fdc5e0cb7d356d37c52c75a1a5 (patch)
treea799e9ded7305476d926cced77af7e6f5de62175 /regress/usr.bin/ssh
parent20d926aad799b0038d002d1b049832e83da441f9 (diff)
test the new utf8 module
Diffstat (limited to 'regress/usr.bin/ssh')
-rw-r--r--regress/usr.bin/ssh/unittests/Makefile4
-rw-r--r--regress/usr.bin/ssh/unittests/utf8/Makefile12
-rw-r--r--regress/usr.bin/ssh/unittests/utf8/tests.c63
3 files changed, 77 insertions, 2 deletions
diff --git a/regress/usr.bin/ssh/unittests/Makefile b/regress/usr.bin/ssh/unittests/Makefile
index d3d90823f90..0a95d4b205f 100644
--- a/regress/usr.bin/ssh/unittests/Makefile
+++ b/regress/usr.bin/ssh/unittests/Makefile
@@ -1,5 +1,5 @@
-# $OpenBSD: Makefile,v 1.5 2015/02/16 22:21:03 djm Exp $
+# $OpenBSD: Makefile,v 1.6 2016/05/26 19:14:25 schwarze Exp $
REGRESS_FAIL_EARLY= yes
-SUBDIR= test_helper sshbuf sshkey bitmap kex hostkeys
+SUBDIR= test_helper sshbuf sshkey bitmap kex hostkeys utf8
.include <bsd.subdir.mk>
diff --git a/regress/usr.bin/ssh/unittests/utf8/Makefile b/regress/usr.bin/ssh/unittests/utf8/Makefile
new file mode 100644
index 00000000000..b55847c7748
--- /dev/null
+++ b/regress/usr.bin/ssh/unittests/utf8/Makefile
@@ -0,0 +1,12 @@
+# $OpenBSD: Makefile,v 1.1 2016/05/26 19:14:25 schwarze Exp $
+
+TEST_ENV= "MALLOC_OPTIONS=AFGJPRX"
+
+PROG=test_utf8
+SRCS=tests.c
+REGRESS_TARGETS=run-regress-${PROG}
+
+run-regress-${PROG}: ${PROG}
+ env ${TEST_ENV} ./${PROG}
+
+.include <bsd.regress.mk>
diff --git a/regress/usr.bin/ssh/unittests/utf8/tests.c b/regress/usr.bin/ssh/unittests/utf8/tests.c
new file mode 100644
index 00000000000..d18cadc5d52
--- /dev/null
+++ b/regress/usr.bin/ssh/unittests/utf8/tests.c
@@ -0,0 +1,63 @@
+/* $OpenBSD: tests.c,v 1.1 2016/05/26 19:14:25 schwarze Exp $ */
+/*
+ * Regress test for the utf8.h *mprintf() API
+ *
+ * Written by Ingo Schwarze <schwarze@openbsd.org> in 2016
+ * and placed in the public domain.
+ */
+
+#include <locale.h>
+#include <string.h>
+
+#include "test_helper.h"
+
+#include "utf8.h"
+
+void one(const char *, const char *, int, int, int, const char *);
+
+void
+one(const char *name, const char *mbs, int width,
+ int wantwidth, int wantlen, const char *wants)
+{
+ char buf[16];
+ int *wp;
+ int len;
+
+ if (wantlen == -2)
+ wantlen = strlen(wants);
+ (void)strlcpy(buf, "utf8_", sizeof(buf));
+ (void)strlcat(buf, name, sizeof(buf));
+ TEST_START(buf);
+ wp = wantwidth == -2 ? NULL : &width;
+ len = snmprintf(buf, sizeof(buf), wp, "%s", mbs);
+ ASSERT_INT_EQ(len, wantlen);
+ ASSERT_STRING_EQ(buf, wants);
+ ASSERT_INT_EQ(width, wantwidth);
+ TEST_DONE();
+}
+
+void
+tests(void)
+{
+ char *loc;
+
+ TEST_START("utf8_setlocale");
+ loc = setlocale(LC_CTYPE, "en_US.UTF-8");
+ ASSERT_PTR_NE(loc, NULL);
+ TEST_DONE();
+
+ one("ascii", "x", -2, -2, -2, "x");
+ one("newline", "a\nb", -2, -2, -2, "a\nb");
+ one("cr", "a\rb", -2, -2, -2, "a\rb");
+ one("tab", "a\tb", -2, -2, -2, "a\tb");
+ one("esc", "\033x", -2, -2, -2, "\\033x");
+ one("inv_badbyte", "\377x", -2, -2, -2, "\\377x");
+ one("inv_nocont", "\341x", -2, -2, -2, "\\341x");
+ one("inv_nolead", "a\200b", -2, -2, -2, "a\\200b");
+ one("sz_ascii", "1234567890123456", -2, -2, 16, "123456789012345");
+ one("sz_esc", "123456789012\033", -2, -2, 16, "123456789012");
+ one("width_ascii", "123", 2, 2, -1, "12");
+ one("width_double", "a\343\201\201", 2, 1, -1, "a");
+ one("double_fit", "a\343\201\201", 3, 3, 4, "a\343\201\201");
+ one("double_spc", "a\343\201\201", 4, 3, 4, "a\343\201\201");
+}