annotate tests/uniconv/test-u32-conv-to-enc.c @ 9309:bbbbbf4cd1c5

Change copyright notice from GPLv2+ to GPLv3+.
author Bruno Haible <bruno@clisp.org>
date Sun, 07 Oct 2007 19:14:58 +0200
parents 9ba2ee3529dc
children 0be6f1ab456d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8958
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of conversion from UTF-32 to legacy encodings.
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2007 Free Software Foundation, Inc.
9ba2ee3529dc Tests for module 'uniconv/u32-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: 8958
diff changeset
4 This program is free software: you can redistribute it and/or modify
8958
9ba2ee3529dc Tests for module 'uniconv/u32-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: 8958
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: 8958
diff changeset
7 (at your option) any later version.
8958
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-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: 8958
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8958
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "uniconv.h"
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <errno.h>
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <stdio.h>
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <stdlib.h>
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <string.h>
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #define SIZEOF(array) (sizeof (array) / sizeof (array[0]))
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #define ASSERT(expr) \
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 do \
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 { \
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 if (!(expr)) \
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 { \
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 abort (); \
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 } \
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 } \
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 while (0)
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 /* Magic number for detecting bounds violations. */
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 #define MAGIC 0x1983EFF1
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 static size_t *
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 new_offsets (size_t n)
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 {
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 size_t *offsets = (size_t *) malloc ((n + 1) * sizeof (size_t));
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 offsets[n] = MAGIC;
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 return offsets;
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 }
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 int
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 main ()
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 {
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 static enum iconv_ilseq_handler handlers[] =
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 { iconveh_error, iconveh_question_mark, iconveh_escape_sequence };
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 size_t h;
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 size_t o;
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 size_t i;
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 #if HAVE_ICONV
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 /* Assume that iconv() supports at least the encodings ASCII, ISO-8859-1,
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 ISO-8859-2, and UTF-8. */
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 /* Test conversion from UTF-32 to ISO-8859-1 with no errors. */
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 for (h = 0; h < SIZEOF (handlers); h++)
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 {
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 enum iconv_ilseq_handler handler = handlers[h];
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 static const uint32_t input[] = /* Ärger mit bösen Bübchen ohne Augenmaß */
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 {
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's',
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h',
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 };
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 for (o = 0; o < 2; o++)
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 {
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 size_t *offsets = (o ? new_offsets (SIZEOF (input)) : NULL);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 char *result = NULL;
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 size_t length = 0;
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 int retval = u32_conv_to_encoding ("ISO-8859-1", handler,
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 input, SIZEOF (input),
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 offsets,
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 &result, &length);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 ASSERT (retval == 0);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 ASSERT (length == strlen (expected));
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 ASSERT (result != NULL);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 ASSERT (memcmp (result, expected, length) == 0);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 if (o)
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 {
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 for (i = 0; i < 37; i++)
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 ASSERT (offsets[i] == i);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 ASSERT (offsets[37] == MAGIC);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 free (offsets);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 }
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 free (result);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 }
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 }
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 /* Test conversion from UTF-32 to ISO-8859-1 with EILSEQ. */
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 for (h = 0; h < SIZEOF (handlers); h++)
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 {
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 enum iconv_ilseq_handler handler = handlers[h];
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 static const uint32_t input[] = /* Rafał Maszkowski */
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 {
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w',
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 's', 'k', 'i'
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 };
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 for (o = 0; o < 2; o++)
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 {
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 size_t *offsets = (o ? new_offsets (SIZEOF (input)) : NULL);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 char *result = NULL;
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 size_t length = 0;
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 int retval = u32_conv_to_encoding ("ISO-8859-1", handler,
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 input, SIZEOF (input),
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 offsets,
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 &result, &length);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 switch (handler)
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 {
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 case iconveh_error:
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 ASSERT (retval == -1 && errno == EILSEQ);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 ASSERT (result == NULL);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 ASSERT (length == 0);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 break;
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 case iconveh_question_mark:
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 {
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 static const char expected[] = "Rafa? Maszkowski";
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 static const char expected_translit[] = "Rafal Maszkowski";
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 ASSERT (retval == 0);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 ASSERT (length == strlen (expected));
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 ASSERT (result != NULL);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 ASSERT (memcmp (result, expected, length) == 0
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 || memcmp (result, expected_translit, length) == 0);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 if (o)
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 {
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 for (i = 0; i < 16; i++)
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 ASSERT (offsets[i] == i);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 ASSERT (offsets[16] == MAGIC);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 free (offsets);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 }
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 free (result);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 }
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 break;
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 case iconveh_escape_sequence:
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 {
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 static const char expected[] = "Rafa\\u0142 Maszkowski";
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 ASSERT (retval == 0);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 ASSERT (length == strlen (expected));
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 ASSERT (result != NULL);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 ASSERT (memcmp (result, expected, length) == 0);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 if (o)
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 {
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 for (i = 0; i < 16; i++)
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 ASSERT (offsets[i] == (i < 5 ? i : i + 5));
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 ASSERT (offsets[16] == MAGIC);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 free (offsets);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 }
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 free (result);
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 }
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 break;
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 }
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 }
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 }
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 #endif
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 return 0;
9ba2ee3529dc Tests for module 'uniconv/u32-conv-to-enc'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 }