Mercurial > gnulib
annotate tests/uniconv/test-u16-conv-from-enc.c @ 40155:84fd38f4932c
tests: Fix some "unused variable" warnings.
* tests/test-fts.c (fts_dealloc): Remove unused variable.
* tests/unigbrk/test-uc-grapheme-breaks.c (main): Likewise.
* tests/test-striconveh.c (main): Move some variable into the
'#if HAVE_ICONV'.
* tests/test-striconveha.c (main): Likewise.
* tests/uniconv/test-u8-conv-from-enc.c (main): Likewise.
* tests/uniconv/test-u16-conv-from-enc.c (main): Likewise.
* tests/uniconv/test-u32-conv-from-enc.c (main): Likewise.
* tests/uniconv/test-u8-conv-to-enc.c (main): Likewise.
* tests/uniconv/test-u16-conv-to-enc.c (main): Likewise.
* tests/uniconv/test-u32-conv-to-enc.c (main): Likewise.
* tests/uniconv/test-u8-strconv-from-enc.c (main): Likewise.
* tests/uniconv/test-u16-strconv-from-enc.c (main): Likewise.
* tests/uniconv/test-u32-strconv-from-enc.c (main): Likewise.
* tests/uniconv/test-u8-strconv-to-enc.c (main): Likewise.
* tests/uniconv/test-u16-strconv-to-enc.c (main): Likewise.
* tests/uniconv/test-u32-strconv-to-enc.c (main): Likewise.
* tests/test-tsearch.c (main): Move some variable into the
'#if HAVE_INITSTATE'.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 27 Jan 2019 12:24:47 +0100 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
7950
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Test of conversion to UTF-16 from legacy encodings. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19543
diff
changeset
|
2 Copyright (C) 2007-2019 Free Software Foundation, Inc. |
7950
a012df800d5c
Tests for module 'uniconv/u16-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 |
7950
a012df800d5c
Tests for module 'uniconv/u16-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. |
7950
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
19190 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
7950
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
8892 | 19 #include <config.h> |
7950
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 #include "uniconv.h" |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 #include <stdlib.h> |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 #include <string.h> |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 #include "unistr.h" |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
27 #include "macros.h" |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
28 extern int iconv_supports_encoding (const char *encoding); |
7950
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 /* Magic number for detecting bounds violations. */ |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 #define MAGIC 0x1983EFF1 |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 static size_t * |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 new_offsets (size_t n) |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 { |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 size_t *offsets = (size_t *) malloc ((n + 1) * sizeof (size_t)); |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 offsets[n] = MAGIC; |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 return offsets; |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 } |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 int |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 main () |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 { |
40155
84fd38f4932c
tests: Fix some "unused variable" warnings.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
44 #if HAVE_ICONV |
7950
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 static enum iconv_ilseq_handler handlers[] = |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 { iconveh_error, iconveh_question_mark, iconveh_escape_sequence }; |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 size_t h; |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 size_t o; |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 size_t i; |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 /* Assume that iconv() supports at least the encodings ASCII, ISO-8859-1, |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 ISO-8859-2, and UTF-8. */ |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 /* Test conversion from ISO-8859-1 to UTF-16 with no errors. */ |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 for (h = 0; h < SIZEOF (handlers); h++) |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 { |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 enum iconv_ilseq_handler handler = handlers[h]; |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 static const uint16_t expected[] = /* Ärger mit bösen Bübchen ohne Augenmaß */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
60 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
61 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
62 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
63 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
64 }; |
7950
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
66 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
67 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
68 size_t length; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
69 uint16_t *result = u16_conv_from_encoding ("ISO-8859-1", handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
70 input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
71 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
72 NULL, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
73 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
74 ASSERT (length == SIZEOF (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
75 ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
76 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
77 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
78 for (i = 0; i < 37; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
79 ASSERT (offsets[i] == i); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
80 ASSERT (offsets[37] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
81 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
82 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
83 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
84 } |
7950
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
85 } |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
86 |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
87 /* Test conversion from ISO-8859-2 to UTF-16 with no errors. */ |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
88 for (h = 0; h < SIZEOF (handlers); h++) |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
89 { |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
90 enum iconv_ilseq_handler handler = handlers[h]; |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
91 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
92 static const uint16_t expected[] = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
93 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
94 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
95 's', 'k', 'i' |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
96 }; |
7950
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
97 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
98 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
99 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
100 size_t length; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
101 uint16_t *result = u16_conv_from_encoding ("ISO-8859-2", handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
102 input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
103 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
104 NULL, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
105 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
106 ASSERT (length == SIZEOF (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
107 ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
108 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
109 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
110 for (i = 0; i < 16; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
111 ASSERT (offsets[i] == i); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
112 ASSERT (offsets[16] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
113 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
114 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
115 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
116 } |
7950
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
117 } |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
118 |
8585
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7950
diff
changeset
|
119 /* autodetect_jp is only supported when iconv() support ISO-2022-JP-2. */ |
11845
466e857417c3
Avoid test failures on Solaris 10.
Bruno Haible <bruno@clisp.org>
parents:
11511
diff
changeset
|
120 # if defined _LIBICONV_VERSION || !(defined _AIX || defined __sgi || defined __hpux || defined __osf__ || defined __sun) |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
121 if (iconv_supports_encoding ("ISO-2022-JP-2")) |
7950
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
122 { |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
123 /* Test conversions from autodetect_jp to UTF-16. */ |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
124 for (h = 0; h < SIZEOF (handlers); h++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
125 { |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
126 enum iconv_ilseq_handler handler = handlers[h]; |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
127 static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */ |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
128 static const uint16_t expected[] = /* こんにちは */ |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
129 { |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
130 0x3053, 0x3093, 0x306B, 0x3061, 0x306F |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
131 }; |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
132 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
133 { |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
134 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
135 size_t length; |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
136 uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler, |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
137 input, strlen (input), |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
138 offsets, |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
139 NULL, &length); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
140 ASSERT (result != NULL); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
141 ASSERT (length == SIZEOF (expected)); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
142 ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
143 if (o) |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
144 { |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
145 for (i = 0; i < 10; i++) |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
146 ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1))); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
147 ASSERT (offsets[10] == MAGIC); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
148 free (offsets); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
149 } |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
150 free (result); |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
151 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
152 } |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
153 for (h = 0; h < SIZEOF (handlers); h++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
154 { |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
155 enum iconv_ilseq_handler handler = handlers[h]; |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
156 static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */ |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
157 static const uint16_t expected[] = /* こんにちは */ |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
158 { |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
159 0x3053, 0x3093, 0x306B, 0x3061, 0x306F |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
160 }; |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
161 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
162 { |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
163 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
164 size_t length; |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
165 uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler, |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
166 input, strlen (input), |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
167 offsets, |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
168 NULL, &length); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
169 ASSERT (result != NULL); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
170 ASSERT (length == SIZEOF (expected)); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
171 ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
172 if (o) |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
173 { |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
174 for (i = 0; i < 10; i++) |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
175 ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1))); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
176 ASSERT (offsets[10] == MAGIC); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
177 free (offsets); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
178 } |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
179 free (result); |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
180 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
181 } |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
182 for (h = 0; h < SIZEOF (handlers); h++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
183 { |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
184 enum iconv_ilseq_handler handler = handlers[h]; |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
185 static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */ |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
186 static const uint16_t expected[] = /* こんにちは */ |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
187 { |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
188 0x3053, 0x3093, 0x306B, 0x3061, 0x306F |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
189 }; |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
190 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
191 { |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
192 size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
193 size_t length; |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
194 uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler, |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
195 input, strlen (input), |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
196 offsets, |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
197 NULL, &length); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
198 ASSERT (result != NULL); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
199 ASSERT (length == SIZEOF (expected)); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
200 ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
201 if (o) |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
202 { |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
203 for (i = 0; i < 16; i++) |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
204 ASSERT (offsets[i] == (i == 0 ? 0 : |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
205 i == 5 ? 1 : |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
206 i == 7 ? 2 : |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
207 i == 9 ? 3 : |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
208 i == 11 ? 4 : |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
209 i == 13 ? 5 : |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
210 (size_t)(-1))); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
211 ASSERT (offsets[16] == MAGIC); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
212 free (offsets); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
213 } |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
214 free (result); |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
215 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
216 } |
7950
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
217 } |
8585
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7950
diff
changeset
|
218 # endif |
7950
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
219 |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
220 #endif |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
221 |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
222 return 0; |
a012df800d5c
Tests for module 'uniconv/u16-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
223 } |