annotate tests/uniconv/test-u16-strconv-from-enc.c @ 16616:2f2ef742aa4b

New module 'exp2'. * lib/math.in.h (exp2): New declaration. * lib/exp2.c: New file. * m4/exp2.m4: New file. * m4/math_h.m4 (gl_MATH_H): Test whether exp2 is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_EXP2, HAVE_DECL_EXP2, REPLACE_EXP2. * modules/math (Makefile.am): Substitute GNULIB_EXP2, HAVE_DECL_EXP2, REPLACE_EXP2. * modules/exp2: New file. * tests/test-math-c++.cc: Check the declaration of exp2. * doc/posix-functions/exp2.texi: Mention the new module and the IRIX and OpenBSD problems.
author Bruno Haible <bruno@clisp.org>
date Wed, 07 Mar 2012 03:29:32 +0100
parents 8250f2777afc
children e542fd46ad6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7957
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of conversion to UTF-16 from legacy encodings.
16201
8250f2777afc maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
2 Copyright (C) 2007-2012 Free Software Foundation, Inc.
7957
4076f3d8b095 Tests for module 'uniconv/u16-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
7957
4076f3d8b095 Tests for module 'uniconv/u16-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.
7957
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8892
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
7957
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
8892
4f6a4b1d68a8 Assume <config.h> exists.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
19 #include <config.h>
7957
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "uniconv.h"
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <stdlib.h>
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
4076f3d8b095 Tests for module 'uniconv/u16-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"
7957
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 int
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 main ()
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 {
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 static enum iconv_ilseq_handler handlers[] =
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 { iconveh_error, iconveh_question_mark, iconveh_escape_sequence };
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 size_t h;
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 #if HAVE_ICONV
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 /* Assume that iconv() supports at least the encodings ASCII, ISO-8859-1,
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 ISO-8859-2, and UTF-8. */
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 /* Test conversion from ISO-8859-1 to UTF-16 with no errors. */
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 for (h = 0; h < SIZEOF (handlers); h++)
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 {
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 enum iconv_ilseq_handler handler = handlers[h];
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 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
45 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11845
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: 11845
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: 11845
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: 11845
diff changeset
49 };
7957
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 uint16_t *result = u16_strconv_from_encoding (input, "ISO-8859-1", handler);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 ASSERT (result != NULL);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 ASSERT (u16_strcmp (result, expected) == 0);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 free (result);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 }
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 /* Test conversion from ISO-8859-2 to UTF-16 with no errors. */
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 for (h = 0; h < SIZEOF (handlers); h++)
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 {
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 enum iconv_ilseq_handler handler = handlers[h];
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 static const uint16_t expected[] =
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11845
diff changeset
62 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11845
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: 11845
diff changeset
64 's', 'k', 'i', 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11845
diff changeset
65 };
7957
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 uint16_t *result = u16_strconv_from_encoding (input, "ISO-8859-2", handler);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 ASSERT (result != NULL);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 ASSERT (u16_strcmp (result, expected) == 0);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 free (result);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 }
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71
8585
0290e58a0863 Avoid test failures on OSF/1, IRIX, HP-UX, AIX.
Bruno Haible <bruno@clisp.org>
parents: 7957
diff changeset
72 /* 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
73 # if defined _LIBICONV_VERSION || !(defined _AIX || defined __sgi || defined __hpux || defined __osf__ || defined __sun)
7957
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 /* Test conversions from autodetect_jp to UTF-16. */
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 for (h = 0; h < SIZEOF (handlers); h++)
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 {
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 enum iconv_ilseq_handler handler = handlers[h];
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 static const uint16_t expected[] = /* こんにちは */
12421
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 0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11845
diff changeset
82 };
7957
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 uint16_t *result = u16_strconv_from_encoding (input, "autodetect_jp", handler);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 ASSERT (result != NULL);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 ASSERT (u16_strcmp (result, expected) == 0);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 free (result);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 }
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 for (h = 0; h < SIZEOF (handlers); h++)
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 {
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 enum iconv_ilseq_handler handler = handlers[h];
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */
4076f3d8b095 Tests for module 'uniconv/u16-strconv-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 0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11845
diff changeset
95 };
7957
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 uint16_t *result = u16_strconv_from_encoding (input, "autodetect_jp", handler);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 ASSERT (result != NULL);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 ASSERT (u16_strcmp (result, expected) == 0);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 free (result);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 }
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 for (h = 0; h < SIZEOF (handlers); h++)
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 {
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 enum iconv_ilseq_handler handler = handlers[h];
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 static const uint16_t expected[] = /* こんにちは */
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11845
diff changeset
106 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11845
diff changeset
107 0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11845
diff changeset
108 };
7957
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 uint16_t *result = u16_strconv_from_encoding (input, "autodetect_jp", handler);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 ASSERT (result != NULL);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 ASSERT (u16_strcmp (result, expected) == 0);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 free (result);
4076f3d8b095 Tests for module 'uniconv/u16-strconv-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: 7957
diff changeset
114 # endif
7957
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 #endif
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 return 0;
4076f3d8b095 Tests for module 'uniconv/u16-strconv-from-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 }