mirror of
https://git.code.sf.net/p/zint/code
synced 2026-05-14 18:13:53 +00:00
eci.c: replace libiconv-adapted code with own implementations so
as to fully comply with BSD license (for why Library GPL 2+ not compatible see https://opensource.stackexchange.com/a/6701), ~3% slower (maybe), +~6K extra in data (gb18030.c, gb2313.c & sjis.c removed, mapping .TXT files moved to backend/tools/data & extra ones added, 2 new PHP generators) GUI: CODE39/EXCODE39: show/hide HIBC check digit option in addition to enable/disable (less confusing) CLI: batch: pedantic check for EOF using intChar in newline fgetc() loop test_args.c: don't use WIFEXITED(), WEXITSTATUS() on Windows manual: lessen some copy/paste verbiage by referring back, other small tweaks/typos
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2021 Robin Stuart <rstuart114@gmail.com>
|
||||
Copyright (C) 2021-2022 Robin Stuart <rstuart114@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -27,72 +27,146 @@
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
*/
|
||||
/* vim: set ts=4 sw=4 et : */
|
||||
|
||||
#include "testcommon.h"
|
||||
#include "test_ksx1001_tab.h"
|
||||
#include "../ksx1001.h"
|
||||
/* For local "private" testing using previous libiconv adaptation, not included for licensing reasons */
|
||||
//#define TEST_JUST_SAY_GNO
|
||||
#ifdef TEST_JUST_SAY_GNO
|
||||
#include "../just_say_gno/ksx1001_gnu.h"
|
||||
#endif
|
||||
|
||||
// As control convert to KS X 1001 using simple table generated from https://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/KSC/KSX1001.TXT plus simple processing
|
||||
static int ksx1001_wctomb_zint2(unsigned int *r, unsigned int wc) {
|
||||
INTERNAL int u_ksx1001_test(const unsigned int u, unsigned char *dest);
|
||||
|
||||
// Version of `u_ksx1001()` taking unsigned int destination for backward-compatible testing
|
||||
static int u_ksx1001_int(const unsigned int u, unsigned int *d) {
|
||||
unsigned char dest[2];
|
||||
int ret = u_ksx1001_test(u, dest);
|
||||
if (ret) {
|
||||
*d = ret == 1 ? dest[0] : ((dest[0] << 8) | dest[1]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// As control convert to KS X 1001 using simple table generated from
|
||||
// https://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/KSC/KSX1001.TXT plus simple processing
|
||||
static int u_ksx1001_int2(unsigned int u, unsigned int *dest) {
|
||||
int tab_length, start_i, end_i;
|
||||
int i;
|
||||
|
||||
if (wc < 0x80) {
|
||||
return 0;
|
||||
if (u < 0x80) {
|
||||
*dest = u;
|
||||
return 1;
|
||||
}
|
||||
if (wc == 0x20AC) { // Euro sign added KS X 1001:1998
|
||||
*r = 0x2266;
|
||||
if (u == 0x20AC) { // Euro sign added KS X 1001:1998
|
||||
*dest = 0x2266 + 0x8080;
|
||||
return 2;
|
||||
}
|
||||
if (wc == 0xAE) { // Registered trademark added KS X 1001:1998
|
||||
*r = 0x2267;
|
||||
if (u == 0xAE) { // Registered trademark added KS X 1001:1998
|
||||
*dest = 0x2267 + 0x8080;
|
||||
return 2;
|
||||
}
|
||||
if (wc == 0x327E) { // Korean postal code symbol added KS X 1001:2002
|
||||
*r = 0x2268;
|
||||
if (u == 0x327E) { // Korean postal code symbol added KS X 1001:2002
|
||||
*dest = 0x2268 + 0x8080;
|
||||
return 2;
|
||||
}
|
||||
tab_length = ARRAY_SIZE(test_ksx1001_tab);
|
||||
start_i = test_ksx1001_tab_ind[wc >> 10];
|
||||
start_i = test_ksx1001_tab_ind[u >> 10];
|
||||
end_i = start_i + 0x800 > tab_length ? tab_length : start_i + 0x800;
|
||||
for (i = start_i; i < end_i; i += 2) {
|
||||
if (test_ksx1001_tab[i + 1] == wc) {
|
||||
*r = test_ksx1001_tab[i];
|
||||
return *r > 0xFF ? 2 : 1;
|
||||
if (test_ksx1001_tab[i + 1] == u) {
|
||||
*dest = test_ksx1001_tab[i] + 0x8080;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_ksx1001_wctomb_zint(void) {
|
||||
#include <time.h>
|
||||
|
||||
#define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC)
|
||||
#define TEST_PERF_RATIO(a1, a2) (a2 ? TEST_PERF_TIME(a1) / TEST_PERF_TIME(a2) : 0)
|
||||
|
||||
#ifdef TEST_JUST_SAY_GNO
|
||||
#define TEST_INT_PERF_ITERATIONS 100
|
||||
#endif
|
||||
|
||||
static void test_u_ksx1001_int(int debug) {
|
||||
|
||||
int ret, ret2;
|
||||
unsigned int val, val2;
|
||||
unsigned i;
|
||||
|
||||
testStart("test_ksx1001_wctomb_zint");
|
||||
#ifdef TEST_JUST_SAY_GNO
|
||||
int j;
|
||||
clock_t start;
|
||||
clock_t total = 0, total_gno = 0;
|
||||
#else
|
||||
(void)debug;
|
||||
#endif
|
||||
|
||||
testStart("test_u_ksx1001_int");
|
||||
|
||||
#ifdef TEST_JUST_SAY_GNO
|
||||
if ((debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
|
||||
printf("test_u_ksx1001_int perf iterations: %d\n", TEST_INT_PERF_ITERATIONS);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = 0; i < 0xFFFE; i++) {
|
||||
if (i >= 0xD800 && i <= 0xDFFF) { // UTF-16 surrogates
|
||||
continue;
|
||||
}
|
||||
val = val2 = 0;
|
||||
ret = ksx1001_wctomb_zint(&val, i);
|
||||
ret2 = ksx1001_wctomb_zint2(&val2, i);
|
||||
ret = u_ksx1001_int(i, &val);
|
||||
ret2 = u_ksx1001_int2(i, &val2);
|
||||
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);
|
||||
if (ret2) {
|
||||
assert_equal(val, val2, "i:%d 0x%04X val 0x%04X != val2 0x%04X\n", (int) i, i, val, val2);
|
||||
}
|
||||
#ifdef TEST_JUST_SAY_GNO
|
||||
if (i >= 0x80) { // `ksx1001_wctomb_zint()` doesn't handle ASCII
|
||||
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
|
||||
val2 = 0;
|
||||
ret2 = ksx1001_wctomb_zint(&val2, i);
|
||||
} else {
|
||||
for (j = 0; j < TEST_INT_PERF_ITERATIONS; j++) {
|
||||
val = val2 = 0;
|
||||
|
||||
start = clock();
|
||||
ret = u_ksx1001_int(i, &val);
|
||||
total += clock() - start;
|
||||
|
||||
start = clock();
|
||||
ret2 = ksx1001_wctomb_zint(&val2, i);
|
||||
total_gno += clock() - start;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
if (ret2) {
|
||||
val2 += 0x8080; // `ksx1001_wctomb_zint()` returns pure KS X 1001 values, convert to EUC-KR
|
||||
assert_equal(val, val2, "i:%d 0x%04X val 0x%04X != val2 0x%04X\n", (int) i, i, val, val2);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TEST_JUST_SAY_GNO
|
||||
if ((debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
|
||||
printf("test_u_ksx1001_int perf totals: new % 8gms, gno % 8gms ratio %g\n",
|
||||
TEST_PERF_TIME(total), TEST_PERF_TIME(total_gno), TEST_PERF_RATIO(total, total_gno));
|
||||
}
|
||||
#endif
|
||||
|
||||
testFinish();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
|
||||
{ "test_ksx1001_wctomb_zint", test_ksx1001_wctomb_zint, 0, 0, 0 },
|
||||
{ "test_u_ksx1001_int", test_u_ksx1001_int, 0, 0, 1 },
|
||||
};
|
||||
|
||||
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
|
||||
@@ -101,3 +175,5 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vim: set ts=4 sw=4 et : */
|
||||
|
||||
Reference in New Issue
Block a user