Mercurial > gnulib
annotate tests/uniconv/test-u16-strconv-to-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 |
---|---|
7964
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Test of conversion from UTF-16 to legacy encodings. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2007-2019 Free Software Foundation, Inc. |
7964
06eece08f196
Tests for module 'uniconv/u16-strconv-to-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 |
7964
06eece08f196
Tests for module 'uniconv/u16-strconv-to-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. |
7964
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-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/>. */ |
7964
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
8892 | 19 #include <config.h> |
7964
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 #include "uniconv.h" |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 #include <errno.h> |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 #include <stdlib.h> |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 #include <string.h> |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
27 #include "macros.h" |
7964
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 int |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 main () |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-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 |
7964
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 static enum iconv_ilseq_handler handlers[] = |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 { iconveh_error, iconveh_question_mark, iconveh_escape_sequence }; |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 size_t h; |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 /* Assume that iconv() supports at least the encodings ASCII, ISO-8859-1, |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 ISO-8859-2, and UTF-8. */ |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 /* Test conversion from UTF-16 to ISO-8859-1 with no errors. */ |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 for (h = 0; h < SIZEOF (handlers); h++) |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 { |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 enum iconv_ilseq_handler handler = handlers[h]; |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 static const uint16_t input[] = /* Ärger mit bösen Bübchen ohne Augenmaß */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
45 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
46 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
47 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
48 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF, 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
49 }; |
7964
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 char *result = u16_strconv_to_encoding (input, "ISO-8859-1", handler); |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 ASSERT (result != NULL); |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 ASSERT (strcmp (result, expected) == 0); |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 free (result); |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 } |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 /* Test conversion from UTF-16 to ISO-8859-1 with EILSEQ. */ |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 for (h = 0; h < SIZEOF (handlers); h++) |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 { |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 enum iconv_ilseq_handler handler = handlers[h]; |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 static const uint16_t input[] = /* Rafał Maszkowski */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
62 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
63 '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:
9889
diff
changeset
|
64 's', 'k', 'i', 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
65 }; |
7964
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 char *result = u16_strconv_to_encoding (input, "ISO-8859-1", handler); |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 switch (handler) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
68 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
69 case iconveh_error: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
70 ASSERT (result == NULL && errno == EILSEQ); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
71 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
72 case iconveh_question_mark: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
73 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
74 static const char expected[] = "Rafa? Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
75 static const char expected_translit[] = "Rafal Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
76 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
77 ASSERT (strcmp (result, expected) == 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
78 || strcmp (result, expected_translit) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
79 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
80 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
81 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
82 case iconveh_escape_sequence: |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
83 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
84 static const char expected[] = "Rafa\\u0142 Maszkowski"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
85 ASSERT (result != NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
86 ASSERT (strcmp (result, expected) == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
87 free (result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
88 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
89 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9889
diff
changeset
|
90 } |
7964
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
91 } |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
92 |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
93 # if 0 |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
94 /* Test conversion from UTF-16 to ISO-8859-1 with EINVAL. */ |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
95 for (h = 0; h < SIZEOF (handlers); h++) |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
96 { |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
97 enum iconv_ilseq_handler handler = handlers[h]; |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
98 static const uint16_t input[] = { 0xD845, 0 }; |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
99 char *result = u16_strconv_to_encoding (input, "ISO-8859-1", handler); |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
100 ASSERT (result != NULL); |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
101 ASSERT (strcmp (result, "") == 0); |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
102 free (result); |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
103 } |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
104 # endif |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
105 |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
106 #endif |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
107 |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
108 return 0; |
06eece08f196
Tests for module 'uniconv/u16-strconv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
109 } |