Mercurial > gnulib
annotate tests/uniconv/test-u8-strconv-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 |
---|---|
7955
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-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. |
7955
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-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 |
7955
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-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. |
7955
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-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/>. */ |
7955
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
8892 | 19 #include <config.h> |
7955
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 #include "uniconv.h" |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 #include <stdlib.h> |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 #include "unistr.h" |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
26 #include "macros.h" |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
27 extern int iconv_supports_encoding (const char *encoding); |
7955
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 int |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 main () |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 { |
40155
84fd38f4932c
tests: Fix some "unused variable" warnings.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
32 #if HAVE_ICONV |
7955
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 static enum iconv_ilseq_handler handlers[] = |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 { iconveh_error, iconveh_question_mark, iconveh_escape_sequence }; |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 size_t h; |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 /* Assume that iconv() supports at least the encodings ASCII, ISO-8859-1, |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 ISO-8859-2, and UTF-8. */ |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */ |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 for (h = 0; h < SIZEOF (handlers); h++) |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 { |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 enum iconv_ilseq_handler handler = handlers[h]; |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 static const uint8_t expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 uint8_t *result = u8_strconv_from_encoding (input, "ISO-8859-1", handler); |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 ASSERT (result != NULL); |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 ASSERT (u8_strcmp (result, expected) == 0); |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 free (result); |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 } |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 /* Test conversion from ISO-8859-2 to UTF-8 with no errors. */ |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 for (h = 0; h < SIZEOF (handlers); h++) |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 { |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 enum iconv_ilseq_handler handler = handlers[h]; |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 static const uint8_t expected[] = "Rafa\305\202 Maszkowski"; |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 uint8_t *result = u8_strconv_from_encoding (input, "ISO-8859-2", handler); |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 ASSERT (result != NULL); |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 ASSERT (u8_strcmp (result, expected) == 0); |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 free (result); |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 } |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 |
8585
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7955
diff
changeset
|
64 /* 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:
9889
diff
changeset
|
65 # 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
|
66 if (iconv_supports_encoding ("ISO-2022-JP-2")) |
7955
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 { |
19543
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
68 /* 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
|
69 for (h = 0; h < SIZEOF (handlers); h++) |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
70 { |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
71 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
|
72 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
|
73 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
|
74 uint8_t *result = u8_strconv_from_encoding (input, "autodetect_jp", handler); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
75 ASSERT (result != NULL); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
76 ASSERT (u8_strcmp (result, expected) == 0); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
77 free (result); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
78 } |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
79 for (h = 0; h < SIZEOF (handlers); h++) |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
80 { |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
81 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
|
82 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
|
83 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
|
84 uint8_t *result = u8_strconv_from_encoding (input, "autodetect_jp", handler); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
85 ASSERT (result != NULL); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
86 ASSERT (u8_strcmp (result, expected) == 0); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
87 free (result); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
88 } |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
89 for (h = 0; h < SIZEOF (handlers); h++) |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
90 { |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 uint8_t *result = u8_strconv_from_encoding (input, "autodetect_jp", handler); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
95 ASSERT (result != NULL); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
96 ASSERT (u8_strcmp (result, expected) == 0); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
97 free (result); |
0258f83b9063
striconveha, uniconv/*: Avoid test failures on musl libc.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
98 } |
7955
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
99 } |
8585
0290e58a0863
Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents:
7955
diff
changeset
|
100 # endif |
7955
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
101 |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
102 #endif |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
103 |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
104 return 0; |
e6591f8e46d0
Tests for module 'uniconv/u8-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
105 } |