File: tst-swprintf.c

package info (click to toggle)
glibc 2.24-11+deb9u4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 225,852 kB
  • sloc: ansic: 996,505; asm: 261,827; sh: 10,484; makefile: 9,856; cpp: 4,169; python: 3,971; perl: 2,254; awk: 1,753; pascal: 1,521; yacc: 291; sed: 80
file content (59 lines) | stat: -rw-r--r-- 1,782 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>

/* This is the relevant piece from the charmap:
<UFF61>     /x8e/xa1     HALFWIDTH IDEOGRAPHIC FULL STOP
<UFF62>     /x8e/xa2     HALFWIDTH LEFT CORNER BRACKET
<UFF63>     /x8e/xa3     HALFWIDTH RIGHT CORNER BRACKET
<UFF64>     /x8e/xa4     HALFWIDTH IDEOGRAPHIC COMMA
 */

const char input[] = "\x8e\xa1g\x8e\xa2h\x8e\xa3i\x8e\xa4j";

static int
do_test (void)
{
  wchar_t buf[1000];
#define nbuf (sizeof (buf) / sizeof (buf[0]))
  int result = 0;
  ssize_t n;

  if (setlocale (LC_ALL, "ja_JP.EUC-JP") == NULL)
    {
      puts ("cannot set locale");
      exit (1);
    }

#define CHECK(fmt, nexp, exp) \
  n = swprintf (buf, nbuf, fmt, input);					      \
  if (n != nexp)							      \
    {									      \
      printf ("swprintf (.., .., L\"%ls\", \"%ls\") return %d, not %d\n",     \
	      fmt, (wchar_t*) input, (int) n, (int) nexp);		      \
      result = 1;							      \
    }									      \
  else if (wcscmp (buf, exp) != 0)					      \
    {									      \
      printf ("\
swprintf (.., .., L\"%ls\", \"%ls\") produced \"%ls\", not \"%ls\"\n",	      \
	     fmt, (wchar_t *) input, buf, exp );			      \
      result = 1;							      \
    }

  CHECK (L"[%-6.0s]", 8, L"[      ]");
  CHECK (L"[%-6.1s]", 8, L"[\xff61     ]");
  CHECK (L"[%-6.2s]", 8, L"[\xff61g    ]");
  CHECK (L"[%-6.3s]", 8, L"[\xff61g\xff62   ]");
  CHECK (L"[%-6.4s]", 8, L"[\xff61g\xff62h  ]");
  CHECK (L"[%-6.5s]", 8, L"[\xff61g\xff62h\xff63 ]");
  CHECK (L"[%-6.6s]", 8, L"[\xff61g\xff62h\xff63i]");
  CHECK (L"[%-6.7s]", 9, L"[\xff61g\xff62h\xff63i\xff64]");
  CHECK (L"[%-6.8s]", 10, L"[\xff61g\xff62h\xff63i\xff64j]");

  return result;
}

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"