Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/backend/tests/test_sjis.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-2023 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 "test_sjis_tab.h" | |
| 34 #include "../eci.h" | |
| 35 /* For local "private" testing using previous libiconv adaptation, not included for licensing reasons */ | |
| 36 #if 0 | |
| 37 #define TEST_JUST_SAY_GNO | |
| 38 #endif | |
| 39 #ifdef TEST_JUST_SAY_GNO | |
| 40 #include "../just_say_gno/sjis_gnu.c" | |
| 41 #endif | |
| 42 | |
| 43 INTERNAL int u_sjis_int_test(const unsigned int u, unsigned int *dest); | |
| 44 | |
| 45 /* As control convert to Shift JIS using simple table generated from | |
| 46 https://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/JIS/SHIFTJIS.TXT plus simple processing | |
| 47 */ | |
| 48 static int u_sjis_int2(unsigned int u, unsigned int *dest) { | |
| 49 int tab_length, start_i, end_i; | |
| 50 int i; | |
| 51 if (u < 0x20 || u == 0x7F) { | |
| 52 *dest = u; | |
| 53 return 1; | |
| 54 } | |
| 55 /* Shortcut */ | |
| 56 if ((u > 0x00F7 && u < 0x0391) || (u > 0x0451 && u < 0x2010) || (u > 0x9FA0 && u < 0xE000) || (u > 0xE757 && u < 0xFF01) || u > 0xFFE5) { | |
| 57 return 0; | |
| 58 } | |
| 59 if (u >= 0xE000 && u <= 0xE757) { /* PUA mappings, not in SHIFTJIS.TXT */ | |
| 60 if (u <= 0xE0BB) { | |
| 61 *dest = u - 0xE000 + 0xF040 + (u >= 0xE000 + 0x3F); | |
| 62 } else if (u <= 0xE177) { | |
| 63 *dest = u - 0xE0BC + 0xF140 + (u >= 0xE0BC + 0x3F); | |
| 64 } else if (u <= 0xE233) { | |
| 65 *dest = u - 0xE178 + 0xF240 + (u >= 0xE178 + 0x3F); | |
| 66 } else if (u <= 0xE2EF) { | |
| 67 *dest = u - 0xE234 + 0xF340 + (u >= 0xE234 + 0x3F); | |
| 68 } else if (u <= 0xE3AB) { | |
| 69 *dest = u - 0xE2F0 + 0xF440 + (u >= 0xE2F0 + 0x3F); | |
| 70 } else if (u <= 0xE467) { | |
| 71 *dest = u - 0xE3AC + 0xF540 + (u >= 0xE3AC + 0x3F); | |
| 72 } else if (u <= 0xE523) { | |
| 73 *dest = u - 0xE468 + 0xF640 + (u >= 0xE468 + 0x3F); | |
| 74 } else if (u <= 0xE5DF) { | |
| 75 *dest = u - 0xE524 + 0xF740 + (u >= 0xE524 + 0x3F); | |
| 76 } else if (u <= 0xE69B) { | |
| 77 *dest = u - 0xE5E0 + 0xF840 + (u >= 0xE5E0 + 0x3F); | |
| 78 } else { | |
| 79 *dest = u - 0xE69C + 0xF940 + (u >= 0xE69C + 0x3F); | |
| 80 } | |
| 81 return 2; | |
| 82 } | |
| 83 tab_length = sizeof(test_sjis_tab) / sizeof(unsigned int); | |
| 84 start_i = test_sjis_tab_ind[u >> 10]; | |
| 85 end_i = start_i + 0x800 > tab_length ? tab_length : start_i + 0x800; | |
| 86 for (i = start_i; i < end_i; i += 2) { | |
| 87 if (test_sjis_tab[i + 1] == u) { | |
| 88 *dest = test_sjis_tab[i]; | |
| 89 return *dest > 0xFF ? 2 : 1; | |
| 90 } | |
| 91 } | |
| 92 return 0; | |
| 93 } | |
| 94 | |
| 95 #include <time.h> | |
| 96 | |
| 97 #define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC) | |
| 98 #define TEST_PERF_RATIO(a1, a2) (a2 ? TEST_PERF_TIME(a1) / TEST_PERF_TIME(a2) : 0) | |
| 99 | |
| 100 #ifdef TEST_JUST_SAY_GNO | |
| 101 #define TEST_INT_PERF_ITERATIONS 100 | |
| 102 #endif | |
| 103 | |
| 104 static void test_u_sjis_int(const testCtx *const p_ctx) { | |
| 105 int debug = p_ctx->debug; | |
| 106 | |
| 107 int ret, ret2; | |
| 108 unsigned int val, val2; | |
| 109 unsigned int i; | |
| 110 | |
| 111 #ifdef TEST_JUST_SAY_GNO | |
| 112 int j; | |
| 113 clock_t start; | |
| 114 clock_t total = 0, total_gno = 0; | |
| 115 #else | |
| 116 (void)debug; | |
| 117 #endif | |
| 118 | |
| 119 testStart("test_u_sjis_int"); | |
| 120 | |
| 121 #ifdef TEST_JUST_SAY_GNO | |
| 122 if ((debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ | |
| 123 printf("test_u_sjis_int perf iterations: %d\n", TEST_INT_PERF_ITERATIONS); | |
| 124 } | |
| 125 #endif | |
| 126 | |
| 127 for (i = 0; i < 0xFFFE; i++) { | |
| 128 if (i >= 0xD800 && i <= 0xDFFF) { /* UTF-16 surrogates */ | |
| 129 continue; | |
| 130 } | |
| 131 if (testContinue(p_ctx, i)) continue; | |
| 132 val = val2 = 0; | |
| 133 ret = u_sjis_int_test(i, &val); | |
| 134 ret2 = u_sjis_int2(i, &val2); | |
| 135 assert_equal(ret, ret2, "i:%d 0x%04X ret %d != ret2 %d, val 0x%04X, val2 0x%04X\n", (int) i, i, ret, ret2, val, val2); | |
| 136 if (ret2) { | |
| 137 assert_equal(val, val2, "i:%d 0x%04X val 0x%04X != val2 0x%04X\n", (int) i, i, val, val2); | |
| 138 } | |
| 139 #ifdef TEST_JUST_SAY_GNO | |
| 140 if (i != 0xFF3C) { /* Full-width reverse solidus duplicate no longer mapped to ignore */ | |
| 141 if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ | |
| 142 val2 = 0; | |
| 143 ret2 = sjis_wctomb_zint(&val2, i); | |
| 144 } else { | |
| 145 for (j = 0; j < TEST_INT_PERF_ITERATIONS; j++) { | |
| 146 val = val2 = 0; | |
| 147 | |
| 148 start = clock(); | |
| 149 ret = u_sjis_int_test(i, &val); | |
| 150 total += clock() - start; | |
| 151 | |
| 152 start = clock(); | |
| 153 ret2 = sjis_wctomb_zint(&val2, i); | |
| 154 total_gno += clock() - start; | |
| 155 } | |
| 156 } | |
| 157 | |
| 158 assert_equal(ret, ret2, "i:%d 0x%04X ret %d != ret2 %d, val 0x%04X, val2 0x%04X\n", (int) i, i, ret, ret2, val, val2); | |
| 159 if (ret2) { | |
| 160 assert_equal(val, val2, "i:%d 0x%04X val 0x%04X != val2 0x%04X\n", (int) i, i, val, val2); | |
| 161 } | |
| 162 } | |
| 163 #endif | |
| 164 } | |
| 165 | |
| 166 #ifdef TEST_JUST_SAY_GNO | |
| 167 if ((debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ | |
| 168 printf("test_u_sjis_int perf totals: new % 8gms, gno % 8gms ratio %g\n", | |
| 169 TEST_PERF_TIME(total), TEST_PERF_TIME(total_gno), TEST_PERF_RATIO(total, total_gno)); | |
| 170 } | |
| 171 #endif | |
| 172 | |
| 173 testFinish(); | |
| 174 } | |
| 175 | |
| 176 static void test_sjis_utf8(const testCtx *const p_ctx) { | |
| 177 | |
| 178 struct item { | |
| 179 char *data; | |
| 180 int length; | |
| 181 int ret; | |
| 182 int ret_length; | |
| 183 unsigned int expected_jisdata[20]; | |
| 184 char *comment; | |
| 185 }; | |
| 186 /* | |
| 187 é 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, UTF-8 C3A9 | |
| 188 β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in Shift JIS 0x83C0, UTF-8 CEB2 | |
| 189 Ж U+0416 in ISO 8859-5 Cyrillic (but not other ISO 8859), Win 1251, in Shift JIS 0x8447, UTF-8 D096 | |
| 190 ¥ U+00A5 in ISO 8859-1 0xA5 (\245), in Shift JIS single-byte 0x5C (\134) (backslash); 0xA5 same codepoint as single-byte half-width katakana ・ (U+FF65) in Shift JIS (below), UTF-8 C2A5 | |
| 191 ・ U+FF65 half-width katakana, not in ISO/Win, in Shift JIS single-byte 0xA5 (\245), UTF-8 EFBDA5 | |
| 192 ソ U+FF7F half-width katakana, not in ISO/Win, in Shift JIS single-byte 0xBF (\277), UTF-8 EFBDBF | |
| 193 ‾ U+203E overline, not in ISO/Win, in Shift JIS single-byte 0x7E (\176) (tilde), UTF-8 E280BE | |
| 194 \ U+FF3C full-width reverse solidus, in Shift JIS 0x815F, was duplicate of mapping of U+005C, UTF-8 EFBCBC | |
| 195 点 U+70B9 kanji, in Shift JIS 0x935F (\223\137), UTF-8 E782B9 | |
| 196 茗 U+8317 kanji, in Shift JIS 0xE4AA (\344\252), UTF-8 E88C97 | |
| 197 テ U+30C6 katakana, in Shift JIS 0x8365 (\203\145), UTF-8 E38386 | |
| 198 */ | |
| 199 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 200 struct item data[] = { | |
| 201 /* 0*/ { "é", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "" }, | |
| 202 /* 1*/ { "~", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "" }, | |
| 203 /* 2*/ { "β", -1, 0, 1, { 0x83C0 }, "" }, | |
| 204 /* 3*/ { "¥", -1, 0, 1, { 0x5C }, "" }, | |
| 205 /* 4*/ { "aβcЖ¥・ソ‾\\点茗テ", -1, 0, 12, { 'a', 0x83C0, 'c', 0x8447, 0x5C, 0xA5, 0xBF, 0x7E, 0x815F, 0x935F, 0xE4AA, 0x8365 }, "" }, | |
| 206 /* 5*/ { "\", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "U+FF3C full-width reverse solidus no longer duplicate mapping of U+005C" }, | |
| 207 /* 6*/ { "\200", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "Invalid UTF-8" }, | |
| 208 }; | |
| 209 int data_size = ARRAY_SIZE(data); | |
| 210 int i, length, ret; | |
| 211 | |
| 212 struct zint_symbol symbol = {0}; | |
| 213 unsigned int jisdata[20]; | |
| 214 | |
| 215 testStart("test_sjis_utf8"); | |
| 216 | |
| 217 for (i = 0; i < data_size; i++) { | |
| 218 int ret_length; | |
| 219 | |
| 220 if (testContinue(p_ctx, i)) continue; | |
| 221 | |
| 222 length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; | |
| 223 ret_length = length; | |
| 224 | |
| 225 ret = sjis_utf8(&symbol, (unsigned char *) data[i].data, &ret_length, jisdata); | |
| 226 assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol.errtxt); | |
| 227 if (ret == 0) { | |
| 228 int j; | |
| 229 assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); | |
| 230 for (j = 0; j < ret_length; j++) { | |
| 231 assert_equal(jisdata[j], data[i].expected_jisdata[j], "i:%d jisdata[%d] %04X != %04X\n", i, j, jisdata[j], data[i].expected_jisdata[j]); | |
| 232 } | |
| 233 } | |
| 234 } | |
| 235 | |
| 236 testFinish(); | |
| 237 } | |
| 238 | |
| 239 static void test_sjis_utf8_to_eci(const testCtx *const p_ctx) { | |
| 240 | |
| 241 struct item { | |
| 242 int eci; | |
| 243 int full_multibyte; | |
| 244 char *data; | |
| 245 int length; | |
| 246 int ret; | |
| 247 int ret_length; | |
| 248 unsigned int expected_jisdata[20]; | |
| 249 char *comment; | |
| 250 }; | |
| 251 /* | |
| 252 é U+00E9 in ISO 8859-1 0xE9, Win 1250 plus other Win, in QR Kanji mode first byte range 0x81..9F, 0xE0..EB | |
| 253 β U+03B2 in ISO 8859-7 Greek 0xE2 (but not other ISO 8859 or Win page) | |
| 254 ¥ U+00A5 in ISO 8859-1 0xA5, outside first byte range 0x81..9F, 0xE0..EB | |
| 255 ú U+00FA in ISO 8859-1 0xFA, outside first byte range | |
| 256 à U+00EO in ISO 8859-1 0xE0, in first byte range | |
| 257 ë U+00EB in ISO 8859-1 0xEB, in first byte range | |
| 258 ì U+00EC in ISO 8859-1 0xEC, outside first byte range | |
| 259 µ U+00B5 in ISO 8859-1 0xB5, outside first byte range | |
| 260 À U+00C0 in ISO 8859-1 0xC0, outside first byte range and 0xEBxx second byte range | |
| 261 */ | |
| 262 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 263 struct item data[] = { | |
| 264 /* 0*/ { 3, 0, "é", -1, 0, 1, { 0xE9 }, "" }, | |
| 265 /* 1*/ { 3, 1, "é", -1, 0, 1, { 0xE9 }, "" }, | |
| 266 /* 2*/ { 3, 0, "β", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "" }, | |
| 267 /* 3*/ { 3, 1, "β", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "" }, | |
| 268 /* 4*/ { 9, 0, "β", -1, 0, 1, { 0xE2 }, "" }, | |
| 269 /* 5*/ { 9, 1, "β", -1, 0, 1, { 0xE2 }, "" }, | |
| 270 /* 6*/ { 3, 0, "¥", -1, 0, 1, { 0xA5 }, "" }, | |
| 271 /* 7*/ { 3, 1, "¥", -1, 0, 1, { 0xA5 }, "" }, | |
| 272 /* 8*/ { 3, 0, "éa", -1, 0, 2, { 0xE9, 0x61 }, "Not full multibyte" }, | |
| 273 /* 9*/ { 3, 1, "éa", -1, 0, 1, { 0xE961 }, "In QR Kanji mode range" }, | |
| 274 /* 10*/ { 3, 0, "éaúbàcëdìeµ", -1, 0, 11, { 0xE9, 0x61, 0xFA, 0x62, 0xE0, 0x63, 0xEB, 0x64, 0xEC, 0x65, 0xB5 }, "" }, | |
| 275 /* 11*/ { 3, 1, "éaúbàcëdìeµ", -1, 0, 8, { 0xE961, 0xFA, 0x62, 0xE063, 0xEB64, 0xEC, 0x65, 0xB5 }, "" }, | |
| 276 /* 12*/ { 3, 0, "ëÀ", -1, 0, 2, { 0xEB, 0xC0 }, "Not full multibyte" }, | |
| 277 /* 13*/ { 3, 1, "ëÀ", -1, 0, 2, { 0xEB, 0xC0 }, "Outside QR Kanji mode range" }, | |
| 278 /* 14*/ { 20, 0, "\\\\", -1, 0, 2, { 0x815F, 0x815F }, "Shift JIS reverse solidus (backslash) mapping from ASCII to double byte" }, | |
| 279 /* 15*/ { 20, 1, "\\\\", -1, 0, 2, { 0x815F, 0x815F }, "Shift JIS reverse solidus (backslash) mapping from ASCII to double byte" }, | |
| 280 /* 16*/ { 20, 0, "爍", -1, 0, 1, { 0xE0A1 }, "Shift JIS U+720D" }, | |
| 281 /* 17*/ { 20, 1, "爍", -1, 0, 1, { 0xE0A1 }, "Shift JIS" }, | |
| 282 /* 18*/ { 20, 0, "~", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "ASCII tilde not in Shift JIS" }, | |
| 283 /* 19*/ { 25, 0, "12", -1, 0, 4, { 0x00, 0x31, 0x00, 0x32 }, "UCS-2BE ASCII" }, | |
| 284 /* 20*/ { 25, 0, "", -1, 0, 4, { 0x00, 0x81, 0x00, 0x81 }, "UCS-2BE U+0081" }, | |
| 285 /* 21*/ { 25, 1, "", -1, 0, 4, { 0x00, 0x81, 0x00, 0x81 }, "UCS-2BE outside QR Kanji mode range" }, | |
| 286 /* 22*/ { 25, 0, "腀", -1, 0, 2, { 0x81, 0x40 }, "UCS-2BE U+8140" }, | |
| 287 /* 23*/ { 25, 1, "腀", -1, 0, 1, { 0x8140 }, "UCS-2BE in QR Kanji mode range" }, | |
| 288 /* 24*/ { 28, 0, "¢¢", -1, 0, 4, { 0xA2, 0x46, 0xA2, 0x46 }, "Big5 U+00A2" }, | |
| 289 /* 25*/ { 28, 1, "¢¢", -1, 0, 4, { 0xA2, 0x46, 0xA2, 0x46 }, "Big5 outside QR Kanji mode range" }, | |
| 290 /* 26*/ { 28, 0, "觡", -1, 0, 2, { 0xE0, 0x40 }, "Big5 U+89E1" }, | |
| 291 /* 27*/ { 28, 1, "觡", -1, 0, 1, { 0xE040 }, "Big5 in QR Kanji mode range" }, | |
| 292 /* 28*/ { 29, 0, "¨¨", -1, 0, 4, { 0xA1, 0xA7, 0xA1, 0xA7 }, "GB 2312 U+00A8" }, | |
| 293 /* 29*/ { 29, 1, "¨¨", -1, 0, 4, { 0xA1, 0xA7, 0xA1, 0xA7 }, "GB 2312 outside QR Kanji mode range" }, | |
| 294 /* 30*/ { 29, 0, "崂", -1, 0, 2, { 0xE1, 0xC0 }, "GB 2312 U+5D02" }, | |
| 295 /* 31*/ { 29, 0, "釦", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "GB 18030 U+91E6 not in GB 2312" }, | |
| 296 /* 32*/ { 29, 1, "崂", -1, 0, 1, { 0xE1C0 }, "GB 2312 in QR Kanji mode range" }, | |
| 297 /* 33*/ { 30, 0, "¡¡", -1, 0, 4, { 0x22 + 0x80, 0x2E + 0x80, 0x22 + 0x80, 0x2E + 0x80 }, "EUC-KR U+00A1 (0xA2AE)" }, | |
| 298 /* 34*/ { 30, 1, "¡¡", -1, 0, 4, { 0x22 + 0x80, 0x2E + 0x80, 0x22 + 0x80, 0x2E + 0x80 }, "EUC-KR 0xA2AE outside QR Kanji mode range" }, | |
| 299 /* 35*/ { 30, 0, "詰", -1, 0, 2, { 0x7D + 0x80, 0x7E + 0x80 }, "EUC-KR U+8A70 (0xFDFE)" }, | |
| 300 /* 36*/ { 30, 1, "詰", -1, 0, 2, { 0x7D + 0x80, 0x7E + 0x80 }, "EUC-KR > 0xEBBF so not in QR Kanji mode range" }, | |
| 301 }; | |
| 302 int data_size = ARRAY_SIZE(data); | |
| 303 int i, length, ret; | |
| 304 | |
| 305 unsigned int jisdata[20]; | |
| 306 | |
| 307 testStart("test_sjis_utf8_to_eci"); | |
| 308 | |
| 309 for (i = 0; i < data_size; i++) { | |
| 310 int ret_length; | |
| 311 | |
| 312 if (testContinue(p_ctx, i)) continue; | |
| 313 | |
| 314 length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; | |
| 315 ret_length = length; | |
| 316 | |
| 317 ret = sjis_utf8_to_eci(data[i].eci, (unsigned char *) data[i].data, &ret_length, jisdata, data[i].full_multibyte); | |
| 318 assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); | |
| 319 if (ret == 0) { | |
| 320 int j; | |
| 321 assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); | |
| 322 for (j = 0; j < ret_length; j++) { | |
| 323 assert_equal(jisdata[j], data[i].expected_jisdata[j], "i:%d jisdata[%d] 0x%04X != 0x%04X\n", i, j, jisdata[j], data[i].expected_jisdata[j]); | |
| 324 } | |
| 325 } | |
| 326 } | |
| 327 | |
| 328 testFinish(); | |
| 329 } | |
| 330 | |
| 331 static void test_sjis_cpy(const testCtx *const p_ctx) { | |
| 332 | |
| 333 struct item { | |
| 334 int full_multibyte; | |
| 335 char *data; | |
| 336 int length; | |
| 337 int ret; | |
| 338 int ret_length; | |
| 339 unsigned int expected_jisdata[20]; | |
| 340 char *comment; | |
| 341 }; | |
| 342 /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ | |
| 343 struct item data[] = { | |
| 344 /* 0*/ { 0, "\351", -1, 0, 1, { 0xE9 }, "Not full multibyte" }, | |
| 345 /* 1*/ { 1, "\351", -1, 0, 1, { 0xE9 }, "In QR Kanji mode first-byte range but only one byte" }, | |
| 346 /* 2*/ { 0, "\351\141", -1, 0, 2, { 0xE9, 0x61 }, "Not full multibyte" }, | |
| 347 /* 3*/ { 1, "\351\141", -1, 0, 1, { 0xE961 }, "In QR Kanji mode range" }, | |
| 348 /* 4*/ { 1, "\201", -1, 0, 1, { 0x81 }, "In QR Kanji mode first-byte range but only one byte" }, | |
| 349 /* 5*/ { 0, "\201\141", -1, 0, 2, { 0x81, 0x61 }, "Not full multibyte" }, | |
| 350 /* 6*/ { 1, "\201\141", -1, 0, 1, { 0x8161 }, "In QR Kanji mode range" }, | |
| 351 /* 7*/ { 0, "\201\077\201\100\237\374\237\375\340\077\340\100\353\277\353\300", -1, 0, 16, { 0x81, 0x3F, 0x81, 0x40, 0x9F, 0xFC, 0x9F, 0xFD, 0xE0, 0x3F, 0xE0, 0x40, 0xEB, 0xBF, 0xEB, 0xC0 }, "" }, | |
| 352 /* 8*/ { 1, "\201\077\201\100\237\374\237\375\340\077\340\100\353\277\353\300", -1, 0, 12, { 0x81, 0x3F, 0x8140, 0x9FFC, 0x9F, 0xFD, 0xE0, 0x3F, 0xE040, 0xEBBF, 0xEB, 0xC0 }, "" }, | |
| 353 }; | |
| 354 int data_size = ARRAY_SIZE(data); | |
| 355 int i, length; | |
| 356 | |
| 357 unsigned int jisdata[20]; | |
| 358 | |
| 359 testStart("test_sjis_cpy"); | |
| 360 | |
| 361 for (i = 0; i < data_size; i++) { | |
| 362 int ret_length; | |
| 363 int j; | |
| 364 | |
| 365 if (testContinue(p_ctx, i)) continue; | |
| 366 | |
| 367 length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; | |
| 368 ret_length = length; | |
| 369 | |
| 370 sjis_cpy((unsigned char *) data[i].data, &ret_length, jisdata, data[i].full_multibyte); | |
| 371 assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); | |
| 372 for (j = 0; j < ret_length; j++) { | |
| 373 assert_equal(jisdata[j], data[i].expected_jisdata[j], "i:%d jisdata[%d] %04X != %04X\n", i, j, jisdata[j], data[i].expected_jisdata[j]); | |
| 374 } | |
| 375 } | |
| 376 | |
| 377 testFinish(); | |
| 378 } | |
| 379 | |
| 380 #define TEST_PERF_ITER_MILLES 100 | |
| 381 #define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000) | |
| 382 | |
| 383 /* Not a real test, just performance indicator */ | |
| 384 static void test_perf(const testCtx *const p_ctx) { | |
| 385 int debug = p_ctx->debug; | |
| 386 | |
| 387 struct item { | |
| 388 char *data; | |
| 389 int ret; | |
| 390 | |
| 391 char *comment; | |
| 392 }; | |
| 393 struct item data[] = { | |
| 394 /* 0*/ { "1234567890", 0, "10 numerics" }, | |
| 395 /* 1*/ { "貫やぐ識禁ぱい再2間変字全ノレ没無8裁", 0, "Small mixed" }, | |
| 396 /* 2*/ { "貫やぐ識禁ぱい再2間変字全ノレ没無8裁花ほゃ過法ひなご札17能つーびれ投覧マ勝動エヨ額界よみ作皇ナヲニ打題ヌルヲ掲布益フが。入35能ト権話しこを断兆モヘ細情おじ名4減エヘイハ側機はょが意見想ハ業独案ユヲウ患職ヲ平美さ毎放どぽたけ家没べお化富べ町大シ情魚ッでれ一冬すぼめり。", 0, "Bigger mixed" }, | |
| 397 /* 3*/ { "貫やぐ識禁ぱい再2間変字全ノレ没無8裁花ほゃ過法ひなご札17能つーびれ投覧マ勝動エヨ額界よみ作皇ナヲニ打題ヌルヲ掲布益フが。入35能ト権話しこを断兆モヘ細情おじ名4減エヘイハ側機はょが意見想ハ業独案ユヲウ患職ヲ平美さ毎放どぽたけ家没べお化富べ町大シ情魚ッでれ一冬すぼめり。社ト可化モマ試音ばじご育青康演ぴぎ権型固スで能麩ぜらもほ河都しちほラ収90作の年要とだむ部動ま者断チ第41一1米索焦茂げむしれ。測フ物使だて目月国スリカハ夏検にいへ児72告物ゆは載核ロアメヱ登輸どべゃ催行アフエハ議歌ワ河倫剖だ。記タケウ因載ヒイホヤ禁3輩彦関トえび肝区勝ワリロ成禁ぼよ界白ウヒキレ中島べせぜい各安うしぽリ覧生テ基一でむしゃ中新トヒキソ声碁スしび起田ア信大未ゅもばち。", 0, "Bigger mixed" }, | |
| 398 /* 4*/ { "点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点", 0, "784 kanji" }, | |
| 399 }; | |
| 400 int data_size = ARRAY_SIZE(data); | |
| 401 int i, length, ret; | |
| 402 | |
| 403 struct zint_symbol symbol = {0}; | |
| 404 int ret_length; | |
| 405 #ifdef TEST_JUST_SAY_GNO | |
| 406 int ret_length2; | |
| 407 #endif | |
| 408 unsigned int ddata[8192]; | |
| 409 int ret2 = 0; | |
| 410 #ifdef TEST_JUST_SAY_GNO | |
| 411 unsigned int ddata2[8192]; | |
| 412 #endif | |
| 413 | |
| 414 clock_t start; | |
| 415 clock_t total = 0, total_gno = 0; | |
| 416 clock_t diff, diff_gno; | |
| 417 int comment_max = 0; | |
| 418 | |
| 419 if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ | |
| 420 return; | |
| 421 } | |
| 422 | |
| 423 for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment); | |
| 424 | |
| 425 printf("Iterations %d\n", TEST_PERF_ITERATIONS); | |
| 426 | |
| 427 for (i = 0; i < data_size; i++) { | |
| 428 int j; | |
| 429 | |
| 430 if (testContinue(p_ctx, i)) continue; | |
| 431 | |
| 432 length = (int) strlen(data[i].data); | |
| 433 | |
| 434 diff = diff_gno = 0; | |
| 435 | |
| 436 for (j = 0; j < TEST_PERF_ITERATIONS; j++) { | |
| 437 ret_length = length; | |
| 438 | |
| 439 start = clock(); | |
| 440 ret = sjis_utf8(&symbol, (unsigned char *) data[i].data, &ret_length, ddata); | |
| 441 diff += clock() - start; | |
| 442 | |
| 443 #ifdef TEST_JUST_SAY_GNO | |
| 444 ret_length2 = length; | |
| 445 start = clock(); | |
| 446 ret2 = sjis_utf8_wctomb(&symbol, (unsigned char *) data[i].data, &ret_length2, ddata2); | |
| 447 diff_gno += clock() - start; | |
| 448 #endif | |
| 449 } | |
| 450 assert_equal(ret, ret2, "i:%d ret %d != ret2 %d\n", (int) i, ret, ret2); | |
| 451 | |
| 452 printf("%*s: new % 8gms, gno % 8gms ratio %g\n", comment_max, data[i].comment, | |
| 453 TEST_PERF_TIME(diff), TEST_PERF_TIME(diff_gno), TEST_PERF_RATIO(diff, diff_gno)); | |
| 454 | |
| 455 total += diff; | |
| 456 total_gno += diff_gno; | |
| 457 } | |
| 458 if (p_ctx->index == -1) { | |
| 459 printf("%*s: new % 8gms, gno % 8gms ratio %g\n", comment_max, "totals", | |
| 460 TEST_PERF_TIME(total), TEST_PERF_TIME(total_gno), TEST_PERF_RATIO(total, total_gno)); | |
| 461 } | |
| 462 } | |
| 463 | |
| 464 int main(int argc, char *argv[]) { | |
| 465 | |
| 466 testFunction funcs[] = { /* name, func */ | |
| 467 { "test_u_sjis_int", test_u_sjis_int }, | |
| 468 { "test_sjis_utf8", test_sjis_utf8 }, | |
| 469 { "test_sjis_utf8_to_eci", test_sjis_utf8_to_eci }, | |
| 470 { "test_sjis_cpy", test_sjis_cpy }, | |
| 471 { "test_perf", test_perf }, | |
| 472 }; | |
| 473 | |
| 474 testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); | |
| 475 | |
| 476 testReport(); | |
| 477 | |
| 478 return 0; | |
| 479 } | |
| 480 | |
| 481 /* vim: set ts=4 sw=4 et : */ |
