summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--regress/unittests/utf8/tests.c65
1 files changed, 42 insertions, 23 deletions
diff --git a/regress/unittests/utf8/tests.c b/regress/unittests/utf8/tests.c
index 31f9fe9c3..f0bbca509 100644
--- a/regress/unittests/utf8/tests.c
+++ b/regress/unittests/utf8/tests.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tests.c,v 1.3 2016/12/19 04:55:18 djm Exp $ */ 1/* $OpenBSD: tests.c,v 1.4 2017/02/19 00:11:29 djm Exp $ */
2/* 2/*
3 * Regress test for the utf8.h *mprintf() API 3 * Regress test for the utf8.h *mprintf() API
4 * 4 *
@@ -15,10 +15,7 @@
15 15
16#include "utf8.h" 16#include "utf8.h"
17 17
18void badarg(void); 18static void
19void one(const char *, const char *, int, int, int, const char *);
20
21void
22badarg(void) 19badarg(void)
23{ 20{
24 char buf[16]; 21 char buf[16];
@@ -33,8 +30,8 @@ badarg(void)
33 TEST_DONE(); 30 TEST_DONE();
34} 31}
35 32
36void 33static void
37one(const char *name, const char *mbs, int width, 34one(int utf8, const char *name, const char *mbs, int width,
38 int wantwidth, int wantlen, const char *wants) 35 int wantwidth, int wantlen, const char *wants)
39{ 36{
40 char buf[16]; 37 char buf[16];
@@ -43,7 +40,7 @@ one(const char *name, const char *mbs, int width,
43 40
44 if (wantlen == -2) 41 if (wantlen == -2)
45 wantlen = strlen(wants); 42 wantlen = strlen(wants);
46 (void)strlcpy(buf, "utf8_", sizeof(buf)); 43 (void)strlcpy(buf, utf8 ? "utf8_" : "c_", sizeof(buf));
47 (void)strlcat(buf, name, sizeof(buf)); 44 (void)strlcat(buf, name, sizeof(buf));
48 TEST_START(buf); 45 TEST_START(buf);
49 wp = wantwidth == -2 ? NULL : &width; 46 wp = wantwidth == -2 ? NULL : &width;
@@ -65,19 +62,41 @@ tests(void)
65 TEST_DONE(); 62 TEST_DONE();
66 63
67 badarg(); 64 badarg();
68 one("empty", "", 2, 0, 0, ""); 65 one(1, "empty", "", 2, 0, 0, "");
69 one("ascii", "x", -2, -2, -2, "x"); 66 one(1, "ascii", "x", -2, -2, -2, "x");
70 one("newline", "a\nb", -2, -2, -2, "a\nb"); 67 one(1, "newline", "a\nb", -2, -2, -2, "a\nb");
71 one("cr", "a\rb", -2, -2, -2, "a\rb"); 68 one(1, "cr", "a\rb", -2, -2, -2, "a\rb");
72 one("tab", "a\tb", -2, -2, -2, "a\tb"); 69 one(1, "tab", "a\tb", -2, -2, -2, "a\tb");
73 one("esc", "\033x", -2, -2, -2, "\\033x"); 70 one(1, "esc", "\033x", -2, -2, -2, "\\033x");
74 one("inv_badbyte", "\377x", -2, -2, -2, "\\377x"); 71 one(1, "inv_badbyte", "\377x", -2, -2, -2, "\\377x");
75 one("inv_nocont", "\341x", -2, -2, -2, "\\341x"); 72 one(1, "inv_nocont", "\341x", -2, -2, -2, "\\341x");
76 one("inv_nolead", "a\200b", -2, -2, -2, "a\\200b"); 73 one(1, "inv_nolead", "a\200b", -2, -2, -2, "a\\200b");
77 one("sz_ascii", "1234567890123456", -2, -2, 16, "123456789012345"); 74 one(1, "sz_ascii", "1234567890123456", -2, -2, 16, "123456789012345");
78 one("sz_esc", "123456789012\033", -2, -2, 16, "123456789012"); 75 one(1, "sz_esc", "123456789012\033", -2, -2, 16, "123456789012");
79 one("width_ascii", "123", 2, 2, -1, "12"); 76 one(1, "width_ascii", "123", 2, 2, -1, "12");
80 one("width_double", "a\343\201\201", 2, 1, -1, "a"); 77 one(1, "width_double", "a\343\201\201", 2, 1, -1, "a");
81 one("double_fit", "a\343\201\201", 3, 3, 4, "a\343\201\201"); 78 one(1, "double_fit", "a\343\201\201", 3, 3, 4, "a\343\201\201");
82 one("double_spc", "a\343\201\201", 4, 3, 4, "a\343\201\201"); 79 one(1, "double_spc", "a\343\201\201", 4, 3, 4, "a\343\201\201");
80
81 TEST_START("C_setlocale");
82 loc = setlocale(LC_CTYPE, "C");
83 ASSERT_PTR_NE(loc, NULL);
84 TEST_DONE();
85
86 badarg();
87 one(0, "empty", "", 2, 0, 0, "");
88 one(0, "ascii", "x", -2, -2, -2, "x");
89 one(0, "newline", "a\nb", -2, -2, -2, "a\nb");
90 one(0, "cr", "a\rb", -2, -2, -2, "a\rb");
91 one(0, "tab", "a\tb", -2, -2, -2, "a\tb");
92 one(0, "esc", "\033x", -2, -2, -2, "\\033x");
93 one(0, "inv_badbyte", "\377x", -2, -2, -2, "\\377x");
94 one(0, "inv_nocont", "\341x", -2, -2, -2, "\\341x");
95 one(0, "inv_nolead", "a\200b", -2, -2, -2, "a\\200b");
96 one(0, "sz_ascii", "1234567890123456", -2, -2, 16, "123456789012345");
97 one(0, "sz_esc", "123456789012\033", -2, -2, 16, "123456789012");
98 one(0, "width_ascii", "123", 2, 2, -1, "12");
99 one(0, "width_double", "a\343\201\201", 2, 1, -1, "a");
100 one(0, "double_fit", "a\343\201\201", 7, 5, -1, "a\\343");
101 one(0, "double_spc", "a\343\201\201", 13, 13, 13, "a\\343\\201\\201");
83} 102}