Mercurial > gnulib
annotate tests/uniconv/test-u8-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 |
---|---|
7947
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Test of conversion to UTF-8 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. |
7947
030daf1722bd
Tests for module 'uniconv/u8-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 |
7947
030daf1722bd
Tests for module 'uniconv/u8-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. |
7947
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
030daf1722bd
Tests for module 'uniconv/u8-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/>. */ |
7947
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
8892 | 19 #include <config.h> |
7947
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 #include "uniconv.h" |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 #include <stdlib.h> |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 #include <string.h> |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 |
030daf1722bd
Tests for module 'uniconv/u8-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); |
7947
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 /* Magic number for detecting bounds violations. */ |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 #define MAGIC 0x1983EFF1 |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 static size_t * |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 new_offsets (size_t n) |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 { |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 size_t *offsets = (size_t *) malloc ((n + 1) * sizeof (size_t)); |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 offsets[n] = MAGIC; |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 return offsets; |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 } |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 int |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 main () |
030daf1722bd
Tests for module 'uniconv/u8-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 |
7947
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 static enum iconv_ilseq_handler handlers[] = |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 { iconveh_error, iconveh_question_mark, iconveh_escape_sequence }; |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 size_t h; |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 size_t o; |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 size_t i; |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 /* Assume that iconv() supports at least the encodings ASCII, ISO-8859-1, |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 ISO-8859-2, and UTF-8. */ |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */ |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 for (h = 0; h < SIZEOF (handlers); h++) |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 { |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 enum iconv_ilseq_handler handler = handlers[h]; |
030daf1722bd
Tests for module 'uniconv/u8-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"; |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 static const uint8_t expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
61 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
62 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
|
63 size_t length; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
64 uint8_t *result = u8_conv_from_encoding ("ISO-8859-1", handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
65 input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
66 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
67 NULL, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
68 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
69 ASSERT (length == u8_strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
70 ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
71 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
72 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
73 for (i = 0; i < 37; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
74 ASSERT (offsets[i] == (i < 1 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
75 i < 12 ? i + 1 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
76 i < 18 ? i + 2 : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
77 i + 3)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
78 ASSERT (offsets[37] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
79 free (offsets); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
80 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
81 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
82 } |
7947
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
83 } |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
84 |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
85 /* Test conversion from ISO-8859-2 to UTF-8 with no errors. */ |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
86 for (h = 0; h < SIZEOF (handlers); h++) |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
87 { |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
88 enum iconv_ilseq_handler handler = handlers[h]; |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
89 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
90 static const uint8_t expected[] = "Rafa\305\202 Maszkowski"; |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
91 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
92 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
93 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
|
94 size_t length; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
95 uint8_t *result = u8_conv_from_encoding ("ISO-8859-2", handler, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
96 input, strlen (input), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
97 offsets, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
98 NULL, &length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
99 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
100 ASSERT (length == u8_strlen (expected)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
101 ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
102 if (o) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
103 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
104 for (i = 0; i < 16; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
105 ASSERT (offsets[i] == (i < 5 ? i : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
106 i + 1)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
107 ASSERT (offsets[16] == MAGIC); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
108 free (offsets); |
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 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
111 } |
7947
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
112 } |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
113 |
8585
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7947
diff
changeset
|
114 /* 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
|
115 # 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
|
116 if (iconv_supports_encoding ("ISO-2022-JP-2")) |
7947
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
117 { |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
118 /* Test conversions from autodetect_jp to UTF-8. */ |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
119 for (h = 0; h < SIZEOF (handlers); h++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
120 { |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
121 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
|
122 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
|
123 static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */ |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
124 for (o = 0; o < 2; o++) |
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 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
|
127 size_t length; |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
128 uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler, |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
129 input, strlen (input), |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
130 offsets, |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
131 NULL, &length); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
132 ASSERT (result != NULL); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
133 ASSERT (length == u8_strlen (expected)); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
134 ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
135 if (o) |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
136 { |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
137 for (i = 0; i < 10; i++) |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
138 ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1))); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
139 ASSERT (offsets[10] == MAGIC); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
140 free (offsets); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
141 } |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
142 free (result); |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
143 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
144 } |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
145 for (h = 0; h < SIZEOF (handlers); h++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
146 { |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
147 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
|
148 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
|
149 static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */ |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
150 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
151 { |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
152 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
|
153 size_t length; |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
154 uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler, |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
155 input, strlen (input), |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
156 offsets, |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
157 NULL, &length); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
158 ASSERT (result != NULL); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
159 ASSERT (length == u8_strlen (expected)); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
160 ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
161 if (o) |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
162 { |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
163 for (i = 0; i < 10; i++) |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
164 ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1))); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
165 ASSERT (offsets[10] == MAGIC); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
166 free (offsets); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
167 } |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
168 free (result); |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
169 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
170 } |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
171 for (h = 0; h < SIZEOF (handlers); h++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
172 { |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
173 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
|
174 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
|
175 static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */ |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
176 for (o = 0; o < 2; o++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
177 { |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
178 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
|
179 size_t length; |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
180 uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler, |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
181 input, strlen (input), |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
182 offsets, |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
183 NULL, &length); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
184 ASSERT (result != NULL); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
185 ASSERT (length == u8_strlen (expected)); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
186 ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
187 if (o) |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
188 { |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
189 for (i = 0; i < 16; i++) |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
190 ASSERT (offsets[i] == (i == 0 ? 0 : |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
191 i == 5 ? 3 : |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
192 i == 7 ? 6 : |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
193 i == 9 ? 9 : |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
194 i == 11 ? 12 : |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
195 i == 13 ? 15 : |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
196 (size_t)(-1))); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
197 ASSERT (offsets[16] == MAGIC); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
198 free (offsets); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
199 } |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
200 free (result); |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
201 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11845
diff
changeset
|
202 } |
7947
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
203 } |
8585
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7947
diff
changeset
|
204 # endif |
7947
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
205 |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
206 #endif |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
207 |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
208 return 0; |
030daf1722bd
Tests for module 'uniconv/u8-conv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
209 } |