diff options
author | schwarze@openbsd.org <schwarze@openbsd.org> | 2016-05-26 19:14:25 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2016-06-08 11:45:05 +1000 |
commit | 016881eb33a7948028848c90f4c7ac42e3af0e87 (patch) | |
tree | 7cf710d33f11d854e16a71442d9bf5e0acc9b8c5 /regress/unittests | |
parent | d4219028bdef448e089376f3afe81ef6079da264 (diff) |
upstream commit
test the new utf8 module
Upstream-Regress-ID: c923d05a20e84e4ef152cbec947fdc4ce6eabbe3
Diffstat (limited to 'regress/unittests')
-rw-r--r-- | regress/unittests/Makefile | 4 | ||||
-rw-r--r-- | regress/unittests/utf8/Makefile | 12 | ||||
-rw-r--r-- | regress/unittests/utf8/tests.c | 63 |
3 files changed, 77 insertions, 2 deletions
diff --git a/regress/unittests/Makefile b/regress/unittests/Makefile index d3d90823f..0a95d4b20 100644 --- a/regress/unittests/Makefile +++ b/regress/unittests/Makefile | |||
@@ -1,5 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.5 2015/02/16 22:21:03 djm Exp $ | 1 | # $OpenBSD: Makefile,v 1.6 2016/05/26 19:14:25 schwarze Exp $ |
2 | REGRESS_FAIL_EARLY= yes | 2 | REGRESS_FAIL_EARLY= yes |
3 | SUBDIR= test_helper sshbuf sshkey bitmap kex hostkeys | 3 | SUBDIR= test_helper sshbuf sshkey bitmap kex hostkeys utf8 |
4 | 4 | ||
5 | .include <bsd.subdir.mk> | 5 | .include <bsd.subdir.mk> |
diff --git a/regress/unittests/utf8/Makefile b/regress/unittests/utf8/Makefile new file mode 100644 index 000000000..b55847c77 --- /dev/null +++ b/regress/unittests/utf8/Makefile | |||
@@ -0,0 +1,12 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2016/05/26 19:14:25 schwarze Exp $ | ||
2 | |||
3 | TEST_ENV= "MALLOC_OPTIONS=AFGJPRX" | ||
4 | |||
5 | PROG=test_utf8 | ||
6 | SRCS=tests.c | ||
7 | REGRESS_TARGETS=run-regress-${PROG} | ||
8 | |||
9 | run-regress-${PROG}: ${PROG} | ||
10 | env ${TEST_ENV} ./${PROG} | ||
11 | |||
12 | .include <bsd.regress.mk> | ||
diff --git a/regress/unittests/utf8/tests.c b/regress/unittests/utf8/tests.c new file mode 100644 index 000000000..d18cadc5d --- /dev/null +++ b/regress/unittests/utf8/tests.c | |||
@@ -0,0 +1,63 @@ | |||
1 | /* $OpenBSD: tests.c,v 1.1 2016/05/26 19:14:25 schwarze Exp $ */ | ||
2 | /* | ||
3 | * Regress test for the utf8.h *mprintf() API | ||
4 | * | ||
5 | * Written by Ingo Schwarze <schwarze@openbsd.org> in 2016 | ||
6 | * and placed in the public domain. | ||
7 | */ | ||
8 | |||
9 | #include <locale.h> | ||
10 | #include <string.h> | ||
11 | |||
12 | #include "test_helper.h" | ||
13 | |||
14 | #include "utf8.h" | ||
15 | |||
16 | void one(const char *, const char *, int, int, int, const char *); | ||
17 | |||
18 | void | ||
19 | one(const char *name, const char *mbs, int width, | ||
20 | int wantwidth, int wantlen, const char *wants) | ||
21 | { | ||
22 | char buf[16]; | ||
23 | int *wp; | ||
24 | int len; | ||
25 | |||
26 | if (wantlen == -2) | ||
27 | wantlen = strlen(wants); | ||
28 | (void)strlcpy(buf, "utf8_", sizeof(buf)); | ||
29 | (void)strlcat(buf, name, sizeof(buf)); | ||
30 | TEST_START(buf); | ||
31 | wp = wantwidth == -2 ? NULL : &width; | ||
32 | len = snmprintf(buf, sizeof(buf), wp, "%s", mbs); | ||
33 | ASSERT_INT_EQ(len, wantlen); | ||
34 | ASSERT_STRING_EQ(buf, wants); | ||
35 | ASSERT_INT_EQ(width, wantwidth); | ||
36 | TEST_DONE(); | ||
37 | } | ||
38 | |||
39 | void | ||
40 | tests(void) | ||
41 | { | ||
42 | char *loc; | ||
43 | |||
44 | TEST_START("utf8_setlocale"); | ||
45 | loc = setlocale(LC_CTYPE, "en_US.UTF-8"); | ||
46 | ASSERT_PTR_NE(loc, NULL); | ||
47 | TEST_DONE(); | ||
48 | |||
49 | one("ascii", "x", -2, -2, -2, "x"); | ||
50 | one("newline", "a\nb", -2, -2, -2, "a\nb"); | ||
51 | one("cr", "a\rb", -2, -2, -2, "a\rb"); | ||
52 | one("tab", "a\tb", -2, -2, -2, "a\tb"); | ||
53 | one("esc", "\033x", -2, -2, -2, "\\033x"); | ||
54 | one("inv_badbyte", "\377x", -2, -2, -2, "\\377x"); | ||
55 | one("inv_nocont", "\341x", -2, -2, -2, "\\341x"); | ||
56 | one("inv_nolead", "a\200b", -2, -2, -2, "a\\200b"); | ||
57 | one("sz_ascii", "1234567890123456", -2, -2, 16, "123456789012345"); | ||
58 | one("sz_esc", "123456789012\033", -2, -2, 16, "123456789012"); | ||
59 | one("width_ascii", "123", 2, 2, -1, "12"); | ||
60 | one("width_double", "a\343\201\201", 2, 1, -1, "a"); | ||
61 | one("double_fit", "a\343\201\201", 3, 3, 4, "a\343\201\201"); | ||
62 | one("double_spc", "a\343\201\201", 4, 3, 4, "a\343\201\201"); | ||
63 | } | ||