comparison mupdf-source/thirdparty/zint/backend/tests/test_eci.c @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 /*
2 libzint - the open source barcode library
3 Copyright (C) 2019-2024 Robin Stuart <rstuart114@gmail.com>
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 3. Neither the name of the project nor the names of its contributors
15 may be used to endorse or promote products derived from this software
16 without specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 SUCH DAMAGE.
29 */
30 /* SPDX-License-Identifier: BSD-3-Clause */
31
32 #include "testcommon.h"
33 #include "../eci.h"
34
35 static void test_bom(const testCtx *const p_ctx) {
36 int debug = p_ctx->debug;
37
38 char data[] = "\xEF\xBB\xBF‹"; /* U+FEFF BOM, with U+2039 (only in Windows pages) */
39
40 char expected[] =
41 "111111100001001111111"
42 "100000101110101000001"
43 "101110100000101011101"
44 "101110100111101011101"
45 "101110100110101011101"
46 "100000101011001000001"
47 "111111101010101111111"
48 "000000001100100000000"
49 "000011110110101100010"
50 "010011011100000100001"
51 "111110110001011111000"
52 "000110000110001011100"
53 "000111110111100001011"
54 "000000001011001000111"
55 "111111101010111001010"
56 "100000101110101101010"
57 "101110101110001110101"
58 "101110100001100101001"
59 "101110100111111111100"
60 "100000100010011010111"
61 "111111100101101000101";
62
63 int length, ret;
64 struct zint_symbol *symbol;
65
66 int width, height;
67
68 testStart("test_bom");
69
70 symbol = ZBarcode_Create();
71 assert_nonnull(symbol, "Symbol not created\n");
72
73 symbol->symbology = BARCODE_QRCODE;
74 symbol->input_mode = UNICODE_MODE;
75 symbol->option_1 = 4;
76 symbol->option_2 = 1;
77 symbol->option_3 = 5 << 8; /* Mask 100 (instead of automatic 010) */
78 symbol->debug |= debug;
79
80 length = (int) strlen(data);
81
82 ret = ZBarcode_Encode(symbol, (unsigned char *) data, length);
83 assert_equal(ret, ZINT_WARN_USES_ECI, "ZBarcode_Encode ret %d != ZINT_WARN_USES_ECI\n", ret);
84 assert_equal(symbol->eci, 21, "eci %d != 21\n", symbol->eci); /* ECI 21 == Windows-1250 */
85
86 ret = testUtilModulesCmp(symbol, expected, &width, &height);
87 assert_equal(ret, 0, "testUtilModulesEqual ret %d != 0, width %d, height %d\n", ret, width, height);
88
89 ZBarcode_Delete(symbol);
90
91 testFinish();
92 }
93
94 static void test_iso_8859_16(const testCtx *const p_ctx) {
95 int debug = p_ctx->debug;
96
97 char data[] = "Ț"; /* U+021A only in ISO 8859-16 */
98 int length, ret;
99 struct zint_symbol *symbol;
100
101 testStart("test_iso_8859_16");
102
103 symbol = ZBarcode_Create();
104 assert_nonnull(symbol, "Symbol not created\n");
105
106 symbol->symbology = BARCODE_QRCODE;
107 symbol->input_mode = UNICODE_MODE;
108 symbol->debug |= debug;
109
110 length = (int) strlen(data);
111
112 ret = ZBarcode_Encode(symbol, (unsigned char *) data, length);
113 assert_equal(ret, ZINT_WARN_USES_ECI, "ZBarcode_Encode ret %d != ZINT_WARN_USES_ECI\n", ret);
114 assert_equal(symbol->eci, 18, "eci %d != 18\n", symbol->eci); /* ECI 18 == ISO 8859-16 */
115
116 ZBarcode_Delete(symbol);
117
118 testFinish();
119 }
120
121 /* Only testing standard non-extended barcodes here, ie not QRCODE, MICROQR, GRIDMATRIX, HANXIN or UPNQR */
122 static void test_reduced_charset_input(const testCtx *const p_ctx) {
123 int debug = p_ctx->debug;
124
125 struct item {
126 int symbology;
127 int input_mode;
128 int eci;
129 char *data;
130 int ret;
131 int expected_eci;
132 char *comment;
133 };
134 /*
135 é U+00E9 in ISO 8859-1 plus other ISO 8859 (but not in ISO 8859-7 or ISO 8859-11), Win 1250 plus other Win, not in Shift JIS
136 β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in Shift JIS
137 ก U+0E01 in ISO 8859-11 Thai (but not other ISO 8859 or Win page), not in Shift JIS
138 Ж U+0416 in ISO 8859-5 Cyrillic (but not other ISO 8859), Win 1251, in Shift JIS
139 ກ U+0E81 Lao not in any ISO 8859 (or Win page) or Shift JIS
140 … U+2026 in Win pages (but not in any ISO 8859)
141 テ U+30C6 katakana, in Shift JIS
142 */
143 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
144 struct item data[] = {
145 /* 0*/ { BARCODE_CODE11, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "ASCII subset only" },
146 /* 1*/ { BARCODE_C25STANDARD, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "Numbers only" },
147 /* 2*/ { BARCODE_CODE39, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "ASCII subset only" },
148 /* 3*/ { BARCODE_EXCODE39, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "ASCII only" },
149 /* 4*/ { BARCODE_EANX, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "Numbers only" },
150 /* 5*/ { BARCODE_CODABAR, UNICODE_MODE, 0, "AéB", ZINT_ERROR_INVALID_DATA, -1, "ASCII subset only" },
151 /* 6*/ { BARCODE_CODE128, UNICODE_MODE, 0, "é", 0, 0, "" },
152 /* 7*/ { BARCODE_CODE128, UNICODE_MODE, 3, "é", ZINT_ERROR_INVALID_OPTION, -1, "Does not support ECI" },
153 /* 8*/ { BARCODE_CODE128, UNICODE_MODE, 0, "β", ZINT_ERROR_INVALID_DATA, -1, "β not in ISO 8859-1" },
154 /* 9*/ { BARCODE_DPLEIT, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "Numbers only" },
155 /* 10*/ { BARCODE_CODE16K, UNICODE_MODE, 0, "é", 0, 0, "" },
156 /* 11*/ { BARCODE_CODE16K, UNICODE_MODE, 3, "é", ZINT_ERROR_INVALID_OPTION, -1, "Does not support ECI" },
157 /* 12*/ { BARCODE_CODE16K, UNICODE_MODE, 0, "β", ZINT_ERROR_INVALID_DATA, -1, "β not in ISO 8859-1" },
158 /* 13*/ { BARCODE_CODE49, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "ASCII only" },
159 /* 14*/ { BARCODE_CODE93, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "ASCII subset only" },
160 /* 15*/ { BARCODE_FLAT, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "Numbers only" },
161 /* 16*/ { BARCODE_DBAR_OMN, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "Numbers only" },
162 /* 17*/ { BARCODE_DBAR_EXP, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "ASCII subset only" },
163 /* 18*/ { BARCODE_LOGMARS, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "ASCII subset only" },
164 /* 19*/ { BARCODE_PDF417, UNICODE_MODE, 0, "é", 0, 0, "" },
165 /* 20*/ { BARCODE_PDF417, UNICODE_MODE, 3, "é", 0, 3, "Supports ECI" },
166 /* 21*/ { BARCODE_PDF417, UNICODE_MODE, 3, "\302\200", ZINT_ERROR_INVALID_DATA, -1, "U+0080" },
167 /* 22*/ { BARCODE_PDF417, UNICODE_MODE, 3, "\302\237", ZINT_ERROR_INVALID_DATA, -1, "U+009F" },
168 /* 23*/ { BARCODE_PDF417, UNICODE_MODE, 0, "˘", ZINT_WARN_USES_ECI, 4, "In ISO 8859-2 and ISO 8859-3 only of single-byte pages" },
169 /* 24*/ { BARCODE_PDF417, UNICODE_MODE, 4, "˘", 0, 4, "" },
170 /* 25*/ { BARCODE_PDF417, UNICODE_MODE, 0, "Ħ", ZINT_WARN_USES_ECI, 5, "In ISO 8859-3 only of single-byte pages" },
171 /* 26*/ { BARCODE_PDF417, UNICODE_MODE, 5, "Ħ", 0, 5, "" },
172 /* 27*/ { BARCODE_PDF417, UNICODE_MODE, 0, "ĸ", ZINT_WARN_USES_ECI, 6, "In ISO 8859-4 and ISO 8859-6 only of single-byte pages" },
173 /* 28*/ { BARCODE_PDF417, UNICODE_MODE, 6, "ĸ", 0, 6, "" },
174 /* 29*/ { BARCODE_PDF417, UNICODE_MODE, 0, "Ж", ZINT_WARN_USES_ECI, 7, "In ISO 8859-5 and Win 1251 only of single-byte pages" },
175 /* 30*/ { BARCODE_PDF417, UNICODE_MODE, 7, "Ж", 0, 7, "" },
176 /* 31*/ { BARCODE_PDF417, UNICODE_MODE, 0, "غ", ZINT_WARN_USES_ECI, 8, "In ISO 8859-6 and Win 1256 only of single-byte pages" },
177 /* 32*/ { BARCODE_PDF417, UNICODE_MODE, 8, "غ", 0, 8, "" },
178 /* 33*/ { BARCODE_PDF417, UNICODE_MODE, 0, "β", ZINT_WARN_USES_ECI, 9, "In ISO 8859-7 only of single-byte pages" },
179 /* 34*/ { BARCODE_PDF417, UNICODE_MODE, 9, "β", 0, 9, "" },
180 /* 35*/ { BARCODE_PDF417, UNICODE_MODE, 0, "‗", ZINT_WARN_USES_ECI, 10, "In ISO 8859-8 only of single-byte pages" },
181 /* 36*/ { BARCODE_PDF417, UNICODE_MODE, 10, "‗", 0, 10, "" },
182 /* 37*/ { BARCODE_PDF417, UNICODE_MODE, 11, "Ğ", 0, 11, "In ISO 8859-9; Note no characters in ISO 8859-9 that aren't also in earlier ISO pages" },
183 /* 38*/ { BARCODE_PDF417, UNICODE_MODE, 12, "Ĩ", 0, 12, "In ISO 8859-10; Note no characters in ISO 8859-10 that aren't also in earlier ISO pages" },
184 /* 39*/ { BARCODE_PDF417, UNICODE_MODE, 0, "ก", ZINT_WARN_USES_ECI, 13, "" },
185 /* 40*/ { BARCODE_PDF417, UNICODE_MODE, 13, "ก", 0, 13, "" },
186 /* 41*/ { BARCODE_PDF417, UNICODE_MODE, 14, "A", ZINT_ERROR_INVALID_OPTION, -1, "Reserved ECI" },
187 /* 42*/ { BARCODE_PDF417, UNICODE_MODE, 0, "„", ZINT_WARN_USES_ECI, 15, "" },
188 /* 43*/ { BARCODE_PDF417, UNICODE_MODE, 15, "„", 0, 15, "In ISO 8859-13 and ISO 8859-16 and Win 125x pages" },
189 /* 44*/ { BARCODE_PDF417, UNICODE_MODE, 0, "Ḃ", ZINT_WARN_USES_ECI, 16, "In ISO 8859-14 only of single-byte pages" },
190 /* 45*/ { BARCODE_PDF417, UNICODE_MODE, 16, "Ḃ", 0, 16, "" },
191 /* 46*/ { BARCODE_PDF417, UNICODE_MODE, 17, "Ž", 0, 17, "In ISO 8859-15; Note no characters in ISO 8859-15 that aren't also in earlier ISO pages" },
192 /* 47*/ { BARCODE_PDF417, UNICODE_MODE, 0, "Ș", ZINT_WARN_USES_ECI, 18, "In ISO 8859-16 only of single-byte pages" },
193 /* 48*/ { BARCODE_PDF417, UNICODE_MODE, 18, "Ș", 0, 18, "" },
194 /* 49*/ { BARCODE_PDF417, UNICODE_MODE, 0, "テ", ZINT_WARN_USES_ECI, 26, "Not in any single-byte page" },
195 /* 50*/ { BARCODE_PDF417, UNICODE_MODE, 19, "A", ZINT_ERROR_INVALID_OPTION, -1, "Reserved ECI" },
196 /* 51*/ { BARCODE_PDF417, UNICODE_MODE, 20, "テ", 0, 20, "In Shift JIS" },
197 /* 52*/ { BARCODE_PDF417, UNICODE_MODE, 20, "テテ", 0, 20, "In Shift JIS" },
198 /* 53*/ { BARCODE_PDF417, UNICODE_MODE, 20, "\\\\", 0, 20, "In Shift JIS" },
199 /* 54*/ { BARCODE_PDF417, UNICODE_MODE, 0, "…", ZINT_WARN_USES_ECI, 21, "In Win 1250 and other Win pages but not in ISO pages" },
200 /* 55*/ { BARCODE_PDF417, UNICODE_MODE, 21, "…", 0, 21, "" },
201 /* 56*/ { BARCODE_PDF417, UNICODE_MODE, 0, "Ґ", ZINT_WARN_USES_ECI, 22, "In Win 1251 only of single-byte pages" },
202 /* 57*/ { BARCODE_PDF417, UNICODE_MODE, 22, "Ґ", 0, 22, "" },
203 /* 58*/ { BARCODE_PDF417, UNICODE_MODE, 0, "˜", ZINT_WARN_USES_ECI, 23, "In Win 1252 only of single-byte pages" },
204 /* 59*/ { BARCODE_PDF417, UNICODE_MODE, 23, "˜", 0, 23, "" },
205 /* 60*/ { BARCODE_PDF417, UNICODE_MODE, 0, "پ", ZINT_WARN_USES_ECI, 24, "In Win 1256 only of single-byte pages" },
206 /* 61*/ { BARCODE_PDF417, UNICODE_MODE, 24, "پ", 0, 24, "" },
207 /* 62*/ { BARCODE_PDF417, UNICODE_MODE, 0, "က", ZINT_WARN_USES_ECI, 26, "Not in any single-byte page" },
208 /* 63*/ { BARCODE_PDF417, UNICODE_MODE, 25, "က", 0, 25, "In UCS-2BE" },
209 /* 64*/ { BARCODE_PDF417, UNICODE_MODE, 25, "ကက", 0, 25, "In UCS-2BE" },
210 /* 65*/ { BARCODE_PDF417, UNICODE_MODE, 25, "12", 0, 25, "UCS-2BE ASCII" },
211 /* 66*/ { BARCODE_PDF417, UNICODE_MODE, 0, "𐀀", ZINT_WARN_USES_ECI, 26, "Not in any single-byte page" },
212 /* 67*/ { BARCODE_PDF417, UNICODE_MODE, 25, "𐀀", 0, 25, "UTF-16BE (in Supplementary Plane)" },
213 /* 68*/ { BARCODE_PDF417, UNICODE_MODE, 0, "テ", ZINT_WARN_USES_ECI, 26, "Defaults to UTF-8 if not in any ISO 8859 or Win page" },
214 /* 69*/ { BARCODE_PDF417, UNICODE_MODE, 26, "テ", 0, 26, "" },
215 /* 70*/ { BARCODE_PDF417, UNICODE_MODE, 26, "テテ", 0, 26, "" },
216 /* 71*/ { BARCODE_PDF417, UNICODE_MODE, 27, "@", 0, 27, "ASCII" },
217 /* 72*/ { BARCODE_PDF417, UNICODE_MODE, 0, "龘", ZINT_WARN_USES_ECI, 26, "Not in any single-byte page" },
218 /* 73*/ { BARCODE_PDF417, UNICODE_MODE, 28, "龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
219 /* 74*/ { BARCODE_PDF417, UNICODE_MODE, 28, "龘龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
220 /* 75*/ { BARCODE_PDF417, UNICODE_MODE, 0, "齄", ZINT_WARN_USES_ECI, 26, "Not in any single-byte page" },
221 /* 76*/ { BARCODE_PDF417, UNICODE_MODE, 29, "齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
222 /* 77*/ { BARCODE_PDF417, UNICODE_MODE, 29, "齄齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
223 /* 78*/ { BARCODE_PDF417, UNICODE_MODE, 0, "가", ZINT_WARN_USES_ECI, 26, "Not in any single-byte page" },
224 /* 79*/ { BARCODE_PDF417, UNICODE_MODE, 30, "가", 0, 30, "U+AC00 in EUC-KR" },
225 /* 80*/ { BARCODE_PDF417, UNICODE_MODE, 30, "가가", 0, 30, "U+AC00 in EUC-KR" },
226 /* 81*/ { BARCODE_PDF417, UNICODE_MODE, 31, "A", 0, 31, "Undefined character set ECI - ignored for character set conversion" },
227 /* 82*/ { BARCODE_PDF417, UNICODE_MODE, 170, "?", 0, 170, "ASCII invariant" },
228 /* 83*/ { BARCODE_PDF417, UNICODE_MODE, 170, "@", ZINT_ERROR_INVALID_DATA, -1, "Not in ASCII invariant" },
229 /* 84*/ { BARCODE_PDF417, UNICODE_MODE, 0, "\200", ZINT_ERROR_INVALID_DATA, -1, "Not UTF-8" },
230 /* 85*/ { BARCODE_PDF417, DATA_MODE, 899, "\200", 0, 899, "8-bit binary" },
231 /* 86*/ { BARCODE_PDF417, UNICODE_MODE, 900, "é", 0, 900, "Non-character set ECIs > 899 ignored for character set conversion" },
232 /* 87*/ { BARCODE_PDF417, UNICODE_MODE, 900, "β", 0, 900, "Non-character set ECIs > 899 ignored for character set conversion" },
233 /* 88*/ { BARCODE_PDF417COMP, UNICODE_MODE, 0, "é", 0, 0, "" },
234 /* 89*/ { BARCODE_PDF417COMP, UNICODE_MODE, 3, "é", 0, 3, "Supports ECI" },
235 /* 90*/ { BARCODE_PDF417COMP, UNICODE_MODE, 0, "β", ZINT_WARN_USES_ECI, 9, "" },
236 /* 91*/ { BARCODE_PDF417COMP, UNICODE_MODE, 9, "β", 0, 9, "" },
237 /* 92*/ { BARCODE_PDF417COMP, UNICODE_MODE, 20, "テ", 0, 20, "In Shift JIS" },
238 /* 93*/ { BARCODE_PDF417COMP, UNICODE_MODE, 20, "テテ", 0, 20, "In Shift JIS" },
239 /* 94*/ { BARCODE_PDF417COMP, UNICODE_MODE, 25, "က", 0, 25, "In UCS-2BE" },
240 /* 95*/ { BARCODE_PDF417COMP, UNICODE_MODE, 25, "ကက", 0, 25, "In UCS-2BE" },
241 /* 96*/ { BARCODE_PDF417COMP, UNICODE_MODE, 25, "12", 0, 25, "ASCII" },
242 /* 97*/ { BARCODE_PDF417COMP, UNICODE_MODE, 26, "テ", 0, 26, "" },
243 /* 98*/ { BARCODE_PDF417COMP, UNICODE_MODE, 26, "テテ", 0, 26, "" },
244 /* 99*/ { BARCODE_PDF417COMP, UNICODE_MODE, 27, "@", 0, 27, "ASCII" },
245 /*100*/ { BARCODE_PDF417COMP, UNICODE_MODE, 28, "龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
246 /*101*/ { BARCODE_PDF417COMP, UNICODE_MODE, 28, "龘龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
247 /*102*/ { BARCODE_PDF417COMP, UNICODE_MODE, 29, "齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
248 /*103*/ { BARCODE_PDF417COMP, UNICODE_MODE, 29, "齄齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
249 /*104*/ { BARCODE_PDF417COMP, UNICODE_MODE, 30, "가", 0, 30, "U+AC00 in EUC-KR" },
250 /*105*/ { BARCODE_PDF417COMP, UNICODE_MODE, 30, "가가", 0, 30, "U+AC00 in EUC-KR" },
251 /*106*/ { BARCODE_MAXICODE, UNICODE_MODE, 0, "é", 0, 0, "" },
252 /*107*/ { BARCODE_MAXICODE, UNICODE_MODE, 3, "é", 0, 3, "Supports ECI" },
253 /*108*/ { BARCODE_MAXICODE, UNICODE_MODE, 0, "β", ZINT_WARN_USES_ECI, 9, "" },
254 /*109*/ { BARCODE_MAXICODE, UNICODE_MODE, 9, "β", 0, 9, "" },
255 /*110*/ { BARCODE_MAXICODE, UNICODE_MODE, 20, "テ", 0, 20, "In Shift JIS" },
256 /*111*/ { BARCODE_MAXICODE, UNICODE_MODE, 20, "テテ", 0, 20, "In Shift JIS" },
257 /*112*/ { BARCODE_MAXICODE, UNICODE_MODE, 25, "က", 0, 25, "In UCS-2BE" },
258 /*113*/ { BARCODE_MAXICODE, UNICODE_MODE, 25, "ကက", 0, 25, "In UCS-2BE" },
259 /*114*/ { BARCODE_MAXICODE, UNICODE_MODE, 25, "12", 0, 25, "ASCII" },
260 /*115*/ { BARCODE_MAXICODE, UNICODE_MODE, 26, "テ", 0, 26, "" },
261 /*116*/ { BARCODE_MAXICODE, UNICODE_MODE, 26, "テテ", 0, 26, "" },
262 /*117*/ { BARCODE_MAXICODE, UNICODE_MODE, 27, "@", 0, 27, "ASCII" },
263 /*118*/ { BARCODE_MAXICODE, UNICODE_MODE, 28, "龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
264 /*119*/ { BARCODE_MAXICODE, UNICODE_MODE, 28, "龘龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
265 /*120*/ { BARCODE_MAXICODE, UNICODE_MODE, 29, "齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
266 /*121*/ { BARCODE_MAXICODE, UNICODE_MODE, 29, "齄齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
267 /*122*/ { BARCODE_MAXICODE, UNICODE_MODE, 30, "가", 0, 30, "U+AC00 in EUC-KR" },
268 /*123*/ { BARCODE_MAXICODE, UNICODE_MODE, 30, "가가", 0, 30, "U+AC00 in EUC-KR" },
269 /*124*/ { BARCODE_CODE128AB, UNICODE_MODE, 0, "é", 0, 0, "" },
270 /*125*/ { BARCODE_CODE128AB, UNICODE_MODE, 3, "é", ZINT_ERROR_INVALID_OPTION, -1, "Does not support ECI" },
271 /*126*/ { BARCODE_CODE128AB, UNICODE_MODE, 0, "β", ZINT_ERROR_INVALID_DATA, -1, "β not in ISO 8859-1" },
272 /*127*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 0, "é", 0, 0, "" },
273 /*128*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 3, "é", 0, 3, "Supports ECI" },
274 /*129*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 0, "β", ZINT_WARN_USES_ECI, 9, "" },
275 /*130*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 9, "β", 0, 9, "" },
276 /*131*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 20, "テ", 0, 20, "In Shift JIS" },
277 /*132*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 20, "テテ", 0, 20, "In Shift JIS" },
278 /*133*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 25, "က", 0, 25, "In UCS-2BE" },
279 /*134*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 25, "ကက", 0, 25, "In UCS-2BE" },
280 /*135*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 25, "12", 0, 25, "ASCII" },
281 /*136*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 26, "テ", 0, 26, "" },
282 /*137*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 26, "テテ", 0, 26, "" },
283 /*138*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 28, "龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
284 /*139*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 28, "龘龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
285 /*140*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 29, "齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
286 /*141*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 29, "齄齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
287 /*142*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 30, "가", 0, 30, "U+AC00 in EUC-KR" },
288 /*143*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 30, "가가", 0, 30, "U+AC00 in EUC-KR" },
289 /*144*/ { BARCODE_CODABLOCKF, UNICODE_MODE, 0, "é", 0, 0, "" },
290 /*145*/ { BARCODE_CODABLOCKF, UNICODE_MODE, 3, "é", ZINT_ERROR_INVALID_OPTION, -1, "Does not support ECI" },
291 /*146*/ { BARCODE_CODABLOCKF, UNICODE_MODE, 0, "β", ZINT_ERROR_INVALID_DATA, -1, "β not in ISO 8859-1" },
292 /*147*/ { BARCODE_NVE18, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "Numbers only" },
293 /*148*/ { BARCODE_MICROPDF417, UNICODE_MODE, 0, "é", 0, 0, "" },
294 /*149*/ { BARCODE_MICROPDF417, UNICODE_MODE, 3, "é", 0, 3, "Supports ECI" },
295 /*150*/ { BARCODE_MICROPDF417, UNICODE_MODE, 0, "β", ZINT_WARN_USES_ECI, 9, "" },
296 /*151*/ { BARCODE_MICROPDF417, UNICODE_MODE, 9, "β", 0, 9, "" },
297 /*152*/ { BARCODE_MICROPDF417, UNICODE_MODE, 20, "テ", 0, 20, "In Shift JIS" },
298 /*153*/ { BARCODE_MICROPDF417, UNICODE_MODE, 20, "テテ", 0, 20, "In Shift JIS" },
299 /*154*/ { BARCODE_MICROPDF417, UNICODE_MODE, 25, "က", 0, 25, "In UCS-2BE" },
300 /*155*/ { BARCODE_MICROPDF417, UNICODE_MODE, 25, "ကက", 0, 25, "In UCS-2BE" },
301 /*156*/ { BARCODE_MICROPDF417, UNICODE_MODE, 25, "12", 0, 25, "ASCII" },
302 /*157*/ { BARCODE_MICROPDF417, UNICODE_MODE, 26, "テ", 0, 26, "" },
303 /*158*/ { BARCODE_MICROPDF417, UNICODE_MODE, 26, "テテ", 0, 26, "" },
304 /*159*/ { BARCODE_MICROPDF417, UNICODE_MODE, 28, "龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
305 /*160*/ { BARCODE_MICROPDF417, UNICODE_MODE, 28, "龘龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
306 /*161*/ { BARCODE_MICROPDF417, UNICODE_MODE, 29, "齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
307 /*162*/ { BARCODE_MICROPDF417, UNICODE_MODE, 29, "齄齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
308 /*163*/ { BARCODE_MICROPDF417, UNICODE_MODE, 30, "가", 0, 30, "U+AC00 in EUC-KR" },
309 /*164*/ { BARCODE_MICROPDF417, UNICODE_MODE, 30, "가가", 0, 30, "U+AC00 in EUC-KR" },
310 /*165*/ { BARCODE_USPS_IMAIL, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "Numbers/dash only" },
311 /*166*/ { BARCODE_AZTEC, UNICODE_MODE, 0, "é", 0, 0, "" },
312 /*167*/ { BARCODE_AZTEC, UNICODE_MODE, 3, "é", 0, 3, "Supports ECI" },
313 /*168*/ { BARCODE_AZTEC, UNICODE_MODE, 0, "β", ZINT_WARN_USES_ECI, 9, "" },
314 /*169*/ { BARCODE_AZTEC, UNICODE_MODE, 9, "β", 0, 9, "" },
315 /*170*/ { BARCODE_AZTEC, UNICODE_MODE, 20, "テ", 0, 20, "In Shift JIS" },
316 /*171*/ { BARCODE_AZTEC, UNICODE_MODE, 20, "テテ", 0, 20, "In Shift JIS" },
317 /*172*/ { BARCODE_AZTEC, UNICODE_MODE, 25, "က", 0, 25, "In UCS-2BE" },
318 /*173*/ { BARCODE_AZTEC, UNICODE_MODE, 25, "ကက", 0, 25, "In UCS-2BE" },
319 /*174*/ { BARCODE_AZTEC, UNICODE_MODE, 25, "12", 0, 25, "ASCII" },
320 /*175*/ { BARCODE_AZTEC, UNICODE_MODE, 26, "テ", 0, 26, "" },
321 /*176*/ { BARCODE_AZTEC, UNICODE_MODE, 26, "テテ", 0, 26, "" },
322 /*177*/ { BARCODE_AZTEC, UNICODE_MODE, 28, "龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
323 /*178*/ { BARCODE_AZTEC, UNICODE_MODE, 28, "龘龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
324 /*179*/ { BARCODE_AZTEC, UNICODE_MODE, 29, "齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
325 /*180*/ { BARCODE_AZTEC, UNICODE_MODE, 29, "齄齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
326 /*181*/ { BARCODE_AZTEC, UNICODE_MODE, 30, "가", 0, 30, "U+AC00 in EUC-KR" },
327 /*182*/ { BARCODE_AZTEC, UNICODE_MODE, 30, "가가", 0, 30, "U+AC00 in EUC-KR" },
328 /*183*/ { BARCODE_HIBC_128, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "HIBC ASCII subset only" },
329 /*184*/ { BARCODE_HIBC_AZTEC, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "HIBC ASCII subset only" },
330 /*185*/ { BARCODE_DOTCODE, UNICODE_MODE, 0, "é", 0, 0, "" },
331 /*186*/ { BARCODE_DOTCODE, UNICODE_MODE, 3, "é", 0, 3, "Supports ECI" },
332 /*187*/ { BARCODE_DOTCODE, UNICODE_MODE, 0, "β", ZINT_WARN_USES_ECI, 9, "" },
333 /*188*/ { BARCODE_DOTCODE, UNICODE_MODE, 9, "β", 0, 9, "" },
334 /*189*/ { BARCODE_DOTCODE, UNICODE_MODE, 20, "テ", 0, 20, "In Shift JIS" },
335 /*190*/ { BARCODE_DOTCODE, UNICODE_MODE, 20, "テテ", 0, 20, "In Shift JIS" },
336 /*191*/ { BARCODE_DOTCODE, UNICODE_MODE, 25, "က", 0, 25, "In UCS-2BE" },
337 /*192*/ { BARCODE_DOTCODE, UNICODE_MODE, 25, "ကက", 0, 25, "In UCS-2BE" },
338 /*193*/ { BARCODE_DOTCODE, UNICODE_MODE, 25, "12", 0, 25, "ASCII" },
339 /*194*/ { BARCODE_DOTCODE, UNICODE_MODE, 26, "テ", 0, 26, "" },
340 /*195*/ { BARCODE_DOTCODE, UNICODE_MODE, 26, "テテ", 0, 26, "" },
341 /*196*/ { BARCODE_DOTCODE, UNICODE_MODE, 28, "龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
342 /*197*/ { BARCODE_DOTCODE, UNICODE_MODE, 28, "龘龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
343 /*198*/ { BARCODE_DOTCODE, UNICODE_MODE, 29, "齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
344 /*199*/ { BARCODE_DOTCODE, UNICODE_MODE, 29, "齄齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
345 /*200*/ { BARCODE_DOTCODE, UNICODE_MODE, 30, "가", 0, 30, "U+AC00 in EUC-KR" },
346 /*201*/ { BARCODE_DOTCODE, UNICODE_MODE, 30, "가가", 0, 30, "U+AC00 in EUC-KR" },
347 /*202*/ { BARCODE_AZRUNE, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "Numbers <= 255 only" },
348 /*203*/ { BARCODE_CODE32, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "Numbers only" },
349 /*204*/ { BARCODE_CODEONE, UNICODE_MODE, 0, "é", 0, 0, "" },
350 /*205*/ { BARCODE_CODEONE, UNICODE_MODE, 3, "é", 0, 3, "Supports ECI" },
351 /*206*/ { BARCODE_CODEONE, UNICODE_MODE, 0, "β", ZINT_WARN_USES_ECI, 9, "" },
352 /*207*/ { BARCODE_CODEONE, UNICODE_MODE, 9, "β", 0, 9, "" },
353 /*208*/ { BARCODE_CODEONE, UNICODE_MODE, 20, "テ", 0, 20, "In Shift JIS" },
354 /*209*/ { BARCODE_CODEONE, UNICODE_MODE, 20, "テテ", 0, 20, "In Shift JIS" },
355 /*210*/ { BARCODE_CODEONE, UNICODE_MODE, 25, "က", 0, 25, "In UCS-2BE" },
356 /*211*/ { BARCODE_CODEONE, UNICODE_MODE, 25, "ကက", 0, 25, "In UCS-2BE" },
357 /*212*/ { BARCODE_CODEONE, UNICODE_MODE, 25, "12", 0, 25, "ASCII" },
358 /*213*/ { BARCODE_CODEONE, UNICODE_MODE, 26, "テ", 0, 26, "" },
359 /*214*/ { BARCODE_CODEONE, UNICODE_MODE, 26, "テテ", 0, 26, "" },
360 /*215*/ { BARCODE_CODEONE, UNICODE_MODE, 28, "龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
361 /*216*/ { BARCODE_CODEONE, UNICODE_MODE, 28, "龘龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
362 /*217*/ { BARCODE_CODEONE, UNICODE_MODE, 29, "齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
363 /*218*/ { BARCODE_CODEONE, UNICODE_MODE, 29, "齄齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
364 /*219*/ { BARCODE_CODEONE, UNICODE_MODE, 30, "가", 0, 30, "U+AC00 in EUC-KR" },
365 /*220*/ { BARCODE_CODEONE, UNICODE_MODE, 30, "가가", 0, 30, "U+AC00 in EUC-KR" },
366 /*221*/ { BARCODE_ULTRA, UNICODE_MODE, 0, "é", 0, 0, "" },
367 /*222*/ { BARCODE_ULTRA, UNICODE_MODE, 3, "é", 0, 3, "Supports ECI" },
368 /*223*/ { BARCODE_ULTRA, UNICODE_MODE, 0, "β", ZINT_WARN_USES_ECI, 9, "" },
369 /*224*/ { BARCODE_ULTRA, UNICODE_MODE, 9, "β", 0, 9, "" },
370 /*225*/ { BARCODE_ULTRA, UNICODE_MODE, 20, "テ", 0, 20, "In Shift JIS" },
371 /*226*/ { BARCODE_ULTRA, UNICODE_MODE, 20, "テテ", 0, 20, "In Shift JIS" },
372 /*227*/ { BARCODE_ULTRA, UNICODE_MODE, 25, "က", 0, 25, "In UCS-2BE" },
373 /*228*/ { BARCODE_ULTRA, UNICODE_MODE, 25, "ကက", 0, 25, "In UCS-2BE" },
374 /*229*/ { BARCODE_ULTRA, UNICODE_MODE, 25, "12", 0, 25, "ASCII" },
375 /*230*/ { BARCODE_ULTRA, UNICODE_MODE, 26, "テ", 0, 26, "" },
376 /*231*/ { BARCODE_ULTRA, UNICODE_MODE, 26, "テテ", 0, 26, "" },
377 /*232*/ { BARCODE_ULTRA, UNICODE_MODE, 28, "龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
378 /*233*/ { BARCODE_ULTRA, UNICODE_MODE, 28, "龘龘", 0, 28, "U+9F98 in Big5 but not in GB2312" },
379 /*234*/ { BARCODE_ULTRA, UNICODE_MODE, 29, "齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
380 /*235*/ { BARCODE_ULTRA, UNICODE_MODE, 29, "齄齄", 0, 29, "U+9F44 in GB2312 but not in Big5" },
381 /*236*/ { BARCODE_ULTRA, UNICODE_MODE, 30, "가", 0, 30, "U+AC00 in EUC-KR" },
382 /*237*/ { BARCODE_ULTRA, UNICODE_MODE, 30, "가가", 0, 30, "U+AC00 in EUC-KR" },
383 };
384 int data_size = ARRAY_SIZE(data);
385 int i, length, ret;
386 struct zint_symbol *symbol;
387
388 testStart("test_reduced_charset_input");
389
390 for (i = 0; i < data_size; i++) {
391
392 if (testContinue(p_ctx, i)) continue;
393
394 symbol = ZBarcode_Create();
395 assert_nonnull(symbol, "Symbol not created\n");
396
397 length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
398
399 ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
400 assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
401
402 if (data[i].expected_eci != -1) {
403 assert_equal(symbol->eci, data[i].expected_eci, "i:%d eci %d != %d\n", i, symbol->eci, data[i].expected_eci);
404 }
405
406 ZBarcode_Delete(symbol);
407 }
408
409 testFinish();
410 }
411
412 static int to_utf8(const unsigned int codepoint, unsigned char *buf) {
413 int length = 0;
414
415 if (codepoint < 0x80) {
416 buf[0] = (unsigned char) codepoint;
417 length = 1;
418 } else if (codepoint < 0x800) {
419 buf[0] = (unsigned char) (0xC0 | (codepoint >> 6));
420 buf[1] = (unsigned char) (0x80 | (codepoint & 0x3F));
421 length = 2;
422 } else if (codepoint < 0x10000) {
423 buf[0] = (unsigned char) (0xE0 | (codepoint >> 12));
424 buf[1] = (unsigned char) (0x80 | ((codepoint >> 6) & 0x3F));
425 buf[2] = (unsigned char) (0x80 | (codepoint & 0x3F));
426 length = 3;
427 } else {
428 buf[0] = (unsigned char) (0xF0 | (codepoint >> 18));
429 buf[1] = (unsigned char) (0x80 | ((codepoint >> 12) & 0x3F));
430 buf[2] = (unsigned char) (0x80 | ((codepoint >> 6) & 0x3F));
431 buf[3] = (unsigned char) (0x80 | (codepoint & 0x3F));
432 length = 4;
433 }
434 buf[length] = '\0';
435
436 return length;
437 }
438
439 /* Original eci.h tables */
440
441 static const unsigned short int iso_8859_1[] = {/* Latin alphabet No. 1 */
442 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
443 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
444 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
445 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf,
446 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
447 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
448 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
449 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff
450 };
451
452 static const unsigned short int iso_8859_2[] = {/* Latin alphabet No. 2 */
453 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
454 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
455 0x00a0, 0x0104, 0x02d8, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7, 0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b,
456 0x00b0, 0x0105, 0x02db, 0x0142, 0x00b4, 0x013e, 0x015b, 0x02c7, 0x00b8, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c,
457 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e,
458 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df,
459 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f,
460 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9
461 };
462
463 static const unsigned short int iso_8859_3[] = {/* Latin alphabet No. 3 */
464 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
465 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
466 0x00a0, 0x0126, 0x02d8, 0x00a3, 0x00a4, 0x0000, 0x0124, 0x00a7, 0x00a8, 0x0130, 0x015e, 0x011e, 0x0134, 0x00ad, 0x0000, 0x017b,
467 0x00b0, 0x0127, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x0125, 0x00b7, 0x00b8, 0x0131, 0x015f, 0x011f, 0x0135, 0x00bd, 0x0000, 0x017c,
468 0x00c0, 0x00c1, 0x00c2, 0x0000, 0x00c4, 0x010a, 0x0108, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
469 0x0000, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x0120, 0x00d6, 0x00d7, 0x011c, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x016c, 0x015c, 0x00df,
470 0x00e0, 0x00e1, 0x00e2, 0x0000, 0x00e4, 0x010b, 0x0109, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
471 0x0000, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x0121, 0x00f6, 0x00f7, 0x011d, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x016d, 0x015d, 0x02d9
472 };
473
474 static const unsigned short int iso_8859_4[] = {/* Latin alphabet No. 4 */
475 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
476 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
477 0x00a0, 0x0104, 0x0138, 0x0156, 0x00a4, 0x0128, 0x013b, 0x00a7, 0x00a8, 0x0160, 0x0112, 0x0122, 0x0166, 0x00ad, 0x017d, 0x00af, /* A5 0x012b -> 0x0128 */
478 0x00b0, 0x0105, 0x02db, 0x0157, 0x00b4, 0x0129, 0x013c, 0x02c7, 0x00b8, 0x0161, 0x0113, 0x0123, 0x0167, 0x014a, 0x017e, 0x014b,
479 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x012a,
480 0x0110, 0x0145, 0x014c, 0x0136, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x0168, 0x016a, 0x00df,
481 0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f, 0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x012b,
482 0x0111, 0x0146, 0x014d, 0x0137, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x0169, 0x016b, 0x02d9
483 };
484
485 static const unsigned short int iso_8859_5[] = {/* Latin/Cyrillic alphabet */
486 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
487 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
488 0x00a0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x00ad, 0x040e, 0x040f,
489 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f,
490 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f,
491 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, 0x043f,
492 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e, 0x044f,
493 0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457, 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x00a7, 0x045e, 0x045f
494 };
495
496 static const unsigned short int iso_8859_6[] = {/* Latin/Arabic alphabet */
497 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
498 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
499 0x00a0, 0x0000, 0x0000, 0x0000, 0x00a4, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x060c, 0x00ad, 0x0000, 0x0000,
500 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x061b, 0x0000, 0x0000, 0x0000, 0x061f,
501 0x0000, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627, 0x0628, 0x0629, 0x062a, 0x062b, 0x062c, 0x062d, 0x062e, 0x062f,
502 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637, 0x0638, 0x0639, 0x063a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
503 0x0640, 0x0641, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647, 0x0648, 0x0649, 0x064a, 0x064b, 0x064c, 0x064d, 0x064e, 0x064f,
504 0x0650, 0x0651, 0x0652, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
505 };
506
507 static const unsigned short int iso_8859_7[] = {/* Latin/Greek alphabet */
508 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
509 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
510 0x00a0, 0x2018, 0x2019, 0x00a3, 0x20ac, 0x20af, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x037a, 0x00ab, 0x00ac, 0x00ad, 0x0000, 0x2015,
511 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x0384, 0x0385, 0x0386, 0x00b7, 0x0388, 0x0389, 0x038a, 0x00bb, 0x038c, 0x00bd, 0x038e, 0x038f,
512 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f,
513 0x03a0, 0x03a1, 0x0000, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7, 0x03a8, 0x03a9, 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af,
514 0x03b0, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf,
515 0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, 0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce, 0x0000
516 };
517
518 static const unsigned short int iso_8859_8[] = {/* Latin/Hebrew alphabet */
519 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
520 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
521 0x00a0, 0x0000, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00d7, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
522 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00f7, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x0000,
523 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
524 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2017,
525 0x05d0, 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x05d5, 0x05d6, 0x05d7, 0x05d8, 0x05d9, 0x05da, 0x05db, 0x05dc, 0x05dd, 0x05de, 0x05df,
526 0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, 0x05e6, 0x05e7, 0x05e8, 0x05e9, 0x05ea, 0x0000, 0x0000, 0x200e, 0x200f, 0x0000
527 };
528
529 static const unsigned short int iso_8859_9[] = {/* Latin alphabet No. 5 */
530 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
531 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
532 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
533 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf,
534 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
535 0x011e, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x0130, 0x015e, 0x00df,
536 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
537 0x011f, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0131, 0x015f, 0x00ff
538 };
539
540 static const unsigned short int iso_8859_10[] = {/* Latin alphabet No. 6 */
541 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
542 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
543 0x00a0, 0x0104, 0x0112, 0x0122, 0x012a, 0x0128, 0x0136, 0x00a7, 0x013b, 0x0110, 0x0160, 0x0166, 0x017d, 0x00ad, 0x016a, 0x014a, /* A5 0x012b -> 0x0128 */
544 0x00b0, 0x0105, 0x0113, 0x0123, 0x012b, 0x0129, 0x0137, 0x00b7, 0x013c, 0x0111, 0x0161, 0x0167, 0x017e, 0x2015, 0x016b, 0x014b,
545 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x00cf,
546 0x00d0, 0x0145, 0x014c, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x0168, 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
547 0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f, 0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x00ef,
548 0x00f0, 0x0146, 0x014d, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x0169, 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x0138
549 };
550
551 static const unsigned short int iso_8859_11[] = {/* Latin/Thai alphabet */
552 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
553 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
554 0x00a0, 0x0e01, 0x0e02, 0x0e03, 0x0e04, 0x0e05, 0x0e06, 0x0e07, 0x0e08, 0x0e09, 0x0e0a, 0x0e0b, 0x0e0c, 0x0e0d, 0x0e0e, 0x0e0f,
555 0x0e10, 0x0e11, 0x0e12, 0x0e13, 0x0e14, 0x0e15, 0x0e16, 0x0e17, 0x0e18, 0x0e19, 0x0e1a, 0x0e1b, 0x0e1c, 0x0e1d, 0x0e1e, 0x0e1f,
556 0x0e20, 0x0e21, 0x0e22, 0x0e23, 0x0e24, 0x0e25, 0x0e26, 0x0e27, 0x0e28, 0x0e29, 0x0e2a, 0x0e2b, 0x0e2c, 0x0e2d, 0x0e2e, 0x0e2f,
557 0x0e30, 0x0e31, 0x0e32, 0x0e33, 0x0e34, 0x0e35, 0x0e36, 0x0e37, 0x0e38, 0x0e39, 0x0e3a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0e3f, /* D5 0x0e36 -> 0x0e35 */
558 0x0e40, 0x0e41, 0x0e42, 0x0e43, 0x0e44, 0x0e45, 0x0e46, 0x0e47, 0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c, 0x0e4d, 0x0e4e, 0x0e4f,
559 0x0e50, 0x0e51, 0x0e52, 0x0e53, 0x0e54, 0x0e55, 0x0e56, 0x0e57, 0x0e58, 0x0e59, 0x0e5a, 0x0e5b, 0x0000, 0x0000, 0x0000, 0x0000
560 };
561
562 static const unsigned short int iso_8859_13[] = {/* Latin alphabet No. 7 */
563 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
564 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
565 0x00a0, 0x201d, 0x00a2, 0x00a3, 0x00a4, 0x201e, 0x00a6, 0x00a7, 0x00d8, 0x00a9, 0x0156, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00c6,
566 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x201c, 0x00b5, 0x00b6, 0x00b7, 0x00f8, 0x00b9, 0x0157, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00e6,
567 0x0104, 0x012e, 0x0100, 0x0106, 0x00c4, 0x00c5, 0x0118, 0x0112, 0x010c, 0x00c9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012a, 0x013b,
568 0x0160, 0x0143, 0x0145, 0x00d3, 0x014c, 0x00d5, 0x00d6, 0x00d7, 0x0172, 0x0141, 0x015a, 0x016a, 0x00dc, 0x017b, 0x017d, 0x00df,
569 0x0105, 0x012f, 0x0101, 0x0107, 0x00e4, 0x00e5, 0x0119, 0x0113, 0x010d, 0x00e9, 0x017a, 0x0117, 0x0123, 0x0137, 0x012b, 0x013c,
570 0x0161, 0x0144, 0x0146, 0x00f3, 0x014d, 0x00f5, 0x00f6, 0x00f7, 0x0173, 0x0142, 0x015b, 0x016b, 0x00fc, 0x017c, 0x017e, 0x2019
571 };
572
573 static const unsigned short int iso_8859_14[] = {/* Latin alphabet No. 8 (Celtic) */
574 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
575 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
576 0x00a0, 0x1e02, 0x1e03, 0x00a3, 0x010a, 0x010b, 0x1e0a, 0x00a7, 0x1e80, 0x00a9, 0x1e82, 0x1e0b, 0x1ef2, 0x00ad, 0x00ae, 0x0178,
577 0x1e1e, 0x1e1f, 0x0120, 0x0121, 0x1e40, 0x1e41, 0x00b6, 0x1e56, 0x1e81, 0x1e57, 0x1e83, 0x1e60, 0x1ef3, 0x1e84, 0x1e85, 0x1e61,
578 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
579 0x0174, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x1e6a, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x0176, 0x00df,
580 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
581 0x0175, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x1e6b, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x0177, 0x00ff
582 };
583
584 static const unsigned short int iso_8859_15[] = {/* Latin alphabet No. 9 */
585 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
586 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
587 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x20ac, 0x00a5, 0x0160, 0x00a7, 0x0161, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
588 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x017d, 0x00b5, 0x00b6, 0x00b7, 0x017e, 0x00b9, 0x00ba, 0x00bb, 0x0152, 0x0153, 0x0178, 0x00bf,
589 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
590 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
591 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
592 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff
593 };
594
595 static const unsigned short int iso_8859_16[] = {/* Latin alphabet No. 10 */
596 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
597 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
598 0x00a0, 0x0104, 0x0105, 0x0141, 0x20ac, 0x201e, 0x0160, 0x00a7, 0x0161, 0x00a9, 0x0218, 0x00ab, 0x0179, 0x00ad, 0x017a, 0x017b,
599 0x00b0, 0x00b1, 0x010c, 0x0142, 0x017d, 0x201d, 0x00b6, 0x00b7, 0x017e, 0x010d, 0x0219, 0x00bb, 0x0152, 0x0153, 0x0178, 0x017c,
600 0x00c0, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0106, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
601 0x0110, 0x0143, 0x00d2, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x015a, 0x0170, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x0118, 0x021a, 0x00df,
602 0x00e0, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x0107, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
603 0x0111, 0x0144, 0x00f2, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x015b, 0x0171, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0119, 0x021b, 0x00ff
604 };
605
606 static const unsigned short int windows_1250[] = {
607 0x20ac, 0x0000, 0x201a, 0x0000, 0x201e, 0x2026, 0x2020, 0x2021, 0x0000, 0x2030, 0x0160, 0x2039, 0x015a, 0x0164, 0x017d, 0x0179,
608 0x0000, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x0000, 0x2122, 0x0161, 0x203a, 0x015b, 0x0165, 0x017e, 0x017a,
609 0x00a0, 0x02c7, 0x02d8, 0x0141, 0x00a4, 0x0104, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x015e, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x017b, /* A2 0x02db -> 0x02d8 */
610 0x00b0, 0x00b1, 0x02db, 0x0142, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x0105, 0x015f, 0x00bb, 0x013d, 0x02dd, 0x013e, 0x017c,
611 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e,
612 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df,
613 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f,
614 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9
615 };
616
617 static const unsigned short int windows_1251[] = {
618 0x0402, 0x0403, 0x201a, 0x0453, 0x201e, 0x2026, 0x2020, 0x2021, 0x20ac, 0x2030, 0x0409, 0x2039, 0x040a, 0x040c, 0x040b, 0x040f,
619 0x0452, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x0000, 0x2122, 0x0459, 0x203a, 0x045a, 0x045c, 0x045b, 0x045f,
620 0x00a0, 0x040e, 0x045e, 0x0408, 0x00a4, 0x0490, 0x00a6, 0x00a7, 0x0401, 0x00a9, 0x0404, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x0407,
621 0x00b0, 0x00b1, 0x0406, 0x0456, 0x0491, 0x00b5, 0x00b6, 0x00b7, 0x0451, 0x2116, 0x0454, 0x00bb, 0x0458, 0x0405, 0x0455, 0x0457,
622 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f,
623 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f,
624 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, 0x043f,
625 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e, 0x044f
626 };
627
628 static const unsigned short int windows_1252[] = {
629 0x20ac, 0x0000, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021, 0x02c6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017d, 0x0000,
630 0x0000, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x02dc, 0x2122, 0x0161, 0x203a, 0x0153, 0x0000, 0x017e, 0x0178,
631 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
632 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf,
633 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
634 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
635 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
636 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff
637 };
638
639 static const unsigned short int windows_1256[] = {
640 0x20ac, 0x067e, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021, 0x02c6, 0x2030, 0x0679, 0x2039, 0x0152, 0x0686, 0x0698, 0x0688,
641 0x06af, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x06a9, 0x2122, 0x0691, 0x203a, 0x0153, 0x200c, 0x200d, 0x06ba,
642 0x00a0, 0x060c, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x06be, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
643 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x061b, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x061f,
644 0x06c1, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627, 0x0628, 0x0629, 0x062a, 0x062b, 0x062c, 0x062d, 0x062e, 0x062f,
645 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x00d7, 0x0637, 0x0638, 0x0639, 0x063a, 0x0640, 0x0641, 0x0642, 0x0643,
646 0x00e0, 0x0644, 0x00e2, 0x0645, 0x0646, 0x0647, 0x0648, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x0649, 0x064a, 0x00ee, 0x00ef,
647 0x064b, 0x064c, 0x064d, 0x064e, 0x00f4, 0x064f, 0x0650, 0x00f7, 0x0651, 0x00f9, 0x0652, 0x00fb, 0x00fc, 0x200e, 0x200f, 0x06d2
648 };
649
650 static void test_utf8_to_eci_sb(const testCtx *const p_ctx) {
651
652 struct item {
653 int eci;
654 const unsigned short *tab;
655 };
656 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
657 struct item data[] = {
658 /* 0*/ { 3, iso_8859_1 },
659 /* 1*/ { 4, iso_8859_2 },
660 /* 2*/ { 5, iso_8859_3 },
661 /* 3*/ { 6, iso_8859_4 },
662 /* 4*/ { 7, iso_8859_5 },
663 /* 5*/ { 8, iso_8859_6 },
664 /* 6*/ { 9, iso_8859_7 },
665 /* 7*/ { 10, iso_8859_8 },
666 /* 8*/ { 11, iso_8859_9 },
667 /* 9*/ { 12, iso_8859_10 },
668 /* 10*/ { 13, iso_8859_11 },
669 /* 11*/ { 15, iso_8859_13 },
670 /* 12*/ { 16, iso_8859_14 },
671 /* 13*/ { 17, iso_8859_15 },
672 /* 14*/ { 18, iso_8859_16 },
673 /* 15*/ { 21, windows_1250 },
674 /* 16*/ { 22, windows_1251 },
675 /* 17*/ { 23, windows_1252 },
676 /* 18*/ { 24, windows_1256 },
677 };
678 int data_size = ARRAY_SIZE(data);
679 int i, length, ret;
680
681 unsigned char source[5];
682 unsigned char dest[2] = {0};
683
684 testStart("test_utf8_to_eci_sb");
685
686 for (i = 0; i < data_size; i++) {
687 int j;
688
689 if (testContinue(p_ctx, i)) continue;
690
691 for (j = 0; j < 128; j++) {
692 int k = j + 128;
693 if (data[i].tab[j]) {
694 length = to_utf8(data[i].tab[j], source);
695 assert_nonzero(length, "i:%d to_utf8 length %d == 0\n", i, length);
696 ret = utf8_to_eci(data[i].eci, source, dest, &length);
697 assert_zero(ret, "i:%d utf8_to_eci ret %d != 0\n", i, ret);
698 assert_equal(*dest, k, "i:%d j:%d eci:%d codepoint:0x%x *dest 0x%X (%d) != 0x%X (%d)\n", i, j, data[i].eci, data[i].tab[j], *dest, *dest, k, k);
699 } else {
700 length = to_utf8(k, source);
701 assert_nonzero(length, "i:%d to_utf8 length %d == 0\n", i, length);
702 ret = utf8_to_eci(data[i].eci, source, dest, &length);
703 if (ret == 0) { /* Should be mapping for this codepoint in another entry */
704 int found = 0;
705 int m;
706 for (m = 0; m < 128; m++) {
707 if (data[i].tab[m] == k) {
708 found = 1;
709 break;
710 }
711 }
712 assert_nonzero(found, "i:%d j:%d eci:%d codepoint:0x%x source:%s not found utf8_to_eci ret %d == 0\n", i, j, data[i].eci, k, source, ret);
713 } else {
714 assert_equal(ret, ZINT_ERROR_INVALID_DATA, "i:%d j:%d eci:%d codepoint:0x%x source:%s utf8_to_eci ret %d != ZINT_ERROR_INVALID_DATA\n", i, j, data[i].eci, k, source, ret);
715 }
716 }
717 }
718 }
719
720 testFinish();
721 }
722
723 static void test_utf8_to_eci_ascii(const testCtx *const p_ctx) {
724
725 struct item {
726 int eci;
727 char *data;
728 int length;
729 int ret;
730 };
731 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
732 struct item data[] = {
733 /* 0*/ { 27, "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", 32, 0 },
734 /* 1*/ { 27, " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0 },
735 /* 2*/ { 27, "\302\200", -1, ZINT_ERROR_INVALID_DATA },
736 /* 3*/ { 170, "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", 32, 0 },
737 /* 4*/ { 170, " !\" %&'()*+,-./0123456789:;<=>? ABCDEFGHIJKLMNOPQRSTUVWXYZ _ abcdefghijklmnopqrstuvwxyz \177", 96, 0 },
738 /* 5*/ { 170, "#", -1, ZINT_ERROR_INVALID_DATA },
739 /* 6*/ { 170, "$", -1, ZINT_ERROR_INVALID_DATA },
740 /* 7*/ { 170, "@", -1, ZINT_ERROR_INVALID_DATA },
741 /* 8*/ { 170, "[", -1, ZINT_ERROR_INVALID_DATA },
742 /* 9*/ { 170, "\\", -1, ZINT_ERROR_INVALID_DATA },
743 /* 10*/ { 170, "]", -1, ZINT_ERROR_INVALID_DATA },
744 /* 11*/ { 170, "^", -1, ZINT_ERROR_INVALID_DATA },
745 /* 12*/ { 170, "`", -1, ZINT_ERROR_INVALID_DATA },
746 /* 13*/ { 170, "{", -1, ZINT_ERROR_INVALID_DATA },
747 /* 14*/ { 170, "|", -1, ZINT_ERROR_INVALID_DATA },
748 /* 15*/ { 170, "}", -1, ZINT_ERROR_INVALID_DATA },
749 /* 16*/ { 170, "~", -1, ZINT_ERROR_INVALID_DATA },
750 /* 17*/ { 170, "\302\200", -1, ZINT_ERROR_INVALID_DATA },
751 /* 18*/ { 170, "~", -1, ZINT_ERROR_INVALID_DATA },
752 /* 19*/ { 1, "A", -1, ZINT_ERROR_INVALID_DATA },
753 /* 20*/ { 2, "A", -1, ZINT_ERROR_INVALID_DATA },
754 /* 21*/ { 14, "A", -1, ZINT_ERROR_INVALID_DATA },
755 /* 22*/ { 19, "A", -1, ZINT_ERROR_INVALID_DATA },
756 /* 23*/ { 26, "A", -1, ZINT_ERROR_INVALID_DATA },
757 };
758 int data_size = ARRAY_SIZE(data);
759 int i, length, ret;
760
761 char dest[128];
762
763 testStart("test_utf8_to_eci_ascii");
764
765 for (i = 0; i < data_size; i++) {
766 int out_length;
767
768 if (testContinue(p_ctx, i)) continue;
769
770 length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
771 out_length = length;
772 ret = utf8_to_eci(data[i].eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length);
773 assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret);
774 if (ret == 0) {
775 assert_equal(length, out_length, "i:%d length %d != %d\n", i, length, out_length);
776 assert_zero(memcmp(data[i].data, dest, length), "i:%d memcmp != 0\n", i);
777 }
778 }
779
780 testFinish();
781 }
782
783 static void test_utf8_to_eci_utf16be(const testCtx *const p_ctx) {
784
785 struct item {
786 char *data;
787 int length;
788 int ret;
789 int expected_length;
790 char *expected;
791 };
792 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
793 struct item data[] = {
794 /* 0*/ { "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", 32, 0, 32 * 2, NULL },
795 /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 * 2, NULL },
796 /* 2*/ { "\302\200\357\277\277", -1, 0, 4, "\000\200\377\377" }, /* U+0080 U+FFFF */
797 /* 3*/ { "\357\277\276", -1, 0, 2, "\377\376" }, /* U+FFFE (reversed BOM) allowed */
798 /* 4*/ { "\357\273\277", -1, 0, 2, "\376\377" }, /* U+FEFF (BOM) allowed */
799 /* 5*/ { "\355\237\277", -1, 0, 2, "\327\377" }, /* U+D7FF (ed9fbf) */
800 /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* U+D800 (eda080) surrogate half not allowed */
801 /* 7*/ { "\355\277\277", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* U+DFFF (edbfbf) surrogate half not allowed */
802 /* 8*/ { "\356\200\200", -1, 0, 2, "\340\000" }, /* U+E000 (ee8080) */
803 /* 9*/ { "\360\220\200\200", -1, 0, 4, "\330\000\334\000" }, /* U+10000 maps to surrogate pair */
804 /* 10*/ { "\360\220\217\277", -1, 0, 4, "\330\000\337\377" }, /* U+103FF maps to surrogate pair */
805 /* 11*/ { "\364\200\200\200", -1, 0, 4, "\333\300\334\000" }, /* U+100000 maps to surrogate pair */
806 /* 12*/ { "\364\217\260\200", -1, 0, 4, "\333\377\334\000" }, /* U+10FC00 maps to surrogate pair */
807 /* 13*/ { "\364\217\277\277", -1, 0, 4, "\333\377\337\377" }, /* U+10FFFF maps to surrogate pair */
808 /* 14*/ { "\364\220\200\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* Non-Unicode 0x110000 not allowed */
809 };
810 int data_size = ARRAY_SIZE(data);
811 int i, length, ret;
812 const int eci = 25;
813
814 testStart("test_utf8_to_eci_utf16be");
815
816 for (i = 0; i < data_size; i++) {
817 int out_length, eci_length;
818 char dest[1024];
819
820 if (testContinue(p_ctx, i)) continue;
821
822 length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
823 out_length = length;
824 eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
825
826 assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length);
827 ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length);
828 assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret);
829 if (ret == 0) {
830 assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length);
831 assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length);
832 if (data[i].expected) {
833 ret = memcmp(dest, data[i].expected, data[i].expected_length);
834 assert_zero(ret, "i:%d memcmp() %d != 0\n", i, ret);
835 } else {
836 int j;
837 for (j = 0; j < length; j++) {
838 assert_zero(dest[j * 2], "i:%d dest[%d] %d != 0\n", i, j * 2, dest[j * 2]);
839 assert_equal(dest[j * 2 + 1], data[i].data[j], "i:%d dest[%d] %d != data[%d] %d\n", i, j * 2 + 1, dest[j * 2 + 1], j, data[i].data[j]);
840 }
841 }
842 }
843 }
844
845 testFinish();
846 }
847
848 static void test_utf8_to_eci_utf16le(const testCtx *const p_ctx) {
849
850 struct item {
851 char *data;
852 int length;
853 int ret;
854 int expected_length;
855 char *expected;
856 };
857 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
858 struct item data[] = {
859 /* 0*/ { "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", 32, 0, 32 * 2, NULL },
860 /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 * 2, NULL },
861 /* 2*/ { "\302\200\357\277\277", -1, 0, 4, "\200\000\377\377" }, /* U+0080 U+FFFF */
862 /* 3*/ { "\357\277\276", -1, 0, 2, "\376\377" }, /* U+FFFE (reversed BOM) allowed */
863 /* 4*/ { "\357\273\277", -1, 0, 2, "\377\376" }, /* U+FEFF (BOM) allowed */
864 /* 5*/ { "\355\237\277", -1, 0, 2, "\377\327" }, /* U+D7FF (ed9fbf) */
865 /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* U+D800 (eda080) surrogate half not allowed */
866 /* 7*/ { "\355\277\277", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* U+DFFF (edbfbf) surrogate half not allowed */
867 /* 8*/ { "\356\200\200", -1, 0, 2, "\000\340" }, /* U+E000 (ee8080) */
868 /* 9*/ { "\360\220\200\200", -1, 0, 4, "\000\330\000\334" }, /* U+10000 maps to surrogate pair */
869 /* 10*/ { "\360\220\217\277", -1, 0, 4, "\000\330\377\337" }, /* U+103FF maps to surrogate pair */
870 /* 11*/ { "\364\200\200\200", -1, 0, 4, "\300\333\000\334" }, /* U+100000 maps to surrogate pair */
871 /* 12*/ { "\364\217\260\200", -1, 0, 4, "\377\333\000\334" }, /* U+10FC00 maps to surrogate pair */
872 /* 13*/ { "\364\217\277\277", -1, 0, 4, "\377\333\377\337" }, /* U+10FFFF maps to surrogate pair */
873 /* 14*/ { "\364\220\200\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* Non-Unicode 0x110000 not allowed */
874 };
875 int data_size = ARRAY_SIZE(data);
876 int i, length, ret;
877 const int eci = 33;
878
879 testStart("test_utf8_to_eci_utf16le");
880
881 for (i = 0; i < data_size; i++) {
882 int out_length, eci_length;
883 char dest[1024];
884
885 if (testContinue(p_ctx, i)) continue;
886
887 length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
888 out_length = length;
889 eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
890
891 assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length);
892 ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length);
893 assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret);
894 if (ret == 0) {
895 assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length);
896 assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length);
897 if (data[i].expected) {
898 ret = memcmp(dest, data[i].expected, data[i].expected_length);
899 assert_zero(ret, "i:%d memcmp() %d != 0\n", i, ret);
900 } else {
901 int j;
902 for (j = 0; j < length; j++) {
903 assert_equal(dest[j * 2], data[i].data[j], "i:%d dest[%d] %d != data[%d] %d\n", i, j * 2, dest[j * 2], j, data[i].data[j]);
904 assert_zero(dest[j * 2 + 1], "i:%d dest[%d] %d != 0\n", i, j * 2 + 1, dest[j * 2 + 1]);
905 }
906 }
907 }
908 }
909
910 testFinish();
911 }
912
913 static void test_utf8_to_eci_utf32be(const testCtx *const p_ctx) {
914
915 struct item {
916 char *data;
917 int length;
918 int ret;
919 int expected_length;
920 char *expected;
921 };
922 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
923 struct item data[] = {
924 /* 0*/ { "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", 32, 0, 32 * 4, NULL },
925 /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 * 4, NULL },
926 /* 2*/ { "\302\200\357\277\277", -1, 0, 8, "\000\000\000\200\000\000\377\377" }, /* U+0080 U+FFFF */
927 /* 3*/ { "\357\277\276", -1, 0, 4, "\000\000\377\376" }, /* U+FFFE (reversed BOM) allowed */
928 /* 4*/ { "\357\273\277", -1, 0, 4, "\000\000\376\377" }, /* U+FEFF (BOM) allowed */
929 /* 5*/ { "\355\237\277", -1, 0, 4, "\000\000\327\377" }, /* U+D7FF (ed9fbf) */
930 /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* U+D800 (eda080) surrogate half not allowed */
931 /* 7*/ { "\355\277\277", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* U+DFFF (edbfbf) surrogate half not allowed */
932 /* 8*/ { "\356\200\200", -1, 0, 4, "\000\000\340\000" }, /* U+E000 (ee8080) */
933 /* 9*/ { "\360\220\200\200", -1, 0, 4, "\000\001\000\000" }, /* U+10000 */
934 /* 10*/ { "\364\217\277\277", -1, 0, 4, "\000\020\377\377" }, /* U+10FFFF */
935 /* 11*/ { "\364\220\200\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* Non-Unicode 0x110000 not allowed */
936 };
937 int data_size = ARRAY_SIZE(data);
938 int i, length, ret;
939 const int eci = 34;
940
941 testStart("test_utf8_to_eci_utf32be");
942
943 for (i = 0; i < data_size; i++) {
944 int out_length, eci_length;
945 char dest[1024];
946
947 if (testContinue(p_ctx, i)) continue;
948
949 length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
950 out_length = length;
951 eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
952
953 assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length);
954 ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length);
955 assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret);
956 if (ret == 0) {
957 assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length);
958 assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length);
959 if (data[i].expected) {
960 ret = memcmp(dest, data[i].expected, data[i].expected_length);
961 assert_zero(ret, "i:%d memcmp() %d != 0\n", i, ret);
962 } else {
963 int j;
964 for (j = 0; j < length; j++) {
965 assert_zero(dest[j * 4], "i:%d dest[%d] %d != 0\n", i, j * 4, dest[j * 4]);
966 assert_zero(dest[j * 4 + 1], "i:%d dest[%d] %d != 0\n", i, j * 4 + 1, dest[j * 4 + 1]);
967 assert_zero(dest[j * 4 + 2], "i:%d dest[%d] %d != 0\n", i, j * 4 + 2, dest[j * 4 + 2]);
968 assert_equal(dest[j * 4 + 3], data[i].data[j], "i:%d dest[%d] %d != data[%d] %d\n", i, j * 4 + 3, dest[j * 4 + 3], j, data[i].data[j]);
969 }
970 }
971 }
972 }
973
974 testFinish();
975 }
976
977 static void test_utf8_to_eci_utf32le(const testCtx *const p_ctx) {
978
979 struct item {
980 char *data;
981 int length;
982 int ret;
983 int expected_length;
984 char *expected;
985 };
986 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
987 struct item data[] = {
988 /* 0*/ { "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", 32, 0, 32 * 4, NULL },
989 /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 * 4, NULL },
990 /* 2*/ { "\302\200\357\277\277", -1, 0, 8, "\200\000\000\000\377\377\000\000" }, /* U+0080 U+FFFF */
991 /* 3*/ { "\357\277\276", -1, 0, 4, "\376\377\000\000" }, /* U+FFFE (reversed BOM) allowed */
992 /* 4*/ { "\357\273\277", -1, 0, 4, "\377\376\000\000" }, /* U+FEFF (BOM) allowed */
993 /* 5*/ { "\355\237\277", -1, 0, 4, "\377\327\000\000" }, /* U+D7FF (ed9fbf) */
994 /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* U+D800 (eda080) surrogate half not allowed */
995 /* 7*/ { "\355\277\277", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* U+DFFF (edbfbf) surrogate half not allowed */
996 /* 8*/ { "\356\200\200", -1, 0, 4, "\000\340\000\000" }, /* U+E000 (ee8080) */
997 /* 9*/ { "\360\220\200\200", -1, 0, 4, "\000\000\001\000" }, /* U+10000 */
998 /* 10*/ { "\364\217\277\277", -1, 0, 4, "\377\377\020\000" }, /* U+10FFFF */
999 /* 11*/ { "\364\220\200\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* Non-Unicode 0x110000 not allowed */
1000 };
1001 int data_size = ARRAY_SIZE(data);
1002 int i, length, ret;
1003 const int eci = 35;
1004
1005 testStart("test_utf8_to_eci_utf32le");
1006
1007 for (i = 0; i < data_size; i++) {
1008 int out_length, eci_length;
1009 char dest[1024];
1010
1011 if (testContinue(p_ctx, i)) continue;
1012
1013 length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
1014 out_length = length;
1015 eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
1016
1017 assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length);
1018 ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length);
1019 assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret);
1020 if (ret == 0) {
1021 assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length);
1022 assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length);
1023 if (data[i].expected) {
1024 ret = memcmp(dest, data[i].expected, data[i].expected_length);
1025 assert_zero(ret, "i:%d memcmp() %d != 0\n", i, ret);
1026 } else {
1027 int j;
1028 for (j = 0; j < length; j++) {
1029 assert_equal(dest[j * 4], data[i].data[j], "i:%d dest[%d] %d != data[%d] %d\n", i, j * 4, dest[j * 4], j, data[i].data[j]);
1030 assert_zero(dest[j * 4 + 1], "i:%d dest[%d] %d != 0\n", i, j * 4 + 1, dest[j * 4 + 1]);
1031 assert_zero(dest[j * 4 + 2], "i:%d dest[%d] %d != 0\n", i, j * 4 + 2, dest[j * 4 + 2]);
1032 assert_zero(dest[j * 4 + 3], "i:%d dest[%d] %d != 0\n", i, j * 4 + 3, dest[j * 4 + 3]);
1033 }
1034 }
1035 }
1036 }
1037
1038 testFinish();
1039 }
1040
1041 static void test_utf8_to_eci_sjis(const testCtx *const p_ctx) {
1042
1043 struct item {
1044 char *data;
1045 int length;
1046 int ret;
1047 int expected_length;
1048 };
1049 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
1050 struct item data[] = {
1051 /* 0*/ { "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", 32, 0, 32 },
1052 /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\177", 95, 0, 95 + 1 }, /* Backslash goes to 2 byte */
1053 /* 2*/ { "~", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for tilde */
1054 /* 3*/ { "\302\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+0080 */
1055 /* 4*/ { "\302\241", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+00A1 Inverted exclaimation mark */
1056 /* 5*/ { "\302\245", -1, 0, 1 }, /* U+00A5 Yen goes to backslash */
1057 /* 6*/ { "\302\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+00BF Inverted question mark */
1058 /* 7*/ { "\303\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+00C0 À */
1059 /* 8*/ { "\303\251", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+00E9 é */
1060 /* 9*/ { "\312\262", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+03B2 β */
1061 /* 10*/ { "\342\272\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+2E80 CJK RADICAL REPEAT */
1062 /* 11*/ { "\343\200\200", -1, 0, 2 }, /* U+3000 IDEOGRAPHIC SPACE */
1063 /* 12*/ { "\343\200\204", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+3004 JAPANESE INDUSTRIAL STANDARD SYMBOL */
1064 /* 13*/ { "\343\201\201", -1, 0, 2 }, /*U+3041 HIRAGANA LETTER SMALL A */
1065 /* 14*/ { "\357\277\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+FFFF */
1066 /* 15*/ { "\357\277\276", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+FFFE (reversed BOM) not allowed */
1067 /* 16*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+D800 surrogate not allowed */
1068 };
1069 int data_size = ARRAY_SIZE(data);
1070 int i, length, ret;
1071 const int eci = 20;
1072
1073 testStart("test_utf8_to_eci_sjis");
1074
1075 for (i = 0; i < data_size; i++) {
1076 int out_length, eci_length;
1077 char dest[1024];
1078
1079 if (testContinue(p_ctx, i)) continue;
1080
1081 length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
1082 out_length = length;
1083 eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
1084
1085 assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length);
1086 ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length);
1087 assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret);
1088 if (ret == 0) {
1089 assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length);
1090 assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length);
1091 }
1092 }
1093
1094 testFinish();
1095 }
1096
1097 static void test_utf8_to_eci_big5(const testCtx *const p_ctx) {
1098
1099 struct item {
1100 char *data;
1101 int length;
1102 int ret;
1103 int expected_length;
1104 };
1105 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
1106 struct item data[] = {
1107 /* 0*/ { "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", 32, 0, 32 },
1108 /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 },
1109 /* 2*/ { "\302\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+0080 */
1110 /* 3*/ { "\343\200\200", -1, 0, 2 }, /* U+3000 IDEOGRAPHIC SPACE */
1111 /* 4*/ { "\357\277\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+FFFF */
1112 /* 5*/ { "\357\277\276", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+FFFE (reversed BOM) not allowed */
1113 /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+D800 surrogate not allowed */
1114 };
1115 int data_size = ARRAY_SIZE(data);
1116 int i, length, ret;
1117 const int eci = 28;
1118
1119 testStart("test_utf8_to_eci_big5");
1120
1121 for (i = 0; i < data_size; i++) {
1122 int out_length, eci_length;
1123 char dest[1024];
1124
1125 if (testContinue(p_ctx, i)) continue;
1126
1127 length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
1128 out_length = length;
1129 eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
1130
1131 assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length);
1132 ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length);
1133 assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret);
1134 if (ret == 0) {
1135 assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length);
1136 assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length);
1137 }
1138 }
1139
1140 testFinish();
1141 }
1142
1143 static void test_utf8_to_eci_gb2312(const testCtx *const p_ctx) {
1144
1145 struct item {
1146 char *data;
1147 int length;
1148 int ret;
1149 int expected_length;
1150 };
1151 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
1152 struct item data[] = {
1153 /* 0*/ { "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", 32, 0, 32 },
1154 /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 },
1155 /* 2*/ { "\302\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+0080 */
1156 /* 3*/ { "\343\200\200", -1, 0, 2 }, /* U+3000 IDEOGRAPHIC SPACE */
1157 /* 4*/ { "\357\277\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+FFFF */
1158 /* 5*/ { "\357\277\276", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+FFFE (reversed BOM) not allowed */
1159 /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+D800 surrogate not allowed */
1160 };
1161 int data_size = ARRAY_SIZE(data);
1162 int i, length, ret;
1163 const int eci = 29;
1164
1165 testStart("test_utf8_to_eci_gb2312");
1166
1167 for (i = 0; i < data_size; i++) {
1168 int out_length, eci_length;
1169 char dest[1024];
1170
1171 if (testContinue(p_ctx, i)) continue;
1172
1173 length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
1174 out_length = length;
1175 eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
1176
1177 assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length);
1178 ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length);
1179 assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret);
1180 if (ret == 0) {
1181 assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length);
1182 assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length);
1183 }
1184 }
1185
1186 testFinish();
1187 }
1188
1189 static void test_utf8_to_eci_euc_kr(const testCtx *const p_ctx) {
1190
1191 struct item {
1192 char *data;
1193 int length;
1194 int ret;
1195 int expected_length;
1196 };
1197 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
1198 struct item data[] = {
1199 /* 0*/ { "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", 32, 0, 32 },
1200 /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 },
1201 /* 2*/ { "\302\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+0080 */
1202 /* 3*/ { "\343\200\200", -1, 0, 2 }, /* U+3000 IDEOGRAPHIC SPACE */
1203 /* 4*/ { "\357\277\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+FFFF */
1204 /* 5*/ { "\357\277\276", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+FFFE (reversed BOM) not allowed */
1205 /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+D800 surrogate not allowed */
1206 };
1207 int data_size = ARRAY_SIZE(data);
1208 int i, length, ret;
1209 const int eci = 30;
1210
1211 testStart("test_utf8_to_eci_euc_kr");
1212
1213 for (i = 0; i < data_size; i++) {
1214 int out_length, eci_length;
1215 char dest[1024];
1216
1217 if (testContinue(p_ctx, i)) continue;
1218
1219 length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
1220 out_length = length;
1221 eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
1222
1223 assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length);
1224 ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length);
1225 assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret);
1226 if (ret == 0) {
1227 assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length);
1228 assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length);
1229 }
1230 }
1231
1232 testFinish();
1233 }
1234
1235 static void test_utf8_to_eci_gbk(const testCtx *const p_ctx) {
1236
1237 struct item {
1238 char *data;
1239 int length;
1240 int ret;
1241 int expected_length;
1242 };
1243 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
1244 struct item data[] = {
1245 /* 0*/ { "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", 32, 0, 32 },
1246 /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 },
1247 /* 2*/ { "\302\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+0080 */
1248 /* 3*/ { "\343\200\200", -1, 0, 2 }, /* U+3000 IDEOGRAPHIC SPACE */
1249 /* 4*/ { "\357\277\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+FFFF */
1250 /* 5*/ { "\357\277\276", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+FFFE (reversed BOM) not allowed */
1251 /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+D800 surrogate not allowed */
1252 };
1253 int data_size = ARRAY_SIZE(data);
1254 int i, length, ret;
1255 const int eci = 31;
1256
1257 testStart("test_utf8_to_eci_gbk");
1258
1259 for (i = 0; i < data_size; i++) {
1260 int out_length, eci_length;
1261 char dest[1024];
1262
1263 if (testContinue(p_ctx, i)) continue;
1264
1265 length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
1266 out_length = length;
1267 eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
1268
1269 assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length);
1270 ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length);
1271 assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret);
1272 if (ret == 0) {
1273 assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length);
1274 assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length);
1275 }
1276 }
1277
1278 testFinish();
1279 }
1280
1281 static void test_utf8_to_eci_gb18030(const testCtx *const p_ctx) {
1282
1283 struct item {
1284 char *data;
1285 int length;
1286 int ret;
1287 int expected_length;
1288 };
1289 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
1290 struct item data[] = {
1291 /* 0*/ { "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", 32, 0, 32 },
1292 /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 },
1293 /* 2*/ { "\302\200", -1, 0, 4 }, /* Has mapping for U+0080 */
1294 /* 3*/ { "\343\200\200", -1, 0, 2 }, /* U+3000 IDEOGRAPHIC SPACE */
1295 /* 4*/ { "\357\277\277", -1, 0, 4 }, /* Has mapping for U+FFFF */
1296 /* 5*/ { "\357\277\276", -1, 0, 4 }, /* U+FFFE (reversed BOM) allowed */
1297 /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+D800 surrogate not allowed */
1298 };
1299 int data_size = ARRAY_SIZE(data);
1300 int i, length, ret;
1301 const int eci = 32;
1302
1303 testStart("test_utf8_to_eci_gb18030");
1304
1305 for (i = 0; i < data_size; i++) {
1306 int out_length, eci_length;
1307 char dest[1024];
1308
1309 if (testContinue(p_ctx, i)) continue;
1310
1311 length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
1312 out_length = length;
1313 eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
1314
1315 assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length);
1316 ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length);
1317 assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret);
1318 if (ret == 0) {
1319 assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length);
1320 assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length);
1321 }
1322 }
1323
1324 testFinish();
1325 }
1326
1327 static void test_is_eci_convertible_segs(const testCtx *const p_ctx) {
1328
1329 struct item {
1330 struct zint_seg segs[3];
1331 int ret;
1332 int expected_convertible[3];
1333 };
1334 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
1335 struct item data[] = {
1336 /* 0*/ { { { TU("A"), -1, 0 }, { TU(""), 0, 0 }, { TU(""), 0, 0 } }, 1, { 1, -1, -1 } },
1337 /* 1*/ { { { TU("A"), -1, 26 }, { TU(""), 0, 0 }, { TU(""), 0, 0 } }, 0, { 0, -1, -1 } },
1338 /* 2*/ { { { TU("A"), -1, 36 }, { TU(""), 0, 0 }, { TU(""), 0, 0 } }, 0, { 0, -1, -1 } },
1339 /* 3*/ { { { TU("A"), -1, 170 }, { TU(""), 0, 0 }, { TU(""), 0, 0 } }, 1, { 1, -1, -1 } },
1340 /* 4*/ { { { TU("A"), -1, 899 }, { TU(""), 0, 0 }, { TU(""), 0, 0 } }, 0, { 0, -1, -1 } },
1341 /* 5*/ { { { TU("A"), -1, 3 }, { TU(""), 0, 0 }, { TU(""), 0, 0 } }, 1, { 1, -1, -1 } },
1342 /* 6*/ { { { TU("A"), -1, 899 }, { TU("A"), -1, 0 }, { TU(""), 0, 0 } }, 1, { 0, 1, -1 } },
1343 /* 7*/ { { { TU("A"), -1, 0 }, { TU("A"), -1, 899 }, { TU(""), 0, 0 } }, 1, { 1, 0, -1 } },
1344 /* 8*/ { { { TU("A"), -1, 3 }, { TU("A"), -1, 4 }, { TU("A"), -1, 35 } }, 1, { 1, 1, 1 } },
1345 /* 9*/ { { { TU("A"), -1, 3 }, { TU("A"), -1, 899 }, { TU("A"), -1, 0 } }, 1, { 1, 0, 1 } },
1346 /* 10*/ { { { TU("A"), -1, 899 }, { TU("A"), -1, 899 }, { TU("A"), -1, 0 } }, 1, { 0, 0, 1 } },
1347 /* 11*/ { { { TU("A"), -1, 899 }, { TU("A"), -1, 0 }, { TU("A"), -1, 899 } }, 1, { 0, 1, 0 } },
1348 /* 12*/ { { { TU("A"), -1, 899 }, { TU("A"), -1, 899 }, { TU("A"), -1, 899 } }, 0, { 0, 0, 0 } },
1349 };
1350 int data_size = ARRAY_SIZE(data);
1351 int i, j, seg_count, ret;
1352
1353 int convertible[3];
1354
1355 testStart("test_is_eci_convertible_segs");
1356
1357 for (i = 0; i < data_size; i++) {
1358
1359 if (testContinue(p_ctx, i)) continue;
1360
1361 for (j = 0, seg_count = 0; j < 3 && data[i].segs[j].length; j++, seg_count++);
1362
1363 for (j = 0; j < 3; j++) convertible[j] = -1;
1364
1365 ret = is_eci_convertible_segs(data[i].segs, seg_count, convertible);
1366 assert_equal(ret, data[i].ret, "i:%d is_eci_convertible_segs ret %d != %d\n", i, ret, data[i].ret);
1367 for (j = 0; j < 3; j++) {
1368 assert_equal(convertible[j], data[i].expected_convertible[j], "i:%d is_eci_convertible_segs convertible[%d] %d != %d\n", i, j, convertible[j], data[i].expected_convertible[j]);
1369 }
1370 }
1371
1372 testFinish();
1373 }
1374
1375 static void test_get_best_eci(const testCtx *const p_ctx) {
1376
1377 struct item {
1378 const char *data;
1379 int length;
1380 int ret;
1381 };
1382 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
1383 struct item data[] = {
1384 /* 0*/ { "ÀÁ", -1, 3 },
1385 /* 1*/ { "Ђ", -1, 7 },
1386 /* 2*/ { "Ѐ", -1, 26 }, /* Cyrillic U+0400 not in single-byte code pages */
1387 /* 3*/ { "β", -1, 9 },
1388 /* 4*/ { "˜", -1, 23 },
1389 /* 5*/ { "βЂ", -1, 26 },
1390 };
1391 int data_size = ARRAY_SIZE(data);
1392 int i, length, ret;
1393
1394 testStart("test_get_best_eci");
1395
1396 for (i = 0; i < data_size; i++) {
1397
1398 if (testContinue(p_ctx, i)) continue;
1399
1400 length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
1401
1402 ret = get_best_eci((const unsigned char *) data[i].data, length);
1403 assert_equal(ret, data[i].ret, "i:%d get_best_eci ret %d != %d\n", i, ret, data[i].ret);
1404 }
1405
1406 testFinish();
1407 }
1408
1409 static void test_get_best_eci_segs(const testCtx *const p_ctx) {
1410
1411 struct item {
1412 struct zint_seg segs[3];
1413 int ret;
1414 int expected_symbol_eci;
1415 };
1416 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
1417 struct item data[] = {
1418 /* 0*/ { { { TU("A"), -1, 0 }, { TU(""), -1, 0 }, { TU(""), 0, 0 } }, 0, 0 },
1419 /* 1*/ { { { TU("A"), -1, 0 }, { TU("ÀÁ"), -1, 0 }, { TU(""), 0, 0 } }, 0, 0 }, /* As 1st seg default ECI, 3 not returned */
1420 /* 2*/ { { { TU("A"), -1, 4 }, { TU("ÀÁ"), -1, 0 }, { TU(""), 0, 0 } }, 3, 0 },
1421 /* 3*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 0 }, { TU(""), 0, 0 } }, 7, 0 },
1422 /* 4*/ { { { TU("A"), -1, 4 }, { TU("Ђ"), -1, 0 }, { TU(""), 0, 0 } }, 7, 0 },
1423 /* 5*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 7 }, { TU("Ѐ"), -1, 0 } }, 26, 0 }, /* Cyrillic U+0400 not in single-byte code pages */
1424 /* 6*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 0 }, { TU("β"), -1, 0 } }, 7, 0 },
1425 /* 7*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 7 }, { TU("β"), -1, 0 } }, 9, 0 },
1426 /* 8*/ { { { TU("˜"), -1, 0 }, { TU("Ђ"), -1, 7 }, { TU(""), 0, 0 } }, 23, 23 },
1427 };
1428 int data_size = ARRAY_SIZE(data);
1429 int i, j, seg_count, ret;
1430 struct zint_symbol *symbol;
1431
1432 testStart("test_get_best_eci_segs");
1433
1434 for (i = 0; i < data_size; i++) {
1435
1436 if (testContinue(p_ctx, i)) continue;
1437
1438 symbol = ZBarcode_Create();
1439 assert_nonnull(symbol, "Symbol not created\n");
1440
1441 for (j = 0, seg_count = 0; j < 3 && data[i].segs[j].length; j++, seg_count++);
1442 for (j = 0; j < seg_count; j++) {
1443 if (data[i].segs[j].length < 0) data[i].segs[j].length = (int) ustrlen(data[i].segs[j].source);
1444 }
1445
1446 ret = get_best_eci_segs(symbol, data[i].segs, seg_count);
1447 assert_equal(ret, data[i].ret, "i:%d get_best_eci_segs ret %d != %d\n", i, ret, data[i].ret);
1448 assert_equal(symbol->eci, data[i].expected_symbol_eci, "i:%d get_best_eci_segs symbol->eci %d != %d\n", i, symbol->eci, data[i].expected_symbol_eci);
1449
1450 ZBarcode_Delete(symbol);
1451 }
1452
1453 testFinish();
1454 }
1455
1456 int main(int argc, char *argv[]) {
1457
1458 testFunction funcs[] = { /* name, func */
1459 { "test_bom", test_bom },
1460 { "test_iso_8859_16", test_iso_8859_16 },
1461 { "test_reduced_charset_input", test_reduced_charset_input },
1462 { "test_utf8_to_eci_sb", test_utf8_to_eci_sb },
1463 { "test_utf8_to_eci_ascii", test_utf8_to_eci_ascii },
1464 { "test_utf8_to_eci_utf16be", test_utf8_to_eci_utf16be },
1465 { "test_utf8_to_eci_utf16le", test_utf8_to_eci_utf16le },
1466 { "test_utf8_to_eci_utf32be", test_utf8_to_eci_utf32be },
1467 { "test_utf8_to_eci_utf32le", test_utf8_to_eci_utf32le },
1468 { "test_utf8_to_eci_sjis", test_utf8_to_eci_sjis },
1469 { "test_utf8_to_eci_big5", test_utf8_to_eci_big5 },
1470 { "test_utf8_to_eci_gb2312", test_utf8_to_eci_gb2312 },
1471 { "test_utf8_to_eci_euc_kr", test_utf8_to_eci_euc_kr },
1472 { "test_utf8_to_eci_gbk", test_utf8_to_eci_gbk },
1473 { "test_utf8_to_eci_gb18030", test_utf8_to_eci_gb18030 },
1474 { "test_is_eci_convertible_segs", test_is_eci_convertible_segs },
1475 { "test_get_best_eci", test_get_best_eci },
1476 { "test_get_best_eci_segs", test_get_best_eci_segs },
1477 };
1478
1479 testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
1480
1481 testReport();
1482
1483 return 0;
1484 }
1485
1486 /* vim: set ts=4 sw=4 et norl : */