annotate tests/uniconv/test-u8-conv-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 5d9b82ca550a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8953
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of conversion from UTF-8 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.
8953
2b71f2b8d75b Tests for module 'uniconv/u8-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: 8953
diff changeset
4 This program is free software: you can redistribute it and/or modify
8953
2b71f2b8d75b Tests for module 'uniconv/u8-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: 8953
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: 8953
diff changeset
7 (at your option) any later version.
8953
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
2b71f2b8d75b Tests for module 'uniconv/u8-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/>. */
8953
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "uniconv.h"
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <errno.h>
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <stdlib.h>
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <string.h>
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include "unistr.h"
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
28 #include "macros.h"
8953
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 /* Magic number for detecting bounds violations. */
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 #define MAGIC 0x1983EFF1
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 static size_t *
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 new_offsets (size_t n)
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 {
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 size_t *offsets = (size_t *) malloc ((n + 1) * sizeof (size_t));
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 offsets[n] = MAGIC;
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 return offsets;
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 }
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 int
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 main ()
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-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
8953
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 static enum iconv_ilseq_handler handlers[] =
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 { iconveh_error, iconveh_question_mark, iconveh_escape_sequence };
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 size_t h;
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 size_t o;
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 size_t i;
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 /* Assume that iconv() supports at least the encodings ASCII, ISO-8859-1,
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 ISO-8859-2, and UTF-8. */
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 for (h = 0; h < SIZEOF (handlers); h++)
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 {
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 enum iconv_ilseq_handler handler = handlers[h];
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 static const uint8_t input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237";
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-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: 11509
diff changeset
61 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
62 size_t *offsets = (o ? new_offsets (u8_strlen (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
63 size_t length;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
64 char *result = u8_conv_to_encoding ("ISO-8859-1", handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
65 input, u8_strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
66 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
67 NULL, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
68 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
69 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
70 ASSERT (memcmp (result, expected, length) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
71 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
72 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
73 for (i = 0; i < 41; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
74 ASSERT (offsets[i] == (i < 1 ? i :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
75 i == 1 ? (size_t)(-1) :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
76 i < 13 ? i - 1 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
77 i == 13 ? (size_t)(-1) :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
78 i < 20 ? i - 2 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
79 i == 20 ? (size_t)(-1) :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
80 i < 40 ? i - 3 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
81 i == 40 ? (size_t)(-1) :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
82 i - 4));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
83 ASSERT (offsets[41] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
84 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
85 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
86 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
87 }
8953
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 }
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 for (h = 0; h < SIZEOF (handlers); h++)
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 {
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 enum iconv_ilseq_handler handler = handlers[h];
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 static const uint8_t input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */
2b71f2b8d75b Tests for module 'uniconv/u8-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 (u8_strlen (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 = u8_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, u8_strlen (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);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
109 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
110 case iconveh_question_mark:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
111 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
112 static const char expected[] = "Rafa? Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
113 static const char expected_translit[] = "Rafal Maszkowski";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
114 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
115 ASSERT (length == strlen (expected));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
116 ASSERT (memcmp (result, expected, length) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
117 || memcmp (result, expected_translit, length) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
118 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
119 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
120 for (i = 0; i < 17; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
121 ASSERT (offsets[i] == (i < 5 ? i :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
122 i == 5 ? (size_t)(-1) :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
123 i - 1));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
124 ASSERT (offsets[17] == 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 < 17; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
139 ASSERT (offsets[i] == (i < 5 ? i :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
140 i == 5 ? (size_t)(-1) :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
141 i + 4));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
142 ASSERT (offsets[17] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
143 free (offsets);
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 free (result);
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 break;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
148 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
149 }
8953
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 }
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 for (h = 0; h < SIZEOF (handlers); h++)
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 {
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 enum iconv_ilseq_handler handler = handlers[h];
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 static const uint8_t input[] = "\342";
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 for (o = 0; o < 2; o++)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
158 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
159 size_t *offsets = (o ? new_offsets (u8_strlen (input)) : NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
160 size_t length;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
161 char *result = u8_conv_to_encoding ("ISO-8859-1", handler,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
162 input, u8_strlen (input),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
163 offsets,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
164 NULL, &length);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
165 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
166 ASSERT (length == strlen (""));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
167 if (o)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
168 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
169 ASSERT (offsets[0] == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
170 ASSERT (offsets[1] == MAGIC);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
171 free (offsets);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
172 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
173 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11509
diff changeset
174 }
8953
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 }
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 #endif
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 return 0;
2b71f2b8d75b Tests for module 'uniconv/u8-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 }