summaryrefslogtreecommitdiff
path: root/regress/usr.bin/ssh/unittests
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2017-02-19 00:11:30 +0000
committerDamien Miller <djm@cvs.openbsd.org>2017-02-19 00:11:30 +0000
commit6e1e6e53221a5a76383314557e2ea810d2f7367e (patch)
tree89c7cf3bd958a08ad5c9cbd846463409e3017186 /regress/usr.bin/ssh/unittests
parent52aef302ba93e9fe72eb9a40341be0826c7bc7ff (diff)
add test cases for C locale; ok schwarze@
Diffstat (limited to 'regress/usr.bin/ssh/unittests')
-rw-r--r--regress/usr.bin/ssh/unittests/utf8/tests.c65
1 files changed, 42 insertions, 23 deletions
diff --git a/regress/usr.bin/ssh/unittests/utf8/tests.c b/regress/usr.bin/ssh/unittests/utf8/tests.c
index 1f1fea1bcca..d857a894b4e 100644
--- a/regress/usr.bin/ssh/unittests/utf8/tests.c
+++ b/regress/usr.bin/ssh/unittests/utf8/tests.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tests.c,v 1.3 2016/12/19 04:55:18 djm Exp $ */
+/* $OpenBSD: tests.c,v 1.4 2017/02/19 00:11:29 djm Exp $ */
/*
* Regress test for the utf8.h *mprintf() API
*
@@ -13,10 +13,7 @@
#include "utf8.h"
-void badarg(void);
-void one(const char *, const char *, int, int, int, const char *);
-
-void
+static void
badarg(void)
{
char buf[16];
@@ -31,8 +28,8 @@ badarg(void)
TEST_DONE();
}
-void
-one(const char *name, const char *mbs, int width,
+static void
+one(int utf8, const char *name, const char *mbs, int width,
int wantwidth, int wantlen, const char *wants)
{
char buf[16];
@@ -41,7 +38,7 @@ one(const char *name, const char *mbs, int width,
if (wantlen == -2)
wantlen = strlen(wants);
- (void)strlcpy(buf, "utf8_", sizeof(buf));
+ (void)strlcpy(buf, utf8 ? "utf8_" : "c_", sizeof(buf));
(void)strlcat(buf, name, sizeof(buf));
TEST_START(buf);
wp = wantwidth == -2 ? NULL : &width;
@@ -63,19 +60,41 @@ tests(void)
TEST_DONE();
badarg();
- one("empty", "", 2, 0, 0, "");
- 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");
+ one(1, "empty", "", 2, 0, 0, "");
+ one(1, "ascii", "x", -2, -2, -2, "x");
+ one(1, "newline", "a\nb", -2, -2, -2, "a\nb");
+ one(1, "cr", "a\rb", -2, -2, -2, "a\rb");
+ one(1, "tab", "a\tb", -2, -2, -2, "a\tb");
+ one(1, "esc", "\033x", -2, -2, -2, "\\033x");
+ one(1, "inv_badbyte", "\377x", -2, -2, -2, "\\377x");
+ one(1, "inv_nocont", "\341x", -2, -2, -2, "\\341x");
+ one(1, "inv_nolead", "a\200b", -2, -2, -2, "a\\200b");
+ one(1, "sz_ascii", "1234567890123456", -2, -2, 16, "123456789012345");
+ one(1, "sz_esc", "123456789012\033", -2, -2, 16, "123456789012");
+ one(1, "width_ascii", "123", 2, 2, -1, "12");
+ one(1, "width_double", "a\343\201\201", 2, 1, -1, "a");
+ one(1, "double_fit", "a\343\201\201", 3, 3, 4, "a\343\201\201");
+ one(1, "double_spc", "a\343\201\201", 4, 3, 4, "a\343\201\201");
+
+ TEST_START("C_setlocale");
+ loc = setlocale(LC_CTYPE, "C");
+ ASSERT_PTR_NE(loc, NULL);
+ TEST_DONE();
+
+ badarg();
+ one(0, "empty", "", 2, 0, 0, "");
+ one(0, "ascii", "x", -2, -2, -2, "x");
+ one(0, "newline", "a\nb", -2, -2, -2, "a\nb");
+ one(0, "cr", "a\rb", -2, -2, -2, "a\rb");
+ one(0, "tab", "a\tb", -2, -2, -2, "a\tb");
+ one(0, "esc", "\033x", -2, -2, -2, "\\033x");
+ one(0, "inv_badbyte", "\377x", -2, -2, -2, "\\377x");
+ one(0, "inv_nocont", "\341x", -2, -2, -2, "\\341x");
+ one(0, "inv_nolead", "a\200b", -2, -2, -2, "a\\200b");
+ one(0, "sz_ascii", "1234567890123456", -2, -2, 16, "123456789012345");
+ one(0, "sz_esc", "123456789012\033", -2, -2, 16, "123456789012");
+ one(0, "width_ascii", "123", 2, 2, -1, "12");
+ one(0, "width_double", "a\343\201\201", 2, 1, -1, "a");
+ one(0, "double_fit", "a\343\201\201", 7, 5, -1, "a\\343");
+ one(0, "double_spc", "a\343\201\201", 13, 13, 13, "a\\343\\201\\201");
}