Mercurial > hg > octave-kai > gnulib-hg
annotate tests/uniconv/test-u32-conv-from-enc.c @ 9889:0be6f1ab456d
Flush the standard error stream before aborting.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 11 Apr 2008 16:31:39 +0200 |
parents | bbbbbf4cd1c5 |
children | d604b921ed8d |
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. |
9889
0be6f1ab456d
Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
2 Copyright (C) 2007-2008 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); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
80 uint32_t *result = NULL; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
81 size_t length = 0; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
82 int retval = u32_conv_from_encoding ("ISO-8859-1", handler, |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
83 input, strlen (input), |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
84 offsets, |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
85 &result, &length); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
86 ASSERT (retval == 0); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
87 ASSERT (length == SIZEOF (expected)); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
88 ASSERT (result != NULL && u32_cmp (result, expected, SIZEOF (expected)) == 0); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
89 if (o) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
90 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
91 for (i = 0; i < 37; i++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
92 ASSERT (offsets[i] == i); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
93 ASSERT (offsets[37] == MAGIC); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
94 free (offsets); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
95 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
96 free (result); |
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 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
100 /* 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
|
101 for (h = 0; h < SIZEOF (handlers); h++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
102 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
103 enum iconv_ilseq_handler handler = handlers[h]; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
104 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
|
105 static const uint32_t expected[] = |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
106 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
107 '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
|
108 's', 'k', 'i' |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
109 }; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
110 for (o = 0; o < 2; o++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
111 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
112 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
113 uint32_t *result = NULL; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
114 size_t length = 0; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
115 int retval = u32_conv_from_encoding ("ISO-8859-2", handler, |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
116 input, strlen (input), |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
117 offsets, |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
118 &result, &length); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
119 ASSERT (retval == 0); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
120 ASSERT (length == SIZEOF (expected)); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
121 ASSERT (result != NULL && u32_cmp (result, expected, SIZEOF (expected)) == 0); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
122 if (o) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
123 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
124 for (i = 0; i < 16; i++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
125 ASSERT (offsets[i] == i); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
126 ASSERT (offsets[16] == MAGIC); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
127 free (offsets); |
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 free (result); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
130 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
131 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
132 |
8585
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7952
diff
changeset
|
133 /* 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
|
134 # 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
|
135 /* 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
|
136 for (h = 0; h < SIZEOF (handlers); h++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
137 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
138 enum iconv_ilseq_handler handler = handlers[h]; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
139 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
|
140 static const uint32_t expected[] = /* こんにちは */ |
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 0x3053, 0x3093, 0x306B, 0x3061, 0x306F |
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 for (o = 0; o < 2; o++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
145 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
146 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
147 uint32_t *result = NULL; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
148 size_t length = 0; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
149 int retval = u32_conv_from_encoding ("autodetect_jp", handler, |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
150 input, strlen (input), |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
151 offsets, |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
152 &result, &length); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
153 ASSERT (retval == 0); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
154 ASSERT (length == SIZEOF (expected)); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
155 ASSERT (result != NULL && u32_cmp (result, expected, SIZEOF (expected)) == 0); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
156 if (o) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
157 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
158 for (i = 0; i < 10; i++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
159 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
|
160 ASSERT (offsets[10] == MAGIC); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
161 free (offsets); |
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 free (result); |
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 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
166 for (h = 0; h < SIZEOF (handlers); h++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
167 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
168 enum iconv_ilseq_handler handler = handlers[h]; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
169 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
|
170 static const uint32_t expected[] = /* こんにちは */ |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
171 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
172 0x3053, 0x3093, 0x306B, 0x3061, 0x306F |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
173 }; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
174 for (o = 0; o < 2; o++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
175 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
176 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
177 uint32_t *result = NULL; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
178 size_t length = 0; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
179 int retval = u32_conv_from_encoding ("autodetect_jp", handler, |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
180 input, strlen (input), |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
181 offsets, |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
182 &result, &length); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
183 ASSERT (retval == 0); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
184 ASSERT (length == SIZEOF (expected)); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
185 ASSERT (result != NULL && u32_cmp (result, expected, SIZEOF (expected)) == 0); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
186 if (o) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
187 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
188 for (i = 0; i < 10; i++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
189 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
|
190 ASSERT (offsets[10] == MAGIC); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
191 free (offsets); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
192 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
193 free (result); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
194 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
195 } |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
196 for (h = 0; h < SIZEOF (handlers); h++) |
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 enum iconv_ilseq_handler handler = handlers[h]; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
199 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
|
200 static const uint32_t expected[] = /* こんにちは */ |
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 0x3053, 0x3093, 0x306B, 0x3061, 0x306F |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
203 }; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
204 for (o = 0; o < 2; o++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
205 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
206 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
207 uint32_t *result = NULL; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
208 size_t length = 0; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
209 int retval = u32_conv_from_encoding ("autodetect_jp", handler, |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
210 input, strlen (input), |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
211 offsets, |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
212 &result, &length); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
213 ASSERT (retval == 0); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
214 ASSERT (length == SIZEOF (expected)); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
215 ASSERT (result != NULL && u32_cmp (result, expected, SIZEOF (expected)) == 0); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
216 if (o) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
217 { |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
218 for (i = 0; i < 16; i++) |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
219 ASSERT (offsets[i] == (i == 0 ? 0 : |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
220 i == 5 ? 1 : |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
221 i == 7 ? 2 : |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
222 i == 9 ? 3 : |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
223 i == 11 ? 4 : |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
224 i == 13 ? 5 : |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
225 (size_t)(-1))); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
226 ASSERT (offsets[16] == MAGIC); |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
227 free (offsets); |
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 free (result); |
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 } |
8585
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7952
diff
changeset
|
232 # endif |
7952
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
233 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
234 #endif |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
235 |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
236 return 0; |
1749041c276c
Tests for module 'uniconv/u32-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
237 } |