annotate tests/unilbrk/test-u32-width-linebreaks.c @ 12421:e8d2c6fc33ad

Use spaces for indentation, not tabs.
author Bruno Haible <bruno@clisp.org>
date Thu, 10 Dec 2009 20:28:30 +0100
parents 2b9bc74f76e4
children a48d3d749ca5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10048
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of line breaking of UTF-32 strings.
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2008 Free Software Foundation, Inc.
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2008. */
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "unilbrk.h"
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <stdio.h>
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <stdlib.h>
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #define SIZEOF(array) (sizeof (array) / sizeof (array[0]))
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #define ASSERT(expr) \
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
28 do \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
29 { \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
30 if (!(expr)) \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
31 { \
10048
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
33 fflush (stderr); \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
34 abort (); \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
35 } \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
36 } \
10048
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 while (0)
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 int
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 main ()
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 {
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 /* Test case n = 0. */
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 u32_width_linebreaks (NULL, 0, 80, 0, 0, NULL, "GB18030", NULL);
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 {
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 static const uint32_t input[61] =
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ',
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
49 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
50 0x0439, 0x0442, 0x0435, '!', ' ',
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
51 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
52 '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ',
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
53 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n'
10048
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 };
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 {
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 char *p = (char *) malloc (SIZEOF (input));
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 size_t i;
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 u32_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB18030", p);
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 for (i = 0; i < 61; i++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
62 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
63 ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
64 i == 25 || i == 45 ? UC_BREAK_POSSIBLE :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
65 UC_BREAK_PROHIBITED));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
66 }
10048
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 free (p);
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 }
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 {
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 char *p = (char *) malloc (SIZEOF (input));
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 size_t i;
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 u32_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB2312", p);
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 for (i = 0; i < 61; i++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
76 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
77 ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
78 i == 11 || i == 25 || i == 45 ? UC_BREAK_POSSIBLE :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
79 UC_BREAK_PROHIBITED));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10063
diff changeset
80 }
10048
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 free (p);
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 }
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 }
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 return 0;
db20f16c3277 Tests for module 'unilbrk/u32-width-linebreaks'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 }