annotate tests/uniconv/test-u16-conv-to-enc.c @ 40224:5d9b82ca550a

tests: Free allocated memory. Reported by <deltatau@protonmail.com> via Assaf Gordon. * tests/test-astrxfrm.c (main): Free allocated memory. * tests/test-bitset.c (compare, check_attributes): Free allocated bitsets. * tests/test-filenamecat.c (main): Free allocated memory. * tests/test-freadahead.c (main): Free allocated memory and close stdin. * tests/test-freadptr.c (main): Likewise. * tests/test-freadptr2.c (main): Free allocated memory. * tests/test-freadseek.c (main): Likewise. * tests/test-gc-arcfour.c (main): Close allocated context. * tests/test-gc-arctwo.c (main): Likewise. * tests/test-gc-des.c (main): Close all allocated contexts. * tests/test-pipe-filter-gi1.c (main): Free allocated memory. * tests/test-pipe-filter-ii1.c (main): Likewise. * tests/test-posix_spawn_file_actions_addchdir.c (main): Destroy the allocated file actions. * tests/test-posix_spawn_file_actions_addclose.c (main): Likewise. * tests/test-posix_spawn_file_actions_adddup2.c (main): Likewise. * tests/test-posix_spawn_file_actions_addopen.c (main): Likewise. * tests/test-sameacls.c (main): Free allocated memory and ACLs. * tests/test-strfmon_l.c (main): Free allocated locales. * tests/test-striconveh.c (main): Free allocated iconv_t objects. * tests/uniconv/test-u8-conv-to-enc.c (main): Free allocated memory. * tests/uniconv/test-u16-conv-to-enc.c (main): Likewise. * tests/uniconv/test-u32-conv-to-enc.c (main): Likewise. * tests/unistr/test-chr.h (main): Free input32. * tests/unistr/test-strchr.h (test_strchr): Likewise.
author Bruno Haible <bruno@clisp.org>
date Sun, 10 Mar 2019 14:05:09 +0100
parents 84fd38f4932c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8956
6ffde2a0e49c Tests for module 'uniconv/u16-conv-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.
8956
6ffde2a0e49c Tests for module 'uniconv/u16-conv-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: 8956
diff changeset
4 This program is free software: you can redistribute it and/or modify
8956
6ffde2a0e49c Tests for module 'uniconv/u16-conv-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: 8956
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: 8956
diff changeset
7 (at your option) any later version.
8956
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
8956
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "uniconv.h"
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <errno.h>
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <stdlib.h>
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <string.h>
6ffde2a0e49c Tests for module 'uniconv/u16-conv-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"
8956
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 /* Magic number for detecting bounds violations. */
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #define MAGIC 0x1983EFF1
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 static size_t *
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 new_offsets (size_t n)
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 {
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 size_t *offsets = (size_t *) malloc ((n + 1) * sizeof (size_t));
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 offsets[n] = MAGIC;
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 return offsets;
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 }
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 int
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 main ()
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 {
40155
84fd38f4932c tests: Fix some "unused variable" warnings.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
43 #if HAVE_ICONV
8956
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 static enum iconv_ilseq_handler handlers[] =
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 { iconveh_error, iconveh_question_mark, iconveh_escape_sequence };
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 size_t h;
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 size_t o;
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 size_t i;
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 /* Assume that iconv() supports at least the encodings ASCII, ISO-8859-1,
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 ISO-8859-2, and UTF-8. */
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 /* Test conversion from UTF-16 to ISO-8859-1 with no errors. */
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 for (h = 0; h < SIZEOF (handlers); h++)
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 {
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 enum iconv_ilseq_handler handler = handlers[h];
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 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: 11509
diff changeset
58 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
59 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's',
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
60 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h',
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
61 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
62 };
8956
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 for (o = 0; o < 2; o++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
65 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
66 size_t *offsets = (o ? new_offsets (SIZEOF (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
67 size_t length;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
68 char *result = u16_conv_to_encoding ("ISO-8859-1", handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
69 input, SIZEOF (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
70 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
71 NULL, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
72 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
73 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
74 ASSERT (memcmp (result, expected, length) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
75 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
76 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
77 for (i = 0; i < 37; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
78 ASSERT (offsets[i] == i);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
79 ASSERT (offsets[37] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
80 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
81 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
82 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
83 }
8956
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 }
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 /* Test conversion from UTF-16 to ISO-8859-1 with EILSEQ. */
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 for (h = 0; h < SIZEOF (handlers); h++)
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 {
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 enum iconv_ilseq_handler handler = handlers[h];
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 static const uint16_t input[] = /* Rafał Maszkowski */
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
91 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
92 '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: 11509
diff changeset
93 's', 'k', 'i'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
94 };
8956
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 for (o = 0; o < 2; o++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
96 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
97 size_t *offsets = (o ? new_offsets (SIZEOF (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
98 size_t length = 0xdead;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
99 char *result = u16_conv_to_encoding ("ISO-8859-1", handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
100 input, SIZEOF (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
101 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
102 NULL, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
103 switch (handler)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
104 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
105 case iconveh_error:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
106 ASSERT (result == NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
107 ASSERT (errno == EILSEQ);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
108 ASSERT (length == 0xdead);
40224
5d9b82ca550a tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents: 40155
diff changeset
109 if (o)
5d9b82ca550a tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents: 40155
diff changeset
110 free (offsets);
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
111 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
112 case iconveh_question_mark:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
113 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
114 static const char expected[] = "Rafa? Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
115 static const char expected_translit[] = "Rafal Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
116 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
117 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
118 ASSERT (memcmp (result, expected, length) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
119 || memcmp (result, expected_translit, length) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
120 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
121 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
122 for (i = 0; i < 16; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
123 ASSERT (offsets[i] == i);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
124 ASSERT (offsets[16] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
125 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
126 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
127 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
128 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
129 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
130 case iconveh_escape_sequence:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
131 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
132 static const char expected[] = "Rafa\\u0142 Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
133 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
134 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
135 ASSERT (memcmp (result, expected, length) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
136 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
137 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
138 for (i = 0; i < 16; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
139 ASSERT (offsets[i] == (i < 5 ? i : i + 5));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
140 ASSERT (offsets[16] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
141 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
142 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
143 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
144 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
145 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
146 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
147 }
8956
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 }
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 /* Test conversion from UTF-16 to ISO-8859-1 with EINVAL. */
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 for (h = 0; h < SIZEOF (handlers); h++)
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 {
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 enum iconv_ilseq_handler handler = handlers[h];
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 static const uint16_t input[] = { 0xD845 };
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 for (o = 0; o < 2; o++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
156 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
157 size_t *offsets = (o ? new_offsets (SIZEOF (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
158 size_t length;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
159 char *result = u16_conv_to_encoding ("ISO-8859-1", handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
160 input, SIZEOF (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
161 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
162 NULL, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
163 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
164 ASSERT (length == strlen (""));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
165 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
166 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
167 ASSERT (offsets[0] == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
168 ASSERT (offsets[1] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
169 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
170 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
171 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
172 }
8956
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 }
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 #endif
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 return 0;
6ffde2a0e49c Tests for module 'uniconv/u16-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 }