~ubuntu-branches/ubuntu/natty/diffutils/natty

« back to all changes in this revision

Viewing changes to gnulib-tests/test-wcwidth.c

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2010-05-04 20:38:00 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100504203800-f67xd9rsa9xl9qqj
Tags: 1:3.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- buffer-read-only: t -*- vi: set ro: */
 
2
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
 
3
/* Test of wcwidth() function.
 
4
   Copyright (C) 2007-2010 Free Software Foundation, Inc.
 
5
 
 
6
   This program is free software: you can redistribute it and/or modify
 
7
   it under the terms of the GNU General Public License as published by
 
8
   the Free Software Foundation; either version 3 of the License, or
 
9
   (at your option) any later version.
 
10
 
 
11
   This program is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
   GNU General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
18
 
 
19
/* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
 
20
 
 
21
#include <config.h>
 
22
 
 
23
#include <wchar.h>
 
24
 
 
25
#include "signature.h"
 
26
SIGNATURE_CHECK (wcwidth, int, (wchar_t));
 
27
 
 
28
#include <locale.h>
 
29
#include <string.h>
 
30
 
 
31
#include "localcharset.h"
 
32
#include "macros.h"
 
33
 
 
34
int
 
35
main ()
 
36
{
 
37
  wchar_t wc;
 
38
 
 
39
  /* Test width of ASCII characters.  */
 
40
  for (wc = 0x20; wc < 0x7F; wc++)
 
41
    ASSERT (wcwidth (wc) == 1);
 
42
 
 
43
  /* Switch to an UTF-8 locale.  */
 
44
  if (setlocale (LC_ALL, "fr_FR.UTF-8") != NULL
 
45
      /* Check whether it's really an UTF-8 locale.
 
46
         On OpenBSD 4.0, the setlocale call succeeds only for the LC_CTYPE
 
47
         category and therefore returns "C/fr_FR.UTF-8/C/C/C/C", but the
 
48
         LC_CTYPE category is effectively set to an ASCII LC_CTYPE category;
 
49
         in particular, locale_charset() returns "ASCII".  */
 
50
      && strcmp (locale_charset (), "UTF-8") == 0)
 
51
    {
 
52
      /* Test width of ASCII characters.  */
 
53
      for (wc = 0x20; wc < 0x7F; wc++)
 
54
        ASSERT (wcwidth (wc) == 1);
 
55
 
 
56
      /* Test width of some non-spacing characters.  */
 
57
      ASSERT (wcwidth (0x0301) == 0);
 
58
      ASSERT (wcwidth (0x05B0) == 0);
 
59
 
 
60
      /* Test width of some format control characters.  */
 
61
      ASSERT (wcwidth (0x200E) <= 0);
 
62
      ASSERT (wcwidth (0x2060) <= 0);
 
63
#if 0  /* wchar_t may be only 16 bits.  */
 
64
      ASSERT (wcwidth (0xE0001) <= 0);
 
65
      ASSERT (wcwidth (0xE0044) <= 0);
 
66
#endif
 
67
 
 
68
      /* Test width of some zero width characters.  */
 
69
      ASSERT (wcwidth (0x200B) == 0);
 
70
      ASSERT (wcwidth (0xFEFF) <= 0);
 
71
 
 
72
      /* Test width of some CJK characters.  */
 
73
      ASSERT (wcwidth (0x3000) == 2);
 
74
      ASSERT (wcwidth (0xB250) == 2);
 
75
      ASSERT (wcwidth (0xFF1A) == 2);
 
76
#if 0  /* wchar_t may be only 16 bits.  */
 
77
      ASSERT (wcwidth (0x20369) == 2);
 
78
      ASSERT (wcwidth (0x2F876) == 2);
 
79
#endif
 
80
    }
 
81
 
 
82
  return 0;
 
83
}