1#include <array_length.h>
2#include <locale.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <wchar.h>
6
7/* This is the relevant piece from the charmap:
8<UFF61> /x8e/xa1 HALFWIDTH IDEOGRAPHIC FULL STOP
9<UFF62> /x8e/xa2 HALFWIDTH LEFT CORNER BRACKET
10<UFF63> /x8e/xa3 HALFWIDTH RIGHT CORNER BRACKET
11<UFF64> /x8e/xa4 HALFWIDTH IDEOGRAPHIC COMMA
12 */
13
14const char input[] = "\x8e\xa1g\x8e\xa2h\x8e\xa3i\x8e\xa4j";
15
16static int
17do_test (void)
18{
19 wchar_t buf[1000];
20 int result = 0;
21 ssize_t n;
22
23 if (setlocale (LC_ALL, "ja_JP.EUC-JP") == NULL)
24 {
25 puts (s: "cannot set locale");
26 exit (1);
27 }
28
29#define CHECK(fmt, nexp, exp) \
30 n = swprintf (buf, array_length (buf), fmt, input); \
31 if (n != nexp) \
32 { \
33 printf ("swprintf (.., .., L\"%ls\", \"%ls\") return %d, not %d\n", \
34 fmt, (wchar_t*) input, (int) n, (int) nexp); \
35 result = 1; \
36 } \
37 else if (wcscmp (buf, exp) != 0) \
38 { \
39 printf ("\
40swprintf (.., .., L\"%ls\", \"%ls\") produced \"%ls\", not \"%ls\"\n", \
41 fmt, (wchar_t *) input, buf, exp ); \
42 result = 1; \
43 }
44
45 CHECK (L"[%-6.0s]", 8, L"[ ]");
46 CHECK (L"[%-6.1s]", 8, L"[\xff61 ]");
47 CHECK (L"[%-6.2s]", 8, L"[\xff61g ]");
48 CHECK (L"[%-6.3s]", 8, L"[\xff61g\xff62 ]");
49 CHECK (L"[%-6.4s]", 8, L"[\xff61g\xff62h ]");
50 CHECK (L"[%-6.5s]", 8, L"[\xff61g\xff62h\xff63 ]");
51 CHECK (L"[%-6.6s]", 8, L"[\xff61g\xff62h\xff63i]");
52 CHECK (L"[%-6.7s]", 9, L"[\xff61g\xff62h\xff63i\xff64]");
53 CHECK (L"[%-6.8s]", 10, L"[\xff61g\xff62h\xff63i\xff64j]");
54
55 return result;
56}
57
58#define TEST_FUNCTION do_test ()
59#include "../test-skeleton.c"
60

source code of glibc/stdio-common/tst-swprintf.c