annotate tests/uniwidth/test-uc_width2.c @ 17935:0ad1f4c9eed5 default tip

tests: support stderr verification with returns_() * tests/init.sh (returns_): Disable tracing for this wrapper function, so that stderr of the wrapped command is unchanged, allowing for verification of the contents.
author Pádraig Brady <P@draigBrady.com>
date Mon, 16 Feb 2015 17:20:39 +0000
parents ab58d4870664
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10355
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of uc_width() function.
17848
ab58d4870664 version-etc: new year
Paul Eggert <eggert@cs.ucla.edu>
parents: 17587
diff changeset
2 Copyright (C) 2007-2015 Free Software Foundation, Inc.
10355
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2008. */
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "uniwidth.h"
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <stdio.h>
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
25 #include "macros.h"
10355
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 /* One of 0, '0', '1', 'A', '2'. */
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 static char current_width;
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 /* The interval for which the current_width holds. */
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 static ucs4_t current_start;
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 static ucs4_t current_end;
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 static void
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 finish_interval (void)
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 {
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 if (current_width != 0)
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 {
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 if (current_start == current_end)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10848
diff changeset
39 printf ("%04X\t\t%c\n", (unsigned) current_start, current_width);
10355
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10848
diff changeset
41 printf ("%04X..%04X\t%c\n", (unsigned) current_start,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10848
diff changeset
42 (unsigned) current_end, current_width);
10355
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 current_width = 0;
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 }
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 }
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 static void
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 add_to_interval (ucs4_t uc, char width)
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 {
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 if (current_width == width && uc == current_end + 1)
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 current_end = uc;
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 else
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 {
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 finish_interval ();
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 current_width = width;
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 current_start = current_end = uc;
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 }
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 }
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 int
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 main ()
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 {
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 ucs4_t uc;
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 for (uc = 0; uc < 0x110000; uc++)
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 {
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 int w1 = uc_width (uc, "UTF-8");
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 int w2 = uc_width (uc, "GBK");
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 char width =
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10848
diff changeset
70 (w1 == 0 && w2 == 0 ? '0' :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10848
diff changeset
71 w1 == 1 && w2 == 1 ? '1' :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10848
diff changeset
72 w1 == 1 && w2 == 2 ? 'A' :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10848
diff changeset
73 w1 == 2 && w2 == 2 ? '2' :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10848
diff changeset
74 0);
10355
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 if (width == 0)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10848
diff changeset
76 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10848
diff changeset
77 /* uc must be a control character. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10848
diff changeset
78 ASSERT (w1 < 0 && w2 < 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10848
diff changeset
79 }
10355
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10848
diff changeset
81 add_to_interval (uc, width);
10355
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 }
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 finish_interval ();
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 return 0;
017cb54cf1da Complete test of uc_width results.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 }