Mercurial > hg > octave-kai > gnulib-hg
annotate tests/uniconv/test-u32-conv-from-enc.c @ 11511:d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 26 Apr 2009 16:43:25 +0200 |
parents | 0be6f1ab456d |
children | 466e857417c3 |
rev | line source |
---|---|
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Test of conversion to UTF-32 from legacy encodings. |
11511
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
2 Copyright (C) 2007-2009 Free Software Foundation, Inc. |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8892
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8892
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8892
diff
changeset
|
7 (at your option) any later version. |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8892
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
8892 | 19 #include <config.h> |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 #include "uniconv.h" |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 |
8754 | 23 #include <stdio.h> |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 #include <stdlib.h> |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 #include <string.h> |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 #include "unistr.h" |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) |
8754 | 30 #define ASSERT(expr) \ |
31 do \ | |
32 { \ | |
33 if (!(expr)) \ | |
34 { \ | |
35 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ | |
9889
0be6f1ab456d
Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
36 fflush (stderr); \ |
8754 | 37 abort (); \ |
38 } \ | |
39 } \ | |
40 while (0) | |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 /* Magic number for detecting bounds violations. */ |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 #define MAGIC 0x1983EFF1 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 static size_t * |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 new_offsets (size_t n) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 size_t *offsets = (size_t *) malloc ((n + 1) * sizeof (size_t)); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 offsets[n] = MAGIC; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 return offsets; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 int |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 main () |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 static enum iconv_ilseq_handler handlers[] = |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 { iconveh_error, iconveh_question_mark, iconveh_escape_sequence }; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 size_t h; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 size_t o; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 size_t i; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 #if HAVE_ICONV |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 /* Assume that iconv() supports at least the encodings ASCII, ISO-8859-1, |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 ISO-8859-2, and UTF-8. */ |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 /* Test conversion from ISO-8859-1 to UTF-16 with no errors. */ |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 for (h = 0; h < SIZEOF (handlers); h++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 enum iconv_ilseq_handler handler = handlers[h]; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 static const uint32_t expected[] = /* Ärger mit bösen Bübchen ohne Augenmaß */ |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
72 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
73 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
75 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
76 }; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
77 for (o = 0; o < 2; o++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
78 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
79 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
11511
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
80 size_t length; |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
81 uint32_t *result = u32_conv_from_encoding ("ISO-8859-1", handler, |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
82 input, strlen (input), |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
83 offsets, |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
84 NULL, &length); |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
85 ASSERT (result != NULL); |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
86 ASSERT (length == SIZEOF (expected)); |
11511
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
87 ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0); |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
88 if (o) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
89 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
90 for (i = 0; i < 37; i++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
91 ASSERT (offsets[i] == i); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
92 ASSERT (offsets[37] == MAGIC); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
93 free (offsets); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
94 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
95 free (result); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
96 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
97 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
98 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
99 /* Test conversion from ISO-8859-2 to UTF-16 with no errors. */ |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
100 for (h = 0; h < SIZEOF (handlers); h++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
101 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
102 enum iconv_ilseq_handler handler = handlers[h]; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
103 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
104 static const uint32_t expected[] = |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
105 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
106 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
107 's', 'k', 'i' |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
108 }; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
109 for (o = 0; o < 2; o++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
110 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
111 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
11511
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
112 size_t length; |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
113 uint32_t *result = u32_conv_from_encoding ("ISO-8859-2", handler, |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
114 input, strlen (input), |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
115 offsets, |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
116 NULL, &length); |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
117 ASSERT (result != NULL); |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
118 ASSERT (length == SIZEOF (expected)); |
11511
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
119 ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0); |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
120 if (o) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
121 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
122 for (i = 0; i < 16; i++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
123 ASSERT (offsets[i] == i); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
124 ASSERT (offsets[16] == MAGIC); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
125 free (offsets); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
126 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
127 free (result); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
128 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
129 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
130 |
8585
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7952
diff
changeset
|
131 /* autodetect_jp is only supported when iconv() support ISO-2022-JP-2. */ |
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7952
diff
changeset
|
132 # if defined _LIBICONV_VERSION || !(defined _AIX || defined __sgi || defined __hpux || defined __osf__) |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
133 /* Test conversions from autodetect_jp to UTF-16. */ |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
134 for (h = 0; h < SIZEOF (handlers); h++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
135 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
136 enum iconv_ilseq_handler handler = handlers[h]; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
137 static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */ |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
138 static const uint32_t expected[] = /* こんにちは */ |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
139 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
140 0x3053, 0x3093, 0x306B, 0x3061, 0x306F |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
141 }; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
142 for (o = 0; o < 2; o++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
143 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
144 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
11511
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
145 size_t length; |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
146 uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler, |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
147 input, strlen (input), |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
148 offsets, |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
149 NULL, &length); |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
150 ASSERT (result != NULL); |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
151 ASSERT (length == SIZEOF (expected)); |
11511
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
152 ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0); |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
153 if (o) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
154 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
155 for (i = 0; i < 10; i++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
156 ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1))); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
157 ASSERT (offsets[10] == MAGIC); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
158 free (offsets); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
159 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
160 free (result); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
161 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
162 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
163 for (h = 0; h < SIZEOF (handlers); h++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
164 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
165 enum iconv_ilseq_handler handler = handlers[h]; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
166 static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */ |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
167 static const uint32_t expected[] = /* こんにちは */ |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
168 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
169 0x3053, 0x3093, 0x306B, 0x3061, 0x306F |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
170 }; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
171 for (o = 0; o < 2; o++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
172 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
173 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
11511
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
174 size_t length; |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
175 uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler, |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
176 input, strlen (input), |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
177 offsets, |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
178 NULL, &length); |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
179 ASSERT (result != NULL); |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
180 ASSERT (length == SIZEOF (expected)); |
11511
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
181 ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0); |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
182 if (o) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
183 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
184 for (i = 0; i < 10; i++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
185 ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1))); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
186 ASSERT (offsets[10] == MAGIC); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
187 free (offsets); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
188 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
189 free (result); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
190 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
191 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
192 for (h = 0; h < SIZEOF (handlers); h++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
193 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
194 enum iconv_ilseq_handler handler = handlers[h]; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
195 static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */ |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
196 static const uint32_t expected[] = /* こんにちは */ |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
197 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
198 0x3053, 0x3093, 0x306B, 0x3061, 0x306F |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
199 }; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
200 for (o = 0; o < 2; o++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
201 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
202 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
11511
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
203 size_t length; |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
204 uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler, |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
205 input, strlen (input), |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
206 offsets, |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
207 NULL, &length); |
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
208 ASSERT (result != NULL); |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
209 ASSERT (length == SIZEOF (expected)); |
11511
d604b921ed8d
Simplify calling convention of u*_conv_from_encoding.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
210 ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0); |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
211 if (o) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
212 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
213 for (i = 0; i < 16; i++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
214 ASSERT (offsets[i] == (i == 0 ? 0 : |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
215 i == 5 ? 1 : |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
216 i == 7 ? 2 : |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
217 i == 9 ? 3 : |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
218 i == 11 ? 4 : |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
219 i == 13 ? 5 : |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
220 (size_t)(-1))); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
221 ASSERT (offsets[16] == MAGIC); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
222 free (offsets); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
223 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
224 free (result); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
225 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
226 } |
8585
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7952
diff
changeset
|
227 # endif |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
228 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
229 #endif |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
230 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
231 return 0; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
232 } |