test suite: convert to use test context p_ctx instead of individual

args; new -x exclude option and ranges; no longer use getopt();
  make C89 compat
This commit is contained in:
gitlost 2022-09-12 19:26:04 +01:00
parent 0d4aa6cce3
commit 90dfbdb5d9
58 changed files with 2822 additions and 2340 deletions

View File

@ -24,17 +24,11 @@ set(testcommon_SRCS testcommon.c testcommon.h)
add_library(testcommon ${testcommon_SRCS}) add_library(testcommon ${testcommon_SRCS})
target_link_libraries(testcommon zint) target_link_libraries(testcommon zint)
target_include_directories(testcommon PUBLIC ${zint_backend_tests_SOURCE_DIR}) target_include_directories(testcommon PUBLIC ${zint_backend_tests_SOURCE_DIR})
if(NOT HAVE_GETOPT)
target_link_libraries(testcommon zint_bundled_getopt)
endif()
if(ZINT_STATIC) if(ZINT_STATIC)
add_library(testcommon-static ${testcommon_SRCS}) add_library(testcommon-static ${testcommon_SRCS})
target_link_libraries(testcommon-static zint-static) target_link_libraries(testcommon-static zint-static)
target_include_directories(testcommon-static PUBLIC ${zint_backend_tests_SOURCE_DIR}) target_include_directories(testcommon-static PUBLIC ${zint_backend_tests_SOURCE_DIR})
if(NOT HAVE_GETOPT)
target_link_libraries(testcommon-static zint_bundled_getopt)
endif()
endif() endif()
zint_add_test(2of5 test_2of5) zint_add_test(2of5 test_2of5)

View File

@ -62,22 +62,48 @@ To run a single dataset item in a single test function, use '-i <index>':
backend/tests/test_dotcode -f input -i 2 backend/tests/test_dotcode -f input -i 2
To run a range of dataset items in a single test function, use '-i <start>,<end>':
backend/tests/test_dotcode -f input -i 2,5
To exclude a single dataset item in a single test function, use '-x <index>':
backend/tests/test_dotcode -f input -x 4
This can also take a range, '-x <start>,<end>':
backend/tests/test_dotcode -f input -x 4,6
The include and exclude options can be used together:
backend/tests/test_dotcode -f input -i 2,7 -x 4
To show debug info (if any), use '-d <flag>': To show debug info (if any), use '-d <flag>':
backend/tests/test_dotcode -f input -i 2 -d 1 backend/tests/test_dotcode -f input -i 2 -d 1
E.g. to print which dataset items are being run, use '-d 16':
backend/tests/test_dotcode -f input -d 16 -i 2
(for other flags see <project-dir>/backend/tests/testcommon.h) (for other flags see <project-dir>/backend/tests/testcommon.h)
To generate test data, use '-g':
backend/tests/test_dotcode -f encode -g
To run a test against BWIPP (if any), use '-d 128': To run a test against BWIPP (if any), use '-d 128':
backend/tests/test_composite -d 128 backend/tests/test_composite -d 128
(see also <project-dir>/backend/tests/tools/run_bwipp_tests.sh) (see also <project-dir>/backend/tests/tools/run_bwipp_tests.sh)
To run a test against ZXing-C++ (if any), use '-d 512':
backend/tests/test_rss -d 512
(see also <project-dir>/backend/tests/tools/run_zxingcpp_tests.sh)
To generate test data, use '-g':
backend/tests/test_dotcode -f encode -g
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
If the zint library was built with static linkage support, i.e. ZINT_STATIC If the zint library was built with static linkage support, i.e. ZINT_STATIC

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -41,7 +43,7 @@ static void test_large(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_C25STANDARD, -1, "1", 80, 0, 1, 817 }, /* 0*/ { BARCODE_C25STANDARD, -1, "1", 80, 0, 1, 817 },
/* 1*/ { BARCODE_C25STANDARD, -1, "1", 81, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 1*/ { BARCODE_C25STANDARD, -1, "1", 81, ZINT_ERROR_TOO_LONG, -1, -1 },
@ -80,7 +82,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -104,7 +106,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_hrt(int index, int debug) { static void test_hrt(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -112,16 +115,16 @@ static void test_hrt(int index, int debug) {
char *data; char *data;
char *expected; char *expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_C25STANDARD, -1, "123456789", "123456789" }, /* 0*/ { BARCODE_C25STANDARD, -1, "123456789", "123456789" },
/* 1*/ { BARCODE_C25STANDARD, 1, "123456789", "1234567895" }, /* 1*/ { BARCODE_C25STANDARD, 1, "123456789", "1234567895" },
/* 2*/ { BARCODE_C25STANDARD, 2, "123456789", "123456789" }, // Suppresses printing of check digit /* 2*/ { BARCODE_C25STANDARD, 2, "123456789", "123456789" }, /* Suppresses printing of check digit */
/* 3*/ { BARCODE_C25INTER, -1, "123456789", "0123456789" }, // Adds leading zero if odd /* 3*/ { BARCODE_C25INTER, -1, "123456789", "0123456789" }, /* Adds leading zero if odd */
/* 4*/ { BARCODE_C25INTER, 1, "123456789", "1234567895" }, // Unless check digit added when it becomes even /* 4*/ { BARCODE_C25INTER, 1, "123456789", "1234567895" }, /* Unless check digit added when it becomes even */
/* 5*/ { BARCODE_C25INTER, 2, "123456789", "123456789" }, /* 5*/ { BARCODE_C25INTER, 2, "123456789", "123456789" },
/* 6*/ { BARCODE_C25INTER, -1, "1234567890", "1234567890" }, // No leading zero if even /* 6*/ { BARCODE_C25INTER, -1, "1234567890", "1234567890" }, /* No leading zero if even */
/* 7*/ { BARCODE_C25INTER, 1, "1234567890", "012345678905" }, // Unless check digit added when it becomes odd /* 7*/ { BARCODE_C25INTER, 1, "1234567890", "012345678905" }, /* Unless check digit added when it becomes odd */
/* 8*/ { BARCODE_C25INTER, 2, "1234567890", "01234567890" }, /* 8*/ { BARCODE_C25INTER, 2, "1234567890", "01234567890" },
/* 9*/ { BARCODE_C25IATA, -1, "123456789", "123456789" }, /* 9*/ { BARCODE_C25IATA, -1, "123456789", "123456789" },
/* 10*/ { BARCODE_C25IATA, 1, "123456789", "1234567895" }, /* 10*/ { BARCODE_C25IATA, 1, "123456789", "1234567895" },
@ -132,11 +135,11 @@ static void test_hrt(int index, int debug) {
/* 15*/ { BARCODE_C25IND, -1, "123456789", "123456789" }, /* 15*/ { BARCODE_C25IND, -1, "123456789", "123456789" },
/* 16*/ { BARCODE_C25IND, 1, "123456789", "1234567895" }, /* 16*/ { BARCODE_C25IND, 1, "123456789", "1234567895" },
/* 17*/ { BARCODE_C25IND, 2, "123456789", "123456789" }, /* 17*/ { BARCODE_C25IND, 2, "123456789", "123456789" },
/* 18*/ { BARCODE_DPLEIT, -1, "123456789", "00001234567890" }, // Leading zeroes added to make 13 + appended checksum /* 18*/ { BARCODE_DPLEIT, -1, "123456789", "00001234567890" }, /* Leading zeroes added to make 13 + appended checksum */
/* 19*/ { BARCODE_DPLEIT, -1, "1234567890123", "12345678901236" }, /* 19*/ { BARCODE_DPLEIT, -1, "1234567890123", "12345678901236" },
/* 20*/ { BARCODE_DPIDENT, -1, "123456789", "001234567890" }, // Leading zeroes added to make 11 + appended checksum /* 20*/ { BARCODE_DPIDENT, -1, "123456789", "001234567890" }, /* Leading zeroes added to make 11 + appended checksum */
/* 21*/ { BARCODE_DPIDENT, -1, "12345678901", "123456789016" }, /* 21*/ { BARCODE_DPIDENT, -1, "12345678901", "123456789016" },
/* 22*/ { BARCODE_ITF14, -1, "123456789", "00001234567895" }, // Leading zeroes added to make 13 + appended checksum /* 22*/ { BARCODE_ITF14, -1, "123456789", "00001234567895" }, /* Leading zeroes added to make 13 + appended checksum */
/* 23*/ { BARCODE_ITF14, -1, "1234567890123", "12345678901231" }, /* 23*/ { BARCODE_ITF14, -1, "1234567890123", "12345678901231" },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -147,7 +150,7 @@ static void test_hrt(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -165,7 +168,8 @@ static void test_hrt(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -174,7 +178,7 @@ static void test_input(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_C25STANDARD, "A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 0*/ { BARCODE_C25STANDARD, "A", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 1*/ { BARCODE_C25INTER, "A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 1*/ { BARCODE_C25INTER, "A", ZINT_ERROR_INVALID_DATA, -1, -1 },
@ -193,7 +197,7 @@ static void test_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -214,7 +218,8 @@ static void test_input(int index, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -227,7 +232,7 @@ static void test_encode(int index, int generate, int debug) {
char *comment; char *comment;
char *expected; char *expected;
}; };
// BARCODE_ITF14 examples verified manually against GS1 General Specifications 21.0.1 /* BARCODE_ITF14 examples verified manually against GS1 General Specifications 21.0.1 */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_C25STANDARD, -1, "87654321", 0, 1, 97, "Standard Code 2 of 5; note zint uses 4X start/end wides while BWIPP uses 3X", /* 0*/ { BARCODE_C25STANDARD, -1, "87654321", 0, 1, 97, "Standard Code 2 of 5; note zint uses 4X start/end wides while BWIPP uses 3X",
"1111010101110100010101000111010001110101110111010101110111011100010101000101110111010111011110101" "1111010101110100010101000111010001110101110111010101110111011100010101000101110111010111011110101"
@ -307,14 +312,14 @@ static void test_encode(int index, int generate, int debug) {
int i, length, ret; int i, length, ret;
struct zint_symbol *symbol; struct zint_symbol *symbol;
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -324,7 +329,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, testUtilBarcodeName(data[i].symbology), data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
@ -374,8 +379,9 @@ static void test_encode(int index, int generate, int debug) {
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000) #define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
#define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC) #define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC)
// Not a real test, just performance indicator /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -413,7 +419,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0; diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
@ -443,7 +449,7 @@ static void test_perf(int index, int debug) {
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/); ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start; diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt); assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; // Undo symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock(); start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/); ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
@ -463,7 +469,7 @@ static void test_perf(int index, int debug) {
total_buf_inter += diff_buf_inter; total_buf_inter += diff_buf_inter;
total_print += diff_print; total_print += diff_print;
} }
if (index == -1) { if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals", printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create)); TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
} }
@ -471,12 +477,12 @@ static void test_perf(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_hrt", test_hrt, 1, 0, 1 }, { "test_hrt", test_hrt },
{ "test_input", test_input, 1, 0, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -31,7 +31,8 @@
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -41,7 +42,7 @@ static void test_large(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_AUSPOST, "1", 23, 0, 3, 133 }, /* 0*/ { BARCODE_AUSPOST, "1", 23, 0, 3, 133 },
/* 1*/ { BARCODE_AUSPOST, "1", 24, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 1*/ { BARCODE_AUSPOST, "1", 24, ZINT_ERROR_TOO_LONG, -1, -1 },
@ -70,7 +71,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -94,7 +95,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_hrt(int index, int debug) { static void test_hrt(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -102,9 +104,9 @@ static void test_hrt(int index, int debug) {
char *expected; char *expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_AUSPOST, "12345678901234567890123", "" }, // None /* 0*/ { BARCODE_AUSPOST, "12345678901234567890123", "" }, /* None */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -114,7 +116,7 @@ static void test_hrt(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -132,7 +134,8 @@ static void test_hrt(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -142,7 +145,7 @@ static void test_input(int index, int debug) {
int expected_width; int expected_width;
char *expected_errtxt; char *expected_errtxt;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_AUSPOST, "12345678", 0, 3, 73, "" }, /* 0*/ { BARCODE_AUSPOST, "12345678", 0, 3, 73, "" },
/* 1*/ { BARCODE_AUSPOST, "1234567A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 405: Invalid character in DPID (first 8 characters) (digits only)" }, /* 1*/ { BARCODE_AUSPOST, "1234567A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 405: Invalid character in DPID (first 8 characters) (digits only)" },
@ -151,12 +154,12 @@ static void test_input(int index, int debug) {
/* 4*/ { BARCODE_AUSPOST, "12345678ABcd#", 0, 3, 103, "" }, /* 4*/ { BARCODE_AUSPOST, "12345678ABcd#", 0, 3, 103, "" },
/* 5*/ { BARCODE_AUSPOST, "1234567890123456", 0, 3, 103, "" }, /* 5*/ { BARCODE_AUSPOST, "1234567890123456", 0, 3, 103, "" },
/* 6*/ { BARCODE_AUSPOST, "123456789012345A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 402: Invalid character in data (digits only for length 16)" }, /* 6*/ { BARCODE_AUSPOST, "123456789012345A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 402: Invalid character in data (digits only for length 16)" },
/* 7*/ { BARCODE_AUSPOST, "12345678ABCDefgh #", 0, 3, 133, "" }, // Length 18 /* 7*/ { BARCODE_AUSPOST, "12345678ABCDefgh #", 0, 3, 133, "" }, /* Length 18 */
/* 8*/ { BARCODE_AUSPOST, "12345678901234567890123", 0, 3, 133, "" }, /* 8*/ { BARCODE_AUSPOST, "12345678901234567890123", 0, 3, 133, "" },
/* 9*/ { BARCODE_AUSPOST, "1234567890123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 406: Invalid character in data (digits only for length 23)" }, /* 9*/ { BARCODE_AUSPOST, "1234567890123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 406: Invalid character in data (digits only for length 23)" },
/* 10*/ { BARCODE_AUSPOST, "1234567", ZINT_ERROR_TOO_LONG, -1, -1, "Error 401: Input wrong length (8, 13, 16, 18 or 23 characters only)" }, // No leading zeroes added /* 10*/ { BARCODE_AUSPOST, "1234567", ZINT_ERROR_TOO_LONG, -1, -1, "Error 401: Input wrong length (8, 13, 16, 18 or 23 characters only)" }, /* No leading zeroes added */
/* 11*/ { BARCODE_AUSREPLY, "12345678", 0, 3, 73, "" }, /* 11*/ { BARCODE_AUSREPLY, "12345678", 0, 3, 73, "" },
/* 12*/ { BARCODE_AUSREPLY, "1234567", 0, 3, 73, "" }, // Leading zeroes added /* 12*/ { BARCODE_AUSREPLY, "1234567", 0, 3, 73, "" }, /* Leading zeroes added */
/* 13*/ { BARCODE_AUSREPLY, "123456789", ZINT_ERROR_TOO_LONG, -1, -1, "Error 403: Input too long (8 character maximum)" }, /* 13*/ { BARCODE_AUSREPLY, "123456789", ZINT_ERROR_TOO_LONG, -1, -1, "Error 403: Input too long (8 character maximum)" },
/* 14*/ { BARCODE_AUSROUTE, "123456", 0, 3, 73, "" }, /* 14*/ { BARCODE_AUSROUTE, "123456", 0, 3, 73, "" },
/* 15*/ { BARCODE_AUSROUTE, "12345", 0, 3, 73, "" }, /* 15*/ { BARCODE_AUSROUTE, "12345", 0, 3, 73, "" },
@ -174,7 +177,7 @@ static void test_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -196,11 +199,13 @@ static void test_input(int index, int debug) {
testFinish(); testFinish();
} }
// Australia Post Customer Barcoding Technical Specifications (Revised 3 Aug 2012) "AusPost Tech Specs" /* Australia Post Customer Barcoding Technical Specifications (Revised 3 Aug 2012) "AusPost Tech Specs"
// https://auspost.com.au/content/dam/auspost_corp/media/documents/customer-barcode-technical-specifications-aug2012.pdf https://auspost.com.au/content/dam/auspost_corp/media/documents/customer-barcode-technical-specifications-aug2012.pdf
// Australia Post A Guide To Printing the 4-State Barcode (Revised 16 March 2012) "AusPost Guide" Australia Post A Guide To Printing the 4-State Barcode (Revised 16 March 2012) "AusPost Guide"
// https://auspost.com.au/content/dam/auspost_corp/media/documents/a-guide-to-printing-the-4state-barcode-v31-mar2012.pdf https://auspost.com.au/content/dam/auspost_corp/media/documents/a-guide-to-printing-the-4state-barcode-v31-mar2012.pdf
static void test_encode(int index, int generate, int debug) { */
static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -297,13 +302,13 @@ static void test_encode(int index, int generate, int debug) {
char bwipp_buf[8192]; char bwipp_buf[8192];
char bwipp_msg[1024]; char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -313,7 +318,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, \"%s\", %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, testUtilBarcodeName(data[i].symbology), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
@ -346,8 +351,9 @@ static void test_encode(int index, int generate, int debug) {
testFinish(); testFinish();
} }
// #181 Christian Hartlage OSS-Fuzz /* #181 Christian Hartlage OSS-Fuzz */
static void test_fuzz(int index, int debug) { static void test_fuzz(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -355,7 +361,7 @@ static void test_fuzz(int index, int debug) {
int length; int length;
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_AUSROUTE, "A\000\000\000", 4, ZINT_ERROR_INVALID_DATA }, /* 0*/ { BARCODE_AUSROUTE, "A\000\000\000", 4, ZINT_ERROR_INVALID_DATA },
/* 1*/ { BARCODE_AUSROUTE, "1\000\000\000", 4, ZINT_ERROR_INVALID_DATA }, /* 1*/ { BARCODE_AUSROUTE, "1\000\000\000", 4, ZINT_ERROR_INVALID_DATA },
@ -372,7 +378,7 @@ static void test_fuzz(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -390,12 +396,12 @@ static void test_fuzz(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_hrt", test_hrt, 1, 0, 1 }, { "test_hrt", test_hrt },
{ "test_input", test_input, 1, 0, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_fuzz", test_fuzz, 1, 0, 1 }, { "test_fuzz", test_fuzz },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_options(int index, int debug) { static void test_options(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -46,7 +48,7 @@ static void test_options(int index, int debug) {
int expected_width; int expected_width;
const char *expected_errtxt; const char *expected_errtxt;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_AZTEC, -1, -1, -1, -1, { 0, 0, "" }, "1234567890", 0, 15, 15, "" }, /* 0*/ { BARCODE_AZTEC, -1, -1, -1, -1, { 0, 0, "" }, "1234567890", 0, 15, 15, "" },
/* 1*/ { BARCODE_AZTEC, -1, -1, 1, -1, { 0, 0, "" }, "1234567890", 0, 15, 15, "" }, /* 1*/ { BARCODE_AZTEC, -1, -1, 1, -1, { 0, 0, "" }, "1234567890", 0, 15, 15, "" },
@ -58,10 +60,10 @@ static void test_options(int index, int debug) {
/* 7*/ { BARCODE_AZTEC, GS1_MODE, READER_INIT, -1, -1, { 0, 0, "" }, "[91]A", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 501: Cannot encode in GS1 and Reader Initialisation mode at the same time" }, /* 7*/ { BARCODE_AZTEC, GS1_MODE, READER_INIT, -1, -1, { 0, 0, "" }, "[91]A", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 501: Cannot encode in GS1 and Reader Initialisation mode at the same time" },
/* 8*/ { BARCODE_AZTEC, GS1_MODE, -1, -1, -1, { 0, 0, "" }, "[91]A", 0, 15, 15, "" }, /* 8*/ { BARCODE_AZTEC, GS1_MODE, -1, -1, -1, { 0, 0, "" }, "[91]A", 0, 15, 15, "" },
/* 9*/ { BARCODE_AZTEC, GS1_MODE | GS1PARENS_MODE, -1, -1, -1, { 0, 0, "" }, "(91)A", 0, 15, 15, "" }, /* 9*/ { BARCODE_AZTEC, GS1_MODE | GS1PARENS_MODE, -1, -1, -1, { 0, 0, "" }, "(91)A", 0, 15, 15, "" },
/* 10*/ { BARCODE_AZTEC, -1, READER_INIT, -1, 26, { 0, 0, "" }, "A", 0, 109, 109, "" }, // 22 layers /* 10*/ { BARCODE_AZTEC, -1, READER_INIT, -1, 26, { 0, 0, "" }, "A", 0, 109, 109, "" }, /* 22 layers */
/* 11*/ { BARCODE_AZTEC, -1, READER_INIT, -1, 27, { 0, 0, "" }, "A", ZINT_ERROR_TOO_LONG, -1, -1, "Error 506: Data too long for reader initialisation symbol" }, // 23 layers /* 11*/ { BARCODE_AZTEC, -1, READER_INIT, -1, 27, { 0, 0, "" }, "A", ZINT_ERROR_TOO_LONG, -1, -1, "Error 506: Data too long for reader initialisation symbol" }, /* 23 layers */
/* 12*/ { BARCODE_AZTEC, -1, READER_INIT, -1, 1, { 0, 0, "" }, "A", 0, 15, 15, "" }, // Compact 1 layer /* 12*/ { BARCODE_AZTEC, -1, READER_INIT, -1, 1, { 0, 0, "" }, "A", 0, 15, 15, "" }, /* Compact 1 layer */
/* 13*/ { BARCODE_AZTEC, -1, READER_INIT, -1, 2, { 0, 0, "" }, "A", 0, 19, 19, "" }, // Compact 2 layers gets set to full 1 layer if READER_INIT set /* 13*/ { BARCODE_AZTEC, -1, READER_INIT, -1, 2, { 0, 0, "" }, "A", 0, 19, 19, "" }, /* Compact 2 layers gets set to full 1 layer if READER_INIT set */
/* 14*/ { BARCODE_AZRUNE, -1, -1, -1, -1, { 0, 0, "" }, "0001", ZINT_ERROR_TOO_LONG, -1, -1, "Error 507: Input too large (3 character maximum)" }, /* 14*/ { BARCODE_AZRUNE, -1, -1, -1, -1, { 0, 0, "" }, "0001", ZINT_ERROR_TOO_LONG, -1, -1, "Error 507: Input too large (3 character maximum)" },
/* 15*/ { BARCODE_AZRUNE, -1, -1, -1, -1, { 0, 0, "" }, "A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 508: Invalid character in data (digits only)" }, /* 15*/ { BARCODE_AZRUNE, -1, -1, -1, -1, { 0, 0, "" }, "A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 508: Invalid character in data (digits only)" },
/* 16*/ { BARCODE_AZRUNE, -1, -1, -1, -1, { 0, 0, "" }, "256", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 509: Input out of range (0 to 255)" }, /* 16*/ { BARCODE_AZRUNE, -1, -1, -1, -1, { 0, 0, "" }, "256", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 509: Input out of range (0 to 255)" },
@ -80,7 +82,7 @@ static void test_options(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -105,7 +107,8 @@ static void test_options(int index, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -2393,14 +2396,14 @@ static void test_encode(int index, int generate, int debug) {
char cmp_buf[32768]; char cmp_buf[32768];
char cmp_msg[1024]; char cmp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -2410,7 +2413,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, %s, %d, %d, \"%s\", %d, %s, %d, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %s, %d, %s, %d, %d, \"%s\", %d, %s, %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].eci, testUtilOutputOptionsName(data[i].output_options), i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].eci, testUtilOutputOptionsName(data[i].output_options),
data[i].option_1, data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length, data[i].option_1, data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length,
@ -2459,7 +2462,8 @@ static void test_encode(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode_segs(int index, int generate, int debug) { static void test_encode_segs(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -2658,14 +2662,14 @@ static void test_encode_segs(int index, int generate, int debug) {
char cmp_buf[32768]; char cmp_buf[32768];
char cmp_msg[1024]; char cmp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_encode_segs"); testStart("test_encode_segs");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -2677,7 +2681,7 @@ static void test_encode_segs(int index, int generate, int debug) {
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count); ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
char escaped1[4096]; char escaped1[4096];
char escaped2[4096]; char escaped2[4096];
int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length;
@ -2743,8 +2747,9 @@ static void test_encode_segs(int index, int generate, int debug) {
testFinish(); testFinish();
} }
// #181 Nico Gunkel OSS-Fuzz /* #181 Nico Gunkel OSS-Fuzz */
static void test_fuzz(int index, int debug) { static void test_fuzz(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -2754,7 +2759,7 @@ static void test_fuzz(int index, int debug) {
int option_1; int option_1;
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_AZTEC, /* 0*/ { BARCODE_AZTEC,
"\133\060\060\060\135\060\125\125\125\125\140\060\125\125\125\125\060\060\060\271\060\060\125\103\164\125\125\125\377\377\125\125" "\133\060\060\060\135\060\125\125\125\125\140\060\125\125\125\125\060\060\060\271\060\060\125\103\164\125\125\125\377\377\125\125"
@ -2828,7 +2833,7 @@ static void test_fuzz(int index, int debug) {
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
"\377\377\377\377\377\377\261\261\261\261\261\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\135\135\135\135\135\135" "\377\377\377\377\377\377\261\261\261\261\261\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\135\135\135\135\135\135"
"\135\335\135\060\060\010\010\010\010\010\060", "\135\335\135\060\060\010\010\010\010\010\060",
2251, DATA_MODE, -1, ZINT_ERROR_TOO_LONG }, // Original OSS-Fuzz triggering data for malloc leak 2251, DATA_MODE, -1, ZINT_ERROR_TOO_LONG }, /* Original OSS-Fuzz triggering data for malloc leak */
/* 1*/ { BARCODE_AZTEC, /* 1*/ { BARCODE_AZTEC,
"\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060" "\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060"
"\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\000\060\060\060\060\000\060\060\000\060\060\060\060" "\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\060\000\060\060\060\060\000\060\060\000\060\060\060\060"
@ -2918,7 +2923,7 @@ static void test_fuzz(int index, int debug) {
"\060\060\060\363\060\060\060\060\060\060\060\060\060\060\060\060\362\060\060\060\060\060\000\060\060\377\060\060\060\175\175\175" "\060\060\060\363\060\060\060\060\060\060\060\060\060\060\060\060\362\060\060\060\060\060\000\060\060\377\060\060\060\175\175\175"
"\175\060\060\060\175\175\175\175\060\060\005\060\005\060\005\060\060\060\060\000\000\060\060\060\060\060\060\377\060\060\060\060" "\175\060\060\060\175\175\175\175\060\060\005\060\005\060\005\060\060\060\060\000\000\060\060\060\060\060\060\377\060\060\060\060"
"\377\060\377\377\060\060\057\060\060\057\060\060\060\000\000\060\060", "\377\060\377\377\060\060\057\060\060\057\060\060\060\000\000\060\060",
2801, DATA_MODE, -1, ZINT_ERROR_TOO_LONG }, // Original OSS-Fuzz triggering data for binary_string buffer overrun 2801, DATA_MODE, -1, ZINT_ERROR_TOO_LONG }, /* Original OSS-Fuzz triggering data for binary_string buffer overrun */
/* 2*/ { BARCODE_AZTEC, /* 2*/ { BARCODE_AZTEC,
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
@ -2953,7 +2958,7 @@ static void test_fuzz(int index, int debug) {
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123", "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123",
4483, -1, 1, 0 }, // 4483 = (1664 (Max codewords) - 169 (ECC codewords) - 2 (overhead)) * 3 (3 4-bit digits per 12-bit wordcode) 4483, -1, 1, 0 }, /* 4483 = (1664 (Max codewords) - 169 (ECC codewords) - 2 (overhead)) * 3 (3 4-bit digits per 12-bit wordcode) */
/* 3*/ { BARCODE_AZTEC, /* 3*/ { BARCODE_AZTEC,
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
@ -3166,7 +3171,7 @@ static void test_fuzz(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -3186,8 +3191,9 @@ static void test_fuzz(int index, int debug) {
#define TEST_PERF_ITERATIONS 1000 #define TEST_PERF_ITERATIONS 1000
// Not a real test, just performance indicator /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -3254,7 +3260,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_encode = diff_buffer = 0; diff_encode = diff_buffer = 0;
@ -3285,19 +3291,19 @@ static void test_perf(int index, int debug) {
total_encode += diff_encode; total_encode += diff_encode;
total_buffer += diff_buffer; total_buffer += diff_buffer;
} }
if (index != -1) { if (p_ctx->index != -1) {
printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC); printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
} }
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_options", test_options, 1, 0, 1 }, { "test_options", test_options },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_encode_segs", test_encode_segs, 1, 1, 1 }, { "test_encode_segs", test_encode_segs },
{ "test_fuzz", test_fuzz, 1, 0, 1 }, { "test_fuzz", test_fuzz },
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -31,7 +31,8 @@
#include "testcommon.h" #include "testcommon.h"
static void test_input(int index, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -83,7 +84,7 @@ static void test_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -118,7 +119,8 @@ static void test_input(int index, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -155,7 +157,7 @@ static void test_encode(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -165,7 +167,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, %d, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, %d, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2,
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
@ -205,9 +207,9 @@ static void test_encode(int index, int generate, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_input", test_input, 1, 0, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -78,7 +78,8 @@ static int u_big5_int2(unsigned int u, unsigned int *dest) {
#define TEST_INT_PERF_ITERATIONS 100 #define TEST_INT_PERF_ITERATIONS 100
#endif #endif
static void test_u_big5_int(int debug) { static void test_u_big5_int(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
unsigned int i; unsigned int i;
int ret, ret2; int ret, ret2;
@ -168,7 +169,7 @@ static int big5_utf8(struct zint_symbol *symbol, const unsigned char source[], i
return 0; return 0;
} }
static void test_big5_utf8(int index) { static void test_big5_utf8(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -178,8 +179,10 @@ static void test_big5_utf8(int index) {
unsigned int expected_b5data[20]; unsigned int expected_b5data[20];
char *comment; char *comment;
}; };
/* _ U+FF3F fullwidth low line, not in ISO/Win, in Big5 0xA1C4, UTF-8 EFBCBF */ /*
/* ╴ U+2574 drawings box light left, not in ISO/Win, not in original Big5 but in "Big5-2003" as 0xA15A, UTF-8 E295B4 */ _ U+FF3F fullwidth low line, not in ISO/Win, in Big5 0xA1C4, UTF-8 EFBCBF
U+2574 drawings box light left, not in ISO/Win, not in original Big5 but in "Big5-2003" as 0xA15A, UTF-8 E295B4
*/
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "_", -1, 0, 1, { 0xA1C4 }, "" }, /* 0*/ { "_", -1, 0, 1, { 0xA1C4 }, "" },
@ -196,7 +199,7 @@ static void test_big5_utf8(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int ret_length; int ret_length;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret_length = length; ret_length = length;
@ -217,9 +220,9 @@ static void test_big5_utf8(int index) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_u_big5_int", test_u_big5_int, 0, 0, 1 }, { "test_u_big5_int", test_u_big5_int },
{ "test_big5_utf8", test_big5_utf8, 1, 0, 0 }, { "test_big5_utf8", test_big5_utf8 },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -34,7 +34,8 @@
INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf); INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf);
static void test_pixel_plot(int index, int debug) { static void test_pixel_plot(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int width; int width;
@ -71,7 +72,7 @@ static void test_pixel_plot(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int size; int size;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -123,7 +124,8 @@ static void test_pixel_plot(int index, int debug) {
testFinish(); testFinish();
} }
static void test_print(int index, int generate, int debug) { static void test_print(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -158,7 +160,7 @@ static void test_print(int index, int generate, int debug) {
testStart("test_print"); testStart("test_print");
if (generate) { if (p_ctx->generate) {
char data_dir_path[1024]; char data_dir_path[1024];
assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir);
if (!testUtilDirExists(data_dir_path)) { if (!testUtilDirExists(data_dir_path)) {
@ -169,7 +171,7 @@ static void test_print(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -200,7 +202,7 @@ static void test_print(int index, int generate, int debug) {
assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i); assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %s, %d, %d, %d, %d, \"%s\", \"%s\", \"%s\", \"%s\"},\n", printf(" /*%3d*/ { %s, %d, %s, %d, %d, %d, %d, \"%s\", \"%s\", \"%s\", \"%s\"},\n",
i, testUtilBarcodeName(data[i].symbology), data[i].border_width, testUtilOutputOptionsName(data[i].output_options), i, testUtilBarcodeName(data[i].symbology), data[i].border_width, testUtilOutputOptionsName(data[i].output_options),
data[i].whitespace_width, data[i].whitespace_height, data[i].whitespace_width, data[i].whitespace_height,
@ -227,11 +229,13 @@ static void test_print(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_outfile(void) { static void test_outfile(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol symbol = {0}; struct zint_symbol symbol = {0};
unsigned char data[] = { "1" }; unsigned char data[] = { "1" };
(void)p_ctx;
testStart("test_outfile"); testStart("test_outfile");
symbol.symbology = BARCODE_CODE128; symbol.symbology = BARCODE_CODE128;
@ -254,10 +258,10 @@ static void test_outfile(void) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_pixel_plot", test_pixel_plot, 1, 0, 1 }, { "test_pixel_plot", test_pixel_plot },
{ "test_print", test_print, 1, 1, 1 }, { "test_print", test_print },
{ "test_outfile", test_outfile, 0, 0, 0 }, { "test_outfile", test_outfile },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_hrt(int index, int debug) { static void test_hrt(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int option_2; int option_2;
@ -39,7 +41,7 @@ static void test_hrt(int index, int debug) {
char *expected; char *expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { -1, "1", -1, "01" }, /* 0*/ { -1, "1", -1, "01" },
/* 1*/ { 3, "1", -1, "01" }, /* 1*/ { 3, "1", -1, "01" },
@ -71,7 +73,7 @@ static void test_hrt(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -89,7 +91,8 @@ static void test_hrt(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int option_2; int option_2;
@ -98,13 +101,13 @@ static void test_input(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { -1, "0", 0, 1, 19 }, // < 3 ignored /* 0*/ { -1, "0", 0, 1, 19 }, /* < 3 ignored */
/* 1*/ { 0, "0", 0, 1, 19, }, /* 1*/ { 0, "0", 0, 1, 19, },
/* 2*/ { 1, "0", 0, 1, 19, }, /* 2*/ { 1, "0", 0, 1, 19, },
/* 3*/ { 2, "0", 0, 1, 19, }, /* 3*/ { 2, "0", 0, 1, 19, },
/* 4*/ { 9, "0", 0, 1, 19, }, // > 8 ignored /* 4*/ { 9, "0", 0, 1, 19, }, /* > 8 ignored */
/* 5*/ { -1, "00", 0, 1, 19 }, /* 5*/ { -1, "00", 0, 1, 19 },
/* 6*/ { 3, "00", 0, 1, 19 }, /* 6*/ { 3, "00", 0, 1, 19 },
/* 7*/ { -1, "26", 0, 1, 19, }, /* 7*/ { -1, "26", 0, 1, 19, },
@ -113,39 +116,39 @@ static void test_input(int index, int debug) {
/* 10*/ { 3, "000", 0, 1, 19, }, /* 10*/ { 3, "000", 0, 1, 19, },
/* 11*/ { 3, "001", 0, 1, 19, }, /* 11*/ { 3, "001", 0, 1, 19, },
/* 12*/ { 3, "026", 0, 1, 19, }, /* 12*/ { 3, "026", 0, 1, 19, },
/* 13*/ { -1, "27", 0, 1, 23 }, // Channel 4 /* 13*/ { -1, "27", 0, 1, 23 }, /* Channel 4 */
/* 14*/ { -1, "026", 0, 1, 23, }, // Defaults to channel 4 due to length /* 14*/ { -1, "026", 0, 1, 23, }, /* Defaults to channel 4 due to length */
/* 15*/ { 3, "0026", 0, 1, 19, }, /* 15*/ { 3, "0026", 0, 1, 19, },
/* 16*/ { 3, "1234", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 16*/ { 3, "1234", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 17*/ { 4, "000", 0, 1, 23 }, /* 17*/ { 4, "000", 0, 1, 23 },
/* 18*/ { -1, "000", 0, 1, 23 }, // Defaults to channel 4 due to length /* 18*/ { -1, "000", 0, 1, 23 }, /* Defaults to channel 4 due to length */
/* 19*/ { 4, "026", 0, 1, 23 }, /* 19*/ { 4, "026", 0, 1, 23 },
/* 20*/ { 4, "0000026", 0, 1, 23 }, /* 20*/ { 4, "0000026", 0, 1, 23 },
/* 21*/ { 4, "0000", 0, 1, 23 }, /* 21*/ { 4, "0000", 0, 1, 23 },
/* 22*/ { 4, "292", 0, 1, 23 }, /* 22*/ { 4, "292", 0, 1, 23 },
/* 23*/ { 4, "293", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 23*/ { 4, "293", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 24*/ { -1, "293", 0, 1, 27 }, // Channel 5 /* 24*/ { -1, "293", 0, 1, 27 }, /* Channel 5 */
/* 25*/ { 5, "0000", 0, 1, 27 }, /* 25*/ { 5, "0000", 0, 1, 27 },
/* 26*/ { -1, "0000", 0, 1, 27 }, // Defaults to channel 5 due to length /* 26*/ { -1, "0000", 0, 1, 27 }, /* Defaults to channel 5 due to length */
/* 27*/ { -1, "3493", 0, 1, 27 }, /* 27*/ { -1, "3493", 0, 1, 27 },
/* 28*/ { 5, "3493", 0, 1, 27 }, /* 28*/ { 5, "3493", 0, 1, 27 },
/* 29*/ { 5, "3494", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 29*/ { 5, "3494", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 30*/ { -1, "3494", 0, 1, 31 }, // Channel 6 /* 30*/ { -1, "3494", 0, 1, 31 }, /* Channel 6 */
/* 31*/ { 6, "00000", 0, 1, 31 }, /* 31*/ { 6, "00000", 0, 1, 31 },
/* 32*/ { -1, "00000", 0, 1, 31 }, // Defaults to channel 5 due to length /* 32*/ { -1, "00000", 0, 1, 31 }, /* Defaults to channel 5 due to length */
/* 33*/ { -1, "44072", 0, 1, 31 }, /* 33*/ { -1, "44072", 0, 1, 31 },
/* 34*/ { 6, "44072", 0, 1, 31 }, /* 34*/ { 6, "44072", 0, 1, 31 },
/* 35*/ { 6, "44073", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 35*/ { 6, "44073", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 36*/ { -1, "44073", 0, 1, 35 }, // Channel 7 /* 36*/ { -1, "44073", 0, 1, 35 }, /* Channel 7 */
/* 37*/ { 7, "000000", 0, 1, 35 }, /* 37*/ { 7, "000000", 0, 1, 35 },
/* 38*/ { -1, "000000", 0, 1, 35 }, // Defaults to channel 7 due to length /* 38*/ { -1, "000000", 0, 1, 35 }, /* Defaults to channel 7 due to length */
/* 39*/ { 7, "576688", 0, 1, 35 }, /* 39*/ { 7, "576688", 0, 1, 35 },
/* 40*/ { 7, "576689", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 40*/ { 7, "576689", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 41*/ { 7, "0576688", 0, 1, 35 }, /* 41*/ { 7, "0576688", 0, 1, 35 },
/* 42*/ { -1, "1234567", 0, 1, 39 }, /* 42*/ { -1, "1234567", 0, 1, 39 },
/* 43*/ { -1, "576689", 0, 1, 39 }, // Channel 8 /* 43*/ { -1, "576689", 0, 1, 39 }, /* Channel 8 */
/* 44*/ { 8, "0000000", 0, 1, 39, }, /* 44*/ { 8, "0000000", 0, 1, 39, },
/* 45*/ { -1, "0000000", 0, 1, 39, }, // Defaults to channel 8 due to length /* 45*/ { -1, "0000000", 0, 1, 39, }, /* Defaults to channel 8 due to length */
/* 46*/ { 8, "1234567", 0, 1, 39, }, /* 46*/ { 8, "1234567", 0, 1, 39, },
/* 47*/ { 8, "7742863", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 47*/ { 8, "7742863", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 48*/ { 8, "01234567", ZINT_ERROR_TOO_LONG, -1, -1 }, /* 48*/ { 8, "01234567", ZINT_ERROR_TOO_LONG, -1, -1 },
@ -161,7 +164,7 @@ static void test_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -182,9 +185,10 @@ static void test_input(int index, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
struct item { struct item {
int option_2; int option_2;
@ -420,7 +424,7 @@ static void test_encode(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -430,7 +434,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %d, \"%s\", %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %d, \"%s\", %s, %d, %d, \"%s\",\n",
i, data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
@ -463,8 +467,8 @@ static void test_encode(int index, int generate, int debug) {
testFinish(); testFinish();
} }
// Dummy to generate pre-calculated tables for channels 7/8 /* Dummy to generate pre-calculated tables for channels 7/8 */
static void test_generate(int generate) { static void test_generate(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -474,7 +478,7 @@ static void test_generate(int generate) {
int i, length, ret; int i, length, ret;
struct zint_symbol *symbol; struct zint_symbol *symbol;
if (!generate) { if (!p_ctx->generate) {
return; return;
} }
@ -493,11 +497,11 @@ static void test_generate(int generate) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_hrt", test_hrt, 1, 0, 1 }, { "test_hrt", test_hrt },
{ "test_input", test_input, 1, 0, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_generate", test_generate, 0, 1, 0 }, { "test_generate", test_generate },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int option_1; int option_1;
@ -41,25 +43,27 @@ static void test_large(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// é U+00E9 (\351, 233), UTF-8 C3A9, CodeB-only extended ASCII /*
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) é U+00E9 (\351, 233), UTF-8 C3A9, CodeB-only extended ASCII
*/
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { -1, -1, "A", 2666, 0, 44, 728 }, /* 0*/ { -1, -1, "A", 2666, 0, 44, 728 },
/* 1*/ { -1, -1, "A", 2725, 0, 44, 739 }, /* 1*/ { -1, -1, "A", 2725, 0, 44, 739 },
/* 2*/ { -1, -1, "A", 2726, 0, 44, 739 }, // 4.2.1 c.3 says max 2725 but actually 44 * 62 - 2 == 2726 as mentioned later in 4.8.1 /* 2*/ { -1, -1, "A", 2726, 0, 44, 739 }, /* 4.2.1 c.3 says max 2725 but actually 44 * 62 - 2 == 2726 as mentioned later in 4.8.1 */
/* 3*/ { -1, -1, "A", 2727, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 3*/ { -1, -1, "A", 2727, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 4*/ { -1, -1, "A", ZINT_MAX_DATA_LEN, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 4*/ { -1, -1, "A", ZINT_MAX_DATA_LEN, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 5*/ { -1, -1, "12", 2726 * 2, 0, 44, 739 }, /* 5*/ { -1, -1, "12", 2726 * 2, 0, 44, 739 },
/* 6*/ { -1, -1, "12", 2726 * 2 + 1, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 6*/ { -1, -1, "12", 2726 * 2 + 1, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 7*/ { -1, -1, "\351", 2726 / 2, 0, 44, 739 }, /* 7*/ { -1, -1, "\351", 2726 / 2, 0, 44, 739 },
/* 8*/ { -1, -1, "\351", 2726 / 2 + 1, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 8*/ { -1, -1, "\351", 2726 / 2 + 1, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 9*/ { 1, -1, "A", 60, 0, 1, 695 }, // CODE128 60 max /* 9*/ { 1, -1, "A", 60, 0, 1, 695 }, /* CODE128 60 max */
/* 10*/ { 1, -1, "A", 61, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 10*/ { 1, -1, "A", 61, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 11*/ { 2, -1, "A", 122, 0, 2, 739 }, /* 11*/ { 2, -1, "A", 122, 0, 2, 739 },
/* 12*/ { 2, 10, "A", 122, 0, 2, 739 }, // Cols 10 -> 67 /* 12*/ { 2, 10, "A", 122, 0, 2, 739 }, /* Cols 10 -> 67 */
/* 13*/ { 2, 67, "A", 122, 0, 2, 739 }, /* 13*/ { 2, 67, "A", 122, 0, 2, 739 },
/* 14*/ { 2, -1, "A", 123, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 14*/ { 2, -1, "A", 123, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 15*/ { 2, -1, "A", 63 * 2, ZINT_ERROR_TOO_LONG, -1, -1 }, // Triggers initial testColumns > 62 /* 15*/ { 2, -1, "A", 63 * 2, ZINT_ERROR_TOO_LONG, -1, -1 }, /* Triggers initial testColumns > 62 */
/* 16*/ { 2, -1, "A", 2726 * 2 + 1, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 16*/ { 2, -1, "A", 2726 * 2 + 1, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 17*/ { 2, 9, "A", 2726 * 2 + 1, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 17*/ { 2, 9, "A", 2726 * 2 + 1, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 18*/ { 3, -1, "A", 184, 0, 3, 739 }, /* 18*/ { 3, -1, "A", 184, 0, 3, 739 },
@ -76,7 +80,7 @@ static void test_large(int index, int debug) {
/* 29*/ { 43, -1, "A", 2665, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 29*/ { 43, -1, "A", 2665, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 30*/ { 44, -1, "A", 2726, 0, 44, 739 }, /* 30*/ { 44, -1, "A", 2726, 0, 44, 739 },
/* 31*/ { 44, -1, "A", 2727, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 31*/ { 44, -1, "A", 2727, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 32*/ { 44, 60, "A", 2726, 0, 44, 739 }, // Cols 60 -> 67 /* 32*/ { 44, 60, "A", 2726, 0, 44, 739 }, /* Cols 60 -> 67 */
/* 33*/ { 44, 67, "A", 2726, 0, 44, 739 }, /* 33*/ { 44, 67, "A", 2726, 0, 44, 739 },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -89,7 +93,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -113,7 +117,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_options(int index, int debug) { static void test_options(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -125,7 +130,7 @@ static void test_options(int index, int debug) {
int expected_width; int expected_width;
char *comment; char *comment;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { UNICODE_MODE, 1, -1, "é", 0, 1, 57, "CODE128" }, /* 0*/ { UNICODE_MODE, 1, -1, "é", 0, 1, 57, "CODE128" },
/* 1*/ { UNICODE_MODE, -1, -1, "A", 0, 2, 101, "Defaults" }, /* 1*/ { UNICODE_MODE, -1, -1, "A", 0, 2, 101, "Defaults" },
@ -160,7 +165,7 @@ static void test_options(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -181,7 +186,8 @@ static void test_options(int index, int debug) {
testFinish(); testFinish();
} }
static void test_reader_init(int index, int generate, int debug) { static void test_reader_init(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -209,19 +215,19 @@ static void test_reader_init(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug); length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options), i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
@ -240,7 +246,8 @@ static void test_reader_init(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int generate, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -254,19 +261,21 @@ static void test_input(int index, int generate, int debug) {
char *expected; char *expected;
char *comment; char *comment;
}; };
// NUL U+0000, CodeA-only /*
// US U+001F (\037, 31), CodeA-only NUL U+0000, CodeA-only
// a U+0061 (\141, 97), CodeB-only US U+001F (\037, 31), CodeA-only
// DEL U+007F (\177, 127), CodeB-only a U+0061 (\141, 97), CodeB-only
// PAD U+0080 (\200, 128), UTF-8 C280 (\302\200), CodeA-only extended ASCII, not in ISO 8859-1 DEL U+007F (\177, 127), CodeB-only
// APC U+009F (\237, 159), UTF-8 C29F, CodeA-only extended ASCII, not in ISO 8859-1 PAD U+0080 (\200, 128), UTF-8 C280 (\302\200), CodeA-only extended ASCII, not in ISO 8859-1
// NBSP U+00A0 (\240, 160), UTF-8 C2A0, CodeA and CodeB extended ASCII APC U+009F (\237, 159), UTF-8 C29F, CodeA-only extended ASCII, not in ISO 8859-1
// ß U+00DF (\337, 223), UTF-8 C39F, CodeA and CodeB extended ASCII NBSP U+00A0 (\240, 160), UTF-8 C2A0, CodeA and CodeB extended ASCII
// à U+00E0 (\340, 224), UTF-8 C3A0, CodeB-only extended ASCII ß U+00DF (\337, 223), UTF-8 C39F, CodeA and CodeB extended ASCII
// á U+00E1 (\341, 225), UTF-8 C3A1, CodeB-only extended ASCII à U+00E0 (\340, 224), UTF-8 C3A0, CodeB-only extended ASCII
// é U+00E9 (\351, 233), UTF-8 C3A9, CodeB-only extended ASCII á U+00E1 (\341, 225), UTF-8 C3A1, CodeB-only extended ASCII
// ñ U+00F1 (\361, 241), UTF-8 C3B1, CodeB-only extended ASCII é U+00E9 (\351, 233), UTF-8 C3A9, CodeB-only extended ASCII
// ÿ U+00FF (\377, 255), UTF-8 C3BF, CodeB-only extended ASCII ñ U+00F1 (\361, 241), UTF-8 C3B1, CodeB-only extended ASCII
ÿ U+00FF (\377, 255), UTF-8 C3BF, CodeB-only extended ASCII
*/
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_CODABLOCKF, UNICODE_MODE, -1, "A", -1, 0, 2, 101, "67 64 40 21 63 64 63 42 6A 67 64 0B 63 64 2B 40 4F 6A", "Fillings 5" }, /* 0*/ { BARCODE_CODABLOCKF, UNICODE_MODE, -1, "A", -1, 0, 2, 101, "67 64 40 21 63 64 63 42 6A 67 64 0B 63 64 2B 40 4F 6A", "Fillings 5" },
/* 1*/ { BARCODE_CODABLOCKF, UNICODE_MODE, -1, "AAA", -1, 0, 2, 101, "67 64 40 21 21 21 63 55 6A 67 64 0B 63 64 0E 57 48 6A", "Fillings 3" }, /* 1*/ { BARCODE_CODABLOCKF, UNICODE_MODE, -1, "AAA", -1, 0, 2, 101, "67 64 40 21 21 21 63 55 6A 67 64 0B 63 64 0E 57 48 6A", "Fillings 3" },
@ -318,19 +327,19 @@ static void test_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, \"%s\", %d, %s, %d, %d, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %s, %d, \"%s\", %d, %s, %d, %d, \"%s\", \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].option_2, i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].option_2,
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length,
@ -349,7 +358,8 @@ static void test_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -460,13 +470,13 @@ static void test_encode(int index, int generate, int debug) {
char bwipp_buf[8192]; char bwipp_buf[8192];
char bwipp_msg[1024]; char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -476,7 +486,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, %d, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), data[i].option_1, data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, testUtilBarcodeName(data[i].symbology), data[i].option_1, data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment); testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment);
@ -513,15 +523,16 @@ static void test_encode(int index, int generate, int debug) {
testFinish(); testFinish();
} }
// #181 Christian Hartlage OSS-Fuzz /* #181 Christian Hartlage OSS-Fuzz */
static void test_fuzz(int index, int debug) { static void test_fuzz(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
int length; int length;
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "\034\034I", 3, 0 }, /* 0*/ { "\034\034I", 3, 0 },
}; };
@ -533,7 +544,7 @@ static void test_fuzz(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -551,13 +562,13 @@ static void test_fuzz(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_options", test_options, 1, 0, 1 }, { "test_options", test_options },
{ "test_reader_init", test_reader_init, 1, 1, 1 }, { "test_reader_init", test_reader_init },
{ "test_input", test_input, 1, 1, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_fuzz", test_fuzz, 1, 0, 1 }, { "test_fuzz", test_fuzz },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -41,22 +43,22 @@ static void test_large(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_CODE11, -1, "1", 121, 0, 1, 999 }, // 8 (Start) + 121*8 + 2*8 (Checks) + 7 (Stop) == 999 /* 0*/ { BARCODE_CODE11, -1, "1", 121, 0, 1, 999 }, /* 8 (Start) + 121*8 + 2*8 (Checks) + 7 (Stop) == 999 */
/* 1*/ { BARCODE_CODE11, -1, "1", 122, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 1*/ { BARCODE_CODE11, -1, "1", 122, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 2*/ { BARCODE_CODE39, -1, "1", 85, 0, 1, 1130 }, // 13 (Start) + 85*13 + 12 (Stop) == 1130 /* 2*/ { BARCODE_CODE39, -1, "1", 85, 0, 1, 1130 }, /* 13 (Start) + 85*13 + 12 (Stop) == 1130 */
/* 3*/ { BARCODE_CODE39, -1, "1", 86, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 3*/ { BARCODE_CODE39, -1, "1", 86, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 4*/ { BARCODE_EXCODE39, -1, "1", 85, 0, 1, 1130 }, /* 4*/ { BARCODE_EXCODE39, -1, "1", 85, 0, 1, 1130 },
/* 5*/ { BARCODE_EXCODE39, -1, "1", 86, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 5*/ { BARCODE_EXCODE39, -1, "1", 86, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 6*/ { BARCODE_EXCODE39, -1, "a", 42, 0, 1, 1117 }, // Takes 2 encoding chars per char /* 6*/ { BARCODE_EXCODE39, -1, "a", 42, 0, 1, 1117 }, /* Takes 2 encoding chars per char */
/* 7*/ { BARCODE_EXCODE39, -1, "a", 43, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 7*/ { BARCODE_EXCODE39, -1, "a", 43, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 8*/ { BARCODE_EXCODE39, -1, "a", 85, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 8*/ { BARCODE_EXCODE39, -1, "a", 85, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 9*/ { BARCODE_LOGMARS, -1, "1", 30, 0, 1, 511 }, // 16 (Start) + 30*16 + 15 (Stop) == 511 /* 9*/ { BARCODE_LOGMARS, -1, "1", 30, 0, 1, 511 }, /* 16 (Start) + 30*16 + 15 (Stop) == 511 */
/* 10*/ { BARCODE_LOGMARS, -1, "1", 31, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 10*/ { BARCODE_LOGMARS, -1, "1", 31, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 11*/ { BARCODE_CODE93, -1, "1", 107, 0, 1, 1000 }, // 9 (Start) + 107*9 + 2*9 (Checks) + 10 (Stop) == 1000 /* 11*/ { BARCODE_CODE93, -1, "1", 107, 0, 1, 1000 }, /* 9 (Start) + 107*9 + 2*9 (Checks) + 10 (Stop) == 1000 */
/* 12*/ { BARCODE_CODE93, -1, "1", 108, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 12*/ { BARCODE_CODE93, -1, "1", 108, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 13*/ { BARCODE_CODE93, -1, "a", 53, 0, 1, 991 }, // Takes 2 encoding chars per char /* 13*/ { BARCODE_CODE93, -1, "a", 53, 0, 1, 991 }, /* Takes 2 encoding chars per char */
/* 14*/ { BARCODE_CODE93, -1, "a", 54, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 14*/ { BARCODE_CODE93, -1, "a", 54, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 15*/ { BARCODE_CODE93, -1, "a", 107, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 15*/ { BARCODE_CODE93, -1, "a", 107, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 16*/ { BARCODE_PZN, -1, "1", 7, 0, 1, 142 }, /* 16*/ { BARCODE_PZN, -1, "1", 7, 0, 1, 142 },
@ -65,7 +67,7 @@ static void test_large(int index, int debug) {
/* 19*/ { BARCODE_VIN, -1, "1", 18, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 19*/ { BARCODE_VIN, -1, "1", 18, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 20*/ { BARCODE_VIN, -1, "1", 16, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 20*/ { BARCODE_VIN, -1, "1", 16, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 21*/ { BARCODE_VIN, 1, "1", 17, 0, 1, 259 }, /* 21*/ { BARCODE_VIN, 1, "1", 17, 0, 1, 259 },
/* 22*/ { BARCODE_HIBC_39, -1, "1", 67, 0, 1, 1135 }, // 69 - 2 ('+' and check digit) /* 22*/ { BARCODE_HIBC_39, -1, "1", 67, 0, 1, 1135 }, /* 69 - 2 ('+' and check digit) */
/* 23*/ { BARCODE_HIBC_39, -1, "1", 68, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 23*/ { BARCODE_HIBC_39, -1, "1", 68, ZINT_ERROR_TOO_LONG, -1, -1 },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -78,7 +80,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -102,7 +104,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_hrt(int index, int debug) { static void test_hrt(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -112,36 +115,36 @@ static void test_hrt(int index, int debug) {
char *expected; char *expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_CODE11, -1, "123-45", -1, "123-4552" }, // 2 checksums /* 0*/ { BARCODE_CODE11, -1, "123-45", -1, "123-4552" }, /* 2 checksums */
/* 1*/ { BARCODE_CODE11, 1, "123-45", -1, "123-455" }, // 1 check digit /* 1*/ { BARCODE_CODE11, 1, "123-45", -1, "123-455" }, /* 1 check digit */
/* 2*/ { BARCODE_CODE11, 2, "123-45", -1, "123-45" }, // No checksums /* 2*/ { BARCODE_CODE11, 2, "123-45", -1, "123-45" }, /* No checksums */
/* 3*/ { BARCODE_CODE11, -1, "123456789012", -1, "123456789012-8" }, // First check digit 10 (A) goes to hyphen /* 3*/ { BARCODE_CODE11, -1, "123456789012", -1, "123456789012-8" }, /* First check digit 10 (A) goes to hyphen */
/* 4*/ { BARCODE_CODE39, -1, "ABC1234", -1, "*ABC1234*" }, /* 4*/ { BARCODE_CODE39, -1, "ABC1234", -1, "*ABC1234*" },
/* 5*/ { BARCODE_CODE39, -1, "abc1234", -1, "*ABC1234*" }, // Converts to upper /* 5*/ { BARCODE_CODE39, -1, "abc1234", -1, "*ABC1234*" }, /* Converts to upper */
/* 6*/ { BARCODE_CODE39, -1, "123456789", -1, "*123456789*" }, /* 6*/ { BARCODE_CODE39, -1, "123456789", -1, "*123456789*" },
/* 7*/ { BARCODE_CODE39, 1, "123456789", -1, "*1234567892*" }, // With check digit /* 7*/ { BARCODE_CODE39, 1, "123456789", -1, "*1234567892*" }, /* With check digit */
/* 8*/ { BARCODE_EXCODE39, -1, "ABC1234", -1, "ABC1234" }, /* 8*/ { BARCODE_EXCODE39, -1, "ABC1234", -1, "ABC1234" },
/* 9*/ { BARCODE_EXCODE39, -1, "abc1234", -1, "abc1234" }, /* 9*/ { BARCODE_EXCODE39, -1, "abc1234", -1, "abc1234" },
/* 10*/ { BARCODE_EXCODE39, 1, "abc1234", -1, "abc1234" }, // With check digit (not displayed) /* 10*/ { BARCODE_EXCODE39, 1, "abc1234", -1, "abc1234" }, /* With check digit (not displayed) */
/* 11*/ { BARCODE_EXCODE39, -1, "a%\000\001$\177z\033\037!+/\\@A~", 16, "a% $ z !+/\\@A~" }, // NUL, ctrls and DEL replaced with spaces /* 11*/ { BARCODE_EXCODE39, -1, "a%\000\001$\177z\033\037!+/\\@A~", 16, "a% $ z !+/\\@A~" }, /* NUL, ctrls and DEL replaced with spaces */
/* 12*/ { BARCODE_LOGMARS, -1, "ABC1234", -1, "ABC1234" }, /* 12*/ { BARCODE_LOGMARS, -1, "ABC1234", -1, "ABC1234" },
/* 13*/ { BARCODE_LOGMARS, -1, "abc1234", -1, "ABC1234" }, // Converts to upper /* 13*/ { BARCODE_LOGMARS, -1, "abc1234", -1, "ABC1234" }, /* Converts to upper */
/* 14*/ { BARCODE_LOGMARS, 1, "abc1234", -1, "ABC12340" }, // With check digit /* 14*/ { BARCODE_LOGMARS, 1, "abc1234", -1, "ABC12340" }, /* With check digit */
/* 15*/ { BARCODE_LOGMARS, 1, "12345/ABCDE", -1, "12345/ABCDET" }, // With check digit /* 15*/ { BARCODE_LOGMARS, 1, "12345/ABCDE", -1, "12345/ABCDET" }, /* With check digit */
/* 16*/ { BARCODE_CODE93, -1, "ABC1234", -1, "ABC1234" }, // No longer shows 2 check chars added (same as BWIPP and TEC-IT) /* 16*/ { BARCODE_CODE93, -1, "ABC1234", -1, "ABC1234" }, /* No longer shows 2 check chars added (same as BWIPP and TEC-IT) */
/* 17*/ { BARCODE_CODE93, 1, "ABC1234", -1, "ABC1234S5" }, // Unless requested /* 17*/ { BARCODE_CODE93, 1, "ABC1234", -1, "ABC1234S5" }, /* Unless requested */
/* 18*/ { BARCODE_CODE93, -1, "abc1234", -1, "abc1234" }, /* 18*/ { BARCODE_CODE93, -1, "abc1234", -1, "abc1234" },
/* 19*/ { BARCODE_CODE93, 1, "abc1234", -1, "abc1234ZG" }, /* 19*/ { BARCODE_CODE93, 1, "abc1234", -1, "abc1234ZG" },
/* 20*/ { BARCODE_CODE93, -1, "A\001a\000b\177d\037e", 9, "A a b d e" }, // NUL, ctrls and DEL replaced with spaces /* 20*/ { BARCODE_CODE93, -1, "A\001a\000b\177d\037e", 9, "A a b d e" }, /* NUL, ctrls and DEL replaced with spaces */
/* 21*/ { BARCODE_PZN, -1, "12345", -1, "PZN -00123458" }, // Pads with zeroes if length < 7 /* 21*/ { BARCODE_PZN, -1, "12345", -1, "PZN -00123458" }, /* Pads with zeroes if length < 7 */
/* 22*/ { BARCODE_PZN, -1, "123456", -1, "PZN -01234562" }, /* 22*/ { BARCODE_PZN, -1, "123456", -1, "PZN -01234562" },
/* 23*/ { BARCODE_PZN, -1, "1234567", -1, "PZN -12345678" }, /* 23*/ { BARCODE_PZN, -1, "1234567", -1, "PZN -12345678" },
/* 24*/ { BARCODE_VIN, -1, "1FTCR10UXTPA78180", -1, "1FTCR10UXTPA78180" }, /* 24*/ { BARCODE_VIN, -1, "1FTCR10UXTPA78180", -1, "1FTCR10UXTPA78180" },
/* 25*/ { BARCODE_VIN, 1, "2FTPX28L0XCA15511", -1, "2FTPX28L0XCA15511" }, // Include Import char - no change /* 25*/ { BARCODE_VIN, 1, "2FTPX28L0XCA15511", -1, "2FTPX28L0XCA15511" }, /* Include Import char - no change */
/* 26*/ { BARCODE_HIBC_39, -1, "ABC1234", -1, "*+ABC1234+*" }, /* 26*/ { BARCODE_HIBC_39, -1, "ABC1234", -1, "*+ABC1234+*" },
/* 27*/ { BARCODE_HIBC_39, -1, "abc1234", -1, "*+ABC1234+*" }, // Converts to upper /* 27*/ { BARCODE_HIBC_39, -1, "abc1234", -1, "*+ABC1234+*" }, /* Converts to upper */
/* 28*/ { BARCODE_HIBC_39, -1, "123456789", -1, "*+1234567890*" }, /* 28*/ { BARCODE_HIBC_39, -1, "123456789", -1, "*+1234567890*" },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -152,7 +155,7 @@ static void test_hrt(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -170,7 +173,8 @@ static void test_hrt(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -181,7 +185,7 @@ static void test_input(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_CODE11, -1, "-", -1, 0, 1, 37 }, /* 0*/ { BARCODE_CODE11, -1, "-", -1, 0, 1, 37 },
/* 1*/ { BARCODE_CODE11, -1, "0123456789-", -1, 0, 1, 115 }, /* 1*/ { BARCODE_CODE11, -1, "0123456789-", -1, 0, 1, 115 },
@ -191,7 +195,7 @@ static void test_input(int index, int debug) {
/* 5*/ { BARCODE_CODE11, -1, "12!", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 5*/ { BARCODE_CODE11, -1, "12!", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 6*/ { BARCODE_CODE11, -1, " ", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 6*/ { BARCODE_CODE11, -1, " ", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 7*/ { BARCODE_CODE11, 3, "1", -1, ZINT_ERROR_INVALID_OPTION, -1, -1 }, /* 7*/ { BARCODE_CODE11, 3, "1", -1, ZINT_ERROR_INVALID_OPTION, -1, -1 },
/* 8*/ { BARCODE_CODE39, -1, "a", -1, 0, 1, 38 }, // Converts to upper /* 8*/ { BARCODE_CODE39, -1, "a", -1, 0, 1, 38 }, /* Converts to upper */
/* 9*/ { BARCODE_CODE39, -1, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%", -1, 0, 1, 584 }, /* 9*/ { BARCODE_CODE39, -1, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%", -1, 0, 1, 584 },
/* 10*/ { BARCODE_CODE39, -1, "AB!", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 10*/ { BARCODE_CODE39, -1, "AB!", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 11*/ { BARCODE_CODE39, -1, "A\"B", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 11*/ { BARCODE_CODE39, -1, "A\"B", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
@ -210,8 +214,8 @@ static void test_input(int index, int debug) {
/* 24*/ { BARCODE_CODE39, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 24*/ { BARCODE_CODE39, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 25*/ { BARCODE_CODE39, -1, "\300", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 25*/ { BARCODE_CODE39, -1, "\300", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 26*/ { BARCODE_CODE39, 0, "1", -1, 0, 1, 38 }, /* 26*/ { BARCODE_CODE39, 0, "1", -1, 0, 1, 38 },
/* 27*/ { BARCODE_CODE39, 1, "1", -1, 0, 1, 51 }, // Check digit /* 27*/ { BARCODE_CODE39, 1, "1", -1, 0, 1, 51 }, /* Check digit */
/* 28*/ { BARCODE_CODE39, 2, "1", -1, 0, 1, 38 }, // option_2 > 1 gnored /* 28*/ { BARCODE_CODE39, 2, "1", -1, 0, 1, 38 }, /* option_2 > 1 gnored */
/* 29*/ { BARCODE_EXCODE39, -1, "A", -1, 0, 1, 38 }, /* 29*/ { BARCODE_EXCODE39, -1, "A", -1, 0, 1, 38 },
/* 30*/ { BARCODE_EXCODE39, -1, "a", -1, 0, 1, 51 }, /* 30*/ { BARCODE_EXCODE39, -1, "a", -1, 0, 1, 51 },
/* 31*/ { BARCODE_EXCODE39, -1, ",", -1, 0, 1, 51 }, /* 31*/ { BARCODE_EXCODE39, -1, ",", -1, 0, 1, 51 },
@ -231,14 +235,14 @@ static void test_input(int index, int debug) {
/* 45*/ { BARCODE_CODE93, -1, "é", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 45*/ { BARCODE_CODE93, -1, "é", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 46*/ { BARCODE_PZN, -1, "1", -1, 0, 1, 142 }, /* 46*/ { BARCODE_PZN, -1, "1", -1, 0, 1, 142 },
/* 47*/ { BARCODE_PZN, -1, "A", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 47*/ { BARCODE_PZN, -1, "A", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 48*/ { BARCODE_PZN, -1, "1000006", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, // Check digit == 10 so can't be used /* 48*/ { BARCODE_PZN, -1, "1000006", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* Check digit == 10 so can't be used */
/* 49*/ { BARCODE_VIN, -1, "5GZCZ43D13S812715", -1, 0, 1, 246 }, /* 49*/ { BARCODE_VIN, -1, "5GZCZ43D13S812715", -1, 0, 1, 246 },
/* 50*/ { BARCODE_VIN, -1, "5GZCZ43D23S812715", -1, ZINT_ERROR_INVALID_CHECK, -1, -1 }, // North American with invalid check character /* 50*/ { BARCODE_VIN, -1, "5GZCZ43D23S812715", -1, ZINT_ERROR_INVALID_CHECK, -1, -1 }, /* North American with invalid check character */
/* 51*/ { BARCODE_VIN, -1, "WP0ZZZ99ZTS392124", -1, 0, 1, 246 }, // Not North American so no check /* 51*/ { BARCODE_VIN, -1, "WP0ZZZ99ZTS392124", -1, 0, 1, 246 }, /* Not North American so no check */
/* 52*/ { BARCODE_VIN, -1, "WP0ZZZ99ZTS392I24", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, // I not allowed /* 52*/ { BARCODE_VIN, -1, "WP0ZZZ99ZTS392I24", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* I not allowed */
/* 53*/ { BARCODE_VIN, -1, "WPOZZZ99ZTS392124", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, // O not allowed /* 53*/ { BARCODE_VIN, -1, "WPOZZZ99ZTS392124", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* O not allowed */
/* 54*/ { BARCODE_VIN, -1, "WPQZZZ99ZTS392124", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, // Q not allowed /* 54*/ { BARCODE_VIN, -1, "WPQZZZ99ZTS392124", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* Q not allowed */
/* 55*/ { BARCODE_HIBC_39, -1, "a", -1, 0, 1, 79 }, // Converts to upper /* 55*/ { BARCODE_HIBC_39, -1, "a", -1, 0, 1, 79 }, /* Converts to upper */
/* 56*/ { BARCODE_HIBC_39, -1, ",", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 56*/ { BARCODE_HIBC_39, -1, ",", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 57*/ { BARCODE_HIBC_39, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 57*/ { BARCODE_HIBC_39, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 58*/ { BARCODE_HIBC_39, -1, "\300", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 58*/ { BARCODE_HIBC_39, -1, "\300", -1, ZINT_ERROR_INVALID_DATA, -1, -1 },
@ -251,7 +255,7 @@ static void test_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -272,7 +276,8 @@ static void test_input(int index, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -422,14 +427,14 @@ static void test_encode(int index, int generate, int debug) {
char cmp_buf[8192]; char cmp_buf[8192];
char cmp_msg[1024]; char cmp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -439,7 +444,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, \"%s\", %d, %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, \"%s\", %d, %s, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length, i, testUtilBarcodeName(data[i].symbology), data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length,
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
@ -489,8 +494,9 @@ static void test_encode(int index, int generate, int debug) {
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000) #define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
#define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC) #define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC)
// Not a real test, just performance indicator /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -532,7 +538,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0; diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
@ -562,7 +568,7 @@ static void test_perf(int index, int debug) {
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/); ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start; diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt); assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; // Undo symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock(); start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/); ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
@ -582,7 +588,7 @@ static void test_perf(int index, int debug) {
total_buf_inter += diff_buf_inter; total_buf_inter += diff_buf_inter;
total_print += diff_print; total_print += diff_print;
} }
if (index == -1) { if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals", printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create)); TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
} }
@ -590,12 +596,12 @@ static void test_perf(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_hrt", test_hrt, 1, 0, 1 }, { "test_hrt", test_hrt },
{ "test_input", test_input, 1, 0, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int eci; int eci;
@ -42,8 +44,8 @@ static void test_large(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// Reference AIM USS Code One Table 2 /* Reference AIM USS Code One Table 2 */
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { -1, -1, { 0, 0, "" }, "1", 3550, 0, 148, 134 }, /* Auto Version H */ /* 0*/ { -1, -1, { 0, 0, "" }, "1", 3550, 0, 148, 134 }, /* Auto Version H */
/* 1*/ { -1, -1, { 0, 0, "" }, "1", 3551, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 1*/ { -1, -1, { 0, 0, "" }, "1", 3551, ZINT_ERROR_TOO_LONG, -1, -1 },
@ -196,8 +198,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -224,7 +225,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -238,7 +240,7 @@ static void test_input(int index, int debug) {
int expected_width; int expected_width;
const char *expected_errtxt; const char *expected_errtxt;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { -1, -1, -1, { 0, 0, "" }, "123456789012ABCDEFGHI", -1, 0, 22, 22, "", }, /* 0*/ { -1, -1, -1, { 0, 0, "" }, "123456789012ABCDEFGHI", -1, 0, 22, 22, "", },
/* 1*/ { -1, -1, -1, { 0, 0, "" }, "123456789012ABCDEFGHIJ", -1, 0, 22, 22, "", }, /* 1*/ { -1, -1, -1, { 0, 0, "" }, "123456789012ABCDEFGHIJ", -1, 0, 22, 22, "", },
@ -276,7 +278,7 @@ static void test_input(int index, int debug) {
/* 33*/ { -1, -1, -1, { 3, 2, "" }, "123456789012ABCDEFGHI", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 712: Structured Append index out of range (1-2)", }, /* 33*/ { -1, -1, -1, { 3, 2, "" }, "123456789012ABCDEFGHI", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 712: Structured Append index out of range (1-2)", },
/* 34*/ { -1, -1, -1, { 1, 2, "1" }, "123456789012ABCDEFGHI", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 713: Structured Append ID not available for Code One", }, /* 34*/ { -1, -1, -1, { 1, 2, "1" }, "123456789012ABCDEFGHI", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 713: Structured Append ID not available for Code One", },
/* 35*/ { -1, -1, 9, { 1, 2, "" }, "123456789012ABCDEFGHI", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 714: Structured Append not available for Version S", }, /* 35*/ { -1, -1, 9, { 1, 2, "" }, "123456789012ABCDEFGHI", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 714: Structured Append not available for Version S", },
/* 36*/ { -1, -1, 9, { 3, 2, "" }, "123456789012ABCDEFGHI", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 714: Structured Append not available for Version S", }, // Trumps other checking /* 36*/ { -1, -1, 9, { 3, 2, "" }, "123456789012ABCDEFGHI", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 714: Structured Append not available for Version S", }, /* Trumps other checking */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -286,8 +288,7 @@ static void test_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -312,7 +313,8 @@ static void test_input(int index, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -329,7 +331,7 @@ static void test_encode(int index, int generate, int debug) {
char *comment; char *comment;
char *expected; char *expected;
}; };
// Figure examples AIM USS Code One (USSCO) Revision March 3, 2000 /* Figure examples AIM USS Code One (USSCO) Revision March 3, 2000 */
struct item data[] = { struct item data[] = {
/* 0*/ { -1, -1, -1, { 0, 0, "" }, "1234567890123456789012", -1, 0, 16, 18, 1, "USSCO Figure 1 (Version A, no padding), same", /* 0*/ { -1, -1, -1, { 0, 0, "" }, "1234567890123456789012", -1, 0, 16, 18, 1, "USSCO Figure 1 (Version A, no padding), same",
"111111111111001100" "111111111111001100"
@ -2883,14 +2885,13 @@ static void test_encode(int index, int generate, int debug) {
char bwipp_buf[32768]; char bwipp_buf[32768];
char bwipp_msg[1024]; char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -2903,7 +2904,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, { %d, %d, \"%s\" }, \"%s\", %d, %s, %d, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, %d, { %d, %d, \"%s\" }, \"%s\", %d, %s, %d, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_2, i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_2,
data[i].structapp.index, data[i].structapp.count, data[i].structapp.id, data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
@ -2949,7 +2950,8 @@ static void test_encode(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode_segs(int index, int generate, int debug) { static void test_encode_segs(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -2964,7 +2966,7 @@ static void test_encode_segs(int index, int generate, int debug) {
char *comment; char *comment;
char *expected; char *expected;
}; };
// Figure examples AIM USS Code One (USSCO) Revision March 3, 2000 /* Figure examples AIM USS Code One (USSCO) Revision March 3, 2000 */
struct item data[] = { struct item data[] = {
/* 0*/ { UNICODE_MODE, -1, { 0, 0, "" }, { { TU(""), -1, 0 }, { TU("Ж"), -1, 7 }, { TU(""), 0, 0 } }, 0, 16, 18, 1, "Standard example", /* 0*/ { UNICODE_MODE, -1, { 0, 0, "" }, { { TU(""), -1, 0 }, { TU("Ж"), -1, 7 }, { TU(""), 0, 0 } }, 0, 16, 18, 1, "Standard example",
"100011010111100011" "100011010111100011"
@ -3272,14 +3274,13 @@ static void test_encode_segs(int index, int generate, int debug) {
char bwipp_buf[32768]; char bwipp_buf[32768];
char bwipp_msg[1024]; char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_encode_segs"); testStart("test_encode_segs");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -3295,7 +3296,7 @@ static void test_encode_segs(int index, int generate, int debug) {
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count); ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
char escaped1[4096]; char escaped1[4096];
char escaped2[4096]; char escaped2[4096];
int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length;
@ -3348,17 +3349,18 @@ static void test_encode_segs(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_fuzz(int index, int debug) { static void test_fuzz(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
int length; int length;
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "3333P33B\035333V3333333333333\0363", -1, 0 }, // #181 Nico Gunkel, OSS-Fuzz /* 0*/ { "3333P33B\035333V3333333333333\0363", -1, 0 }, /* #181 Nico Gunkel, OSS-Fuzz */
/* 1*/ { "{{-06\024755712162106130000000829203983\377", -1, 0 }, // #232 Jan Schrewe, CI-Fuzz, out-of-bounds in is_last_single_ascii() sp + 1 /* 1*/ { "{{-06\024755712162106130000000829203983\377", -1, 0 }, /* #232 Jan Schrewe, CI-Fuzz, out-of-bounds in is_last_single_ascii() sp + 1 */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -3368,8 +3370,7 @@ static void test_fuzz(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -3390,12 +3391,12 @@ static void test_fuzz(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_input", test_input, 1, 0, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_encode_segs", test_encode_segs, 1, 1, 1 }, { "test_encode_segs", test_encode_segs },
{ "test_fuzz", test_fuzz, 1, 0, 1 }, { "test_fuzz", test_fuzz },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -33,7 +33,8 @@
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -42,22 +43,24 @@ static void test_large(int index, int debug) {
int ret; int ret;
int expected_width; int expected_width;
}; };
// é U+00E9 (\351, 233), UTF-8 C3A9, CodeB-only extended ASCII /*
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) é U+00E9 (\351, 233), UTF-8 C3A9, CodeB-only extended ASCII
*/
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_CODE128, "A", 60, 0, 695 }, /* 0*/ { BARCODE_CODE128, "A", 60, 0, 695 },
/* 1*/ { BARCODE_CODE128, "A", 61, ZINT_ERROR_TOO_LONG, -1 }, /* 1*/ { BARCODE_CODE128, "A", 61, ZINT_ERROR_TOO_LONG, -1 },
/* 2*/ { BARCODE_CODE128, "A", 161, ZINT_ERROR_TOO_LONG, -1 }, /* 2*/ { BARCODE_CODE128, "A", 161, ZINT_ERROR_TOO_LONG, -1 },
/* 3*/ { BARCODE_CODE128, "\351A", 40, 0, 695 }, /* 3*/ { BARCODE_CODE128, "\351A", 40, 0, 695 },
/* 4*/ { BARCODE_CODE128, "\351A", 41, ZINT_ERROR_TOO_LONG, -1 }, // 41 chars (+ 20 shifts) /* 4*/ { BARCODE_CODE128, "\351A", 41, ZINT_ERROR_TOO_LONG, -1 }, /* 41 chars (+ 20 shifts) */
/* 5*/ { BARCODE_CODE128, "0", 120, 0, 695 }, /* 5*/ { BARCODE_CODE128, "0", 120, 0, 695 },
/* 6*/ { BARCODE_CODE128, "0", 121, ZINT_ERROR_TOO_LONG, -1 }, /* 6*/ { BARCODE_CODE128, "0", 121, ZINT_ERROR_TOO_LONG, -1 },
/* 7*/ { BARCODE_CODE128B, "A", 60, 0, 695 }, /* 7*/ { BARCODE_CODE128B, "A", 60, 0, 695 },
/* 8*/ { BARCODE_CODE128B, "A", 61, ZINT_ERROR_TOO_LONG, -1 }, /* 8*/ { BARCODE_CODE128B, "A", 61, ZINT_ERROR_TOO_LONG, -1 },
/* 9*/ { BARCODE_CODE128B, "0", 60, 0, 695 }, /* 9*/ { BARCODE_CODE128B, "0", 60, 0, 695 },
/* 10*/ { BARCODE_CODE128B, "0", 61, ZINT_ERROR_TOO_LONG, -1 }, /* 10*/ { BARCODE_CODE128B, "0", 61, ZINT_ERROR_TOO_LONG, -1 },
/* 11*/ { BARCODE_GS1_128, "[90]123456789012345678901234567890[91]1234567890123456789012345678901234567890123456789012345678901234567890[92]1234567890", -1, 0, 706 }, // 116 nos + 3 FNC1s /* 11*/ { BARCODE_GS1_128, "[90]123456789012345678901234567890[91]1234567890123456789012345678901234567890123456789012345678901234567890[92]1234567890", -1, 0, 706 }, /* 116 nos + 3 FNC1s */
/* 12*/ { BARCODE_GS1_128, "[90]123456789012345678901234567890[91]1234567890123456789012345678901234567890123456789012345678901234567890[92]1234[93]1234", -1, ZINT_ERROR_TOO_LONG, -1 }, // 116 nos + 4 FNC1s /* 12*/ { BARCODE_GS1_128, "[90]123456789012345678901234567890[91]1234567890123456789012345678901234567890123456789012345678901234567890[92]1234[93]1234", -1, ZINT_ERROR_TOO_LONG, -1 }, /* 116 nos + 4 FNC1s */
/* 13*/ { BARCODE_GS1_128, "A", 161, ZINT_ERROR_TOO_LONG, -1 }, /* 13*/ { BARCODE_GS1_128, "A", 161, ZINT_ERROR_TOO_LONG, -1 },
/* 14*/ { BARCODE_EAN14, "1234567890123", -1, 0, 134 }, /* 14*/ { BARCODE_EAN14, "1234567890123", -1, 0, 134 },
/* 15*/ { BARCODE_EAN14, "12345678901234", -1, ZINT_ERROR_TOO_LONG, -1 }, /* 15*/ { BARCODE_EAN14, "12345678901234", -1, ZINT_ERROR_TOO_LONG, -1 },
@ -76,7 +79,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -105,7 +108,8 @@ static void test_large(int index, int debug) {
INTERNAL int c128_hrt_cpy_iso8859_1_test(struct zint_symbol *symbol, const unsigned char source[], const int length); INTERNAL int c128_hrt_cpy_iso8859_1_test(struct zint_symbol *symbol, const unsigned char source[], const int length);
static void test_hrt_cpy_iso8859_1(int index, int debug) { static void test_hrt_cpy_iso8859_1(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -114,10 +118,12 @@ static void test_hrt_cpy_iso8859_1(int index, int debug) {
char *expected; char *expected;
char *comment; char *comment;
}; };
// NBSP U+00A0 (\240, 160), UTF-8 C2A0 (\302\240) /*
// ¡ U+00A1 (\241, 161), UTF-8 C2A1 (\302\241) NBSP U+00A0 (\240, 160), UTF-8 C2A0 (\302\240)
// é U+00E9 (\351, 233), UTF-8 C3A9 ¡ U+00A1 (\241, 161), UTF-8 C2A1 (\302\241)
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) é U+00E9 (\351, 233), UTF-8 C3A9
*/
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "", -1, 0, "", "" }, /* 0*/ { "", -1, 0, "", "" },
/* 1*/ { "abc", -1, 3, "abc", "" }, /* 1*/ { "abc", -1, 3, "abc", "" },
@ -154,12 +160,12 @@ static void test_hrt_cpy_iso8859_1(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret = c128_hrt_cpy_iso8859_1_test(&symbol, (unsigned char *) data[i].data, length); ret = c128_hrt_cpy_iso8859_1_test(&symbol, (unsigned char *) data[i].data, length);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) {
for (j = 0; j < ret; j++) { for (j = 0; j < ret; j++) {
fprintf(stderr, "symbol.text[%d] %2X\n", j, symbol.text[j]); fprintf(stderr, "symbol.text[%d] %2X\n", j, symbol.text[j]);
} }
@ -173,7 +179,8 @@ static void test_hrt_cpy_iso8859_1(int index, int debug) {
testFinish(); testFinish();
} }
static void test_hrt(int index, int debug) { static void test_hrt(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -183,8 +190,10 @@ static void test_hrt(int index, int debug) {
char *expected; char *expected;
}; };
// é U+00E9 (\351, 233), UTF-8 C3A9, CodeB-only extended ASCII /*
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) é U+00E9 (\351, 233), UTF-8 C3A9, CodeB-only extended ASCII
*/
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_CODE128, UNICODE_MODE, "1234567890", -1, "1234567890" }, /* 0*/ { BARCODE_CODE128, UNICODE_MODE, "1234567890", -1, "1234567890" },
/* 1*/ { BARCODE_CODE128, UNICODE_MODE, "\000ABC\000DEF\000", 9, " ABC DEF " }, /* 1*/ { BARCODE_CODE128, UNICODE_MODE, "\000ABC\000DEF\000", 9, " ABC DEF " },
@ -192,12 +201,12 @@ static void test_hrt(int index, int debug) {
/* 3*/ { BARCODE_CODE128, UNICODE_MODE, "12345\01167890\037\177", -1, "12345 67890 " }, /* 3*/ { BARCODE_CODE128, UNICODE_MODE, "12345\01167890\037\177", -1, "12345 67890 " },
/* 4*/ { BARCODE_CODE128, UNICODE_MODE, "abcdé", -1, "abcdé" }, /* 4*/ { BARCODE_CODE128, UNICODE_MODE, "abcdé", -1, "abcdé" },
/* 5*/ { BARCODE_CODE128, DATA_MODE, "abcd\351", -1, "abcdé" }, /* 5*/ { BARCODE_CODE128, DATA_MODE, "abcd\351", -1, "abcdé" },
/* 6*/ { BARCODE_CODE128, DATA_MODE, "ab\240cd\351", -1, "ab\302\240cdé" }, // NBSP /* 6*/ { BARCODE_CODE128, DATA_MODE, "ab\240cd\351", -1, "ab\302\240cdé" }, /* NBSP */
/* 7*/ { BARCODE_CODE128B, UNICODE_MODE, "abcdé", -1, "abcdé" }, /* 7*/ { BARCODE_CODE128B, UNICODE_MODE, "abcdé", -1, "abcdé" },
/* 8*/ { BARCODE_CODE128B, DATA_MODE, "abcd\351", -1, "abcdé" }, /* 8*/ { BARCODE_CODE128B, DATA_MODE, "abcd\351", -1, "abcdé" },
/* 9*/ { BARCODE_HIBC_128, UNICODE_MODE, "1234567890", -1, "*+12345678900*" }, /* 9*/ { BARCODE_HIBC_128, UNICODE_MODE, "1234567890", -1, "*+12345678900*" },
/* 10*/ { BARCODE_HIBC_128, UNICODE_MODE, "a99912345", -1, "*+A999123457*" }, // Converts to upper /* 10*/ { BARCODE_HIBC_128, UNICODE_MODE, "a99912345", -1, "*+A999123457*" }, /* Converts to upper */
// BARCODE_GS1_128, BARCODE_EAN14, BARCODE_NVE18 hrt tested in test_gs1.c /* BARCODE_GS1_128, BARCODE_EAN14, BARCODE_NVE18 hrt tested in test_gs1.c */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -207,7 +216,7 @@ static void test_hrt(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -225,7 +234,8 @@ static void test_hrt(int index, int debug) {
testFinish(); testFinish();
} }
static void test_reader_init(int index, int generate, int debug) { static void test_reader_init(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -257,19 +267,19 @@ static void test_reader_init(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug); length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options), i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
@ -288,7 +298,8 @@ static void test_reader_init(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int generate, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -299,14 +310,16 @@ static void test_input(int index, int generate, int debug) {
char *expected; char *expected;
char *comment; char *comment;
}; };
// NUL U+0000, CodeA-only /*
// US U+001F (\037, 31), CodeA-only NUL U+0000, CodeA-only
// a U+0061 (\141, 97), CodeB-only US U+001F (\037, 31), CodeA-only
// b U+0062 (\142, 98), CodeB-only a U+0061 (\141, 97), CodeB-only
// PAD U+0080 (\200, 128), UTF-8 C280 (\302\200), CodeA-only extended ASCII, not in ISO 8859-1 b U+0062 (\142, 98), CodeB-only
// APC U+009F (\237, 159), UTF-8 C29F, CodeA-only extended ASCII, not in ISO 8859-1 PAD U+0080 (\200, 128), UTF-8 C280 (\302\200), CodeA-only extended ASCII, not in ISO 8859-1
// ß U+00DF (\337, 223), UTF-8 C39F, CodeA and CodeB extended ASCII APC U+009F (\237, 159), UTF-8 C29F, CodeA-only extended ASCII, not in ISO 8859-1
// é U+00E9 (\351, 233), UTF-8 C3A9, CodeB-only extended ASCII ß U+00DF (\337, 223), UTF-8 C39F, CodeA and CodeB extended ASCII
é U+00E9 (\351, 233), UTF-8 C3A9, CodeB-only extended ASCII
*/
struct item data[] = { struct item data[] = {
/* 0*/ { UNICODE_MODE, "\302\200", -1, ZINT_ERROR_INVALID_DATA, 0, "Error 204: Invalid character in input data (ISO/IEC 8859-1 only)", "PAD not in ISO 8859-1" }, /* 0*/ { UNICODE_MODE, "\302\200", -1, ZINT_ERROR_INVALID_DATA, 0, "Error 204: Invalid character in input data (ISO/IEC 8859-1 only)", "PAD not in ISO 8859-1" },
/* 1*/ { DATA_MODE, "\200", -1, 0, 57, "(5) 103 101 64 23 106", "PAD ok using binary" }, /* 1*/ { DATA_MODE, "\200", -1, 0, 57, "(5) 103 101 64 23 106", "PAD ok using binary" },
@ -354,19 +367,19 @@ static void test_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_CODE128, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); length = testUtilSetSymbol(symbol, BARCODE_CODE128, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, \"%s\", %d, %s, %d, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, \"%s\", %d, %s, %d, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length, i, testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length,
testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].comment); testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].comment);
@ -383,7 +396,8 @@ static void test_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_ean128_input(int index, int generate, int debug) { static void test_ean128_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -431,19 +445,19 @@ static void test_ean128_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_GS1_128, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); length = testUtilSetSymbol(symbol, BARCODE_GS1_128, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, \"%s\", %s, %d, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, \"%s\", %s, %d, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].comment); testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].comment);
@ -460,7 +474,8 @@ static void test_ean128_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_hibc_input(int index, int generate, int debug) { static void test_hibc_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -488,19 +503,19 @@ static void test_hibc_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_HIBC_128, UNICODE_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); length = testUtilSetSymbol(symbol, BARCODE_HIBC_128, UNICODE_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { \"%s\", %s, %d, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { \"%s\", %s, %d, \"%s\", \"%s\" },\n",
i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].comment); testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].comment);
@ -517,7 +532,8 @@ static void test_hibc_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_ean14_input(int index, int generate, int debug) { static void test_ean14_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -540,19 +556,19 @@ static void test_ean14_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_EAN14, UNICODE_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); length = testUtilSetSymbol(symbol, BARCODE_EAN14, UNICODE_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { \"%s\", %s, %d, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { \"%s\", %s, %d, \"%s\", \"%s\" },\n",
i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].comment); testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].comment);
@ -569,7 +585,8 @@ static void test_ean14_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_dpd_input(int index, int generate, int debug) { static void test_dpd_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -596,19 +613,19 @@ static void test_dpd_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_DPD, UNICODE_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); length = testUtilSetSymbol(symbol, BARCODE_DPD, UNICODE_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { \"%s\", %s, %d, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { \"%s\", %s, %d, \"%s\", \"%s\" },\n",
i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].comment); testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].comment);
@ -625,7 +642,8 @@ static void test_dpd_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -639,8 +657,8 @@ static void test_encode(int index, int generate, int debug) {
char *comment; char *comment;
char *expected; char *expected;
}; };
// BARCODE_GS1_128 examples verified manually against GS1 General Specifications 21.0.1 (GGS) /* BARCODE_GS1_128 examples verified manually against GS1 General Specifications 21.0.1 (GGS) */
// BARCODE_DPD examples Specification DPD and primetime Parcel Despatch (DPDAPPD) Version 4.0.2 /* BARCODE_DPD examples Specification DPD and primetime Parcel Despatch (DPDAPPD) Version 4.0.2 */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_CODE128, UNICODE_MODE, "AIM", 0, 1, 68, 1, "ISO/IEC 15417:2007 Figure 1", /* 0*/ { BARCODE_CODE128, UNICODE_MODE, "AIM", 0, 1, 68, 1, "ISO/IEC 15417:2007 Figure 1",
"11010010000101000110001100010001010111011000101110110001100011101011" "11010010000101000110001100010001010111011000101110110001100011101011"
@ -786,14 +804,14 @@ static void test_encode(int index, int generate, int debug) {
char cmp_buf[8192]; char cmp_buf[8192];
char cmp_msg[1024]; char cmp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -803,7 +821,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, \"%s\", %s, %d, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %s, \"%s\", %s, %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment); testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment);
@ -857,8 +875,9 @@ static void test_encode(int index, int generate, int debug) {
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000) #define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
#define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC) #define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC)
// Not a real test, just performance indicator /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -894,7 +913,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0; diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
@ -924,7 +943,7 @@ static void test_perf(int index, int debug) {
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/); ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start; diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt); assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; // Undo symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock(); start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/); ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
@ -944,7 +963,7 @@ static void test_perf(int index, int debug) {
total_buf_inter += diff_buf_inter; total_buf_inter += diff_buf_inter;
total_print += diff_print; total_print += diff_print;
} }
if (index == -1) { if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals", printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create)); TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
} }
@ -952,18 +971,18 @@ static void test_perf(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_hrt_cpy_iso8859_1", test_hrt_cpy_iso8859_1, 1, 0, 1 }, { "test_hrt_cpy_iso8859_1", test_hrt_cpy_iso8859_1 },
{ "test_hrt", test_hrt, 1, 0, 1 }, { "test_hrt", test_hrt },
{ "test_reader_init", test_reader_init, 1, 1, 1 }, { "test_reader_init", test_reader_init },
{ "test_input", test_input, 1, 1, 1 }, { "test_input", test_input },
{ "test_ean128_input", test_ean128_input, 1, 1, 1 }, { "test_ean128_input", test_ean128_input },
{ "test_hibc_input", test_hibc_input, 1, 1, 1 }, { "test_hibc_input", test_hibc_input },
{ "test_ean14_input", test_ean14_input, 1, 1, 1 }, { "test_ean14_input", test_ean14_input },
{ "test_dpd_input", test_dpd_input, 1, 1, 1 }, { "test_dpd_input", test_dpd_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *pattern; char *pattern;
@ -39,11 +41,11 @@ static void test_large(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "A", 77, 0, 16, 70 }, // BS EN 12323:2005 4.1 (l) /* 0*/ { "A", 77, 0, 16, 70 }, /* BS EN 12323:2005 4.1 (l) */
/* 1*/ { "A", 78, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 1*/ { "A", 78, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 2*/ { "0", 154, 0, 16, 70 }, // BS EN 12323:2005 4.1 (l) /* 2*/ { "0", 154, 0, 16, 70 }, /* BS EN 12323:2005 4.1 (l) */
/* 3*/ { "0", 155, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 3*/ { "0", 155, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 4*/ { "0", 161, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 4*/ { "0", 161, ZINT_ERROR_TOO_LONG, -1, -1 },
}; };
@ -57,7 +59,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -81,7 +83,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_reader_init(int index, int generate, int debug) { static void test_reader_init(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -109,19 +112,19 @@ static void test_reader_init(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_CODE16K, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug); length = testUtilSetSymbol(symbol, BARCODE_CODE16K, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options), i, testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
@ -140,7 +143,8 @@ static void test_reader_init(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int generate, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -153,13 +157,15 @@ static void test_input(int index, int generate, int debug) {
char *expected; char *expected;
char *comment; char *comment;
}; };
// NUL U+0000, CodeA-only /*
// US U+001F (\037, 31), CodeA-only NUL U+0000, CodeA-only
// a U+0061 (\141, 97), CodeB-only US U+001F (\037, 31), CodeA-only
// b U+0062 (\142, 98), CodeB-only a U+0061 (\141, 97), CodeB-only
// APC U+009F (\237, 159), UTF-8 C29F, CodeA-only extended ASCII, not in ISO 8859-1 b U+0062 (\142, 98), CodeB-only
// ß U+00DF (\337, 223), UTF-8 C39F, CodeA and CodeB extended ASCII APC U+009F (\237, 159), UTF-8 C29F, CodeA-only extended ASCII, not in ISO 8859-1
// é U+00E9 (\351, 233), UTF-8 C3A9, CodeB-only extended ASCII ß U+00DF (\337, 223), UTF-8 C39F, CodeA and CodeB extended ASCII
é U+00E9 (\351, 233), UTF-8 C3A9, CodeB-only extended ASCII
*/
struct item data[] = { struct item data[] = {
/* 0*/ { UNICODE_MODE, -1, "\037", -1, 0, 2, 70, "(10) 0 95 103 103 103 103 103 103 22 42", "ModeA US Pad (6)" }, /* 0*/ { UNICODE_MODE, -1, "\037", -1, 0, 2, 70, "(10) 0 95 103 103 103 103 103 103 22 42", "ModeA US Pad (6)" },
/* 1*/ { UNICODE_MODE, -1, "A", -1, 0, 2, 70, "(10) 1 33 103 103 103 103 103 103 52 82", "ModeB A Pad (6)" }, /* 1*/ { UNICODE_MODE, -1, "A", -1, 0, 2, 70, "(10) 1 33 103 103 103 103 103 103 52 82", "ModeB A Pad (6)" },
@ -203,19 +209,19 @@ static void test_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_CODE16K, data[i].input_mode, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); length = testUtilSetSymbol(symbol, BARCODE_CODE16K, data[i].input_mode, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, \"%s\", %d, %s, %d, %d, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %d, \"%s\", %d, %s, %d, %d, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, i, testUtilInputModeName(data[i].input_mode), data[i].option_1,
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length,
@ -234,7 +240,8 @@ static void test_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -298,13 +305,13 @@ static void test_encode(int index, int generate, int debug) {
char bwipp_buf[8192]; char bwipp_buf[8192];
char bwipp_msg[1024]; char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -314,7 +321,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, i, testUtilInputModeName(data[i].input_mode), data[i].option_1,
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
@ -350,11 +357,11 @@ static void test_encode(int index, int generate, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_reader_init", test_reader_init, 1, 1, 1 }, { "test_reader_init", test_reader_init },
{ "test_input", test_input, 1, 1, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *pattern; char *pattern;
@ -39,11 +41,11 @@ static void test_large(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "A", 49, 0, 8, 70 }, // ANSI/AIM BC6-2000 Table 1 /* 0*/ { "A", 49, 0, 8, 70 }, /* ANSI/AIM BC6-2000 Table 1 */
/* 1*/ { "A", 50, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 1*/ { "A", 50, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 2*/ { "0", 81, 0, 8, 70 }, // ANSI/AIM BC6-2000 Table 1 /* 2*/ { "0", 81, 0, 8, 70 }, /* ANSI/AIM BC6-2000 Table 1 */
/* 3*/ { "0", 82, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 3*/ { "0", 82, ZINT_ERROR_TOO_LONG, -1, -1 },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -56,7 +58,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -80,7 +82,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int generate, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -93,8 +96,10 @@ static void test_input(int index, int generate, int debug) {
char *expected; char *expected;
char *comment; char *comment;
}; };
// NUL U+0000, S1 SP (39) /*
// US U+001F (\037, 31), S1 5 NUL U+0000, S1 SP (39)
US U+001F (\037, 31), S1 5
*/
struct item data[] = { struct item data[] = {
/* 0*/ { UNICODE_MODE, -1, "é", -1, ZINT_ERROR_INVALID_DATA, 0, 0, "Error 431: Invalid character in input data", "ASCII only" }, /* 0*/ { UNICODE_MODE, -1, "é", -1, ZINT_ERROR_INVALID_DATA, 0, 0, "Error 431: Invalid character in input data", "ASCII only" },
/* 1*/ { UNICODE_MODE, -1, "EXAMPLE 2", -1, 0, 2, 70, "(16) 14 33 10 22 25 21 14 41 38 2 35 14 18 13 0 22", "2.3.7 Symbol Example" }, /* 1*/ { UNICODE_MODE, -1, "EXAMPLE 2", -1, 0, 2, 70, "(16) 14 33 10 22 25 21 14 41 38 2 35 14 18 13 0 22", "2.3.7 Symbol Example" },
@ -132,19 +137,19 @@ static void test_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_CODE49, data[i].input_mode, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); length = testUtilSetSymbol(symbol, BARCODE_CODE49, data[i].input_mode, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, \"%s\", %d, %s, %d, %d, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %d, \"%s\", %d, %s, %d, %d, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, i, testUtilInputModeName(data[i].input_mode), data[i].option_1,
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length,
@ -163,7 +168,8 @@ static void test_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -212,13 +218,13 @@ static void test_encode(int index, int generate, int debug) {
char bwipp_buf[8192]; char bwipp_buf[8192];
char bwipp_msg[1024]; char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -228,7 +234,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, i, testUtilInputModeName(data[i].input_mode), data[i].option_1,
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
@ -264,10 +270,10 @@ static void test_encode(int index, int generate, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_input", test_input, 1, 1, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -51,7 +51,7 @@ static int is_sane_orig(const char test_string[], const unsigned char source[],
return 0; return 0;
} }
static void test_is_sane(int index) { static void test_is_sane(const testCtx *const p_ctx) {
struct item { struct item {
unsigned int flg; unsigned int flg;
@ -156,7 +156,7 @@ static void test_is_sane(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
@ -185,7 +185,7 @@ static void test_is_sane(int index) {
testFinish(); testFinish();
} }
static void test_is_sane_lookup(int index) { static void test_is_sane_lookup(const testCtx *const p_ctx) {
struct item { struct item {
char *test_string; char *test_string;
@ -210,7 +210,7 @@ static void test_is_sane_lookup(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
test_length = data[i].test_length == -1 ? (int) strlen(data[i].test_string) : data[i].test_length; test_length = data[i].test_length == -1 ? (int) strlen(data[i].test_string) : data[i].test_length;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
@ -229,7 +229,7 @@ static void test_is_sane_lookup(int index) {
testFinish(); testFinish();
} }
static void test_is_valid_utf8(int index) { static void test_is_valid_utf8(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -257,7 +257,7 @@ static void test_is_valid_utf8(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
@ -268,7 +268,8 @@ static void test_is_valid_utf8(int index) {
testFinish(); testFinish();
} }
static void test_utf8_to_unicode(int index, int debug) { static void test_utf8_to_unicode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -300,7 +301,7 @@ static void test_utf8_to_unicode(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int ret_length; int ret_length;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret_length = length; ret_length = length;
@ -319,7 +320,8 @@ static void test_utf8_to_unicode(int index, int debug) {
testFinish(); testFinish();
} }
static void test_set_height(int index, int debug) { static void test_set_height(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int rows; int rows;
@ -361,7 +363,7 @@ static void test_set_height(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
memset(&symbol, 0, sizeof(symbol)); memset(&symbol, 0, sizeof(symbol));
symbol.rows = data[i].rows; symbol.rows = data[i].rows;
@ -379,7 +381,8 @@ static void test_set_height(int index, int debug) {
testFinish(); testFinish();
} }
static void test_debug_test_codeword_dump_int(int index, int debug) { static void test_debug_test_codeword_dump_int(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int codewords[50]; int codewords[50];
@ -402,7 +405,7 @@ static void test_debug_test_codeword_dump_int(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
debug_test_codeword_dump_int(&symbol, data[i].codewords, data[i].length); debug_test_codeword_dump_int(&symbol, data[i].codewords, data[i].length);
assert_nonzero(strlen(symbol.errtxt) < 92, "i:%d strlen(%s) >= 92 (%d)\n", i, symbol.errtxt, (int) strlen(symbol.errtxt)); assert_nonzero(strlen(symbol.errtxt) < 92, "i:%d strlen(%s) >= 92 (%d)\n", i, symbol.errtxt, (int) strlen(symbol.errtxt));
@ -414,13 +417,13 @@ static void test_debug_test_codeword_dump_int(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_is_sane", test_is_sane, 1, 0, 0 }, { "test_is_sane", test_is_sane },
{ "test_is_sane_lookup", test_is_sane_lookup, 1, 0, 0 }, { "test_is_sane_lookup", test_is_sane_lookup },
{ "test_is_valid_utf8", test_is_valid_utf8, 1, 0, 0 }, { "test_is_valid_utf8", test_is_valid_utf8 },
{ "test_utf8_to_unicode", test_utf8_to_unicode, 1, 0, 1 }, { "test_utf8_to_unicode", test_utf8_to_unicode },
{ "test_set_height", test_set_height, 1, 0, 1 }, { "test_set_height", test_set_height },
{ "test_debug_test_codeword_dump_int", test_debug_test_codeword_dump_int, 1, 0, 1 }, { "test_debug_test_codeword_dump_int", test_debug_test_codeword_dump_int },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_eanx_leading_zeroes(int index, int debug) { static void test_eanx_leading_zeroes(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -41,35 +43,35 @@ static void test_eanx_leading_zeroes(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_EANX_CC, "1", "[21]A12345678", 0, 8, 72 }, // EAN-8 /* 0*/ { BARCODE_EANX_CC, "1", "[21]A12345678", 0, 8, 72 }, /* EAN-8 */
/* 1*/ { BARCODE_EANX_CC, "12", "[21]A12345678", 0, 8, 72 }, /* 1*/ { BARCODE_EANX_CC, "12", "[21]A12345678", 0, 8, 72 },
/* 2*/ { BARCODE_EANX_CC, "123", "[21]A12345678", 0, 8, 72 }, /* 2*/ { BARCODE_EANX_CC, "123", "[21]A12345678", 0, 8, 72 },
/* 3*/ { BARCODE_EANX_CC, "1234", "[21]A12345678", 0, 8, 72 }, /* 3*/ { BARCODE_EANX_CC, "1234", "[21]A12345678", 0, 8, 72 },
/* 4*/ { BARCODE_EANX_CC, "12345", "[21]A12345678", 0, 8, 72 }, /* 4*/ { BARCODE_EANX_CC, "12345", "[21]A12345678", 0, 8, 72 },
/* 5*/ { BARCODE_EANX_CC, "123456", "[21]A12345678", 0, 8, 72 }, /* 5*/ { BARCODE_EANX_CC, "123456", "[21]A12345678", 0, 8, 72 },
/* 6*/ { BARCODE_EANX_CC, "1234567", "[21]A12345678", 0, 8, 72 }, /* 6*/ { BARCODE_EANX_CC, "1234567", "[21]A12345678", 0, 8, 72 },
/* 7*/ { BARCODE_EANX_CC, "12345678", "[21]A12345678", 0, 7, 99 }, // EAN-13 /* 7*/ { BARCODE_EANX_CC, "12345678", "[21]A12345678", 0, 7, 99 }, /* EAN-13 */
/* 8*/ { BARCODE_EANX_CC, "1+12", "[21]A12345678", 0, 8, 99 }, // EAN-8 + EAN-2 /* 8*/ { BARCODE_EANX_CC, "1+12", "[21]A12345678", 0, 8, 99 }, /* EAN-8 + EAN-2 */
/* 9*/ { BARCODE_EANX_CC, "12+12", "[21]A12345678", 0, 8, 99 }, /* 9*/ { BARCODE_EANX_CC, "12+12", "[21]A12345678", 0, 8, 99 },
/*10*/ { BARCODE_EANX_CC, "123+12", "[21]A12345678", 0, 8, 99 }, /*10*/ { BARCODE_EANX_CC, "123+12", "[21]A12345678", 0, 8, 99 },
/*11*/ { BARCODE_EANX_CC, "1234+12", "[21]A12345678", 0, 8, 99 }, /*11*/ { BARCODE_EANX_CC, "1234+12", "[21]A12345678", 0, 8, 99 },
/*12*/ { BARCODE_EANX_CC, "12345+12", "[21]A12345678", 0, 8, 99 }, /*12*/ { BARCODE_EANX_CC, "12345+12", "[21]A12345678", 0, 8, 99 },
/*13*/ { BARCODE_EANX_CC, "123456+12", "[21]A12345678", 0, 8, 99 }, /*13*/ { BARCODE_EANX_CC, "123456+12", "[21]A12345678", 0, 8, 99 },
/*14*/ { BARCODE_EANX_CC, "1234567+12", "[21]A12345678", 0, 8, 99 }, /*14*/ { BARCODE_EANX_CC, "1234567+12", "[21]A12345678", 0, 8, 99 },
/*15*/ { BARCODE_EANX_CC, "12345678+12", "[21]A12345678", 0, 7, 126 }, // EAN-13 + EAN-2 /*15*/ { BARCODE_EANX_CC, "12345678+12", "[21]A12345678", 0, 7, 126 }, /* EAN-13 + EAN-2 */
/*16*/ { BARCODE_EANX_CC, "1+123", "[21]A12345678", 0, 8, 126 }, // EAN-8 + EAN-5 /*16*/ { BARCODE_EANX_CC, "1+123", "[21]A12345678", 0, 8, 126 }, /* EAN-8 + EAN-5 */
/*17*/ { BARCODE_EANX_CC, "12+123", "[21]A12345678", 0, 8, 126 }, /*17*/ { BARCODE_EANX_CC, "12+123", "[21]A12345678", 0, 8, 126 },
/*18*/ { BARCODE_EANX_CC, "123+123", "[21]A12345678", 0, 8, 126 }, /*18*/ { BARCODE_EANX_CC, "123+123", "[21]A12345678", 0, 8, 126 },
/*19*/ { BARCODE_EANX_CC, "1234+123", "[21]A12345678", 0, 8, 126 }, /*19*/ { BARCODE_EANX_CC, "1234+123", "[21]A12345678", 0, 8, 126 },
/*20*/ { BARCODE_EANX_CC, "12345+123", "[21]A12345678", 0, 8, 126 }, /*20*/ { BARCODE_EANX_CC, "12345+123", "[21]A12345678", 0, 8, 126 },
/*21*/ { BARCODE_EANX_CC, "123456+123", "[21]A12345678", 0, 8, 126 }, /*21*/ { BARCODE_EANX_CC, "123456+123", "[21]A12345678", 0, 8, 126 },
/*22*/ { BARCODE_EANX_CC, "1234567+123", "[21]A12345678", 0, 8, 126 }, /*22*/ { BARCODE_EANX_CC, "1234567+123", "[21]A12345678", 0, 8, 126 },
/*23*/ { BARCODE_EANX_CC, "12345678+123", "[21]A12345678", 0, 7, 153 }, // EAN-13 + EAN-5 /*23*/ { BARCODE_EANX_CC, "12345678+123", "[21]A12345678", 0, 7, 153 }, /* EAN-13 + EAN-5 */
/*24*/ { BARCODE_EANX_CC, "1234567890128", "[21]A12345678", 0, 7, 99 }, // EAN-13 + CHK /*24*/ { BARCODE_EANX_CC, "1234567890128", "[21]A12345678", 0, 7, 99 }, /* EAN-13 + CHK */
/*25*/ { BARCODE_EANX_CC, "1234567890128+12", "[21]A12345678", 0, 7, 126 }, // EAN-13 + CHK + EAN-2 /*25*/ { BARCODE_EANX_CC, "1234567890128+12", "[21]A12345678", 0, 7, 126 }, /* EAN-13 + CHK + EAN-2 */
/*26*/ { BARCODE_EANX_CC, "1234567890128+12345", "[21]A12345678", 0, 7, 153 }, // EAN-13 + CHK + EAN-5 /*26*/ { BARCODE_EANX_CC, "1234567890128+12345", "[21]A12345678", 0, 7, 153 }, /* EAN-13 + CHK + EAN-5 */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, composite_length, ret; int i, length, composite_length, ret;
@ -79,7 +81,7 @@ static void test_eanx_leading_zeroes(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -132,8 +134,9 @@ static void test_helper_generate(const struct zint_symbol *symbol, int ret, int
} }
} }
// Replicate examples from GS1 General Specifications 21.0.1 and ISO/IEC 24723:2010 /* Replicate examples from GS1 General Specifications 21.0.1 and ISO/IEC 24723:2010 */
static void test_examples(int index, int generate, int debug) { static void test_examples(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -149,7 +152,7 @@ static void test_examples(int index, int generate, int debug) {
char *comment; char *comment;
char *expected; char *expected;
}; };
// Verified manually against GS1 General Specifications 21.0.1 (GGS) and ISO/IEC 24723:2010, with noted exceptions, and verified via bwipp_dump.ps against BWIPP /* Verified manually against GS1 General Specifications 21.0.1 (GGS) and ISO/IEC 24723:2010, with noted exceptions, and verified via bwipp_dump.ps against BWIPP */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_DBAR_OMNSTK_CC, -1, 1, "0401234567890", "[17]050101[10]ABC123", 0, 11, 56, 1, "GSS Figure 5.1-5. GS1 DataBar Stacked Omnidirectional barcode with a Composite Component", /* 0*/ { BARCODE_DBAR_OMNSTK_CC, -1, 1, "0401234567890", "[17]050101[10]ABC123", 0, 11, 56, 1, "GSS Figure 5.1-5. GS1 DataBar Stacked Omnidirectional barcode with a Composite Component",
"01101100110101110001001100001000000110100111011110101001" "01101100110101110001001100001000000110100111011110101001"
@ -1528,14 +1531,13 @@ static void test_examples(int index, int generate, int debug) {
char bwipp_buf[32768]; char bwipp_buf[32768];
char bwipp_msg[1024]; char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_examples"); testStart("test_examples");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1549,7 +1551,7 @@ static void test_examples(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, \"%s\", \"%s\", %s, %d, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %s, %d, \"%s\", \"%s\", %s, %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(symbol->symbology), testUtilInputModeName(data[i].input_mode), data[i].option_1, i, testUtilBarcodeName(symbol->symbology), testUtilInputModeName(data[i].input_mode), data[i].option_1,
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilEscape(data[i].composite, composite_length, esc_composite, sizeof(esc_composite)), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilEscape(data[i].composite, composite_length, esc_composite, sizeof(esc_composite)),
@ -1585,7 +1587,8 @@ static void test_examples(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_odd_numbered_numeric(int index, int generate, int debug) { static void test_odd_numbered_numeric(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1599,7 +1602,7 @@ static void test_odd_numbered_numeric(int index, int generate, int debug) {
char *comment; char *comment;
char *expected; char *expected;
}; };
// Verified via bwipp_dump.ps against BWIPP, and manually against tec-it.com /* Verified via bwipp_dump.ps against BWIPP, and manually against tec-it.com */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_UPCE_CC, 1, "1234567", "[91]1234567890123", 0, 9, 55, "Test odd-numbered numeric, 1st fit, 9-bit remainder, 7-bit final, 2-bit alphanumeric latch, no padding", /* 0*/ { BARCODE_UPCE_CC, 1, "1234567", "[91]1234567890123", 0, 9, 55, "Test odd-numbered numeric, 1st fit, 9-bit remainder, 7-bit final, 2-bit alphanumeric latch, no padding",
"1101100110111011101011110001001111100110010011110101001" "1101100110111011101011110001001111100110010011110101001"
@ -1701,14 +1704,13 @@ static void test_odd_numbered_numeric(int index, int generate, int debug) {
char bwipp_buf[8192]; char bwipp_buf[8192];
char bwipp_msg[1024]; char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_odd_numbered_numeric"); testStart("test_odd_numbered_numeric");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1722,7 +1724,7 @@ static void test_odd_numbered_numeric(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].comment, -1 /*bwipp_cmp*/); test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].comment, -1 /*bwipp_cmp*/);
} else { } else {
int width, row; int width, row;
@ -1749,7 +1751,8 @@ static void test_odd_numbered_numeric(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_ean128_cc_shift(int index, int generate, int debug) { static void test_ean128_cc_shift(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1764,7 +1767,7 @@ static void test_ean128_cc_shift(int index, int generate, int debug) {
char *comment; char *comment;
char *expected; char *expected;
}; };
// Verified via bwipp_dump.ps against BWIPP except where noted, when shift verified manually (tec-it.com seems to be off by 2 for top shifts > 1) /* Verified via bwipp_dump.ps against BWIPP except where noted, when shift verified manually (tec-it.com seems to be off by 2 for top shifts > 1) */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_GS1_128_CC, -1, "[91]1", "[21]A1B2C3D4E5F6G7H8", 0, 6, 100, 0, "CC-A alignment, bottom shift 10, **NOT SAME** as BWIPP, Start B whereas BWIPP uses Start C, codeword count the same", /* 0*/ { BARCODE_GS1_128_CC, -1, "[91]1", "[21]A1B2C3D4E5F6G7H8", 0, 6, 100, 0, "CC-A alignment, bottom shift 10, **NOT SAME** as BWIPP, Start B whereas BWIPP uses Start C, codeword count the same",
"1101001000110100001000001101101011110111110010010001101010000010010000011101110100010000111011001010" "1101001000110100001000001101101011110111110010010001101010000010010000011101110100010000111011001010"
@ -1830,13 +1833,13 @@ static void test_ean128_cc_shift(int index, int generate, int debug) {
char bwipp_buf[8192]; char bwipp_buf[8192];
char bwipp_msg[1024]; char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_ean128_cc_shift"); testStart("test_ean128_cc_shift");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1850,7 +1853,7 @@ static void test_ean128_cc_shift(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].comment, data[i].bwipp_cmp); test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].comment, data[i].bwipp_cmp);
} else { } else {
int width, row; int width, row;
@ -1881,7 +1884,8 @@ static void test_ean128_cc_shift(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_ean128_cc_width(int index, int generate, int debug) { static void test_ean128_cc_width(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -1892,7 +1896,7 @@ static void test_ean128_cc_width(int index, int generate, int debug) {
int expected_width; int expected_width;
char *comment; char *comment;
}; };
// Verified manually with BWIPP (except very large tests) /* Verified manually with BWIPP (except very large tests) */
struct item data[] = { struct item data[] = {
/* 0*/ { "[91]1", "[02]13012345678909", 0, 11, 103, "" }, /* 0*/ { "[91]1", "[02]13012345678909", 0, 11, 103, "" },
/* 1*/ { "[91]12", "[02]13012345678909", 0, 20, 86, "" }, /* 1*/ { "[91]12", "[02]13012345678909", 0, 20, 86, "" },
@ -1916,7 +1920,7 @@ static void test_ean128_cc_width(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1930,7 +1934,7 @@ static void test_ean128_cc_width(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%2d*/ { \"%s\", \"%s\", %s, %d, %d, \"%s\" },\n", printf(" /*%2d*/ { \"%s\", \"%s\", %s, %d, %d, \"%s\" },\n",
i, data[i].data, data[i].composite, testUtilErrorName(ret), symbol->rows, symbol->width, data[i].comment); i, data[i].data, data[i].composite, testUtilErrorName(ret), symbol->rows, symbol->width, data[i].comment);
} else { } else {
@ -1944,8 +1948,9 @@ static void test_ean128_cc_width(int index, int generate, int debug) {
testFinish(); testFinish();
} }
// Test general-purpose data compaction /* Test general-purpose data compaction */
static void test_encodation_0(int index, int generate, int debug) { static void test_encodation_0(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1959,7 +1964,7 @@ static void test_encodation_0(int index, int generate, int debug) {
char *comment; char *comment;
char *expected; char *expected;
}; };
// Verified via bwipp_dump.ps against BWIPP and manually against tec-it.com (with noted exception) /* Verified via bwipp_dump.ps against BWIPP and manually against tec-it.com (with noted exception) */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_UPCE_CC, 1, "1234567", "[91]1", 0, 9, 55, "Single numeric", /* 0*/ { BARCODE_UPCE_CC, 1, "1234567", "[91]1", 0, 9, 55, "Single numeric",
"1101100110111101110101111101010001000111100011110101001" "1101100110111101110101111101010001000111100011110101001"
@ -2376,13 +2381,13 @@ static void test_encodation_0(int index, int generate, int debug) {
char bwipp_buf[8192]; char bwipp_buf[8192];
char bwipp_msg[1024]; char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_encodation_0"); testStart("test_encodation_0");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -2396,7 +2401,7 @@ static void test_encodation_0(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].comment, -1 /*bwipp_cmp*/); test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].comment, -1 /*bwipp_cmp*/);
} else { } else {
int width, row; int width, row;
@ -2423,7 +2428,8 @@ static void test_encodation_0(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encodation_10(int index, int generate, int debug) { static void test_encodation_10(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -2437,7 +2443,7 @@ static void test_encodation_10(int index, int generate, int debug) {
char *comment; char *comment;
char *expected; char *expected;
}; };
// Verified via bwipp_dump.ps against BWIPP, and manually, with noted exceptions, against tec-it.com /* Verified via bwipp_dump.ps against BWIPP, and manually, with noted exceptions, against tec-it.com */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_UPCE_CC, 1, "1234567", "[11]201001[10]AB1234", 0, 9, 55, "Mode '10' date + even-numbered numeric lot, 1st fit, alphanumeric latch and padding", /* 0*/ { BARCODE_UPCE_CC, 1, "1234567", "[11]201001[10]AB1234", 0, 9, 55, "Mode '10' date + even-numbered numeric lot, 1st fit, alphanumeric latch and padding",
"1101100110101110000100011001001000100111100011110101001" "1101100110101110000100011001001000100111100011110101001"
@ -2513,13 +2519,13 @@ static void test_encodation_10(int index, int generate, int debug) {
char bwipp_buf[8192]; char bwipp_buf[8192];
char bwipp_msg[1024]; char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_encodation_10"); testStart("test_encodation_10");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -2533,7 +2539,7 @@ static void test_encodation_10(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].comment, -1 /*bwipp_cmp*/); test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].comment, -1 /*bwipp_cmp*/);
} else { } else {
int width, row; int width, row;
@ -2560,7 +2566,8 @@ static void test_encodation_10(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encodation_11(int index, int generate, int debug) { static void test_encodation_11(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -2574,7 +2581,7 @@ static void test_encodation_11(int index, int generate, int debug) {
char *comment; char *comment;
char *expected; char *expected;
}; };
// Verified via bwipp_dump.ps against BWIPP, and manually against tec-it.com (with noted exception) /* Verified via bwipp_dump.ps against BWIPP, and manually against tec-it.com (with noted exception) */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_UPCE_CC, 1, "1234567", "[90]A", 0, 9, 55, "Mode '11', letter prefix only", /* 0*/ { BARCODE_UPCE_CC, 1, "1234567", "[90]A", 0, 9, 55, "Mode '11', letter prefix only",
"1101100110100111100000101001110110010011111011110101001" "1101100110100111100000101001110110010011111011110101001"
@ -2928,14 +2935,13 @@ static void test_encodation_11(int index, int generate, int debug) {
char bwipp_buf[8192]; char bwipp_buf[8192];
char bwipp_msg[1024]; char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_encodation_11"); testStart("test_encodation_11");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -2949,7 +2955,7 @@ static void test_encodation_11(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].comment, -1 /*bwipp_cmp*/); test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].comment, -1 /*bwipp_cmp*/);
} else { } else {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d %s symbol->rows %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows, data[i].data); assert_equal(symbol->rows, data[i].expected_rows, "i:%d %s symbol->rows %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows, data[i].data);
@ -2977,7 +2983,8 @@ static void test_encodation_11(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_addongap(int index, int generate, int debug) { static void test_addongap(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -2991,7 +2998,7 @@ static void test_addongap(int index, int generate, int debug) {
char *comment; char *comment;
char *expected; char *expected;
}; };
// Verified via bwipp_dump.ps against BWIPP /* Verified via bwipp_dump.ps against BWIPP */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_EANX_CC, 1, -1, "1234567+12", 0, 8, 99, "EAN-8 default 7 gap", /* 0*/ { BARCODE_EANX_CC, 1, -1, "1234567+12", 0, 8, 99, "EAN-8 default 7 gap",
"100100011111001101010011000111100010110011001101100111100001011101001101000000000000000000000000000" "100100011111001101010011000111100010110011001101100111100001011101001101000000000000000000000000000"
@ -3081,13 +3088,13 @@ static void test_addongap(int index, int generate, int debug) {
char *composite = "[91]12"; char *composite = "[91]12";
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_addongap"); testStart("test_addongap");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -3101,7 +3108,7 @@ static void test_addongap(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (const unsigned char *) composite, composite_length); ret = ZBarcode_Encode(symbol, (const unsigned char *) composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), data[i].option_1, data[i].option_2, data[i].data, i, testUtilBarcodeName(data[i].symbology), data[i].option_1, data[i].option_2, data[i].data,
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
@ -3132,7 +3139,8 @@ static void test_addongap(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_gs1parens(int index, int debug) { static void test_gs1parens(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -3144,12 +3152,12 @@ static void test_gs1parens(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_EANX_CC, -1, "1234567", "[21]A12345678", 0, 8, 72 }, // EAN-8 /* 0*/ { BARCODE_EANX_CC, -1, "1234567", "[21]A12345678", 0, 8, 72 }, /* EAN-8 */
/* 1*/ { BARCODE_EANX_CC, GS1PARENS_MODE, "1234567", "(21)A12345678", 0, 8, 72 }, // EAN-8 /* 1*/ { BARCODE_EANX_CC, GS1PARENS_MODE, "1234567", "(21)A12345678", 0, 8, 72 }, /* EAN-8 */
/* 2*/ { BARCODE_EANX_CC, -1, "123456789012", "[21]A12345678", 0, 7, 99 }, // EAN-13 /* 2*/ { BARCODE_EANX_CC, -1, "123456789012", "[21]A12345678", 0, 7, 99 }, /* EAN-13 */
/* 3*/ { BARCODE_EANX_CC, GS1PARENS_MODE, "123456789012", "(21)A12345678", 0, 7, 99 }, // EAN-13 /* 3*/ { BARCODE_EANX_CC, GS1PARENS_MODE, "123456789012", "(21)A12345678", 0, 7, 99 }, /* EAN-13 */
/* 4*/ { BARCODE_GS1_128_CC, -1, "[01]12345678901231", "[21]A12345678", 0, 5, 145 }, /* 4*/ { BARCODE_GS1_128_CC, -1, "[01]12345678901231", "[21]A12345678", 0, 5, 145 },
/* 5*/ { BARCODE_GS1_128_CC, GS1PARENS_MODE, "(01)12345678901231", "(21)A12345678", 0, 5, 145 }, /* 5*/ { BARCODE_GS1_128_CC, GS1PARENS_MODE, "(01)12345678901231", "(21)A12345678", 0, 5, 145 },
/* 6*/ { BARCODE_DBAR_OMN_CC, -1, "12345678901231", "[21]A12345678", 0, 5, 100 }, /* 6*/ { BARCODE_DBAR_OMN_CC, -1, "12345678901231", "[21]A12345678", 0, 5, 100 },
@ -3177,7 +3185,7 @@ static void test_gs1parens(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -3202,7 +3210,8 @@ static void test_gs1parens(int index, int debug) {
testFinish(); testFinish();
} }
static void test_hrt(int index, int debug) { static void test_hrt(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -3213,42 +3222,42 @@ static void test_hrt(int index, int debug) {
int ret; int ret;
char *expected; char *expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_EANX_CC, -1, "1234567", "[20]12", 0, "12345670" }, // EAN-8 /* 0*/ { BARCODE_EANX_CC, -1, "1234567", "[20]12", 0, "12345670" }, /* EAN-8 */
/* 1*/ { BARCODE_EANX_CC, -1, "123456789012", "[20]12", 0, "1234567890128" }, // EAN-13 /* 1*/ { BARCODE_EANX_CC, -1, "123456789012", "[20]12", 0, "1234567890128" }, /* EAN-13 */
/* 2*/ { BARCODE_EANX_CC, -1, "1234567890128", "[20]12", 0, "1234567890128" }, /* 2*/ { BARCODE_EANX_CC, -1, "1234567890128", "[20]12", 0, "1234567890128" },
/* 3*/ { BARCODE_EANX_CC, -1, "1234567890123", "[20]12", ZINT_ERROR_INVALID_CHECK, "" }, /* 3*/ { BARCODE_EANX_CC, -1, "1234567890123", "[20]12", ZINT_ERROR_INVALID_CHECK, "" },
/* 4*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, "1234567890123", "[20]12", ZINT_ERROR_INVALID_CHECK, "" }, // Still checked /* 4*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, "1234567890123", "[20]12", ZINT_ERROR_INVALID_CHECK, "" }, /* Still checked */
/* 5*/ { BARCODE_EANX_CC, -1, "1234567890128", "[20]1A", ZINT_WARN_NONCOMPLIANT, "1234567890128" }, // AI (20) should be 2 nos. /* 5*/ { BARCODE_EANX_CC, -1, "1234567890128", "[20]1A", ZINT_WARN_NONCOMPLIANT, "1234567890128" }, /* AI (20) should be 2 nos. */
/* 6*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, "1234567890128", "[20]1A", 0, "1234567890128" }, /* 6*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, "1234567890128", "[20]1A", 0, "1234567890128" },
/* 7*/ { BARCODE_DBAR_OMN_CC, -1, "1234567890123", "[20]12", 0, "(01)12345678901231" }, /* 7*/ { BARCODE_DBAR_OMN_CC, -1, "1234567890123", "[20]12", 0, "(01)12345678901231" },
/* 8*/ { BARCODE_DBAR_OMN_CC, -1, "12345678901231", "[20]12", 0, "(01)12345678901231" }, /* 8*/ { BARCODE_DBAR_OMN_CC, -1, "12345678901231", "[20]12", 0, "(01)12345678901231" },
/* 9*/ { BARCODE_DBAR_OMN_CC, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, "" }, /* 9*/ { BARCODE_DBAR_OMN_CC, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, "" },
/* 10*/ { BARCODE_DBAR_OMN_CC, GS1NOCHECK_MODE, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, "" }, // Still checked /* 10*/ { BARCODE_DBAR_OMN_CC, GS1NOCHECK_MODE, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, "" }, /* Still checked */
/* 11*/ { BARCODE_DBAR_OMN_CC, -1, "12345678901231", "[20]1A", ZINT_WARN_NONCOMPLIANT, "(01)12345678901231" }, // AI (20) should be 2 nos. /* 11*/ { BARCODE_DBAR_OMN_CC, -1, "12345678901231", "[20]1A", ZINT_WARN_NONCOMPLIANT, "(01)12345678901231" }, /* AI (20) should be 2 nos. */
/* 12*/ { BARCODE_DBAR_OMN_CC, GS1NOCHECK_MODE, "12345678901231", "[20]1A", 0, "(01)12345678901231" }, /* 12*/ { BARCODE_DBAR_OMN_CC, GS1NOCHECK_MODE, "12345678901231", "[20]1A", 0, "(01)12345678901231" },
/* 13*/ { BARCODE_DBAR_LTD_CC, -1, "1234567890123", "[20]12", 0, "(01)12345678901231" }, /* 13*/ { BARCODE_DBAR_LTD_CC, -1, "1234567890123", "[20]12", 0, "(01)12345678901231" },
/* 14*/ { BARCODE_DBAR_LTD_CC, -1, "12345678901231", "[20]12", 0, "(01)12345678901231" }, /* 14*/ { BARCODE_DBAR_LTD_CC, -1, "12345678901231", "[20]12", 0, "(01)12345678901231" },
/* 15*/ { BARCODE_DBAR_LTD_CC, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, "" }, /* 15*/ { BARCODE_DBAR_LTD_CC, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, "" },
/* 16*/ { BARCODE_DBAR_LTD_CC, GS1NOCHECK_MODE, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, "" }, // Still checked /* 16*/ { BARCODE_DBAR_LTD_CC, GS1NOCHECK_MODE, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, "" }, /* Still checked */
/* 17*/ { BARCODE_DBAR_LTD_CC, -1, "12345678901231", "[20]1A", ZINT_WARN_NONCOMPLIANT, "(01)12345678901231" }, // AI (20) should be 2 nos. /* 17*/ { BARCODE_DBAR_LTD_CC, -1, "12345678901231", "[20]1A", ZINT_WARN_NONCOMPLIANT, "(01)12345678901231" }, /* AI (20) should be 2 nos. */
/* 18*/ { BARCODE_DBAR_LTD_CC, GS1NOCHECK_MODE, "12345678901231", "[20]1A", 0, "(01)12345678901231" }, /* 18*/ { BARCODE_DBAR_LTD_CC, GS1NOCHECK_MODE, "12345678901231", "[20]1A", 0, "(01)12345678901231" },
/* 19*/ { BARCODE_UPCA_CC, -1, "12345678901", "[20]12", 0, "123456789012" }, /* 19*/ { BARCODE_UPCA_CC, -1, "12345678901", "[20]12", 0, "123456789012" },
/* 20*/ { BARCODE_UPCA_CC, -1, "123456789012", "[20]12", 0, "123456789012" }, /* 20*/ { BARCODE_UPCA_CC, -1, "123456789012", "[20]12", 0, "123456789012" },
/* 21*/ { BARCODE_UPCA_CC, -1, "123456789013", "[20]12", ZINT_ERROR_INVALID_CHECK, "" }, /* 21*/ { BARCODE_UPCA_CC, -1, "123456789013", "[20]12", ZINT_ERROR_INVALID_CHECK, "" },
/* 22*/ { BARCODE_UPCA_CC, GS1NOCHECK_MODE, "123456789013", "[20]12", ZINT_ERROR_INVALID_CHECK, "" }, // Still checked /* 22*/ { BARCODE_UPCA_CC, GS1NOCHECK_MODE, "123456789013", "[20]12", ZINT_ERROR_INVALID_CHECK, "" }, /* Still checked */
/* 23*/ { BARCODE_UPCA_CC, -1, "123456789012", "[20]1A", ZINT_WARN_NONCOMPLIANT, "123456789012" }, // AI (20) should be 2 nos. /* 23*/ { BARCODE_UPCA_CC, -1, "123456789012", "[20]1A", ZINT_WARN_NONCOMPLIANT, "123456789012" }, /* AI (20) should be 2 nos. */
/* 24*/ { BARCODE_UPCA_CC, GS1NOCHECK_MODE, "123456789012", "[20]1A", 0, "123456789012" }, /* 24*/ { BARCODE_UPCA_CC, GS1NOCHECK_MODE, "123456789012", "[20]1A", 0, "123456789012" },
/* 25*/ { BARCODE_UPCE_CC, -1, "123456", "[20]12", 0, "01234565" }, /* 25*/ { BARCODE_UPCE_CC, -1, "123456", "[20]12", 0, "01234565" },
/* 26*/ { BARCODE_UPCE_CC, -1, "1234567", "[20]12", 0, "12345670" }, /* 26*/ { BARCODE_UPCE_CC, -1, "1234567", "[20]12", 0, "12345670" },
/* 27*/ { BARCODE_UPCE_CC, -1, "12345670", "[20]12", 0, "12345670" }, /* 27*/ { BARCODE_UPCE_CC, -1, "12345670", "[20]12", 0, "12345670" },
/* 28*/ { BARCODE_UPCE_CC, -1, "12345671", "[20]12", ZINT_ERROR_INVALID_CHECK, "" }, /* 28*/ { BARCODE_UPCE_CC, -1, "12345671", "[20]12", ZINT_ERROR_INVALID_CHECK, "" },
/* 29*/ { BARCODE_UPCE_CC, GS1NOCHECK_MODE, "12345671", "[20]12", ZINT_ERROR_INVALID_CHECK, "" }, // Still checked /* 29*/ { BARCODE_UPCE_CC, GS1NOCHECK_MODE, "12345671", "[20]12", ZINT_ERROR_INVALID_CHECK, "" }, /* Still checked */
/* 30*/ { BARCODE_UPCE_CC, -1, "12345670", "[20]12", 0, "12345670" }, // Check digit can now be given for UPCE_CC, like UPCA_CC /* 30*/ { BARCODE_UPCE_CC, -1, "12345670", "[20]12", 0, "12345670" }, /* Check digit can now be given for UPCE_CC, like UPCA_CC */
/* 31*/ { BARCODE_UPCE_CC, -1, "1234567", "[20]1A", ZINT_WARN_NONCOMPLIANT, "12345670" }, // AI (20) should be 2 nos. /* 31*/ { BARCODE_UPCE_CC, -1, "1234567", "[20]1A", ZINT_WARN_NONCOMPLIANT, "12345670" }, /* AI (20) should be 2 nos. */
/* 32*/ { BARCODE_UPCE_CC, GS1NOCHECK_MODE, "1234567", "[20]1A", 0, "12345670" }, /* 32*/ { BARCODE_UPCE_CC, GS1NOCHECK_MODE, "1234567", "[20]1A", 0, "12345670" },
/* 33*/ { BARCODE_DBAR_STK_CC, -1, "12345678901231", "[20]12", 0, "" }, // No HRT for stacked symbologies /* 33*/ { BARCODE_DBAR_STK_CC, -1, "12345678901231", "[20]12", 0, "" }, /* No HRT for stacked symbologies */
/* 34*/ { BARCODE_DBAR_OMNSTK_CC, -1, "12345678901231", "[20]12", 0, "" }, /* 34*/ { BARCODE_DBAR_OMNSTK_CC, -1, "12345678901231", "[20]12", 0, "" },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -3259,7 +3268,7 @@ static void test_hrt(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -3281,8 +3290,9 @@ static void test_hrt(int index, int debug) {
testFinish(); testFinish();
} }
// See also `test_gs1nocheck_mode()` in "test.gs1.c" for GS1_128-based and DBAR_EXP-based symbologies /* See also `test_gs1nocheck_mode()` in "test.gs1.c" for GS1_128-based and DBAR_EXP-based symbologies */
static void test_input(int index, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -3298,111 +3308,111 @@ static void test_input(int index, int debug) {
int expected_width; int expected_width;
char *expected_errtxt; char *expected_errtxt;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567", "[20]12", 0, 8, 72, "" }, // EAN-8 /* 0*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567", "[20]12", 0, 8, 72, "" }, /* EAN-8 */
/* 1*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "123456A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 284: Invalid character in data (digits and \"+\" only) in linear component" }, // EAN-8 /* 1*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "123456A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 284: Invalid character in data (digits and \"+\" only) in linear component" }, /* EAN-8 */
/* 2*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 284: Invalid character in data (digits and \"+\" only) in linear component" }, // Linear component still checked /* 2*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 284: Invalid character in data (digits and \"+\" only) in linear component" }, /* Linear component still checked */
/* 3*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567", "[20]1A", ZINT_WARN_NONCOMPLIANT, 8, 72, "Warning 261: AI (20) position 2: Non-numeric character 'A' in 2D component" }, /* 3*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567", "[20]1A", ZINT_WARN_NONCOMPLIANT, 8, 72, "Warning 261: AI (20) position 2: Non-numeric character 'A' in 2D component" },
/* 4*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567", "[20]1A", 0, 8, 72, "" }, /* 4*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567", "[20]1A", 0, 8, 72, "" },
/* 5*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567", "[02]12345678901234", ZINT_WARN_NONCOMPLIANT, 8, 72, "Warning 261: AI (02) position 14: Bad checksum '4', expected '1' in 2D component" }, /* 5*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567", "[02]12345678901234", ZINT_WARN_NONCOMPLIANT, 8, 72, "Warning 261: AI (02) position 14: Bad checksum '4', expected '1' in 2D component" },
/* 6*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567", "[02]12345678901234", 0, 8, 72, "" }, /* 6*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567", "[02]12345678901234", 0, 8, 72, "" },
/* 7*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "12345671", "[20]12", 0, 7, 99, "" }, // EAN-13 for EANX_CC as length 8 only EAN-8 for EANX_CHK /* 7*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "12345671", "[20]12", 0, 7, 99, "" }, /* EAN-13 for EANX_CC as length 8 only EAN-8 for EANX_CHK */
/* 8*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "123456789012", "[20]12", 0, 7, 99, "" }, // EAN-13 /* 8*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "123456789012", "[20]12", 0, 7, 99, "" }, /* EAN-13 */
/* 9*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567890128", "[20]12", 0, 7, 99, "" }, // EAN-13 /* 9*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567890128", "[20]12", 0, 7, 99, "" }, /* EAN-13 */
/* 10*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567890123", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 275: Invalid check digit '3', expecting '8' in linear component" }, /* 10*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567890123", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 275: Invalid check digit '3', expecting '8' in linear component" },
/* 11*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567890123", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 275: Invalid check digit '3', expecting '8' in linear component" }, // Linear component still checked /* 11*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567890123", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 275: Invalid check digit '3', expecting '8' in linear component" }, /* Linear component still checked */
/* 12*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "12345678901234", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 448: Input too long (13 character maximum) in linear component" }, /* 12*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "12345678901234", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 448: Input too long (13 character maximum) in linear component" },
/* 13*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901234", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 448: Input too long (13 character maximum) in linear component" }, /* 13*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901234", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 448: Input too long (13 character maximum) in linear component" },
/* 14*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "123456789012A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 284: Invalid character in data (digits and \"+\" only) in linear component" }, /* 14*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "123456789012A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 284: Invalid character in data (digits and \"+\" only) in linear component" },
/* 15*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456789012A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 284: Invalid character in data (digits and \"+\" only) in linear component" }, /* 15*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456789012A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 284: Invalid character in data (digits and \"+\" only) in linear component" },
/* 16*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567890128", "[20]1A", ZINT_WARN_NONCOMPLIANT, 7, 99, "Warning 261: AI (20) position 2: Non-numeric character 'A' in 2D component" }, // AI (20) should be 2 nos. /* 16*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567890128", "[20]1A", ZINT_WARN_NONCOMPLIANT, 7, 99, "Warning 261: AI (20) position 2: Non-numeric character 'A' in 2D component" }, /* AI (20) should be 2 nos. */
/* 17*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567890128", "[20]1A", 0, 7, 99, "" }, /* 17*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567890128", "[20]1A", 0, 7, 99, "" },
/* 18*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567890128", "[02]12345678901234", ZINT_WARN_NONCOMPLIANT, 7, 99, "Warning 261: AI (02) position 14: Bad checksum '4', expected '1' in 2D component" }, /* 18*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567890128", "[02]12345678901234", ZINT_WARN_NONCOMPLIANT, 7, 99, "Warning 261: AI (02) position 14: Bad checksum '4', expected '1' in 2D component" },
/* 19*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567890128", "[02]12345678901234", 0, 7, 99, "" }, /* 19*/ { BARCODE_EANX_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567890128", "[02]12345678901234", 0, 7, 99, "" },
/* 20*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567890128", "[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]123456789012345678901234567890123456789012345678901234567", 0, 48, 99, "" }, // Max CC-B for EAN-13 /* 20*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567890128", "[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]123456789012345678901234567890123456789012345678901234567", 0, 48, 99, "" }, /* Max CC-B for EAN-13 */
/* 21*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567890128", "[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]1234567890123456789012345678901234567890123456789012345678", ZINT_ERROR_TOO_LONG, -1, -1, "Error 444: Input too long for selected 2D component" }, /* 21*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "1234567890128", "[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]1234567890123456789012345678901234567890123456789012345678", ZINT_ERROR_TOO_LONG, -1, -1, "Error 444: Input too long for selected 2D component" },
/* 22*/ { BARCODE_EANX_CC, -1, 3, -1, -1, "1234567890128", "[20]12", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 447: Invalid mode (CC-C only valid with GS1-128 linear component)" }, /* 22*/ { BARCODE_EANX_CC, -1, 3, -1, -1, "1234567890128", "[20]12", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 447: Invalid mode (CC-C only valid with GS1-128 linear component)" },
/* 23*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "123456789012345678901", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 449: Input wrong length in linear component" }, /* 23*/ { BARCODE_EANX_CC, -1, -1, -1, -1, "123456789012345678901", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 449: Input wrong length in linear component" },
/* 24*/ { BARCODE_DBAR_OMN_CC, -1, -1, -1, -1, "1234567890123", "[20]12", 0, 5, 100, "" }, /* 24*/ { BARCODE_DBAR_OMN_CC, -1, -1, -1, -1, "1234567890123", "[20]12", 0, 5, 100, "" },
/* 25*/ { BARCODE_DBAR_OMN_CC, -1, -1, -1, -1, "12345678901231", "[20]12", 0, 5, 100, "" }, /* 25*/ { BARCODE_DBAR_OMN_CC, -1, -1, -1, -1, "12345678901231", "[20]12", 0, 5, 100, "" },
/* 26*/ { BARCODE_DBAR_OMN_CC, -1, -1, -1, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 388: Invalid check digit '2', expecting '1' in linear component" }, /* 26*/ { BARCODE_DBAR_OMN_CC, -1, -1, -1, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 388: Invalid check digit '2', expecting '1' in linear component" },
/* 27*/ { BARCODE_DBAR_OMN_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 388: Invalid check digit '2', expecting '1' in linear component" }, // Linear component still checked /* 27*/ { BARCODE_DBAR_OMN_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 388: Invalid check digit '2', expecting '1' in linear component" }, /* Linear component still checked */
/* 28*/ { BARCODE_DBAR_OMN_CC, -1, -1, -1, -1, "123456789012312", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 380: Input too long (14 character maximum) in linear component" }, /* 28*/ { BARCODE_DBAR_OMN_CC, -1, -1, -1, -1, "123456789012312", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 380: Input too long (14 character maximum) in linear component" },
/* 29*/ { BARCODE_DBAR_OMN_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456789012312", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 380: Input too long (14 character maximum) in linear component" }, /* 29*/ { BARCODE_DBAR_OMN_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456789012312", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 380: Input too long (14 character maximum) in linear component" },
/* 30*/ { BARCODE_DBAR_OMN_CC, -1, -1, -1, -1, "1234567890123A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 381: Invalid character in data (digits only) in linear component" }, /* 30*/ { BARCODE_DBAR_OMN_CC, -1, -1, -1, -1, "1234567890123A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 381: Invalid character in data (digits only) in linear component" },
/* 31*/ { BARCODE_DBAR_OMN_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567890123A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 381: Invalid character in data (digits only) in linear component" }, /* 31*/ { BARCODE_DBAR_OMN_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567890123A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 381: Invalid character in data (digits only) in linear component" },
/* 32*/ { BARCODE_DBAR_OMN_CC, -1, -1, -1, -1, "12345678901231", "[20]1A", ZINT_WARN_NONCOMPLIANT, 5, 100, "Warning 261: AI (20) position 2: Non-numeric character 'A' in 2D component" }, // AI (20) should be 2 nos. /* 32*/ { BARCODE_DBAR_OMN_CC, -1, -1, -1, -1, "12345678901231", "[20]1A", ZINT_WARN_NONCOMPLIANT, 5, 100, "Warning 261: AI (20) position 2: Non-numeric character 'A' in 2D component" }, /* AI (20) should be 2 nos. */
/* 33*/ { BARCODE_DBAR_OMN_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901231", "[20]1A", 0, 5, 100, "" }, /* 33*/ { BARCODE_DBAR_OMN_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901231", "[20]1A", 0, 5, 100, "" },
/* 34*/ { BARCODE_DBAR_OMN_CC, -1, -1, -1, -1, "12345678901231", "[02]12345678901234", ZINT_WARN_NONCOMPLIANT, 5, 100, "Warning 261: AI (02) position 14: Bad checksum '4', expected '1' in 2D component" }, /* 34*/ { BARCODE_DBAR_OMN_CC, -1, -1, -1, -1, "12345678901231", "[02]12345678901234", ZINT_WARN_NONCOMPLIANT, 5, 100, "Warning 261: AI (02) position 14: Bad checksum '4', expected '1' in 2D component" },
/* 35*/ { BARCODE_DBAR_OMN_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901231", "[02]12345678901234", 0, 5, 100, "" }, /* 35*/ { BARCODE_DBAR_OMN_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901231", "[02]12345678901234", 0, 5, 100, "" },
/* 36*/ { BARCODE_DBAR_LTD_CC, -1, -1, -1, -1, "1234567890123", "[20]12", 0, 6, 79, "" }, /* 36*/ { BARCODE_DBAR_LTD_CC, -1, -1, -1, -1, "1234567890123", "[20]12", 0, 6, 79, "" },
/* 37*/ { BARCODE_DBAR_LTD_CC, -1, -1, -1, -1, "12345678901231", "[20]12", 0, 6, 79, "" }, /* 37*/ { BARCODE_DBAR_LTD_CC, -1, -1, -1, -1, "12345678901231", "[20]12", 0, 6, 79, "" },
/* 38*/ { BARCODE_DBAR_LTD_CC, -1, -1, -1, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 389: Invalid check digit '2', expecting '1' in linear component" }, /* 38*/ { BARCODE_DBAR_LTD_CC, -1, -1, -1, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 389: Invalid check digit '2', expecting '1' in linear component" },
/* 39*/ { BARCODE_DBAR_LTD_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 389: Invalid check digit '2', expecting '1' in linear component" }, // Linear component still checked /* 39*/ { BARCODE_DBAR_LTD_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 389: Invalid check digit '2', expecting '1' in linear component" }, /* Linear component still checked */
/* 40*/ { BARCODE_DBAR_LTD_CC, -1, -1, -1, -1, "123456789012345", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 382: Input too long (14 character maximum) in linear component" }, /* 40*/ { BARCODE_DBAR_LTD_CC, -1, -1, -1, -1, "123456789012345", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 382: Input too long (14 character maximum) in linear component" },
/* 41*/ { BARCODE_DBAR_LTD_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456789012345", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 382: Input too long (14 character maximum) in linear component" }, /* 41*/ { BARCODE_DBAR_LTD_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456789012345", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 382: Input too long (14 character maximum) in linear component" },
/* 42*/ { BARCODE_DBAR_LTD_CC, -1, -1, -1, -1, "A1234567890123", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 383: Invalid character in data (digits only) in linear component" }, /* 42*/ { BARCODE_DBAR_LTD_CC, -1, -1, -1, -1, "A1234567890123", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 383: Invalid character in data (digits only) in linear component" },
/* 43*/ { BARCODE_DBAR_LTD_CC, GS1NOCHECK_MODE, -1, -1, -1, "A1234567890123", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 383: Invalid character in data (digits only) in linear component" }, /* 43*/ { BARCODE_DBAR_LTD_CC, GS1NOCHECK_MODE, -1, -1, -1, "A1234567890123", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 383: Invalid character in data (digits only) in linear component" },
/* 44*/ { BARCODE_DBAR_LTD_CC, -1, -1, -1, -1, "12345678901231", "[20]1A", ZINT_WARN_NONCOMPLIANT, 6, 79, "Warning 261: AI (20) position 2: Non-numeric character 'A' in 2D component" }, // AI (20) should be 2 nos. /* 44*/ { BARCODE_DBAR_LTD_CC, -1, -1, -1, -1, "12345678901231", "[20]1A", ZINT_WARN_NONCOMPLIANT, 6, 79, "Warning 261: AI (20) position 2: Non-numeric character 'A' in 2D component" }, /* AI (20) should be 2 nos. */
/* 45*/ { BARCODE_DBAR_LTD_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901231", "[20]1A", 0, 6, 79, "" }, /* 45*/ { BARCODE_DBAR_LTD_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901231", "[20]1A", 0, 6, 79, "" },
/* 46*/ { BARCODE_DBAR_LTD_CC, -1, -1, -1, -1, "12345678901231", "[02]12345678901234", ZINT_WARN_NONCOMPLIANT, 6, 79, "Warning 261: AI (02) position 14: Bad checksum '4', expected '1' in 2D component" }, /* 46*/ { BARCODE_DBAR_LTD_CC, -1, -1, -1, -1, "12345678901231", "[02]12345678901234", ZINT_WARN_NONCOMPLIANT, 6, 79, "Warning 261: AI (02) position 14: Bad checksum '4', expected '1' in 2D component" },
/* 47*/ { BARCODE_DBAR_LTD_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901231", "[02]12345678901234", 0, 6, 79, "" }, /* 47*/ { BARCODE_DBAR_LTD_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901231", "[02]12345678901234", 0, 6, 79, "" },
/* 48*/ { BARCODE_UPCA_CC, -1, -1, -1, -1, "12345678901", "[20]12", 0, 7, 99, "" }, /* 48*/ { BARCODE_UPCA_CC, -1, -1, -1, -1, "12345678901", "[20]12", 0, 7, 99, "" },
/* 49*/ { BARCODE_UPCA_CC, -1, -1, -1, -1, "123456789012", "[20]12", 0, 7, 99, "" }, /* 49*/ { BARCODE_UPCA_CC, -1, -1, -1, -1, "123456789012", "[20]12", 0, 7, 99, "" },
/* 50*/ { BARCODE_UPCA_CC, -1, -1, -1, -1, "123456789013", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 270: Invalid check digit '3', expecting '2' in linear component" }, /* 50*/ { BARCODE_UPCA_CC, -1, -1, -1, -1, "123456789013", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 270: Invalid check digit '3', expecting '2' in linear component" },
/* 51*/ { BARCODE_UPCA_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456789013", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 270: Invalid check digit '3', expecting '2' in linear component" }, // Linear component still checked /* 51*/ { BARCODE_UPCA_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456789013", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 270: Invalid check digit '3', expecting '2' in linear component" }, /* Linear component still checked */
/* 52*/ { BARCODE_UPCA_CC, -1, -1, -1, -1, "1234567890123", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 289: Input wrong length (12 character maximum) in linear component" }, /* 52*/ { BARCODE_UPCA_CC, -1, -1, -1, -1, "1234567890123", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 289: Input wrong length (12 character maximum) in linear component" },
/* 53*/ { BARCODE_UPCA_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567890123", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 289: Input wrong length (12 character maximum) in linear component" }, /* 53*/ { BARCODE_UPCA_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567890123", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 289: Input wrong length (12 character maximum) in linear component" },
/* 54*/ { BARCODE_UPCA_CC, -1, -1, -1, -1, "12345678901A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 284: Invalid character in data (digits and \"+\" only) in linear component" }, /* 54*/ { BARCODE_UPCA_CC, -1, -1, -1, -1, "12345678901A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 284: Invalid character in data (digits and \"+\" only) in linear component" },
/* 55*/ { BARCODE_UPCA_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 284: Invalid character in data (digits and \"+\" only) in linear component" }, /* 55*/ { BARCODE_UPCA_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 284: Invalid character in data (digits and \"+\" only) in linear component" },
/* 56*/ { BARCODE_UPCA_CC, -1, -1, -1, -1, "123456789012", "[20]1A", ZINT_WARN_NONCOMPLIANT, 7, 99, "Warning 261: AI (20) position 2: Non-numeric character 'A' in 2D component" }, // AI (20) should be 2 nos. /* 56*/ { BARCODE_UPCA_CC, -1, -1, -1, -1, "123456789012", "[20]1A", ZINT_WARN_NONCOMPLIANT, 7, 99, "Warning 261: AI (20) position 2: Non-numeric character 'A' in 2D component" }, /* AI (20) should be 2 nos. */
/* 57*/ { BARCODE_UPCA_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456789012", "[20]1A", 0, 7, 99, "" }, /* 57*/ { BARCODE_UPCA_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456789012", "[20]1A", 0, 7, 99, "" },
/* 58*/ { BARCODE_UPCA_CC, -1, -1, -1, -1, "123456789012", "[02]12345678901234", ZINT_WARN_NONCOMPLIANT, 7, 99, "Warning 261: AI (02) position 14: Bad checksum '4', expected '1' in 2D component" }, /* 58*/ { BARCODE_UPCA_CC, -1, -1, -1, -1, "123456789012", "[02]12345678901234", ZINT_WARN_NONCOMPLIANT, 7, 99, "Warning 261: AI (02) position 14: Bad checksum '4', expected '1' in 2D component" },
/* 59*/ { BARCODE_UPCA_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456789012", "[02]12345678901234", 0, 7, 99, "" }, /* 59*/ { BARCODE_UPCA_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456789012", "[02]12345678901234", 0, 7, 99, "" },
/* 60*/ { BARCODE_UPCE_CC, -1, -1, -1, -1, "123456", "[20]12", 0, 9, 55, "" }, /* 60*/ { BARCODE_UPCE_CC, -1, -1, -1, -1, "123456", "[20]12", 0, 9, 55, "" },
/* 61*/ { BARCODE_UPCE_CC, -1, -1, -1, -1, "1234567", "[20]12", 0, 9, 55, "" }, /* 61*/ { BARCODE_UPCE_CC, -1, -1, -1, -1, "1234567", "[20]12", 0, 9, 55, "" },
/* 62*/ { BARCODE_UPCE_CC, -1, -1, -1, -1, "12345670", "[20]12", 0, 9, 55, "" }, // Check digit can now be given for UPCE_CC, like UPCA_CC /* 62*/ { BARCODE_UPCE_CC, -1, -1, -1, -1, "12345670", "[20]12", 0, 9, 55, "" }, /* Check digit can now be given for UPCE_CC, like UPCA_CC */
/* 63*/ { BARCODE_UPCE_CC, -1, -1, -1, -1, "12345671", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 274: Invalid check digit '1', expecting '0' in linear component" }, /* 63*/ { BARCODE_UPCE_CC, -1, -1, -1, -1, "12345671", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 274: Invalid check digit '1', expecting '0' in linear component" },
/* 64*/ { BARCODE_UPCE_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345671", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 274: Invalid check digit '1', expecting '0' in linear component" }, // Linear component still checked /* 64*/ { BARCODE_UPCE_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345671", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 274: Invalid check digit '1', expecting '0' in linear component" }, /* Linear component still checked */
/* 65*/ { BARCODE_UPCE_CC, -1, -1, -1, -1, "123456712", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 291: Input wrong length (8 character maximum) in linear component" }, /* 65*/ { BARCODE_UPCE_CC, -1, -1, -1, -1, "123456712", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 291: Input wrong length (8 character maximum) in linear component" },
/* 66*/ { BARCODE_UPCE_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456712", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 291: Input wrong length (8 character maximum) in linear component" }, /* 66*/ { BARCODE_UPCE_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456712", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 291: Input wrong length (8 character maximum) in linear component" },
/* 67*/ { BARCODE_UPCE_CC, -1, -1, -1, -1, "1234567A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 284: Invalid character in data (digits and \"+\" only) in linear component" }, /* 67*/ { BARCODE_UPCE_CC, -1, -1, -1, -1, "1234567A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 284: Invalid character in data (digits and \"+\" only) in linear component" },
/* 68*/ { BARCODE_UPCE_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 284: Invalid character in data (digits and \"+\" only) in linear component" }, /* 68*/ { BARCODE_UPCE_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 284: Invalid character in data (digits and \"+\" only) in linear component" },
/* 69*/ { BARCODE_UPCE_CC, -1, -1, -1, -1, "1234567", "[20]1A", ZINT_WARN_NONCOMPLIANT, 9, 55, "Warning 261: AI (20) position 2: Non-numeric character 'A' in 2D component" }, // AI (20) should be 2 nos. /* 69*/ { BARCODE_UPCE_CC, -1, -1, -1, -1, "1234567", "[20]1A", ZINT_WARN_NONCOMPLIANT, 9, 55, "Warning 261: AI (20) position 2: Non-numeric character 'A' in 2D component" }, /* AI (20) should be 2 nos. */
/* 70*/ { BARCODE_UPCE_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567", "[20]1A", 0, 9, 55, "" }, /* 70*/ { BARCODE_UPCE_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567", "[20]1A", 0, 9, 55, "" },
/* 71*/ { BARCODE_UPCE_CC, -1, -1, -1, -1, "1234567", "[02]12345678901234", ZINT_WARN_NONCOMPLIANT, 9, 55, "Warning 261: AI (02) position 14: Bad checksum '4', expected '1' in 2D component" }, /* 71*/ { BARCODE_UPCE_CC, -1, -1, -1, -1, "1234567", "[02]12345678901234", ZINT_WARN_NONCOMPLIANT, 9, 55, "Warning 261: AI (02) position 14: Bad checksum '4', expected '1' in 2D component" },
/* 72*/ { BARCODE_UPCE_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567", "[02]12345678901234", 0, 9, 55, "" }, /* 72*/ { BARCODE_UPCE_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567", "[02]12345678901234", 0, 9, 55, "" },
/* 73*/ { BARCODE_DBAR_STK_CC, -1, -1, -1, -1, "1234567890123", "[20]12", 0, 9, 56, "" }, /* 73*/ { BARCODE_DBAR_STK_CC, -1, -1, -1, -1, "1234567890123", "[20]12", 0, 9, 56, "" },
/* 74*/ { BARCODE_DBAR_STK_CC, -1, -1, -1, -1, "12345678901231", "[20]12", 0, 9, 56, "" }, /* 74*/ { BARCODE_DBAR_STK_CC, -1, -1, -1, -1, "12345678901231", "[20]12", 0, 9, 56, "" },
/* 75*/ { BARCODE_DBAR_STK_CC, -1, -1, -1, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 388: Invalid check digit '2', expecting '1' in linear component" }, /* 75*/ { BARCODE_DBAR_STK_CC, -1, -1, -1, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 388: Invalid check digit '2', expecting '1' in linear component" },
/* 76*/ { BARCODE_DBAR_STK_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 388: Invalid check digit '2', expecting '1' in linear component" }, // Linear component still checked /* 76*/ { BARCODE_DBAR_STK_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 388: Invalid check digit '2', expecting '1' in linear component" }, /* Linear component still checked */
/* 77*/ { BARCODE_DBAR_STK_CC, -1, -1, -1, -1, "123456789012323", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 380: Input too long (14 character maximum) in linear component" }, /* 77*/ { BARCODE_DBAR_STK_CC, -1, -1, -1, -1, "123456789012323", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 380: Input too long (14 character maximum) in linear component" },
/* 78*/ { BARCODE_DBAR_STK_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456789012323", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 380: Input too long (14 character maximum) in linear component" }, /* 78*/ { BARCODE_DBAR_STK_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456789012323", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 380: Input too long (14 character maximum) in linear component" },
/* 79*/ { BARCODE_DBAR_STK_CC, -1, -1, -1, -1, "1234567890123A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 381: Invalid character in data (digits only) in linear component" }, /* 79*/ { BARCODE_DBAR_STK_CC, -1, -1, -1, -1, "1234567890123A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 381: Invalid character in data (digits only) in linear component" },
/* 80*/ { BARCODE_DBAR_STK_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567890123A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 381: Invalid character in data (digits only) in linear component" }, /* 80*/ { BARCODE_DBAR_STK_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567890123A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 381: Invalid character in data (digits only) in linear component" },
/* 81*/ { BARCODE_DBAR_STK_CC, -1, -1, -1, -1, "12345678901231", "[20]1A", ZINT_WARN_NONCOMPLIANT, 9, 56, "Warning 261: AI (20) position 2: Non-numeric character 'A' in 2D component" }, // AI (20) should be 2 nos. /* 81*/ { BARCODE_DBAR_STK_CC, -1, -1, -1, -1, "12345678901231", "[20]1A", ZINT_WARN_NONCOMPLIANT, 9, 56, "Warning 261: AI (20) position 2: Non-numeric character 'A' in 2D component" }, /* AI (20) should be 2 nos. */
/* 82*/ { BARCODE_DBAR_STK_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901231", "[20]1A", 0, 9, 56, "" }, /* 82*/ { BARCODE_DBAR_STK_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901231", "[20]1A", 0, 9, 56, "" },
/* 83*/ { BARCODE_DBAR_STK_CC, -1, -1, -1, -1, "12345678901231", "[02]12345678901234", ZINT_WARN_NONCOMPLIANT, 9, 56, "Warning 261: AI (02) position 14: Bad checksum '4', expected '1' in 2D component" }, /* 83*/ { BARCODE_DBAR_STK_CC, -1, -1, -1, -1, "12345678901231", "[02]12345678901234", ZINT_WARN_NONCOMPLIANT, 9, 56, "Warning 261: AI (02) position 14: Bad checksum '4', expected '1' in 2D component" },
/* 84*/ { BARCODE_DBAR_STK_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901231", "[02]12345678901234", 0, 9, 56, "" }, /* 84*/ { BARCODE_DBAR_STK_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901231", "[02]12345678901234", 0, 9, 56, "" },
/* 85*/ { BARCODE_DBAR_OMNSTK_CC, -1, -1, -1, -1, "1234567890123", "[20]12", 0, 11, 56, "" }, /* 85*/ { BARCODE_DBAR_OMNSTK_CC, -1, -1, -1, -1, "1234567890123", "[20]12", 0, 11, 56, "" },
/* 86*/ { BARCODE_DBAR_OMNSTK_CC, -1, -1, -1, -1, "12345678901231", "[20]12", 0, 11, 56, "" }, /* 86*/ { BARCODE_DBAR_OMNSTK_CC, -1, -1, -1, -1, "12345678901231", "[20]12", 0, 11, 56, "" },
/* 87*/ { BARCODE_DBAR_OMNSTK_CC, -1, -1, -1, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 388: Invalid check digit '2', expecting '1' in linear component" }, /* 87*/ { BARCODE_DBAR_OMNSTK_CC, -1, -1, -1, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 388: Invalid check digit '2', expecting '1' in linear component" },
/* 88*/ { BARCODE_DBAR_OMNSTK_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 388: Invalid check digit '2', expecting '1' in linear component" }, // Linear component still checked /* 88*/ { BARCODE_DBAR_OMNSTK_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901232", "[20]12", ZINT_ERROR_INVALID_CHECK, -1, -1, "Error 388: Invalid check digit '2', expecting '1' in linear component" }, /* Linear component still checked */
/* 89*/ { BARCODE_DBAR_OMNSTK_CC, -1, -1, -1, -1, "123456789012312", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 380: Input too long (14 character maximum) in linear component" }, /* 89*/ { BARCODE_DBAR_OMNSTK_CC, -1, -1, -1, -1, "123456789012312", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 380: Input too long (14 character maximum) in linear component" },
/* 90*/ { BARCODE_DBAR_OMNSTK_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456789012312", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 380: Input too long (14 character maximum) in linear component" }, /* 90*/ { BARCODE_DBAR_OMNSTK_CC, GS1NOCHECK_MODE, -1, -1, -1, "123456789012312", "[20]12", ZINT_ERROR_TOO_LONG, -1, -1, "Error 380: Input too long (14 character maximum) in linear component" },
/* 91*/ { BARCODE_DBAR_OMNSTK_CC, -1, -1, -1, -1, "1234567890123A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 381: Invalid character in data (digits only) in linear component" }, /* 91*/ { BARCODE_DBAR_OMNSTK_CC, -1, -1, -1, -1, "1234567890123A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 381: Invalid character in data (digits only) in linear component" },
/* 92*/ { BARCODE_DBAR_OMNSTK_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567890123A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 381: Invalid character in data (digits only) in linear component" }, /* 92*/ { BARCODE_DBAR_OMNSTK_CC, GS1NOCHECK_MODE, -1, -1, -1, "1234567890123A", "[20]12", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 381: Invalid character in data (digits only) in linear component" },
/* 93*/ { BARCODE_DBAR_OMNSTK_CC, -1, -1, -1, -1, "12345678901231", "[20]1A", ZINT_WARN_NONCOMPLIANT, 11, 56, "Warning 261: AI (20) position 2: Non-numeric character 'A' in 2D component" }, // AI (20) should be 2 nos. /* 93*/ { BARCODE_DBAR_OMNSTK_CC, -1, -1, -1, -1, "12345678901231", "[20]1A", ZINT_WARN_NONCOMPLIANT, 11, 56, "Warning 261: AI (20) position 2: Non-numeric character 'A' in 2D component" }, /* AI (20) should be 2 nos. */
/* 94*/ { BARCODE_DBAR_OMNSTK_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901231", "[20]1A", 0, 11, 56, "" }, /* 94*/ { BARCODE_DBAR_OMNSTK_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901231", "[20]1A", 0, 11, 56, "" },
/* 95*/ { BARCODE_DBAR_OMNSTK_CC, -1, -1, -1, -1, "12345678901231", "[02]12345678901234", ZINT_WARN_NONCOMPLIANT, 11, 56, "Warning 261: AI (02) position 14: Bad checksum '4', expected '1' in 2D component" }, /* 95*/ { BARCODE_DBAR_OMNSTK_CC, -1, -1, -1, -1, "12345678901231", "[02]12345678901234", ZINT_WARN_NONCOMPLIANT, 11, 56, "Warning 261: AI (02) position 14: Bad checksum '4', expected '1' in 2D component" },
/* 96*/ { BARCODE_DBAR_OMNSTK_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901231", "[02]12345678901234", 0, 11, 56, "" }, /* 96*/ { BARCODE_DBAR_OMNSTK_CC, GS1NOCHECK_MODE, -1, -1, -1, "12345678901231", "[02]12345678901234", 0, 11, 56, "" },
/* 97*/ { BARCODE_GS1_128_CC, -1, -1, -1, -1, "", "[20]12", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 445: No primary (linear) message" }, /* 97*/ { BARCODE_GS1_128_CC, -1, -1, -1, -1, "", "[20]12", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 445: No primary (linear) message" },
/* 98*/ { BARCODE_GS1_128_CC, -1, -1, -1, -1, "[01]12345678901231", "[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[95]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[96]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[97]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[98]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[99]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", 0, 31, 273, "" }, // Tries CC-A then CC-B then CC-C - ensure errtxt empty /* 98*/ { BARCODE_GS1_128_CC, -1, -1, -1, -1, "[01]12345678901231", "[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[95]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[96]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[97]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[98]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[99]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", 0, 31, 273, "" }, /* Tries CC-A then CC-B then CC-C - ensure errtxt empty */
/* 99*/ { BARCODE_GS1_128_CC, -1, -1, -1, -1, "[01]12345678901231[90]123456789012345678901234567890[91]1234567890123456789012345678901234567890123456789012345678901234", "[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[95]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[96]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[97]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[98]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[99]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[95]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[96]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[97]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[98]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[99]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]123456789012345678901234567890123456789012345678901234567890123", 0, 29, 702, "" }, // Max linear and CC-C input /* 99*/ { BARCODE_GS1_128_CC, -1, -1, -1, -1, "[01]12345678901231[90]123456789012345678901234567890[91]1234567890123456789012345678901234567890123456789012345678901234", "[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[95]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[96]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[97]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[98]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[99]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[95]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[96]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[97]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[98]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[99]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]123456789012345678901234567890123456789012345678901234567890123", 0, 29, 702, "" }, /* Max linear and CC-C input */
/*100*/ { BARCODE_GS1_128_CC, -1, -1, -1, -1,"[01]12345678901231[90]123456789012345678901234567890[91]1234567890123456789012345678901234567890123456789012345678901234", "[91]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[92]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[94]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[95]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[96]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[97]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[98]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[99]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[91]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[92]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[94]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[95]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[96]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL", ZINT_ERROR_TOO_LONG, -1, -1, "Error 442: Input too long for selected 2D component" }, // Max linear and oversized CC-C input /*100*/ { BARCODE_GS1_128_CC, -1, -1, -1, -1,"[01]12345678901231[90]123456789012345678901234567890[91]1234567890123456789012345678901234567890123456789012345678901234", "[91]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[92]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[94]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[95]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[96]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[97]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[98]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[99]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[91]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[92]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[94]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[95]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[96]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL", ZINT_ERROR_TOO_LONG, -1, -1, "Error 442: Input too long for selected 2D component" }, /* Max linear and oversized CC-C input */
/*101*/ { BARCODE_GS1_128_CC, -1, -1, -1, -1, "[01]12345678901231", "[91]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[92]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[94]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[95]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[96]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[97]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[98]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[99]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[91]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[92]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[94]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[95]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[96]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[91]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[92]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[91]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[92]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI" "JKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLM", ZINT_ERROR_TOO_LONG, -1, -1, "Error 446: 2D component input data too long" }, // Reduced length 2291 /*101*/ { BARCODE_GS1_128_CC, -1, -1, -1, -1, "[01]12345678901231", "[91]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[92]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[94]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[95]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[96]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[97]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[98]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[99]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[91]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[92]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[94]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[95]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[96]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[91]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[92]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[91]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[92]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI" "JKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL[93]ABCDEFGHIJKLM", ZINT_ERROR_TOO_LONG, -1, -1, "Error 446: 2D component input data too long" }, /* Reduced length 2291 */
/*102*/ { BARCODE_GS1_128_CC, -1, -1, -1, -1, "[01]12345678901231", "[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012" "345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[11]121212[20]12", 0, 32, 579, "" }, // Reduced length 2372 digits (no FNC1s) with not recommended ECC 4 > 2361 digit limit given in ISO/IEC 24723:2010 4.1 (d)(2)(iii) /*102*/ { BARCODE_GS1_128_CC, -1, -1, -1, -1, "[01]12345678901231", "[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012" "345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[11]121212[20]12", 0, 32, 579, "" }, /* Reduced length 2372 digits (no FNC1s) with not recommended ECC 4 > 2361 digit limit given in ISO/IEC 24723:2010 4.1 (d)(2)(iii) */
/*103*/ { BARCODE_DBAR_EXPSTK_CC, -1, -1, -1, -1, "[91]1234567890123456789012345678901234", "[20]12", 0, 13, 102, "" }, /*103*/ { BARCODE_DBAR_EXPSTK_CC, -1, -1, -1, -1, "[91]1234567890123456789012345678901234", "[20]12", 0, 13, 102, "" },
/*104*/ { BARCODE_DBAR_EXPSTK_CC, -1, -1, 1, -1, "[91]1234567890123456789012345678901234", "[20]12", 0, 13, 102, "" }, /*104*/ { BARCODE_DBAR_EXPSTK_CC, -1, -1, 1, -1, "[91]1234567890123456789012345678901234", "[20]12", 0, 13, 102, "" },
/*105*/ { BARCODE_DBAR_EXPSTK_CC, -1, -1, 2, -1, "[91]1234567890123456789012345678901234", "[20]12", 0, 13, 102, "" }, /*105*/ { BARCODE_DBAR_EXPSTK_CC, -1, -1, 2, -1, "[91]1234567890123456789012345678901234", "[20]12", 0, 13, 102, "" },
@ -3420,7 +3430,7 @@ static void test_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -3447,8 +3457,9 @@ static void test_input(int index, int debug) {
testFinish(); testFinish();
} }
// #181 Christian Hartlage OSS-Fuzz /* #181 Christian Hartlage OSS-Fuzz */
static void test_fuzz(int index, int debug) { static void test_fuzz(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -3457,7 +3468,7 @@ static void test_fuzz(int index, int debug) {
char *composite; char *composite;
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_EANX_CC, "+123456789012345678", -1, "[21]A12345678", ZINT_ERROR_TOO_LONG }, /* 0*/ { BARCODE_EANX_CC, "+123456789012345678", -1, "[21]A12345678", ZINT_ERROR_TOO_LONG },
/* 1*/ { BARCODE_UPCA_CC, "+123456789012345678", -1, "[21]A12345678", ZINT_ERROR_TOO_LONG }, /* 1*/ { BARCODE_UPCA_CC, "+123456789012345678", -1, "[21]A12345678", ZINT_ERROR_TOO_LONG },
@ -3473,7 +3484,7 @@ static void test_fuzz(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -3497,8 +3508,9 @@ static void test_fuzz(int index, int debug) {
#define TEST_PERF_ITERATIONS 1000 #define TEST_PERF_ITERATIONS 1000
// Not a real test, just performance indicator /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -3542,7 +3554,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_encode = diff_buffer = 0; diff_encode = diff_buffer = 0;
@ -3577,28 +3589,28 @@ static void test_perf(int index, int debug) {
total_encode += diff_encode; total_encode += diff_encode;
total_buffer += diff_buffer; total_buffer += diff_buffer;
} }
if (index != -1) { if (p_ctx->index != -1) {
printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC); printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
} }
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_eanx_leading_zeroes", test_eanx_leading_zeroes, 1, 0, 1 }, { "test_eanx_leading_zeroes", test_eanx_leading_zeroes },
{ "test_examples", test_examples, 1, 1, 1 }, { "test_examples", test_examples },
{ "test_odd_numbered_numeric", test_odd_numbered_numeric, 1, 1, 1 }, { "test_odd_numbered_numeric", test_odd_numbered_numeric },
{ "test_ean128_cc_shift", test_ean128_cc_shift, 1, 1, 1 }, { "test_ean128_cc_shift", test_ean128_cc_shift },
{ "test_ean128_cc_width", test_ean128_cc_width, 1, 1, 1 }, { "test_ean128_cc_width", test_ean128_cc_width },
{ "test_encodation_0", test_encodation_0, 1, 1, 1 }, { "test_encodation_0", test_encodation_0 },
{ "test_encodation_10", test_encodation_10, 1, 1, 1 }, { "test_encodation_10", test_encodation_10 },
{ "test_encodation_11", test_encodation_11, 1, 1, 1 }, { "test_encodation_11", test_encodation_11 },
{ "test_addongap", test_addongap, 1, 1, 1 }, { "test_addongap", test_addongap },
{ "test_gs1parens", test_gs1parens, 1, 0, 1 }, { "test_gs1parens", test_gs1parens },
{ "test_hrt", test_hrt, 1, 0, 1 }, { "test_hrt", test_hrt },
{ "test_input", test_input, 1, 0, 1 }, { "test_input", test_input },
{ "test_fuzz", test_fuzz, 1, 0, 1 }, { "test_fuzz", test_fuzz },
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -32,7 +32,8 @@
#include "testcommon.h" #include "testcommon.h"
#include "../gs1.h" #include "../gs1.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -44,17 +45,17 @@ static void test_large(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// ISO/IEC 16022:2006 Table 7 and ISO/IEC 21471:2020 (DMRE) Table 7 /* ISO/IEC 16022:2006 Table 7 and ISO/IEC 21471:2020 (DMRE) Table 7 */
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "1", 3116, 0, 144, 144 }, /* 0*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "1", 3116, 0, 144, 144 },
/* 1*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "1", 3117, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 1*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "1", 3117, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 2*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "1", 10922, ZINT_ERROR_TOO_LONG, -1, -1 }, // Minimal encoding can handle max (10921 + 1) * 6 = 65532 < 65536 (2*16) due to sizeof(previous) /* 2*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "1", 10922, ZINT_ERROR_TOO_LONG, -1, -1 }, /* Minimal encoding can handle max (10921 + 1) * 6 = 65532 < 65536 (2*16) due to sizeof(previous) */
/* 3*/ { BARCODE_DATAMATRIX, -1, { 1, 2, "001001"}, "1", 3108, 0, 144, 144 }, // Structured Append 4 codewords overhead == 8 digits /* 3*/ { BARCODE_DATAMATRIX, -1, { 1, 2, "001001"}, "1", 3108, 0, 144, 144 }, /* Structured Append 4 codewords overhead == 8 digits */
/* 4*/ { BARCODE_DATAMATRIX, -1, { 1, 2, "001001"}, "1", 3109, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 4*/ { BARCODE_DATAMATRIX, -1, { 1, 2, "001001"}, "1", 3109, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 5*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "A", 2335, 0, 144, 144 }, /* 5*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "A", 2335, 0, 144, 144 },
/* 6*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "A", 2336, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 6*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "A", 2336, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 7*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "\200", 1556, 0, 144, 144 }, // Spec says 1555 but 1556 correct as only single byte count of 0 required /* 7*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "\200", 1556, 0, 144, 144 }, /* Spec says 1555 but 1556 correct as only single byte count of 0 required */
/* 8*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "\200", 1557, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 8*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "\200", 1557, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 9*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "\001", 1558, 0, 144, 144 }, /* 9*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "\001", 1558, 0, 144, 144 },
/* 10*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "\001", 1559, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 10*/ { BARCODE_DATAMATRIX, -1, { 0, 0, "" }, "\001", 1559, ZINT_ERROR_TOO_LONG, -1, -1 },
@ -154,55 +155,55 @@ static void test_large(int index, int debug) {
/*104*/ { BARCODE_DATAMATRIX, 16, { 0, 0, "" }, "1", 561, ZINT_ERROR_TOO_LONG, -1, -1 }, /*104*/ { BARCODE_DATAMATRIX, 16, { 0, 0, "" }, "1", 561, ZINT_ERROR_TOO_LONG, -1, -1 },
/*105*/ { BARCODE_DATAMATRIX, 16, { 0, 0, "" }, "A", 418, 0, 64, 64 }, /*105*/ { BARCODE_DATAMATRIX, 16, { 0, 0, "" }, "A", 418, 0, 64, 64 },
/*106*/ { BARCODE_DATAMATRIX, 16, { 0, 0, "" }, "A", 419, ZINT_ERROR_TOO_LONG, -1, -1 }, /*106*/ { BARCODE_DATAMATRIX, 16, { 0, 0, "" }, "A", 419, ZINT_ERROR_TOO_LONG, -1, -1 },
/*107*/ { BARCODE_DATAMATRIX, 16, { 0, 0, "" }, "\200", 278, 0, 64, 64 }, // Spec says 277 but 278 correct as only single byte count of 0 required /*107*/ { BARCODE_DATAMATRIX, 16, { 0, 0, "" }, "\200", 278, 0, 64, 64 }, /* Spec says 277 but 278 correct as only single byte count of 0 required */
/*108*/ { BARCODE_DATAMATRIX, 16, { 0, 0, "" }, "\200", 279, ZINT_ERROR_TOO_LONG, -1, -1 }, /*108*/ { BARCODE_DATAMATRIX, 16, { 0, 0, "" }, "\200", 279, ZINT_ERROR_TOO_LONG, -1, -1 },
/*109*/ { BARCODE_DATAMATRIX, 17, { 0, 0, "" }, "1", 736, 0, 72, 72 }, /*109*/ { BARCODE_DATAMATRIX, 17, { 0, 0, "" }, "1", 736, 0, 72, 72 },
/*110*/ { BARCODE_DATAMATRIX, 17, { 0, 0, "" }, "1", 737, ZINT_ERROR_TOO_LONG, -1, -1 }, /*110*/ { BARCODE_DATAMATRIX, 17, { 0, 0, "" }, "1", 737, ZINT_ERROR_TOO_LONG, -1, -1 },
/*111*/ { BARCODE_DATAMATRIX, 17, { 0, 0, "" }, "A", 550, 0, 72, 72 }, /*111*/ { BARCODE_DATAMATRIX, 17, { 0, 0, "" }, "A", 550, 0, 72, 72 },
/*112*/ { BARCODE_DATAMATRIX, 17, { 0, 0, "" }, "A", 551, ZINT_ERROR_TOO_LONG, -1, -1 }, /*112*/ { BARCODE_DATAMATRIX, 17, { 0, 0, "" }, "A", 551, ZINT_ERROR_TOO_LONG, -1, -1 },
/*113*/ { BARCODE_DATAMATRIX, 17, { 0, 0, "" }, "\200", 366, 0, 72, 72 }, // Spec says 365 but 366 correct as only single byte count of 0 required /*113*/ { BARCODE_DATAMATRIX, 17, { 0, 0, "" }, "\200", 366, 0, 72, 72 }, /* Spec says 365 but 366 correct as only single byte count of 0 required */
/*114*/ { BARCODE_DATAMATRIX, 17, { 0, 0, "" }, "\200", 367, ZINT_ERROR_TOO_LONG, -1, -1 }, /*114*/ { BARCODE_DATAMATRIX, 17, { 0, 0, "" }, "\200", 367, ZINT_ERROR_TOO_LONG, -1, -1 },
/*115*/ { BARCODE_DATAMATRIX, 18, { 0, 0, "" }, "1", 912, 0, 80, 80 }, /*115*/ { BARCODE_DATAMATRIX, 18, { 0, 0, "" }, "1", 912, 0, 80, 80 },
/*116*/ { BARCODE_DATAMATRIX, 18, { 0, 0, "" }, "1", 913, ZINT_ERROR_TOO_LONG, -1, -1 }, /*116*/ { BARCODE_DATAMATRIX, 18, { 0, 0, "" }, "1", 913, ZINT_ERROR_TOO_LONG, -1, -1 },
/*117*/ { BARCODE_DATAMATRIX, 18, { 0, 0, "" }, "A", 682, 0, 80, 80 }, /*117*/ { BARCODE_DATAMATRIX, 18, { 0, 0, "" }, "A", 682, 0, 80, 80 },
/*118*/ { BARCODE_DATAMATRIX, 18, { 0, 0, "" }, "A", 683, ZINT_ERROR_TOO_LONG, -1, -1 }, /*118*/ { BARCODE_DATAMATRIX, 18, { 0, 0, "" }, "A", 683, ZINT_ERROR_TOO_LONG, -1, -1 },
/*119*/ { BARCODE_DATAMATRIX, 18, { 0, 0, "" }, "\200", 454, 0, 80, 80 }, // Spec says 453 but 454 correct as only single byte count of 0 required /*119*/ { BARCODE_DATAMATRIX, 18, { 0, 0, "" }, "\200", 454, 0, 80, 80 }, /* Spec says 453 but 454 correct as only single byte count of 0 required */
/*120*/ { BARCODE_DATAMATRIX, 18, { 0, 0, "" }, "\200", 455, ZINT_ERROR_TOO_LONG, -1, -1 }, /*120*/ { BARCODE_DATAMATRIX, 18, { 0, 0, "" }, "\200", 455, ZINT_ERROR_TOO_LONG, -1, -1 },
/*121*/ { BARCODE_DATAMATRIX, 19, { 0, 0, "" }, "1", 1152, 0, 88, 88 }, /*121*/ { BARCODE_DATAMATRIX, 19, { 0, 0, "" }, "1", 1152, 0, 88, 88 },
/*122*/ { BARCODE_DATAMATRIX, 19, { 0, 0, "" }, "1", 1153, ZINT_ERROR_TOO_LONG, -1, -1 }, /*122*/ { BARCODE_DATAMATRIX, 19, { 0, 0, "" }, "1", 1153, ZINT_ERROR_TOO_LONG, -1, -1 },
/*123*/ { BARCODE_DATAMATRIX, 19, { 0, 0, "" }, "A", 862, 0, 88, 88 }, /*123*/ { BARCODE_DATAMATRIX, 19, { 0, 0, "" }, "A", 862, 0, 88, 88 },
/*124*/ { BARCODE_DATAMATRIX, 19, { 0, 0, "" }, "A", 863, ZINT_ERROR_TOO_LONG, -1, -1 }, /*124*/ { BARCODE_DATAMATRIX, 19, { 0, 0, "" }, "A", 863, ZINT_ERROR_TOO_LONG, -1, -1 },
/*125*/ { BARCODE_DATAMATRIX, 19, { 0, 0, "" }, "\200", 574, 0, 88, 88 }, // Spec says 573 but 574 correct as only single byte count of 0 required /*125*/ { BARCODE_DATAMATRIX, 19, { 0, 0, "" }, "\200", 574, 0, 88, 88 }, /* Spec says 573 but 574 correct as only single byte count of 0 required */
/*126*/ { BARCODE_DATAMATRIX, 19, { 0, 0, "" }, "\200", 575, ZINT_ERROR_TOO_LONG, -1, -1 }, /*126*/ { BARCODE_DATAMATRIX, 19, { 0, 0, "" }, "\200", 575, ZINT_ERROR_TOO_LONG, -1, -1 },
/*127*/ { BARCODE_DATAMATRIX, 20, { 0, 0, "" }, "1", 1392, 0, 96, 96 }, /*127*/ { BARCODE_DATAMATRIX, 20, { 0, 0, "" }, "1", 1392, 0, 96, 96 },
/*128*/ { BARCODE_DATAMATRIX, 20, { 0, 0, "" }, "1", 1393, ZINT_ERROR_TOO_LONG, -1, -1 }, /*128*/ { BARCODE_DATAMATRIX, 20, { 0, 0, "" }, "1", 1393, ZINT_ERROR_TOO_LONG, -1, -1 },
/*129*/ { BARCODE_DATAMATRIX, 20, { 0, 0, "" }, "A", 1042, 0, 96, 96 }, /*129*/ { BARCODE_DATAMATRIX, 20, { 0, 0, "" }, "A", 1042, 0, 96, 96 },
/*130*/ { BARCODE_DATAMATRIX, 20, { 0, 0, "" }, "A", 1043, ZINT_ERROR_TOO_LONG, -1, -1 }, /*130*/ { BARCODE_DATAMATRIX, 20, { 0, 0, "" }, "A", 1043, ZINT_ERROR_TOO_LONG, -1, -1 },
/*131*/ { BARCODE_DATAMATRIX, 20, { 0, 0, "" }, "\200", 694, 0, 96, 96 }, // Spec says 693 but 694 correct as only single byte count of 0 required /*131*/ { BARCODE_DATAMATRIX, 20, { 0, 0, "" }, "\200", 694, 0, 96, 96 }, /* Spec says 693 but 694 correct as only single byte count of 0 required */
/*132*/ { BARCODE_DATAMATRIX, 20, { 0, 0, "" }, "\200", 695, ZINT_ERROR_TOO_LONG, -1, -1 }, /*132*/ { BARCODE_DATAMATRIX, 20, { 0, 0, "" }, "\200", 695, ZINT_ERROR_TOO_LONG, -1, -1 },
/*133*/ { BARCODE_DATAMATRIX, 21, { 0, 0, "" }, "1", 1632, 0, 104, 104 }, /*133*/ { BARCODE_DATAMATRIX, 21, { 0, 0, "" }, "1", 1632, 0, 104, 104 },
/*134*/ { BARCODE_DATAMATRIX, 21, { 0, 0, "" }, "1", 1633, ZINT_ERROR_TOO_LONG, -1, -1 }, /*134*/ { BARCODE_DATAMATRIX, 21, { 0, 0, "" }, "1", 1633, ZINT_ERROR_TOO_LONG, -1, -1 },
/*135*/ { BARCODE_DATAMATRIX, 21, { 0, 0, "" }, "A", 1222, 0, 104, 104 }, /*135*/ { BARCODE_DATAMATRIX, 21, { 0, 0, "" }, "A", 1222, 0, 104, 104 },
/*136*/ { BARCODE_DATAMATRIX, 21, { 0, 0, "" }, "A", 1223, ZINT_ERROR_TOO_LONG, -1, -1 }, /*136*/ { BARCODE_DATAMATRIX, 21, { 0, 0, "" }, "A", 1223, ZINT_ERROR_TOO_LONG, -1, -1 },
/*137*/ { BARCODE_DATAMATRIX, 21, { 0, 0, "" }, "\200", 814, 0, 104, 104 }, // Spec says 813 but 814 correct as only single byte count of 0 required /*137*/ { BARCODE_DATAMATRIX, 21, { 0, 0, "" }, "\200", 814, 0, 104, 104 }, /* Spec says 813 but 814 correct as only single byte count of 0 required */
/*138*/ { BARCODE_DATAMATRIX, 21, { 0, 0, "" }, "\200", 815, ZINT_ERROR_TOO_LONG, -1, -1 }, /*138*/ { BARCODE_DATAMATRIX, 21, { 0, 0, "" }, "\200", 815, ZINT_ERROR_TOO_LONG, -1, -1 },
/*139*/ { BARCODE_DATAMATRIX, 22, { 0, 0, "" }, "1", 2100, 0, 120, 120 }, /*139*/ { BARCODE_DATAMATRIX, 22, { 0, 0, "" }, "1", 2100, 0, 120, 120 },
/*140*/ { BARCODE_DATAMATRIX, 22, { 0, 0, "" }, "1", 2101, ZINT_ERROR_TOO_LONG, -1, -1 }, /*140*/ { BARCODE_DATAMATRIX, 22, { 0, 0, "" }, "1", 2101, ZINT_ERROR_TOO_LONG, -1, -1 },
/*141*/ { BARCODE_DATAMATRIX, 22, { 0, 0, "" }, "A", 1573, 0, 120, 120 }, /*141*/ { BARCODE_DATAMATRIX, 22, { 0, 0, "" }, "A", 1573, 0, 120, 120 },
/*142*/ { BARCODE_DATAMATRIX, 22, { 0, 0, "" }, "A", 1574, ZINT_ERROR_TOO_LONG, -1, -1 }, /*142*/ { BARCODE_DATAMATRIX, 22, { 0, 0, "" }, "A", 1574, ZINT_ERROR_TOO_LONG, -1, -1 },
/*143*/ { BARCODE_DATAMATRIX, 22, { 0, 0, "" }, "\200", 1048, 0, 120, 120 }, // Spec says 1047 but 1048 correct as only single byte count of 0 required /*143*/ { BARCODE_DATAMATRIX, 22, { 0, 0, "" }, "\200", 1048, 0, 120, 120 }, /* Spec says 1047 but 1048 correct as only single byte count of 0 required */
/*144*/ { BARCODE_DATAMATRIX, 22, { 0, 0, "" }, "\200", 1049, ZINT_ERROR_TOO_LONG, -1, -1 }, /*144*/ { BARCODE_DATAMATRIX, 22, { 0, 0, "" }, "\200", 1049, ZINT_ERROR_TOO_LONG, -1, -1 },
/*145*/ { BARCODE_DATAMATRIX, 23, { 0, 0, "" }, "1", 2608, 0, 132, 132 }, /*145*/ { BARCODE_DATAMATRIX, 23, { 0, 0, "" }, "1", 2608, 0, 132, 132 },
/*146*/ { BARCODE_DATAMATRIX, 23, { 0, 0, "" }, "1", 2609, ZINT_ERROR_TOO_LONG, -1, -1 }, /*146*/ { BARCODE_DATAMATRIX, 23, { 0, 0, "" }, "1", 2609, ZINT_ERROR_TOO_LONG, -1, -1 },
/*147*/ { BARCODE_DATAMATRIX, 23, { 0, 0, "" }, "A", 1954, 0, 132, 132 }, /*147*/ { BARCODE_DATAMATRIX, 23, { 0, 0, "" }, "A", 1954, 0, 132, 132 },
/*148*/ { BARCODE_DATAMATRIX, 23, { 0, 0, "" }, "A", 1955, ZINT_ERROR_TOO_LONG, -1, -1 }, /*148*/ { BARCODE_DATAMATRIX, 23, { 0, 0, "" }, "A", 1955, ZINT_ERROR_TOO_LONG, -1, -1 },
/*149*/ { BARCODE_DATAMATRIX, 23, { 0, 0, "" }, "\200", 1302, 0, 132, 132 }, // Spec says 1301 but 1302 correct as only single byte count of 0 required /*149*/ { BARCODE_DATAMATRIX, 23, { 0, 0, "" }, "\200", 1302, 0, 132, 132 }, /* Spec says 1301 but 1302 correct as only single byte count of 0 required */
/*150*/ { BARCODE_DATAMATRIX, 23, { 0, 0, "" }, "\200", 1303, ZINT_ERROR_TOO_LONG, -1, -1 }, /*150*/ { BARCODE_DATAMATRIX, 23, { 0, 0, "" }, "\200", 1303, ZINT_ERROR_TOO_LONG, -1, -1 },
/*151*/ { BARCODE_DATAMATRIX, 24, { 0, 0, "" }, "1", 3116, 0, 144, 144 }, /*151*/ { BARCODE_DATAMATRIX, 24, { 0, 0, "" }, "1", 3116, 0, 144, 144 },
/*152*/ { BARCODE_DATAMATRIX, 24, { 0, 0, "" }, "1", 3117, ZINT_ERROR_TOO_LONG, -1, -1 }, /*152*/ { BARCODE_DATAMATRIX, 24, { 0, 0, "" }, "1", 3117, ZINT_ERROR_TOO_LONG, -1, -1 },
/*153*/ { BARCODE_DATAMATRIX, 24, { 0, 0, "" }, "A", 2335, 0, 144, 144 }, /*153*/ { BARCODE_DATAMATRIX, 24, { 0, 0, "" }, "A", 2335, 0, 144, 144 },
/*154*/ { BARCODE_DATAMATRIX, 24, { 0, 0, "" }, "A", 2336, ZINT_ERROR_TOO_LONG, -1, -1 }, /*154*/ { BARCODE_DATAMATRIX, 24, { 0, 0, "" }, "A", 2336, ZINT_ERROR_TOO_LONG, -1, -1 },
/*155*/ { BARCODE_DATAMATRIX, 24, { 0, 0, "" }, "\200", 1556, 0, 144, 144 }, // Spec says 1555 but 1556 correct as only single byte count of 0 required /*155*/ { BARCODE_DATAMATRIX, 24, { 0, 0, "" }, "\200", 1556, 0, 144, 144 }, /* Spec says 1555 but 1556 correct as only single byte count of 0 required */
/*156*/ { BARCODE_DATAMATRIX, 24, { 0, 0, "" }, "\200", 1557, ZINT_ERROR_TOO_LONG, -1, -1 }, /*156*/ { BARCODE_DATAMATRIX, 24, { 0, 0, "" }, "\200", 1557, ZINT_ERROR_TOO_LONG, -1, -1 },
/*157*/ { BARCODE_DATAMATRIX, 25, { 0, 0, "" }, "1", 10, 0, 8, 18 }, /*157*/ { BARCODE_DATAMATRIX, 25, { 0, 0, "" }, "1", 10, 0, 8, 18 },
/*158*/ { BARCODE_DATAMATRIX, 25, { 0, 0, "" }, "1", 11, ZINT_ERROR_TOO_LONG, -1, -1 }, /*158*/ { BARCODE_DATAMATRIX, 25, { 0, 0, "" }, "1", 11, ZINT_ERROR_TOO_LONG, -1, -1 },
@ -306,7 +307,7 @@ static void test_large(int index, int debug) {
/*256*/ { BARCODE_DATAMATRIX, 41, { 0, 0, "" }, "A", 83, ZINT_ERROR_TOO_LONG, -1, -1 }, /*256*/ { BARCODE_DATAMATRIX, 41, { 0, 0, "" }, "A", 83, ZINT_ERROR_TOO_LONG, -1, -1 },
/*257*/ { BARCODE_DATAMATRIX, 41, { 0, 0, "" }, "\200", 54, 0, 20, 44 }, /*257*/ { BARCODE_DATAMATRIX, 41, { 0, 0, "" }, "\200", 54, 0, 20, 44 },
/*258*/ { BARCODE_DATAMATRIX, 41, { 0, 0, "" }, "\200", 55, ZINT_ERROR_TOO_LONG, -1, -1 }, /*258*/ { BARCODE_DATAMATRIX, 41, { 0, 0, "" }, "\200", 55, ZINT_ERROR_TOO_LONG, -1, -1 },
/*259*/ { BARCODE_DATAMATRIX, 42, { 0, 0, "" }, "1", 168, 0, 20, 64 }, // Spec says 186 but typo /*259*/ { BARCODE_DATAMATRIX, 42, { 0, 0, "" }, "1", 168, 0, 20, 64 }, /* Spec says 186 but typo */
/*260*/ { BARCODE_DATAMATRIX, 42, { 0, 0, "" }, "1", 169, ZINT_ERROR_TOO_LONG, -1, -1 }, /*260*/ { BARCODE_DATAMATRIX, 42, { 0, 0, "" }, "1", 169, ZINT_ERROR_TOO_LONG, -1, -1 },
/*261*/ { BARCODE_DATAMATRIX, 42, { 0, 0, "" }, "A", 124, 0, 20, 64 }, /*261*/ { BARCODE_DATAMATRIX, 42, { 0, 0, "" }, "A", 124, 0, 20, 64 },
/*262*/ { BARCODE_DATAMATRIX, 42, { 0, 0, "" }, "A", 125, ZINT_ERROR_TOO_LONG, -1, -1 }, /*262*/ { BARCODE_DATAMATRIX, 42, { 0, 0, "" }, "A", 125, ZINT_ERROR_TOO_LONG, -1, -1 },
@ -359,7 +360,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -395,8 +396,9 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
// Note need ZINT_SANITIZE set for these /* Note need ZINT_SANITIZE set for these */
static void test_buffer(int index, int debug) { static void test_buffer(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int eci; int eci;
@ -406,7 +408,7 @@ static void test_buffer(int index, int debug) {
int ret; int ret;
char *comment; char *comment;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { 16383, UNICODE_MODE, READER_INIT, "1", 0, "" }, /* 0*/ { 16383, UNICODE_MODE, READER_INIT, "1", 0, "" },
/* 1*/ { 3, UNICODE_MODE, 0, "000106j 05 Galeria A Nação0000000000", 0, "From Okapi, consecutive use of upper shift; #176" }, /* 1*/ { 3, UNICODE_MODE, 0, "000106j 05 Galeria A Nação0000000000", 0, "From Okapi, consecutive use of upper shift; #176" },
@ -419,7 +421,7 @@ static void test_buffer(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -435,7 +437,8 @@ static void test_buffer(int index, int debug) {
testFinish(); testFinish();
} }
static void test_options(int index, int debug) { static void test_options(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -452,86 +455,86 @@ static void test_options(int index, int debug) {
int expected_width; int expected_width;
const char *expected_errtxt; const char *expected_errtxt;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "1", 0, 10, 10, "" }, /* 0*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "1", 0, 10, 10, "" },
/* 1*/ { BARCODE_DATAMATRIX, -1, 2, -1, -1, -1, { 0, 0, "" }, "1", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 524: Older Data Matrix standards are no longer supported" }, /* 1*/ { BARCODE_DATAMATRIX, -1, 2, -1, -1, -1, { 0, 0, "" }, "1", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 524: Older Data Matrix standards are no longer supported" },
/* 2*/ { BARCODE_DATAMATRIX, -1, -1, 1, -1, -1, { 0, 0, "" }, "1", 0, 10, 10, "" }, /* 2*/ { BARCODE_DATAMATRIX, -1, -1, 1, -1, -1, { 0, 0, "" }, "1", 0, 10, 10, "" },
/* 3*/ { BARCODE_DATAMATRIX, -1, -1, 2, -1, -1, { 0, 0, "" }, "1", 0, 12, 12, "" }, /* 3*/ { BARCODE_DATAMATRIX, -1, -1, 2, -1, -1, { 0, 0, "" }, "1", 0, 12, 12, "" },
/* 4*/ { BARCODE_DATAMATRIX, -1, -1, 48, -1, -1, { 0, 0, "" }, "1", 0, 26, 64, "" }, /* 4*/ { BARCODE_DATAMATRIX, -1, -1, 48, -1, -1, { 0, 0, "" }, "1", 0, 26, 64, "" },
/* 5*/ { BARCODE_DATAMATRIX, -1, -1, 49, -1, -1, { 0, 0, "" }, "1", 0, 10, 10, "" }, // Ignored /* 5*/ { BARCODE_DATAMATRIX, -1, -1, 49, -1, -1, { 0, 0, "" }, "1", 0, 10, 10, "" }, /* Ignored */
/* 6*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "____", 0, 12, 12, "" }, // 4 data /* 6*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "____", 0, 12, 12, "" }, /* 4 data */
/* 7*/ { BARCODE_DATAMATRIX, -1, -1, 1, -1, -1, { 0, 0, "" }, "____", ZINT_ERROR_TOO_LONG, -1, -1, "Error 522: Input too long for selected symbol size" }, /* 7*/ { BARCODE_DATAMATRIX, -1, -1, 1, -1, -1, { 0, 0, "" }, "____", ZINT_ERROR_TOO_LONG, -1, -1, "Error 522: Input too long for selected symbol size" },
/* 8*/ { BARCODE_DATAMATRIX, -1, -1, 25, -1, -1, { 0, 0, "" }, "____", 0, 8, 18, "" }, /* 8*/ { BARCODE_DATAMATRIX, -1, -1, 25, -1, -1, { 0, 0, "" }, "____", 0, 8, 18, "" },
/* 9*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "__________", 0, 8, 32, "" }, // 10 data /* 9*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "__________", 0, 8, 32, "" }, /* 10 data */
/* 10*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "__________", 0, 8, 32, "" }, /* 10*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "__________", 0, 8, 32, "" },
/* 11*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "__________", 0, 16, 16, "" }, /* 11*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "__________", 0, 16, 16, "" },
/* 12*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_______________", 0, 12, 26, "" }, // 15 data /* 12*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_______________", 0, 12, 26, "" }, /* 15 data */
/* 13*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_______________", 0, 12, 26, "" }, /* 13*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_______________", 0, 12, 26, "" },
/* 14*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_______________", 0, 18, 18, "" }, /* 14*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_______________", 0, 18, 18, "" },
/* 15*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "__________________", 0, 18, 18, "" }, // 18 data /* 15*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "__________________", 0, 18, 18, "" }, /* 18 data */
/* 16*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "___________________", 0, 20, 20, "" }, // 19 data /* 16*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "___________________", 0, 20, 20, "" }, /* 19 data */
/* 17*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_____________________", 0, 20, 20, "" }, // 21 data /* 17*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_____________________", 0, 20, 20, "" }, /* 21 data */
/* 18*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_______________________", 0, 22, 22, "" }, // 23 data /* 18*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_______________________", 0, 22, 22, "" }, /* 23 data */
/* 19*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_______________________", 0, 8, 64, "" }, /* 19*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_______________________", 0, 8, 64, "" },
/* 20*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_______________________", 0, 22, 22, "" }, /* 20*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_______________________", 0, 22, 22, "" },
/* 21*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_______________________________", 0, 16, 36, "" }, // 31 data /* 21*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_______________________________", 0, 16, 36, "" }, /* 31 data */
/* 22*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_______________________________", 0, 16, 36, "" }, /* 22*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_______________________________", 0, 16, 36, "" },
/* 23*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_______________________________", 0, 24, 24, "" }, /* 23*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_______________________________", 0, 24, 24, "" },
/* 24*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_____________________________________", 0, 26, 26, "" }, // 37 data /* 24*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_____________________________________", 0, 26, 26, "" }, /* 37 data */
/* 25*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_____________________________________", 0, 8, 96, "" }, /* 25*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_____________________________________", 0, 8, 96, "" },
/* 26*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_____________________________________", 0, 26, 26, "" }, /* 26*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_____________________________________", 0, 26, 26, "" },
/* 27*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_______________________________________", 0, 26, 26, "" }, // 39 data /* 27*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_______________________________________", 0, 26, 26, "" }, /* 39 data */
/* 28*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_______________________________________", 0, 12, 64, "" }, /* 28*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_______________________________________", 0, 12, 64, "" },
/* 29*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_______________________________________", 0, 26, 26, "" }, /* 29*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_______________________________________", 0, 26, 26, "" },
/* 30*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "___________________________________________", 0, 26, 26, "" }, // 43 data /* 30*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "___________________________________________", 0, 26, 26, "" }, /* 43 data */
/* 31*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "___________________________________________", 0, 12, 64, "" }, /* 31*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "___________________________________________", 0, 12, 64, "" },
/* 32*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "___________________________________________", 0, 26, 26, "" }, /* 32*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "___________________________________________", 0, 26, 26, "" },
/* 33*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "____________________________________________", 0, 26, 26, "" }, // 44 data /* 33*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "____________________________________________", 0, 26, 26, "" }, /* 44 data */
/* 34*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_____________________________________________", 0, 16, 48, "" }, // 45 data /* 34*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_____________________________________________", 0, 16, 48, "" }, /* 45 data */
/* 35*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_____________________________________________", 0, 16, 48, "" }, /* 35*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_____________________________________________", 0, 16, 48, "" },
/* 36*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_____________________________________________", 0, 32, 32, "" }, /* 36*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_____________________________________________", 0, 32, 32, "" },
/* 37*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_________________________________________________", 0, 16, 48, "" }, // 49 data /* 37*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_________________________________________________", 0, 16, 48, "" }, /* 49 data */
/* 38*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_________________________________________________", 0, 16, 48, "" }, /* 38*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_________________________________________________", 0, 16, 48, "" },
/* 39*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_________________________________________________", 0, 32, 32, "" }, /* 39*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_________________________________________________", 0, 32, 32, "" },
/* 40*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "__________________________________________________", 0, 32, 32, "" }, // 50 data /* 40*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "__________________________________________________", 0, 32, 32, "" }, /* 50 data */
/* 41*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "__________________________________________________", 0, 20, 44, "" }, /* 41*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "__________________________________________________", 0, 20, 44, "" },
/* 42*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "__________________________________________________", 0, 32, 32, "" }, /* 42*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "__________________________________________________", 0, 32, 32, "" },
/* 43*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTU", 0, 32, 32, "" }, // 51 data /* 43*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTU", 0, 32, 32, "" }, /* 51 data */
/* 44*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTU", 0, 20, 44, "" }, /* 44*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTU", 0, 20, 44, "" },
/* 45*/ { BARCODE_DATAMATRIX, -1, -1, -1, 9999, -1, { 0, 0, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTU", 0, 32, 32, "" }, // Ignored /* 45*/ { BARCODE_DATAMATRIX, -1, -1, -1, 9999, -1, { 0, 0, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTU", 0, 32, 32, "" }, /* Ignored */
/* 46*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_____________________________________________________________", 0, 32, 32, "" }, // 61 data /* 46*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_____________________________________________________________", 0, 32, 32, "" }, /* 61 data */
/* 47*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "______________________________________________________________", 0, 32, 32, "" }, // 62 data /* 47*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "______________________________________________________________", 0, 32, 32, "" }, /* 62 data */
/* 48*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_______________________________________________________________", 0, 36, 36, "" }, // 63 data /* 48*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_______________________________________________________________", 0, 36, 36, "" }, /* 63 data */
/* 49*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_______________________________________________________________", 0, 8, 144, "" }, /* 49*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_______________________________________________________________", 0, 8, 144, "" },
/* 50*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_______________________________________________________________", 0, 36, 36, "" }, /* 50*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_______________________________________________________________", 0, 36, 36, "" },
/* 51*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "________________________________________________________________", 0, 36, 36, "" }, // 64 data /* 51*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "________________________________________________________________", 0, 36, 36, "" }, /* 64 data */
/* 52*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "________________________________________________________________", 0, 12, 88, "" }, /* 52*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "________________________________________________________________", 0, 12, 88, "" },
/* 53*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "________________________________________________________________", 0, 36, 36, "" }, /* 53*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "________________________________________________________________", 0, 36, 36, "" },
/* 54*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_________________________________________________________________", 0, 36, 36, "" }, // 65 data /* 54*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_________________________________________________________________", 0, 36, 36, "" }, /* 65 data */
/* 55*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_________________________________________________________________", 0, 26, 40, "" }, /* 55*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_________________________________________________________________", 0, 26, 40, "" },
/* 56*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_________________________________________________________________", 0, 36, 36, "" }, /* 56*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_________________________________________________________________", 0, 36, 36, "" },
/* 57*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "______________________________________________________________________", 0, 36, 36, "" }, // 70 data /* 57*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "______________________________________________________________________", 0, 36, 36, "" }, /* 70 data */
/* 58*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "______________________________________________________________________", 0, 26, 40, "" }, /* 58*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "______________________________________________________________________", 0, 26, 40, "" },
/* 59*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "______________________________________________________________________", 0, 36, 36, "" }, /* 59*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "______________________________________________________________________", 0, 36, 36, "" },
/* 60*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_______________________________________________________________________", 0, 36, 36, "" }, // 71 data /* 60*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "_______________________________________________________________________", 0, 36, 36, "" }, /* 71 data */
/* 61*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_______________________________________________________________________", 0, 22, 48, "" }, /* 61*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "_______________________________________________________________________", 0, 22, 48, "" },
/* 62*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_______________________________________________________________________", 0, 36, 36, "" }, /* 62*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "_______________________________________________________________________", 0, 36, 36, "" },
/* 63*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "________________________________________________________________________________", 0, 36, 36, "" }, // 80 data /* 63*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "________________________________________________________________________________", 0, 36, 36, "" }, /* 80 data */
/* 64*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "________________________________________________________________________________", 0, 24, 48, "" }, /* 64*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "________________________________________________________________________________", 0, 24, 48, "" },
/* 65*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "________________________________________________________________________________", 0, 36, 36, "" }, /* 65*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "________________________________________________________________________________", 0, 36, 36, "" },
/* 66*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "____________________________________________________________________________________", 0, 36, 36, "" }, // 84 data /* 66*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "____________________________________________________________________________________", 0, 36, 36, "" }, /* 84 data */
/* 67*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "____________________________________________________________________________________", 0, 20, 64, "" }, /* 67*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "____________________________________________________________________________________", 0, 20, 64, "" },
/* 68*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "____________________________________________________________________________________", 0, 36, 36, "" }, /* 68*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "____________________________________________________________________________________", 0, 36, 36, "" },
/* 69*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "__________________________________________________________________________________________", 0, 40, 40, "" }, // 90 data /* 69*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "__________________________________________________________________________________________", 0, 40, 40, "" }, /* 90 data */
/* 70*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "__________________________________________________________________________________________", 0, 26, 48, "" }, /* 70*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "__________________________________________________________________________________________", 0, 26, 48, "" },
/* 71*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "__________________________________________________________________________________________", 0, 40, 40, "" }, /* 71*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "__________________________________________________________________________________________", 0, 40, 40, "" },
/* 72*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "___________________________________________________________________________________________", 0, 40, 40, "" }, // 91 data /* 72*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "___________________________________________________________________________________________", 0, 40, 40, "" }, /* 91 data */
/* 73*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "___________________________________________________________________________________________", 0, 24, 64, "" }, /* 73*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "___________________________________________________________________________________________", 0, 24, 64, "" },
/* 74*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "___________________________________________________________________________________________", 0, 40, 40, "" }, /* 74*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "___________________________________________________________________________________________", 0, 40, 40, "" },
/* 75*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "______________________________________________________________________________________________________________________", 0, 44, 44, "" }, // 118 data /* 75*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 0, 0, "" }, "______________________________________________________________________________________________________________________", 0, 44, 44, "" }, /* 118 data */
/* 76*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "______________________________________________________________________________________________________________________", 0, 26, 64, "" }, // 118 data /* 76*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, -1, { 0, 0, "" }, "______________________________________________________________________________________________________________________", 0, 26, 64, "" }, /* 118 data */
/* 77*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "______________________________________________________________________________________________________________________", 0, 44, 44, "" }, // 118 data /* 77*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, -1, { 0, 0, "" }, "______________________________________________________________________________________________________________________", 0, 44, 44, "" }, /* 118 data */
/* 78*/ { BARCODE_DATAMATRIX, GS1_MODE, -1, -1, -1, -1, { 0, 0, "" }, "[90]12", 0, 10, 10, "" }, /* 78*/ { BARCODE_DATAMATRIX, GS1_MODE, -1, -1, -1, -1, { 0, 0, "" }, "[90]12", 0, 10, 10, "" },
/* 79*/ { BARCODE_DATAMATRIX, GS1_MODE | GS1PARENS_MODE, -1, -1, -1, -1, { 0, 0, "" }, "(90)12", 0, 10, 10, "" }, /* 79*/ { BARCODE_DATAMATRIX, GS1_MODE | GS1PARENS_MODE, -1, -1, -1, -1, { 0, 0, "" }, "(90)12", 0, 10, 10, "" },
/* 80*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 1, 2, "" }, "1", 0, 12, 12, "" }, /* 80*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 1, 2, "" }, "1", 0, 12, 12, "" },
@ -550,7 +553,7 @@ static void test_options(int index, int debug) {
/* 93*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 2, 3, "255255" }, "1", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 724: Structured Append ID1 '255' and ID2 '255' out of range (001-254) (ID '255255')" }, /* 93*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 2, 3, "255255" }, "1", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 724: Structured Append ID1 '255' and ID2 '255' out of range (001-254) (ID '255255')" },
/* 94*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 2, 3, "1234567" }, "1", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 722: Structured Append ID too long (6 digit maximum)" }, /* 94*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, { 2, 3, "1234567" }, "1", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 722: Structured Append ID too long (6 digit maximum)" },
/* 95*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, READER_INIT, { 2, 3, "1001" }, "1", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 727: Cannot have Structured Append and Reader Initialisation at the same time" }, /* 95*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, READER_INIT, { 2, 3, "1001" }, "1", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 727: Cannot have Structured Append and Reader Initialisation at the same time" },
/* 96*/ { BARCODE_DATAMATRIX, ESCAPE_MODE, -1, -1, -1, -1, { 2, 3, "1001" }, "[)>\\R05\\GA\\R\\E", 0, 12, 26, "" }, // Macro05/06 ignored if have Structured Append TODO: error/warning /* 96*/ { BARCODE_DATAMATRIX, ESCAPE_MODE, -1, -1, -1, -1, { 2, 3, "1001" }, "[)>\\R05\\GA\\R\\E", 0, 12, 26, "" }, /* Macro05/06 ignored if have Structured Append TODO: error/warning */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -560,12 +563,12 @@ static void test_options(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
debug &= ~ZINT_DEBUG_TEST; // Want real errtxt debug &= ~ZINT_DEBUG_TEST; /* Want real errtxt */
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, data[i].option_3, data[i].output_options, data[i].data, -1, debug); length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, data[i].option_3, data[i].output_options, data[i].data, -1, debug);
if (data[i].structapp.count) { if (data[i].structapp.count) {
symbol->structapp = data[i].structapp; symbol->structapp = data[i].structapp;
@ -596,7 +599,8 @@ static void test_options(int index, int debug) {
testFinish(); testFinish();
} }
static void test_reader_init(int index, int generate, int debug) { static void test_reader_init(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -623,19 +627,19 @@ static void test_reader_init(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug); length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options), i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
@ -660,7 +664,8 @@ INTERNAL int dm_encode_test(struct zint_symbol *symbol, const unsigned char sour
const int gs1, unsigned char target[], int *p_tp); const int gs1, unsigned char target[], int *p_tp);
#endif #endif
static void test_input(int index, int generate, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -678,7 +683,7 @@ static void test_input(int index, int generate, int debug) {
char *expected; char *expected;
char *comment; char *comment;
int expected_diff; // Difference between default minimal encodation and ISO encodation (FAST_MODE) int expected_diff; /* Difference between default minimal encodation and ISO encodation (FAST_MODE) */
}; };
struct item data[] = { struct item data[] = {
/* 0*/ { UNICODE_MODE | FAST_MODE, 0, -1, -1, -1, "0466010592130100000k*AGUATY80", 0, 0, 18, 18, 1, "(32) 86 C4 83 87 DE 8F 83 82 82 31 6C EE 08 85 D6 D2 EF 65 93 B0 1C 3C 76 FB D4 AB 16 11", "#208", 0 }, /* 0*/ { UNICODE_MODE | FAST_MODE, 0, -1, -1, -1, "0466010592130100000k*AGUATY80", 0, 0, 18, 18, 1, "(32) 86 C4 83 87 DE 8F 83 82 82 31 6C EE 08 85 D6 D2 EF 65 93 B0 1C 3C 76 FB D4 AB 16 11", "#208", 0 },
@ -930,27 +935,26 @@ static void test_input(int index, int generate, int debug) {
char cmp_buf[32768]; char cmp_buf[32768];
char cmp_msg[1024]; char cmp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_input"); testStart("test_input");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_DATAMATRIX, data[i].input_mode, data[i].eci, -1 /*option_1*/, data[i].option_2, data[i].option_3, data[i].output_options, data[i].data, -1, debug); length = testUtilSetSymbol(symbol, BARCODE_DATAMATRIX, data[i].input_mode, data[i].eci, -1 /*option_1*/, data[i].option_2, data[i].option_3, data[i].output_options, data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, %s, %s, \"%s\", %s, %d, %d, %d, %d, \"%s\", \"%s\", %d },\n", printf(" /*%3d*/ { %s, %d, %d, %s, %s, \"%s\", %s, %d, %d, %d, %d, \"%s\", \"%s\", %d },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_2, testUtilOption3Name(data[i].option_3), i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_2, testUtilOption3Name(data[i].option_3),
testUtilOutputOptionsName(data[i].output_options), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilOutputOptionsName(data[i].output_options), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
@ -1049,7 +1053,8 @@ static void test_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1066,11 +1071,12 @@ static void test_encode(int index, int generate, int debug) {
int expected_width; int expected_width;
int bwipp_cmp; int bwipp_cmp;
char *comment; char *comment;
int expected_diff; // Difference between default minimal encodation and ISO encodation (FAST_MODE) int expected_diff; /* Difference between default minimal encodation and ISO encodation (FAST_MODE) */
char *expected; char *expected;
}; };
// Verified manually against ISO/IEC 16022:2006, ISO/IEC 21471:2020, GS1 General Specifications 21.0.1 (GGS), ANSI/HIBC LIC 2.6-2016 (HIBC/LIC), /* Verified manually against ISO/IEC 16022:2006, ISO/IEC 21471:2020, GS1 General Specifications 21.0.1 (GGS), ANSI/HIBC LIC 2.6-2016 (HIBC/LIC),
// ANSI/HIBC PAS 1.3-2010 (HIBC/PAS) and AIM ITS/04-023:2022 (ECI Part 3: Register), with noted exceptions ANSI/HIBC PAS 1.3-2010 (HIBC/PAS) and AIM ITS/04-023:2022 (ECI Part 3: Register), with noted exceptions
*/
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_DATAMATRIX, FAST_MODE, -1, -1, -1, -1, "1234abcd", -1, 0, 14, 14, 1, "", 0, /* 0*/ { BARCODE_DATAMATRIX, FAST_MODE, -1, -1, -1, -1, "1234abcd", -1, 0, 14, 14, 1, "", 0,
"10101010101010" "10101010101010"
@ -5181,15 +5187,14 @@ static void test_encode(int index, int generate, int debug) {
char cmp_buf[32768]; char cmp_buf[32768];
char cmp_msg[1024]; char cmp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -5201,7 +5206,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, %s, %d, %s, \"%s\", %d, %s, %d, %d, %d, \"%s\", %d,\n", printf(" /*%3d*/ { %s, %s, %d, %s, %d, %s, \"%s\", %d, %s, %d, %d, %d, \"%s\", %d,\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].eci, i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].eci,
testUtilOutputOptionsName(data[i].output_options), testUtilOutputOptionsName(data[i].output_options),
@ -5289,7 +5294,8 @@ static void test_encode(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode_segs(int index, int generate, int debug) { static void test_encode_segs(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -5477,15 +5483,14 @@ static void test_encode_segs(int index, int generate, int debug) {
char cmp_buf[32768]; char cmp_buf[32768];
char cmp_msg[1024]; char cmp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_encode_segs"); testStart("test_encode_segs");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -5501,7 +5506,7 @@ static void test_encode_segs(int index, int generate, int debug) {
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count); ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
char escaped1[4096]; char escaped1[4096];
char escaped2[4096]; char escaped2[4096];
int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length;
@ -5570,7 +5575,8 @@ static void test_encode_segs(int index, int generate, int debug) {
} }
#ifdef ZINT_TEST_ENCODING #ifdef ZINT_TEST_ENCODING
static void test_minimalenc(int index, int debug) { static void test_minimalenc(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -5581,10 +5587,10 @@ static void test_minimalenc(int index, int debug) {
int length; int length;
int ret; int ret;
int expected_diff; // Difference between default minimal encodation and ISO encodation (FAST_MODE) int expected_diff; /* Difference between default minimal encodation and ISO encodation (FAST_MODE) */
char *comment; char *comment;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_DATAMATRIX, -1, -1, -1, "A", -1, 0, 0, "ASC" }, /* 0*/ { BARCODE_DATAMATRIX, -1, -1, -1, "A", -1, 0, 0, "ASC" },
/* 1*/ { BARCODE_DATAMATRIX, -1, -1, -1, "AA", -1, 0, 0, "ASC" }, /* 1*/ { BARCODE_DATAMATRIX, -1, -1, -1, "AA", -1, 0, 0, "ASC" },
@ -6617,8 +6623,7 @@ static void test_minimalenc(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -6672,8 +6677,9 @@ static void test_minimalenc(int index, int debug) {
#endif #endif
#define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC) #define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC)
// Not a real test, just performance indicator /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -6779,7 +6785,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0; diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
@ -6809,7 +6815,7 @@ static void test_perf(int index, int debug) {
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/); ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start; diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt); assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; // Undo symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock(); start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/); ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
@ -6829,7 +6835,7 @@ static void test_perf(int index, int debug) {
total_buf_inter += diff_buf_inter; total_buf_inter += diff_buf_inter;
total_print += diff_print; total_print += diff_print;
} }
if (index == -1) { if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals", printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create)); TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
} }
@ -6837,18 +6843,18 @@ static void test_perf(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_buffer", test_buffer, 1, 0, 1 }, { "test_buffer", test_buffer },
{ "test_options", test_options, 1, 0, 1 }, { "test_options", test_options },
{ "test_reader_init", test_reader_init, 1, 1, 1 }, { "test_reader_init", test_reader_init },
{ "test_input", test_input, 1, 1, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_encode_segs", test_encode_segs, 1, 1, 1 }, { "test_encode_segs", test_encode_segs },
#ifdef ZINT_TEST_ENCODING #ifdef ZINT_TEST_ENCODING
{ "test_minimalenc", test_minimalenc, 1, 0, 1 }, { "test_minimalenc", test_minimalenc },
#endif #endif
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int option_2; int option_2;
@ -38,14 +40,14 @@ static void test_large(int index, int debug) {
int length; int length;
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { 200, '0', 2940, 0 }, // 2940 largest Code Set C data that fits in 200x199 HxW /* 0*/ { 200, '0', 2940, 0 }, /* 2940 largest Code Set C data that fits in 200x199 HxW */
/* 1*/ { 200, '0', 2941, ZINT_ERROR_INVALID_OPTION }, /* 1*/ { 200, '0', 2941, ZINT_ERROR_INVALID_OPTION },
/* 2*/ { 200, '9', 200, 0 }, // Changes a number of mask scores re pre-Rev. 4 version, but best score still the same (7) /* 2*/ { 200, '9', 200, 0 }, /* Changes a number of mask scores re pre-Rev. 4 version, but best score still the same (7) */
/* 3*/ { 201, '0', 2940, ZINT_ERROR_INVALID_OPTION }, /* 3*/ { 201, '0', 2940, ZINT_ERROR_INVALID_OPTION },
/* 4*/ { 201, '0', 2974, ZINT_ERROR_INVALID_OPTION }, // Height > 200 also /* 4*/ { 201, '0', 2974, ZINT_ERROR_INVALID_OPTION }, /* Height > 200 also */
/* 5*/ { 30, '\001', 71, 0 }, // Codeword length 72, ECC length 39, for ND + 1 == 112 /* 5*/ { 30, '\001', 71, 0 }, /* Codeword length 72, ECC length 39, for ND + 1 == 112 */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -57,7 +59,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -75,7 +77,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_options(int index, int debug) { static void test_options(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -90,19 +93,19 @@ static void test_options(int index, int debug) {
int expected_width; int expected_width;
const char *expected_errtxt; const char *expected_errtxt;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { -1, -1, -1, -1, { 0, 0, "" }, "1", 0, 9, 14, "" }, /* 0*/ { -1, -1, -1, -1, { 0, 0, "" }, "1", 0, 9, 14, "" },
/* 1*/ { -1, -1, -1, -1, { 0, 0, "" }, "1234567890", 0, 12, 19, "" }, /* 1*/ { -1, -1, -1, -1, { 0, 0, "" }, "1234567890", 0, 12, 19, "" },
/* 2*/ { -1, -1, 19, -1, { 0, 0, "" }, "1234567890", 0, 12, 19, "" }, /* 2*/ { -1, -1, 19, -1, { 0, 0, "" }, "1234567890", 0, 12, 19, "" },
/* 3*/ { -1, -1, 12, -1, { 0, 0, "" }, "1234567890", 0, 19, 12, "" }, /* 3*/ { -1, -1, 12, -1, { 0, 0, "" }, "1234567890", 0, 19, 12, "" },
/* 4*/ { -1, -1, 5, -1, { 0, 0, "" }, "1234567890", 0, 44, 5, "" }, /* 4*/ { -1, -1, 5, -1, { 0, 0, "" }, "1234567890", 0, 44, 5, "" },
/* 5*/ { -1, -1, 4, -1, { 0, 0, "" }, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 529: Symbol width 4 is too small" }, // Cols < 5 /* 5*/ { -1, -1, 4, -1, { 0, 0, "" }, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 529: Symbol width 4 is too small" }, /* Cols < 5 */
/* 6*/ { -1, -1, 200, -1, { 0, 0, "" }, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 529: Symbol height 3 is too small" }, // Not enough data - height 3 too small /* 6*/ { -1, -1, 200, -1, { 0, 0, "" }, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 529: Symbol height 3 is too small" }, /* Not enough data - height 3 too small */
/* 7*/ { -1, -1, 200, -1, { 0, 0, "" }, "1234567890123456789012345678901234567890", 0, 5, 200, "" }, // Cols 200 max /* 7*/ { -1, -1, 200, -1, { 0, 0, "" }, "1234567890123456789012345678901234567890", 0, 5, 200, "" }, /* Cols 200 max */
/* 8*/ { -1, -1, 200, -1, { 0, 0, "" }, "12345678901234567890123456789012345678901234567890123456789012345678901234567890", 0, 7, 200, "" }, /* 8*/ { -1, -1, 200, -1, { 0, 0, "" }, "12345678901234567890123456789012345678901234567890123456789012345678901234567890", 0, 7, 200, "" },
/* 9*/ { -1, -1, 201, -1, { 0, 0, "" }, "12345678901234567890123456789012345678901234567890123456789012345678901234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 528: Symbol width 201 is too large" }, /* 9*/ { -1, -1, 201, -1, { 0, 0, "" }, "12345678901234567890123456789012345678901234567890123456789012345678901234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 528: Symbol width 201 is too large" },
/* 10*/ { -1, -1, -1, 10 << 8, { 0, 0, "" }, "1", 0, 9, 14, "" }, // Mask > 8 + 1 ignored /* 10*/ { -1, -1, -1, 10 << 8, { 0, 0, "" }, "1", 0, 9, 14, "" }, /* Mask > 8 + 1 ignored */
/* 11*/ { -1, -1, 19, -1, { 0, 0, "" }, "ABCDE", 0, 12, 19, "" }, /* 11*/ { -1, -1, 19, -1, { 0, 0, "" }, "ABCDE", 0, 12, 19, "" },
/* 12*/ { -1, -1, 19, -1, { 35, 35, "" }, "ABCDE", 0, 16, 19, "" }, /* 12*/ { -1, -1, 19, -1, { 35, 35, "" }, "ABCDE", 0, 16, 19, "" },
/* 13*/ { -1, -1, 19, -1, { 1, 1, "" }, "ABCDE", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 730: Structured Append count out of range (2-35)" }, /* 13*/ { -1, -1, 19, -1, { 1, 1, "" }, "ABCDE", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 730: Structured Append count out of range (2-35)" },
@ -118,7 +121,7 @@ static void test_options(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -143,7 +146,8 @@ static void test_options(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int generate, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -210,19 +214,19 @@ static void test_input(int index, int generate, int debug) {
char cmp_buf[32768]; char cmp_buf[32768];
char cmp_msg[1024]; char cmp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_input"); testStart("test_input");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt debug |= ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, data[i].input_mode, data[i].eci, length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, data[i].input_mode, data[i].eci,
-1 /*option_1*/, data[i].option_2, data[i].option_3, -1 /*output_options*/, -1 /*option_1*/, data[i].option_2, data[i].option_3, -1 /*output_options*/,
@ -234,7 +238,7 @@ static void test_input(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, %d, { %d, %d, \"%s\" }, \"%s\", %d, %s, \"%s\", %d, \"%s\" },\n", printf(" /*%3d*/ { %s, %d, %d, %d, { %d, %d, \"%s\" }, \"%s\", %d, %s, \"%s\", %d, \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_2, data[i].option_3, i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_2, data[i].option_3,
data[i].structapp.index, data[i].structapp.count, data[i].structapp.id, data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
@ -278,7 +282,8 @@ static void test_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -296,7 +301,7 @@ static void test_encode(int index, int generate, int debug) {
char *comment; char *comment;
char *expected; char *expected;
}; };
// ISS DotCode, Rev 4.0, DRAFT 0.15, TSC Pre-PR #5, MAY 28, 2019 /* ISS DotCode, Rev 4.0, DRAFT 0.15, TSC Pre-PR #5, MAY 28, 2019 */
struct item data[] = { struct item data[] = {
/* 0*/ { GS1_MODE, 64, -1, { 0, 0, "" }, "[01]00012345678905[17]201231[10]ABC123456", -1, 0, 9, 64, 1, 1, "ISS DotCode Rev 4.0 Figure 1 (left), same", /* 0*/ { GS1_MODE, 64, -1, { 0, 0, "" }, "[01]00012345678905[17]201231[10]ABC123456", -1, 0, 9, 64, 1, 1, "ISS DotCode Rev 4.0 Figure 1 (left), same",
"1010000000101000101010000010000010001010100010101000101000001010" "1010000000101000101010000010000010001010100010101000101000001010"
@ -1076,15 +1081,14 @@ static void test_encode(int index, int generate, int debug) {
char cmp_buf[8192]; char cmp_buf[8192];
char cmp_msg[1024]; char cmp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1097,7 +1101,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %s, { %d, %d, \"%s\" }, \"%s\", %d, %s, %d, %d, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, %s, { %d, %d, \"%s\" }, \"%s\", %d, %s, %d, %d, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_2, testUtilOption3Name(data[i].option_3), i, testUtilInputModeName(data[i].input_mode), data[i].option_2, testUtilOption3Name(data[i].option_3),
data[i].structapp.index, data[i].structapp.count, data[i].structapp.id, data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
@ -1151,7 +1155,8 @@ static void test_encode(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode_segs(int index, int generate, int debug) { static void test_encode_segs(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -1168,7 +1173,7 @@ static void test_encode_segs(int index, int generate, int debug) {
char *comment; char *comment;
char *expected; char *expected;
}; };
// ISS DotCode, Rev 4.0, DRAFT 0.15, TSC Pre-PR #5, MAY 28, 2019 /* ISS DotCode, Rev 4.0, DRAFT 0.15, TSC Pre-PR #5, MAY 28, 2019 */
struct item data[] = { struct item data[] = {
/* 0*/ { UNICODE_MODE, 18, -1, { 0, 0, "" }, { { TU(""), -1, 0 }, { TU("Ж"), -1, 7 }, { TU(""), 0, 0 } }, 0, 13, 18, 1, 1, "ISS DotCode Rev 4.0 13.5 example **NOT SAME** different encodation", /* 0*/ { UNICODE_MODE, 18, -1, { 0, 0, "" }, { { TU(""), -1, 0 }, { TU("Ж"), -1, 7 }, { TU(""), 0, 0 } }, 0, 13, 18, 1, 1, "ISS DotCode Rev 4.0 13.5 example **NOT SAME** different encodation",
"100000001010101010" "100000001010101010"
@ -1455,15 +1460,14 @@ static void test_encode_segs(int index, int generate, int debug) {
char cmp_buf[8192]; char cmp_buf[8192];
char cmp_msg[1024]; char cmp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_encode_segs"); testStart("test_encode_segs");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1478,7 +1482,7 @@ static void test_encode_segs(int index, int generate, int debug) {
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count); ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
char escaped1[4096]; char escaped1[4096];
char escaped2[4096]; char escaped2[4096];
int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length;
@ -1546,8 +1550,9 @@ static void test_encode_segs(int index, int generate, int debug) {
testFinish(); testFinish();
} }
// #181 Christian Hartlage / Nico Gunkel OSS-Fuzz /* #181 Christian Hartlage / Nico Gunkel OSS-Fuzz */
static void test_fuzz(int index, int debug) { static void test_fuzz(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -1555,9 +1560,9 @@ static void test_fuzz(int index, int debug) {
int input_mode; int input_mode;
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "(\207'", -1, DATA_MODE, 0 }, // 0x28,0x87,0x27 Note: should but doesn't trigger sanitize error if no length check, for some reason; UPDATE: use up-to-date gcc (9)! /* 0*/ { "(\207'", -1, DATA_MODE, 0 }, /* 0x28,0x87,0x27 Note: should but doesn't trigger sanitize error if no length check, for some reason; UPDATE: use up-to-date gcc (9)! */
/* 1*/ { /* 1*/ {
"\133\061\106\133\061\106\070\161\116\133\116\116\067\040\116\016\000\116\125\111\125\125\316\125\125\116\116\116\116\117\116\125" "\133\061\106\133\061\106\070\161\116\133\116\116\067\040\116\016\000\116\125\111\125\125\316\125\125\116\116\116\116\117\116\125"
"\111\125\103\316\125\125\116\116\116\116\117\000\000\116\136\116\116\001\116\316\076\116\116\057\136\116\116\134\000\000\116\116" "\111\125\103\316\125\125\116\116\116\116\117\000\000\116\136\116\116\001\116\316\076\116\116\057\136\116\116\134\000\000\116\116"
@ -1572,13 +1577,13 @@ static void test_fuzz(int index, int debug) {
"\330\330\071\071\071\071\071\071\071\071\071\071\071\071\071\071\071\071\065\071\071\071\071\071\071\071\071\071\071\071\071\071" "\330\330\071\071\071\071\071\071\071\071\071\071\071\071\071\071\071\071\065\071\071\071\071\071\071\071\071\071\071\071\071\071"
"\071\071\071\071\071\072\071\071\277\071\071\077\071\071\071\071\071\071\071\071\154\071\071\071\071\071\071\071\071\071\071\071" "\071\071\071\071\071\072\071\071\277\071\071\077\071\071\071\071\071\071\071\071\154\071\071\071\071\071\071\071\071\071\071\071"
"\071\071\071\011\071\071\071\071\071\071\071\071\071\071\071\071\071\071\105\105\105\105\105\105\105\105\105\105\105\105\105\071" "\071\071\071\011\071\071\071\071\071\071\071\071\071\071\071\071\071\071\105\105\105\105\105\105\105\105\105\105\105\105\105\071"
"\071\071\071\071\071", // Original OSS-Fuzz triggering data for index out of bounds (encoding of HT/FS/GS/RS when shifting to code set B) "\071\071\071\071\071", /* Original OSS-Fuzz triggering data for index out of bounds (encoding of HT/FS/GS/RS when shifting to code set B) */
421, DATA_MODE, 0 }, 421, DATA_MODE, 0 },
/* 2*/ { "\233:", -1, DATA_MODE, 0 }, // Original OSS-Fuzz triggering data for codeword_array buffer overflow, L777 /* 2*/ { "\233:", -1, DATA_MODE, 0 }, /* Original OSS-Fuzz triggering data for codeword_array buffer overflow, L777 */
/* 3*/ { "\241\034", -1, DATA_MODE, 0 }, // As above L793 /* 3*/ { "\241\034", -1, DATA_MODE, 0 }, /* As above L793 */
/* 4*/ { "\270\036", -1, DATA_MODE, 0 }, // As above L799 /* 4*/ { "\270\036", -1, DATA_MODE, 0 }, /* As above L799 */
/* 5*/ { "\237\032", -1, DATA_MODE, 0 }, // As above L904 /* 5*/ { "\237\032", -1, DATA_MODE, 0 }, /* As above L904 */
/* 6*/ { "\237", -1, DATA_MODE, 0 }, // As above L1090 /* 6*/ { "\237", -1, DATA_MODE, 0 }, /* As above L1090 */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -1588,7 +1593,7 @@ static void test_fuzz(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1606,10 +1611,10 @@ static void test_fuzz(int index, int debug) {
#define GF 113 #define GF 113
// Dummy to generate pre-calculated coefficients for GF(113) of generator polys of degree 3 to 39 /* Dummy to generate pre-calculated coefficients for GF(113) of generator polys of degree 3 to 39 */
static void test_generate(int generate) { static void test_generate(const testCtx *const p_ctx) {
// roots (antilogs): root[0] = 1; for (i = 1; i < GF - 1; i++) root[i] = (PM * root[i - 1]) % GF; /* roots (antilogs): root[0] = 1; for (i = 1; i < GF - 1; i++) root[i] = (PM * root[i - 1]) % GF; */
static const int root[GF - 1] = { static const int root[GF - 1] = {
1, 3, 9, 27, 81, 17, 51, 40, 7, 21, 1, 3, 9, 27, 81, 17, 51, 40, 7, 21,
63, 76, 2, 6, 18, 54, 49, 34, 102, 80, 63, 76, 2, 6, 18, 54, 49, 34, 102, 80,
@ -1626,11 +1631,11 @@ static void test_generate(int generate) {
}; };
int i, j, nc, cind, ci; int i, j, nc, cind, ci;
// Degree nc has nc + 1 terms /* Degree nc has nc + 1 terms */
char coefs[820 - 5] = {0}; // 40*(41 + 1)/2 == 820 less 2 + 3 (degrees 1 and 2) char coefs[820 - 5] = {0}; /* 40*(41 + 1)/2 == 820 less 2 + 3 (degrees 1 and 2) */
int cinds[39 - 2] = {0}; int cinds[39 - 2] = {0};
if (!generate) { if (!p_ctx->generate) {
return; return;
} }
@ -1665,8 +1670,9 @@ static void test_generate(int generate) {
#define TEST_PERF_ITERATIONS 1000 #define TEST_PERF_ITERATIONS 1000
// Not a real test, just performance indicator /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1702,7 +1708,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_encode = diff_buffer = 0; diff_encode = diff_buffer = 0;
@ -1733,22 +1739,22 @@ static void test_perf(int index, int debug) {
total_encode += diff_encode; total_encode += diff_encode;
total_buffer += diff_buffer; total_buffer += diff_buffer;
} }
if (index != -1) { if (p_ctx->index != -1) {
printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC); printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
} }
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_options", test_options, 1, 0, 1 }, { "test_options", test_options },
{ "test_input", test_input, 1, 1, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_encode_segs", test_encode_segs, 1, 1, 1 }, { "test_encode_segs", test_encode_segs },
{ "test_fuzz", test_fuzz, 1, 0, 1 }, { "test_fuzz", test_fuzz },
{ "test_generate", test_generate, 0, 1, 0 }, { "test_generate", test_generate },
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,13 +27,15 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
#include "../eci.h" #include "../eci.h"
static void test_bom(int debug) { static void test_bom(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
char data[] = "\xEF\xBB\xBF"; // U+FEFF BOM, with U+2039 (only in Windows pages) char data[] = "\xEF\xBB\xBF"; /* U+FEFF BOM, with U+2039 (only in Windows pages) */
char expected[] = char expected[] =
"111111100001001111111" "111111100001001111111"
@ -72,14 +74,14 @@ static void test_bom(int debug) {
symbol->input_mode = UNICODE_MODE; symbol->input_mode = UNICODE_MODE;
symbol->option_1 = 4; symbol->option_1 = 4;
symbol->option_2 = 1; symbol->option_2 = 1;
symbol->option_3 = 5 << 8; // Mask 100 (instead of automatic 010) symbol->option_3 = 5 << 8; /* Mask 100 (instead of automatic 010) */
symbol->debug |= debug; symbol->debug |= debug;
length = (int) strlen(data); length = (int) strlen(data);
ret = ZBarcode_Encode(symbol, (unsigned char *) data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data, length);
assert_equal(ret, ZINT_WARN_USES_ECI, "ZBarcode_Encode ret %d != ZINT_WARN_USES_ECI\n", ret); assert_equal(ret, ZINT_WARN_USES_ECI, "ZBarcode_Encode ret %d != ZINT_WARN_USES_ECI\n", ret);
assert_equal(symbol->eci, 21, "eci %d != 21\n", symbol->eci); // ECI 21 == Windows-1250 assert_equal(symbol->eci, 21, "eci %d != 21\n", symbol->eci); /* ECI 21 == Windows-1250 */
ret = testUtilModulesCmp(symbol, expected, &width, &height); ret = testUtilModulesCmp(symbol, expected, &width, &height);
assert_equal(ret, 0, "testUtilModulesEqual ret %d != 0, width %d, height %d\n", ret, width, height); assert_equal(ret, 0, "testUtilModulesEqual ret %d != 0, width %d, height %d\n", ret, width, height);
@ -89,9 +91,10 @@ static void test_bom(int debug) {
testFinish(); testFinish();
} }
static void test_iso_8859_16(int debug) { static void test_iso_8859_16(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
char data[] = "Ț"; // U+021A only in ISO 8859-16 char data[] = "Ț"; /* U+021A only in ISO 8859-16 */
int length, ret; int length, ret;
struct zint_symbol *symbol; struct zint_symbol *symbol;
@ -108,15 +111,16 @@ static void test_iso_8859_16(int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data, length);
assert_equal(ret, ZINT_WARN_USES_ECI, "ZBarcode_Encode ret %d != ZINT_WARN_USES_ECI\n", ret); assert_equal(ret, ZINT_WARN_USES_ECI, "ZBarcode_Encode ret %d != ZINT_WARN_USES_ECI\n", ret);
assert_equal(symbol->eci, 18, "eci %d != 18\n", symbol->eci); // ECI 18 == ISO 8859-16 assert_equal(symbol->eci, 18, "eci %d != 18\n", symbol->eci); /* ECI 18 == ISO 8859-16 */
ZBarcode_Delete(symbol); ZBarcode_Delete(symbol);
testFinish(); testFinish();
} }
// Only testing standard non-extended barcodes here, ie not QRCODE, MICROQR, GRIDMATRIX, HANXIN or UPNQR /* Only testing standard non-extended barcodes here, ie not QRCODE, MICROQR, GRIDMATRIX, HANXIN or UPNQR */
static void test_reduced_charset_input(int index, int debug) { static void test_reduced_charset_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -127,14 +131,16 @@ static void test_reduced_charset_input(int index, int debug) {
int expected_eci; int expected_eci;
char *comment; char *comment;
}; };
// é 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 /*
// β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in Shift JIS é 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
// ก U+0E01 in ISO 8859-11 Thai (but not other ISO 8859 or Win page), not in Shift JIS β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in Shift JIS
// Ж U+0416 in ISO 8859-5 Cyrillic (but not other ISO 8859), Win 1251, in Shift JIS U+0E01 in ISO 8859-11 Thai (but not other ISO 8859 or Win page), not in Shift JIS
// ກ U+0E81 Lao not in any ISO 8859 (or Win page) or Shift JIS Ж U+0416 in ISO 8859-5 Cyrillic (but not other ISO 8859), Win 1251, in Shift JIS
// … U+2026 in Win pages (but not in any ISO 8859) U+0E81 Lao not in any ISO 8859 (or Win page) or Shift JIS
// テ U+30C6 katakana, in Shift JIS U+2026 in Win pages (but not in any ISO 8859)
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) U+30C6 katakana, in Shift JIS
*/
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_CODE11, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "ASCII subset only" }, /* 0*/ { BARCODE_CODE11, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "ASCII subset only" },
/* 1*/ { BARCODE_C25STANDARD, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "Numbers only" }, /* 1*/ { BARCODE_C25STANDARD, UNICODE_MODE, 0, "é", ZINT_ERROR_INVALID_DATA, -1, "Numbers only" },
@ -383,7 +389,7 @@ static void test_reduced_charset_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -430,9 +436,9 @@ static int to_utf8(const unsigned int codepoint, unsigned char *buf) {
return length; return length;
} }
// Original eci.h tables /* Original eci.h tables */
static const unsigned short int iso_8859_1[] = {// Latin alphabet No. 1 static const unsigned short int iso_8859_1[] = {/* Latin alphabet No. 1 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
@ -443,7 +449,7 @@ static const unsigned short int iso_8859_1[] = {// Latin alphabet No. 1
0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff
}; };
static const unsigned short int iso_8859_2[] = {// Latin alphabet No. 2 static const unsigned short int iso_8859_2[] = {/* Latin alphabet No. 2 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00a0, 0x0104, 0x02d8, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7, 0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b, 0x00a0, 0x0104, 0x02d8, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7, 0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b,
@ -454,7 +460,7 @@ static const unsigned short int iso_8859_2[] = {// Latin alphabet No. 2
0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9
}; };
static const unsigned short int iso_8859_3[] = {// Latin alphabet No. 3 static const unsigned short int iso_8859_3[] = {/* Latin alphabet No. 3 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00a0, 0x0126, 0x02d8, 0x00a3, 0x00a4, 0x0000, 0x0124, 0x00a7, 0x00a8, 0x0130, 0x015e, 0x011e, 0x0134, 0x00ad, 0x0000, 0x017b, 0x00a0, 0x0126, 0x02d8, 0x00a3, 0x00a4, 0x0000, 0x0124, 0x00a7, 0x00a8, 0x0130, 0x015e, 0x011e, 0x0134, 0x00ad, 0x0000, 0x017b,
@ -465,10 +471,10 @@ static const unsigned short int iso_8859_3[] = {// Latin alphabet No. 3
0x0000, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x0121, 0x00f6, 0x00f7, 0x011d, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x016d, 0x015d, 0x02d9 0x0000, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x0121, 0x00f6, 0x00f7, 0x011d, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x016d, 0x015d, 0x02d9
}; };
static const unsigned short int iso_8859_4[] = {// Latin alphabet No. 4 static const unsigned short int iso_8859_4[] = {/* Latin alphabet No. 4 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00a0, 0x0104, 0x0138, 0x0156, 0x00a4, 0x0128, 0x013b, 0x00a7, 0x00a8, 0x0160, 0x0112, 0x0122, 0x0166, 0x00ad, 0x017d, 0x00af, // A5 0x012b -> 0x0128 0x00a0, 0x0104, 0x0138, 0x0156, 0x00a4, 0x0128, 0x013b, 0x00a7, 0x00a8, 0x0160, 0x0112, 0x0122, 0x0166, 0x00ad, 0x017d, 0x00af, /* A5 0x012b -> 0x0128 */
0x00b0, 0x0105, 0x02db, 0x0157, 0x00b4, 0x0129, 0x013c, 0x02c7, 0x00b8, 0x0161, 0x0113, 0x0123, 0x0167, 0x014a, 0x017e, 0x014b, 0x00b0, 0x0105, 0x02db, 0x0157, 0x00b4, 0x0129, 0x013c, 0x02c7, 0x00b8, 0x0161, 0x0113, 0x0123, 0x0167, 0x014a, 0x017e, 0x014b,
0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x012a, 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x012a,
0x0110, 0x0145, 0x014c, 0x0136, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x0168, 0x016a, 0x00df, 0x0110, 0x0145, 0x014c, 0x0136, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x0168, 0x016a, 0x00df,
@ -476,7 +482,7 @@ static const unsigned short int iso_8859_4[] = {// Latin alphabet No. 4
0x0111, 0x0146, 0x014d, 0x0137, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x0169, 0x016b, 0x02d9 0x0111, 0x0146, 0x014d, 0x0137, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x0169, 0x016b, 0x02d9
}; };
static const unsigned short int iso_8859_5[] = {// Latin/Cyrillic alphabet static const unsigned short int iso_8859_5[] = {/* Latin/Cyrillic alphabet */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00a0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x00ad, 0x040e, 0x040f, 0x00a0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x00ad, 0x040e, 0x040f,
@ -487,7 +493,7 @@ static const unsigned short int iso_8859_5[] = {// Latin/Cyrillic alphabet
0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457, 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x00a7, 0x045e, 0x045f 0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457, 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x00a7, 0x045e, 0x045f
}; };
static const unsigned short int iso_8859_6[] = {// Latin/Arabic alphabet static const unsigned short int iso_8859_6[] = {/* Latin/Arabic alphabet */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00a0, 0x0000, 0x0000, 0x0000, 0x00a4, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x060c, 0x00ad, 0x0000, 0x0000, 0x00a0, 0x0000, 0x0000, 0x0000, 0x00a4, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x060c, 0x00ad, 0x0000, 0x0000,
@ -498,7 +504,7 @@ static const unsigned short int iso_8859_6[] = {// Latin/Arabic alphabet
0x0650, 0x0651, 0x0652, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 0x0650, 0x0651, 0x0652, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
}; };
static const unsigned short int iso_8859_7[] = {// Latin/Greek alphabet static const unsigned short int iso_8859_7[] = {/* Latin/Greek alphabet */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00a0, 0x2018, 0x2019, 0x00a3, 0x20ac, 0x20af, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x037a, 0x00ab, 0x00ac, 0x00ad, 0x0000, 0x2015, 0x00a0, 0x2018, 0x2019, 0x00a3, 0x20ac, 0x20af, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x037a, 0x00ab, 0x00ac, 0x00ad, 0x0000, 0x2015,
@ -509,7 +515,7 @@ static const unsigned short int iso_8859_7[] = {// Latin/Greek alphabet
0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, 0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce, 0x0000 0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, 0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce, 0x0000
}; };
static const unsigned short int iso_8859_8[] = {// Latin/Hebrew alphabet static const unsigned short int iso_8859_8[] = {/* Latin/Hebrew alphabet */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00a0, 0x0000, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00d7, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, 0x00a0, 0x0000, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00d7, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
@ -520,7 +526,7 @@ static const unsigned short int iso_8859_8[] = {// Latin/Hebrew alphabet
0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, 0x05e6, 0x05e7, 0x05e8, 0x05e9, 0x05ea, 0x0000, 0x0000, 0x200e, 0x200f, 0x0000 0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, 0x05e6, 0x05e7, 0x05e8, 0x05e9, 0x05ea, 0x0000, 0x0000, 0x200e, 0x200f, 0x0000
}; };
static const unsigned short int iso_8859_9[] = {// Latin alphabet No. 5 static const unsigned short int iso_8859_9[] = {/* Latin alphabet No. 5 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
@ -531,10 +537,10 @@ static const unsigned short int iso_8859_9[] = {// Latin alphabet No. 5
0x011f, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0131, 0x015f, 0x00ff 0x011f, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0131, 0x015f, 0x00ff
}; };
static const unsigned short int iso_8859_10[] = {// Latin alphabet No. 6 static const unsigned short int iso_8859_10[] = {/* Latin alphabet No. 6 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00a0, 0x0104, 0x0112, 0x0122, 0x012a, 0x0128, 0x0136, 0x00a7, 0x013b, 0x0110, 0x0160, 0x0166, 0x017d, 0x00ad, 0x016a, 0x014a, // A5 0x012b -> 0x0128 0x00a0, 0x0104, 0x0112, 0x0122, 0x012a, 0x0128, 0x0136, 0x00a7, 0x013b, 0x0110, 0x0160, 0x0166, 0x017d, 0x00ad, 0x016a, 0x014a, /* A5 0x012b -> 0x0128 */
0x00b0, 0x0105, 0x0113, 0x0123, 0x012b, 0x0129, 0x0137, 0x00b7, 0x013c, 0x0111, 0x0161, 0x0167, 0x017e, 0x2015, 0x016b, 0x014b, 0x00b0, 0x0105, 0x0113, 0x0123, 0x012b, 0x0129, 0x0137, 0x00b7, 0x013c, 0x0111, 0x0161, 0x0167, 0x017e, 0x2015, 0x016b, 0x014b,
0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x00cf, 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x00cf,
0x00d0, 0x0145, 0x014c, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x0168, 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, 0x00d0, 0x0145, 0x014c, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x0168, 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
@ -542,18 +548,18 @@ static const unsigned short int iso_8859_10[] = {// Latin alphabet No. 6
0x00f0, 0x0146, 0x014d, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x0169, 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x0138 0x00f0, 0x0146, 0x014d, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x0169, 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x0138
}; };
static const unsigned short int iso_8859_11[] = {// Latin/Thai alphabet static const unsigned short int iso_8859_11[] = {/* Latin/Thai alphabet */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00a0, 0x0e01, 0x0e02, 0x0e03, 0x0e04, 0x0e05, 0x0e06, 0x0e07, 0x0e08, 0x0e09, 0x0e0a, 0x0e0b, 0x0e0c, 0x0e0d, 0x0e0e, 0x0e0f, 0x00a0, 0x0e01, 0x0e02, 0x0e03, 0x0e04, 0x0e05, 0x0e06, 0x0e07, 0x0e08, 0x0e09, 0x0e0a, 0x0e0b, 0x0e0c, 0x0e0d, 0x0e0e, 0x0e0f,
0x0e10, 0x0e11, 0x0e12, 0x0e13, 0x0e14, 0x0e15, 0x0e16, 0x0e17, 0x0e18, 0x0e19, 0x0e1a, 0x0e1b, 0x0e1c, 0x0e1d, 0x0e1e, 0x0e1f, 0x0e10, 0x0e11, 0x0e12, 0x0e13, 0x0e14, 0x0e15, 0x0e16, 0x0e17, 0x0e18, 0x0e19, 0x0e1a, 0x0e1b, 0x0e1c, 0x0e1d, 0x0e1e, 0x0e1f,
0x0e20, 0x0e21, 0x0e22, 0x0e23, 0x0e24, 0x0e25, 0x0e26, 0x0e27, 0x0e28, 0x0e29, 0x0e2a, 0x0e2b, 0x0e2c, 0x0e2d, 0x0e2e, 0x0e2f, 0x0e20, 0x0e21, 0x0e22, 0x0e23, 0x0e24, 0x0e25, 0x0e26, 0x0e27, 0x0e28, 0x0e29, 0x0e2a, 0x0e2b, 0x0e2c, 0x0e2d, 0x0e2e, 0x0e2f,
0x0e30, 0x0e31, 0x0e32, 0x0e33, 0x0e34, 0x0e35, 0x0e36, 0x0e37, 0x0e38, 0x0e39, 0x0e3a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0e3f, // D5 0x0e36 -> 0x0e35 0x0e30, 0x0e31, 0x0e32, 0x0e33, 0x0e34, 0x0e35, 0x0e36, 0x0e37, 0x0e38, 0x0e39, 0x0e3a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0e3f, /* D5 0x0e36 -> 0x0e35 */
0x0e40, 0x0e41, 0x0e42, 0x0e43, 0x0e44, 0x0e45, 0x0e46, 0x0e47, 0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c, 0x0e4d, 0x0e4e, 0x0e4f, 0x0e40, 0x0e41, 0x0e42, 0x0e43, 0x0e44, 0x0e45, 0x0e46, 0x0e47, 0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c, 0x0e4d, 0x0e4e, 0x0e4f,
0x0e50, 0x0e51, 0x0e52, 0x0e53, 0x0e54, 0x0e55, 0x0e56, 0x0e57, 0x0e58, 0x0e59, 0x0e5a, 0x0e5b, 0x0000, 0x0000, 0x0000, 0x0000 0x0e50, 0x0e51, 0x0e52, 0x0e53, 0x0e54, 0x0e55, 0x0e56, 0x0e57, 0x0e58, 0x0e59, 0x0e5a, 0x0e5b, 0x0000, 0x0000, 0x0000, 0x0000
}; };
static const unsigned short int iso_8859_13[] = {// Latin alphabet No. 7 static const unsigned short int iso_8859_13[] = {/* Latin alphabet No. 7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00a0, 0x201d, 0x00a2, 0x00a3, 0x00a4, 0x201e, 0x00a6, 0x00a7, 0x00d8, 0x00a9, 0x0156, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00c6, 0x00a0, 0x201d, 0x00a2, 0x00a3, 0x00a4, 0x201e, 0x00a6, 0x00a7, 0x00d8, 0x00a9, 0x0156, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00c6,
@ -564,7 +570,7 @@ static const unsigned short int iso_8859_13[] = {// Latin alphabet No. 7
0x0161, 0x0144, 0x0146, 0x00f3, 0x014d, 0x00f5, 0x00f6, 0x00f7, 0x0173, 0x0142, 0x015b, 0x016b, 0x00fc, 0x017c, 0x017e, 0x2019 0x0161, 0x0144, 0x0146, 0x00f3, 0x014d, 0x00f5, 0x00f6, 0x00f7, 0x0173, 0x0142, 0x015b, 0x016b, 0x00fc, 0x017c, 0x017e, 0x2019
}; };
static const unsigned short int iso_8859_14[] = {// Latin alphabet No. 8 (Celtic) static const unsigned short int iso_8859_14[] = {/* Latin alphabet No. 8 (Celtic) */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00a0, 0x1e02, 0x1e03, 0x00a3, 0x010a, 0x010b, 0x1e0a, 0x00a7, 0x1e80, 0x00a9, 0x1e82, 0x1e0b, 0x1ef2, 0x00ad, 0x00ae, 0x0178, 0x00a0, 0x1e02, 0x1e03, 0x00a3, 0x010a, 0x010b, 0x1e0a, 0x00a7, 0x1e80, 0x00a9, 0x1e82, 0x1e0b, 0x1ef2, 0x00ad, 0x00ae, 0x0178,
@ -575,7 +581,7 @@ static const unsigned short int iso_8859_14[] = {// Latin alphabet No. 8 (Celtic
0x0175, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x1e6b, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x0177, 0x00ff 0x0175, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x1e6b, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x0177, 0x00ff
}; };
static const unsigned short int iso_8859_15[] = {// Latin alphabet No. 9 static const unsigned short int iso_8859_15[] = {/* Latin alphabet No. 9 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x20ac, 0x00a5, 0x0160, 0x00a7, 0x0161, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x20ac, 0x00a5, 0x0160, 0x00a7, 0x0161, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
@ -586,7 +592,7 @@ static const unsigned short int iso_8859_15[] = {// Latin alphabet No. 9
0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff
}; };
static const unsigned short int iso_8859_16[] = {// Latin alphabet No. 10 static const unsigned short int iso_8859_16[] = {/* Latin alphabet No. 10 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00a0, 0x0104, 0x0105, 0x0141, 0x20ac, 0x201e, 0x0160, 0x00a7, 0x0161, 0x00a9, 0x0218, 0x00ab, 0x0179, 0x00ad, 0x017a, 0x017b, 0x00a0, 0x0104, 0x0105, 0x0141, 0x20ac, 0x201e, 0x0160, 0x00a7, 0x0161, 0x00a9, 0x0218, 0x00ab, 0x0179, 0x00ad, 0x017a, 0x017b,
@ -600,7 +606,7 @@ static const unsigned short int iso_8859_16[] = {// Latin alphabet No. 10
static const unsigned short int windows_1250[] = { static const unsigned short int windows_1250[] = {
0x20ac, 0x0000, 0x201a, 0x0000, 0x201e, 0x2026, 0x2020, 0x2021, 0x0000, 0x2030, 0x0160, 0x2039, 0x015a, 0x0164, 0x017d, 0x0179, 0x20ac, 0x0000, 0x201a, 0x0000, 0x201e, 0x2026, 0x2020, 0x2021, 0x0000, 0x2030, 0x0160, 0x2039, 0x015a, 0x0164, 0x017d, 0x0179,
0x0000, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x0000, 0x2122, 0x0161, 0x203a, 0x015b, 0x0165, 0x017e, 0x017a, 0x0000, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x0000, 0x2122, 0x0161, 0x203a, 0x015b, 0x0165, 0x017e, 0x017a,
0x00a0, 0x02c7, 0x02d8, 0x0141, 0x00a4, 0x0104, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x015e, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x017b, // A2 0x02db -> 0x02d8 0x00a0, 0x02c7, 0x02d8, 0x0141, 0x00a4, 0x0104, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x015e, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x017b, /* A2 0x02db -> 0x02d8 */
0x00b0, 0x00b1, 0x02db, 0x0142, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x0105, 0x015f, 0x00bb, 0x013d, 0x02dd, 0x013e, 0x017c, 0x00b0, 0x00b1, 0x02db, 0x0142, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x0105, 0x015f, 0x00bb, 0x013d, 0x02dd, 0x013e, 0x017c,
0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e,
0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df,
@ -641,13 +647,13 @@ static const unsigned short int windows_1256[] = {
0x064b, 0x064c, 0x064d, 0x064e, 0x00f4, 0x064f, 0x0650, 0x00f7, 0x0651, 0x00f9, 0x0652, 0x00fb, 0x00fc, 0x200e, 0x200f, 0x06d2 0x064b, 0x064c, 0x064d, 0x064e, 0x00f4, 0x064f, 0x0650, 0x00f7, 0x0651, 0x00f9, 0x0652, 0x00fb, 0x00fc, 0x200e, 0x200f, 0x06d2
}; };
static void test_utf8_to_eci_sb(int index) { static void test_utf8_to_eci_sb(const testCtx *const p_ctx) {
struct item { struct item {
int eci; int eci;
const unsigned short *tab; const unsigned short *tab;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { 3, iso_8859_1 }, /* 0*/ { 3, iso_8859_1 },
/* 1*/ { 4, iso_8859_2 }, /* 1*/ { 4, iso_8859_2 },
@ -680,7 +686,7 @@ static void test_utf8_to_eci_sb(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
for (j = 0; j < 128; j++) { for (j = 0; j < 128; j++) {
int k = j + 128; int k = j + 128;
@ -694,7 +700,7 @@ static void test_utf8_to_eci_sb(int index) {
length = to_utf8(k, source); length = to_utf8(k, source);
assert_nonzero(length, "i:%d to_utf8 length %d == 0\n", i, length); assert_nonzero(length, "i:%d to_utf8 length %d == 0\n", i, length);
ret = utf8_to_eci(data[i].eci, source, dest, &length); ret = utf8_to_eci(data[i].eci, source, dest, &length);
if (ret == 0) { // Should be mapping for this codepoint in another entry if (ret == 0) { /* Should be mapping for this codepoint in another entry */
int found = 0; int found = 0;
int m; int m;
for (m = 0; m < 128; m++) { for (m = 0; m < 128; m++) {
@ -714,7 +720,7 @@ static void test_utf8_to_eci_sb(int index) {
testFinish(); testFinish();
} }
static void test_utf8_to_eci_ascii(void) { static void test_utf8_to_eci_ascii(const testCtx *const p_ctx) {
struct item { struct item {
int eci; int eci;
@ -722,7 +728,7 @@ static void test_utf8_to_eci_ascii(void) {
int length; int length;
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 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 }, /* 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 },
/* 1*/ { 27, " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0 }, /* 1*/ { 27, " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0 },
@ -758,6 +764,9 @@ static void test_utf8_to_eci_ascii(void) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int out_length; int out_length;
if (testContinue(p_ctx, i)) continue;
length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
out_length = length; out_length = length;
ret = utf8_to_eci(data[i].eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); ret = utf8_to_eci(data[i].eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length);
@ -771,7 +780,7 @@ static void test_utf8_to_eci_ascii(void) {
testFinish(); testFinish();
} }
static void test_utf8_to_eci_utf16be(void) { static void test_utf8_to_eci_utf16be(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -780,23 +789,23 @@ static void test_utf8_to_eci_utf16be(void) {
int expected_length; int expected_length;
char *expected; char *expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 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 }, /* 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 },
/* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 * 2, NULL }, /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 * 2, NULL },
/* 2*/ { "\302\200\357\277\277", -1, 0, 4, "\000\200\377\377" }, // U+0080 U+FFFF /* 2*/ { "\302\200\357\277\277", -1, 0, 4, "\000\200\377\377" }, /* U+0080 U+FFFF */
/* 3*/ { "\357\277\276", -1, 0, 2, "\377\376" }, // U+FFFE (reversed BOM) allowed /* 3*/ { "\357\277\276", -1, 0, 2, "\377\376" }, /* U+FFFE (reversed BOM) allowed */
/* 4*/ { "\357\273\277", -1, 0, 2, "\376\377" }, // U+FEFF (BOM) allowed /* 4*/ { "\357\273\277", -1, 0, 2, "\376\377" }, /* U+FEFF (BOM) allowed */
/* 5*/ { "\355\237\277", -1, 0, 2, "\327\377" }, // U+D7FF (ed9fbf) /* 5*/ { "\355\237\277", -1, 0, 2, "\327\377" }, /* U+D7FF (ed9fbf) */
/* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, // U+D800 (eda080) surrogate half not allowed /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* U+D800 (eda080) surrogate half not allowed */
/* 7*/ { "\355\277\277", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, // U+DFFF (edbfbf) surrogate half not allowed /* 7*/ { "\355\277\277", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* U+DFFF (edbfbf) surrogate half not allowed */
/* 8*/ { "\356\200\200", -1, 0, 2, "\340\000" }, // U+E000 (ee8080) /* 8*/ { "\356\200\200", -1, 0, 2, "\340\000" }, /* U+E000 (ee8080) */
/* 9*/ { "\360\220\200\200", -1, 0, 4, "\330\000\334\000" }, // U+10000 maps to surrogate pair /* 9*/ { "\360\220\200\200", -1, 0, 4, "\330\000\334\000" }, /* U+10000 maps to surrogate pair */
/* 10*/ { "\360\220\217\277", -1, 0, 4, "\330\000\337\377" }, // U+103FF maps to surrogate pair /* 10*/ { "\360\220\217\277", -1, 0, 4, "\330\000\337\377" }, /* U+103FF maps to surrogate pair */
/* 11*/ { "\364\200\200\200", -1, 0, 4, "\333\300\334\000" }, // U+100000 maps to surrogate pair /* 11*/ { "\364\200\200\200", -1, 0, 4, "\333\300\334\000" }, /* U+100000 maps to surrogate pair */
/* 12*/ { "\364\217\260\200", -1, 0, 4, "\333\377\334\000" }, // U+10FC00 maps to surrogate pair /* 12*/ { "\364\217\260\200", -1, 0, 4, "\333\377\334\000" }, /* U+10FC00 maps to surrogate pair */
/* 13*/ { "\364\217\277\277", -1, 0, 4, "\333\377\337\377" }, // U+10FFFF maps to surrogate pair /* 13*/ { "\364\217\277\277", -1, 0, 4, "\333\377\337\377" }, /* U+10FFFF maps to surrogate pair */
/* 14*/ { "\364\220\200\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, // Non-Unicode 0x110000 not allowed /* 14*/ { "\364\220\200\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* Non-Unicode 0x110000 not allowed */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -808,6 +817,8 @@ static void test_utf8_to_eci_utf16be(void) {
int out_length, eci_length; int out_length, eci_length;
char dest[1024]; char dest[1024];
if (testContinue(p_ctx, i)) continue;
length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
out_length = length; out_length = length;
eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
@ -834,7 +845,7 @@ static void test_utf8_to_eci_utf16be(void) {
testFinish(); testFinish();
} }
static void test_utf8_to_eci_utf16le(void) { static void test_utf8_to_eci_utf16le(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -843,23 +854,23 @@ static void test_utf8_to_eci_utf16le(void) {
int expected_length; int expected_length;
char *expected; char *expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 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 }, /* 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 },
/* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 * 2, NULL }, /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 * 2, NULL },
/* 2*/ { "\302\200\357\277\277", -1, 0, 4, "\200\000\377\377" }, // U+0080 U+FFFF /* 2*/ { "\302\200\357\277\277", -1, 0, 4, "\200\000\377\377" }, /* U+0080 U+FFFF */
/* 3*/ { "\357\277\276", -1, 0, 2, "\376\377" }, // U+FFFE (reversed BOM) allowed /* 3*/ { "\357\277\276", -1, 0, 2, "\376\377" }, /* U+FFFE (reversed BOM) allowed */
/* 4*/ { "\357\273\277", -1, 0, 2, "\377\376" }, // U+FEFF (BOM) allowed /* 4*/ { "\357\273\277", -1, 0, 2, "\377\376" }, /* U+FEFF (BOM) allowed */
/* 5*/ { "\355\237\277", -1, 0, 2, "\377\327" }, // U+D7FF (ed9fbf) /* 5*/ { "\355\237\277", -1, 0, 2, "\377\327" }, /* U+D7FF (ed9fbf) */
/* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, // U+D800 (eda080) surrogate half not allowed /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* U+D800 (eda080) surrogate half not allowed */
/* 7*/ { "\355\277\277", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, // U+DFFF (edbfbf) surrogate half not allowed /* 7*/ { "\355\277\277", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* U+DFFF (edbfbf) surrogate half not allowed */
/* 8*/ { "\356\200\200", -1, 0, 2, "\000\340" }, // U+E000 (ee8080) /* 8*/ { "\356\200\200", -1, 0, 2, "\000\340" }, /* U+E000 (ee8080) */
/* 9*/ { "\360\220\200\200", -1, 0, 4, "\000\330\000\334" }, // U+10000 maps to surrogate pair /* 9*/ { "\360\220\200\200", -1, 0, 4, "\000\330\000\334" }, /* U+10000 maps to surrogate pair */
/* 10*/ { "\360\220\217\277", -1, 0, 4, "\000\330\377\337" }, // U+103FF maps to surrogate pair /* 10*/ { "\360\220\217\277", -1, 0, 4, "\000\330\377\337" }, /* U+103FF maps to surrogate pair */
/* 11*/ { "\364\200\200\200", -1, 0, 4, "\300\333\000\334" }, // U+100000 maps to surrogate pair /* 11*/ { "\364\200\200\200", -1, 0, 4, "\300\333\000\334" }, /* U+100000 maps to surrogate pair */
/* 12*/ { "\364\217\260\200", -1, 0, 4, "\377\333\000\334" }, // U+10FC00 maps to surrogate pair /* 12*/ { "\364\217\260\200", -1, 0, 4, "\377\333\000\334" }, /* U+10FC00 maps to surrogate pair */
/* 13*/ { "\364\217\277\277", -1, 0, 4, "\377\333\377\337" }, // U+10FFFF maps to surrogate pair /* 13*/ { "\364\217\277\277", -1, 0, 4, "\377\333\377\337" }, /* U+10FFFF maps to surrogate pair */
/* 14*/ { "\364\220\200\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, // Non-Unicode 0x110000 not allowed /* 14*/ { "\364\220\200\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* Non-Unicode 0x110000 not allowed */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -871,6 +882,8 @@ static void test_utf8_to_eci_utf16le(void) {
int out_length, eci_length; int out_length, eci_length;
char dest[1024]; char dest[1024];
if (testContinue(p_ctx, i)) continue;
length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
out_length = length; out_length = length;
eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
@ -897,7 +910,7 @@ static void test_utf8_to_eci_utf16le(void) {
testFinish(); testFinish();
} }
static void test_utf8_to_eci_utf32be(void) { static void test_utf8_to_eci_utf32be(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -906,20 +919,20 @@ static void test_utf8_to_eci_utf32be(void) {
int expected_length; int expected_length;
char *expected; char *expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 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 }, /* 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 },
/* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 * 4, NULL }, /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 * 4, NULL },
/* 2*/ { "\302\200\357\277\277", -1, 0, 8, "\000\000\000\200\000\000\377\377" }, // U+0080 U+FFFF /* 2*/ { "\302\200\357\277\277", -1, 0, 8, "\000\000\000\200\000\000\377\377" }, /* U+0080 U+FFFF */
/* 3*/ { "\357\277\276", -1, 0, 4, "\000\000\377\376" }, // U+FFFE (reversed BOM) allowed /* 3*/ { "\357\277\276", -1, 0, 4, "\000\000\377\376" }, /* U+FFFE (reversed BOM) allowed */
/* 4*/ { "\357\273\277", -1, 0, 4, "\000\000\376\377" }, // U+FEFF (BOM) allowed /* 4*/ { "\357\273\277", -1, 0, 4, "\000\000\376\377" }, /* U+FEFF (BOM) allowed */
/* 5*/ { "\355\237\277", -1, 0, 4, "\000\000\327\377" }, // U+D7FF (ed9fbf) /* 5*/ { "\355\237\277", -1, 0, 4, "\000\000\327\377" }, /* U+D7FF (ed9fbf) */
/* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, // U+D800 (eda080) surrogate half not allowed /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* U+D800 (eda080) surrogate half not allowed */
/* 7*/ { "\355\277\277", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, // U+DFFF (edbfbf) surrogate half not allowed /* 7*/ { "\355\277\277", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* U+DFFF (edbfbf) surrogate half not allowed */
/* 8*/ { "\356\200\200", -1, 0, 4, "\000\000\340\000" }, // U+E000 (ee8080) /* 8*/ { "\356\200\200", -1, 0, 4, "\000\000\340\000" }, /* U+E000 (ee8080) */
/* 9*/ { "\360\220\200\200", -1, 0, 4, "\000\001\000\000" }, // U+10000 /* 9*/ { "\360\220\200\200", -1, 0, 4, "\000\001\000\000" }, /* U+10000 */
/* 10*/ { "\364\217\277\277", -1, 0, 4, "\000\020\377\377" }, // U+10FFFF /* 10*/ { "\364\217\277\277", -1, 0, 4, "\000\020\377\377" }, /* U+10FFFF */
/* 11*/ { "\364\220\200\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, // Non-Unicode 0x110000 not allowed /* 11*/ { "\364\220\200\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* Non-Unicode 0x110000 not allowed */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -931,6 +944,8 @@ static void test_utf8_to_eci_utf32be(void) {
int out_length, eci_length; int out_length, eci_length;
char dest[1024]; char dest[1024];
if (testContinue(p_ctx, i)) continue;
length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
out_length = length; out_length = length;
eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
@ -959,7 +974,7 @@ static void test_utf8_to_eci_utf32be(void) {
testFinish(); testFinish();
} }
static void test_utf8_to_eci_utf32le(void) { static void test_utf8_to_eci_utf32le(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -968,20 +983,20 @@ static void test_utf8_to_eci_utf32le(void) {
int expected_length; int expected_length;
char *expected; char *expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 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 }, /* 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 },
/* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 * 4, NULL }, /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 * 4, NULL },
/* 2*/ { "\302\200\357\277\277", -1, 0, 8, "\200\000\000\000\377\377\000\000" }, // U+0080 U+FFFF /* 2*/ { "\302\200\357\277\277", -1, 0, 8, "\200\000\000\000\377\377\000\000" }, /* U+0080 U+FFFF */
/* 3*/ { "\357\277\276", -1, 0, 4, "\376\377\000\000" }, // U+FFFE (reversed BOM) allowed /* 3*/ { "\357\277\276", -1, 0, 4, "\376\377\000\000" }, /* U+FFFE (reversed BOM) allowed */
/* 4*/ { "\357\273\277", -1, 0, 4, "\377\376\000\000" }, // U+FEFF (BOM) allowed /* 4*/ { "\357\273\277", -1, 0, 4, "\377\376\000\000" }, /* U+FEFF (BOM) allowed */
/* 5*/ { "\355\237\277", -1, 0, 4, "\377\327\000\000" }, // U+D7FF (ed9fbf) /* 5*/ { "\355\237\277", -1, 0, 4, "\377\327\000\000" }, /* U+D7FF (ed9fbf) */
/* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, // U+D800 (eda080) surrogate half not allowed /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* U+D800 (eda080) surrogate half not allowed */
/* 7*/ { "\355\277\277", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, // U+DFFF (edbfbf) surrogate half not allowed /* 7*/ { "\355\277\277", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* U+DFFF (edbfbf) surrogate half not allowed */
/* 8*/ { "\356\200\200", -1, 0, 4, "\000\340\000\000" }, // U+E000 (ee8080) /* 8*/ { "\356\200\200", -1, 0, 4, "\000\340\000\000" }, /* U+E000 (ee8080) */
/* 9*/ { "\360\220\200\200", -1, 0, 4, "\000\000\001\000" }, // U+10000 /* 9*/ { "\360\220\200\200", -1, 0, 4, "\000\000\001\000" }, /* U+10000 */
/* 10*/ { "\364\217\277\277", -1, 0, 4, "\377\377\020\000" }, // U+10FFFF /* 10*/ { "\364\217\277\277", -1, 0, 4, "\377\377\020\000" }, /* U+10FFFF */
/* 11*/ { "\364\220\200\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, // Non-Unicode 0x110000 not allowed /* 11*/ { "\364\220\200\200", -1, ZINT_ERROR_INVALID_DATA, -1, NULL }, /* Non-Unicode 0x110000 not allowed */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -993,6 +1008,8 @@ static void test_utf8_to_eci_utf32le(void) {
int out_length, eci_length; int out_length, eci_length;
char dest[1024]; char dest[1024];
if (testContinue(p_ctx, i)) continue;
length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
out_length = length; out_length = length;
eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
@ -1021,7 +1038,7 @@ static void test_utf8_to_eci_utf32le(void) {
testFinish(); testFinish();
} }
static void test_utf8_to_eci_sjis(void) { static void test_utf8_to_eci_sjis(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -1029,25 +1046,25 @@ static void test_utf8_to_eci_sjis(void) {
int ret; int ret;
int expected_length; int expected_length;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 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 }, /* 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 },
/* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\177", 95, 0, 95 + 1 }, // Backslash goes to 2 byte /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\177", 95, 0, 95 + 1 }, /* Backslash goes to 2 byte */
/* 2*/ { "~", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for tilde /* 2*/ { "~", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for tilde */
/* 3*/ { "\302\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+0080 /* 3*/ { "\302\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+0080 */
/* 4*/ { "\302\241", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+00A1 Inverted exclaimation mark /* 4*/ { "\302\241", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+00A1 Inverted exclaimation mark */
/* 5*/ { "\302\245", -1, 0, 1 }, // U+00A5 Yen goes to backslash /* 5*/ { "\302\245", -1, 0, 1 }, /* U+00A5 Yen goes to backslash */
/* 6*/ { "\302\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+00BF Inverted question mark /* 6*/ { "\302\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+00BF Inverted question mark */
/* 7*/ { "\303\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+00C0 À /* 7*/ { "\303\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+00C0 À */
/* 8*/ { "\303\251", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+00E9 é /* 8*/ { "\303\251", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+00E9 é */
/* 9*/ { "\312\262", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+03B2 β /* 9*/ { "\312\262", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+03B2 β */
/* 10*/ { "\342\272\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+2E80 CJK RADICAL REPEAT /* 10*/ { "\342\272\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+2E80 CJK RADICAL REPEAT */
/* 11*/ { "\343\200\200", -1, 0, 2 }, // U+3000 IDEOGRAPHIC SPACE /* 11*/ { "\343\200\200", -1, 0, 2 }, /* U+3000 IDEOGRAPHIC SPACE */
/* 12*/ { "\343\200\204", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+3004 JAPANESE INDUSTRIAL STANDARD SYMBOL /* 12*/ { "\343\200\204", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+3004 JAPANESE INDUSTRIAL STANDARD SYMBOL */
/* 13*/ { "\343\201\201", -1, 0, 2 }, //U+3041 HIRAGANA LETTER SMALL A /* 13*/ { "\343\201\201", -1, 0, 2 }, /*U+3041 HIRAGANA LETTER SMALL A */
/* 14*/ { "\357\277\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+FFFF /* 14*/ { "\357\277\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+FFFF */
/* 15*/ { "\357\277\276", -1, ZINT_ERROR_INVALID_DATA, -1 }, // U+FFFE (reversed BOM) not allowed /* 15*/ { "\357\277\276", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+FFFE (reversed BOM) not allowed */
/* 16*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, // U+D800 surrogate not allowed /* 16*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+D800 surrogate not allowed */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -1059,6 +1076,8 @@ static void test_utf8_to_eci_sjis(void) {
int out_length, eci_length; int out_length, eci_length;
char dest[1024]; char dest[1024];
if (testContinue(p_ctx, i)) continue;
length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
out_length = length; out_length = length;
eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
@ -1075,7 +1094,7 @@ static void test_utf8_to_eci_sjis(void) {
testFinish(); testFinish();
} }
static void test_utf8_to_eci_big5(void) { static void test_utf8_to_eci_big5(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -1083,15 +1102,15 @@ static void test_utf8_to_eci_big5(void) {
int ret; int ret;
int expected_length; int expected_length;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 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 }, /* 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 },
/* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 }, /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 },
/* 2*/ { "\302\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+0080 /* 2*/ { "\302\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+0080 */
/* 3*/ { "\343\200\200", -1, 0, 2 }, // U+3000 IDEOGRAPHIC SPACE /* 3*/ { "\343\200\200", -1, 0, 2 }, /* U+3000 IDEOGRAPHIC SPACE */
/* 4*/ { "\357\277\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+FFFF /* 4*/ { "\357\277\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+FFFF */
/* 5*/ { "\357\277\276", -1, ZINT_ERROR_INVALID_DATA, -1 }, // U+FFFE (reversed BOM) not allowed /* 5*/ { "\357\277\276", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+FFFE (reversed BOM) not allowed */
/* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, // U+D800 surrogate not allowed /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+D800 surrogate not allowed */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -1103,6 +1122,8 @@ static void test_utf8_to_eci_big5(void) {
int out_length, eci_length; int out_length, eci_length;
char dest[1024]; char dest[1024];
if (testContinue(p_ctx, i)) continue;
length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
out_length = length; out_length = length;
eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
@ -1119,7 +1140,7 @@ static void test_utf8_to_eci_big5(void) {
testFinish(); testFinish();
} }
static void test_utf8_to_eci_gb2312(void) { static void test_utf8_to_eci_gb2312(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -1127,15 +1148,15 @@ static void test_utf8_to_eci_gb2312(void) {
int ret; int ret;
int expected_length; int expected_length;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 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 }, /* 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 },
/* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 }, /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 },
/* 2*/ { "\302\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+0080 /* 2*/ { "\302\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+0080 */
/* 3*/ { "\343\200\200", -1, 0, 2 }, // U+3000 IDEOGRAPHIC SPACE /* 3*/ { "\343\200\200", -1, 0, 2 }, /* U+3000 IDEOGRAPHIC SPACE */
/* 4*/ { "\357\277\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+FFFF /* 4*/ { "\357\277\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+FFFF */
/* 5*/ { "\357\277\276", -1, ZINT_ERROR_INVALID_DATA, -1 }, // U+FFFE (reversed BOM) not allowed /* 5*/ { "\357\277\276", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+FFFE (reversed BOM) not allowed */
/* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, // U+D800 surrogate not allowed /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+D800 surrogate not allowed */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -1147,6 +1168,8 @@ static void test_utf8_to_eci_gb2312(void) {
int out_length, eci_length; int out_length, eci_length;
char dest[1024]; char dest[1024];
if (testContinue(p_ctx, i)) continue;
length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
out_length = length; out_length = length;
eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
@ -1163,7 +1186,7 @@ static void test_utf8_to_eci_gb2312(void) {
testFinish(); testFinish();
} }
static void test_utf8_to_eci_euc_kr(void) { static void test_utf8_to_eci_euc_kr(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -1171,15 +1194,15 @@ static void test_utf8_to_eci_euc_kr(void) {
int ret; int ret;
int expected_length; int expected_length;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 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 }, /* 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 },
/* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 }, /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 },
/* 2*/ { "\302\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+0080 /* 2*/ { "\302\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+0080 */
/* 3*/ { "\343\200\200", -1, 0, 2 }, // U+3000 IDEOGRAPHIC SPACE /* 3*/ { "\343\200\200", -1, 0, 2 }, /* U+3000 IDEOGRAPHIC SPACE */
/* 4*/ { "\357\277\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+FFFF /* 4*/ { "\357\277\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+FFFF */
/* 5*/ { "\357\277\276", -1, ZINT_ERROR_INVALID_DATA, -1 }, // U+FFFE (reversed BOM) not allowed /* 5*/ { "\357\277\276", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+FFFE (reversed BOM) not allowed */
/* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, // U+D800 surrogate not allowed /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+D800 surrogate not allowed */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -1191,6 +1214,8 @@ static void test_utf8_to_eci_euc_kr(void) {
int out_length, eci_length; int out_length, eci_length;
char dest[1024]; char dest[1024];
if (testContinue(p_ctx, i)) continue;
length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
out_length = length; out_length = length;
eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
@ -1207,7 +1232,7 @@ static void test_utf8_to_eci_euc_kr(void) {
testFinish(); testFinish();
} }
static void test_utf8_to_eci_gbk(void) { static void test_utf8_to_eci_gbk(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -1215,15 +1240,15 @@ static void test_utf8_to_eci_gbk(void) {
int ret; int ret;
int expected_length; int expected_length;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 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 }, /* 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 },
/* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 }, /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 },
/* 2*/ { "\302\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+0080 /* 2*/ { "\302\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+0080 */
/* 3*/ { "\343\200\200", -1, 0, 2 }, // U+3000 IDEOGRAPHIC SPACE /* 3*/ { "\343\200\200", -1, 0, 2 }, /* U+3000 IDEOGRAPHIC SPACE */
/* 4*/ { "\357\277\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, // No mapping for U+FFFF /* 4*/ { "\357\277\277", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* No mapping for U+FFFF */
/* 5*/ { "\357\277\276", -1, ZINT_ERROR_INVALID_DATA, -1 }, // U+FFFE (reversed BOM) not allowed /* 5*/ { "\357\277\276", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+FFFE (reversed BOM) not allowed */
/* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, // U+D800 surrogate not allowed /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+D800 surrogate not allowed */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -1235,6 +1260,8 @@ static void test_utf8_to_eci_gbk(void) {
int out_length, eci_length; int out_length, eci_length;
char dest[1024]; char dest[1024];
if (testContinue(p_ctx, i)) continue;
length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
out_length = length; out_length = length;
eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
@ -1251,7 +1278,7 @@ static void test_utf8_to_eci_gbk(void) {
testFinish(); testFinish();
} }
static void test_utf8_to_eci_gb18030(void) { static void test_utf8_to_eci_gb18030(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -1259,15 +1286,15 @@ static void test_utf8_to_eci_gb18030(void) {
int ret; int ret;
int expected_length; int expected_length;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 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 }, /* 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 },
/* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 }, /* 1*/ { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177", 96, 0, 96 },
/* 2*/ { "\302\200", -1, 0, 4 }, // Has mapping for U+0080 /* 2*/ { "\302\200", -1, 0, 4 }, /* Has mapping for U+0080 */
/* 3*/ { "\343\200\200", -1, 0, 2 }, // U+3000 IDEOGRAPHIC SPACE /* 3*/ { "\343\200\200", -1, 0, 2 }, /* U+3000 IDEOGRAPHIC SPACE */
/* 4*/ { "\357\277\277", -1, 0, 4 }, // Has mapping for U+FFFF /* 4*/ { "\357\277\277", -1, 0, 4 }, /* Has mapping for U+FFFF */
/* 5*/ { "\357\277\276", -1, 0, 4 }, // U+FFFE (reversed BOM) allowed /* 5*/ { "\357\277\276", -1, 0, 4 }, /* U+FFFE (reversed BOM) allowed */
/* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, // U+D800 surrogate not allowed /* 6*/ { "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, /* U+D800 surrogate not allowed */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -1279,6 +1306,8 @@ static void test_utf8_to_eci_gb18030(void) {
int out_length, eci_length; int out_length, eci_length;
char dest[1024]; char dest[1024];
if (testContinue(p_ctx, i)) continue;
length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
out_length = length; out_length = length;
eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length);
@ -1295,14 +1324,14 @@ static void test_utf8_to_eci_gb18030(void) {
testFinish(); testFinish();
} }
static void test_is_eci_convertible_segs(int index) { static void test_is_eci_convertible_segs(const testCtx *const p_ctx) {
struct item { struct item {
struct zint_seg segs[3]; struct zint_seg segs[3];
int ret; int ret;
int expected_convertible[3]; int expected_convertible[3];
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { { { TU("A"), -1, 0 }, { TU(""), 0, 0 }, { TU(""), 0, 0 } }, 1, { 1, -1, -1 } }, /* 0*/ { { { TU("A"), -1, 0 }, { TU(""), 0, 0 }, { TU(""), 0, 0 } }, 1, { 1, -1, -1 } },
/* 1*/ { { { TU("A"), -1, 26 }, { TU(""), 0, 0 }, { TU(""), 0, 0 } }, 0, { 0, -1, -1 } }, /* 1*/ { { { TU("A"), -1, 26 }, { TU(""), 0, 0 }, { TU(""), 0, 0 } }, 0, { 0, -1, -1 } },
@ -1327,7 +1356,7 @@ static void test_is_eci_convertible_segs(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
for (j = 0, seg_count = 0; j < 3 && data[i].segs[j].length; j++, seg_count++); for (j = 0, seg_count = 0; j < 3 && data[i].segs[j].length; j++, seg_count++);
@ -1343,19 +1372,19 @@ static void test_is_eci_convertible_segs(int index) {
testFinish(); testFinish();
} }
static void test_get_best_eci(int index) { static void test_get_best_eci(const testCtx *const p_ctx) {
struct item { struct item {
const char *data; const char *data;
int length; int length;
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "\300\301", -1, 0 }, /* 0*/ { "\300\301", -1, 0 },
/* 1*/ { "ÀÁ", -1, 3 }, /* 1*/ { "ÀÁ", -1, 3 },
/* 2*/ { "Ђ", -1, 7 }, /* 2*/ { "Ђ", -1, 7 },
/* 3*/ { "Ѐ", -1, 26 }, // Cyrillic U+0400 not in single-byte code pages /* 3*/ { "Ѐ", -1, 26 }, /* Cyrillic U+0400 not in single-byte code pages */
/* 4*/ { "β", -1, 9 }, /* 4*/ { "β", -1, 9 },
/* 5*/ { "˜", -1, 23 }, /* 5*/ { "˜", -1, 23 },
/* 6*/ { "βЂ", -1, 26 }, /* 6*/ { "βЂ", -1, 26 },
@ -1368,7 +1397,7 @@ static void test_get_best_eci(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
@ -1379,22 +1408,22 @@ static void test_get_best_eci(int index) {
testFinish(); testFinish();
} }
static void test_get_best_eci_segs(int index) { static void test_get_best_eci_segs(const testCtx *const p_ctx) {
struct item { struct item {
struct zint_seg segs[3]; struct zint_seg segs[3];
int ret; int ret;
int expected_symbol_eci; int expected_symbol_eci;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { { { TU("\300\301"), -1, 0 }, { TU(""), -1, 0 }, { TU(""), 0, 0 } }, 0, 0 }, /* 0*/ { { { TU("\300\301"), -1, 0 }, { TU(""), -1, 0 }, { TU(""), 0, 0 } }, 0, 0 },
/* 1*/ { { { TU("A"), -1, 0 }, { TU("\300\301"), -1, 0 }, { TU(""), 0, 0 } }, 0, 0 }, /* 1*/ { { { TU("A"), -1, 0 }, { TU("\300\301"), -1, 0 }, { TU(""), 0, 0 } }, 0, 0 },
/* 2*/ { { { TU("A"), -1, 0 }, { TU("ÀÁ"), -1, 0 }, { TU(""), 0, 0 } }, 0, 0 }, // As 1st seg default ECI, 3 not returned /* 2*/ { { { TU("A"), -1, 0 }, { TU("ÀÁ"), -1, 0 }, { TU(""), 0, 0 } }, 0, 0 }, /* As 1st seg default ECI, 3 not returned */
/* 3*/ { { { TU("A"), -1, 4 }, { TU("ÀÁ"), -1, 0 }, { TU(""), 0, 0 } }, 3, 0 }, /* 3*/ { { { TU("A"), -1, 4 }, { TU("ÀÁ"), -1, 0 }, { TU(""), 0, 0 } }, 3, 0 },
/* 4*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 0 }, { TU(""), 0, 0 } }, 7, 0 }, /* 4*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 0 }, { TU(""), 0, 0 } }, 7, 0 },
/* 5*/ { { { TU("A"), -1, 4 }, { TU("Ђ"), -1, 0 }, { TU(""), 0, 0 } }, 7, 0 }, /* 5*/ { { { TU("A"), -1, 4 }, { TU("Ђ"), -1, 0 }, { TU(""), 0, 0 } }, 7, 0 },
/* 6*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 7 }, { TU("Ѐ"), -1, 0 } }, 26, 0 }, // Cyrillic U+0400 not in single-byte code pages /* 6*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 7 }, { TU("Ѐ"), -1, 0 } }, 26, 0 }, /* Cyrillic U+0400 not in single-byte code pages */
/* 7*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 0 }, { TU("β"), -1, 0 } }, 7, 0 }, /* 7*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 0 }, { TU("β"), -1, 0 } }, 7, 0 },
/* 8*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 7 }, { TU("β"), -1, 0 } }, 9, 0 }, /* 8*/ { { { TU("A"), -1, 0 }, { TU("Ђ"), -1, 7 }, { TU("β"), -1, 0 } }, 9, 0 },
/* 9*/ { { { TU("˜"), -1, 0 }, { TU("Ђ"), -1, 7 }, { TU(""), 0, 0 } }, 23, 23 }, /* 9*/ { { { TU("˜"), -1, 0 }, { TU("Ђ"), -1, 7 }, { TU(""), 0, 0 } }, 23, 23 },
@ -1407,7 +1436,7 @@ static void test_get_best_eci_segs(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1429,25 +1458,25 @@ static void test_get_best_eci_segs(int index) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_bom", test_bom, 0, 0, 1 }, { "test_bom", test_bom },
{ "test_iso_8859_16", test_iso_8859_16, 0, 0, 1 }, { "test_iso_8859_16", test_iso_8859_16 },
{ "test_reduced_charset_input", test_reduced_charset_input, 1, 0, 1 }, { "test_reduced_charset_input", test_reduced_charset_input },
{ "test_utf8_to_eci_sb", test_utf8_to_eci_sb, 1, 0, 0 }, { "test_utf8_to_eci_sb", test_utf8_to_eci_sb },
{ "test_utf8_to_eci_ascii", test_utf8_to_eci_ascii, 0, 0, 0 }, { "test_utf8_to_eci_ascii", test_utf8_to_eci_ascii },
{ "test_utf8_to_eci_utf16be", test_utf8_to_eci_utf16be, 0, 0, 0 }, { "test_utf8_to_eci_utf16be", test_utf8_to_eci_utf16be },
{ "test_utf8_to_eci_utf16le", test_utf8_to_eci_utf16le, 0, 0, 0 }, { "test_utf8_to_eci_utf16le", test_utf8_to_eci_utf16le },
{ "test_utf8_to_eci_utf32be", test_utf8_to_eci_utf32be, 0, 0, 0 }, { "test_utf8_to_eci_utf32be", test_utf8_to_eci_utf32be },
{ "test_utf8_to_eci_utf32le", test_utf8_to_eci_utf32le, 0, 0, 0 }, { "test_utf8_to_eci_utf32le", test_utf8_to_eci_utf32le },
{ "test_utf8_to_eci_sjis", test_utf8_to_eci_sjis, 0, 0, 0 }, { "test_utf8_to_eci_sjis", test_utf8_to_eci_sjis },
{ "test_utf8_to_eci_big5", test_utf8_to_eci_big5, 0, 0, 0 }, { "test_utf8_to_eci_big5", test_utf8_to_eci_big5 },
{ "test_utf8_to_eci_gb2312", test_utf8_to_eci_gb2312, 0, 0, 0 }, { "test_utf8_to_eci_gb2312", test_utf8_to_eci_gb2312 },
{ "test_utf8_to_eci_euc_kr", test_utf8_to_eci_euc_kr, 0, 0, 0 }, { "test_utf8_to_eci_euc_kr", test_utf8_to_eci_euc_kr },
{ "test_utf8_to_eci_gbk", test_utf8_to_eci_gbk, 0, 0, 0 }, { "test_utf8_to_eci_gbk", test_utf8_to_eci_gbk },
{ "test_utf8_to_eci_gb18030", test_utf8_to_eci_gb18030, 0, 0, 0 }, { "test_utf8_to_eci_gb18030", test_utf8_to_eci_gb18030 },
{ "test_is_eci_convertible_segs", test_is_eci_convertible_segs, 1, 0, 0 }, { "test_is_eci_convertible_segs", test_is_eci_convertible_segs },
{ "test_get_best_eci", test_get_best_eci, 1, 0, 0 }, { "test_get_best_eci", test_get_best_eci },
{ "test_get_best_eci_segs", test_get_best_eci_segs, 1, 0, 0 }, { "test_get_best_eci_segs", test_get_best_eci_segs },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -1,6 +1,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2020-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -27,12 +27,13 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
#include <sys/stat.h> #include <sys/stat.h>
static void test_print(int index, int generate, int debug) { static void test_print(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -78,13 +79,13 @@ static void test_print(int index, int generate, int debug) {
int escaped_size = 1024; int escaped_size = 1024;
int have_libreoffice = 0; int have_libreoffice = 0;
if (generate) { if (p_ctx->generate) {
have_libreoffice = testUtilHaveLibreOffice(); have_libreoffice = testUtilHaveLibreOffice();
} }
testStart("test_print"); testStart("test_print");
if (generate) { if (p_ctx->generate) {
char data_dir_path[1024]; char data_dir_path[1024];
assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir);
if (!testUtilDirExists(data_dir_path)) { if (!testUtilDirExists(data_dir_path)) {
@ -95,7 +96,7 @@ static void test_print(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -126,7 +127,7 @@ static void test_print(int index, int generate, int debug) {
assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i); assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, %s, %d, %d, %d, %d, \"%s\", \"%s\", %d, \"%s\", \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %s, %d, %s, %d, %d, %d, %d, \"%s\", \"%s\", %d, \"%s\", \"%s\", \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].border_width, i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].border_width,
testUtilOutputOptionsName(data[i].output_options), data[i].whitespace_width, data[i].whitespace_height, testUtilOutputOptionsName(data[i].output_options), data[i].whitespace_width, data[i].whitespace_height,
@ -135,8 +136,8 @@ static void test_print(int index, int generate, int debug) {
ret = testUtilRename(symbol->outfile, expected_file); ret = testUtilRename(symbol->outfile, expected_file);
assert_zero(ret, "i:%d testUtilRename(%s, %s) ret %d != 0\n", i, symbol->outfile, expected_file, ret); assert_zero(ret, "i:%d testUtilRename(%s, %s) ret %d != 0\n", i, symbol->outfile, expected_file, ret);
if (have_libreoffice) { if (have_libreoffice) {
// Note this will fail (on Ubuntu anyway) if LibreOffice Base/Calc/Impress/Writer running (i.e. anything but LibreOffice Draw) /* Note this will fail (on Ubuntu anyway) if LibreOffice Base/Calc/Impress/Writer running (i.e. anything but LibreOffice Draw)
// Doesn't seem to be a way to force Draw invocation through the command line Doesn't seem to be a way to force Draw invocation through the command line */
ret = testUtilVerifyLibreOffice(expected_file, debug); ret = testUtilVerifyLibreOffice(expected_file, debug);
assert_zero(ret, "i:%d %s libreoffice %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret); assert_zero(ret, "i:%d %s libreoffice %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret);
} }
@ -146,7 +147,7 @@ static void test_print(int index, int generate, int debug) {
ret = testUtilCmpBins(symbol->outfile, expected_file); ret = testUtilCmpBins(symbol->outfile, expected_file);
assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret); assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
if (index == -1) assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile); if (p_ctx->index == -1) assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
} }
ZBarcode_Delete(symbol); ZBarcode_Delete(symbol);
@ -157,11 +158,13 @@ static void test_print(int index, int generate, int debug) {
INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle); INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle);
static void test_outfile(void) { static void test_outfile(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol symbol = {0}; struct zint_symbol symbol = {0};
struct zint_vector vector = {0}; struct zint_vector vector = {0};
(void)p_ctx;
testStart("test_outfile"); testStart("test_outfile");
symbol.symbology = BARCODE_CODE128; symbol.symbology = BARCODE_CODE128;
@ -187,9 +190,9 @@ static void test_outfile(void) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_print", test_print, 1, 1, 1 }, { "test_print", test_print },
{ "test_outfile", test_outfile, 0, 0, 0 }, { "test_outfile", test_outfile },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
@ -198,3 +201,5 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -27,13 +27,14 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
#include "test_gb18030_tab.h" #include "test_gb18030_tab.h"
#include "test_gbk_tab.h" #include "test_gbk_tab.h"
#include "../eci.h" #include "../eci.h"
/* For local "private" testing using previous libiconv adaptation, not included for licensing reasons */ /* For local "private" testing using previous libiconv adaptation, not included for licensing reasons */
//#define TEST_JUST_SAY_GNO /* #define TEST_JUST_SAY_GNO */
#ifdef TEST_JUST_SAY_GNO #ifdef TEST_JUST_SAY_GNO
#include "../just_say_gno/gb18030_gnu.c" #include "../just_say_gno/gb18030_gnu.c"
#include "../just_say_gno/gb2312_gnu.c" #include "../just_say_gno/gb2312_gnu.c"
@ -41,29 +42,30 @@
INTERNAL int u_gb18030_int_test(const unsigned int u, unsigned int *dest1, unsigned int *dest2); INTERNAL int u_gb18030_int_test(const unsigned int u, unsigned int *dest1, unsigned int *dest2);
// As control convert to GB 18030 using table generated from GB18030.TXT plus simple processing. /* As control convert to GB 18030 using table generated from GB18030.TXT plus simple processing.
// The version of GB18030.TXT is jdk-1.4.2/GB18030.TXT taken from The version of GB18030.TXT is jdk-1.4.2/GB18030.TXT taken from
// https://haible.de/bruno/charsets/conversion-tables/GB18030.html https://haible.de/bruno/charsets/conversion-tables/GB18030.html
// The generated file backend/tests/test_gb18030_tab.h does not include U+10000..10FFFF codepoints to save space. The generated file backend/tests/test_gb18030_tab.h does not include U+10000..10FFFF codepoints to save space.
// See also backend/tests/tools/data/GB18030.TXT.README and backend/tests/tools/gen_test_tab.php. See also backend/tests/tools/data/GB18030.TXT.README and backend/tests/tools/gen_test_tab.php.
*/
static int u_gb18030_int2(unsigned int u, unsigned int *dest1, unsigned int *dest2) { static int u_gb18030_int2(unsigned int u, unsigned int *dest1, unsigned int *dest2) {
unsigned int c; unsigned int c;
int tab_length, start_i, end_i; int tab_length, start_i, end_i;
int i; int i;
// GB18030 two-byte extension /* GB18030 two-byte extension */
if (u == 0x1E3F) { // GB 18030-2005 change, was PUA U+E7C7 below, see Table 3-39, p.111, Lunde 2nd ed. if (u == 0x1E3F) { /* GB 18030-2005 change, was PUA U+E7C7 below, see Table 3-39, p.111, Lunde 2nd ed. */
*dest1 = 0xA8BC; *dest1 = 0xA8BC;
return 2; return 2;
} }
// GB18030 four-byte extension /* GB18030 four-byte extension */
if (u == 0xE7C7) { // PUA if (u == 0xE7C7) { /* PUA */
*dest1 = 0x8135; *dest1 = 0x8135;
*dest2 = 0xF437; *dest2 = 0xF437;
return 4; return 4;
} }
// GB18030 two-byte extension /* GB18030 two-byte extension */
if (u >= 0x9FB4 && u <= 0x9FBB) { // GB 18030-2005 change, were PUA, see Table 3-37, p.108, Lunde 2nd ed. if (u >= 0x9FB4 && u <= 0x9FBB) { /* GB 18030-2005 change, were PUA, see Table 3-37, p.108, Lunde 2nd ed. */
if (u == 0x9FB4) { if (u == 0x9FB4) {
*dest1 = 0xFE59; *dest1 = 0xFE59;
} else if (u == 0x9FB5) { } else if (u == 0x9FB5) {
@ -81,8 +83,8 @@ static int u_gb18030_int2(unsigned int u, unsigned int *dest1, unsigned int *des
} }
return 2; return 2;
} }
// GB18030 two-byte extension /* GB18030 two-byte extension */
if (u >= 0xFE10 && u <= 0xFE19) { // GB 18030-2005 change, were PUA, see Table 3-37, p.108, Lunde 2nd ed. if (u >= 0xFE10 && u <= 0xFE19) { /* GB 18030-2005 change, were PUA, see Table 3-37, p.108, Lunde 2nd ed. */
if (u == 0xFE10) { if (u == 0xFE10) {
*dest1 = 0xA6D9; *dest1 = 0xA6D9;
} else if (u == 0xFE11) { } else if (u == 0xFE11) {
@ -98,8 +100,8 @@ static int u_gb18030_int2(unsigned int u, unsigned int *dest1, unsigned int *des
} }
return 2; return 2;
} }
// GB18030 four-byte extension /* GB18030 four-byte extension */
if (u >= 0xFE1A && u <= 0xFE2F) { // These are Vertical Forms (U+FE1A..FE1F unassigned) and Combining Half Marks (U+FE20..FE2F) if (u >= 0xFE1A && u <= 0xFE2F) { /* These are Vertical Forms (U+FE1A..FE1F unassigned) and Combining Half Marks (U+FE20..FE2F) */
if (u >= 0xFE1A && u <= 0xFE1D) { if (u >= 0xFE1A && u <= 0xFE1D) {
c = 0x84318336 + (u - 0xFE1A); c = 0x84318336 + (u - 0xFE1A);
} else if (u >= 0xFE1E && u <= 0xFE27) { } else if (u >= 0xFE1E && u <= 0xFE27) {
@ -111,9 +113,9 @@ static int u_gb18030_int2(unsigned int u, unsigned int *dest1, unsigned int *des
*dest2 = c & 0xFFFF; *dest2 = c & 0xFFFF;
return 4; return 4;
} }
// GB18030 /* GB18030 */
// Code set 3 (Unicode U+10000..U+10FFFF) /* Code set 3 (Unicode U+10000..U+10FFFF) */
if (u >= 0x10000 /*&& u < 0x10400*/) { // Not being called for U+10400..U+10FFFF if (u >= 0x10000 /*&& u < 0x10400*/) { /* Not being called for U+10400..U+10FFFF */
c = u - 0x10000; c = u - 0x10000;
*dest1 = 0x9030; *dest1 = 0x9030;
*dest2 = 0x8130 + (c % 10) + 0x100 * (c / 10); *dest2 = 0x8130 + (c % 10) + 0x100 * (c / 10);
@ -147,7 +149,8 @@ static int u_gb18030_int2(unsigned int u, unsigned int *dest1, unsigned int *des
#define TEST_INT_PERF_ITERATIONS 250 #define TEST_INT_PERF_ITERATIONS 250
#endif #endif
static void test_u_gb18030_int(int debug) { static void test_u_gb18030_int(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
int ret, ret2; int ret, ret2;
unsigned int val1_1, val1_2, val2_1, val2_2; unsigned int val1_1, val1_2, val2_1, val2_2;
@ -176,8 +179,8 @@ static void test_u_gb18030_int(int debug) {
} }
#endif #endif
for (i = 0; i < 0x10400; i++) { // Don't bother with U+10400..U+10FFFF, programmatically filled for (i = 0; i < 0x10400; i++) { /* Don't bother with U+10400..U+10FFFF, programmatically filled */
if (i >= 0xD800 && i <= 0xDFFF) { // UTF-16 surrogates if (i >= 0xD800 && i <= 0xDFFF) { /* UTF-16 surrogates */
continue; continue;
} }
val1_1 = val1_2 = val2_1 = val2_2 = 0; val1_1 = val1_2 = val2_1 = val2_2 = 0;
@ -214,7 +217,7 @@ static void test_u_gb18030_int(int debug) {
#endif #endif
} }
// u_gb18030() assumes valid Unicode so now returns a nonsense value here /* u_gb18030() assumes valid Unicode so now returns a nonsense value here */
val1_1 = val1_2 = 0; val1_1 = val1_2 = 0;
ret = u_gb18030_int_test(0x110000, &val1_1, &val1_2); /* Invalid Unicode codepoint */ ret = u_gb18030_int_test(0x110000, &val1_1, &val1_2); /* Invalid Unicode codepoint */
assert_equal(ret, 4, "0x110000 ret %d != 4, val1_1 0x%04X, val1_2 0x%04X\n", ret, val1_1, val1_2); assert_equal(ret, 4, "0x110000 ret %d != 4, val1_1 0x%04X, val1_2 0x%04X\n", ret, val1_1, val1_2);
@ -237,7 +240,7 @@ static void test_u_gb18030_int(int debug) {
testFinish(); testFinish();
} }
static void test_gb18030_utf8(int index) { static void test_gb18030_utf8(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -247,15 +250,17 @@ static void test_gb18030_utf8(int index) {
unsigned int expected_gbdata[30]; unsigned int expected_gbdata[30];
char *comment; char *comment;
}; };
// é 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, in GB 18030 0xA8A6, UTF-8 C3A9 /*
// β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in GB 18030 0xA6C2, UTF-8 CEB2 é 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, in GB 18030 0xA8A6, UTF-8 C3A9
// ¤ U+00A4 in ISO 8859-1 plus other ISO 8859 (but not in ISO 8859-7 or ISO 8859-11), Win 1250 plus other Win, in GB 18030 0xA1E8, UTF-8 C2A4 β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in GB 18030 0xA6C2, UTF-8 CEB2
// ¥ U+00A5 in ISO 8859-1 0xA5, in GB 18030 4-byte 0x81308436, UTF-8 C2A5 ¤ U+00A4 in ISO 8859-1 plus other ISO 8859 (but not in ISO 8859-7 or ISO 8859-11), Win 1250 plus other Win, in GB 18030 0xA1E8, UTF-8 C2A4
// ・ U+30FB katakana middle dot, not in any ISO or Win page, in GB 18030 0xA1A4, duplicate of mapping of U+00B7, UTF-8 E383BB ¥ U+00A5 in ISO 8859-1 0xA5, in GB 18030 4-byte 0x81308436, UTF-8 C2A5
// · U+00B7 middle dot in ISO 8859-1 0xB7, in GB 18030 "GB 18030 subset" 0xA1A4, duplicate of mapping of U+30FB, UTF-8 C2B7 U+30FB katakana middle dot, not in any ISO or Win page, in GB 18030 0xA1A4, duplicate of mapping of U+00B7, UTF-8 E383BB
// ― U+2015 horizontal bar in ISO 8859-7 Greek and ISO 8859-10 Nordic, not in any Win page, in GB 18030 "GB18030.TXT" 0xA1AA, duplicate of mapping of U+2014, UTF-8 E28095 · U+00B7 middle dot in ISO 8859-1 0xB7, in GB 18030 "GB 18030 subset" 0xA1A4, duplicate of mapping of U+30FB, UTF-8 C2B7
// — U+2014 em dash, not in any ISO, in Win 1250 and other Win, in GB 18030 "GB 18030 subset" 0xA1AA, duplicate of mapping of U+2015, UTF-8 E28094 U+2015 horizontal bar in ISO 8859-7 Greek and ISO 8859-10 Nordic, not in any Win page, in GB 18030 "GB18030.TXT" 0xA1AA, duplicate of mapping of U+2014, UTF-8 E28095
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) U+2014 em dash, not in any ISO, in Win 1250 and other Win, in GB 18030 "GB 18030 subset" 0xA1AA, duplicate of mapping of U+2015, UTF-8 E28094
*/
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "é", -1, 0, 1, { 0xA8A6 }, "" }, /* 0*/ { "é", -1, 0, 1, { 0xA8A6 }, "" },
/* 1*/ { "β", -1, 0, 1, { 0xA6C2 }, "" }, /* 1*/ { "β", -1, 0, 1, { 0xA6C2 }, "" },
@ -281,7 +286,7 @@ static void test_gb18030_utf8(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int ret_length; int ret_length;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret_length = length; ret_length = length;
@ -300,7 +305,7 @@ static void test_gb18030_utf8(int index) {
testFinish(); testFinish();
} }
static void test_gb18030_utf8_to_eci(int index) { static void test_gb18030_utf8_to_eci(const testCtx *const p_ctx) {
struct item { struct item {
int eci; int eci;
@ -312,13 +317,15 @@ static void test_gb18030_utf8_to_eci(int index) {
unsigned int expected_gbdata[30]; unsigned int expected_gbdata[30];
char *comment; char *comment;
}; };
// é U+00E9 in ISO 8859-1 0xE9, Win 1250 plus other Win, in HANXIN Chinese mode first byte range 0x81..FE /*
// β U+03B2 in ISO 8859-7 Greek 0xE2 (but not other ISO 8859 or Win page) é U+00E9 in ISO 8859-1 0xE9, Win 1250 plus other Win, in HANXIN Chinese mode first byte range 0x81..FE
// ¥ U+00A5 in ISO 8859-1 0xA5, in first byte range 0x81..FE β U+03B2 in ISO 8859-7 Greek 0xE2 (but not other ISO 8859 or Win page)
// ÿ U+00FF in ISO 8859-1 0xFF, outside first byte and second/third/fourth byte ranges ¥ U+00A5 in ISO 8859-1 0xA5, in first byte range 0x81..FE
// @ U+0040 in ASCII 0x40, outside first byte range, in double-byte second byte range, outside quad-byte second/third/fourth byte ranges ÿ U+00FF in ISO 8859-1 0xFF, outside first byte and second/third/fourth byte ranges
// 9 U+0039 in ASCII 0x39, outside first byte range, outside double-byte second byte range and quad-byte third byte range, in quad-byte second/fourth byte ranges @ U+0040 in ASCII 0x40, outside first byte range, in double-byte second byte range, outside quad-byte second/third/fourth byte ranges
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) 9 U+0039 in ASCII 0x39, outside first byte range, outside double-byte second byte range and quad-byte third byte range, in quad-byte second/fourth byte ranges
*/
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { 3, 0, "é", -1, 0, 1, { 0xE9 }, "Not full multibyte" }, /* 0*/ { 3, 0, "é", -1, 0, 1, { 0xE9 }, "Not full multibyte" },
/* 1*/ { 3, 1, "é", -1, 0, 1, { 0xE9 }, "First byte in range but only one byte" }, /* 1*/ { 3, 1, "é", -1, 0, 1, { 0xE9 }, "First byte in range but only one byte" },
@ -396,7 +403,7 @@ static void test_gb18030_utf8_to_eci(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int ret_length; int ret_length;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret_length = length; ret_length = length;
@ -418,7 +425,7 @@ static void test_gb18030_utf8_to_eci(int index) {
INTERNAL void gb18030_cpy_test(const unsigned char source[], int *p_length, unsigned int *ddata, INTERNAL void gb18030_cpy_test(const unsigned char source[], int *p_length, unsigned int *ddata,
const int full_multibyte); const int full_multibyte);
static void test_gb18030_cpy(int index) { static void test_gb18030_cpy(const testCtx *const p_ctx) {
struct item { struct item {
int full_multibyte; int full_multibyte;
@ -429,7 +436,7 @@ static void test_gb18030_cpy(int index) {
unsigned int expected_gbdata[30]; unsigned int expected_gbdata[30];
char *comment; char *comment;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { 0, "\351", -1, 0, 1, { 0xE9 }, "Not full multibyte" }, /* 0*/ { 0, "\351", -1, 0, 1, { 0xE9 }, "Not full multibyte" },
/* 1*/ { 1, "\351", -1, 0, 1, { 0xE9 }, "In HANXIN Chinese mode first-byte range but only one byte" }, /* 1*/ { 1, "\351", -1, 0, 1, { 0xE9 }, "In HANXIN Chinese mode first-byte range but only one byte" },
@ -453,7 +460,7 @@ static void test_gb18030_cpy(int index) {
int ret_length; int ret_length;
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret_length = length; ret_length = length;
@ -492,7 +499,7 @@ static int u_gbk_int2(unsigned int u, unsigned int *dest) {
return 0; return 0;
} }
static void test_u_gbk_int(void) { static void test_u_gbk_int(const testCtx *const p_ctx) {
int ret, ret2; int ret, ret2;
unsigned int val, val2; unsigned int val, val2;
@ -501,9 +508,11 @@ static void test_u_gbk_int(void) {
testStart("test_u_gbk_int"); testStart("test_u_gbk_int");
for (i = 0; i < 0xFFFE; i++) { for (i = 0; i < 0xFFFE; i++) {
if (i >= 0xD800 && i <= 0xDFFF) { // UTF-16 surrogates if (i >= 0xD800 && i <= 0xDFFF) { /* UTF-16 surrogates */
continue; continue;
} }
if (testContinue(p_ctx, i)) continue;
val = val2 = 0; val = val2 = 0;
ret = u_gbk_int_test(i, &val); ret = u_gbk_int_test(i, &val);
ret2 = u_gbk_int2(i, &val2); ret2 = u_gbk_int2(i, &val2);
@ -519,8 +528,9 @@ static void test_u_gbk_int(void) {
#define TEST_PERF_ITER_MILLES 50 #define TEST_PERF_ITER_MILLES 50
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000) #define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
// Not a real test, just performance indicator /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -565,7 +575,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = (int) strlen(data[i].data); length = (int) strlen(data[i].data);
@ -597,7 +607,7 @@ static void test_perf(int index, int debug) {
total += diff; total += diff;
total_gno += diff_gno; total_gno += diff_gno;
} }
if (index == -1) { if (p_ctx->index == -1) {
printf("%*s: new % 8gms, gno % 8gms ratio % 9g, eci %gms\n", comment_max, "totals", printf("%*s: new % 8gms, gno % 8gms ratio % 9g, eci %gms\n", comment_max, "totals",
TEST_PERF_TIME(total), TEST_PERF_TIME(total_gno), TEST_PERF_RATIO(total, total_gno), TEST_PERF_TIME(total_eci)); TEST_PERF_TIME(total), TEST_PERF_TIME(total_gno), TEST_PERF_RATIO(total, total_gno), TEST_PERF_TIME(total_eci));
} }
@ -605,13 +615,13 @@ static void test_perf(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_u_gb18030_int", test_u_gb18030_int, 0, 0, 1 }, { "test_u_gb18030_int", test_u_gb18030_int },
{ "test_gb18030_utf8", test_gb18030_utf8, 1, 0, 0 }, { "test_gb18030_utf8", test_gb18030_utf8 },
{ "test_gb18030_utf8_to_eci", test_gb18030_utf8_to_eci, 1, 0, 0 }, { "test_gb18030_utf8_to_eci", test_gb18030_utf8_to_eci },
{ "test_gb18030_cpy", test_gb18030_cpy, 1, 0, 0 }, { "test_gb18030_cpy", test_gb18030_cpy },
{ "test_u_gbk_int", test_u_gbk_int, 0, 0, 0 }, { "test_u_gbk_int", test_u_gbk_int },
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,20 +27,21 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
#include "test_gb2312_tab.h" #include "test_gb2312_tab.h"
#include "../eci.h" #include "../eci.h"
/* For local "private" testing using previous libiconv adaptation, not included for licensing reasons */ /* For local "private" testing using previous libiconv adaptation, not included for licensing reasons */
//#define TEST_JUST_SAY_GNO /* #define TEST_JUST_SAY_GNO */
#ifdef TEST_JUST_SAY_GNO #ifdef TEST_JUST_SAY_GNO
#include "../just_say_gno/gb2312_gnu.c" #include "../just_say_gno/gb2312_gnu.c"
#endif #endif
INTERNAL int u_gb2312_int_test(const unsigned int u, unsigned int *d); INTERNAL int u_gb2312_int_test(const unsigned int u, unsigned int *d);
// As control convert to GB 2312 using simple table generated from unicode.org GB2312.TXT plus simple processing /* As control convert to GB 2312 using simple table generated from unicode.org GB2312.TXT plus simple processing */
// GB2312.TXT no longer on unicode.org site but available from https://haible.de/bruno/charsets/conversion-tables/GB2312.html /* GB2312.TXT no longer on unicode.org site but available from https://haible.de/bruno/charsets/conversion-tables/GB2312.html */
static int u_gb2312_int2(unsigned int u, unsigned int *d) { static int u_gb2312_int2(unsigned int u, unsigned int *d) {
int tab_length, start_i, end_i; int tab_length, start_i, end_i;
int i; int i;
@ -49,7 +50,7 @@ static int u_gb2312_int2(unsigned int u, unsigned int *d) {
*d = (unsigned char) u; *d = (unsigned char) u;
return 1; return 1;
} }
// Shortcut /* Shortcut */
if ((u > 0x0451 && u < 0x2015) || (u > 0x3229 && u < 0x4E00) || (u > 0x9FA0 && u < 0xFF01) || u > 0xFFE5) { if ((u > 0x0451 && u < 0x2015) || (u > 0x3229 && u < 0x4E00) || (u > 0x9FA0 && u < 0xFF01) || u > 0xFFE5) {
return 0; return 0;
} }
@ -58,7 +59,7 @@ static int u_gb2312_int2(unsigned int u, unsigned int *d) {
end_i = start_i + 0x800 > tab_length ? tab_length : start_i + 0x800; end_i = start_i + 0x800 > tab_length ? tab_length : start_i + 0x800;
for (i = start_i; i < end_i; i += 2) { for (i = start_i; i < end_i; i += 2) {
if (test_gb2312_tab[i + 1] == u) { if (test_gb2312_tab[i + 1] == u) {
*d = test_gb2312_tab[i] + 0x8080; // Table in GB 2312 not EUC-CN *d = test_gb2312_tab[i] + 0x8080; /* Table in GB 2312 not EUC-CN */
return 2; return 2;
} }
} }
@ -74,7 +75,8 @@ static int u_gb2312_int2(unsigned int u, unsigned int *d) {
#define TEST_INT_PERF_ITERATIONS 250 #define TEST_INT_PERF_ITERATIONS 250
#endif #endif
static void test_u_gb2312_int(int debug) { static void test_u_gb2312_int(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
int ret, ret2; int ret, ret2;
unsigned int val, val2; unsigned int val, val2;
@ -97,7 +99,7 @@ static void test_u_gb2312_int(int debug) {
#endif #endif
for (i = 0; i < 0xFFFE; i++) { for (i = 0; i < 0xFFFE; i++) {
if (i >= 0xD800 && i <= 0xDFFF) { // UTF-16 surrogates if (i >= 0xD800 && i <= 0xDFFF) { /* UTF-16 surrogates */
continue; continue;
} }
val = val2 = 0; val = val2 = 0;
@ -108,7 +110,7 @@ static void test_u_gb2312_int(int debug) {
assert_equal(val, val2, "i:%d 0x%04X val 0x%04X != val2 0x%04X\n", (int) i, i, val, val2); 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 #ifdef TEST_JUST_SAY_GNO
// `gb2312_wctomb_zint()` doesn't handle ASCII; and ignore duplicate mappings, no longer done /* `gb2312_wctomb_zint()` doesn't handle ASCII; and ignore duplicate mappings, no longer done */
if (i >= 0x80 && i != 0xB7 && i != 0x2014) { if (i >= 0x80 && i != 0xB7 && i != 0x2014) {
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
val2 = 0; val2 = 0;
@ -145,7 +147,7 @@ static void test_u_gb2312_int(int debug) {
testFinish(); testFinish();
} }
static void test_gb2312_utf8(int index) { static void test_gb2312_utf8(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -155,15 +157,17 @@ static void test_gb2312_utf8(int index) {
unsigned int expected_gbdata[20]; unsigned int expected_gbdata[20];
char *comment; char *comment;
}; };
// é 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, in GB 2312 0xA8A6, UTF-8 C3A9 /*
// β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in GB 2312 0xA6C2, UTF-8 CEB2 é 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, in GB 2312 0xA8A6, UTF-8 C3A9
// ¤ U+00A4 in ISO 8859-1 plus other ISO 8859 (but not in ISO 8859-7 or ISO 8859-11), Win 1250 plus other Win, in GB 2312 0xA1E8, UTF-8 C2A4 β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in GB 2312 0xA6C2, UTF-8 CEB2
// ¥ U+00A5 in ISO 8859-1 0xA5, not in GB 2312, UTF-8 C2A5 ¤ U+00A4 in ISO 8859-1 plus other ISO 8859 (but not in ISO 8859-7 or ISO 8859-11), Win 1250 plus other Win, in GB 2312 0xA1E8, UTF-8 C2A4
// ・ U+30FB katakana middle dot, not in any ISO or Win page, in GB 2312 "GB2312.TXT" 0xA1A4, duplicate of mapping of U+00B7, UTF-8 E383BB ¥ U+00A5 in ISO 8859-1 0xA5, not in GB 2312, UTF-8 C2A5
// · U+00B7 middle dot in ISO 8859-1 0xB7, in GB 2312 "GB 18030 subset" 0xA1A4, duplicate of mapping of U+30FB, UTF-8 C2B7 U+30FB katakana middle dot, not in any ISO or Win page, in GB 2312 "GB2312.TXT" 0xA1A4, duplicate of mapping of U+00B7, UTF-8 E383BB
// ― U+2015 horizontal bar in ISO 8859-7 Greek and ISO 8859-10 Nordic, not in any Win page, in GB 2312 "GB2312.TXT" 0xA1AA, duplicate of mapping of U+2014, UTF-8 E28095 · U+00B7 middle dot in ISO 8859-1 0xB7, in GB 2312 "GB 18030 subset" 0xA1A4, duplicate of mapping of U+30FB, UTF-8 C2B7
// — U+2014 em dash, not in any ISO, in Win 1250 and other Win, in GB 2312 "GB 18030 subset" 0xA1AA, duplicate of mapping of U+2015, UTF-8 E28094 U+2015 horizontal bar in ISO 8859-7 Greek and ISO 8859-10 Nordic, not in any Win page, in GB 2312 "GB2312.TXT" 0xA1AA, duplicate of mapping of U+2014, UTF-8 E28095
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) U+2014 em dash, not in any ISO, in Win 1250 and other Win, in GB 2312 "GB 18030 subset" 0xA1AA, duplicate of mapping of U+2015, UTF-8 E28094
*/
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "é", -1, 0, 1, { 0xA8A6 }, "" }, /* 0*/ { "é", -1, 0, 1, { 0xA8A6 }, "" },
/* 1*/ { "β", -1, 0, 1, { 0xA6C2 }, "" }, /* 1*/ { "β", -1, 0, 1, { 0xA6C2 }, "" },
@ -188,7 +192,7 @@ static void test_gb2312_utf8(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int ret_length; int ret_length;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret_length = length; ret_length = length;
@ -207,7 +211,7 @@ static void test_gb2312_utf8(int index) {
testFinish(); testFinish();
} }
static void test_gb2312_utf8_to_eci(int index) { static void test_gb2312_utf8_to_eci(const testCtx *const p_ctx) {
struct item { struct item {
int eci; int eci;
@ -219,19 +223,21 @@ static void test_gb2312_utf8_to_eci(int index) {
unsigned int expected_gbdata[20]; unsigned int expected_gbdata[20];
char *comment; char *comment;
}; };
// é U+00E9 in ISO 8859-1 0xE9, Win 1250 plus other Win, in GRIDMATRIX Chinese mode first byte range 0xA1..A9, 0xB0..F7 /*
// β U+03B2 in ISO 8859-7 Greek 0xE2 (but not other ISO 8859 or Win page) é U+00E9 in ISO 8859-1 0xE9, Win 1250 plus other Win, in GRIDMATRIX Chinese mode first byte range 0xA1..A9, 0xB0..F7
// ¥ U+00A5 in ISO 8859-1 0xA5, in first byte range 0xA1..A9, 0xB0..F7 β U+03B2 in ISO 8859-7 Greek 0xE2 (but not other ISO 8859 or Win page)
// NBSP U+00A0 in ISO 8859-1 0xA0, outside first byte and second byte range 0xA1..FE, UTF-8 C2A0 (\302\240) ¥ U+00A5 in ISO 8859-1 0xA5, in first byte range 0xA1..A9, 0xB0..F7
// ¡ U+00A1 in ISO 8859-1 0xA1, in first byte range NBSP U+00A0 in ISO 8859-1 0xA0, outside first byte and second byte range 0xA1..FE, UTF-8 C2A0 (\302\240)
// © U+00A9 in ISO 8859-1 0xA9, in first byte range ¡ U+00A1 in ISO 8859-1 0xA1, in first byte range
// ª U+00AA in ISO 8859-1 0xAA, outside first byte range © U+00A9 in ISO 8859-1 0xA9, in first byte range
// ¯ U+00AF in ISO 8859-1 0xAF, outside first byte range ª U+00AA in ISO 8859-1 0xAA, outside first byte range
// ° U+00B0 in ISO 8859-1 0xB0, in first byte range ¯ U+00AF in ISO 8859-1 0xAF, outside first byte range
// ÷ U+00F7 in ISO 8859-1 0xF7, in first byte range ° U+00B0 in ISO 8859-1 0xB0, in first byte range
// ø U+00F8 in ISO 8859-1 0xF8, outside first byte range ÷ U+00F7 in ISO 8859-1 0xF7, in first byte range
// ÿ U+00FF in ISO 8859-1 0xFF, outside first byte and second byte range ø U+00F8 in ISO 8859-1 0xF8, outside first byte range
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) ÿ U+00FF in ISO 8859-1 0xFF, outside first byte and second byte range
*/
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { 3, 0, "é", -1, 0, 1, { 0xE9 }, "Not full multibyte" }, /* 0*/ { 3, 0, "é", -1, 0, 1, { 0xE9 }, "Not full multibyte" },
/* 1*/ { 3, 1, "é", -1, 0, 1, { 0xE9 }, "First byte in range but only one byte" }, /* 1*/ { 3, 1, "é", -1, 0, 1, { 0xE9 }, "First byte in range but only one byte" },
@ -288,7 +294,7 @@ static void test_gb2312_utf8_to_eci(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int ret_length; int ret_length;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret_length = length; ret_length = length;
@ -310,7 +316,7 @@ static void test_gb2312_utf8_to_eci(int index) {
INTERNAL void gb2312_cpy_test(const unsigned char source[], int *p_length, unsigned int *ddata, INTERNAL void gb2312_cpy_test(const unsigned char source[], int *p_length, unsigned int *ddata,
const int full_multibyte); const int full_multibyte);
static void test_gb2312_cpy(int index) { static void test_gb2312_cpy(const testCtx *const p_ctx) {
struct item { struct item {
int full_multibyte; int full_multibyte;
@ -321,7 +327,7 @@ static void test_gb2312_cpy(int index) {
unsigned int expected_gbdata[20]; unsigned int expected_gbdata[20];
char *comment; char *comment;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { 0, "\351", -1, 0, 1, { 0xE9 }, "Not full multibyte" }, /* 0*/ { 0, "\351", -1, 0, 1, { 0xE9 }, "Not full multibyte" },
/* 1*/ { 1, "\351", -1, 0, 1, { 0xE9 }, "In GRIDMATRIX Chinese mode first-byte range but only one byte" }, /* 1*/ { 1, "\351", -1, 0, 1, { 0xE9 }, "In GRIDMATRIX Chinese mode first-byte range but only one byte" },
@ -345,7 +351,7 @@ static void test_gb2312_cpy(int index) {
int ret_length; int ret_length;
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret_length = length; ret_length = length;
@ -363,8 +369,9 @@ static void test_gb2312_cpy(int index) {
#define TEST_PERF_ITER_MILLES 100 #define TEST_PERF_ITER_MILLES 100
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000) #define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
// Not a real test, just performance indicator /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -407,7 +414,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = (int) strlen(data[i].data); length = (int) strlen(data[i].data);
@ -449,7 +456,7 @@ static void test_perf(int index, int debug) {
total_eci += diff_eci; total_eci += diff_eci;
total_eci_gno += diff_eci_gno; total_eci_gno += diff_eci_gno;
} }
if (index == -1) { if (p_ctx->index == -1) {
printf("%*s: new % 8gms, gno % 8gms ratio % 9g | eci % 8gms, gno % 8gms ratio %g\n", comment_max, "totals", printf("%*s: new % 8gms, gno % 8gms ratio % 9g | eci % 8gms, gno % 8gms ratio %g\n", comment_max, "totals",
TEST_PERF_TIME(total), TEST_PERF_TIME(total_gno), TEST_PERF_RATIO(total, total_gno), TEST_PERF_TIME(total), TEST_PERF_TIME(total_gno), TEST_PERF_RATIO(total, total_gno),
TEST_PERF_TIME(total_eci), TEST_PERF_TIME(total_eci_gno), TEST_PERF_RATIO(total_eci, total_eci_gno)); TEST_PERF_TIME(total_eci), TEST_PERF_TIME(total_eci_gno), TEST_PERF_RATIO(total_eci, total_eci_gno));
@ -458,12 +465,12 @@ static void test_perf(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_u_gb2312_int", test_u_gb2312_int, 0, 0, 1 }, { "test_u_gb2312_int", test_u_gb2312_int },
{ "test_gb2312_utf8", test_gb2312_utf8, 1, 0, 0 }, { "test_gb2312_utf8", test_gb2312_utf8 },
{ "test_gb2312_utf8_to_eci", test_gb2312_utf8_to_eci, 1, 0, 0 }, { "test_gb2312_utf8_to_eci", test_gb2312_utf8_to_eci },
{ "test_gb2312_cpy", test_gb2312_cpy, 1, 0, 0 }, { "test_gb2312_cpy", test_gb2312_cpy },
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -1,6 +1,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2020-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -27,13 +27,14 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf); INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf);
static void test_pixel_plot(int index, int debug) { static void test_pixel_plot(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int width; int width;
@ -42,7 +43,7 @@ static void test_pixel_plot(int index, int debug) {
int repeat; int repeat;
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { 1, 1, "1", 0, 0 }, /* 0*/ { 1, 1, "1", 0, 0 },
/* 1*/ { 2, 1, "11", 0, 0 }, /* 1*/ { 2, 1, "11", 0, 0 },
@ -52,8 +53,8 @@ static void test_pixel_plot(int index, int debug) {
/* 5*/ { 3, 2, "101010", 0, 0 }, /* 5*/ { 3, 2, "101010", 0, 0 },
/* 6*/ { 3, 3, "101010101", 0, 0 }, /* 6*/ { 3, 3, "101010101", 0, 0 },
/* 7*/ { 8, 2, "CBMWKRYGGYRKWMBC", 0, 0 }, /* 7*/ { 8, 2, "CBMWKRYGGYRKWMBC", 0, 0 },
/* 8*/ { 20, 30, "WWCWBWMWRWYWGWKCCWCMCRCYCGCKBWBCBBMBRBYBGBKMWMCMBMMRMYMGMKRWRCRBRMRRYRGRKYWYCYBYMYRYYGYKGWGCGBGMGRGYGGKKWKCKBKMKRKYKGKK", 1, 0 }, // Single LZW block, size 255 /* 8*/ { 20, 30, "WWCWBWMWRWYWGWKCCWCMCRCYCGCKBWBCBBMBRBYBGBKMWMCMBMMRMYMGMKRWRCRBRMRRYRGRKYWYCYBYMYRYYGYKGWGCGBGMGRGYGGKKWKCKBKMKRKYKGKK", 1, 0 }, /* Single LZW block, size 255 */
/* 9*/ { 19, 32, "WWCWBWMWRWYWGWKCCWCMCRCYCGCKBWBCBBMBRBYBGBKMWMCMBMMRMYMGMKRWRCRBRMRRYRGRKYWYCYBYMYRYYGYKGWGCGBGMGRGYGGKKWK", 1, 0 }, // Two LZW blocks, last size 1 /* 9*/ { 19, 32, "WWCWBWMWRWYWGWKCCWCMCRCYCGCKBWBCBBMBRBYBGBKMWMCMBMMRMYMGMKRWRCRBRMRRYRGRKYWYCYBYMYRYYGYKGWGCGBGMGRGYGGKKWK", 1, 0 }, /* Two LZW blocks, last size 1 */
/* 10*/ { 1, 1, "D", 0, ZINT_ERROR_INVALID_DATA }, /* 10*/ { 1, 1, "D", 0, ZINT_ERROR_INVALID_DATA },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -62,7 +63,7 @@ static void test_pixel_plot(int index, int debug) {
char *gif = "out.gif"; char *gif = "out.gif";
char data_buf[19 * 32 + 1]; // 19 * 32 == 608 char data_buf[19 * 32 + 1]; /* 19 * 32 == 608 */
int have_identify = testUtilHaveIdentify(); int have_identify = testUtilHaveIdentify();
@ -71,7 +72,7 @@ static void test_pixel_plot(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int size; int size;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -119,7 +120,8 @@ static void test_pixel_plot(int index, int debug) {
testFinish(); testFinish();
} }
static void test_print(int index, int generate, int debug) { static void test_print(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -185,7 +187,7 @@ static void test_print(int index, int generate, int debug) {
testStart("test_print"); testStart("test_print");
if (generate) { if (p_ctx->generate) {
char data_dir_path[1024]; char data_dir_path[1024];
assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir);
if (!testUtilDirExists(data_dir_path)) { if (!testUtilDirExists(data_dir_path)) {
@ -196,7 +198,7 @@ static void test_print(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -239,7 +241,7 @@ static void test_print(int index, int generate, int debug) {
assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i); assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %s, %d, %d, %d, %d, %.5g, %.5g, %.5g, \"%s\", \"%s\", \"%s\", \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %d, %s, %d, %d, %d, %d, %.5g, %.5g, %.5g, \"%s\", \"%s\", \"%s\", \"%s\", \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), data[i].border_width, testUtilOutputOptionsName(data[i].output_options), i, testUtilBarcodeName(data[i].symbology), data[i].border_width, testUtilOutputOptionsName(data[i].output_options),
data[i].whitespace_width, data[i].whitespace_height, data[i].whitespace_width, data[i].whitespace_height,
@ -266,11 +268,13 @@ static void test_print(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_outfile(void) { static void test_outfile(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol symbol = {0}; struct zint_symbol symbol = {0};
unsigned char data[] = { "1" }; unsigned char data[] = { "1" };
(void)p_ctx;
testStart("test_outfile"); testStart("test_outfile");
symbol.symbology = BARCODE_CODE128; symbol.symbology = BARCODE_CODE128;
@ -291,7 +295,9 @@ static void test_outfile(void) {
testFinish(); testFinish();
} }
static void test_large_scale(int debug) { static void test_large_scale(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
int length, ret; int length, ret;
struct zint_symbol symbol = {0}; struct zint_symbol symbol = {0};
char data[] = "1"; char data[] = "1";
@ -304,15 +310,15 @@ static void test_large_scale(int debug) {
strcpy(symbol.fgcolour, "000000"); strcpy(symbol.fgcolour, "000000");
strcpy(symbol.bgcolour, "ffffff"); strcpy(symbol.bgcolour, "ffffff");
strcpy(symbol.outfile, "out.gif"); strcpy(symbol.outfile, "out.gif");
// X-dimension 0.27mm * 95 = 25.65 ~ 25 pixels so 12.5 gives 95 dpmm (2400 dpi) /* X-dimension 0.27mm * 95 = 25.65 ~ 25 pixels so 12.5 gives 95 dpmm (2400 dpi) */
symbol.scale = 12.5f; // 70.0f would cause re-alloc as LZW > 1MB but very slow symbol.scale = 12.5f; /* 70.0f would cause re-alloc as LZW > 1MB but very slow */
symbol.dot_size = 4.0f / 5.0f; symbol.dot_size = 4.0f / 5.0f;
ret = ZBarcode_Encode_and_Print(&symbol, (unsigned char *) data, length, 0 /*rotate_angle*/); ret = ZBarcode_Encode_and_Print(&symbol, (unsigned char *) data, length, 0 /*rotate_angle*/);
assert_zero(ret, "%s ZBarcode_Encode_and_Print ret %d != 0 %s\n", testUtilBarcodeName(symbol.symbology), ret, symbol.errtxt); assert_zero(ret, "%s ZBarcode_Encode_and_Print ret %d != 0 %s\n", testUtilBarcodeName(symbol.symbology), ret, symbol.errtxt);
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) { /* -d 64 */ if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) { /* -d 64 */
// 129.1 kB file manually inspected and checked (1.1 MB file for scale 70.0f also checked) /* 129.1 kB file manually inspected and checked (1.1 MB file for scale 70.0f also checked) */
assert_zero(remove(symbol.outfile), "remove(%s) != 0\n", symbol.outfile); assert_zero(remove(symbol.outfile), "remove(%s) != 0\n", symbol.outfile);
} }
@ -323,11 +329,11 @@ static void test_large_scale(int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_pixel_plot", test_pixel_plot, 1, 0, 1 }, { "test_pixel_plot", test_pixel_plot },
{ "test_print", test_print, 1, 1, 1 }, { "test_print", test_print },
{ "test_outfile", test_outfile, 0, 0, 0 }, { "test_outfile", test_outfile },
{ "test_large_scale", test_large_scale, 0, 0, 1 }, { "test_large_scale", test_large_scale },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
@ -336,3 +342,5 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int option_2; int option_2;
@ -41,11 +43,11 @@ static void test_large(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { -1, -1, "1", 2751, 0, 162, 162 }, /* 0*/ { -1, -1, "1", 2751, 0, 162, 162 },
/* 1*/ { -1, -1, "1", 2752, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 1*/ { -1, -1, "1", 2752, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 2*/ { -1, -1, "1", 2755, ZINT_ERROR_TOO_LONG, -1, -1 }, // Triggers buffer > 9191 /* 2*/ { -1, -1, "1", 2755, ZINT_ERROR_TOO_LONG, -1, -1 }, /* Triggers buffer > 9191 */
/* 3*/ { -1, -1, "A", 1836, 0, 162, 162 }, /* 3*/ { -1, -1, "A", 1836, 0, 162, 162 },
/* 4*/ { -1, -1, "A", 1837, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 4*/ { -1, -1, "A", 1837, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 5*/ { -1, -1, "A1", 1529, 0, 162, 162 }, /* 5*/ { -1, -1, "A1", 1529, 0, 162, 162 },
@ -75,7 +77,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -99,7 +101,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_options(int index, int debug) { static void test_options(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int option_1; int option_1;
@ -111,21 +114,21 @@ static void test_options(int index, int debug) {
int expected_size; int expected_size;
const char *expected_errtxt; const char *expected_errtxt;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { 0, 0, { 0, 0, "" }, "12345", 0, 0, 18, "" }, /* 0*/ { 0, 0, { 0, 0, "" }, "12345", 0, 0, 18, "" },
/* 1*/ { 0, 1, { 0, 0, "" }, "12345", 0, 0, 18, "" }, /* 1*/ { 0, 1, { 0, 0, "" }, "12345", 0, 0, 18, "" },
/* 2*/ { 0, 2, { 0, 0, "" }, "12345", 0, 0, 30, "" }, /* 2*/ { 0, 2, { 0, 0, "" }, "12345", 0, 0, 30, "" },
/* 3*/ { 0, 14, { 0, 0, "" }, "12345", 0, 0, 18, "" }, // Version > max version 13 so ignored /* 3*/ { 0, 14, { 0, 0, "" }, "12345", 0, 0, 18, "" }, /* Version > max version 13 so ignored */
/* 4*/ { 0, 13, { 0, 0, "" }, "12345", 0, 0, 162, "" }, /* 4*/ { 0, 13, { 0, 0, "" }, "12345", 0, 0, 162, "" },
/* 5*/ { 0, 1, { 0, 0, "" }, "1234567890123456789", ZINT_ERROR_TOO_LONG, -1, -1, "Error 534: Input data too long for selected symbol size" }, /* 5*/ { 0, 1, { 0, 0, "" }, "1234567890123456789", ZINT_ERROR_TOO_LONG, -1, -1, "Error 534: Input data too long for selected symbol size" },
/* 6*/ { 0, 2, { 0, 0, "" }, "1234567890123456789", 0, 0, 30, "" }, /* 6*/ { 0, 2, { 0, 0, "" }, "1234567890123456789", 0, 0, 30, "" },
/* 7*/ { 0, 0, { 0, 0, "" }, "123456789012345678", 0, 0, 30, "" }, // Version auto-set to 2 /* 7*/ { 0, 0, { 0, 0, "" }, "123456789012345678", 0, 0, 30, "" }, /* Version auto-set to 2 */
/* 8*/ { 0, 1, { 0, 0, "" }, "123456789012345678", 0, 0, 18, "" }, /* 8*/ { 0, 1, { 0, 0, "" }, "123456789012345678", 0, 0, 18, "" },
/* 9*/ { 5, 1, { 0, 0, "" }, "123456789012345678", 0, 0, 18, "" }, // Version specified so overrides ECC level which gets reduced to 4 /* 9*/ { 5, 1, { 0, 0, "" }, "123456789012345678", 0, 0, 18, "" }, /* Version specified so overrides ECC level which gets reduced to 4 */
/* 10*/ { 5, 0, { 0, 0, "" }, "123456789012345678", 0, 0, 30, "" }, // Version not specified so increased to allow for ECC level /* 10*/ { 5, 0, { 0, 0, "" }, "123456789012345678", 0, 0, 30, "" }, /* Version not specified so increased to allow for ECC level */
/* 11*/ { 6, 0, { 0, 0, "" }, "123456789012345678", 0, 0, 30, "" }, // ECC > max ECC 5 so ignored and auto-settings version 2, ECC 4 used /* 11*/ { 6, 0, { 0, 0, "" }, "123456789012345678", 0, 0, 30, "" }, /* ECC > max ECC 5 so ignored and auto-settings version 2, ECC 4 used */
/* 12*/ { 1, 0, { 0, 0, "" }, "123456789012345678", 0, 0, 30, "" }, // ECC < min ECC 2, ECC 2 used /* 12*/ { 1, 0, { 0, 0, "" }, "123456789012345678", 0, 0, 30, "" }, /* ECC < min ECC 2, ECC 2 used */
/* 13*/ { 4, 1, { 0, 0, "" }, "123456789012345678", 0, 0, 18, "" }, /* 13*/ { 4, 1, { 0, 0, "" }, "123456789012345678", 0, 0, 18, "" },
/* 14*/ { 0, 0, { 1, 2, "" }, "12345", 0, 0, 18, "" }, /* 14*/ { 0, 0, { 1, 2, "" }, "12345", 0, 0, 18, "" },
/* 15*/ { 0, 0, { 1, 1, "" }, "12345", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 536: Structured Append count out of range (2-16)" }, /* 15*/ { 0, 0, { 1, 1, "" }, "12345", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 536: Structured Append count out of range (2-16)" },
@ -145,7 +148,7 @@ static void test_options(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -174,7 +177,8 @@ static void test_options(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int generate, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -188,11 +192,13 @@ static void test_input(int index, int generate, int debug) {
char *expected; char *expected;
char *comment; char *comment;
}; };
// é 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, in GB 2312 0xA8A6, UTF-8 C3A9 /*
// β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in GB 2312 0xA6C2, UTF-8 CEB2 é 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, in GB 2312 0xA8A6, UTF-8 C3A9
// ÿ U+00FF in ISO 8859-1 0xFF, not in GB 2312, outside first byte and second byte range, UTF-8 C3BF β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in GB 2312 0xA6C2, UTF-8 CEB2
// ㈩ U+3229 in GB 2312 0x226E ÿ U+00FF in ISO 8859-1 0xFF, not in GB 2312, outside first byte and second byte range, UTF-8 C3BF
// 一 U+4E00 in GB 2312 0x523B U+3229 in GB 2312 0x226E
U+4E00 in GB 2312 0x523B
*/
struct item data[] = { struct item data[] = {
/* 0*/ { UNICODE_MODE, 0, -1, -1, { 0, 0, "" }, "é", 0, 0, "08 54 6F 78 00", "H1 (GB 2312) Note: Grid Matrix default is GB 2312, not ISO 8859-1" }, /* 0*/ { UNICODE_MODE, 0, -1, -1, { 0, 0, "" }, "é", 0, 0, "08 54 6F 78 00", "H1 (GB 2312) Note: Grid Matrix default is GB 2312, not ISO 8859-1" },
/* 1*/ { UNICODE_MODE, 3, -1, -1, { 0, 0, "" }, "é", 0, 3, "60 01 58 00 74 40", "ECI-3 B1 (ISO 8859-1)" }, /* 1*/ { UNICODE_MODE, 3, -1, -1, { 0, 0, "" }, "é", 0, 3, "60 01 58 00 74 40", "ECI-3 B1 (ISO 8859-1)" },
@ -321,12 +327,12 @@ static void test_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt debug |= ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_GRIDMATRIX, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, data[i].option_3, data[i].output_options, data[i].data, -1, debug); length = testUtilSetSymbol(symbol, BARCODE_GRIDMATRIX, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, data[i].option_3, data[i].output_options, data[i].data, -1, debug);
if (data[i].structapp.count) { if (data[i].structapp.count) {
@ -336,7 +342,7 @@ static void test_input(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %s, %s, { %d, %d, \"%s\" }, \"%s\", %s, %d, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %d, %s, %s, { %d, %d, \"%s\" }, \"%s\", %s, %d, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, testUtilOutputOptionsName(data[i].output_options), testUtilOption3Name(data[i].option_3), i, testUtilInputModeName(data[i].input_mode), data[i].eci, testUtilOutputOptionsName(data[i].output_options), testUtilOption3Name(data[i].option_3),
data[i].structapp.index, data[i].structapp.count, data[i].structapp.id, data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
@ -355,7 +361,8 @@ static void test_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -475,7 +482,7 @@ static void test_encode(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -485,7 +492,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { \"%s\", %s, %d, %d, %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { \"%s\", %s, %d, %d, %s, %d, %d, \"%s\",\n",
i, data[i].data, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, testUtilErrorName(data[i].ret), i, data[i].data, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, testUtilErrorName(data[i].ret),
symbol->rows, symbol->width, data[i].comment); symbol->rows, symbol->width, data[i].comment);
@ -508,7 +515,8 @@ static void test_encode(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode_segs(int index, int generate, int debug) { static void test_encode_segs(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -523,8 +531,10 @@ static void test_encode_segs(int index, int generate, int debug) {
char *comment; char *comment;
char *expected; char *expected;
}; };
// ¶ not in GB 2312 (in ISO/IEC 8869-1) /*
// Ж in GB 2312 (and ISO/IEC 8859-5) not in GB 2312 (in ISO/IEC 8869-1)
Ж in GB 2312 (and ISO/IEC 8859-5)
*/
struct item data[] = { struct item data[] = {
/* 0*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, { { TU(""), -1, 0 }, { TU("Ж"), -1, 7 }, { TU(""), 0, 0 } }, ZINT_WARN_USES_ECI, 30, 30, "Standard example (adds ECI 3 for ¶)", /* 0*/ { UNICODE_MODE, -1, -1, { 0, 0, "" }, { { TU(""), -1, 0 }, { TU("Ж"), -1, 7 }, { TU(""), 0, 0 } }, ZINT_WARN_USES_ECI, 30, 30, "Standard example (adds ECI 3 for ¶)",
"111111000000111111000000111111" "111111000000111111000000111111"
@ -809,7 +819,7 @@ static void test_encode_segs(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -822,7 +832,7 @@ static void test_encode_segs(int index, int generate, int debug) {
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count); ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
char escaped1[8192]; char escaped1[8192];
char escaped2[8192]; char escaped2[8192];
int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length;
@ -859,8 +869,9 @@ static void test_encode_segs(int index, int generate, int debug) {
#define TEST_PERF_ITERATIONS 1000 #define TEST_PERF_ITERATIONS 1000
// Not a real test, just performance indicator /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -904,7 +915,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_encode = diff_buffer = 0; diff_encode = diff_buffer = 0;
@ -935,20 +946,20 @@ static void test_perf(int index, int debug) {
total_encode += diff_encode; total_encode += diff_encode;
total_buffer += diff_buffer; total_buffer += diff_buffer;
} }
if (index != -1) { if (p_ctx->index != -1) {
printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC); printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
} }
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_options", test_options, 1, 0, 1 }, { "test_options", test_options },
{ "test_input", test_input, 1, 1, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_encode_segs", test_encode_segs, 1, 1, 1 }, { "test_encode_segs", test_encode_segs },
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,13 +27,15 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
/* /*
* Check that GS1_128-based and DBAR_EXP-based symbologies reduce GS1 data * Check that GS1_128-based and DBAR_EXP-based symbologies reduce GS1 data
*/ */
static void test_gs1_reduce(int index, int generate, int debug) { static void test_gs1_reduce(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -203,7 +205,7 @@ static void test_gs1_reduce(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -218,7 +220,7 @@ static void test_gs1_reduce(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); ret = ZBarcode_Encode(symbol, (unsigned char *) text, length);
if (generate) { if (p_ctx->generate) {
if (data[i].ret == 0) { if (data[i].ret == 0) {
printf(" /*%2d*/ { %s, %s, \"%s\", \"%s\", %d, \"%s\",\n", printf(" /*%2d*/ { %s, %s, \"%s\", \"%s\", %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].data, data[i].composite, data[i].ret, data[i].comment); i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].data, data[i].composite, data[i].ret, data[i].comment);
@ -257,7 +259,8 @@ static void test_gs1_reduce(int index, int generate, int debug) {
* Check GS1_128-based and DBAR_EXP-based symbologies HRT * Check GS1_128-based and DBAR_EXP-based symbologies HRT
* See test_hrt() in test_rss.c and test_composite.c for DBAR other than DBAR_EXP-based * See test_hrt() in test_rss.c and test_composite.c for DBAR other than DBAR_EXP-based
*/ */
static void test_hrt(int index, int debug) { static void test_hrt(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -319,7 +322,7 @@ static void test_hrt(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -345,7 +348,7 @@ static void test_hrt(int index, int debug) {
#include "../gs1.h" #include "../gs1.h"
static void test_gs1_verify(int index, int debug) { static void test_gs1_verify(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -1350,8 +1353,7 @@ static void test_gs1_verify(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1371,7 +1373,7 @@ static void test_gs1_verify(int index, int debug) {
testFinish(); testFinish();
} }
static void test_gs1_lint(int index, int debug) { static void test_gs1_lint(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -1768,8 +1770,7 @@ static void test_gs1_lint(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1793,7 +1794,8 @@ static void test_gs1_lint(int index, int debug) {
/* /*
* Check GS1_MODE for non-forced GS1 compliant symbologies (see gs1_compliant() in library.c) * Check GS1_MODE for non-forced GS1 compliant symbologies (see gs1_compliant() in library.c)
*/ */
static void test_input_mode(int index, int debug) { static void test_input_mode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1935,7 +1937,7 @@ static void test_input_mode(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1944,7 +1946,7 @@ static void test_input_mode(int index, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (index == -1 && data[i].compare_previous) { if (p_ctx->index == -1 && data[i].compare_previous) {
ret = testUtilSymbolCmp(symbol, &previous_symbol); ret = testUtilSymbolCmp(symbol, &previous_symbol);
assert_zero(ret, "i:%d testUtilSymbolCmp ret %d != 0\n", i, ret); assert_zero(ret, "i:%d testUtilSymbolCmp ret %d != 0\n", i, ret);
} }
@ -1959,7 +1961,8 @@ static void test_input_mode(int index, int debug) {
/* /*
* Check GS1NOCHECK_MODE for GS1_128-based and DBAR_EXP-based symbologies * Check GS1NOCHECK_MODE for GS1_128-based and DBAR_EXP-based symbologies
*/ */
static void test_gs1nocheck_mode(int index, int debug) { static void test_gs1nocheck_mode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -2152,7 +2155,7 @@ static void test_gs1nocheck_mode(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -2177,13 +2180,13 @@ static void test_gs1nocheck_mode(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_gs1_reduce", test_gs1_reduce, 1, 1, 1 }, { "test_gs1_reduce", test_gs1_reduce },
{ "test_hrt", test_hrt, 1, 0, 1 }, { "test_hrt", test_hrt },
{ "test_gs1_verify", test_gs1_verify, 1, 0, 1 }, { "test_gs1_verify", test_gs1_verify },
{ "test_gs1_lint", test_gs1_lint, 1, 0, 1 }, { "test_gs1_lint", test_gs1_lint },
{ "test_input_mode", test_input_mode, 1, 0, 1 }, { "test_input_mode", test_input_mode },
{ "test_gs1nocheck_mode", test_gs1nocheck_mode, 1, 0, 1 }, { "test_gs1nocheck_mode", test_gs1nocheck_mode },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int option_1; int option_1;
@ -42,7 +44,7 @@ static void test_large(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { -1, -1, -1, "1", 7827, 0, 189, 189 }, /* 0*/ { -1, -1, -1, "1", 7827, 0, 189, 189 },
/* 1*/ { -1, -1, -1, "1", 7828, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 1*/ { -1, -1, -1, "1", 7828, ZINT_ERROR_TOO_LONG, -1, -1 },
@ -77,7 +79,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -101,7 +103,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_options(int index, int debug) { static void test_options(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int option_1; int option_1;
@ -111,20 +114,20 @@ static void test_options(int index, int debug) {
int ret_vector; int ret_vector;
int expected_size; int expected_size;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { -1, -1, "12345", 0, 0, 23 }, // Default version 1, ECC auto-set to 4 /* 0*/ { -1, -1, "12345", 0, 0, 23 }, /* Default version 1, ECC auto-set to 4 */
/* 1*/ { 1, -1, "12345", 0, 0, 23 }, /* 1*/ { 1, -1, "12345", 0, 0, 23 },
/* 2*/ { -1, 2, "12345", 0, 0, 25 }, /* 2*/ { -1, 2, "12345", 0, 0, 25 },
/* 3*/ { -1, 85, "12345", 0, 0, 23 }, // Version > max version 85 so ignored /* 3*/ { -1, 85, "12345", 0, 0, 23 }, /* Version > max version 85 so ignored */
/* 4*/ { -1, 84, "12345", 0, 0, 189 }, /* 4*/ { -1, 84, "12345", 0, 0, 189 },
/* 5*/ { 1, 1, "1234567890123456789012345678901234567890123456", ZINT_ERROR_TOO_LONG, -1, -1 }, /* 5*/ { 1, 1, "1234567890123456789012345678901234567890123456", ZINT_ERROR_TOO_LONG, -1, -1 },
/* 6*/ { 4, 1, "1234567890123456", ZINT_ERROR_TOO_LONG, -1, -1 }, /* 6*/ { 4, 1, "1234567890123456", ZINT_ERROR_TOO_LONG, -1, -1 },
/* 7*/ { 4, 2, "12345678901234567", 0, 0, 25 }, /* 7*/ { 4, 2, "12345678901234567", 0, 0, 25 },
/* 8*/ { 4, -1, "12345678901234567", 0, 0, 25 }, // Version auto-set to 2 /* 8*/ { 4, -1, "12345678901234567", 0, 0, 25 }, /* Version auto-set to 2 */
/* 9*/ { -1, -1, "12345678901234567", 0, 0, 23 }, // Version auto-set to 1, ECC auto-set to 3 /* 9*/ { -1, -1, "12345678901234567", 0, 0, 23 }, /* Version auto-set to 1, ECC auto-set to 3 */
/* 10*/ { 5, -1, "12345678901234567", 0, 0, 23 }, // ECC > max ECC 4 so ignored and auto-settings version 1, ECC 3 used /* 10*/ { 5, -1, "12345678901234567", 0, 0, 23 }, /* ECC > max ECC 4 so ignored and auto-settings version 1, ECC 3 used */
/* 11*/ { -1, -1, "1234567890123456789012345678901234567890123456", 0, 0, 25 }, // Version auto-set to 2, ECC auto-set to 2 /* 11*/ { -1, -1, "1234567890123456789012345678901234567890123456", 0, 0, 25 }, /* Version auto-set to 2, ECC auto-set to 2 */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -134,7 +137,7 @@ static void test_options(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -157,7 +160,8 @@ static void test_options(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int generate, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -171,15 +175,17 @@ static void test_input(int index, int generate, int debug) {
int zxingcpp_cmp; int zxingcpp_cmp;
char *comment; char *comment;
}; };
// é 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, in GB 18030 0xA8A6, UTF-8 C3A9 /*
// β U+03B2 in ISO 8859-7 Greek 0xE2 (but not other ISO 8859 or Win page), in GB 18030 0xA6C2, UTF-8 CEB2 é 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, in GB 18030 0xA8A6, UTF-8 C3A9
// ÿ U+00FF in ISO 8859-1 0xFF, not in GB 18030, outside first byte and second byte range, UTF-8 C3BF β U+03B2 in ISO 8859-7 Greek 0xE2 (but not other ISO 8859 or Win page), in GB 18030 0xA6C2, UTF-8 CEB2
// PAD U+0080 GB 18030 4-byte Region 0x81308130, UTF-8 C280 (\302\200) ÿ U+00FF in ISO 8859-1 0xFF, not in GB 18030, outside first byte and second byte range, UTF-8 C3BF
// 啊 U+554A GB 18030 Region One 0xB0A1, UTF-8 E5958A PAD U+0080 GB 18030 4-byte Region 0x81308130, UTF-8 C280 (\302\200)
// 亍 U+4E8D GB 18030 Region Two 0xD8A1, UTF-8 E4BA8D U+554A GB 18030 Region One 0xB0A1, UTF-8 E5958A
// 齄 U+9F44 GB 18030 Region Two 0xF7FE, UTF-8 E9BD84 U+4E8D GB 18030 Region Two 0xD8A1, UTF-8 E4BA8D
// 丂 U+4E02 GB 18030 2-byte Region 0x8140, UTF-8 E4B882 U+9F44 GB 18030 Region Two 0xF7FE, UTF-8 E9BD84
// <20> (REPLACEMENT CHARACTER) U+FFFD GB 18030 4-byte Region 0x81308130, UTF-8 EFBFBD (\357\277\275) U+4E02 GB 18030 2-byte Region 0x8140, UTF-8 E4B882
<EFBFBD> (REPLACEMENT CHARACTER) U+FFFD GB 18030 4-byte Region 0x81308130, UTF-8 EFBFBD (\357\277\275)
*/
struct item data[] = { struct item data[] = {
/* 0*/ { UNICODE_MODE, 0, -1, "é", -1, 0, 0, "30 00 F4 80 00 00 00 00 00", 1, "B1 (ISO 8859-1)" }, /* 0*/ { UNICODE_MODE, 0, -1, "é", -1, 0, 0, "30 00 F4 80 00 00 00 00 00", 1, "B1 (ISO 8859-1)" },
/* 1*/ { UNICODE_MODE, 3, -1, "é", -1, 0, 3, "80 33 00 0F 48 00 00 00 00", 1, "ECI-3 B1 (ISO 8859-1)" }, /* 1*/ { UNICODE_MODE, 3, -1, "é", -1, 0, 3, "80 33 00 0F 48 00 00 00 00", 1, "ECI-3 B1 (ISO 8859-1)" },
@ -278,25 +284,25 @@ static void test_input(int index, int generate, int debug) {
char cmp_buf[32768]; char cmp_buf[32768];
char cmp_msg[1024]; char cmp_msg[1024];
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_input"); testStart("test_input");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt debug |= ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_HANXIN, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, data[i].option_3, -1 /*output_options*/, data[i].data, data[i].length, debug); length = testUtilSetSymbol(symbol, BARCODE_HANXIN, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, data[i].option_3, -1 /*output_options*/, data[i].data, data[i].length, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %s, \"%s\", %d, %s, %d, \"%s\", %d, \"%s\" },\n", printf(" /*%3d*/ { %s, %d, %s, \"%s\", %d, %s, %d, \"%s\", %d, \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, testUtilOption3Name(data[i].option_3), i, testUtilInputModeName(data[i].input_mode), data[i].eci, testUtilOption3Name(data[i].option_3),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length,
@ -333,7 +339,8 @@ static void test_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -3255,13 +3262,13 @@ static void test_encode(int index, int generate, int debug) {
char cmp_buf[32768]; char cmp_buf[32768];
char cmp_msg[1024]; char cmp_msg[1024];
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -3273,7 +3280,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, %d, %s, \"%s\", %d, %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, %d, %d, %s, \"%s\", %d, %s, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, i, testUtilInputModeName(data[i].input_mode), data[i].eci,
data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3), data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3),
@ -3310,7 +3317,8 @@ static void test_encode(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode_segs(int index, int generate, int debug) { static void test_encode_segs(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -3538,13 +3546,13 @@ static void test_encode_segs(int index, int generate, int debug) {
char cmp_buf[32768]; char cmp_buf[32768];
char cmp_msg[1024]; char cmp_msg[1024];
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_encode_segs"); testStart("test_encode_segs");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -3557,7 +3565,7 @@ static void test_encode_segs(int index, int generate, int debug) {
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count); ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
char escaped1[8192]; char escaped1[8192];
char escaped2[8192]; char escaped2[8192];
int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length;
@ -3617,8 +3625,9 @@ static void test_encode_segs(int index, int generate, int debug) {
#define TEST_PERF_ITERATIONS 1000 #define TEST_PERF_ITERATIONS 1000
// Not a real test, just performance indicator /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -3678,7 +3687,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_encode = diff_buffer = 0; diff_encode = diff_buffer = 0;
@ -3709,20 +3718,20 @@ static void test_perf(int index, int debug) {
total_encode += diff_encode; total_encode += diff_encode;
total_buffer += diff_buffer; total_buffer += diff_buffer;
} }
if (index != -1) { if (p_ctx->index != -1) {
printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC); printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
} }
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_options", test_options, 1, 0, 1 }, { "test_options", test_options },
{ "test_input", test_input, 1, 1, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_encode_segs", test_encode_segs, 1, 1, 1 }, { "test_encode_segs", test_encode_segs },
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -41,9 +41,10 @@
#define TEST_CSV_PERF_ITERATIONS 100 #define TEST_CSV_PERF_ITERATIONS 100
//#define TEST_IMAIL_CSV_MAX 300 /* #define TEST_IMAIL_CSV_MAX 300 */
static void test_csv(int index, int debug) { static void test_csv(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
char csvfile[1024]; char csvfile[1024];
FILE *fd; FILE *fd;
@ -84,10 +85,10 @@ static void test_csv(int index, int debug) {
lc++; lc++;
if (index != -1 && lc != index + 1) continue; if (testContinue(p_ctx, lc - 1)) continue;
#ifdef TEST_IMAIL_CSV_MAX #ifdef TEST_IMAIL_CSV_MAX
if (lc > TEST_IMAIL_CSV_MAX && index == -1) { if (lc > TEST_IMAIL_CSV_MAX && p_ctx->index == -1) {
break; break;
} }
#endif #endif
@ -159,15 +160,16 @@ static void test_csv(int index, int debug) {
testFinish(); testFinish();
} }
static void test_hrt(int index, int debug) { static void test_hrt(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
char *expected; char *expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "53379777234994544928-51135759461", "" }, // None /* 0*/ { "53379777234994544928-51135759461", "" }, /* None */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -177,7 +179,7 @@ static void test_hrt(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -195,7 +197,8 @@ static void test_hrt(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -203,20 +206,20 @@ static void test_input(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "53379777234994544928-51135759461", 0, 3, 129 }, /* 0*/ { "53379777234994544928-51135759461", 0, 3, 129 },
/* 1*/ { "123456789012345678901234567890123", ZINT_ERROR_TOO_LONG, -1, -1 }, /* 1*/ { "123456789012345678901234567890123", ZINT_ERROR_TOO_LONG, -1, -1 },
/* 2*/ { "A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 2*/ { "A", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 3*/ { "12345678901234567890", 0, 3, 129 }, // Tracker only, no ZIP /* 3*/ { "12345678901234567890", 0, 3, 129 }, /* Tracker only, no ZIP */
/* 4*/ { "15345678901234567890", ZINT_ERROR_INVALID_DATA, -1, -1 }, // Tracker 2nd char > 4 /* 4*/ { "15345678901234567890", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* Tracker 2nd char > 4 */
/* 5*/ { "1234567890123456789", ZINT_ERROR_INVALID_DATA, -1, -1 }, // Tracker 20 chars /* 5*/ { "1234567890123456789", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* Tracker 20 chars */
/* 6*/ { "12345678901234567890-1234", ZINT_ERROR_INVALID_DATA, -1, -1 }, // ZIP wrong len /* 6*/ { "12345678901234567890-1234", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* ZIP wrong len */
/* 7*/ { "12345678901234567890-12345", 0, 3, 129 }, /* 7*/ { "12345678901234567890-12345", 0, 3, 129 },
/* 8*/ { "12345678901234567890-123456", ZINT_ERROR_INVALID_DATA, -1, -1 }, // ZIP wrong len /* 8*/ { "12345678901234567890-123456", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* ZIP wrong len */
/* 9*/ { "12345678901234567890-12345678", ZINT_ERROR_INVALID_DATA, -1, -1 }, // ZIP wrong len /* 9*/ { "12345678901234567890-12345678", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* ZIP wrong len */
/* 10*/ { "12345678901234567890-123456789", 0, 3, 129 }, /* 10*/ { "12345678901234567890-123456789", 0, 3, 129 },
/* 11*/ { "12345678901234567890-1234567890", ZINT_ERROR_INVALID_DATA, -1, -1 }, // ZIP wrong len /* 11*/ { "12345678901234567890-1234567890", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* ZIP wrong len */
/* 12*/ { "12345678901234567890-12345678901", 0, 3, 129 }, /* 12*/ { "12345678901234567890-12345678901", 0, 3, 129 },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -227,7 +230,7 @@ static void test_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -248,7 +251,8 @@ static void test_input(int index, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -274,13 +278,13 @@ static void test_encode(int index, int generate, int debug) {
char bwipp_buf[8192]; char bwipp_buf[8192];
char bwipp_msg[1024]; char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -290,7 +294,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { \"%s\", %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
@ -325,11 +329,11 @@ static void test_encode(int index, int generate, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_csv", test_csv, 1, 0, 1 }, { "test_csv", test_csv },
{ "test_hrt", test_hrt, 1, 0, 1 }, { "test_hrt", test_hrt },
{ "test_input", test_input, 1, 0, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -1,6 +1,6 @@
/* /*
libzint - the open source barcode library 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 Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -27,18 +27,18 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
#include "../iso3166.h" #include "../iso3166.h"
static void test_numeric(int index) { static void test_numeric(const testCtx *const p_ctx) {
struct item { struct item {
int data; int data;
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { -1, 0 }, /* 0*/ { -1, 0 },
/* 1*/ { 0, 0 }, /* 1*/ { 0, 0 },
@ -381,7 +381,7 @@ static void test_numeric(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
ret = iso3166_numeric(data[i].data); ret = iso3166_numeric(data[i].data);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret);
@ -436,13 +436,15 @@ static int bc_iso3166_numeric(int cc) {
return 0; return 0;
} }
static void test_numeric_bc(void) { static void test_numeric_bc(const testCtx *const p_ctx) {
int i, ret, bc_ret; int i, ret, bc_ret;
testStart("test_numeric_bc"); testStart("test_numeric_bc");
for (i = 0; i < 1001; i++) { for (i = 0; i < 1001; i++) {
if (testContinue(p_ctx, i)) continue;
ret = iso3166_numeric(i); ret = iso3166_numeric(i);
bc_ret = bc_iso3166_numeric(i); bc_ret = bc_iso3166_numeric(i);
assert_equal(ret, bc_ret, "i:%d ret %d != bc_ret %d\n", i, ret, bc_ret); assert_equal(ret, bc_ret, "i:%d ret %d != bc_ret %d\n", i, ret, bc_ret);
@ -451,13 +453,13 @@ static void test_numeric_bc(void) {
testFinish(); testFinish();
} }
static void test_alpha2(int index) { static void test_alpha2(const testCtx *const p_ctx) {
struct item { struct item {
const char *data; const char *data;
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "", 0 }, /* 0*/ { "", 0 },
/* 1*/ { "A", 0 }, /* 1*/ { "A", 0 },
@ -681,7 +683,7 @@ static void test_alpha2(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
ret = iso3166_alpha2(data[i].data); ret = iso3166_alpha2(data[i].data);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret);
@ -737,11 +739,13 @@ static int bc_iso3166_alpha2(const char *cc) {
return 0; return 0;
} }
static void test_alpha2_bc(void) { static void test_alpha2_bc(const testCtx *const p_ctx) {
int i, ret, bc_ret; int i, ret, bc_ret;
char data[2]; char data[2];
(void)p_ctx;
testStart("test_alpha2_bc"); testStart("test_alpha2_bc");
for (i = 0; i < 128; i++) { for (i = 0; i < 128; i++) {
@ -760,11 +764,11 @@ static void test_alpha2_bc(void) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_numeric", test_numeric, 1, 0, 0 }, { "test_numeric", test_numeric },
{ "test_alpha2", test_alpha2, 1, 0, 0 }, { "test_alpha2", test_alpha2 },
{ "test_numeric_bc", test_numeric_bc, 0, 0, 0 }, { "test_numeric_bc", test_numeric_bc },
{ "test_alpha2_bc", test_alpha2_bc, 0, 0, 0 }, { "test_alpha2_bc", test_alpha2_bc },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
@ -773,3 +777,5 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -32,7 +32,7 @@
#include "testcommon.h" #include "testcommon.h"
#include "../iso4217.h" #include "../iso4217.h"
static void test_numeric(int index) { static void test_numeric(const testCtx *const p_ctx) {
struct item { struct item {
int data; int data;
@ -436,7 +436,7 @@ static void test_numeric(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
ret = iso4217_numeric(data[i].data); ret = iso4217_numeric(data[i].data);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret);
@ -484,13 +484,14 @@ static int bc_iso4217_numeric(int cc) {
return 0; return 0;
} }
static void test_numeric_bc(void) { static void test_numeric_bc(const testCtx *const p_ctx) {
int i, ret, bc_ret; int i, ret, bc_ret;
testStart("test_numeric_bc"); testStart("test_numeric_bc");
for (i = 0; i < 1001; i++) { for (i = 0; i < 1001; i++) {
if (testContinue(p_ctx, i)) continue;
ret = iso4217_numeric(i); ret = iso4217_numeric(i);
bc_ret = bc_iso4217_numeric(i); bc_ret = bc_iso4217_numeric(i);
assert_equal(ret, bc_ret, "i:%d ret %d != bc_ret %d\n", i, ret, bc_ret); assert_equal(ret, bc_ret, "i:%d ret %d != bc_ret %d\n", i, ret, bc_ret);
@ -501,9 +502,9 @@ static void test_numeric_bc(void) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_numeric", test_numeric, 1, 0, 0 }, { "test_numeric", test_numeric },
{ "test_numeric_bc", test_numeric_bc, 0, 0, 0 }, { "test_numeric_bc", test_numeric_bc },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,19 +27,20 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
#include "test_ksx1001_tab.h" #include "test_ksx1001_tab.h"
#include "../ksx1001.h" #include "../ksx1001.h"
/* For local "private" testing using previous libiconv adaptation, not included for licensing reasons */ /* For local "private" testing using previous libiconv adaptation, not included for licensing reasons */
//#define TEST_JUST_SAY_GNO /* #define TEST_JUST_SAY_GNO */
#ifdef TEST_JUST_SAY_GNO #ifdef TEST_JUST_SAY_GNO
#include "../just_say_gno/ksx1001_gnu.h" #include "../just_say_gno/ksx1001_gnu.h"
#endif #endif
INTERNAL int u_ksx1001_test(const unsigned int u, unsigned char *dest); INTERNAL int u_ksx1001_test(const unsigned int u, unsigned char *dest);
// Version of `u_ksx1001()` taking unsigned int destination for backward-compatible testing /* Version of `u_ksx1001()` taking unsigned int destination for backward-compatible testing */
static int u_ksx1001_int(const unsigned int u, unsigned int *d) { static int u_ksx1001_int(const unsigned int u, unsigned int *d) {
unsigned char dest[2]; unsigned char dest[2];
int ret = u_ksx1001_test(u, dest); int ret = u_ksx1001_test(u, dest);
@ -49,8 +50,9 @@ static int u_ksx1001_int(const unsigned int u, unsigned int *d) {
return ret; return ret;
} }
// As control convert to KS X 1001 using simple table generated from /* 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 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) { static int u_ksx1001_int2(unsigned int u, unsigned int *dest) {
int tab_length, start_i, end_i; int tab_length, start_i, end_i;
int i; int i;
@ -59,15 +61,15 @@ static int u_ksx1001_int2(unsigned int u, unsigned int *dest) {
*dest = u; *dest = u;
return 1; return 1;
} }
if (u == 0x20AC) { // Euro sign added KS X 1001:1998 if (u == 0x20AC) { /* Euro sign added KS X 1001:1998 */
*dest = 0x2266 + 0x8080; *dest = 0x2266 + 0x8080;
return 2; return 2;
} }
if (u == 0xAE) { // Registered trademark added KS X 1001:1998 if (u == 0xAE) { /* Registered trademark added KS X 1001:1998 */
*dest = 0x2267 + 0x8080; *dest = 0x2267 + 0x8080;
return 2; return 2;
} }
if (u == 0x327E) { // Korean postal code symbol added KS X 1001:2002 if (u == 0x327E) { /* Korean postal code symbol added KS X 1001:2002 */
*dest = 0x2268 + 0x8080; *dest = 0x2268 + 0x8080;
return 2; return 2;
} }
@ -92,7 +94,8 @@ static int u_ksx1001_int2(unsigned int u, unsigned int *dest) {
#define TEST_INT_PERF_ITERATIONS 100 #define TEST_INT_PERF_ITERATIONS 100
#endif #endif
static void test_u_ksx1001_int(int debug) { static void test_u_ksx1001_int(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
int ret, ret2; int ret, ret2;
unsigned int val, val2; unsigned int val, val2;
@ -115,7 +118,7 @@ static void test_u_ksx1001_int(int debug) {
#endif #endif
for (i = 0; i < 0xFFFE; i++) { for (i = 0; i < 0xFFFE; i++) {
if (i >= 0xD800 && i <= 0xDFFF) { // UTF-16 surrogates if (i >= 0xD800 && i <= 0xDFFF) { /* UTF-16 surrogates */
continue; continue;
} }
val = val2 = 0; val = val2 = 0;
@ -126,7 +129,7 @@ static void test_u_ksx1001_int(int debug) {
assert_equal(val, val2, "i:%d 0x%04X val 0x%04X != val2 0x%04X\n", (int) i, i, val, val2); 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 #ifdef TEST_JUST_SAY_GNO
if (i >= 0x80) { // `ksx1001_wctomb_zint()` doesn't handle ASCII if (i >= 0x80) { /* `ksx1001_wctomb_zint()` doesn't handle ASCII */
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
val2 = 0; val2 = 0;
ret2 = ksx1001_wctomb_zint(&val2, i); ret2 = ksx1001_wctomb_zint(&val2, i);
@ -146,7 +149,7 @@ static void test_u_ksx1001_int(int debug) {
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); 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) { if (ret2) {
val2 += 0x8080; // `ksx1001_wctomb_zint()` returns pure KS X 1001 values, convert to EUC-KR 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); assert_equal(val, val2, "i:%d 0x%04X val 0x%04X != val2 0x%04X\n", (int) i, i, val, val2);
} }
} }
@ -165,8 +168,8 @@ static void test_u_ksx1001_int(int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_u_ksx1001_int", test_u_ksx1001_int, 0, 0, 1 }, { "test_u_ksx1001_int", test_u_ksx1001_int },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -53,13 +53,13 @@
INTERNAL int clz_u64_test(uint64_t x); INTERNAL int clz_u64_test(uint64_t x);
static void test_clz_u64(int index) { static void test_clz_u64(const testCtx *const p_ctx) {
struct item { struct item {
uint64_t s; uint64_t s;
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { 0x0, 64 }, /* 0*/ { 0x0, 64 },
/* 1*/ { 0x1, 63 }, /* 1*/ { 0x1, 63 },
@ -195,7 +195,7 @@ static void test_clz_u64(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
ret = clz_u64_test(data[i].s); ret = clz_u64_test(data[i].s);
assert_equal(ret, data[i].ret, "i:%d 0x%" LX_FMT "X ret %d != %d\n", i, data[i].s, ret, data[i].ret); assert_equal(ret, data[i].ret, "i:%d 0x%" LX_FMT "X ret %d != %d\n", i, data[i].s, ret, data[i].ret);
@ -204,14 +204,14 @@ static void test_clz_u64(int index) {
testFinish(); testFinish();
} }
static void test_load(int index) { static void test_load(const testCtx *const p_ctx) {
struct item { struct item {
large_int t; large_int t;
large_int s; large_int s;
large_int expected; large_int expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { LI(0, 0), LI(0, 0), LI(0, 0) }, /* 0*/ { LI(0, 0), LI(0, 0), LI(0, 0) },
/* 1*/ { LI(1, 1), LI(0, 0), LI(0, 0) }, /* 1*/ { LI(1, 1), LI(0, 0), LI(0, 0) },
@ -228,7 +228,7 @@ static void test_load(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
large_load(&data[i].t, &data[i].s); large_load(&data[i].t, &data[i].s);
@ -241,7 +241,7 @@ static void test_load(int index) {
testFinish(); testFinish();
} }
static void test_load_str_u64(int index) { static void test_load_str_u64(const testCtx *const p_ctx) {
struct item { struct item {
large_int t; large_int t;
@ -249,15 +249,15 @@ static void test_load_str_u64(int index) {
int length; int length;
large_int expected; large_int expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { LI(0, 0), "0", -1, LI(0, 0) }, /* 0*/ { LI(0, 0), "0", -1, LI(0, 0) },
/* 1*/ { LI(0, 1), "1", -1, LI(1, 0) }, /* 1*/ { LI(0, 1), "1", -1, LI(1, 0) },
/* 2*/ { LI(1, 1), "4294967296", -1, LI(4294967296, 0) }, /* 2*/ { LI(1, 1), "4294967296", -1, LI(4294967296, 0) },
/* 3*/ { LI(1, 1), "18446744073709551615", -1, LI(0xFFFFFFFFFFFFFFFF, 0) }, /* 3*/ { LI(1, 1), "18446744073709551615", -1, LI(0xFFFFFFFFFFFFFFFF, 0) },
/* 4*/ { LI(1, 1), "18446744073709551616", -1, LI(0, 0) }, // Overflow 18446744073709551616 == 2^64 == 0 /* 4*/ { LI(1, 1), "18446744073709551616", -1, LI(0, 0) }, /* Overflow 18446744073709551616 == 2^64 == 0 */
/* 5*/ { LI(2, 2), "123", 2, LI(12, 0) }, // Only reads up to length /* 5*/ { LI(2, 2), "123", 2, LI(12, 0) }, /* Only reads up to length */
/* 6*/ { LI(2, 2), "123A1X", -1, LI(123, 0) }, // Only reads decimal /* 6*/ { LI(2, 2), "123A1X", -1, LI(123, 0) }, /* Only reads decimal */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i; int i;
@ -269,7 +269,7 @@ static void test_load_str_u64(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
large_load_str_u64(&data[i].t, (unsigned char *) data[i].s, data[i].length == -1 ? (int) strlen(data[i].s) : data[i].length); large_load_str_u64(&data[i].t, (unsigned char *) data[i].s, data[i].length == -1 ? (int) strlen(data[i].s) : data[i].length);
@ -282,14 +282,14 @@ static void test_load_str_u64(int index) {
testFinish(); testFinish();
} }
static void test_add_u64(int index) { static void test_add_u64(const testCtx *const p_ctx) {
struct item { struct item {
large_int t; large_int t;
uint64_t s; uint64_t s;
large_int expected; large_int expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { LI(0, 0), 0, LI(0, 0) }, /* 0*/ { LI(0, 0), 0, LI(0, 0) },
/* 1*/ { LI(1, 0), 0, LI(1, 0) }, /* 1*/ { LI(1, 0), 0, LI(1, 0) },
@ -301,7 +301,7 @@ static void test_add_u64(int index) {
/* 7*/ { LI(0xFFFFFFFFFFFFFFFE, 100), 4, LI(2, 101) }, /* 7*/ { LI(0xFFFFFFFFFFFFFFFE, 100), 4, LI(2, 101) },
/* 8*/ { LI(0xFFFFFFFFFFFFFF0E, 0xFFFFFE), 0xFF, LI(0xD, 0xFFFFFF) }, /* 8*/ { LI(0xFFFFFFFFFFFFFF0E, 0xFFFFFE), 0xFF, LI(0xD, 0xFFFFFF) },
/* 9*/ { LI(0xFFFFFFFF00000001, 0xFFFFFFFF), 0xFFFFFFFF, LI(0, 0x100000000) }, /* 9*/ { LI(0xFFFFFFFF00000001, 0xFFFFFFFF), 0xFFFFFFFF, LI(0, 0x100000000) },
/* 10*/ { LI(0x0000000000000001, 0xFFFFFFFFFFFFFFFF), 0xFFFFFFFFFFFFFFFF, LI(0, 0) }, // Overflow /* 10*/ { LI(0x0000000000000001, 0xFFFFFFFFFFFFFFFF), 0xFFFFFFFFFFFFFFFF, LI(0, 0) }, /* Overflow */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i; int i;
@ -313,7 +313,7 @@ static void test_add_u64(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
large_add_u64(&data[i].t, data[i].s); large_add_u64(&data[i].t, data[i].s);
@ -326,14 +326,14 @@ static void test_add_u64(int index) {
testFinish(); testFinish();
} }
static void test_sub_u64(int index) { static void test_sub_u64(const testCtx *const p_ctx) {
struct item { struct item {
large_int t; large_int t;
uint64_t s; uint64_t s;
large_int expected; large_int expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { LI(0, 0), 0, LI(0, 0) }, /* 0*/ { LI(0, 0), 0, LI(0, 0) },
/* 1*/ { LI(1, 0), 0, LI(1, 0) }, /* 1*/ { LI(1, 0), 0, LI(1, 0) },
@ -357,7 +357,7 @@ static void test_sub_u64(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
large_sub_u64(&data[i].t, data[i].s); large_sub_u64(&data[i].t, data[i].s);
@ -370,14 +370,14 @@ static void test_sub_u64(int index) {
testFinish(); testFinish();
} }
static void test_mul_u64(int index) { static void test_mul_u64(const testCtx *const p_ctx) {
struct item { struct item {
large_int t; large_int t;
uint64_t s; uint64_t s;
large_int expected; large_int expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { LI(0, 0), 0, LI(0, 0) }, /* 0*/ { LI(0, 0), 0, LI(0, 0) },
/* 1*/ { LI(1, 0), 0, LI(0, 0) }, /* 1*/ { LI(1, 0), 0, LI(0, 0) },
@ -392,7 +392,7 @@ static void test_mul_u64(int index) {
/* 10*/ { LI(0xFFFFFFFFFFFFFFFF, 0x3FFFFFFFFFFFFFFF), 4, LI(0xFFFFFFFFFFFFFFFC, 0xFFFFFFFFFFFFFFFF) }, /* 10*/ { LI(0xFFFFFFFFFFFFFFFF, 0x3FFFFFFFFFFFFFFF), 4, LI(0xFFFFFFFFFFFFFFFC, 0xFFFFFFFFFFFFFFFF) },
/* 11*/ { LI(0x3333333333333333, 0x111), 5, LI(0xFFFFFFFFFFFFFFFF, 0x555) }, /* 11*/ { LI(0x3333333333333333, 0x111), 5, LI(0xFFFFFFFFFFFFFFFF, 0x555) },
/* 12*/ { LI(0x3333333333333334, 0x111), 5, LI(4, 0x556) }, /* 12*/ { LI(0x3333333333333334, 0x111), 5, LI(4, 0x556) },
/* 13*/ { LI(0x2222222222222222, 0x2222222222222222), 8, LI(0x1111111111111110, 0x1111111111111111) }, // Overflow /* 13*/ { LI(0x2222222222222222, 0x2222222222222222), 8, LI(0x1111111111111110, 0x1111111111111111) }, /* Overflow */
/* 14*/ { LI(432, 518), 10, LI(4320, 5180) }, /* 14*/ { LI(432, 518), 10, LI(4320, 5180) },
/* 15*/ { LI(0xCCCCCCCCCCCCCCCC, 0xCCCCCCCCCCCCCCC), 20, LI(0xFFFFFFFFFFFFFFF0, 0xFFFFFFFFFFFFFFFF) }, /* 15*/ { LI(0xCCCCCCCCCCCCCCCC, 0xCCCCCCCCCCCCCCC), 20, LI(0xFFFFFFFFFFFFFFF0, 0xFFFFFFFFFFFFFFFF) },
/* 16*/ { LI(432, 518), 100, LI(43200, 51800) }, /* 16*/ { LI(432, 518), 100, LI(43200, 51800) },
@ -414,7 +414,7 @@ static void test_mul_u64(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
large_mul_u64(&data[i].t, data[i].s); large_mul_u64(&data[i].t, data[i].s);
@ -427,7 +427,7 @@ static void test_mul_u64(int index) {
testFinish(); testFinish();
} }
static void test_div_u64(int index) { static void test_div_u64(const testCtx *const p_ctx) {
uint64_t r; uint64_t r;
struct item { struct item {
@ -436,12 +436,12 @@ static void test_div_u64(int index) {
uint64_t expected_r; uint64_t expected_r;
large_int expected; large_int expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { LI(0, 0), 1, 0, LI(0, 0) }, /* 0*/ { LI(0, 0), 1, 0, LI(0, 0) },
/* 1*/ { LI(1, 0), 1, 0, LI(1, 0) }, /* 1*/ { LI(1, 0), 1, 0, LI(1, 0) },
/* 2*/ { LI(4990000, 0), 509999, 400009, LI(9, 0) }, /* 2*/ { LI(4990000, 0), 509999, 400009, LI(9, 0) },
/* 3*/ { LI(3, 0), 2, 1, LI(1, 0) }, // BEGIN divmnu64.c.txt (first 3 errors) /* 3*/ { LI(3, 0), 2, 1, LI(1, 0) }, /* BEGIN divmnu64.c.txt (first 3 errors) */
/* 4*/ { LI(3, 0), 3, 0, LI(1, 0) }, /* 4*/ { LI(3, 0), 3, 0, LI(1, 0) },
/* 5*/ { LI(3, 0), 4, 3, LI(0, 0) }, /* 5*/ { LI(3, 0), 4, 3, LI(0, 0) },
/* 6*/ { LI(0, 0), 0xFFFFFFFF, 0, LI(0, 0) }, /* 6*/ { LI(0, 0), 0xFFFFFFFF, 0, LI(0, 0) },
@ -465,10 +465,10 @@ static void test_div_u64(int index) {
/* 24*/ { LI(0x0000FFFF0000FFFF, 0), 0x0000FFFF0000FFFF, 0, LI(1, 0) }, /* 24*/ { LI(0x0000FFFF0000FFFF, 0), 0x0000FFFF0000FFFF, 0, LI(1, 0) },
/* 25*/ { LI(0x0000FFFF0000FFFF, 0), 0x100000000, 0x0000FFFF, LI(0x0000FFFF, 0) }, /* 25*/ { LI(0x0000FFFF0000FFFF, 0), 0x100000000, 0x0000FFFF, LI(0x0000FFFF, 0) },
/* 26*/ { LI(0x00004567000089AB, 0x00000123), 0x100000000, 0x000089AB, LI(0x0000012300004567, 0) }, /* 26*/ { LI(0x00004567000089AB, 0x00000123), 0x100000000, 0x000089AB, LI(0x0000012300004567, 0) },
/* 27*/ { LI(0x0000FFFE00000000, 0x00008000), 0x000080000000FFFF, 0x7FFF0000FFFF, LI(0xFFFFFFFF, 0) }, // END divmnu64.c.txt (last 6 96-bit divisor); shows that first qhat0 can = b + 1 /* 27*/ { LI(0x0000FFFE00000000, 0x00008000), 0x000080000000FFFF, 0x7FFF0000FFFF, LI(0xFFFFFFFF, 0) }, /* END divmnu64.c.txt (last 6 96-bit divisor); shows that first qhat0 can = b + 1 */
/* 28*/ { LI(0, 0x80000000FFFE0000), 0x80000000FFFF0000, 0x1FFFE00000000, LI(0xFFFFFFFFFFFE0000, 0) }, // Shows that first qhat1 can = b + 1 /* 28*/ { LI(0, 0x80000000FFFE0000), 0x80000000FFFF0000, 0x1FFFE00000000, LI(0xFFFFFFFFFFFE0000, 0) }, /* Shows that first qhat1 can = b + 1 */
/* 29*/ { LI(0xFFFE000000000000, 0x80000000), 0x80000000FFFF0000, 0x7FFF0000FFFF0000, LI(0xFFFFFFFF, 0) }, // First qhat0 = b + 1 /* 29*/ { LI(0xFFFE000000000000, 0x80000000), 0x80000000FFFF0000, 0x7FFF0000FFFF0000, LI(0xFFFFFFFF, 0) }, /* First qhat0 = b + 1 */
/* 30*/ { LI(0x7FFF800000000000, 0), 0x800000000001, 0x7FFFFFFF0002, LI(0xFFFE, 0) }, // "add back" examples won't trigger as divisor only 2 digits (in 2**32 base) /* 30*/ { LI(0x7FFF800000000000, 0), 0x800000000001, 0x7FFFFFFF0002, LI(0xFFFE, 0) }, /* "add back" examples won't trigger as divisor only 2 digits (in 2**32 base) */
/* 31*/ { LI(0, 0x7FFF800000000000), 0x800000000001, 0x1FFFE0000, LI(0xFFFFFFFE00020000, 0xFFFE) }, /* 31*/ { LI(0, 0x7FFF800000000000), 0x800000000001, 0x1FFFE0000, LI(0xFFFFFFFE00020000, 0xFFFE) },
/* 32*/ { LI(0x0000000000000003, 0x80000000), 0x2000000000000001, 0x1FFFFFFC00000004, LI(0x3FFFFFFFF, 0) }, /* 32*/ { LI(0x0000000000000003, 0x80000000), 0x2000000000000001, 0x1FFFFFFC00000004, LI(0x3FFFFFFFF, 0) },
/* 33*/ { LI(0x0000000000000003, 0x00008000), 0x2000000000000001, 0x1FFFFFFFFFFC0004, LI(0x3FFFF, 0) }, /* 33*/ { LI(0x0000000000000003, 0x00008000), 0x2000000000000001, 0x1FFFFFFFFFFC0004, LI(0x3FFFF, 0) },
@ -506,26 +506,26 @@ static void test_div_u64(int index) {
/* 65*/ { LI(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0x3000000000000000, 0xFFFFFFFFFFFFFFF, LI(0x5555555555555555, 5) }, /* 65*/ { LI(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0x3000000000000000, 0xFFFFFFFFFFFFFFF, LI(0x5555555555555555, 5) },
/* 66*/ { LI(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0xFFFFFFFFFFFFFFFF, 0, LI(1, 1) }, /* 66*/ { LI(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0xFFFFFFFFFFFFFFFF, 0, LI(1, 1) },
/* 67*/ { LI(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFEFFFFFFFF), 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFEFFFFFFFF, LI(0xFFFFFFFF00000000, 0) }, /* 67*/ { LI(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFEFFFFFFFF), 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFEFFFFFFFF, LI(0xFFFFFFFF00000000, 0) },
/* 68*/ { LI(0x00000F70677372AE, 0), 0x453AF5, 0, LI(0x391736, 0) }, // Divisor 0x453AF5 (4537077) used by RSS14 /* 68*/ { LI(0x00000F70677372AE, 0), 0x453AF5, 0, LI(0x391736, 0) }, /* Divisor 0x453AF5 (4537077) used by RSS14 */
/* 69*/ { LI(0x00000F70677372AF, 0), 0x453AF5, 1, LI(0x391736, 0) }, /* 69*/ { LI(0x00000F70677372AF, 0), 0x453AF5, 1, LI(0x391736, 0) },
/* 70*/ { LI(0x00000F70677372B0, 0), 0x453AF5, 2, LI(0x391736, 0) }, /* 70*/ { LI(0x00000F70677372B0, 0), 0x453AF5, 2, LI(0x391736, 0) },
/* 71*/ { LI(0x453AF4, 0), 0x453AF5, 0x453AF4, LI(0, 0) }, /* 71*/ { LI(0x453AF4, 0), 0x453AF5, 0x453AF4, LI(0, 0) },
/* 72*/ { LI(0x453AF5, 0), 0x453AF5, 0, LI(1, 0) }, /* 72*/ { LI(0x453AF5, 0), 0x453AF5, 0, LI(1, 0) },
/* 73*/ { LI(0x453AF6, 0), 0x453AF5, 1, LI(1, 0) }, /* 73*/ { LI(0x453AF6, 0), 0x453AF5, 1, LI(1, 0) },
/* 74*/ { { 0x453AF5 * 10 - 1, 0 }, 0x453AF5, 0x453AF4, LI(9, 0) }, /* 74*/ { { 0x453AF5 * 10 - 1, 0 }, 0x453AF5, 0x453AF4, LI(9, 0) },
/* 75*/ { LI(0x000003A03166E0CE, 0), 0x1EB983, 0x1EB982, LI(0x1E35C4, 0) }, // Divisor 0x1EB983 (2013571) used by RSS_LTD /* 75*/ { LI(0x000003A03166E0CE, 0), 0x1EB983, 0x1EB982, LI(0x1E35C4, 0) }, /* Divisor 0x1EB983 (2013571) used by RSS_LTD */
/* 76*/ { LI(0x000003A03166E0CF, 0), 0x1EB983, 0, LI(0x1E35C5, 0) }, /* 76*/ { LI(0x000003A03166E0CF, 0), 0x1EB983, 0, LI(0x1E35C5, 0) },
/* 77*/ { LI(0x000003A03166E0D0, 0), 0x1EB983, 1, LI(0x1E35C5, 0) }, /* 77*/ { LI(0x000003A03166E0D0, 0), 0x1EB983, 1, LI(0x1E35C5, 0) },
/* 78*/ { LI(0x93BB793904CAFFFF, 0x13F50B74), 32, 0x1F, LI(0xA49DDBC9C82657FF, 0x9FA85B) }, // Divisor 32 used by MAILMARK /* 78*/ { LI(0x93BB793904CAFFFF, 0x13F50B74), 32, 0x1F, LI(0xA49DDBC9C82657FF, 0x9FA85B) }, /* Divisor 32 used by MAILMARK */
/* 79*/ { LI(0x93BB793904CB0000, 0x13F50B74), 32, 0, LI(0xA49DDBC9C8265800, 0x9FA85B) }, /* 79*/ { LI(0x93BB793904CB0000, 0x13F50B74), 32, 0, LI(0xA49DDBC9C8265800, 0x9FA85B) },
/* 80*/ { LI(0x93BB793904CB0001, 0x13F50B74), 32, 1, LI(0xA49DDBC9C8265800, 0x9FA85B) }, /* 80*/ { LI(0x93BB793904CB0001, 0x13F50B74), 32, 1, LI(0xA49DDBC9C8265800, 0x9FA85B) },
/* 81*/ { LI(0x93BB793904CAFFFF, 0x13F50B74), 30, 0x1D, LI(0x8D752EB519C27FFF, 0xAA4D2E) }, // Divisor 30 used by MAILMARK /* 81*/ { LI(0x93BB793904CAFFFF, 0x13F50B74), 30, 0x1D, LI(0x8D752EB519C27FFF, 0xAA4D2E) }, /* Divisor 30 used by MAILMARK */
/* 82*/ { LI(0x93BB793904CB0000, 0x13F50B74), 30, 0, LI(0x8D752EB519C28000, 0xAA4D2E) }, /* 82*/ { LI(0x93BB793904CB0000, 0x13F50B74), 30, 0, LI(0x8D752EB519C28000, 0xAA4D2E) },
/* 83*/ { LI(0x93BB793904CB0001, 0x13F50B74), 30, 1, LI(0x8D752EB519C28000, 0xAA4D2E) }, /* 83*/ { LI(0x93BB793904CB0001, 0x13F50B74), 30, 1, LI(0x8D752EB519C28000, 0xAA4D2E) },
/* 84*/ { LI(0x4ABC16A2E5C005FF, 0x16907B2A2), 636, 635, LI(0xD70F9761AA390E7F, 0x9151FD) }, // Divisor 636 used by ONECODE /* 84*/ { LI(0x4ABC16A2E5C005FF, 0x16907B2A2), 636, 635, LI(0xD70F9761AA390E7F, 0x9151FD) }, /* Divisor 636 used by ONECODE */
/* 85*/ { LI(0x4ABC16A2E5C00600, 0x16907B2A2), 636, 0, LI(0xD70F9761AA390E80, 0x9151FD) }, /* 85*/ { LI(0x4ABC16A2E5C00600, 0x16907B2A2), 636, 0, LI(0xD70F9761AA390E80, 0x9151FD) },
/* 86*/ { LI(0x4ABC16A2E5C00601, 0x16907B2A2), 636, 1, LI(0xD70F9761AA390E80, 0x9151FD) }, /* 86*/ { LI(0x4ABC16A2E5C00601, 0x16907B2A2), 636, 1, LI(0xD70F9761AA390E80, 0x9151FD) },
/* 87*/ { LI(0x4ABC16A2E5C00734, 0x16907B2A2), 1365, 1364, LI(0xD93B96FDAE65FA60, 0x43B5AC) }, // Divisor 1365 used by ONECODE /* 87*/ { LI(0x4ABC16A2E5C00734, 0x16907B2A2), 1365, 1364, LI(0xD93B96FDAE65FA60, 0x43B5AC) }, /* Divisor 1365 used by ONECODE */
/* 88*/ { LI(0x4ABC16A2E5C00735, 0x16907B2A2), 1365, 0, LI(0xD93B96FDAE65FA61, 0x43B5AC) }, /* 88*/ { LI(0x4ABC16A2E5C00735, 0x16907B2A2), 1365, 0, LI(0xD93B96FDAE65FA61, 0x43B5AC) },
/* 89*/ { LI(0x4ABC16A2E5C00736, 0x16907B2A2), 1365, 1, LI(0xD93B96FDAE65FA61, 0x43B5AC) }, /* 89*/ { LI(0x4ABC16A2E5C00736, 0x16907B2A2), 1365, 1, LI(0xD93B96FDAE65FA61, 0x43B5AC) },
}; };
@ -539,7 +539,7 @@ static void test_div_u64(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
r = large_div_u64(&data[i].t, data[i].s); r = large_div_u64(&data[i].t, data[i].s);
@ -554,14 +554,14 @@ static void test_div_u64(int index) {
testFinish(); testFinish();
} }
static void test_unset_bit(int index) { static void test_unset_bit(const testCtx *const p_ctx) {
struct item { struct item {
large_int t; large_int t;
int s; int s;
large_int expected; large_int expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { LI(0, 0), 0, LI(0, 0) }, /* 0*/ { LI(0, 0), 0, LI(0, 0) },
/* 1*/ { LI(0, 0xFFFFFFFFFFFFFFFF), 0, LI(0, 0xFFFFFFFFFFFFFFFF) }, /* 1*/ { LI(0, 0xFFFFFFFFFFFFFFFF), 0, LI(0, 0xFFFFFFFFFFFFFFFF) },
@ -705,7 +705,7 @@ static void test_unset_bit(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
large_unset_bit(&data[i].t, data[i].s); large_unset_bit(&data[i].t, data[i].s);
@ -718,7 +718,7 @@ static void test_unset_bit(int index) {
testFinish(); testFinish();
} }
static void test_uint_array(int index) { static void test_uint_array(const testCtx *const p_ctx) {
struct item { struct item {
large_int t; large_int t;
@ -726,7 +726,7 @@ static void test_uint_array(int index) {
int bits; int bits;
unsigned int expected[130]; unsigned int expected[130];
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { LI(0, 0), 0, 0, { 0 } }, /* 0*/ { LI(0, 0), 0, 0, { 0 } },
/* 1*/ { LI(1, 1), 16, 0, { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 } }, /* 1*/ { LI(1, 1), 16, 0, { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 } },
@ -757,10 +757,10 @@ static void test_uint_array(int index) {
/* 26*/ { LI(1, 1), 7, 19, { 0, 0, 0, 0x80, 0, 0, 1 } }, /* 26*/ { LI(1, 1), 7, 19, { 0, 0, 0, 0x80, 0, 0, 1 } },
/* 27*/ { LI(1, 1), 5, 31, { 0, 0, 4, 0, 1 } }, /* 27*/ { LI(1, 1), 5, 31, { 0, 0, 4, 0, 1 } },
/* 28*/ { LI(1, 1), 4, 32, { 0, 1, 0, 1 } }, /* 28*/ { LI(1, 1), 4, 32, { 0, 1, 0, 1 } },
/* 29*/ { LI(1, 1), 4, 33, { 0, 1, 0, 1 } }, // Bits > 32 ignored and treated as 32 /* 29*/ { LI(1, 1), 4, 33, { 0, 1, 0, 1 } }, /* Bits > 32 ignored and treated as 32 */
/* 30*/ { LI(0xF0F0F0F0F0F0F0F0, 0xE0F0F0F0F0F0F0F0), 129, 1, { 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 } }, // Leading zeroes /* 30*/ { LI(0xF0F0F0F0F0F0F0F0, 0xE0F0F0F0F0F0F0F0), 129, 1, { 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 } }, /* Leading zeroes */
/* 31*/ { LI(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 130, 1, { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } }, // Leading zeroes /* 31*/ { LI(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 130, 1, { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } }, /* Leading zeroes */
/* 32*/ { LI(0xFFFFFFFFFFFFFFFF, 0xEFFFFFFFFFFFFFFF), 127, 1, { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } }, // Truncated /* 32*/ { LI(0xFFFFFFFFFFFFFFFF, 0xEFFFFFFFFFFFFFFF), 127, 1, { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } }, /* Truncated */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i; int i;
@ -779,7 +779,7 @@ static void test_uint_array(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
memset(uint_array, 0, sizeof(uint_array)); memset(uint_array, 0, sizeof(uint_array));
@ -807,13 +807,13 @@ static void test_uint_array(int index) {
testFinish(); testFinish();
} }
static void test_dump(int index) { static void test_dump(const testCtx *const p_ctx) {
struct item { struct item {
large_int t; large_int t;
char *expected; char *expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { LI(0, 0), "0x0" }, /* 0*/ { LI(0, 0), "0x0" },
/* 1*/ { LI(1, 0), "0x1" }, /* 1*/ { LI(1, 0), "0x1" },
@ -870,7 +870,7 @@ static void test_dump(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
memset(dump, 0, sizeof(dump)); memset(dump, 0, sizeof(dump));
@ -885,17 +885,17 @@ static void test_dump(int index) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_clz_u64", test_clz_u64, 1, 0, 0 }, { "test_clz_u64", test_clz_u64 },
{ "test_load", test_load, 1, 0, 0 }, { "test_load", test_load },
{ "test_load_str_u64", test_load_str_u64, 1, 0, 0 }, { "test_load_str_u64", test_load_str_u64 },
{ "test_add_u64", test_add_u64, 1, 0, 0 }, { "test_add_u64", test_add_u64 },
{ "test_sub_u64", test_sub_u64, 1, 0, 0 }, { "test_sub_u64", test_sub_u64 },
{ "test_mul_u64", test_mul_u64, 1, 0, 0 }, { "test_mul_u64", test_mul_u64 },
{ "test_div_u64", test_div_u64, 1, 0, 0 }, { "test_div_u64", test_div_u64 },
{ "test_unset_bit", test_unset_bit, 1, 0, 0 }, { "test_unset_bit", test_unset_bit },
{ "test_uint_array", test_uint_array, 1, 0, 0 }, { "test_uint_array", test_uint_array },
{ "test_dump", test_dump, 1, 0, 0 }, { "test_dump", test_dump },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -34,7 +34,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <errno.h> #include <errno.h>
static void test_checks(int index, int debug) { static void test_checks(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -220,7 +221,7 @@ static void test_checks(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -269,7 +270,8 @@ static void test_checks(int index, int debug) {
testFinish(); testFinish();
} }
static void test_checks_segs(int index, int debug) { static void test_checks_segs(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -309,7 +311,7 @@ static void test_checks_segs(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -331,7 +333,8 @@ static void test_checks_segs(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input_data(int index, int debug) { static void test_input_data(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -363,7 +366,7 @@ static void test_input_data(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -388,13 +391,15 @@ static void test_input_data(int index, int debug) {
testFinish(); testFinish();
} }
static void test_symbologies(void) { static void test_symbologies(const testCtx *const p_ctx) {
int i, ret; int i, ret;
struct zint_symbol symbol = {0}; struct zint_symbol symbol = {0};
testStart("test_symbologies"); testStart("test_symbologies");
for (i = -1; i < 148; i++) { for (i = -1; i < 148; i++) {
if (testContinue(p_ctx, i)) continue;
symbol.symbology = i; symbol.symbology = i;
ret = ZBarcode_Encode(&symbol, TU("1"), 0); ret = ZBarcode_Encode(&symbol, TU("1"), 0);
assert_notequal(ret, ZINT_ERROR_ENCODING_PROBLEM, "i:%d Encoding problem (%s)\n", i, symbol.errtxt); assert_notequal(ret, ZINT_ERROR_ENCODING_PROBLEM, "i:%d Encoding problem (%s)\n", i, symbol.errtxt);
@ -403,7 +408,8 @@ static void test_symbologies(void) {
testFinish(); testFinish();
} }
static void test_input_mode(int index, int debug) { static void test_input_mode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -434,7 +440,7 @@ static void test_input_mode(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -451,7 +457,8 @@ static void test_input_mode(int index, int debug) {
testFinish(); testFinish();
} }
static void test_escape_char_process(int index, int generate, int debug) { static void test_escape_char_process(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -559,8 +566,7 @@ static void test_escape_char_process(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -579,7 +585,7 @@ static void test_escape_char_process(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, TU(text), length); ret = ZBarcode_Encode(symbol, TU(text), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, \"%s\", \"%s\", %s, %d, \"%s\", %d, \"%s\" },\n", printf(" /*%3d*/ { %s, %s, %d, \"%s\", \"%s\", %s, %d, \"%s\", %d, \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].eci, i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].eci,
testUtilEscape(data[i].data, length, escaped, ARRAY_SIZE(escaped)), testUtilEscape(data[i].data, length, escaped, ARRAY_SIZE(escaped)),
@ -590,7 +596,7 @@ static void test_escape_char_process(int index, int generate, int debug) {
if (ret < ZINT_ERROR) { if (ret < ZINT_ERROR) {
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data); assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
if (index == -1 && data[i].compare_previous) { if (p_ctx->index == -1 && data[i].compare_previous) {
ret = testUtilSymbolCmp(symbol, &previous_symbol); ret = testUtilSymbolCmp(symbol, &previous_symbol);
assert_zero(ret, "i:%d testUtilSymbolCmp ret %d != 0\n", i, ret); assert_zero(ret, "i:%d testUtilSymbolCmp ret %d != 0\n", i, ret);
} }
@ -633,7 +639,7 @@ static void test_escape_char_process(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_cap(int index) { static void test_cap(const testCtx *const p_ctx) {
struct item { struct item {
int symbology; int symbology;
@ -660,7 +666,7 @@ static void test_cap(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
ret = ZBarcode_Cap(data[i].symbology, data[i].cap_flag); ret = ZBarcode_Cap(data[i].symbology, data[i].cap_flag);
assert_equal(ret, data[i].expected, "i:%d ZBarcode_Cap(%s, 0x%X) 0x%X != 0x%X\n", i, testUtilBarcodeName(data[i].symbology), data[i].cap_flag, ret, data[i].expected); assert_equal(ret, data[i].expected, "i:%d ZBarcode_Cap(%s, 0x%X) 0x%X != 0x%X\n", i, testUtilBarcodeName(data[i].symbology), data[i].cap_flag, ret, data[i].expected);
@ -669,7 +675,7 @@ static void test_cap(int index) {
testFinish(); testFinish();
} }
static void test_cap_compliant_height(void) { static void test_cap_compliant_height(const testCtx *const p_ctx) {
int symbol_id; int symbol_id;
int ret; int ret;
@ -677,11 +683,12 @@ static void test_cap_compliant_height(void) {
for (symbol_id = 1; symbol_id <= BARCODE_LAST; symbol_id++) { for (symbol_id = 1; symbol_id <= BARCODE_LAST; symbol_id++) {
if (!ZBarcode_ValidID(symbol_id)) continue; if (!ZBarcode_ValidID(symbol_id)) continue;
if (testContinue(p_ctx, symbol_id)) continue;
ret = ZBarcode_Cap(symbol_id, ZINT_CAP_COMPLIANT_HEIGHT); ret = ZBarcode_Cap(symbol_id, ZINT_CAP_COMPLIANT_HEIGHT);
switch (symbol_id) { switch (symbol_id) {
//case BARCODE_CODE11: /* TODO: Find doc */ /*case BARCODE_CODE11: TODO: Find doc */
case BARCODE_C25INTER: case BARCODE_C25INTER:
case BARCODE_CODE39: case BARCODE_CODE39:
case BARCODE_EXCODE39: case BARCODE_EXCODE39:
@ -689,12 +696,12 @@ static void test_cap_compliant_height(void) {
case BARCODE_EANX_CHK: case BARCODE_EANX_CHK:
case BARCODE_GS1_128: case BARCODE_GS1_128:
case BARCODE_CODABAR: case BARCODE_CODABAR:
//case BARCODE_DPLEIT: /* TODO: Find doc */ /*case BARCODE_DPLEIT: TODO: Find doc */
//case BARCODE_DPIDENT: /* TODO: Find doc */ /*case BARCODE_DPIDENT: TODO: Find doc */
case BARCODE_CODE16K: case BARCODE_CODE16K:
case BARCODE_CODE49: case BARCODE_CODE49:
case BARCODE_CODE93: case BARCODE_CODE93:
//case BARCODE_FLAT: /* TODO: Find doc */ /*case BARCODE_FLAT: TODO: Find doc */
case BARCODE_DBAR_OMN: case BARCODE_DBAR_OMN:
case BARCODE_DBAR_LTD: case BARCODE_DBAR_LTD:
case BARCODE_DBAR_EXP: case BARCODE_DBAR_EXP:
@ -704,7 +711,7 @@ static void test_cap_compliant_height(void) {
case BARCODE_UPCE: case BARCODE_UPCE:
case BARCODE_UPCE_CHK: case BARCODE_UPCE_CHK:
case BARCODE_POSTNET: case BARCODE_POSTNET:
//case BARCODE_MSI_PLESSEY: /* TODO: Find doc */ /*case BARCODE_MSI_PLESSEY: TODO: Find doc */
case BARCODE_FIM: case BARCODE_FIM:
case BARCODE_LOGMARS: case BARCODE_LOGMARS:
case BARCODE_PHARMA: case BARCODE_PHARMA:
@ -718,17 +725,17 @@ static void test_cap_compliant_height(void) {
case BARCODE_ISBNX: case BARCODE_ISBNX:
case BARCODE_RM4SCC: case BARCODE_RM4SCC:
case BARCODE_EAN14: case BARCODE_EAN14:
//case BARCODE_VIN: /* Spec unlikely */ /*case BARCODE_VIN: Spec unlikely */
case BARCODE_CODABLOCKF: case BARCODE_CODABLOCKF:
case BARCODE_NVE18: case BARCODE_NVE18:
case BARCODE_JAPANPOST: case BARCODE_JAPANPOST:
//case BARCODE_KOREAPOST: /* TODO: Find doc */ /*case BARCODE_KOREAPOST: TODO: Find doc */
case BARCODE_DBAR_STK: case BARCODE_DBAR_STK:
case BARCODE_DBAR_OMNSTK: case BARCODE_DBAR_OMNSTK:
case BARCODE_DBAR_EXPSTK: case BARCODE_DBAR_EXPSTK:
case BARCODE_PLANET: case BARCODE_PLANET:
case BARCODE_USPS_IMAIL: case BARCODE_USPS_IMAIL:
//case BARCODE_PLESSEY: /* TODO: Find doc */ /*case BARCODE_PLESSEY: TODO: Find doc */
case BARCODE_TELEPEN_NUM: case BARCODE_TELEPEN_NUM:
case BARCODE_ITF14: case BARCODE_ITF14:
case BARCODE_KIX: case BARCODE_KIX:
@ -760,12 +767,14 @@ static void test_cap_compliant_height(void) {
testFinish(); testFinish();
} }
static void test_encode_file_empty(void) { static void test_encode_file_empty(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol *symbol; struct zint_symbol *symbol;
char filename[] = "in.bin"; char filename[] = "in.bin";
FILE *fstream; FILE *fstream;
(void)p_ctx;
testStart("test_encode_file_empty"); testStart("test_encode_file_empty");
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
@ -789,13 +798,15 @@ static void test_encode_file_empty(void) {
testFinish(); testFinish();
} }
static void test_encode_file_too_large(void) { static void test_encode_file_too_large(const testCtx *const p_ctx) {
char filename[] = "in.bin"; char filename[] = "in.bin";
FILE *fstream; FILE *fstream;
int ret; int ret;
struct zint_symbol *symbol; struct zint_symbol *symbol;
char buf[ZINT_MAX_DATA_LEN + 1] = {0}; char buf[ZINT_MAX_DATA_LEN + 1] = {0};
(void)p_ctx;
testStart("test_encode_file_too_large"); testStart("test_encode_file_too_large");
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
@ -822,7 +833,7 @@ static void test_encode_file_too_large(void) {
} }
/* #181 Nico Gunkel OSS-Fuzz */ /* #181 Nico Gunkel OSS-Fuzz */
static void test_encode_file_unreadable(void) { static void test_encode_file_unreadable(const testCtx *const p_ctx) {
#ifndef _WIN32 #ifndef _WIN32
int ret; int ret;
struct zint_symbol *symbol; struct zint_symbol *symbol;
@ -832,6 +843,8 @@ static void test_encode_file_unreadable(void) {
int fd; int fd;
#endif #endif
(void)p_ctx;
testStart("test_encode_file_unreadable"); testStart("test_encode_file_unreadable");
#ifdef _WIN32 #ifdef _WIN32
@ -866,11 +879,13 @@ static void test_encode_file_unreadable(void) {
} }
/* #181 Nico Gunkel OSS-Fuzz (buffer not freed on fread() error) Note: unable to reproduce fread() error using this method */ /* #181 Nico Gunkel OSS-Fuzz (buffer not freed on fread() error) Note: unable to reproduce fread() error using this method */
static void test_encode_file_directory(void) { static void test_encode_file_directory(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol *symbol; struct zint_symbol *symbol;
char dirname[] = "in_dir"; char dirname[] = "in_dir";
(void)p_ctx;
testStart("test_encode_file_directory"); testStart("test_encode_file_directory");
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
@ -891,7 +906,7 @@ static void test_encode_file_directory(void) {
testFinish(); testFinish();
} }
static void test_encode_file(void) { static void test_encode_file(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol *symbol; struct zint_symbol *symbol;
char *data = "1"; char *data = "1";
@ -899,6 +914,8 @@ static void test_encode_file(void) {
char *outfile = "test_encode_file_out.gif"; char *outfile = "test_encode_file_out.gif";
FILE *fp; FILE *fp;
(void)p_ctx;
testStart("test_encode_file"); testStart("test_encode_file");
(void) remove(filename); /* In case junk hanging around */ (void) remove(filename); /* In case junk hanging around */
@ -954,11 +971,13 @@ static void test_encode_file(void) {
testFinish(); testFinish();
} }
static void test_encode_print_outfile_directory(void) { static void test_encode_print_outfile_directory(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol *symbol; struct zint_symbol *symbol;
char dirname[] = "outdir.txt"; char dirname[] = "outdir.txt";
(void)p_ctx;
testStart("test_encode_print_outfile_directory"); testStart("test_encode_print_outfile_directory");
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
@ -980,7 +999,7 @@ static void test_encode_print_outfile_directory(void) {
testFinish(); testFinish();
} }
static void test_bad_args(void) { static void test_bad_args(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol *symbol; struct zint_symbol *symbol;
char *data = "1"; char *data = "1";
@ -990,6 +1009,8 @@ static void test_bad_args(void) {
struct zint_seg seg_empty = { TU(""), -1, 4 }; struct zint_seg seg_empty = { TU(""), -1, 4 };
struct zint_seg seg_too_long = { TU("1"), ZINT_MAX_DATA_LEN + 1, 4 }; struct zint_seg seg_too_long = { TU("1"), ZINT_MAX_DATA_LEN + 1, 4 };
(void)p_ctx;
testStart("test_bad_args"); testStart("test_bad_args");
/* These just return, no error */ /* These just return, no error */
@ -1120,12 +1141,14 @@ static void test_bad_args(void) {
testFinish(); testFinish();
} }
static void test_valid_id(void) { static void test_valid_id(const testCtx *const p_ctx) {
int ret; int ret;
const char *name; const char *name;
int symbol_id; int symbol_id;
(void)p_ctx;
testStart("test_valid_id"); testStart("test_valid_id");
for (symbol_id = -1; symbol_id < 160; symbol_id++) { for (symbol_id = -1; symbol_id < 160; symbol_id++) {
@ -1146,7 +1169,7 @@ static void test_valid_id(void) {
INTERNAL int error_tag_test(struct zint_symbol *symbol, int error_number, const char *error_string); INTERNAL int error_tag_test(struct zint_symbol *symbol, int error_number, const char *error_string);
static void test_error_tag(int index) { static void test_error_tag(const testCtx *const p_ctx) {
struct item { struct item {
int error_number; int error_number;
@ -1181,7 +1204,7 @@ static void test_error_tag(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
struct zint_symbol symbol = {0}; struct zint_symbol symbol = {0};
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol.warn_level = data[i].warn_level; symbol.warn_level = data[i].warn_level;
@ -1202,13 +1225,15 @@ static void test_error_tag(int index) {
INTERNAL void strip_bom_test(unsigned char *source, int *input_length); INTERNAL void strip_bom_test(unsigned char *source, int *input_length);
static void test_strip_bom(void) { static void test_strip_bom(const testCtx *const p_ctx) {
int length, ret; int length, ret;
char data[] = "\357\273\277A"; /* U+FEFF BOM, with "A" */ char data[] = "\357\273\277A"; /* U+FEFF BOM, with "A" */
char bom_only[] = "\357\273\277"; /* U+FEFF BOM only */ char bom_only[] = "\357\273\277"; /* U+FEFF BOM only */
char buf[6]; char buf[6];
(void)p_ctx;
testStart("test_strip_bom"); testStart("test_strip_bom");
strcpy(buf, data); strcpy(buf, data);
@ -1229,12 +1254,14 @@ static void test_strip_bom(void) {
testFinish(); testFinish();
} }
static void test_zero_outfile(void) { static void test_zero_outfile(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol *symbol; struct zint_symbol *symbol;
char *data = "1234"; char *data = "1234";
(void)p_ctx;
testStart("test_zero_outfile"); testStart("test_zero_outfile");
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
@ -1260,12 +1287,14 @@ static void test_zero_outfile(void) {
testFinish(); testFinish();
} }
static void test_clear(void) { static void test_clear(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol *symbol; struct zint_symbol *symbol;
char *data = "1234"; char *data = "1234";
(void)p_ctx;
testStart("test_clear"); testStart("test_clear");
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
@ -1354,27 +1383,27 @@ static void test_clear(void) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_checks", test_checks, 1, 0, 1 }, { "test_checks", test_checks },
{ "test_checks_segs", test_checks_segs, 1, 0, 1 }, { "test_checks_segs", test_checks_segs },
{ "test_input_data", test_input_data, 1, 0, 1 }, { "test_input_data", test_input_data },
{ "test_symbologies", test_symbologies, 0, 0, 0 }, { "test_symbologies", test_symbologies },
{ "test_input_mode", test_input_mode, 1, 0, 1 }, { "test_input_mode", test_input_mode },
{ "test_escape_char_process", test_escape_char_process, 1, 1, 1 }, { "test_escape_char_process", test_escape_char_process },
{ "test_cap", test_cap, 1, 0, 0 }, { "test_cap", test_cap },
{ "test_cap_compliant_height", test_cap_compliant_height, 0, 0, 0 }, { "test_cap_compliant_height", test_cap_compliant_height },
{ "test_encode_file_empty", test_encode_file_empty, 0, 0, 0 }, { "test_encode_file_empty", test_encode_file_empty },
{ "test_encode_file_too_large", test_encode_file_too_large, 0, 0, 0 }, { "test_encode_file_too_large", test_encode_file_too_large },
{ "test_encode_file_unreadable", test_encode_file_unreadable, 0, 0, 0 }, { "test_encode_file_unreadable", test_encode_file_unreadable },
{ "test_encode_file_directory", test_encode_file_directory, 0, 0, 0 }, { "test_encode_file_directory", test_encode_file_directory },
{ "test_encode_file", test_encode_file, 0, 0, 0 }, { "test_encode_file", test_encode_file },
{ "test_encode_print_outfile_directory", test_encode_print_outfile_directory, 0, 0, 0 }, { "test_encode_print_outfile_directory", test_encode_print_outfile_directory },
{ "test_bad_args", test_bad_args, 0, 0, 0 }, { "test_bad_args", test_bad_args },
{ "test_valid_id", test_valid_id, 0, 0, 0 }, { "test_valid_id", test_valid_id },
{ "test_error_tag", test_error_tag, 1, 0, 0 }, { "test_error_tag", test_error_tag },
{ "test_strip_bom", test_strip_bom, 0, 0, 0 }, { "test_strip_bom", test_strip_bom },
{ "test_zero_outfile", test_zero_outfile, 0, 0, 0 }, { "test_zero_outfile", test_zero_outfile },
{ "test_clear", test_clear, 0, 0, 0 }, { "test_clear", test_clear },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -1,6 +1,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2019 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2019-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -27,11 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_input(int index, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -39,62 +40,62 @@ static void test_input(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "41038422416563762XY11 ", 0, 3, 155 }, /* 0*/ { "41038422416563762XY11 ", 0, 3, 155 },
/* 1*/ { "41038422416563762XY11 ", ZINT_ERROR_TOO_LONG, -1, -1 }, /* 1*/ { "41038422416563762XY11 ", ZINT_ERROR_TOO_LONG, -1, -1 },
/* 2*/ { "41038422416563762xy11 ", 0, 3, 155 }, // Case insensitive /* 2*/ { "41038422416563762xy11 ", 0, 3, 155 }, /* Case insensitive */
/* 3*/ { "41038422416563762xy11 .", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 3*/ { "41038422416563762xy11 .", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 4*/ { "0100000000000AA000AA0A", 0, 3, 131, }, // Length 22, Mailmark C (2 digit chain id) /* 4*/ { "0100000000000AA000AA0A", 0, 3, 131, }, /* Length 22, Mailmark C (2 digit chain id) */
/* 5*/ { "5100000000000AA000AA0A", ZINT_ERROR_INVALID_DATA, -1, -1 }, // 1st char format 0-4 only /* 5*/ { "5100000000000AA000AA0A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 1st char format 0-4 only */
/* 6*/ { "0000000000000AA000AA0A", ZINT_ERROR_INVALID_DATA, -1, -1 }, // 2nd char version id 1-4 only /* 6*/ { "0000000000000AA000AA0A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 2nd char version id 1-4 only */
/* 7*/ { "01F0000000000AA000AA0A", ZINT_ERROR_INVALID_DATA, -1, -1 }, // 3rd char class 0-9A-E only /* 7*/ { "01F0000000000AA000AA0A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 3rd char class 0-9A-E only */
/* 8*/ { "0100A00000000AA000AA0A", ZINT_ERROR_INVALID_DATA, -1, -1 }, // 4-5th chars chain id 2 digits /* 8*/ { "0100A00000000AA000AA0A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 4-5th chars chain id 2 digits */
/* 9*/ { "010000000000AAA000AA0A", ZINT_ERROR_INVALID_DATA, -1, -1 }, // 6-13th chars item id 8 digits /* 9*/ { "010000000000AAA000AA0A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 6-13th chars item id 8 digits */
/* 10*/ { "0100000000000 A000AA0A", ZINT_ERROR_INVALID_DATA, -1, -1 }, // Remaining chars post code /* 10*/ { "0100000000000 A000AA0A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* Remaining chars post code */
/* 11*/ { "0100000000000C1I2JQ3N ", 0, 3, 131, }, // F N F N L L N L S /* 11*/ { "0100000000000C1I2JQ3N ", 0, 3, 131, }, /* F N F N L L N L S */
/* 12*/ { "010000000000091I2JQ3N ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F N F N L L N L S bad 1st F /* 12*/ { "010000000000091I2JQ3N ", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F N F N L L N L S bad 1st F */
/* 13*/ { "0100000000000CAI2JQ3N ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F N F N L L N L S bad 1st N /* 13*/ { "0100000000000CAI2JQ3N ", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F N F N L L N L S bad 1st N */
/* 14*/ { "0100000000000C1I2IQ3N ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F N F N L L N L S bad 1st L /* 14*/ { "0100000000000C1I2IQ3N ", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F N F N L L N L S bad 1st L */
/* 15*/ { "0100000000000C1I2IQ3NA", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F N F N L L N L S bad S /* 15*/ { "0100000000000C1I2IQ3NA", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F N F N L L N L S bad S */
/* 16*/ { "0100000000000KM12JQ3N ", 0, 3, 131, }, // F F N N L L N L S /* 16*/ { "0100000000000KM12JQ3N ", 0, 3, 131, }, /* F F N N L L N L S */
/* 17*/ { "0100000000000K 12JQ3N ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F F N N L L N L S bad 2nd F (non-numeric otherwise matches last pattern) /* 17*/ { "0100000000000K 12JQ3N ", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F F N N L L N L S bad 2nd F (non-numeric otherwise matches last pattern) */
/* 18*/ { "0100000000000KM1AJQ3N ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F F N N L L N L S bad 2nd N /* 18*/ { "0100000000000KM1AJQ3N ", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F F N N L L N L S bad 2nd N */
/* 19*/ { "0100000000000KM12JO3N ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F F N N L L N L S bad 2nd L /* 19*/ { "0100000000000KM12JO3N ", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F F N N L L N L S bad 2nd L */
/* 20*/ { "0100000000000KM12JQ3NA", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F F N N L L N L S bad S /* 20*/ { "0100000000000KM12JQ3NA", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F F N N L L N L S bad S */
/* 21*/ { "0100000000000OV123JQ4U", 0, 3, 131, }, // F F N N N L L N L /* 21*/ { "0100000000000OV123JQ4U", 0, 3, 131, }, /* F F N N N L L N L */
/* 22*/ { "01000000000009V123JQ4U", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F F N N N L L N L bad 1st F /* 22*/ { "01000000000009V123JQ4U", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F F N N N L L N L bad 1st F */
/* 23*/ { "0100000000000OV12AJQ4U", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F F N N N L L N L bad 3rd N /* 23*/ { "0100000000000OV12AJQ4U", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F F N N N L L N L bad 3rd N */
/* 24*/ { "0100000000000OV123JQ4V", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F F N N N L L N L bad 3rd L /* 24*/ { "0100000000000OV123JQ4V", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F F N N N L L N L bad 3rd L */
/* 25*/ { "0100000000000CI1K3JQ4U", 0, 3, 131, }, // F F N F N L L N L /* 25*/ { "0100000000000CI1K3JQ4U", 0, 3, 131, }, /* F F N F N L L N L */
/* 26*/ { "0100000000000CI1 3JQ4U", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F F N F N L L N L bad 3rd F (non-numeric otherwise matches pattern above) /* 26*/ { "0100000000000CI1 3JQ4U", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F F N F N L L N L bad 3rd F (non-numeric otherwise matches pattern above) */
/* 27*/ { "0100000000000CIAK3JQ4U", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F F N F N L L N L bad 1st N /* 27*/ { "0100000000000CIAK3JQ4U", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F F N F N L L N L bad 1st N */
/* 28*/ { "0100000000000CI1K3CQ4U", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F F N F N L L N L bad 1st L /* 28*/ { "0100000000000CI1K3CQ4U", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F F N F N L L N L bad 1st L */
/* 29*/ { "0100000000000C12JQ3U ", 0, 3, 131, }, // F N N L L N L S S /* 29*/ { "0100000000000C12JQ3U ", 0, 3, 131, }, /* F N N L L N L S S */
/* 30*/ { "0100000000000912JQ3U ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F N N L L N L S S bad F /* 30*/ { "0100000000000912JQ3U ", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F N N L L N L S S bad F */
/* 31*/ { "0100000000000C1AJQ3U ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F N N L L N L S S bad 2nd N /* 31*/ { "0100000000000C1AJQ3U ", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F N N L L N L S S bad 2nd N */
/* 32*/ { "0100000000000C12JO3U ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F N N L L N L S S bad 2nd L /* 32*/ { "0100000000000C12JO3U ", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F N N L L N L S S bad 2nd L */
/* 33*/ { "0100000000000C12JQ3UA ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F N N L L N L S S bad 1st S /* 33*/ { "0100000000000C12JQ3UA ", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F N N L L N L S S bad 1st S */
/* 34*/ { "0100000000000C123JQ4U ", 0, 3, 131, }, // F N N N L L N L S /* 34*/ { "0100000000000C123JQ4U ", 0, 3, 131, }, /* F N N N L L N L S */
/* 35*/ { "01000000000009123JQ4U ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F N N N L L N L S bad F /* 35*/ { "01000000000009123JQ4U ", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F N N N L L N L S bad F */
/* 36*/ { "0100000000000C12AJQ4U ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F N N N L L N L S bad 3rd N /* 36*/ { "0100000000000C12AJQ4U ", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F N N N L L N L S bad 3rd N */
/* 37*/ { "0100000000000C123JQ4V ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F N N N L L N L S bad 3rd L /* 37*/ { "0100000000000C123JQ4V ", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F N N N L L N L S bad 3rd L */
/* 38*/ { "0100000000000C123JQ4U1", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F N N N L L N L S bad S /* 38*/ { "0100000000000C123JQ4U1", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F N N N L L N L S bad S */
/* 39*/ { "01000000000000000AA000AA0A", 0, 3, 155, }, // Length 26, Mailmark L (6 digit chain id) /* 39*/ { "01000000000000000AA000AA0A", 0, 3, 155, }, /* Length 26, Mailmark L (6 digit chain id) */
/* 40*/ { "010A0000000000000AA000AA0A", ZINT_ERROR_INVALID_DATA, -1, -1 }, // 4-9th chars chain id 6 digits /* 40*/ { "010A0000000000000AA000AA0A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 4-9th chars chain id 6 digits */
/* 41*/ { "010A0000000000000 A000AA0A", ZINT_ERROR_INVALID_DATA, -1, -1 }, // Post code /* 41*/ { "010A0000000000000 A000AA0A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* Post code */
/* 42*/ { "01000000000000000C1I2JQ3N ", 0, 3, 155, }, // F N F N L L N L S /* 42*/ { "01000000000000000C1I2JQ3N ", 0, 3, 155, }, /* F N F N L L N L S */
/* 43*/ { "01000000000000000C1 2JQ3N ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F N F N L L N L S bad 2nd F /* 43*/ { "01000000000000000C1 2JQ3N ", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F N F N L L N L S bad 2nd F */
/* 44*/ { "01000000000000000KM12JQ3N ", 0, 3, 155, }, // F F N N L L N L S /* 44*/ { "01000000000000000KM12JQ3N ", 0, 3, 155, }, /* F F N N L L N L S */
/* 45*/ { "01000000000000000KM12JQAN ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F F N N L L N L S bad 3rd N /* 45*/ { "01000000000000000KM12JQAN ", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F F N N L L N L S bad 3rd N */
/* 46*/ { "01000000000000000OV123JQ4U", 0, 3, 155, }, // F F N N N L L N L /* 46*/ { "01000000000000000OV123JQ4U", 0, 3, 155, }, /* F F N N N L L N L */
/* 47*/ { "01000000000000000OV123IQ4U", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F F N N N L L N L bad 1st L /* 47*/ { "01000000000000000OV123IQ4U", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F F N N N L L N L bad 1st L */
/* 48*/ { "01000000000000000CI1K3JQ4U", 0, 3, 155, }, // F F N F N L L N L /* 48*/ { "01000000000000000CI1K3JQ4U", 0, 3, 155, }, /* F F N F N L L N L */
/* 49*/ { "010000000000000009I1K3JQ4U", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F F N F N L L N L bad 1st F /* 49*/ { "010000000000000009I1K3JQ4U", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F F N F N L L N L bad 1st F */
/* 50*/ { "01000000000000000C12JQ3U ", 0, 3, 155, }, // F N N L L N L S S /* 50*/ { "01000000000000000C12JQ3U ", 0, 3, 155, }, /* F N N L L N L S S */
/* 51*/ { "01000000000000000C12JQ3U A", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F N N L L N L S S bad 2nd S /* 51*/ { "01000000000000000C12JQ3U A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F N N L L N L S S bad 2nd S */
/* 52*/ { "01000000000000000C123JQ4U ", 0, 3, 155, }, // F N N N L L N L S /* 52*/ { "01000000000000000C123JQ4U ", 0, 3, 155, }, /* F N N N L L N L S */
/* 53*/ { "01000000000000000C 23JQ4U ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F N N N L L N L S bad 1st N (non-alpha otherwise matches 2nd pattern) /* 53*/ { "01000000000000000C 23JQ4U ", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* F N N N L L N L S bad 1st N (non-alpha otherwise matches 2nd pattern) */
/* 54*/ { "41038422416563762XY1", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 54*/ { "41038422416563762XY1", ZINT_ERROR_INVALID_DATA, -1, -1 },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -105,7 +106,7 @@ static void test_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -126,11 +127,13 @@ static void test_input(int index, int debug) {
testFinish(); testFinish();
} }
// Royal Mail Mailmark barcode C encoding and decoding (Sep 2015) RMMBCED /* Royal Mail Mailmark barcode C encoding and decoding (Sep 2015) RMMBCED
// https://www.royalmail.com/sites/default/files/Mailmark-4-state-barcode-C-encoding-and-decoding-instructions-Sept-2015.pdf https://www.royalmail.com/sites/default/files/Mailmark-4-state-barcode-C-encoding-and-decoding-instructions-Sept-2015.pdf
// Royal Mail Mailmark barcode L encoding and decoding (Sep 2015) RMMBLED Royal Mail Mailmark barcode L encoding and decoding (Sep 2015) RMMBLED
// https://www.royalmail.com/sites/default/files/Mailmark-4-state-barcode-L-encoding-and-decoding-instructions-Sept-2015.pdf https://www.royalmail.com/sites/default/files/Mailmark-4-state-barcode-L-encoding-and-decoding-instructions-Sept-2015.pdf
static void test_encode_vector(int index, int debug) { */
static void test_encode_vector(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -140,28 +143,28 @@ static void test_encode_vector(int index, int debug) {
int ret_vector; int ret_vector;
char *expected_daft; char *expected_daft;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "1100000000000XY11 ", 0, 100, 30, 0, "TTDTTATTDTAATTDTAATTDTAATTDTTDDAATAADDATAATDDFAFTDDTAADDDTAAFDFAFF" }, // Example 1 from RMMBCED /* 0*/ { "1100000000000XY11 ", 0, 100, 30, 0, "TTDTTATTDTAATTDTAATTDTAATTDTTDDAATAADDATAATDDFAFTDDTAADDDTAAFDFAFF" }, /* Example 1 from RMMBCED */
/* 1*/ { "21B2254800659JW5O9QA6Y", 0, 100, 30, 0, "DAATATTTADTAATTFADDDDTTFTFDDDDFFDFDAFTADDTFFTDDATADTTFATTDAFDTFDDA" }, // Example 2 from RMMBCED /* 1*/ { "21B2254800659JW5O9QA6Y", 0, 100, 30, 0, "DAATATTTADTAATTFADDDDTTFTFDDDDFFDFDAFTADDTFFTDDATADTTFATTDAFDTFDDA" }, /* Example 2 from RMMBCED */
/* 2*/ { "11000000000000000XY11 ", 0, 100, 30, 0, "TTDTTATDDTTATTDTAATTDTAATDDTTATTDTTDATFTAATDDTAATDDTATATFAADDAATAATDDTAADFTFTA" }, // Example 1 from RMMBLED /* 2*/ { "11000000000000000XY11 ", 0, 100, 30, 0, "TTDTTATDDTTATTDTAATTDTAATDDTTATTDTTDATFTAATDDTAATDDTATATFAADDAATAATDDTAADFTFTA" }, /* Example 1 from RMMBLED */
/* 3*/ { "41038422416563762EF61AH8T", 0, 100, 30, 0, "DTTFATTDDTATTTATFTDFFFTFDFDAFTTTADTTFDTFDDDTDFDDFTFAADTFDTDTDTFAATAFDDTAATTDTT" }, // Example 2 from RMMBLED /* 3*/ { "41038422416563762EF61AH8T", 0, 100, 30, 0, "DTTFATTDDTATTTATFTDFFFTFDFDAFTTTADTTFDTFDDDTDFDDFTFAADTFDTDTDTFAATAFDDTAATTDTT" }, /* Example 2 from RMMBLED */
/* 4*/ { "0100000000000AA000AA0A", 0, 100, 30, 0, "TFATTADAAATAFAFADFTAFATDTTDTTAAFTTFFTTDFTTFFTTAFADFDFAAFTDDFDADDAA" }, /* 4*/ { "0100000000000AA000AA0A", 0, 100, 30, 0, "TFATTADAAATAFAFADFTAFATDTTDTTAAFTTFFTTDFTTFFTTAFADFDFAAFTDDFDADDAA" },
/* 5*/ { "0100000000009JA500AA0A", 0, 100, 30, 0, "TAFTTDADATTFDTFDFDFDTAATADADTTTATTFTDDDDTATDATDFTFFATAFFAFADAFFTDT" }, /* 5*/ { "0100000000009JA500AA0A", 0, 100, 30, 0, "TAFTTDADATTFDTFDFDFDTAATADADTTTATTFTDDDDTATDATDFTFFATAFFAFADAFFTDT" },
/* 6*/ { "1234567890123C1I2JQ3N ", 0, 100, 30, 0, "TTDTDFTFDTAAFFDATAATFDDTATTTFDFTDTTFDFTTTFAAFFTDTADDATDDDTFFATFFAF" }, // F N F N L L N L S /* 6*/ { "1234567890123C1I2JQ3N ", 0, 100, 30, 0, "TTDTDFTFDTAAFFDATAATFDDTATTTFDFTDTTFDFTTTFAAFFTDTADDATDDDTFFATFFAF" }, /* F N F N L L N L S */
/* 7*/ { "2345678901234KM12JQ3N ", 0, 100, 30, 0, "TDTFAFADDATATATTAAFAFTFTDADFDTDAAADFFDTTDDTDDFATDDTFDATFDFTFFFDFTA" }, // F F N N L L N L S /* 7*/ { "2345678901234KM12JQ3N ", 0, 100, 30, 0, "TDTFAFADDATATATTAAFAFTFTDADFDTDAAADFFDTTDDTDDFATDDTFDATFDFTFFFDFTA" }, /* F F N N L L N L S */
/* 8*/ { "34A6789012345OV123JQ4U", 0, 100, 30, 0, "TDTTATADDATDADADATTAFATDAADAFTTTAAFDATFAFDDFDATFDTADDTFFAAFDDTTAAD" }, // F F N N N L L N L /* 8*/ { "34A6789012345OV123JQ4U", 0, 100, 30, 0, "TDTTATADDATDADADATTAFATDAADAFTTTAAFDATFAFDDFDATFDTADDTFFAAFDDTTAAD" }, /* F F N N N L L N L */
/* 9*/ { "44E9999999999CI1K3JQ4U", 0, 100, 30, 0, "DADTFDATFAFAFFAADTDFTTAAFFAFFDFATFTFDDAAFDFDDFAFDTDTDDATTDATTAFDAD" }, // F F N F N L L N L /* 9*/ { "44E9999999999CI1K3JQ4U", 0, 100, 30, 0, "DADTFDATFAFAFFAADTDFTTAAFFAFFDFATFTFDDAAFDFDDFAFDTDTDDATTDATTAFDAD" }, /* F F N F N L L N L */
/* 10*/ { "0418070504030C12JQ3U ", 0, 100, 30, 0, "FTAFFDAFTDDFTDTAFAADDDTADFTFAFFFATAAATFTDDDATFATFTTFTFFATADTDAAFTA" }, // F N N L L N L S S /* 10*/ { "0418070504030C12JQ3U ", 0, 100, 30, 0, "FTAFFDAFTDDFTDTAFAADDDTADFTFAFFFATAAATFTDDDATFATFTTFTFFATADTDAAFTA" }, /* F N N L L N L S S */
/* 11*/ { "02D7543219876C123JQ4U ", 0, 100, 30, 0, "AFTFAFATFDDFFDTTDDFAFDFDAFFTFAAFTTDATDFATATFTDFTFTTTFFTTATDATFDFTA" }, // F N N N L L N L S /* 11*/ { "02D7543219876C123JQ4U ", 0, 100, 30, 0, "AFTFAFATFDDFFDTTDDFAFDFDAFFTFAAFTTDATDFATATFTDFTFTTTFFTTATDATFDFTA" }, /* F N N N L L N L S */
/* 12*/ { "01000000000000000AA000AA0A", 0, 100, 30, 0, "FDTTATTDDFFDATFAFDDTFFDDAATTTATTDTTADADDFDFTFAFAADTADDFDFTDTFTAFDDATDAFDFFATDT" }, /* 12*/ { "01000000000000000AA000AA0A", 0, 100, 30, 0, "FDTTATTDDFFDATFAFDDTFFDDAATTTATTDTTADADDFDFTFAFAADTADDFDFTDTFTAFDDATDAFDFFATDT" },
/* 13*/ { "01000000000000009JA500AA0A", 0, 100, 30, 0, "FDTDAADTDAAADDDAFADDDFDDAFAADDAADTTAAFFDDTFTTDDTDFDTTDDTTFFDTDTFAADTAFAAFFDFDF" }, /* 13*/ { "01000000000000009JA500AA0A", 0, 100, 30, 0, "FDTDAADTDAAADDDAFADDDFDDAFAADDAADTTAAFFDDTFTTDDTDFDTTDDTTFFDTDTFAADTAFAAFFDFDF" },
/* 14*/ { "01000000000000000C1I2JQ3N ", 0, 100, 30, 0, "TDTTDFTDDFDFFDTTAAATFFAADAFTTATTDTTAATFATDTTFAAFDFDAFTDADFTDFDFTFFFDADAFDDAATT" }, // F N F N L L N L S /* 14*/ { "01000000000000000C1I2JQ3N ", 0, 100, 30, 0, "TDTTDFTDDFDFFDTTAAATFFAADAFTTATTDTTAATFATDTTFAAFDFDAFTDADFTDFDFTFFFDADAFDDAATT" }, /* F N F N L L N L S */
/* 15*/ { "01777777777777777KM12JQ3N ", 0, 100, 30, 0, "AFFADATDDTATDFFAFAAADDTATFFDADDDADDAFFAFDDTADTTFDFATAFDDAAFFTTAFADTAAFTTDTFFTA" }, // F F N N L L N L S /* 15*/ { "01777777777777777KM12JQ3N ", 0, 100, 30, 0, "AFFADATDDTATDFFAFAAADDTATFFDADDDADDAFFAFDDTADTTFDFATAFDDAAFFTTAFADTAAFTTDTFFTA" }, /* F F N N L L N L S */
/* 16*/ { "33C55555555555555OV123JQ4U", 0, 100, 30, 0, "FDTTFDDTDFFAAAADDFFDTFTFDDTADAAADATTFAFTTFDATTDDTDAFTAFTDDTTADDFFTAFDTDDTDTTAF" }, // F F N N N L L N L /* 16*/ { "33C55555555555555OV123JQ4U", 0, 100, 30, 0, "FDTTFDDTDFFAAAADDFFDTFTFDDTADAAADATTFAFTTFDATTDDTDAFTAFTDDTTADDFFTAFDTDDTDTTAF" }, /* F F N N N L L N L */
/* 17*/ { "42944444444444444CI1K3JQ4U", 0, 100, 30, 0, "FTDDTTTTFAFFTATFTTFTDTFTFAADADTAFDADDTFDFDAFDFTTAFATFDFDTTFATFDFDAAAFTFTDFFTAF" }, // F F N F N L L N L /* 17*/ { "42944444444444444CI1K3JQ4U", 0, 100, 30, 0, "FTDDTTTTFAFFTATFTTFTDTFTFAADADTAFDADDTFDFDAFDFTTAFATFDFDTTFATFDFDAAAFTFTDFFTAF" }, /* F F N F N L L N L */
/* 18*/ { "31833333333333333C12JQ3U ", 0, 100, 30, 0, "DTTAFFDATATFAADAFDFATFFTFFTTTADTTTDTAAATDDTFFDDFTAADTTDTFFFDAFTFAADFDDAFDFTAFF" }, // F N N L L N L S S /* 18*/ { "31833333333333333C12JQ3U ", 0, 100, 30, 0, "DTTAFFDATATFAADAFDFATFFTFFTTTADTTTDTAAATDDTFFDDFTAADTTDTFFFDAFTFAADFDDAFDFTAFF" }, /* F N N L L N L S S */
/* 19*/ { "22799999999999999C123JQ4U ", 0, 100, 30, 0, "DDATTDDATATTTAFDTAADATDDFFTFFDFFDTFAADDFAADFDFFTFFTFFDFDFTATATFDDFTFFFTFFTDDTF" }, // F N N N L L N L S /* 19*/ { "22799999999999999C123JQ4U ", 0, 100, 30, 0, "DDATTDDATATTTAFDTAADATDDFFTFFDFFDTFAADDFAADFDFFTFFTFFDFDFTATATFDDFTFFFTFFTDDTF" }, /* F N N N L L N L S */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -173,7 +176,7 @@ static void test_encode_vector(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -198,7 +201,8 @@ static void test_encode_vector(int index, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -226,7 +230,7 @@ static void test_encode(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -236,7 +240,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { \"%s\", %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
@ -262,10 +266,10 @@ static void test_encode(int index, int generate, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_input", test_input, 1, 0, 1 }, { "test_input", test_input },
{ "test_encode_vector", test_encode_vector, 1, 0, 1 }, { "test_encode_vector", test_encode_vector },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
@ -274,3 +278,5 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -31,7 +31,8 @@
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int option_1; int option_1;
@ -90,7 +91,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -115,7 +116,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int generate, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -200,7 +202,7 @@ static void test_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -216,7 +218,7 @@ static void test_input(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, %d, { %d, %d, \"%s\" }, \"%s\", %d, \"%s\", %s, %d, \"%s\", %d, %d, \"%s\" },\n", printf(" /*%3d*/ { %s, %d, %d, %d, { %d, %d, \"%s\" }, \"%s\", %d, \"%s\", %s, %d, \"%s\", %d, %d, \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, data[i].option_2, i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, data[i].option_2,
data[i].structapp.index, data[i].structapp.count, data[i].structapp.id, data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
@ -267,7 +269,8 @@ static void test_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -1002,7 +1005,7 @@ static void test_encode(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1016,7 +1019,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, { %d, %d, \"%s\" }, \"%s\", %d, \"%s\", %s, %d, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, %d, { %d, %d, \"%s\" }, \"%s\", %d, \"%s\", %s, %d, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2,
data[i].structapp.index, data[i].structapp.count, data[i].structapp.id, data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
@ -1066,7 +1069,8 @@ static void test_encode(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode_segs(int index, int generate, int debug) { static void test_encode_segs(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -1415,7 +1419,7 @@ static void test_encode_segs(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1431,7 +1435,7 @@ static void test_encode_segs(int index, int generate, int debug) {
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count); ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
char escaped1[4096]; char escaped1[4096];
char escaped2[4096]; char escaped2[4096];
int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length;
@ -1497,7 +1501,8 @@ static void test_encode_segs(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_best_supported_set(int index, int generate, int debug) { static void test_best_supported_set(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -1558,7 +1563,7 @@ static void test_best_supported_set(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1568,7 +1573,7 @@ static void test_best_supported_set(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
if (generate) { if (p_ctx->generate) {
printf(" /*%2d*/ { \"%s\", %d, %.0f, %.0f, %d, %d, %d, \"%s\",\n", printf(" /*%2d*/ { \"%s\", %d, %.0f, %.0f, %d, %d, %d, \"%s\",\n",
i, testUtilEscape(data[i].data, length, escaped_data, sizeof(escaped_data)), ret, i, testUtilEscape(data[i].data, length, escaped_data, sizeof(escaped_data)), ret,
data[i].w, data[i].h, data[i].ret_vector, symbol->rows, symbol->width, data[i].comment); data[i].w, data[i].h, data[i].ret_vector, symbol->rows, symbol->width, data[i].comment);
@ -1594,7 +1599,8 @@ static void test_best_supported_set(int index, int generate, int debug) {
} }
/* #181 Nico Gunkel OSS-Fuzz */ /* #181 Nico Gunkel OSS-Fuzz */
static void test_fuzz(int index, int debug) { static void test_fuzz(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int eci; int eci;
@ -1619,7 +1625,7 @@ static void test_fuzz(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1640,7 +1646,8 @@ static void test_fuzz(int index, int debug) {
#define TEST_PERF_ITERATIONS 1000 #define TEST_PERF_ITERATIONS 1000
/* Not a real test, just performance indicator */ /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1672,7 +1679,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_encode = diff_buffer = 0; diff_encode = diff_buffer = 0;
@ -1704,21 +1711,21 @@ static void test_perf(int index, int debug) {
total_encode += diff_encode; total_encode += diff_encode;
total_buffer += diff_buffer; total_buffer += diff_buffer;
} }
if (index != -1) { if (p_ctx->index != -1) {
printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC); printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
} }
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_input", test_input, 1, 1, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_encode_segs", test_encode_segs, 1, 1, 1 }, { "test_encode_segs", test_encode_segs },
{ "test_best_supported_set", test_best_supported_set, 1, 1, 1 }, { "test_best_supported_set", test_best_supported_set },
{ "test_fuzz", test_fuzz, 1, 0, 1 }, { "test_fuzz", test_fuzz },
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -41,7 +43,7 @@ static void test_large(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_CODABAR, -1, "A1234567890123456789012345678901234567890123456789012345678B", 60, 0, 1, 602 }, /* 0*/ { BARCODE_CODABAR, -1, "A1234567890123456789012345678901234567890123456789012345678B", 60, 0, 1, 602 },
/* 1*/ { BARCODE_CODABAR, -1, "A12345678901234567890123456789012345678901234567890123456789B", 61, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 1*/ { BARCODE_CODABAR, -1, "A12345678901234567890123456789012345678901234567890123456789B", 61, ZINT_ERROR_TOO_LONG, -1, -1 },
@ -64,7 +66,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -88,7 +90,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_hrt(int index, int debug) { static void test_hrt(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -97,16 +100,16 @@ static void test_hrt(int index, int debug) {
char *expected; char *expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_CODABAR, -1, "A1234B", "A1234B" }, /* 0*/ { BARCODE_CODABAR, -1, "A1234B", "A1234B" },
/* 1*/ { BARCODE_CODABAR, -1, "a1234c", "A1234C" }, // Converts to upper /* 1*/ { BARCODE_CODABAR, -1, "a1234c", "A1234C" }, /* Converts to upper */
/* 2*/ { BARCODE_CODABAR, 1, "A1234B", "A1234B" }, // Check not included /* 2*/ { BARCODE_CODABAR, 1, "A1234B", "A1234B" }, /* Check not included */
/* 3*/ { BARCODE_CODABAR, 2, "A1234B", "A12345B" }, // Check included /* 3*/ { BARCODE_CODABAR, 2, "A1234B", "A12345B" }, /* Check included */
/* 4*/ { BARCODE_CODABAR, 1, "A123456A", "A123456A" }, // Check not included /* 4*/ { BARCODE_CODABAR, 1, "A123456A", "A123456A" }, /* Check not included */
/* 5*/ { BARCODE_CODABAR, 2, "A123456A", "A123456$A" }, // Check included /* 5*/ { BARCODE_CODABAR, 2, "A123456A", "A123456$A" }, /* Check included */
/* 6*/ { BARCODE_PHARMA, -1, "123456", "" }, // None /* 6*/ { BARCODE_PHARMA, -1, "123456", "" }, /* None */
/* 7*/ { BARCODE_PHARMA_TWO, -1, "123456", "" }, // None /* 7*/ { BARCODE_PHARMA_TWO, -1, "123456", "" }, /* None */
/* 8*/ { BARCODE_CODE32, -1, "123456", "A001234564" }, /* 8*/ { BARCODE_CODE32, -1, "123456", "A001234564" },
/* 9*/ { BARCODE_CODE32, -1, "12345678", "A123456788" }, /* 9*/ { BARCODE_CODE32, -1, "12345678", "A123456788" },
}; };
@ -118,7 +121,7 @@ static void test_hrt(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -136,7 +139,8 @@ static void test_hrt(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -146,7 +150,7 @@ static void test_input(int index, int debug) {
int expected_width; int expected_width;
const char *expected_errtxt; const char *expected_errtxt;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_CODABAR, "A1234B", 0, 1, 62, "" }, /* 0*/ { BARCODE_CODABAR, "A1234B", 0, 1, 62, "" },
/* 1*/ { BARCODE_CODABAR, "1234B", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 358: Does not begin with \"A\", \"B\", \"C\" or \"D\"" }, /* 1*/ { BARCODE_CODABAR, "1234B", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 358: Does not begin with \"A\", \"B\", \"C\" or \"D\"" },
@ -183,7 +187,7 @@ static void test_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -205,7 +209,8 @@ static void test_input(int index, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -260,14 +265,14 @@ static void test_encode(int index, int generate, int debug) {
char cmp_buf[8192]; char cmp_buf[8192];
char cmp_msg[1024]; char cmp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -277,7 +282,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, testUtilBarcodeName(data[i].symbology), data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
@ -323,11 +328,11 @@ static void test_encode(int index, int generate, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_hrt", test_hrt, 1, 0, 1 }, { "test_hrt", test_hrt },
{ "test_input", test_input, 1, 0, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -34,7 +34,7 @@
INTERNAL int out_quiet_zones_test(const struct zint_symbol *symbol, const int hide_text, INTERNAL int out_quiet_zones_test(const struct zint_symbol *symbol, const int hide_text,
float *left, float *right, float *top, float *bottom); float *left, float *right, float *top, float *bottom);
static void test_quiet_zones(void) { static void test_quiet_zones(const testCtx *const p_ctx) {
int i, ret; int i, ret;
struct zint_symbol symbol = {0}; struct zint_symbol symbol = {0};
int hide_text = 0; int hide_text = 0;
@ -44,10 +44,12 @@ static void test_quiet_zones(void) {
for (i = 1; i <= BARCODE_LAST; i++) { for (i = 1; i <= BARCODE_LAST; i++) {
if (!ZBarcode_ValidID(i)) continue; if (!ZBarcode_ValidID(i)) continue;
if (testContinue(p_ctx, i)) continue;
symbol.symbology = i; symbol.symbology = i;
symbol.output_options = BARCODE_QUIET_ZONES; symbol.output_options = BARCODE_QUIET_ZONES;
ret = out_quiet_zones_test(&symbol, hide_text, &left, &right, &top, &bottom); ret = out_quiet_zones_test(&symbol, hide_text, &left, &right, &top, &bottom);
if (i != BARCODE_FLAT && i != BARCODE_BC412) { // Only two which aren't marked as done if (i != BARCODE_FLAT && i != BARCODE_BC412) { /* Only two which aren't marked as done */
assert_nonzero(ret, "i:%d %s not done\n", i, testUtilBarcodeName(i)); assert_nonzero(ret, "i:%d %s not done\n", i, testUtilBarcodeName(i));
} }
} }
@ -57,8 +59,8 @@ static void test_quiet_zones(void) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_quiet_zones", test_quiet_zones, 0, 0, 0 }, { "test_quiet_zones", test_quiet_zones },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -1,6 +1,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2020-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -27,11 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_print(int index, int generate, int debug) { static void test_print(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -47,7 +48,7 @@ static void test_print(int index, int generate, int debug) {
char *data; char *data;
char *expected_file; char *expected_file;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_GRIDMATRIX, -1, -1, -1, -1, -1, -1, "C3C3C3", "", 0.75, "Grid Matrix", "gridmatrix_fg_0.75.pcx" }, /* 0*/ { BARCODE_GRIDMATRIX, -1, -1, -1, -1, -1, -1, "C3C3C3", "", 0.75, "Grid Matrix", "gridmatrix_fg_0.75.pcx" },
/* 1*/ { BARCODE_CODABLOCKF, -1, -1, -1, -1, -1, 20, "FFFFFF", "000000", 0, "1234567890123456789012345678901234567890", "codeblockf_reverse.pcx" }, /* 1*/ { BARCODE_CODABLOCKF, -1, -1, -1, -1, -1, 20, "FFFFFF", "000000", 0, "1234567890123456789012345678901234567890", "codeblockf_reverse.pcx" },
@ -68,7 +69,7 @@ static void test_print(int index, int generate, int debug) {
testStart("test_pcx"); testStart("test_pcx");
if (generate) { if (p_ctx->generate) {
char data_dir_path[1024]; char data_dir_path[1024];
assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir);
if (!testUtilDirExists(data_dir_path)) { if (!testUtilDirExists(data_dir_path)) {
@ -79,7 +80,7 @@ static void test_print(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -114,7 +115,7 @@ static void test_print(int index, int generate, int debug) {
assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i); assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %s, %d, %d, %d, %d, \"%s\", \"%s\", \"%s\", \"%s\"},\n", printf(" /*%3d*/ { %s, %d, %s, %d, %d, %d, %d, \"%s\", \"%s\", \"%s\", \"%s\"},\n",
i, testUtilBarcodeName(data[i].symbology), data[i].border_width, testUtilOutputOptionsName(data[i].output_options), i, testUtilBarcodeName(data[i].symbology), data[i].border_width, testUtilOutputOptionsName(data[i].output_options),
data[i].whitespace_width, data[i].whitespace_height, data[i].whitespace_width, data[i].whitespace_height,
@ -143,11 +144,13 @@ static void test_print(int index, int generate, int debug) {
INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf); INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf);
static void test_outfile(void) { static void test_outfile(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol symbol = {0}; struct zint_symbol symbol = {0};
unsigned char data[] = { "1" }; unsigned char data[] = { "1" };
(void)p_ctx;
testStart("test_outfile"); testStart("test_outfile");
symbol.symbology = BARCODE_CODE128; symbol.symbology = BARCODE_CODE128;
@ -170,9 +173,9 @@ static void test_outfile(void) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_print", test_print, 1, 1, 1 }, { "test_print", test_print },
{ "test_outfile", test_outfile, 0, 0, 0 }, { "test_outfile", test_outfile },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
@ -181,3 +184,5 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -31,7 +31,8 @@
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -68,7 +69,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -97,7 +98,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_options(int index, int debug) { static void test_options(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -179,7 +181,7 @@ static void test_options(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -205,7 +207,7 @@ static void test_options(int index, int debug) {
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, symbol->errtxt); assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, symbol->errtxt);
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt); assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt);
if (index == -1 && data[i].compare_previous != -1) { if (p_ctx->index == -1 && data[i].compare_previous != -1) {
ret = testUtilSymbolCmp(symbol, &previous_symbol); ret = testUtilSymbolCmp(symbol, &previous_symbol);
assert_equal(!ret, !data[i].compare_previous, "i:%d testUtilSymbolCmp !ret %d != %d\n", i, ret, data[i].compare_previous); assert_equal(!ret, !data[i].compare_previous, "i:%d testUtilSymbolCmp !ret %d != %d\n", i, ret, data[i].compare_previous);
} }
@ -222,7 +224,8 @@ static void test_options(int index, int debug) {
testFinish(); testFinish();
} }
static void test_reader_init(int index, int generate, int debug) { static void test_reader_init(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -253,7 +256,7 @@ static void test_reader_init(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -265,7 +268,7 @@ static void test_reader_init(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options), i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
@ -298,7 +301,8 @@ static void test_reader_init(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int generate, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -383,7 +387,7 @@ static void test_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -398,7 +402,7 @@ static void test_input(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, %d, %d, { %d, %d, \"%s\" }, \"%s\", %s, %d, %d, %d, \"%s\", %d, \"%s\" },\n", printf(" /*%3d*/ { %s, %s, %d, %d, %d, { %d, %d, \"%s\" }, \"%s\", %s, %d, %d, %d, \"%s\", %d, \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, data[i].option_2, i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, data[i].option_2,
data[i].structapp.index, data[i].structapp.count, data[i].structapp.id, data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
@ -447,7 +451,8 @@ static void test_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -2090,8 +2095,7 @@ static void test_encode(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -2101,7 +2105,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %s, %d, %d, %d, \"%s\", %s, %d, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, %s, %d, %d, %d, \"%s\", %s, %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), data[i].eci, testUtilInputModeName(data[i].input_mode), i, testUtilBarcodeName(data[i].symbology), data[i].eci, testUtilInputModeName(data[i].input_mode),
data[i].option_1, data[i].option_2, data[i].option_3, data[i].option_1, data[i].option_2, data[i].option_3,
@ -2151,7 +2155,8 @@ static void test_encode(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode_segs(int index, int generate, int debug) { static void test_encode_segs(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -2455,7 +2460,7 @@ static void test_encode_segs(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -2467,7 +2472,7 @@ static void test_encode_segs(int index, int generate, int debug) {
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count); ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
char escaped1[4096]; char escaped1[4096];
char escaped2[4096]; char escaped2[4096];
int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length;
@ -2539,7 +2544,8 @@ static void test_encode_segs(int index, int generate, int debug) {
} }
/* #181 Nico Gunkel OSS-Fuzz */ /* #181 Nico Gunkel OSS-Fuzz */
static void test_fuzz(int index, int debug) { static void test_fuzz(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -2812,7 +2818,7 @@ static void test_fuzz(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -2904,7 +2910,7 @@ static int annex_d_decode_dump(int chainemc[], int mclength, unsigned char *chai
return 0; return 0;
} }
static void test_numbprocess(int index) { static void test_numbprocess(const testCtx *const p_ctx) {
struct item { struct item {
unsigned char *chaine; unsigned char *chaine;
@ -2977,7 +2983,7 @@ static void test_numbprocess(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
mclength = 0; mclength = 0;
length = (int) ustrlen(data[i].chaine); length = (int) ustrlen(data[i].chaine);
@ -3007,7 +3013,8 @@ static void test_numbprocess(int index) {
#define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC) #define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC)
/* Not a real test, just performance indicator */ /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -3078,7 +3085,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0; diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
@ -3128,7 +3135,7 @@ static void test_perf(int index, int debug) {
total_buf_inter += diff_buf_inter; total_buf_inter += diff_buf_inter;
total_print += diff_print; total_print += diff_print;
} }
if (index == -1) { if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals", printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create)); TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
} }
@ -3136,16 +3143,16 @@ static void test_perf(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_options", test_options, 1, 0, 1 }, { "test_options", test_options },
{ "test_reader_init", test_reader_init, 1, 1, 1 }, { "test_reader_init", test_reader_init },
{ "test_input", test_input, 1, 1, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_encode_segs", test_encode_segs, 1, 1, 1 }, { "test_encode_segs", test_encode_segs },
{ "test_fuzz", test_fuzz, 1, 0, 1 }, { "test_fuzz", test_fuzz },
{ "test_numbprocess", test_numbprocess, 1, 0, 0 }, { "test_numbprocess", test_numbprocess },
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -41,25 +43,25 @@ static void test_large(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_MSI_PLESSEY, -1, "9", 65, 0, 1, 787 }, /* 0*/ { BARCODE_MSI_PLESSEY, -1, "9", 65, 0, 1, 787 },
/* 1*/ { BARCODE_MSI_PLESSEY, -1, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 1*/ { BARCODE_MSI_PLESSEY, -1, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 2*/ { BARCODE_MSI_PLESSEY, 1, "9", 65, 0, 1, 799 }, // 1 mod-10 check digit /* 2*/ { BARCODE_MSI_PLESSEY, 1, "9", 65, 0, 1, 799 }, /* 1 mod-10 check digit */
/* 3*/ { BARCODE_MSI_PLESSEY, 1, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 3*/ { BARCODE_MSI_PLESSEY, 1, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 4*/ { BARCODE_MSI_PLESSEY, 2, "9", 65, 0, 1, 811 }, // 2 mod-10 check digits /* 4*/ { BARCODE_MSI_PLESSEY, 2, "9", 65, 0, 1, 811 }, /* 2 mod-10 check digits */
/* 5*/ { BARCODE_MSI_PLESSEY, 2, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 5*/ { BARCODE_MSI_PLESSEY, 2, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 6*/ { BARCODE_MSI_PLESSEY, 3, "9", 65, 0, 1, 799 }, // 1 mod-11 check digit /* 6*/ { BARCODE_MSI_PLESSEY, 3, "9", 65, 0, 1, 799 }, /* 1 mod-11 check digit */
/* 7*/ { BARCODE_MSI_PLESSEY, 3, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 7*/ { BARCODE_MSI_PLESSEY, 3, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 8*/ { BARCODE_MSI_PLESSEY, 3, "3", 65, 0, 1, 811 }, // 1 mod-11 double check digit "10" /* 8*/ { BARCODE_MSI_PLESSEY, 3, "3", 65, 0, 1, 811 }, /* 1 mod-11 double check digit "10" */
/* 9*/ { BARCODE_MSI_PLESSEY, 3, "3", 66, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 9*/ { BARCODE_MSI_PLESSEY, 3, "3", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 10*/ { BARCODE_MSI_PLESSEY, 4, "9", 65, 0, 1, 811 }, // 1 mod-11 and 1 mod-10 check digit /* 10*/ { BARCODE_MSI_PLESSEY, 4, "9", 65, 0, 1, 811 }, /* 1 mod-11 and 1 mod-10 check digit */
/* 11*/ { BARCODE_MSI_PLESSEY, 4, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 11*/ { BARCODE_MSI_PLESSEY, 4, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 12*/ { BARCODE_MSI_PLESSEY, 4, "3", 65, 0, 1, 823 }, // 1 mod-11 double check digit "10" and 1 mod-10 check digit /* 12*/ { BARCODE_MSI_PLESSEY, 4, "3", 65, 0, 1, 823 }, /* 1 mod-11 double check digit "10" and 1 mod-10 check digit */
/* 13*/ { BARCODE_MSI_PLESSEY, 4, "3", 66, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 13*/ { BARCODE_MSI_PLESSEY, 4, "3", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 14*/ { BARCODE_MSI_PLESSEY, 5, "9", 65, 0, 1, 799 }, // 1 NCR mod-11 check digit /* 14*/ { BARCODE_MSI_PLESSEY, 5, "9", 65, 0, 1, 799 }, /* 1 NCR mod-11 check digit */
/* 15*/ { BARCODE_MSI_PLESSEY, 5, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 15*/ { BARCODE_MSI_PLESSEY, 5, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 16*/ { BARCODE_MSI_PLESSEY, 6, "9", 65, 0, 1, 811 }, // 1 NCR mod-11 and 1 mod-10 check digit /* 16*/ { BARCODE_MSI_PLESSEY, 6, "9", 65, 0, 1, 811 }, /* 1 NCR mod-11 and 1 mod-10 check digit */
/* 17*/ { BARCODE_MSI_PLESSEY, 6, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 17*/ { BARCODE_MSI_PLESSEY, 6, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 18*/ { BARCODE_PLESSEY, -1, "A", 65, 0, 1, 1107 }, /* 18*/ { BARCODE_PLESSEY, -1, "A", 65, 0, 1, 1107 },
/* 19*/ { BARCODE_PLESSEY, -1, "A", 66, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 19*/ { BARCODE_PLESSEY, -1, "A", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
@ -74,7 +76,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -98,7 +100,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_hrt(int index, int debug) { static void test_hrt(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -107,7 +110,7 @@ static void test_hrt(int index, int debug) {
char *expected; char *expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_MSI_PLESSEY, -1, "1234567", "1234567" }, /* 0*/ { BARCODE_MSI_PLESSEY, -1, "1234567", "1234567" },
/* 1*/ { BARCODE_MSI_PLESSEY, 0, "1234567", "1234567" }, /* 1*/ { BARCODE_MSI_PLESSEY, 0, "1234567", "1234567" },
@ -133,8 +136,8 @@ static void test_hrt(int index, int debug) {
/* 21*/ { BARCODE_MSI_PLESSEY, 2, "123456", "12345666" }, /* 21*/ { BARCODE_MSI_PLESSEY, 2, "123456", "12345666" },
/* 22*/ { BARCODE_MSI_PLESSEY, 3, "123456", "1234560" }, /* 22*/ { BARCODE_MSI_PLESSEY, 3, "123456", "1234560" },
/* 23*/ { BARCODE_MSI_PLESSEY, 4, "123456", "12345609" }, /* 23*/ { BARCODE_MSI_PLESSEY, 4, "123456", "12345609" },
/* 24*/ { BARCODE_MSI_PLESSEY, 3, "2211", "221110" }, // Mod-11 check digit '10' /* 24*/ { BARCODE_MSI_PLESSEY, 3, "2211", "221110" }, /* Mod-11 check digit '10' */
/* 25*/ { BARCODE_MSI_PLESSEY, 3 + 10, "2211", "2211" }, // Mod-11 check digit '10' /* 25*/ { BARCODE_MSI_PLESSEY, 3 + 10, "2211", "2211" }, /* Mod-11 check digit '10' */
/* 26*/ { BARCODE_MSI_PLESSEY, 4, "2211", "2211100" }, /* 26*/ { BARCODE_MSI_PLESSEY, 4, "2211", "2211100" },
/* 27*/ { BARCODE_MSI_PLESSEY, 4 + 10, "2211", "2211" }, /* 27*/ { BARCODE_MSI_PLESSEY, 4 + 10, "2211", "2211" },
/* 28*/ { BARCODE_PLESSEY, -1, "0123456789ABCDEF", "0123456789ABCDEF" }, /* 28*/ { BARCODE_PLESSEY, -1, "0123456789ABCDEF", "0123456789ABCDEF" },
@ -147,7 +150,7 @@ static void test_hrt(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -165,7 +168,8 @@ static void test_hrt(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -175,12 +179,12 @@ static void test_input(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_MSI_PLESSEY, -1, "1", 0, 1, 19 }, /* 0*/ { BARCODE_MSI_PLESSEY, -1, "1", 0, 1, 19 },
/* 1*/ { BARCODE_MSI_PLESSEY, -1, "A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 1*/ { BARCODE_MSI_PLESSEY, -1, "A", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 2*/ { BARCODE_MSI_PLESSEY, -2, "1", 0, 1, 19 }, // < 0 ignored /* 2*/ { BARCODE_MSI_PLESSEY, -2, "1", 0, 1, 19 }, /* < 0 ignored */
/* 3*/ { BARCODE_MSI_PLESSEY, 7, "1", 0, 1, 19 }, // > 6 ignored /* 3*/ { BARCODE_MSI_PLESSEY, 7, "1", 0, 1, 19 }, /* > 6 ignored */
/* 4*/ { BARCODE_PLESSEY, -1, "A", 0, 1, 83 }, /* 4*/ { BARCODE_PLESSEY, -1, "A", 0, 1, 83 },
/* 5*/ { BARCODE_PLESSEY, -1, "G", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 5*/ { BARCODE_PLESSEY, -1, "G", ZINT_ERROR_INVALID_DATA, -1, -1 },
}; };
@ -192,7 +196,7 @@ static void test_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -213,7 +217,8 @@ static void test_input(int index, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -269,13 +274,13 @@ static void test_encode(int index, int generate, int debug) {
char bwipp_buf[4096]; char bwipp_buf[4096];
char bwipp_msg[1024]; char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -285,7 +290,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, testUtilBarcodeName(data[i].symbology), data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
@ -324,8 +329,9 @@ static void test_encode(int index, int generate, int debug) {
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000) #define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
#define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC) #define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC)
// Not a real test, just performance indicator /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -363,7 +369,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0; diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
@ -393,7 +399,7 @@ static void test_perf(int index, int debug) {
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/); ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start; diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt); assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; // Undo symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock(); start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/); ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
@ -413,7 +419,7 @@ static void test_perf(int index, int debug) {
total_buf_inter += diff_buf_inter; total_buf_inter += diff_buf_inter;
total_print += diff_print; total_print += diff_print;
} }
if (index == -1) { if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals", printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create)); TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
} }
@ -421,12 +427,12 @@ static void test_perf(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_hrt", test_hrt, 1, 0, 1 }, { "test_hrt", test_hrt },
{ "test_input", test_input, 1, 0, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -35,7 +35,8 @@
INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf); INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf);
static void test_pixel_plot(int index, int debug) { static void test_pixel_plot(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int width; int width;
@ -69,7 +70,7 @@ static void test_pixel_plot(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int size; int size;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -117,7 +118,8 @@ static void test_pixel_plot(int index, int debug) {
testFinish(); testFinish();
} }
static void test_print(int index, int generate, int debug) { static void test_print(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -214,7 +216,7 @@ static void test_print(int index, int generate, int debug) {
testStart("test_print"); testStart("test_print");
if (generate) { if (p_ctx->generate) {
char data_dir_path[1024]; char data_dir_path[1024];
assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir);
if (!testUtilDirExists(data_dir_path)) { if (!testUtilDirExists(data_dir_path)) {
@ -226,7 +228,7 @@ static void test_print(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int text_length; int text_length;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -276,7 +278,7 @@ static void test_print(int index, int generate, int debug) {
assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i); assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, %s, %d, %d, %d, %d, %d, %.5g, %.5g, \"%s\", \"%s\", \"%s\", \"%s\", %s, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %s, %d, %s, %d, %d, %d, %d, %d, %.5g, %.5g, \"%s\", \"%s\", \"%s\", \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].border_width, testUtilOutputOptionsName(data[i].output_options), i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].border_width, testUtilOutputOptionsName(data[i].output_options),
data[i].whitespace_width, data[i].whitespace_height, data[i].show_hrt, data[i].option_1, data[i].option_2, data[i].height, data[i].scale, data[i].fgcolour, data[i].bgcolour, data[i].whitespace_width, data[i].whitespace_height, data[i].show_hrt, data[i].option_1, data[i].option_2, data[i].height, data[i].scale, data[i].fgcolour, data[i].bgcolour,
@ -304,11 +306,13 @@ static void test_print(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_outfile(void) { static void test_outfile(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol symbol = {0}; struct zint_symbol symbol = {0};
unsigned char data[] = { "1" }; unsigned char data[] = { "1" };
(void)p_ctx;
testStart("test_outfile"); testStart("test_outfile");
symbol.symbology = BARCODE_CODE128; symbol.symbology = BARCODE_CODE128;
@ -339,7 +343,7 @@ struct wpng_error_type {
INTERNAL void wpng_error_handler_test(png_structp png_ptr, png_const_charp msg); INTERNAL void wpng_error_handler_test(png_structp png_ptr, png_const_charp msg);
static void test_wpng_error_handler(void) { static void test_wpng_error_handler(const testCtx *const p_ctx) {
int ret; int ret;
char filename[] = "out.png"; char filename[] = "out.png";
FILE *fp; FILE *fp;
@ -348,6 +352,8 @@ static void test_wpng_error_handler(void) {
png_structp png_ptr; png_structp png_ptr;
png_infop info_ptr; png_infop info_ptr;
(void)p_ctx;
testStart("test_wpng_error_handler"); testStart("test_wpng_error_handler");
wpng_error.symbol = &symbol; wpng_error.symbol = &symbol;
@ -387,13 +393,15 @@ static void test_wpng_error_handler(void) {
} }
/* Check compliant height printable for max CODABLOCKF with 44 rows * ((62 cols) * 0.55 + 3)) = 1632.4 */ /* Check compliant height printable for max CODABLOCKF with 44 rows * ((62 cols) * 0.55 + 3)) = 1632.4 */
static void test_large_compliant_height(void) { static void test_large_compliant_height(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol *symbol = NULL; struct zint_symbol *symbol = NULL;
const char pattern[] = { "1" }; const char pattern[] = { "1" };
const int codablockf_max = 2726; const int codablockf_max = 2726;
char data_buf[2726 + 1]; char data_buf[2726 + 1];
(void)p_ctx;
testStart("test_large_compliant_height"); testStart("test_large_compliant_height");
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
@ -415,12 +423,12 @@ static void test_large_compliant_height(void) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_pixel_plot", test_pixel_plot, 1, 0, 1 }, { "test_pixel_plot", test_pixel_plot },
{ "test_print", test_print, 1, 1, 1 }, { "test_print", test_print },
{ "test_outfile", test_outfile, 0, 0, 0 }, { "test_outfile", test_outfile },
{ "test_wpng_error_handler", test_wpng_error_handler, 0, 0, 0 }, { "test_wpng_error_handler", test_wpng_error_handler },
{ "test_large_compliant_height", test_large_compliant_height, 0, 0, 0 }, { "test_large_compliant_height", test_large_compliant_height },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -35,7 +35,8 @@
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -86,7 +87,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -110,7 +111,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_koreapost(int index, int debug) { static void test_koreapost(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -132,7 +134,7 @@ static void test_koreapost(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -157,7 +159,8 @@ static void test_koreapost(int index, int debug) {
testFinish(); testFinish();
} }
static void test_japanpost(int index, int debug) { static void test_japanpost(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -184,7 +187,7 @@ static void test_japanpost(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -209,7 +212,8 @@ static void test_japanpost(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -279,7 +283,7 @@ static void test_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -304,7 +308,8 @@ static void test_input(int index, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -460,7 +465,7 @@ static void test_encode(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -470,7 +475,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, \"%s\", %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, testUtilBarcodeName(data[i].symbology), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
@ -510,7 +515,8 @@ static void test_encode(int index, int generate, int debug) {
#define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC) #define TEST_PERF_TIME(arg) ((arg) * 1000.0 / CLOCKS_PER_SEC)
/* Not a real test, just performance indicator */ /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -547,7 +553,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0; diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
@ -597,7 +603,7 @@ static void test_perf(int index, int debug) {
total_buf_inter += diff_buf_inter; total_buf_inter += diff_buf_inter;
total_print += diff_print; total_print += diff_print;
} }
if (index == -1) { if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals", printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create)); TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
} }
@ -605,13 +611,13 @@ static void test_perf(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_koreapost", test_koreapost, 1, 0, 1 }, { "test_koreapost", test_koreapost },
{ "test_japanpost", test_japanpost, 1, 0, 1 }, { "test_japanpost", test_japanpost },
{ "test_input", test_input, 1, 0, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -1,6 +1,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2020-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -27,14 +27,15 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
#include <sys/stat.h> #include <sys/stat.h>
#define TEST_PRINT_OVERWRITE_EXPECTED "bmp,emf,eps,gif,pcx,png,svg,tif,txt" #define TEST_PRINT_OVERWRITE_EXPECTED "bmp,emf,eps,gif,pcx,png,svg,tif,txt"
static void test_print(int index, int generate, int debug) { static void test_print(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -71,7 +72,8 @@ static void test_print(int index, int generate, int debug) {
int have_ghostscript = 0; int have_ghostscript = 0;
int have_vnu = 0; int have_vnu = 0;
int have_tiffinfo = 0; int have_tiffinfo = 0;
if (generate) {
if (p_ctx->generate) {
have_identify = testUtilHaveIdentify(); have_identify = testUtilHaveIdentify();
have_libreoffice = testUtilHaveLibreOffice(); have_libreoffice = testUtilHaveLibreOffice();
have_ghostscript = testUtilHaveGhostscript(); have_ghostscript = testUtilHaveGhostscript();
@ -83,7 +85,7 @@ static void test_print(int index, int generate, int debug) {
assert_nonzero(testUtilDataPath(data_dir, sizeof(data_dir), "/backend/tests/data", NULL), "testUtilDataPath == 0\n"); assert_nonzero(testUtilDataPath(data_dir, sizeof(data_dir), "/backend/tests/data", NULL), "testUtilDataPath == 0\n");
if (generate) { if (p_ctx->generate) {
if (!testUtilDirExists(data_dir)) { if (!testUtilDirExists(data_dir)) {
ret = testUtilMkDir(data_dir); ret = testUtilMkDir(data_dir);
assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno)); assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
@ -110,7 +112,7 @@ static void test_print(int index, int generate, int debug) {
strcat(data_subdir, "/"); strcat(data_subdir, "/");
strcat(data_subdir, exts[j]); strcat(data_subdir, exts[j]);
if (generate) { if (p_ctx->generate) {
if (!testUtilDirExists(data_subdir)) { if (!testUtilDirExists(data_subdir)) {
ret = testUtilMkDir(data_subdir); ret = testUtilMkDir(data_subdir);
assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_subdir, ret, errno, strerror(errno)); assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_subdir, ret, errno, strerror(errno));
@ -119,7 +121,7 @@ static void test_print(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -147,7 +149,7 @@ static void test_print(int index, int generate, int debug) {
ret = ZBarcode_Print(symbol, 0); ret = ZBarcode_Print(symbol, 0);
assert_zero(ret, "i:%d j:%d %s %s ZBarcode_Print %s ret %d != 0\n", i, j, exts[j], testUtilBarcodeName(data[i].symbology), symbol->outfile, ret); assert_zero(ret, "i:%d j:%d %s %s ZBarcode_Print %s ret %d != 0\n", i, j, exts[j], testUtilBarcodeName(data[i].symbology), symbol->outfile, ret);
if (generate) { if (p_ctx->generate) {
if (j == 0) { if (j == 0) {
printf(" /*%3d*/ { %s, %d, %d, %.8g, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %d, %d, %.8g, \"%s\", \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), data[i].option_1, data[i].option_2, data[i].scale, i, testUtilBarcodeName(data[i].symbology), data[i].option_1, data[i].option_2, data[i].scale,
@ -163,17 +165,17 @@ static void test_print(int index, int generate, int debug) {
} }
} else if (strcmp(exts[j], "svg") == 0 || strcmp(exts[j], "emf") == 0) { } else if (strcmp(exts[j], "svg") == 0 || strcmp(exts[j], "emf") == 0) {
if (have_libreoffice) { if (have_libreoffice) {
ret = testUtilVerifyLibreOffice(expected_file, debug); // Slow ret = testUtilVerifyLibreOffice(expected_file, debug); /* Slow */
assert_zero(ret, "i:%d %s libreoffice %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret); assert_zero(ret, "i:%d %s libreoffice %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret);
} }
if (have_vnu && strcmp(exts[j], "svg") == 0) { if (have_vnu && strcmp(exts[j], "svg") == 0) {
ret = testUtilVerifyVnu(expected_file, debug); // Very slow ret = testUtilVerifyVnu(expected_file, debug); /* Very slow */
assert_zero(ret, "i:%d %s vnu %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret); assert_zero(ret, "i:%d %s vnu %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret);
} }
} else if (strcmp(exts[j], "tif") == 0 && have_tiffinfo) { // Much faster (and better) than identify } else if (strcmp(exts[j], "tif") == 0 && have_tiffinfo) { /* Much faster (and better) than identify */
ret = testUtilVerifyTiffInfo(expected_file, debug); ret = testUtilVerifyTiffInfo(expected_file, debug);
assert_zero(ret, "i:%d %s tiffinfo %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret); assert_zero(ret, "i:%d %s tiffinfo %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret);
} else if (strcmp(exts[j], "txt") != 0) { // I.e. rasters } else if (strcmp(exts[j], "txt") != 0) { /* I.e. rasters */
if (have_identify) { if (have_identify) {
ret = testUtilVerifyIdentify(expected_file, debug); ret = testUtilVerifyIdentify(expected_file, debug);
assert_zero(ret, "i:%d %s identify %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret); assert_zero(ret, "i:%d %s identify %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret);
@ -202,7 +204,7 @@ static void test_print(int index, int generate, int debug) {
assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret); assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
} }
if (index == -1) assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile); if (p_ctx->index == -1) assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
} }
ZBarcode_Delete(symbol); ZBarcode_Delete(symbol);
@ -214,8 +216,8 @@ static void test_print(int index, int generate, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_print", test_print, 1, 1, 1 }, { "test_print", test_print },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
@ -224,3 +226,5 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -32,7 +32,8 @@
#include "testcommon.h" #include "testcommon.h"
#include <sys/stat.h> #include <sys/stat.h>
static void test_print(int index, int generate, int debug) { static void test_print(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -105,7 +106,7 @@ static void test_print(int index, int generate, int debug) {
testStart("test_print"); testStart("test_print");
if (generate) { if (p_ctx->generate) {
char data_dir_path[1024]; char data_dir_path[1024];
assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir);
if (!testUtilDirExists(data_dir_path)) { if (!testUtilDirExists(data_dir_path)) {
@ -116,7 +117,7 @@ static void test_print(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -153,7 +154,7 @@ static void test_print(int index, int generate, int debug) {
assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i); assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, %s, %d, %d, %d, %d, %.5g, %.5g, \"%s\", \"%s\", %d, \"%s\", \"%s\"},\n", printf(" /*%3d*/ { %s, %s, %d, %s, %d, %d, %d, %d, %.5g, %.5g, \"%s\", \"%s\", %d, \"%s\", \"%s\"},\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].border_width, i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].border_width,
testUtilOutputOptionsName(data[i].output_options), data[i].whitespace_width, data[i].whitespace_height, data[i].option_1, data[i].option_2, testUtilOutputOptionsName(data[i].output_options), data[i].whitespace_width, data[i].whitespace_height, data[i].option_1, data[i].option_2,
@ -182,7 +183,7 @@ static void test_print(int index, int generate, int debug) {
INTERNAL void ps_convert_test(const unsigned char *string, unsigned char *ps_string); INTERNAL void ps_convert_test(const unsigned char *string, unsigned char *ps_string);
static void test_ps_convert(int index) { static void test_ps_convert(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -200,7 +201,7 @@ static void test_ps_convert(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
ps_convert_test((unsigned char *) data[i].data, converted); ps_convert_test((unsigned char *) data[i].data, converted);
assert_zero(strcmp((char *) converted, data[i].expected), "i:%d ps_convert(%s) %s != %s\n", i, data[i].data, converted, data[i].expected); assert_zero(strcmp((char *) converted, data[i].expected), "i:%d ps_convert(%s) %s != %s\n", i, data[i].data, converted, data[i].expected);
@ -211,11 +212,13 @@ static void test_ps_convert(int index) {
INTERNAL int ps_plot(struct zint_symbol *symbol, int rotate_angle); INTERNAL int ps_plot(struct zint_symbol *symbol, int rotate_angle);
static void test_outfile(void) { static void test_outfile(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol symbol = {0}; struct zint_symbol symbol = {0};
struct zint_vector vector = {0}; struct zint_vector vector = {0};
(void)p_ctx;
testStart("test_outfile"); testStart("test_outfile");
symbol.symbology = BARCODE_CODE128; symbol.symbology = BARCODE_CODE128;
@ -241,10 +244,10 @@ static void test_outfile(void) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_print", test_print, 1, 1, 1 }, { "test_print", test_print },
{ "test_ps_convert", test_ps_convert, 1, 0, 0 }, { "test_ps_convert", test_ps_convert },
{ "test_outfile", test_outfile, 0, 0, 0 }, { "test_outfile", test_outfile },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -31,7 +31,8 @@
#include "testcommon.h" #include "testcommon.h"
static void test_qr_options(int index, int debug) { static void test_qr_options(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int option_1; int option_1;
@ -99,8 +100,7 @@ static void test_qr_options(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -112,7 +112,7 @@ static void test_qr_options(int index, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt); assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt);
if (index == -1 && data[i].compare_previous != -1) { if (p_ctx->index == -1 && data[i].compare_previous != -1) {
ret = testUtilSymbolCmp(symbol, &previous_symbol); ret = testUtilSymbolCmp(symbol, &previous_symbol);
assert_equal(!ret, !data[i].compare_previous, "i:%d testUtilSymbolCmp !ret %d != %d\n", i, ret, data[i].compare_previous); assert_equal(!ret, !data[i].compare_previous, "i:%d testUtilSymbolCmp !ret %d != %d\n", i, ret, data[i].compare_previous);
} }
@ -131,7 +131,8 @@ static void test_qr_options(int index, int debug) {
testFinish(); testFinish();
} }
static void test_qr_input(int index, int generate, int debug) { static void test_qr_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -322,8 +323,7 @@ static void test_qr_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -335,7 +335,7 @@ static void test_qr_input(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, %s, \"%s\", %s, %d, \"%s\", %d, %d, \"%s\" },\n", printf(" /*%3d*/ { %s, %d, %d, %s, \"%s\", %s, %d, \"%s\", %d, %d, \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, testUtilOption3Name(data[i].option_3), i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, testUtilOption3Name(data[i].option_3),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
@ -386,7 +386,8 @@ static void test_qr_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_qr_gs1(int index, int generate, int debug) { static void test_qr_gs1(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -426,8 +427,7 @@ static void test_qr_gs1(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -439,7 +439,7 @@ static void test_qr_gs1(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_3, i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_3,
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment); testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
@ -468,7 +468,8 @@ static void test_qr_gs1(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_qr_optimize(int index, int generate, int debug) { static void test_qr_optimize(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -527,8 +528,7 @@ static void test_qr_optimize(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -540,7 +540,7 @@ static void test_qr_optimize(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, \"%s\", %d, \"%s\" },\n", printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, \"%s\", %d, \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_3, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_3, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->errtxt, data[i].bwipp_cmp, data[i].comment); testUtilErrorName(data[i].ret), symbol->errtxt, data[i].bwipp_cmp, data[i].comment);
@ -580,7 +580,8 @@ static void test_qr_optimize(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_qr_encode(int index, int generate, int debug) { static void test_qr_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -3980,8 +3981,7 @@ static void test_qr_encode(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -3996,7 +3996,7 @@ static void test_qr_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, %d, %d, %s, { %d, %d, \"%s\" }, \"%s\", %d, %s, %d, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %s, %d, %d, %d, %s, { %d, %d, \"%s\" }, \"%s\", %d, %s, %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode),
data[i].eci, data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3), data[i].eci, data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3),
@ -4046,7 +4046,8 @@ static void test_qr_encode(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_qr_encode_segs(int index, int generate, int debug) { static void test_qr_encode_segs(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -4301,8 +4302,7 @@ static void test_qr_encode_segs(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -4318,7 +4318,7 @@ static void test_qr_encode_segs(int index, int generate, int debug) {
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count); ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
char escaped1[4096]; char escaped1[4096];
char escaped2[4096]; char escaped2[4096];
int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length;
@ -4392,7 +4392,8 @@ static void test_qr_encode_segs(int index, int generate, int debug) {
#define TEST_PERF_ITERATIONS 1000 #define TEST_PERF_ITERATIONS 1000
/* Not a real test, just performance indicator */ /* Not a real test, just performance indicator */
static void test_qr_perf(int index, int debug) { static void test_qr_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -4434,7 +4435,7 @@ static void test_qr_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_encode = diff_buffer = 0; diff_encode = diff_buffer = 0;
@ -4465,12 +4466,13 @@ static void test_qr_perf(int index, int debug) {
total_encode += diff_encode; total_encode += diff_encode;
total_buffer += diff_buffer; total_buffer += diff_buffer;
} }
if (index != -1) { if (p_ctx->index != -1) {
printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC); printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
} }
} }
static void test_microqr_options(int index, int debug) { static void test_microqr_options(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int option_1; int option_1;
@ -4557,7 +4559,7 @@ static void test_microqr_options(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -4566,7 +4568,7 @@ static void test_microqr_options(int index, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt); assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt);
if (index == -1 && data[i].compare_previous != -1) { if (p_ctx->index == -1 && data[i].compare_previous != -1) {
ret = testUtilSymbolCmp(symbol, &previous_symbol); ret = testUtilSymbolCmp(symbol, &previous_symbol);
assert_equal(!ret, !data[i].compare_previous, "i:%d testUtilSymbolCmp !ret %d != %d\n", i, ret, data[i].compare_previous); assert_equal(!ret, !data[i].compare_previous, "i:%d testUtilSymbolCmp !ret %d != %d\n", i, ret, data[i].compare_previous);
} }
@ -4585,7 +4587,8 @@ static void test_microqr_options(int index, int debug) {
testFinish(); testFinish();
} }
static void test_microqr_input(int index, int generate, int debug) { static void test_microqr_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -4669,8 +4672,7 @@ static void test_microqr_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -4682,7 +4684,7 @@ static void test_microqr_input(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %s, \"%s\", %s, \"%s\", %d, %d, \"%s\" },\n", printf(" /*%3d*/ { %s, %d, %s, \"%s\", %s, \"%s\", %d, %d, \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, testUtilOption3Name(data[i].option_3), i, testUtilInputModeName(data[i].input_mode), data[i].option_1, testUtilOption3Name(data[i].option_3),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
@ -4730,7 +4732,8 @@ static void test_microqr_input(int index, int generate, int debug) {
} }
/* Check MICROQR padding (4-bit final codeword for M1 and M3 in particular) */ /* Check MICROQR padding (4-bit final codeword for M1 and M3 in particular) */
static void test_microqr_padding(int index, int generate, int debug) { static void test_microqr_padding(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int option_1; int option_1;
@ -4791,8 +4794,7 @@ static void test_microqr_padding(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -4810,7 +4812,7 @@ static void test_microqr_padding(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %d, \"%s\", %s, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %d, \"%s\", %s, \"%s\", \"%s\" },\n",
i, data[i].option_1, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, data[i].option_1, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment); testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
@ -4845,7 +4847,8 @@ static void test_microqr_padding(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_microqr_optimize(int index, int generate, int debug) { static void test_microqr_optimize(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -4889,7 +4892,7 @@ static void test_microqr_optimize(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -4901,7 +4904,7 @@ static void test_microqr_optimize(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, %s, \"%s\", %s, \"%s\", %d, %d, \"%s\" },\n", printf(" /*%3d*/ { %s, %d, %d, %s, \"%s\", %s, \"%s\", %d, %d, \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3), i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
@ -4946,7 +4949,8 @@ static void test_microqr_optimize(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_microqr_encode(int index, int generate, int debug) { static void test_microqr_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -5922,7 +5926,7 @@ static void test_microqr_encode(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -5932,7 +5936,7 @@ static void test_microqr_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, %s, \"%s\", %s, %d, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, %d, %s, \"%s\", %s, %d, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3), i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret),
@ -5981,7 +5985,8 @@ static void test_microqr_encode(int index, int generate, int debug) {
} }
/* Not a real test, just performance indicator */ /* Not a real test, just performance indicator */
static void test_microqr_perf(int index, int debug) { static void test_microqr_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -6013,7 +6018,7 @@ static void test_microqr_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_encode = diff_buffer = 0; diff_encode = diff_buffer = 0;
@ -6044,12 +6049,13 @@ static void test_microqr_perf(int index, int debug) {
total_encode += diff_encode; total_encode += diff_encode;
total_buffer += diff_buffer; total_buffer += diff_buffer;
} }
if (index != -1) { if (p_ctx->index != -1) {
printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC); printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
} }
} }
static void test_upnqr_input(int index, int generate, int debug) { static void test_upnqr_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -6081,7 +6087,7 @@ static void test_upnqr_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -6096,7 +6102,7 @@ static void test_upnqr_input(int index, int generate, int debug) {
assert_equal(symbol->eci, 4, "i:%d ZBarcode_Encode symbol->eci %d != 4\n", i, symbol->eci); assert_equal(symbol->eci, 4, "i:%d ZBarcode_Encode symbol->eci %d != 4\n", i, symbol->eci);
} }
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, \"%s\", %s, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), i, testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret),
symbol->errtxt, data[i].comment); symbol->errtxt, data[i].comment);
@ -6110,7 +6116,8 @@ static void test_upnqr_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_upnqr_encode(int index, int generate, int debug) { static void test_upnqr_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -6541,7 +6548,7 @@ static void test_upnqr_encode(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -6551,7 +6558,7 @@ static void test_upnqr_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, %s, \"%s\", %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, %d, %s, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3), i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
@ -6603,7 +6610,8 @@ static void test_upnqr_encode(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_rmqr_large(int index, int debug) { static void test_rmqr_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int option_1; int option_1;
@ -7140,7 +7148,7 @@ static void test_rmqr_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -7173,7 +7181,8 @@ static void test_rmqr_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_rmqr_options(int index, int debug) { static void test_rmqr_options(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int option_1; int option_1;
@ -7264,7 +7273,7 @@ static void test_rmqr_options(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -7288,7 +7297,8 @@ static void test_rmqr_options(int index, int debug) {
testFinish(); testFinish();
} }
static void test_rmqr_input(int index, int generate, int debug) { static void test_rmqr_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -7437,7 +7447,7 @@ static void test_rmqr_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -7449,7 +7459,7 @@ static void test_rmqr_input(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, %d, %s, \"%s\", %s, %d, \"%s\", %d, \"%s\" },\n", printf(" /*%3d*/ { %s, %d, %d, %d, %s, \"%s\", %s, %d, \"%s\", %d, \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, i, testUtilInputModeName(data[i].input_mode), data[i].eci,
data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3), data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3),
@ -7486,7 +7496,8 @@ static void test_rmqr_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_rmqr_gs1(int index, int generate, int debug) { static void test_rmqr_gs1(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -7520,7 +7531,7 @@ static void test_rmqr_gs1(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -7532,7 +7543,7 @@ static void test_rmqr_gs1(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, \"%s\", %s, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment); i, testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
} else { } else {
@ -7545,7 +7556,8 @@ static void test_rmqr_gs1(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_rmqr_optimize(int index, int generate, int debug) { static void test_rmqr_optimize(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -7595,7 +7607,7 @@ static void test_rmqr_optimize(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -7607,7 +7619,7 @@ static void test_rmqr_optimize(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, \"%s\", %d, \"%s\" },\n", printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, \"%s\", %d, \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2,
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
@ -7637,7 +7649,8 @@ static void test_rmqr_optimize(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_rmqr_encode(int index, int generate, int debug) { static void test_rmqr_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -8035,7 +8048,7 @@ static void test_rmqr_encode(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -8045,7 +8058,7 @@ static void test_rmqr_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, %d, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, %d, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2,
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret),
@ -8082,7 +8095,8 @@ static void test_rmqr_encode(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_rmqr_encode_segs(int index, int generate, int debug) { static void test_rmqr_encode_segs(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -8204,7 +8218,7 @@ static void test_rmqr_encode_segs(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -8217,7 +8231,7 @@ static void test_rmqr_encode_segs(int index, int generate, int debug) {
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count); ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
char escaped1[4096]; char escaped1[4096];
char escaped2[4096]; char escaped2[4096];
int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length;
@ -8284,32 +8298,32 @@ static void test_rmqr_encode_segs(int index, int generate, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_qr_options", test_qr_options, 1, 0, 1 }, { "test_qr_options", test_qr_options },
{ "test_qr_input", test_qr_input, 1, 1, 1 }, { "test_qr_input", test_qr_input },
{ "test_qr_gs1", test_qr_gs1, 1, 1, 1 }, { "test_qr_gs1", test_qr_gs1 },
{ "test_qr_optimize", test_qr_optimize, 1, 1, 1 }, { "test_qr_optimize", test_qr_optimize },
{ "test_qr_encode", test_qr_encode, 1, 1, 1 }, { "test_qr_encode", test_qr_encode },
{ "test_qr_encode_segs", test_qr_encode_segs, 1, 1, 1 }, { "test_qr_encode_segs", test_qr_encode_segs },
{ "test_qr_perf", test_qr_perf, 1, 0, 1 }, { "test_qr_perf", test_qr_perf },
{ "test_microqr_options", test_microqr_options, 1, 0, 1 }, { "test_microqr_options", test_microqr_options },
{ "test_microqr_input", test_microqr_input, 1, 1, 1 }, { "test_microqr_input", test_microqr_input },
{ "test_microqr_padding", test_microqr_padding, 1, 1, 1 }, { "test_microqr_padding", test_microqr_padding },
{ "test_microqr_optimize", test_microqr_optimize, 1, 1, 1 }, { "test_microqr_optimize", test_microqr_optimize },
{ "test_microqr_encode", test_microqr_encode, 1, 1, 1 }, { "test_microqr_encode", test_microqr_encode },
{ "test_microqr_perf", test_microqr_perf, 1, 0, 1 }, { "test_microqr_perf", test_microqr_perf },
{ "test_upnqr_input", test_upnqr_input, 1, 1, 1 }, { "test_upnqr_input", test_upnqr_input },
{ "test_upnqr_encode", test_upnqr_encode, 1, 1, 1 }, { "test_upnqr_encode", test_upnqr_encode },
{ "test_rmqr_large", test_rmqr_large, 1, 0, 1 }, { "test_rmqr_large", test_rmqr_large },
{ "test_rmqr_options", test_rmqr_options, 1, 0, 1 }, { "test_rmqr_options", test_rmqr_options },
{ "test_rmqr_input", test_rmqr_input, 1, 1, 1 }, { "test_rmqr_input", test_rmqr_input },
{ "test_rmqr_gs1", test_rmqr_gs1, 1, 1, 1 }, { "test_rmqr_gs1", test_rmqr_gs1 },
{ "test_rmqr_optimize", test_rmqr_optimize, 1, 1, 1 }, { "test_rmqr_optimize", test_rmqr_optimize },
{ "test_rmqr_encode", test_rmqr_encode, 1, 1, 1 }, { "test_rmqr_encode", test_rmqr_encode },
{ "test_rmqr_encode_segs", test_rmqr_encode_segs, 1, 1, 1 }, { "test_rmqr_encode_segs", test_rmqr_encode_segs },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -41,7 +41,8 @@ static int is_row_column_black(struct zint_symbol *symbol, int row, int column)
return symbol->bitmap[i] == 0 && symbol->bitmap[i + 1] == 0 && symbol->bitmap[i + 2] == 0; /* Black */ return symbol->bitmap[i] == 0 && symbol->bitmap[i + 1] == 0 && symbol->bitmap[i + 2] == 0; /* Black */
} }
static void test_options(int index, int debug) { static void test_options(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -75,7 +76,7 @@ static void test_options(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -105,7 +106,8 @@ static void test_options(int index, int debug) {
testFinish(); testFinish();
} }
static void test_buffer(int index, int generate, int debug) { static void test_buffer(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -391,8 +393,7 @@ static void test_buffer(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i); /* ZINT_DEBUG_TEST_PRINT 16 */
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -412,9 +413,9 @@ static void test_buffer(int index, int generate, int debug) {
assert_zero(ret, "i:%d ZBarcode_Buffer(%s) ret %d != 0 (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt); assert_zero(ret, "i:%d ZBarcode_Buffer(%s) ret %d != 0 (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt);
assert_nonnull(symbol->bitmap, "i:%d ZBarcode_Buffer(%s) bitmap NULL\n", i, testUtilBarcodeName(data[i].symbology)); assert_nonnull(symbol->bitmap, "i:%d ZBarcode_Buffer(%s) bitmap NULL\n", i, testUtilBarcodeName(data[i].symbology));
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */ if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, \"%s\", \"%s\", %.8g, %d, %d, %d, %d },\n", printf(" /*%3d*/ { %s, %s, \"%s\", \"%s\", %.8g, %d, %d, %d, %d },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilOutputOptionsName(data[i].output_options), i, testUtilBarcodeName(data[i].symbology), testUtilOutputOptionsName(data[i].output_options),
data[i].data, data[i].composite, data[i].data, data[i].composite,
@ -435,7 +436,8 @@ static void test_buffer(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_upcean_hrt(int index, int debug) { static void test_upcean_hrt(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -498,8 +500,7 @@ static void test_upcean_hrt(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i); /* ZINT_DEBUG_TEST_PRINT 16 */
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -516,7 +517,7 @@ static void test_upcean_hrt(int index, int debug) {
assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret);
assert_nonnull(symbol->bitmap, "i:%d (%d) symbol->bitmap NULL\n", i, data[i].symbology); assert_nonnull(symbol->bitmap, "i:%d (%d) symbol->bitmap NULL\n", i, data[i].symbology);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */ if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */
assert_equal(symbol->height, data[i].expected_height, "i:%d (%s) symbol->height %.8g != %.8g\n", i, testUtilBarcodeName(data[i].symbology), symbol->height, data[i].expected_height); assert_equal(symbol->height, data[i].expected_height, "i:%d (%s) symbol->height %.8g != %.8g\n", i, testUtilBarcodeName(data[i].symbology), symbol->height, data[i].expected_height);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d (%s) symbol->rows %d != %d\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows); assert_equal(symbol->rows, data[i].expected_rows, "i:%d (%s) symbol->rows %d != %d\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows);
@ -573,7 +574,8 @@ static void test_upcean_hrt(int index, int debug) {
testFinish(); testFinish();
} }
static void test_row_separator(int index, int debug) { static void test_row_separator(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -614,7 +616,7 @@ static void test_row_separator(int index, int debug) {
int j, separator_bits_set; int j, separator_bits_set;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -636,7 +638,7 @@ static void test_row_separator(int index, int debug) {
assert_equal(symbol->bitmap_height, data[i].expected_bitmap_height, "i:%d (%s) symbol->bitmap_height %d != %d\n", i, testUtilBarcodeName(data[i].symbology), assert_equal(symbol->bitmap_height, data[i].expected_bitmap_height, "i:%d (%s) symbol->bitmap_height %d != %d\n", i, testUtilBarcodeName(data[i].symbology),
symbol->bitmap_height, data[i].expected_bitmap_height); symbol->bitmap_height, data[i].expected_bitmap_height);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */ if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */
for (j = data[i].expected_separator_row; j < data[i].expected_separator_row + data[i].expected_separator_height; j++) { for (j = data[i].expected_separator_row; j < data[i].expected_separator_row + data[i].expected_separator_height; j++) {
separator_bits_set = is_row_column_black(symbol, j, data[i].expected_separator_col); separator_bits_set = is_row_column_black(symbol, j, data[i].expected_separator_col);
@ -659,7 +661,8 @@ static void test_row_separator(int index, int debug) {
testFinish(); testFinish();
} }
static void test_stacking(int index, int debug) { static void test_stacking(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -695,7 +698,7 @@ static void test_stacking(int index, int debug) {
int j, separator_bits_set; int j, separator_bits_set;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -718,7 +721,7 @@ static void test_stacking(int index, int debug) {
assert_equal(symbol->bitmap_width, data[i].expected_bitmap_width, "i:%d (%d) symbol->bitmap_width %d != %d\n", i, data[i].symbology, symbol->bitmap_width, data[i].expected_bitmap_width); assert_equal(symbol->bitmap_width, data[i].expected_bitmap_width, "i:%d (%d) symbol->bitmap_width %d != %d\n", i, data[i].symbology, symbol->bitmap_width, data[i].expected_bitmap_width);
assert_equal(symbol->bitmap_height, data[i].expected_bitmap_height, "i:%d (%d) symbol->bitmap_height %d != %d\n", i, data[i].symbology, symbol->bitmap_height, data[i].expected_bitmap_height); assert_equal(symbol->bitmap_height, data[i].expected_bitmap_height, "i:%d (%d) symbol->bitmap_height %d != %d\n", i, data[i].symbology, symbol->bitmap_height, data[i].expected_bitmap_height);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */ if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */
if (data[i].expected_separator_row != -1) { if (data[i].expected_separator_row != -1) {
for (j = data[i].expected_separator_row; j < data[i].expected_separator_row + data[i].expected_separator_height; j++) { for (j = data[i].expected_separator_row; j < data[i].expected_separator_row + data[i].expected_separator_height; j++) {
@ -743,7 +746,8 @@ static void test_stacking(int index, int debug) {
testFinish(); testFinish();
} }
static void test_stacking_too_many(int debug) { static void test_stacking_too_many(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
int i, length, ret; int i, length, ret;
struct zint_symbol *symbol; struct zint_symbol *symbol;
@ -773,7 +777,8 @@ static void test_stacking_too_many(int debug) {
testFinish(); testFinish();
} }
static void test_output_options(int index, int debug) { static void test_output_options(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -896,7 +901,7 @@ static void test_output_options(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -924,7 +929,7 @@ static void test_output_options(int index, int debug) {
if (ret < 5) { if (ret < 5) {
assert_nonnull(symbol->bitmap, "i:%d (%s) symbol->bitmap NULL\n", i, testUtilBarcodeName(data[i].symbology)); assert_nonnull(symbol->bitmap, "i:%d (%s) symbol->bitmap NULL\n", i, testUtilBarcodeName(data[i].symbology));
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */ if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */
assert_equal(symbol->height, data[i].expected_height, "i:%d (%s) symbol->height %.8g != %.8g\n", i, testUtilBarcodeName(data[i].symbology), symbol->height, data[i].expected_height); assert_equal(symbol->height, data[i].expected_height, "i:%d (%s) symbol->height %.8g != %.8g\n", i, testUtilBarcodeName(data[i].symbology), symbol->height, data[i].expected_height);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d (%s) symbol->rows %d != %d\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows); assert_equal(symbol->rows, data[i].expected_rows, "i:%d (%s) symbol->rows %d != %d\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows);
@ -952,7 +957,8 @@ static void test_output_options(int index, int debug) {
testFinish(); testFinish();
} }
static void test_draw_string_wrap(int index, int debug) { static void test_draw_string_wrap(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -983,7 +989,7 @@ static void test_draw_string_wrap(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int text_bits_set, row, column; int text_bits_set, row, column;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1006,7 +1012,7 @@ static void test_draw_string_wrap(int index, int debug) {
assert_equal(symbol->bitmap_width, data[i].expected_bitmap_width, "i:%d (%d) symbol->bitmap_width %d != %d\n", i, data[i].symbology, symbol->bitmap_width, data[i].expected_bitmap_width); assert_equal(symbol->bitmap_width, data[i].expected_bitmap_width, "i:%d (%d) symbol->bitmap_width %d != %d\n", i, data[i].symbology, symbol->bitmap_width, data[i].expected_bitmap_width);
assert_equal(symbol->bitmap_height, data[i].expected_bitmap_height, "i:%d (%d) symbol->bitmap_height %d != %d\n", i, data[i].symbology, symbol->bitmap_height, data[i].expected_bitmap_height); assert_equal(symbol->bitmap_height, data[i].expected_bitmap_height, "i:%d (%d) symbol->bitmap_height %d != %d\n", i, data[i].symbology, symbol->bitmap_height, data[i].expected_bitmap_height);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */ if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */
ret = ZBarcode_Print(symbol, 0); ret = ZBarcode_Print(symbol, 0);
assert_zero(ret, "i:%d ZBarcode_Print(%d) ret %d != 0\n", i, data[i].symbology, ret); assert_zero(ret, "i:%d ZBarcode_Print(%d) ret %d != 0\n", i, data[i].symbology, ret);
@ -1028,7 +1034,8 @@ static void test_draw_string_wrap(int index, int debug) {
testFinish(); testFinish();
} }
static void test_code128_utf8(int index, int debug) { static void test_code128_utf8(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -1055,7 +1062,7 @@ static void test_code128_utf8(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int text_bits_set, row, column; int text_bits_set, row, column;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1075,7 +1082,7 @@ static void test_code128_utf8(int index, int debug) {
assert_equal(symbol->bitmap_width, data[i].expected_bitmap_width, "i:%d (%d) symbol->bitmap_width %d != %d\n", i, BARCODE_CODE128, symbol->bitmap_width, data[i].expected_bitmap_width); assert_equal(symbol->bitmap_width, data[i].expected_bitmap_width, "i:%d (%d) symbol->bitmap_width %d != %d\n", i, BARCODE_CODE128, symbol->bitmap_width, data[i].expected_bitmap_width);
assert_equal(symbol->bitmap_height, data[i].expected_bitmap_height, "i:%d (%d) symbol->bitmap_height %d != %d\n", i, BARCODE_CODE128, symbol->bitmap_height, data[i].expected_bitmap_height); assert_equal(symbol->bitmap_height, data[i].expected_bitmap_height, "i:%d (%d) symbol->bitmap_height %d != %d\n", i, BARCODE_CODE128, symbol->bitmap_height, data[i].expected_bitmap_height);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */ if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */
ret = ZBarcode_Print(symbol, 0); ret = ZBarcode_Print(symbol, 0);
assert_zero(ret, "i:%d ZBarcode_Print(%d) ret %d != 0\n", i, BARCODE_CODE128, ret); assert_zero(ret, "i:%d ZBarcode_Print(%d) ret %d != 0\n", i, BARCODE_CODE128, ret);
@ -1096,7 +1103,8 @@ static void test_code128_utf8(int index, int debug) {
testFinish(); testFinish();
} }
static void test_scale(int index, int debug) { static void test_scale(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1220,7 +1228,7 @@ static void test_scale(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int row, column; int row, column;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1250,7 +1258,7 @@ static void test_scale(int index, int debug) {
assert_equal(ret, data[i].ret_raster, "i:%d ZBarcode_Buffer(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret_raster, symbol->errtxt); assert_equal(ret, data[i].ret_raster, "i:%d ZBarcode_Buffer(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret_raster, symbol->errtxt);
assert_nonnull(symbol->bitmap, "i:%d (%d) symbol->bitmap NULL\n", i, data[i].symbology); assert_nonnull(symbol->bitmap, "i:%d (%d) symbol->bitmap NULL\n", i, data[i].symbology);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */ if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */
assert_equal(symbol->height, data[i].expected_height, "i:%d (%d) symbol->height %.8g != %.8g\n", i, data[i].symbology, symbol->height, data[i].expected_height); assert_equal(symbol->height, data[i].expected_height, "i:%d (%d) symbol->height %.8g != %.8g\n", i, data[i].symbology, symbol->height, data[i].expected_height);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d (%d) symbol->rows %d != %d\n", i, data[i].symbology, symbol->rows, data[i].expected_rows); assert_equal(symbol->rows, data[i].expected_rows, "i:%d (%d) symbol->rows %d != %d\n", i, data[i].symbology, symbol->rows, data[i].expected_rows);
@ -1281,7 +1289,8 @@ static void test_scale(int index, int debug) {
testFinish(); testFinish();
} }
static void test_guard_descent(int index, int debug) { static void test_guard_descent(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1344,7 +1353,7 @@ static void test_guard_descent(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int row, column; int row, column;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1361,7 +1370,7 @@ static void test_guard_descent(int index, int debug) {
assert_equal(ret, data[i].ret_raster, "i:%d ZBarcode_Buffer(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret_raster, symbol->errtxt); assert_equal(ret, data[i].ret_raster, "i:%d ZBarcode_Buffer(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret_raster, symbol->errtxt);
assert_nonnull(symbol->bitmap, "i:%d (%d) symbol->bitmap NULL\n", i, data[i].symbology); assert_nonnull(symbol->bitmap, "i:%d (%d) symbol->bitmap NULL\n", i, data[i].symbology);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */ if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */
assert_equal(symbol->height, data[i].expected_height, "i:%d (%d) symbol->height %.8g != %.8g\n", i, data[i].symbology, symbol->height, data[i].expected_height); assert_equal(symbol->height, data[i].expected_height, "i:%d (%d) symbol->height %.8g != %.8g\n", i, data[i].symbology, symbol->height, data[i].expected_height);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d (%d) symbol->rows %d != %d\n", i, data[i].symbology, symbol->rows, data[i].expected_rows); assert_equal(symbol->rows, data[i].expected_rows, "i:%d (%d) symbol->rows %d != %d\n", i, data[i].symbology, symbol->rows, data[i].expected_rows);
@ -1396,7 +1405,8 @@ static void test_guard_descent(int index, int debug) {
testFinish(); testFinish();
} }
static void test_quiet_zones(int index, int debug) { static void test_quiet_zones(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1709,7 +1719,7 @@ static void test_quiet_zones(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int row, column; int row, column;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1735,7 +1745,7 @@ static void test_quiet_zones(int index, int debug) {
assert_equal(ret, data[i].ret_raster, "i:%d ZBarcode_Buffer(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret_raster, symbol->errtxt); assert_equal(ret, data[i].ret_raster, "i:%d ZBarcode_Buffer(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret_raster, symbol->errtxt);
assert_nonnull(symbol->bitmap, "i:%d (%d) symbol->bitmap NULL\n", i, data[i].symbology); assert_nonnull(symbol->bitmap, "i:%d (%d) symbol->bitmap NULL\n", i, data[i].symbology);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */ if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */
assert_equal(symbol->height, data[i].expected_height, "i:%d (%d) symbol->height %.8g != %.8g\n", i, data[i].symbology, symbol->height, data[i].expected_height); assert_equal(symbol->height, data[i].expected_height, "i:%d (%d) symbol->height %.8g != %.8g\n", i, data[i].symbology, symbol->height, data[i].expected_height);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d (%d) symbol->rows %d != %d\n", i, data[i].symbology, symbol->rows, data[i].expected_rows); assert_equal(symbol->rows, data[i].expected_rows, "i:%d (%d) symbol->rows %d != %d\n", i, data[i].symbology, symbol->rows, data[i].expected_rows);
@ -1770,7 +1780,8 @@ static void test_quiet_zones(int index, int debug) {
testFinish(); testFinish();
} }
static void test_buffer_plot(int index, int generate, int debug) { static void test_buffer_plot(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1895,8 +1906,7 @@ static void test_buffer_plot(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i); /* ZINT_DEBUG_TEST_PRINT 16 */
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1925,9 +1935,9 @@ static void test_buffer_plot(int index, int generate, int debug) {
assert_zero(ret, "i:%d ZBarcode_Buffer(%s) ret %d != 0 (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt); assert_zero(ret, "i:%d ZBarcode_Buffer(%s) ret %d != 0 (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt);
assert_nonnull(symbol->bitmap, "i:%d ZBarcode_Buffer(%s) bitmap NULL\n", i, testUtilBarcodeName(data[i].symbology)); assert_nonnull(symbol->bitmap, "i:%d ZBarcode_Buffer(%s) bitmap NULL\n", i, testUtilBarcodeName(data[i].symbology));
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */ if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); /* ZINT_DEBUG_TEST_PRINT 16 */
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, %d, %s, %g, \"%s\", \"%s\", \"%s\", %s, %g, %d, %d, %d, %d,\n", printf(" /*%3d*/ { %s, %d, %d, %d, %s, %g, \"%s\", \"%s\", \"%s\", %s, %g, %d, %d, %d, %d,\n",
i, testUtilBarcodeName(data[i].symbology), data[i].option_1, data[i].option_2, data[i].whitespace_width, testUtilOutputOptionsName(data[i].output_options), i, testUtilBarcodeName(data[i].symbology), data[i].option_1, data[i].option_2, data[i].whitespace_width, testUtilOutputOptionsName(data[i].output_options),
data[i].height, data[i].fgcolour, data[i].bgcolour, data[i].data, testUtilErrorName(data[i].ret), data[i].height, data[i].fgcolour, data[i].bgcolour, data[i].data, testUtilErrorName(data[i].ret),
@ -1962,7 +1972,8 @@ static void test_buffer_plot(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_height(int index, int generate, int debug) { static void test_height(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -2601,8 +2612,7 @@ static void test_height(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -2633,9 +2643,9 @@ static void test_height(int index, int generate, int debug) {
assert_zero(ret, "i:%d ZBarcode_Buffer(%s) ret %d != 0 (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt); assert_zero(ret, "i:%d ZBarcode_Buffer(%s) ret %d != 0 (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt);
assert_nonnull(symbol->bitmap, "i:%d ZBarcode_Buffer(%s) bitmap NULL\n", i, testUtilBarcodeName(data[i].symbology)); assert_nonnull(symbol->bitmap, "i:%d ZBarcode_Buffer(%s) bitmap NULL\n", i, testUtilBarcodeName(data[i].symbology));
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %.5g, \"%s\", \"%s\", %s, %.8g, %d, %d, %d, %d, \"%s\" },\n", printf(" /*%3d*/ { %s, %s, %.5g, \"%s\", \"%s\", %s, %.8g, %d, %d, %d, %d, \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilOutputOptionsName(data[i].output_options), i, testUtilBarcodeName(data[i].symbology), testUtilOutputOptionsName(data[i].output_options),
data[i].height, data[i].data, data[i].composite, testUtilErrorName(data[i].ret), data[i].height, data[i].data, data[i].composite, testUtilErrorName(data[i].ret),
@ -2656,7 +2666,8 @@ static void test_height(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_height_per_row(int index, int generate, int debug) { static void test_height_per_row(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -2766,8 +2777,7 @@ static void test_height_per_row(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -2795,9 +2805,9 @@ static void test_height_per_row(int index, int generate, int debug) {
assert_zero(ret, "i:%d ZBarcode_Buffer(%s) ret %d != 0 (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt); assert_zero(ret, "i:%d ZBarcode_Buffer(%s) ret %d != 0 (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt);
assert_nonnull(symbol->bitmap, "i:%d ZBarcode_Buffer(%s) bitmap NULL\n", i, testUtilBarcodeName(data[i].symbology)); assert_nonnull(symbol->bitmap, "i:%d ZBarcode_Buffer(%s) bitmap NULL\n", i, testUtilBarcodeName(data[i].symbology));
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, %d, %d, %.5g, %.5g, \"%s\", \"%s\", %s, %.8g, %d, %d, %d, %d, \"%s\" },\n", printf(" /*%3d*/ { %s, %s, %d, %d, %d, %.5g, %.5g, \"%s\", \"%s\", %s, %.8g, %d, %d, %d, %d, \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode),
data[i].option_1, data[i].option_2, data[i].option_3, data[i].height, data[i].scale, data[i].option_1, data[i].option_2, data[i].option_3, data[i].height, data[i].scale,
@ -2826,7 +2836,8 @@ static void test_height_per_row(int index, int generate, int debug) {
#define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC) #define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC)
/* Not a real test, just performance indicator for scaling */ /* Not a real test, just performance indicator for scaling */
static void test_perf_scale(int index, int debug) { static void test_perf_scale(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -2876,7 +2887,7 @@ static void test_perf_scale(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0; diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
@ -2932,7 +2943,7 @@ static void test_perf_scale(int index, int debug) {
total_buf_inter += diff_buf_inter; total_buf_inter += diff_buf_inter;
total_print += diff_print; total_print += diff_print;
} }
if (index == -1) { if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals", printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create)); TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
} }
@ -2940,23 +2951,23 @@ static void test_perf_scale(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_options", test_options, 1, 0, 1 }, { "test_options", test_options, },
{ "test_buffer", test_buffer, 1, 1, 1 }, { "test_buffer", test_buffer, },
{ "test_upcean_hrt", test_upcean_hrt, 1, 0, 1 }, { "test_upcean_hrt", test_upcean_hrt, },
{ "test_row_separator", test_row_separator, 1, 0, 1 }, { "test_row_separator", test_row_separator, },
{ "test_stacking", test_stacking, 1, 0, 1 }, { "test_stacking", test_stacking, },
{ "test_stacking_too_many", test_stacking_too_many, 0, 0, 1 }, { "test_stacking_too_many", test_stacking_too_many, },
{ "test_output_options", test_output_options, 1, 0, 1 }, { "test_output_options", test_output_options, },
{ "test_draw_string_wrap", test_draw_string_wrap, 1, 0, 1 }, { "test_draw_string_wrap", test_draw_string_wrap, },
{ "test_code128_utf8", test_code128_utf8, 1, 0, 1 }, { "test_code128_utf8", test_code128_utf8, },
{ "test_scale", test_scale, 1, 0, 1 }, { "test_scale", test_scale, },
{ "test_guard_descent", test_guard_descent, 1, 0, 1 }, { "test_guard_descent", test_guard_descent, },
{ "test_quiet_zones", test_quiet_zones, 1, 0, 1 }, { "test_quiet_zones", test_quiet_zones, },
{ "test_buffer_plot", test_buffer_plot, 1, 1, 1 }, { "test_buffer_plot", test_buffer_plot, },
{ "test_height", test_height, 1, 1, 1 }, { "test_height", test_height, },
{ "test_height_per_row", test_height_per_row, 1, 1, 1 }, { "test_height_per_row", test_height_per_row, },
{ "test_perf_scale", test_perf_scale, 1, 0, 1 }, { "test_perf_scale", test_perf_scale, },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -1,6 +1,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2020-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -27,12 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
#include "../reedsol.h" #include "../reedsol.h"
// Print out the log/alog tables for "backend/reedsol_logs.h" /* Print out the log/alog tables for "backend/reedsol_logs.h" */
static void print_logs(const char *name, int logmod, unsigned int *logt, unsigned int *alog, int u16, int last) { static void print_logs(const char *name, int logmod, unsigned int *logt, unsigned int *alog, int u16, int last) {
int i; int i;
const char *type = u16 ? "short" : "char"; const char *type = u16 ? "short" : "char";
@ -50,7 +50,7 @@ static void print_logs(const char *name, int logmod, unsigned int *logt, unsigne
if (i % 16 == 0) printf("\n "); if (i % 16 == 0) printf("\n ");
printf(format, alog[i]); printf(format, alog[i]);
} }
// Double antilog table /* Double antilog table */
for (i = 0; i < logmod; i++) { for (i = 0; i < logmod; i++) {
if (i % 16 == 0) printf("\n "); if (i % 16 == 0) printf("\n ");
printf(format, alog[i]); printf(format, alog[i]);
@ -66,7 +66,7 @@ static void gen_logs(const unsigned int prime_poly, int logmod, unsigned int *lo
b = logmod + 1; b = logmod + 1;
// Calculate the log/alog tables /* Calculate the log/alog tables */
for (p = 1, v = 0; v < logmod; v++) { for (p = 1, v = 0; v < logmod; v++) {
alog[v] = p; alog[v] = p;
logt[p] = v; logt[p] = v;
@ -76,8 +76,8 @@ static void gen_logs(const unsigned int prime_poly, int logmod, unsigned int *lo
} }
} }
// Dummy to generate static log/antilog tables for "backend/reedsol_logs.h" /* Dummy to generate static log/antilog tables for "backend/reedsol_logs.h" */
static void test_generate(int generate) { static void test_generate(const testCtx *const p_ctx) {
struct item { struct item {
const char *name; const char *name;
@ -100,7 +100,7 @@ static void test_generate(int generate) {
unsigned int logt[4096]; unsigned int logt[4096];
unsigned int alog[8192]; unsigned int alog[8192];
if (!generate) { if (!p_ctx->generate) {
return; return;
} }
@ -110,7 +110,8 @@ static void test_generate(int generate) {
} }
} }
static void test_encoding(int index, int debug) { static void test_encoding(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
unsigned int prime_poly; unsigned int prime_poly;
@ -121,26 +122,26 @@ static void test_encoding(int index, int debug) {
unsigned char expected[256]; unsigned char expected[256];
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { 0x43, 4, 1, 7, { 4, 20, 49, 37, 49, 38, 23 }, { 54, 17, 53, 58 } }, // AUSPOST Australia Post Customer Barcoding Technical Specifications Diagram 10 /* 0*/ { 0x43, 4, 1, 7, { 4, 20, 49, 37, 49, 38, 23 }, { 54, 17, 53, 58 } }, /* AUSPOST Australia Post Customer Barcoding Technical Specifications Diagram 10 */
/* 1*/ { 0x43, 7, 1, 10, { 9, 50, 1, 41, 47, 2, 39, 37, 1, 27 }, { 38, 50, 8, 16, 10, 20, 40 } }, // AZTEC ISO/IEC 24778:2008 Section G.4 /* 1*/ { 0x43, 7, 1, 10, { 9, 50, 1, 41, 47, 2, 39, 37, 1, 27 }, { 38, 50, 8, 16, 10, 20, 40 } }, /* AZTEC ISO/IEC 24778:2008 Section G.4 */
/* 2*/ { 0x13, 5, 1, 2, { 0, 9 }, { 12, 2, 3, 1, 9 } }, // AZTEC ISO/IEC 24778:2008 Section G.4 Mode Message /* 2*/ { 0x13, 5, 1, 2, { 0, 9 }, { 12, 2, 3, 1, 9 } }, /* AZTEC ISO/IEC 24778:2008 Section G.4 Mode Message */
/* 3*/ { 0x12d, 5, 1, 3, { 142, 164, 186 }, { 114, 25, 5, 88, 102 } }, // DATAMATRIX ISO/IEC 16022:2006 Annex O /* 3*/ { 0x12d, 5, 1, 3, { 142, 164, 186 }, { 114, 25, 5, 88, 102 } }, /* DATAMATRIX ISO/IEC 16022:2006 Annex O */
/* 4*/ { 0x89, 25, 1, 25, { 42, 13, 54, 39, 124, 91, 121, 65, 28, 40, 95, 48, 0, 126, 0, 126, 0, 126, 0, 126, 0, 126, 0, 126, 0 }, { 123, 47, 2, 20, 54, 112, 35, 23, 100, 89, 55, 17, 101, 4, 14, 33, 48, 62, 98, 52, 2, 79, 92, 70, 102 } }, // GRIDMATRIX AIMD014 Section 6.8 /* 4*/ { 0x89, 25, 1, 25, { 42, 13, 54, 39, 124, 91, 121, 65, 28, 40, 95, 48, 0, 126, 0, 126, 0, 126, 0, 126, 0, 126, 0, 126, 0 }, { 123, 47, 2, 20, 54, 112, 35, 23, 100, 89, 55, 17, 101, 4, 14, 33, 48, 62, 98, 52, 2, 79, 92, 70, 102 } }, /* GRIDMATRIX AIMD014 Section 6.8 */
/* 5*/ { 0x163, 4, 1, 21, { 0x11, 0xED, 0xC8, 0xC5, 0x40, 0x0F, 0xF4 }, { 0xEB, 0xB4, 0x68, 0x1D } }, // HANXIN ISO/IEC DIS 20830:2019 Annex K.1 /* 5*/ { 0x163, 4, 1, 21, { 0x11, 0xED, 0xC8, 0xC5, 0x40, 0x0F, 0xF4 }, { 0xEB, 0xB4, 0x68, 0x1D } }, /* HANXIN ISO/IEC DIS 20830:2019 Annex K.1 */
/* 6*/ { 0x163, 24, 1, 27, { 0x11, 0xED, 0xC8, 0xC5, 0x40, 0x0F, 0xF4, 0x8A, 0x2C, 0xC3, 0x4E, 0x3D, 0x09, 0x25, 0x9A, 0x7A, 0x29, 0xAB, 0xEA, 0x3E, 0x46, 0x4C, 0x7E, 0x73, 0xE8, 0x6C, 0xC7 }, { 0x08, 0x57, 0x0C, 0xE0, 0x7A, 0xA5, 0xDD, 0xA2, 0x99, 0xCF, 0xA4, 0x82, 0xAD, 0x11, 0xB0, 0x84, 0x74, 0x5D, 0x9A, 0x99, 0x0B, 0xCD, 0x49, 0x77 } }, // HANXIN ISO/IEC DIS 20830:2019 Annex K.2 1st block /* 6*/ { 0x163, 24, 1, 27, { 0x11, 0xED, 0xC8, 0xC5, 0x40, 0x0F, 0xF4, 0x8A, 0x2C, 0xC3, 0x4E, 0x3D, 0x09, 0x25, 0x9A, 0x7A, 0x29, 0xAB, 0xEA, 0x3E, 0x46, 0x4C, 0x7E, 0x73, 0xE8, 0x6C, 0xC7 }, { 0x08, 0x57, 0x0C, 0xE0, 0x7A, 0xA5, 0xDD, 0xA2, 0x99, 0xCF, 0xA4, 0x82, 0xAD, 0x11, 0xB0, 0x84, 0x74, 0x5D, 0x9A, 0x99, 0x0B, 0xCD, 0x49, 0x77 } }, /* HANXIN ISO/IEC DIS 20830:2019 Annex K.2 1st block */
/* 7*/ { 0x163, 24, 1, 27, { 0xE7, 0x3E, 0x33, 0x29, 0xE8, 0xFC, }, { 0xA2, 0xA7, 0x68, 0x8A, 0x5F, 0xE6, 0xAA, 0x11, 0xA6, 0x69, 0x4A, 0xCF, 0xCF, 0x20, 0x5D, 0x00, 0x1B, 0x79, 0xA1, 0xFE, 0xB7, 0x94, 0x03, 0x9B } }, // HANXIN ISO/IEC DIS 20830:2019 Annex K.2 2nd block /* 7*/ { 0x163, 24, 1, 27, { 0xE7, 0x3E, 0x33, 0x29, 0xE8, 0xFC, }, { 0xA2, 0xA7, 0x68, 0x8A, 0x5F, 0xE6, 0xAA, 0x11, 0xA6, 0x69, 0x4A, 0xCF, 0xCF, 0x20, 0x5D, 0x00, 0x1B, 0x79, 0xA1, 0xFE, 0xB7, 0x94, 0x03, 0x9B } }, /* HANXIN ISO/IEC DIS 20830:2019 Annex K.2 2nd block */
/* 8*/ { 0x163, 24, 1, 29, { 0x00 }, { 0x00 } }, // HANXIN ISO/IEC DIS 20830:2019 Annex K.2 3rd block /* 8*/ { 0x163, 24, 1, 29, { 0x00 }, { 0x00 } }, /* HANXIN ISO/IEC DIS 20830:2019 Annex K.2 3rd block */
/* 9*/ { 0x25, 6, 1, 16, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }, { 14, 7, 23, 3, 23, 15 } }, // MAILMARK Royal Mail Mailmark barcode C encoding and decoding Example 2.3.1 /* 9*/ { 0x25, 6, 1, 16, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }, { 14, 7, 23, 3, 23, 15 } }, /* MAILMARK Royal Mail Mailmark barcode C encoding and decoding Example 2.3.1 */
/* 10*/ { 0x25, 6, 1, 16, { 15, 22, 3, 25, 23, 26, 7, 3, 20, 14, 1, 4, 16, 3, 9, 28 }, { 27, 22, 24, 16, 6, 24 } }, // MAILMARK Royal Mail Mailmark barcode C encoding and decoding Example 2.3.2 /* 10*/ { 0x25, 6, 1, 16, { 15, 22, 3, 25, 23, 26, 7, 3, 20, 14, 1, 4, 16, 3, 9, 28 }, { 27, 22, 24, 16, 6, 24 } }, /* MAILMARK Royal Mail Mailmark barcode C encoding and decoding Example 2.3.2 */
/* 11*/ { 0x25, 7, 1, 19, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }, { 20, 1, 20, 7, 14, 11, 18 } }, // MAILMARK Royal Mail Mailmark barcode L encoding and decoding Example 2.3.1 /* 11*/ { 0x25, 7, 1, 19, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }, { 20, 1, 20, 7, 14, 11, 18 } }, /* MAILMARK Royal Mail Mailmark barcode L encoding and decoding Example 2.3.1 */
/* 12*/ { 0x25, 7, 1, 19, { 0, 8, 21, 10, 29, 1, 29, 21, 2, 24, 15, 2, 19, 1, 4, 15, 11, 4, 16 }, { 19, 7, 9, 8, 6, 16, 16 } }, // MAILMARK Royal Mail Mailmark barcode L encoding and decoding Example 2.3.2 /* 12*/ { 0x25, 7, 1, 19, { 0, 8, 21, 10, 29, 1, 29, 21, 2, 24, 15, 2, 19, 1, 4, 15, 11, 4, 16 }, { 19, 7, 9, 8, 6, 16, 16 } }, /* MAILMARK Royal Mail Mailmark barcode L encoding and decoding Example 2.3.2 */
/* 13*/ { 0x43, 10, 1, 10, { 4, 13, 63, 1, 24, 9, 59, 3, 15, 4 }, { 50, 2, 42, 51, 53, 34, 22, 20, 5, 16 } }, // MAXICODE Annex H Primary /* 13*/ { 0x43, 10, 1, 10, { 4, 13, 63, 1, 24, 9, 59, 3, 15, 4 }, { 50, 2, 42, 51, 53, 34, 22, 20, 5, 16 } }, /* MAXICODE Annex H Primary */
/* 14*/ { 0x43, 20, 1, 42, { 5, 57, 49, 47, 8, 18, 59, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33 }, { 31, 2, 58, 6, 6, 39, 13, 63, 2, 30, 19, 19, 14, 19, 23, 17, 62, 8, 2, 23 } }, // MAXICODE Annex H Secondary odd /* 14*/ { 0x43, 20, 1, 42, { 5, 57, 49, 47, 8, 18, 59, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33 }, { 31, 2, 58, 6, 6, 39, 13, 63, 2, 30, 19, 19, 14, 19, 23, 17, 62, 8, 2, 23 } }, /* MAXICODE Annex H Secondary odd */
/* 15*/ { 0x43, 20, 1, 42, { 47, 40, 57, 3, 1, 19, 41, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33 }, { 1, 15, 22, 28, 39, 17, 60, 5, 35, 35, 4, 8, 0, 32, 51, 45, 63, 53, 61, 14 } }, // MAXICODE Annex H Secondary even /* 15*/ { 0x43, 20, 1, 42, { 47, 40, 57, 3, 1, 19, 41, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33 }, { 1, 15, 22, 28, 39, 17, 60, 5, 35, 35, 4, 8, 0, 32, 51, 45, 63, 53, 61, 14 } }, /* MAXICODE Annex H Secondary even */
/* 16*/ { 0x11d, 10, 0, 16, { 0x10, 0x20, 0x0C, 0x56, 0x61, 0x80, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11 }, { 0xA5, 0x24, 0xD4, 0xC1, 0xED, 0x36, 0xC7, 0x87, 0x2C, 0x55 } }, // QRCODE Annex I.2 /* 16*/ { 0x11d, 10, 0, 16, { 0x10, 0x20, 0x0C, 0x56, 0x61, 0x80, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11 }, { 0xA5, 0x24, 0xD4, 0xC1, 0xED, 0x36, 0xC7, 0x87, 0x2C, 0x55 } }, /* QRCODE Annex I.2 */
/* 17*/ { 0x11d, 5, 0, 5, { 0x40, 0x18, 0xAC, 0xC3, 0x00 }, { 0x86, 0x0D, 0x22, 0xAE, 0x30 } }, // QRCODE Annex I.3 /* 17*/ { 0x11d, 5, 0, 5, { 0x40, 0x18, 0xAC, 0xC3, 0x00 }, { 0x86, 0x0D, 0x22, 0xAE, 0x30 } }, /* QRCODE Annex I.3 */
/* 18*/ { 0x163, 256, 0, 1, { 0xFF }, { 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255 } }, /* 18*/ { 0x163, 256, 0, 1, { 0xFF }, { 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255 } },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -153,13 +154,13 @@ static void test_encoding(int index, int debug) {
rs_t rs; rs_t rs;
unsigned char res[1024]; unsigned char res[1024];
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
rs_init_gf(&rs, data[i].prime_poly); rs_init_gf(&rs, data[i].prime_poly);
rs_init_code(&rs, data[i].nsym, data[i].index); rs_init_code(&rs, data[i].nsym, data[i].index);
rs_encode(&rs, data[i].datalen, data[i].data, res); rs_encode(&rs, data[i].datalen, data[i].data, res);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) {
fprintf(stderr, "res "); for (j = data[i].nsym - 1; j >= 0; j--) fprintf(stderr, "%d, ", res[j]); fprintf(stderr, "\n"); fprintf(stderr, "res "); for (j = data[i].nsym - 1; j >= 0; j--) fprintf(stderr, "%d, ", res[j]); fprintf(stderr, "\n");
fprintf(stderr, "exp "); for (j = 0; j < data[i].nsym; j++) fprintf(stderr, "%d, ", data[i].expected[j]); fprintf(stderr, "\n"); fprintf(stderr, "exp "); for (j = 0; j < data[i].nsym; j++) fprintf(stderr, "%d, ", data[i].expected[j]); fprintf(stderr, "\n");
} }
@ -172,7 +173,8 @@ static void test_encoding(int index, int debug) {
testFinish(); testFinish();
} }
static void test_encoding_uint(int index, int debug) { static void test_encoding_uint(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
unsigned int prime_poly; unsigned int prime_poly;
@ -183,26 +185,26 @@ static void test_encoding_uint(int index, int debug) {
unsigned int expected[256]; unsigned int expected[256];
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { 0x43, 4, 1, 7, { 4, 20, 49, 37, 49, 38, 23 }, { 54, 17, 53, 58 } }, // AUSPOST Australia Post Customer Barcoding Technical Specifications Diagram 10 /* 0*/ { 0x43, 4, 1, 7, { 4, 20, 49, 37, 49, 38, 23 }, { 54, 17, 53, 58 } }, /* AUSPOST Australia Post Customer Barcoding Technical Specifications Diagram 10 */
/* 1*/ { 0x43, 7, 1, 10, { 9, 50, 1, 41, 47, 2, 39, 37, 1, 27 }, { 38, 50, 8, 16, 10, 20, 40 } }, // AZTEC ISO/IEC 24778:2008 Section G.4 /* 1*/ { 0x43, 7, 1, 10, { 9, 50, 1, 41, 47, 2, 39, 37, 1, 27 }, { 38, 50, 8, 16, 10, 20, 40 } }, /* AZTEC ISO/IEC 24778:2008 Section G.4 */
/* 2*/ { 0x13, 5, 1, 2, { 0, 9 }, { 12, 2, 3, 1, 9 } }, // AZTEC ISO/IEC 24778:2008 Section G.4 Mode Message /* 2*/ { 0x13, 5, 1, 2, { 0, 9 }, { 12, 2, 3, 1, 9 } }, /* AZTEC ISO/IEC 24778:2008 Section G.4 Mode Message */
/* 3*/ { 0x12d, 5, 1, 3, { 142, 164, 186 }, { 114, 25, 5, 88, 102 } }, // DATAMATRIX ISO/IEC 16022:2006 Annex O /* 3*/ { 0x12d, 5, 1, 3, { 142, 164, 186 }, { 114, 25, 5, 88, 102 } }, /* DATAMATRIX ISO/IEC 16022:2006 Annex O */
/* 4*/ { 0x89, 25, 1, 25, { 42, 13, 54, 39, 124, 91, 121, 65, 28, 40, 95, 48, 0, 126, 0, 126, 0, 126, 0, 126, 0, 126, 0, 126, 0 }, { 123, 47, 2, 20, 54, 112, 35, 23, 100, 89, 55, 17, 101, 4, 14, 33, 48, 62, 98, 52, 2, 79, 92, 70, 102 } }, // GRIDMATRIX AIMD014 Section 6.8 /* 4*/ { 0x89, 25, 1, 25, { 42, 13, 54, 39, 124, 91, 121, 65, 28, 40, 95, 48, 0, 126, 0, 126, 0, 126, 0, 126, 0, 126, 0, 126, 0 }, { 123, 47, 2, 20, 54, 112, 35, 23, 100, 89, 55, 17, 101, 4, 14, 33, 48, 62, 98, 52, 2, 79, 92, 70, 102 } }, /* GRIDMATRIX AIMD014 Section 6.8 */
/* 5*/ { 0x163, 4, 1, 21, { 0x11, 0xED, 0xC8, 0xC5, 0x40, 0x0F, 0xF4 }, { 0xEB, 0xB4, 0x68, 0x1D } }, // HANXIN ISO/IEC DIS 20830:2019 Annex K.1 /* 5*/ { 0x163, 4, 1, 21, { 0x11, 0xED, 0xC8, 0xC5, 0x40, 0x0F, 0xF4 }, { 0xEB, 0xB4, 0x68, 0x1D } }, /* HANXIN ISO/IEC DIS 20830:2019 Annex K.1 */
/* 6*/ { 0x163, 24, 1, 27, { 0x11, 0xED, 0xC8, 0xC5, 0x40, 0x0F, 0xF4, 0x8A, 0x2C, 0xC3, 0x4E, 0x3D, 0x09, 0x25, 0x9A, 0x7A, 0x29, 0xAB, 0xEA, 0x3E, 0x46, 0x4C, 0x7E, 0x73, 0xE8, 0x6C, 0xC7 }, { 0x08, 0x57, 0x0C, 0xE0, 0x7A, 0xA5, 0xDD, 0xA2, 0x99, 0xCF, 0xA4, 0x82, 0xAD, 0x11, 0xB0, 0x84, 0x74, 0x5D, 0x9A, 0x99, 0x0B, 0xCD, 0x49, 0x77 } }, // HANXIN ISO/IEC DIS 20830:2019 Annex K.2 1st block /* 6*/ { 0x163, 24, 1, 27, { 0x11, 0xED, 0xC8, 0xC5, 0x40, 0x0F, 0xF4, 0x8A, 0x2C, 0xC3, 0x4E, 0x3D, 0x09, 0x25, 0x9A, 0x7A, 0x29, 0xAB, 0xEA, 0x3E, 0x46, 0x4C, 0x7E, 0x73, 0xE8, 0x6C, 0xC7 }, { 0x08, 0x57, 0x0C, 0xE0, 0x7A, 0xA5, 0xDD, 0xA2, 0x99, 0xCF, 0xA4, 0x82, 0xAD, 0x11, 0xB0, 0x84, 0x74, 0x5D, 0x9A, 0x99, 0x0B, 0xCD, 0x49, 0x77 } }, /* HANXIN ISO/IEC DIS 20830:2019 Annex K.2 1st block */
/* 7*/ { 0x163, 24, 1, 27, { 0xE7, 0x3E, 0x33, 0x29, 0xE8, 0xFC, }, { 0xA2, 0xA7, 0x68, 0x8A, 0x5F, 0xE6, 0xAA, 0x11, 0xA6, 0x69, 0x4A, 0xCF, 0xCF, 0x20, 0x5D, 0x00, 0x1B, 0x79, 0xA1, 0xFE, 0xB7, 0x94, 0x03, 0x9B } }, // HANXIN ISO/IEC DIS 20830:2019 Annex K.2 2nd block /* 7*/ { 0x163, 24, 1, 27, { 0xE7, 0x3E, 0x33, 0x29, 0xE8, 0xFC, }, { 0xA2, 0xA7, 0x68, 0x8A, 0x5F, 0xE6, 0xAA, 0x11, 0xA6, 0x69, 0x4A, 0xCF, 0xCF, 0x20, 0x5D, 0x00, 0x1B, 0x79, 0xA1, 0xFE, 0xB7, 0x94, 0x03, 0x9B } }, /* HANXIN ISO/IEC DIS 20830:2019 Annex K.2 2nd block */
/* 8*/ { 0x163, 24, 1, 29, { 0x00 }, { 0x00 } }, // HANXIN ISO/IEC DIS 20830:2019 Annex K.2 3rd block /* 8*/ { 0x163, 24, 1, 29, { 0x00 }, { 0x00 } }, /* HANXIN ISO/IEC DIS 20830:2019 Annex K.2 3rd block */
/* 9*/ { 0x25, 6, 1, 16, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }, { 14, 7, 23, 3, 23, 15 } }, // MAILMARK Royal Mail Mailmark barcode C encoding and decoding Example 2.3.1 /* 9*/ { 0x25, 6, 1, 16, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }, { 14, 7, 23, 3, 23, 15 } }, /* MAILMARK Royal Mail Mailmark barcode C encoding and decoding Example 2.3.1 */
/* 10*/ { 0x25, 6, 1, 16, { 15, 22, 3, 25, 23, 26, 7, 3, 20, 14, 1, 4, 16, 3, 9, 28 }, { 27, 22, 24, 16, 6, 24 } }, // MAILMARK Royal Mail Mailmark barcode C encoding and decoding Example 2.3.2 /* 10*/ { 0x25, 6, 1, 16, { 15, 22, 3, 25, 23, 26, 7, 3, 20, 14, 1, 4, 16, 3, 9, 28 }, { 27, 22, 24, 16, 6, 24 } }, /* MAILMARK Royal Mail Mailmark barcode C encoding and decoding Example 2.3.2 */
/* 11*/ { 0x25, 7, 1, 19, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }, { 20, 1, 20, 7, 14, 11, 18 } }, // MAILMARK Royal Mail Mailmark barcode L encoding and decoding Example 2.3.1 /* 11*/ { 0x25, 7, 1, 19, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }, { 20, 1, 20, 7, 14, 11, 18 } }, /* MAILMARK Royal Mail Mailmark barcode L encoding and decoding Example 2.3.1 */
/* 12*/ { 0x25, 7, 1, 19, { 0, 8, 21, 10, 29, 1, 29, 21, 2, 24, 15, 2, 19, 1, 4, 15, 11, 4, 16 }, { 19, 7, 9, 8, 6, 16, 16 } }, // MAILMARK Royal Mail Mailmark barcode L encoding and decoding Example 2.3.2 /* 12*/ { 0x25, 7, 1, 19, { 0, 8, 21, 10, 29, 1, 29, 21, 2, 24, 15, 2, 19, 1, 4, 15, 11, 4, 16 }, { 19, 7, 9, 8, 6, 16, 16 } }, /* MAILMARK Royal Mail Mailmark barcode L encoding and decoding Example 2.3.2 */
/* 13*/ { 0x43, 10, 1, 10, { 4, 13, 63, 1, 24, 9, 59, 3, 15, 4 }, { 50, 2, 42, 51, 53, 34, 22, 20, 5, 16 } }, // MAXICODE Annex H Primary /* 13*/ { 0x43, 10, 1, 10, { 4, 13, 63, 1, 24, 9, 59, 3, 15, 4 }, { 50, 2, 42, 51, 53, 34, 22, 20, 5, 16 } }, /* MAXICODE Annex H Primary */
/* 14*/ { 0x43, 20, 1, 42, { 5, 57, 49, 47, 8, 18, 59, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33 }, { 31, 2, 58, 6, 6, 39, 13, 63, 2, 30, 19, 19, 14, 19, 23, 17, 62, 8, 2, 23 } }, // MAXICODE Annex H Secondary odd /* 14*/ { 0x43, 20, 1, 42, { 5, 57, 49, 47, 8, 18, 59, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33 }, { 31, 2, 58, 6, 6, 39, 13, 63, 2, 30, 19, 19, 14, 19, 23, 17, 62, 8, 2, 23 } }, /* MAXICODE Annex H Secondary odd */
/* 15*/ { 0x43, 20, 1, 42, { 47, 40, 57, 3, 1, 19, 41, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33 }, { 1, 15, 22, 28, 39, 17, 60, 5, 35, 35, 4, 8, 0, 32, 51, 45, 63, 53, 61, 14 } }, // MAXICODE Annex H Secondary even /* 15*/ { 0x43, 20, 1, 42, { 47, 40, 57, 3, 1, 19, 41, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33 }, { 1, 15, 22, 28, 39, 17, 60, 5, 35, 35, 4, 8, 0, 32, 51, 45, 63, 53, 61, 14 } }, /* MAXICODE Annex H Secondary even */
/* 16*/ { 0x11d, 10, 0, 16, { 0x10, 0x20, 0x0C, 0x56, 0x61, 0x80, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11 }, { 0xA5, 0x24, 0xD4, 0xC1, 0xED, 0x36, 0xC7, 0x87, 0x2C, 0x55 } }, // QRCODE Annex I.2 /* 16*/ { 0x11d, 10, 0, 16, { 0x10, 0x20, 0x0C, 0x56, 0x61, 0x80, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11 }, { 0xA5, 0x24, 0xD4, 0xC1, 0xED, 0x36, 0xC7, 0x87, 0x2C, 0x55 } }, /* QRCODE Annex I.2 */
/* 17*/ { 0x11d, 5, 0, 5, { 0x40, 0x18, 0xAC, 0xC3, 0x00 }, { 0x86, 0x0D, 0x22, 0xAE, 0x30 } }, // QRCODE Annex I.3 /* 17*/ { 0x11d, 5, 0, 5, { 0x40, 0x18, 0xAC, 0xC3, 0x00 }, { 0x86, 0x0D, 0x22, 0xAE, 0x30 } }, /* QRCODE Annex I.3 */
/* 18*/ { 0x163, 256, 0, 1, { 0xFF }, { 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255 } }, /* 18*/ { 0x163, 256, 0, 1, { 0xFF }, { 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255 } },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -215,13 +217,13 @@ static void test_encoding_uint(int index, int debug) {
rs_t rs; rs_t rs;
unsigned int res[1024]; unsigned int res[1024];
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
rs_init_gf(&rs, data[i].prime_poly); rs_init_gf(&rs, data[i].prime_poly);
rs_init_code(&rs, data[i].nsym, data[i].index); rs_init_code(&rs, data[i].nsym, data[i].index);
rs_encode_uint(&rs, data[i].datalen, data[i].data, res); rs_encode_uint(&rs, data[i].datalen, data[i].data, res);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) {
fprintf(stderr, "res "); for (j = data[i].nsym - 1; j >= 0; j--) fprintf(stderr, "%d, ", res[j]); fprintf(stderr, "\n"); fprintf(stderr, "res "); for (j = data[i].nsym - 1; j >= 0; j--) fprintf(stderr, "%d, ", res[j]); fprintf(stderr, "\n");
fprintf(stderr, "exp "); for (j = 0; j < data[i].nsym; j++) fprintf(stderr, "%d, ", data[i].expected[j]); fprintf(stderr, "\n"); fprintf(stderr, "exp "); for (j = 0; j < data[i].nsym; j++) fprintf(stderr, "%d, ", data[i].expected[j]); fprintf(stderr, "\n");
} }
@ -234,7 +236,8 @@ static void test_encoding_uint(int index, int debug) {
testFinish(); testFinish();
} }
static void test_uint_encoding(int index, int debug) { static void test_uint_encoding(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
unsigned int prime_poly; unsigned int prime_poly;
@ -246,7 +249,7 @@ static void test_uint_encoding(int index, int debug) {
unsigned int expected[256]; unsigned int expected[256];
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { 0x409, 1023, 4, 1, 7, { 0x3FF, 0x000, 0x100, 0x1FF, 0x3FF, 0x000, 0x123 }, { 229, 153, 993, 674 } }, /* 0*/ { 0x409, 1023, 4, 1, 7, { 0x3FF, 0x000, 0x100, 0x1FF, 0x3FF, 0x000, 0x123 }, { 229, 153, 993, 674 } },
/* 1*/ { 0x1069, 4095, 4, 1, 7, { 0xFFF, 0x000, 0x700, 0x7FF, 0xFFF, 0x000, 0x123 }, { 3472, 2350, 3494, 575 } }, /* 1*/ { 0x1069, 4095, 4, 1, 7, { 0xFFF, 0x000, 0x700, 0x7FF, 0xFFF, 0x000, 0x123 }, { 3472, 2350, 3494, 575 } },
@ -263,14 +266,14 @@ static void test_uint_encoding(int index, int debug) {
rs_uint_t rs_uint; rs_uint_t rs_uint;
unsigned int res[1024]; unsigned int res[1024];
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
assert_nonzero(rs_uint_init_gf(&rs_uint, data[i].prime_poly, data[i].logmod), "i:%d rs_uint_init_gf() == 0\n", i); assert_nonzero(rs_uint_init_gf(&rs_uint, data[i].prime_poly, data[i].logmod), "i:%d rs_uint_init_gf() == 0\n", i);
rs_uint_init_code(&rs_uint, data[i].nsym, data[i].index); rs_uint_init_code(&rs_uint, data[i].nsym, data[i].index);
rs_uint_encode(&rs_uint, data[i].datalen, data[i].data, res); rs_uint_encode(&rs_uint, data[i].datalen, data[i].data, res);
rs_uint_free(&rs_uint); rs_uint_free(&rs_uint);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) {
fprintf(stderr, "res "); for (j = data[i].nsym - 1; j >= 0; j--) fprintf(stderr, "%d, ", res[j]); fprintf(stderr, "\n"); fprintf(stderr, "res "); for (j = data[i].nsym - 1; j >= 0; j--) fprintf(stderr, "%d, ", res[j]); fprintf(stderr, "\n");
fprintf(stderr, "exp "); for (j = 0; j < data[i].nsym; j++) fprintf(stderr, "%d, ", data[i].expected[j]); fprintf(stderr, "\n"); fprintf(stderr, "exp "); for (j = 0; j < data[i].nsym; j++) fprintf(stderr, "%d, ", data[i].expected[j]); fprintf(stderr, "\n");
} }
@ -301,11 +304,11 @@ static void test_uint_encoding(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_generate", test_generate, 0, 1, 0 }, { "test_generate", test_generate },
{ "test_encoding", test_encoding, 1, 0, 1 }, { "test_encoding", test_encoding },
{ "test_encoding_uint", test_encoding_uint, 1, 0, 1 }, { "test_encoding_uint", test_encoding_uint },
{ "test_uint_encoding", test_uint_encoding, 1, 0, 1 }, { "test_uint_encoding", test_uint_encoding },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
@ -314,3 +317,5 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -31,7 +31,8 @@
#include "testcommon.h" #include "testcommon.h"
static void test_binary_div_modulo_divisor(int index, int generate, int debug) { static void test_binary_div_modulo_divisor(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -133,7 +134,7 @@ static void test_binary_div_modulo_divisor(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -149,7 +150,7 @@ static void test_binary_div_modulo_divisor(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (const unsigned char *) text, length); ret = ZBarcode_Encode(symbol, (const unsigned char *) text, length);
assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 (%s)\n", i, ret, symbol->errtxt); assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, \"%s\", %.0f, %.0f, %d, %d, ", printf(" /*%3d*/ { %s, \"%s\", %.0f, %.0f, %d, %d, ",
i, testUtilBarcodeName(data[i].symbology), data[i].data, data[i].w, data[i].h, symbol->rows, symbol->width); i, testUtilBarcodeName(data[i].symbology), data[i].data, data[i].w, data[i].h, symbol->rows, symbol->width);
testUtilModulesPrintRow(symbol, symbol->rows - 1, "", " },\n"); testUtilModulesPrintRow(symbol, symbol->rows - 1, "", " },\n");
@ -193,7 +194,8 @@ static void test_binary_div_modulo_divisor(int index, int generate, int debug) {
} }
/* Replicate examples from GS1 General Specifications 21.0.1 and ISO/IEC 24724:2011 */ /* Replicate examples from GS1 General Specifications 21.0.1 and ISO/IEC 24724:2011 */
static void test_examples(int index, int generate, int debug) { static void test_examples(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -874,8 +876,7 @@ static void test_examples(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -885,7 +886,7 @@ static void test_examples(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, %d, \"%s\", %d, %d, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %s, %d, %d, \"%s\", %d, %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(symbol->symbology), testUtilInputModeName(data[i].input_mode), i, testUtilBarcodeName(symbol->symbology), testUtilInputModeName(data[i].input_mode),
data[i].option_2, data[i].option_3, data[i].option_2, data[i].option_3,
@ -933,7 +934,8 @@ static void test_examples(int index, int generate, int debug) {
} }
/* Test general-purpose data compaction */ /* Test general-purpose data compaction */
static void test_general_field(int index, int generate, int debug) { static void test_general_field(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1201,7 +1203,7 @@ static void test_general_field(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1211,7 +1213,7 @@ static void test_general_field(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].data, length);
assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 (%s)\n", i, ret, symbol->errtxt); assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%2d*/ { %s, \"%s\", %d, %d, %d, \"%s\",\n", printf(" /*%2d*/ { %s, \"%s\", %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(symbol->symbology), data[i].data, ret, symbol->rows, symbol->width, data[i].comment); i, testUtilBarcodeName(symbol->symbology), data[i].data, ret, symbol->rows, symbol->width, data[i].comment);
testUtilModulesPrint(symbol, " ", "\n"); testUtilModulesPrint(symbol, " ", "\n");
@ -1232,7 +1234,8 @@ static void test_general_field(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_binary_buffer_size(int index, int generate, int debug) { static void test_binary_buffer_size(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -1264,7 +1267,7 @@ static void test_binary_buffer_size(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1274,7 +1277,7 @@ static void test_binary_buffer_size(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, \"%s\", %s, %d, %d, \"%s\" },\n", printf(" /*%3d*/ { %s, \"%s\", %s, %d, %d, \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].data, testUtilErrorName(ret), symbol->rows, symbol->width, data[i].comment); i, testUtilInputModeName(data[i].input_mode), data[i].data, testUtilErrorName(ret), symbol->rows, symbol->width, data[i].comment);
} else { } else {
@ -1288,7 +1291,8 @@ static void test_binary_buffer_size(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_hrt(int index, int debug) { static void test_hrt(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1318,7 +1322,7 @@ static void test_hrt(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1336,7 +1340,8 @@ static void test_hrt(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1471,7 +1476,7 @@ static void test_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1495,13 +1500,13 @@ static void test_input(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_binary_div_modulo_divisor", test_binary_div_modulo_divisor, 1, 1, 1 }, { "test_binary_div_modulo_divisor", test_binary_div_modulo_divisor },
{ "test_examples", test_examples, 1, 1, 1 }, { "test_examples", test_examples },
{ "test_general_field", test_general_field, 1, 1, 1 }, { "test_general_field", test_general_field },
{ "test_binary_buffer_size", test_binary_buffer_size, 1, 1, 1 }, { "test_binary_buffer_size", test_binary_buffer_size },
{ "test_hrt", test_hrt, 1, 0, 1 }, { "test_hrt", test_hrt },
{ "test_input", test_input, 1, 0, 1 }, { "test_input", test_input },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,19 +27,22 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
#include "test_sjis_tab.h" #include "test_sjis_tab.h"
#include "../eci.h" #include "../eci.h"
/* For local "private" testing using previous libiconv adaptation, not included for licensing reasons */ /* For local "private" testing using previous libiconv adaptation, not included for licensing reasons */
//#define TEST_JUST_SAY_GNO /* #define TEST_JUST_SAY_GNO */
#ifdef TEST_JUST_SAY_GNO #ifdef TEST_JUST_SAY_GNO
#include "../just_say_gno/sjis_gnu.c" #include "../just_say_gno/sjis_gnu.c"
#endif #endif
INTERNAL int u_sjis_int_test(const unsigned int u, unsigned int *dest); INTERNAL int u_sjis_int_test(const unsigned int u, unsigned int *dest);
// As control convert to Shift JIS using simple table generated from https://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/JIS/SHIFTJIS.TXT plus simple processing /* As control convert to Shift JIS using simple table generated from
https://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/JIS/SHIFTJIS.TXT plus simple processing
*/
static int u_sjis_int2(unsigned int u, unsigned int *dest) { static int u_sjis_int2(unsigned int u, unsigned int *dest) {
int tab_length, start_i, end_i; int tab_length, start_i, end_i;
int i; int i;
@ -47,11 +50,11 @@ static int u_sjis_int2(unsigned int u, unsigned int *dest) {
*dest = u; *dest = u;
return 1; return 1;
} }
// Shortcut /* Shortcut */
if ((u > 0x00F7 && u < 0x0391) || (u > 0x0451 && u < 0x2010) || (u > 0x9FA0 && u < 0xE000) || (u > 0xE757 && u < 0xFF01) || u > 0xFFE5) { if ((u > 0x00F7 && u < 0x0391) || (u > 0x0451 && u < 0x2010) || (u > 0x9FA0 && u < 0xE000) || (u > 0xE757 && u < 0xFF01) || u > 0xFFE5) {
return 0; return 0;
} }
if (u >= 0xE000 && u <= 0xE757) { // PUA mappings, not in SHIFTJIS.TXT if (u >= 0xE000 && u <= 0xE757) { /* PUA mappings, not in SHIFTJIS.TXT */
if (u <= 0xE0BB) { if (u <= 0xE0BB) {
*dest = u - 0xE000 + 0xF040 + (u >= 0xE000 + 0x3F); *dest = u - 0xE000 + 0xF040 + (u >= 0xE000 + 0x3F);
} else if (u <= 0xE177) { } else if (u <= 0xE177) {
@ -96,7 +99,8 @@ static int u_sjis_int2(unsigned int u, unsigned int *dest) {
#define TEST_INT_PERF_ITERATIONS 100 #define TEST_INT_PERF_ITERATIONS 100
#endif #endif
static void test_u_sjis_int(int debug) { static void test_u_sjis_int(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
int ret, ret2; int ret, ret2;
unsigned int val, val2; unsigned int val, val2;
@ -119,9 +123,11 @@ static void test_u_sjis_int(int debug) {
#endif #endif
for (i = 0; i < 0xFFFE; i++) { for (i = 0; i < 0xFFFE; i++) {
if (i >= 0xD800 && i <= 0xDFFF) { // UTF-16 surrogates if (i >= 0xD800 && i <= 0xDFFF) { /* UTF-16 surrogates */
continue; continue;
} }
if (testContinue(p_ctx, i)) continue;
val = val2 = 0; val = val2 = 0;
ret = u_sjis_int_test(i, &val); ret = u_sjis_int_test(i, &val);
ret2 = u_sjis_int2(i, &val2); ret2 = u_sjis_int2(i, &val2);
@ -130,7 +136,7 @@ static void test_u_sjis_int(int debug) {
assert_equal(val, val2, "i:%d 0x%04X val 0x%04X != val2 0x%04X\n", (int) i, i, val, val2); 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 #ifdef TEST_JUST_SAY_GNO
if (i != 0xFF3C) { // Full-width reverse solidus duplicate no longer mapped to ignore if (i != 0xFF3C) { /* Full-width reverse solidus duplicate no longer mapped to ignore */
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
val2 = 0; val2 = 0;
ret2 = sjis_wctomb_zint(&val2, i); ret2 = sjis_wctomb_zint(&val2, i);
@ -166,7 +172,7 @@ static void test_u_sjis_int(int debug) {
testFinish(); testFinish();
} }
static void test_sjis_utf8(int index) { static void test_sjis_utf8(const testCtx *const p_ctx) {
struct item { struct item {
char *data; char *data;
@ -176,18 +182,20 @@ static void test_sjis_utf8(int index) {
unsigned int expected_jisdata[20]; unsigned int expected_jisdata[20];
char *comment; char *comment;
}; };
// é 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 /*
// β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in Shift JIS 0x83C0, UTF-8 CEB2 é 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
// Ж U+0416 in ISO 8859-5 Cyrillic (but not other ISO 8859), Win 1251, in Shift JIS 0x8447, UTF-8 D096 β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in Shift JIS 0x83C0, UTF-8 CEB2
// ¥ 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 Ж U+0416 in ISO 8859-5 Cyrillic (but not other ISO 8859), Win 1251, in Shift JIS 0x8447, UTF-8 D096
// ・ U+FF65 half-width katakana, not in ISO/Win, in Shift JIS single-byte 0xA5 (\245), UTF-8 EFBDA5 ¥ 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
// ソ U+FF7F half-width katakana, not in ISO/Win, in Shift JIS single-byte 0xBF (\277), UTF-8 EFBDBF U+FF65 half-width katakana, not in ISO/Win, in Shift JIS single-byte 0xA5 (\245), UTF-8 EFBDA5
// ‾ U+203E overline, not in ISO/Win, in Shift JIS single-byte 0x7E (\176) (tilde), UTF-8 E280BE ソ U+FF7F half-width katakana, not in ISO/Win, in Shift JIS single-byte 0xBF (\277), UTF-8 EFBDBF
// U+FF3C full-width reverse solidus, in Shift JIS 0x815F, was duplicate of mapping of U+005C, UTF-8 EFBCBC U+203E overline, not in ISO/Win, in Shift JIS single-byte 0x7E (\176) (tilde), UTF-8 E280BE
// 点 U+70B9 kanji, in Shift JIS 0x935F (\223\137), UTF-8 E782B9 U+FF3C full-width reverse solidus, in Shift JIS 0x815F, was duplicate of mapping of U+005C, UTF-8 EFBCBC
// 茗 U+8317 kanji, in Shift JIS 0xE4AA (\344\252), UTF-8 E88C97 U+70B9 kanji, in Shift JIS 0x935F (\223\137), UTF-8 E782B9
// テ U+30C6 katakana, in Shift JIS 0x8365 (\203\145), UTF-8 E38386 U+8317 kanji, in Shift JIS 0xE4AA (\344\252), UTF-8 E88C97
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) U+30C6 katakana, in Shift JIS 0x8365 (\203\145), UTF-8 E38386
*/
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "é", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "" }, /* 0*/ { "é", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "" },
/* 1*/ { "~", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "" }, /* 1*/ { "~", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "" },
@ -208,7 +216,7 @@ static void test_sjis_utf8(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int ret_length; int ret_length;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret_length = length; ret_length = length;
@ -227,7 +235,7 @@ static void test_sjis_utf8(int index) {
testFinish(); testFinish();
} }
static void test_sjis_utf8_to_eci(int index) { static void test_sjis_utf8_to_eci(const testCtx *const p_ctx) {
struct item { struct item {
int eci; int eci;
@ -239,16 +247,18 @@ static void test_sjis_utf8_to_eci(int index) {
unsigned int expected_jisdata[20]; unsigned int expected_jisdata[20];
char *comment; char *comment;
}; };
// é U+00E9 in ISO 8859-1 0xE9, Win 1250 plus other Win, in QR Kanji mode first byte range 0x81..9F, 0xE0..EB /*
// β U+03B2 in ISO 8859-7 Greek 0xE2 (but not other ISO 8859 or Win page) é U+00E9 in ISO 8859-1 0xE9, Win 1250 plus other Win, in QR Kanji mode first byte range 0x81..9F, 0xE0..EB
// ¥ U+00A5 in ISO 8859-1 0xA5, outside first byte range 0x81..9F, 0xE0..EB β U+03B2 in ISO 8859-7 Greek 0xE2 (but not other ISO 8859 or Win page)
// ú U+00FA in ISO 8859-1 0xFA, outside first byte range ¥ U+00A5 in ISO 8859-1 0xA5, outside first byte range 0x81..9F, 0xE0..EB
// à U+00EO in ISO 8859-1 0xE0, in first byte range ú U+00FA in ISO 8859-1 0xFA, outside first byte range
// ë U+00EB in ISO 8859-1 0xEB, in first byte range à U+00EO in ISO 8859-1 0xE0, in first byte range
// ì U+00EC in ISO 8859-1 0xEC, outside first byte range ë U+00EB in ISO 8859-1 0xEB, in first byte range
// µ U+00B5 in ISO 8859-1 0xB5, outside first byte range ì U+00EC in ISO 8859-1 0xEC, outside first byte range
// À U+00C0 in ISO 8859-1 0xC0, outside first byte range and 0xEBxx second byte range µ U+00B5 in ISO 8859-1 0xB5, outside first byte range
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) À U+00C0 in ISO 8859-1 0xC0, outside first byte range and 0xEBxx second byte range
*/
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { 3, 0, "é", -1, 0, 1, { 0xE9 }, "" }, /* 0*/ { 3, 0, "é", -1, 0, 1, { 0xE9 }, "" },
/* 1*/ { 3, 1, "é", -1, 0, 1, { 0xE9 }, "" }, /* 1*/ { 3, 1, "é", -1, 0, 1, { 0xE9 }, "" },
@ -298,7 +308,7 @@ static void test_sjis_utf8_to_eci(int index) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int ret_length; int ret_length;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret_length = length; ret_length = length;
@ -317,7 +327,7 @@ static void test_sjis_utf8_to_eci(int index) {
testFinish(); testFinish();
} }
static void test_sjis_cpy(int index) { static void test_sjis_cpy(const testCtx *const p_ctx) {
struct item { struct item {
int full_multibyte; int full_multibyte;
@ -328,7 +338,7 @@ static void test_sjis_cpy(int index) {
unsigned int expected_jisdata[20]; unsigned int expected_jisdata[20];
char *comment; char *comment;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { 0, "\351", -1, 0, 1, { 0xE9 }, "Not full multibyte" }, /* 0*/ { 0, "\351", -1, 0, 1, { 0xE9 }, "Not full multibyte" },
/* 1*/ { 1, "\351", -1, 0, 1, { 0xE9 }, "In QR Kanji mode first-byte range but only one byte" }, /* 1*/ { 1, "\351", -1, 0, 1, { 0xE9 }, "In QR Kanji mode first-byte range but only one byte" },
@ -351,7 +361,7 @@ static void test_sjis_cpy(int index) {
int ret_length; int ret_length;
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret_length = length; ret_length = length;
@ -369,8 +379,9 @@ static void test_sjis_cpy(int index) {
#define TEST_PERF_ITER_MILLES 100 #define TEST_PERF_ITER_MILLES 100
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000) #define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
// Not a real test, just performance indicator /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -412,7 +423,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
length = (int) strlen(data[i].data); length = (int) strlen(data[i].data);
@ -439,7 +450,7 @@ static void test_perf(int index, int debug) {
total += diff; total += diff;
total_gno += diff_gno; total_gno += diff_gno;
} }
if (index == -1) { if (p_ctx->index == -1) {
printf("%*s: new % 8gms, gno % 8gms ratio %g\n", comment_max, "totals", printf("%*s: new % 8gms, gno % 8gms ratio %g\n", comment_max, "totals",
TEST_PERF_TIME(total), TEST_PERF_TIME(total_gno), TEST_PERF_RATIO(total, total_gno)); TEST_PERF_TIME(total), TEST_PERF_TIME(total_gno), TEST_PERF_RATIO(total, total_gno));
} }
@ -447,12 +458,12 @@ static void test_perf(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_u_sjis_int", test_u_sjis_int, 0, 0, 1 }, { "test_u_sjis_int", test_u_sjis_int },
{ "test_sjis_utf8", test_sjis_utf8, 1, 0, 0 }, { "test_sjis_utf8", test_sjis_utf8 },
{ "test_sjis_utf8_to_eci", test_sjis_utf8_to_eci, 1, 0, 0 }, { "test_sjis_utf8_to_eci", test_sjis_utf8_to_eci },
{ "test_sjis_cpy", test_sjis_cpy, 1, 0, 0 }, { "test_sjis_cpy", test_sjis_cpy },
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -32,7 +32,8 @@
#include "testcommon.h" #include "testcommon.h"
#include <sys/stat.h> #include <sys/stat.h>
static void test_print(int index, int generate, int debug) { static void test_print(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -124,7 +125,7 @@ static void test_print(int index, int generate, int debug) {
testStart("test_print"); testStart("test_print");
if (generate) { if (p_ctx->generate) {
char data_dir_path[1024]; char data_dir_path[1024];
have_libreoffice = testUtilHaveLibreOffice(); have_libreoffice = testUtilHaveLibreOffice();
@ -140,8 +141,7 @@ static void test_print(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int text_length; int text_length;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i); /* ZINT_DEBUG_TEST_PRINT 16 */
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -186,7 +186,7 @@ static void test_print(int index, int generate, int debug) {
assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i); assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, %s, %d, %d, %d, %d, %d, %d, %.8g, \"%s\", \"%s\", %d, \"%s\", \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %s, %d, %s, %d, %d, %d, %d, %d, %d, %.8g, \"%s\", \"%s\", %d, \"%s\", \"%s\", \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].border_width, i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].border_width,
testUtilOutputOptionsName(data[i].output_options), data[i].whitespace_width, data[i].whitespace_height, data[i].show_hrt, testUtilOutputOptionsName(data[i].output_options), data[i].whitespace_width, data[i].whitespace_height, data[i].show_hrt,
@ -219,11 +219,13 @@ static void test_print(int index, int generate, int debug) {
INTERNAL int svg_plot(struct zint_symbol *symbol, int rotate_angle); INTERNAL int svg_plot(struct zint_symbol *symbol, int rotate_angle);
static void test_outfile(void) { static void test_outfile(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol symbol = {0}; struct zint_symbol symbol = {0};
struct zint_vector vector = {0}; struct zint_vector vector = {0};
(void)p_ctx;
testStart("test_outfile"); testStart("test_outfile");
symbol.symbology = BARCODE_CODE128; symbol.symbology = BARCODE_CODE128;
@ -249,9 +251,9 @@ static void test_outfile(void) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_print", test_print, 1, 1, 1 }, { "test_print", test_print },
{ "test_outfile", test_outfile, 0, 0, 0 }, { "test_outfile", test_outfile },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -31,7 +31,8 @@
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -58,7 +59,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -82,7 +83,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_hrt(int index, int debug) { static void test_hrt(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -110,7 +112,7 @@ static void test_hrt(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -128,7 +130,8 @@ static void test_hrt(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -158,7 +161,7 @@ static void test_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -183,7 +186,8 @@ static void test_input(int index, int debug) {
https://telepen.co.uk/wp-content/uploads/2018/10/Barcode-Symbology-information-and-History.pdf */ https://telepen.co.uk/wp-content/uploads/2018/10/Barcode-Symbology-information-and-History.pdf */
/* E2326U: SB Telepen Barcode Fonts Guide Issue 2 (Apr 2009) /* E2326U: SB Telepen Barcode Fonts Guide Issue 2 (Apr 2009)
https://telepen.co.uk/wp-content/uploads/2018/09/SB-Telepen-Barcode-Fonts-V2.pdf */ https://telepen.co.uk/wp-content/uploads/2018/09/SB-Telepen-Barcode-Fonts-V2.pdf */
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -242,7 +246,7 @@ static void test_encode(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -252,7 +256,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, \"%s\", %d, %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, \"%s\", %d, %s, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length, i, testUtilBarcodeName(data[i].symbology), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length,
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
@ -286,7 +290,8 @@ static void test_encode(int index, int generate, int debug) {
} }
/* #181 Nico Gunkel OSS-Fuzz */ /* #181 Nico Gunkel OSS-Fuzz */
static void test_fuzz(int index, int debug) { static void test_fuzz(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -314,7 +319,7 @@ static void test_fuzz(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -370,11 +375,11 @@ static const char TeleTable[128][16] = {
}; };
/* Dummy to generate lengths table */ /* Dummy to generate lengths table */
static void test_generate_lens(int generate) { static void test_generate_lens(const testCtx *const p_ctx) {
int i; int i;
if (!generate) { if (!p_ctx->generate) {
return; return;
} }
@ -391,13 +396,13 @@ static void test_generate_lens(int generate) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_hrt", test_hrt, 1, 0, 1 }, { "test_hrt", test_hrt },
{ "test_input", test_input, 1, 0, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_fuzz", test_fuzz, 1, 0, 1 }, { "test_fuzz", test_fuzz },
{ "test_generate_lens", test_generate_lens, 0, 1, 0 }, { "test_generate_lens", test_generate_lens },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -1,6 +1,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2020-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -27,25 +27,26 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
#include <sys/stat.h> #include <sys/stat.h>
INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf); INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf);
// For overview when debugging: ./test_tiff -f pixel_plot -d 5 /* For overview when debugging: ./test_tiff -f pixel_plot -d 5 */
static void test_pixel_plot(int index, int debug) { static void test_pixel_plot(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int width; int width;
int height; int height;
char *pattern; char *pattern;
int repeat; int repeat;
int no_identify; // identify fails for some valid TIFFs (eg. RGB with LZW and large rows) int no_identify; /* identify fails for some valid TIFFs (eg. RGB with LZW and large rows) */
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { 1, 1, "1", 0, 0, 0 }, /* 0*/ { 1, 1, "1", 0, 0, 0 },
/* 1*/ { 2, 1, "11", 0, 0, 0 }, /* 1*/ { 2, 1, "11", 0, 0, 0 },
@ -63,28 +64,28 @@ static void test_pixel_plot(int index, int debug) {
/* 13*/ { 3, 3, "101010101", 0, 0, 0 }, /* 13*/ { 3, 3, "101010101", 0, 0, 0 },
/* 14*/ { 4, 3, "10", 1, 0, 0 }, /* 14*/ { 4, 3, "10", 1, 0, 0 },
/* 15*/ { 3, 4, "10", 1, 0, 0 }, /* 15*/ { 3, 4, "10", 1, 0, 0 },
/* 16*/ { 45, 44, "10", 1, 0, 0 }, // Strip Count 1, Rows Per Strip 44 (45 * 44 * 4 == 7920) /* 16*/ { 45, 44, "10", 1, 0, 0 }, /* Strip Count 1, Rows Per Strip 44 (45 * 44 * 4 == 7920) */
/* 17*/ { 45, 45, "10", 1, 0, 0 }, // Strip Count 1, Rows Per Strip 45 (45 * 45 * 4 == 8100) /* 17*/ { 45, 45, "10", 1, 0, 0 }, /* Strip Count 1, Rows Per Strip 45 (45 * 45 * 4 == 8100) */
/* 18*/ { 46, 45, "10", 1, 0, 0 }, // Strip Count 2, Rows Per Strip 44 (46 * 45 * 4 == 8280) /* 18*/ { 46, 45, "10", 1, 0, 0 }, /* Strip Count 2, Rows Per Strip 44 (46 * 45 * 4 == 8280) */
/* 19*/ { 46, 46, "10", 1, 0, 0 }, // Strip Count 2, Rows Per Strip 44 /* 19*/ { 46, 46, "10", 1, 0, 0 }, /* Strip Count 2, Rows Per Strip 44 */
/* 20*/ { 2048, 1, "10", 1, 1, 0 }, // Strip Count 1, Rows Per Strip 1 (2048 * 4 == 8192) /* 20*/ { 2048, 1, "10", 1, 1, 0 }, /* Strip Count 1, Rows Per Strip 1 (2048 * 4 == 8192) */
/* 21*/ { 1, 2048, "10", 1, 0, 0 }, // Strip Count 1, Rows Per Strip 2048 /* 21*/ { 1, 2048, "10", 1, 0, 0 }, /* Strip Count 1, Rows Per Strip 2048 */
/* 22*/ { 2048, 2, "10", 1, 1, 0 }, // Strip Count 2, Rows Per Strip 1 /* 22*/ { 2048, 2, "10", 1, 1, 0 }, /* Strip Count 2, Rows Per Strip 1 */
/* 23*/ { 2, 2048, "10", 1, 0, 0 }, // Strip Count 2, Rows Per Strip 1024 (2 * 1024 * 4 == 8192) /* 23*/ { 2, 2048, "10", 1, 0, 0 }, /* Strip Count 2, Rows Per Strip 1024 (2 * 1024 * 4 == 8192) */
/* 24*/ { 2048, 3, "10", 1, 1, 0 }, // Strip Count 3, Rows Per Strip 1 /* 24*/ { 2048, 3, "10", 1, 1, 0 }, /* Strip Count 3, Rows Per Strip 1 */
/* 25*/ { 3, 2048, "10", 1, 0, 0 }, // Strip Count 4, Rows Per Strip 682 ((3 * 682 + 2) * 4 == 8192) /* 25*/ { 3, 2048, "10", 1, 0, 0 }, /* Strip Count 4, Rows Per Strip 682 ((3 * 682 + 2) * 4 == 8192) */
/* 26*/ { 2049, 4, "10", 1, 1, 0 }, // Strip Count 4, Rows Per Strip 1 (2049 * 1 * 4 == 8196) - large rows in 1 strip, even if > 8192 /* 26*/ { 2049, 4, "10", 1, 1, 0 }, /* Strip Count 4, Rows Per Strip 1 (2049 * 1 * 4 == 8196) - large rows in 1 strip, even if > 8192 */
/* 27*/ { 4, 2049, "10", 1, 0, 0 }, // Strip Count 5, Rows Per Strip 512 ((4 * 512 + 1) * 4 == 8196) /* 27*/ { 4, 2049, "10", 1, 0, 0 }, /* Strip Count 5, Rows Per Strip 512 ((4 * 512 + 1) * 4 == 8196) */
/* 28*/ { 4096, 1, "10", 1, 1, 0 }, // Strip Count 1, Rows Per Strip 1 /* 28*/ { 4096, 1, "10", 1, 1, 0 }, /* Strip Count 1, Rows Per Strip 1 */
/* 29*/ { 1, 4096, "10", 1, 0, 0 }, // Strip Count 2, Rows Per Strip 2048 /* 29*/ { 1, 4096, "10", 1, 0, 0 }, /* Strip Count 2, Rows Per Strip 2048 */
/* 30*/ { 4096, 2, "10", 1, 1, 0 }, // Strip Count 2, Rows Per Strip 1 /* 30*/ { 4096, 2, "10", 1, 1, 0 }, /* Strip Count 2, Rows Per Strip 1 */
/* 31*/ { 2, 4096, "10", 1, 0, 0 }, // Strip Count 4, Rows Per Strip 1024 /* 31*/ { 2, 4096, "10", 1, 0, 0 }, /* Strip Count 4, Rows Per Strip 1024 */
/* 32*/ { 8192, 2, "10", 1, 1, 0 }, // Strip Count 2, Rows Per Strip 1 /* 32*/ { 8192, 2, "10", 1, 1, 0 }, /* Strip Count 2, Rows Per Strip 1 */
/* 33*/ { 2, 8192, "10", 1, 0, 0 }, // Strip Count 8, Rows Per Strip 1024 /* 33*/ { 2, 8192, "10", 1, 0, 0 }, /* Strip Count 8, Rows Per Strip 1024 */
/* 34*/ { ZINT_MAX_DATA_LEN, 1, "10", 1, 1, 0 }, // Strip Count 1, Rows Per Strip 1 /* 34*/ { ZINT_MAX_DATA_LEN, 1, "10", 1, 1, 0 }, /* Strip Count 1, Rows Per Strip 1 */
/* 35*/ { 1, ZINT_MAX_DATA_LEN, "10", 1, 0, 0 }, // Strip Count 9, Rows Per Strip 2048 /* 35*/ { 1, ZINT_MAX_DATA_LEN, "10", 1, 0, 0 }, /* Strip Count 9, Rows Per Strip 2048 */
/* 36*/ { ZINT_MAX_DATA_LEN, 2, "10", 1, 1, 0 }, // Strip Count 2, Rows Per Strip 1 /* 36*/ { ZINT_MAX_DATA_LEN, 2, "10", 1, 1, 0 }, /* Strip Count 2, Rows Per Strip 1 */
/* 37*/ { 2, ZINT_MAX_DATA_LEN, "10", 1, 0, 0 }, // Strip Count 17, Rows Per Strip 1024 /* 37*/ { 2, ZINT_MAX_DATA_LEN, "10", 1, 0, 0 }, /* Strip Count 17, Rows Per Strip 1024 */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, ret; int i, ret;
@ -105,13 +106,13 @@ static void test_pixel_plot(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int size; int size;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
strcpy(symbol->outfile, tif); strcpy(symbol->outfile, tif);
symbol->bitmap_width = data[i].width; symbol->bitmap_width = data[i].width;
symbol->bitmap_height = data[i].height; symbol->bitmap_height = data[i].height;
symbol->symbology = BARCODE_ULTRA; // Use ULTRA with alpha background to force RGB symbol->symbology = BARCODE_ULTRA; /* Use ULTRA with alpha background to force RGB */
strcpy(symbol->bgcolour, "FFFFFFEE"); strcpy(symbol->bgcolour, "FFFFFFEE");
symbol->debug |= debug; symbol->debug |= debug;
@ -156,7 +157,8 @@ static void test_pixel_plot(int index, int debug) {
testFinish(); testFinish();
} }
static void test_print(int index, int generate, int debug) { static void test_print(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -216,7 +218,7 @@ static void test_print(int index, int generate, int debug) {
testStart("test_print"); testStart("test_print");
if (generate) { if (p_ctx->generate) {
char data_dir_path[1024]; char data_dir_path[1024];
assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir);
if (!testUtilDirExists(data_dir_path)) { if (!testUtilDirExists(data_dir_path)) {
@ -228,7 +230,7 @@ static void test_print(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int text_length; int text_length;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -275,7 +277,7 @@ static void test_print(int index, int generate, int debug) {
assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i); assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, %s, %d, %d, %d, %d, %d, %d, %.5g, \"%s\",\"%s\", \"%s\", \"%s\", \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %s, %d, %s, %d, %d, %d, %d, %d, %d, %.5g, \"%s\",\"%s\", \"%s\", \"%s\", \"%s\", \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].border_width, testUtilOutputOptionsName(data[i].output_options), i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].border_width, testUtilOutputOptionsName(data[i].output_options),
data[i].whitespace_width, data[i].whitespace_height, data[i].show_hrt, data[i].option_1, data[i].option_2, data[i].whitespace_width, data[i].whitespace_height, data[i].show_hrt, data[i].option_1, data[i].option_2,
@ -305,11 +307,13 @@ static void test_print(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_outfile(void) { static void test_outfile(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol symbol = {0}; struct zint_symbol symbol = {0};
unsigned char data[] = { "1" }; unsigned char data[] = { "1" };
(void)p_ctx;
testStart("test_outfile"); testStart("test_outfile");
symbol.symbology = BARCODE_CODE128; symbol.symbology = BARCODE_CODE128;
@ -332,10 +336,10 @@ static void test_outfile(void) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_pixel_plot", test_pixel_plot, 1, 0, 1 }, { "test_pixel_plot", test_pixel_plot },
{ "test_print", test_print, 1, 1, 1 }, { "test_print", test_print },
{ "test_outfile", test_outfile, 0, 0, 0 }, { "test_outfile", test_outfile },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
@ -344,3 +348,5 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_large(int index, int debug) { static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int option_1; int option_1;
@ -42,14 +44,14 @@ static void test_large(int index, int debug) {
int expected_rows; int expected_rows;
int expected_width; int expected_width;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { -1, -1, { 0, 0, "" }, "1", 252, 0, 31, 66 }, // Default EC2 /* 0*/ { -1, -1, { 0, 0, "" }, "1", 252, 0, 31, 66 }, /* Default EC2 */
/* 1*/ { -1, -1, { 0, 0, "" }, "1", 253, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 1*/ { -1, -1, { 0, 0, "" }, "1", 253, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 2*/ { -1, -1, { 0, 0, "" }, "1", ZINT_MAX_DATA_LEN, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 2*/ { -1, -1, { 0, 0, "" }, "1", ZINT_MAX_DATA_LEN, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 3*/ { -1, -1, { 1, 2, "" }, "1", 251, 0, 31, 66 }, // Structured Append no File Number 1 codeword overhead /* 3*/ { -1, -1, { 1, 2, "" }, "1", 251, 0, 31, 66 }, /* Structured Append no File Number 1 codeword overhead */
/* 4*/ { -1, -1, { 1, 2, "" }, "1", 252, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 4*/ { -1, -1, { 1, 2, "" }, "1", 252, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 5*/ { -1, -1, { 1, 2, "1" }, "1", 249, 0, 31, 66 }, // Structured Append with File Number 3 codewords overhead /* 5*/ { -1, -1, { 1, 2, "1" }, "1", 249, 0, 31, 66 }, /* Structured Append with File Number 3 codewords overhead */
/* 6*/ { -1, -1, { 1, 2, "1" }, "1", 250, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 6*/ { -1, -1, { 1, 2, "1" }, "1", 250, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 7*/ { -1, -1, { 0, 0, "" }, "A", 252, 0, 31, 66 }, /* 7*/ { -1, -1, { 0, 0, "" }, "A", 252, 0, 31, 66 },
/* 8*/ { -1, -1, { 0, 0, "" }, "A", 253, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 8*/ { -1, -1, { 0, 0, "" }, "A", 253, ZINT_ERROR_TOO_LONG, -1, -1 },
@ -92,7 +94,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -119,7 +121,8 @@ static void test_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_reader_init(int index, int generate, int debug) { static void test_reader_init(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -146,20 +149,19 @@ static void test_reader_init(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_ULTRA, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, data[i].option_3, data[i].output_options, data[i].data, -1, debug); length = testUtilSetSymbol(symbol, BARCODE_ULTRA, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, data[i].option_3, data[i].output_options, data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options), testUtilOption3Name(data[i].option_3), i, testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options), testUtilOption3Name(data[i].option_3),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
@ -178,7 +180,8 @@ static void test_reader_init(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int generate, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -271,13 +274,12 @@ static void test_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_ULTRA, data[i].input_mode, data[i].eci, length = testUtilSetSymbol(symbol, BARCODE_ULTRA, data[i].input_mode, data[i].eci,
data[i].option_1, data[i].option_2, data[i].option_3, data[i].option_1, data[i].option_2, data[i].option_3,
@ -289,7 +291,7 @@ static void test_input(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, %d, %s, { %d, %d, \"%s\" }, \"%s\", %s, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, %d, %d, %d, %s, { %d, %d, \"%s\" }, \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3), i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3),
data[i].structapp.index, data[i].structapp.count, data[i].structapp.id, data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
@ -304,7 +306,8 @@ static void test_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -322,8 +325,9 @@ static void test_encode(int index, int generate, int debug) {
char *comment; char *comment;
char *expected; char *expected;
}; };
// Based on AIMD/TSC15032-43 (v 0.99c), with values updated from BWIPP update 2021-07-14 /* Based on AIMD/TSC15032-43 (v 0.99c), with values updated from BWIPP update 2021-07-14
// https://github.com/bwipp/postscriptbarcode/commit/4255810845fa8d45c6192dd30aee1fdad1aaf0cc https://github.com/bwipp/postscriptbarcode/commit/4255810845fa8d45c6192dd30aee1fdad1aaf0cc
*/
struct item data[] = { struct item data[] = {
/* 0*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "ULTRACODE_123456789!", 0, 13, 22, 1, "AIMD/TSC15032-43 Figure G.1 **NOT SAME** different compression", /* 0*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "ULTRACODE_123456789!", 0, 13, 22, 1, "AIMD/TSC15032-43 Figure G.1 **NOT SAME** different compression",
"7777777777777777777777" "7777777777777777777777"
@ -778,14 +782,13 @@ static void test_encode(int index, int generate, int debug) {
char bwipp_buf[32768]; char bwipp_buf[32768];
char bwipp_msg[1024]; char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -798,7 +801,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, %d, %s, { %d, %d, \"%s\" }, \"%s\", %s, %d, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, %d, %d, %s, { %d, %d, \"%s\" }, \"%s\", %s, %d, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3), i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3),
data[i].structapp.index, data[i].structapp.count, data[i].structapp.id, data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
@ -836,7 +839,8 @@ static void test_encode(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_encode_segs(int index, int generate, int debug) { static void test_encode_segs(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int input_mode; int input_mode;
@ -853,8 +857,9 @@ static void test_encode_segs(int index, int generate, int debug) {
char *comment; char *comment;
char *expected; char *expected;
}; };
// Based on AIMD/TSC15032-43 (v 0.99c), with values updated from BWIPP update 2021-07-14 /* Based on AIMD/TSC15032-43 (v 0.99c), with values updated from BWIPP update 2021-07-14
// https://github.com/bwipp/postscriptbarcode/commit/4255810845fa8d45c6192dd30aee1fdad1aaf0cc https://github.com/bwipp/postscriptbarcode/commit/4255810845fa8d45c6192dd30aee1fdad1aaf0cc
*/
struct item data[] = { struct item data[] = {
/* 0*/ { UNICODE_MODE, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, { { TU(""), -1, 0 }, { TU("Ж"), -1, 7 }, { TU(""), 0, 0 } }, 0, 13, 15, 0, "Standard example; BWIPP no ECI support for Ultracode", /* 0*/ { UNICODE_MODE, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, { { TU(""), -1, 0 }, { TU("Ж"), -1, 7 }, { TU(""), 0, 0 } }, 0, 13, 15, 0, "Standard example; BWIPP no ECI support for Ultracode",
"777777777777777" "777777777777777"
@ -1018,14 +1023,13 @@ static void test_encode_segs(int index, int generate, int debug) {
char bwipp_buf[32768]; char bwipp_buf[32768];
char bwipp_msg[1024]; char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_encode_segs"); testStart("test_encode_segs");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1040,7 +1044,7 @@ static void test_encode_segs(int index, int generate, int debug) {
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count); ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
char escaped1[4096]; char escaped1[4096];
char escaped2[4096]; char escaped2[4096];
int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length;
@ -1087,12 +1091,12 @@ static void test_encode_segs(int index, int generate, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_large", test_large, 1, 0, 1 }, { "test_large", test_large },
{ "test_reader_init", test_reader_init, 1, 1, 1 }, { "test_reader_init", test_reader_init },
{ "test_input", test_input, 1, 1, 1 }, { "test_input", test_input },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_encode_segs", test_encode_segs, 1, 1, 1 }, { "test_encode_segs", test_encode_segs },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
static void test_upce_input(int index, int debug) { static void test_upce_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -39,21 +41,21 @@ static void test_upce_input(int index, int debug) {
char *hrt; char *hrt;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_UPCE, "12345", 0, "00123457" }, // equivalent: 00123400005, Check digit: 7 /* 0*/ { BARCODE_UPCE, "12345", 0, "00123457" }, /* equivalent: 00123400005, Check digit: 7 */
/* 1*/ { BARCODE_UPCE_CHK, "12345", ZINT_ERROR_INVALID_CHECK, "" }, /* 1*/ { BARCODE_UPCE_CHK, "12345", ZINT_ERROR_INVALID_CHECK, "" },
/* 2*/ { BARCODE_UPCE_CHK, "12344", 0, "00012344" }, // equivalent: 00012000003, Check digit: 4 /* 2*/ { BARCODE_UPCE_CHK, "12344", 0, "00012344" }, /* equivalent: 00012000003, Check digit: 4 */
/* 3*/ { BARCODE_UPCE, "123456", 0, "01234565" }, // equivalent: 01234500006, Check digit: 5 /* 3*/ { BARCODE_UPCE, "123456", 0, "01234565" }, /* equivalent: 01234500006, Check digit: 5 */
/* 4*/ { BARCODE_UPCE_CHK, "123456", ZINT_ERROR_INVALID_CHECK, "" }, /* 4*/ { BARCODE_UPCE_CHK, "123456", ZINT_ERROR_INVALID_CHECK, "" },
/* 5*/ { BARCODE_UPCE_CHK, "123457", 0, "00123457" }, // equivalent: 00123400005, Check digit: 7 /* 5*/ { BARCODE_UPCE_CHK, "123457", 0, "00123457" }, /* equivalent: 00123400005, Check digit: 7 */
/* 6*/ { BARCODE_UPCE, "1234567", 0, "12345670" }, // equivalent: 12345600007, Check digit: 0 /* 6*/ { BARCODE_UPCE, "1234567", 0, "12345670" }, /* equivalent: 12345600007, Check digit: 0 */
/* 7*/ { BARCODE_UPCE_CHK, "1234567", ZINT_ERROR_INVALID_CHECK, "" }, /* 7*/ { BARCODE_UPCE_CHK, "1234567", ZINT_ERROR_INVALID_CHECK, "" },
/* 8*/ { BARCODE_UPCE_CHK, "1234565", 0, "01234565" }, // equivalent: 01234500006, Check digit: 5 /* 8*/ { BARCODE_UPCE_CHK, "1234565", 0, "01234565" }, /* equivalent: 01234500006, Check digit: 5 */
/* 9*/ { BARCODE_UPCE, "12345678", ZINT_ERROR_INVALID_CHECK, "" }, /* 9*/ { BARCODE_UPCE, "12345678", ZINT_ERROR_INVALID_CHECK, "" },
/* 10*/ { BARCODE_UPCE, "12345670", 0, "12345670" }, // equivalent: 12345600007, Check digit: 0 /* 10*/ { BARCODE_UPCE, "12345670", 0, "12345670" }, /* equivalent: 12345600007, Check digit: 0 */
/* 11*/ { BARCODE_UPCE_CHK, "12345678", ZINT_ERROR_INVALID_CHECK, "" }, /* 11*/ { BARCODE_UPCE_CHK, "12345678", ZINT_ERROR_INVALID_CHECK, "" },
/* 12*/ { BARCODE_UPCE_CHK, "12345670", 0, "12345670" }, // equivalent: 12345600007, Check digit: 0 /* 12*/ { BARCODE_UPCE_CHK, "12345670", 0, "12345670" }, /* equivalent: 12345600007, Check digit: 0 */
/* 13*/ { BARCODE_UPCE, "123456789", ZINT_ERROR_TOO_LONG, "" }, /* 13*/ { BARCODE_UPCE, "123456789", ZINT_ERROR_TOO_LONG, "" },
/* 14*/ { BARCODE_UPCE_CHK, "123456789", ZINT_ERROR_TOO_LONG, "" }, /* 14*/ { BARCODE_UPCE_CHK, "123456789", ZINT_ERROR_TOO_LONG, "" },
/* 15*/ { BARCODE_UPCE, "123456A", ZINT_ERROR_INVALID_DATA, "" }, /* 15*/ { BARCODE_UPCE, "123456A", ZINT_ERROR_INVALID_DATA, "" },
@ -62,31 +64,31 @@ static void test_upce_input(int index, int debug) {
/* 18*/ { BARCODE_UPCE_CHK, "123456A", ZINT_ERROR_INVALID_DATA, "" }, /* 18*/ { BARCODE_UPCE_CHK, "123456A", ZINT_ERROR_INVALID_DATA, "" },
/* 19*/ { BARCODE_UPCE_CHK, "1234567A", ZINT_ERROR_INVALID_DATA, "" }, /* 19*/ { BARCODE_UPCE_CHK, "1234567A", ZINT_ERROR_INVALID_DATA, "" },
/* 20*/ { BARCODE_UPCE_CHK, "12345678A", ZINT_ERROR_INVALID_DATA, "" }, /* 20*/ { BARCODE_UPCE_CHK, "12345678A", ZINT_ERROR_INVALID_DATA, "" },
/* 21*/ { BARCODE_UPCE, "2345678", 0, "03456781" }, // 2 ignored, equivalent: 03456700008, Check digit: 1 /* 21*/ { BARCODE_UPCE, "2345678", 0, "03456781" }, /* 2 ignored, equivalent: 03456700008, Check digit: 1 */
/* 22*/ { BARCODE_UPCE_CHK, "23456781", 0, "03456781" }, // 2 ignored, equivalent: 03456700008, Check digit: 1 /* 22*/ { BARCODE_UPCE_CHK, "23456781", 0, "03456781" }, /* 2 ignored, equivalent: 03456700008, Check digit: 1 */
/* 23*/ { BARCODE_UPCE, "123455", 0, "01234558" }, // equivalent: 01234500005, Check digit: 8 (BS 797 Rule 3 (a)) /* 23*/ { BARCODE_UPCE, "123455", 0, "01234558" }, /* equivalent: 01234500005, Check digit: 8 (BS 797 Rule 3 (a)) */
/* 24*/ { BARCODE_UPCE_CHK, "1234558", 0, "01234558" }, // equivalent: 01234500005, Check digit: 8 (BS 797 Rule 3 (a)) /* 24*/ { BARCODE_UPCE_CHK, "1234558", 0, "01234558" }, /* equivalent: 01234500005, Check digit: 8 (BS 797 Rule 3 (a)) */
/* 25*/ { BARCODE_UPCE, "456784", 0, "04567840" }, // equivalent: 04567000008, Check digit: 0 (BS 797 Rule 3 (b)) /* 25*/ { BARCODE_UPCE, "456784", 0, "04567840" }, /* equivalent: 04567000008, Check digit: 0 (BS 797 Rule 3 (b)) */
/* 26*/ { BARCODE_UPCE_CHK, "4567840", 0, "04567840" }, // equivalent: 04567000008, Check digit: 0 (BS 797 Rule 3 (b)) /* 26*/ { BARCODE_UPCE_CHK, "4567840", 0, "04567840" }, /* equivalent: 04567000008, Check digit: 0 (BS 797 Rule 3 (b)) */
/* 27*/ { BARCODE_UPCE, "345670", 0, "03456703" }, // equivalent: 03400000567, Check digit: 3 (BS 797 Rule 3 (c)) /* 27*/ { BARCODE_UPCE, "345670", 0, "03456703" }, /* equivalent: 03400000567, Check digit: 3 (BS 797 Rule 3 (c)) */
/* 28*/ { BARCODE_UPCE_CHK, "3456703", 0, "03456703" }, // equivalent: 03400000567, Check digit: 3 (BS 797 Rule 3 (c)) /* 28*/ { BARCODE_UPCE_CHK, "3456703", 0, "03456703" }, /* equivalent: 03400000567, Check digit: 3 (BS 797 Rule 3 (c)) */
/* 29*/ { BARCODE_UPCE, "984753", 0, "09847531" }, // equivalent: 09840000075, Check digit: 1 (BS 797 Rule 3 (d)) /* 29*/ { BARCODE_UPCE, "984753", 0, "09847531" }, /* equivalent: 09840000075, Check digit: 1 (BS 797 Rule 3 (d)) */
/* 30*/ { BARCODE_UPCE_CHK, "9847531", 0, "09847531" }, // equivalent: 09840000075, Check digit: 1 (BS 797 Rule 3 (d)) /* 30*/ { BARCODE_UPCE_CHK, "9847531", 0, "09847531" }, /* equivalent: 09840000075, Check digit: 1 (BS 797 Rule 3 (d)) */
/* 31*/ { BARCODE_UPCE, "120453", ZINT_ERROR_INVALID_DATA, "" }, // If last digit (emode) 3, 3rd can't be 0, 1 or 2 (BS 787 Table 5 NOTE 1) /* 31*/ { BARCODE_UPCE, "120453", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 3, 3rd can't be 0, 1 or 2 (BS 787 Table 5 NOTE 1) */
/* 32*/ { BARCODE_UPCE, "121453", ZINT_ERROR_INVALID_DATA, "" }, // If last digit (emode) 3, 3rd can't be 0, 1 or 2 (BS 787 Table 5 NOTE 1) /* 32*/ { BARCODE_UPCE, "121453", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 3, 3rd can't be 0, 1 or 2 (BS 787 Table 5 NOTE 1) */
/* 33*/ { BARCODE_UPCE, "122453", ZINT_ERROR_INVALID_DATA, "" }, // If last digit (emode) 3, 3rd can't be 0, 1 or 2 (BS 787 Table 5 NOTE 1) /* 33*/ { BARCODE_UPCE, "122453", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 3, 3rd can't be 0, 1 or 2 (BS 787 Table 5 NOTE 1) */
/* 34*/ { BARCODE_UPCE, "123453", 0, "01234531" }, /* 34*/ { BARCODE_UPCE, "123453", 0, "01234531" },
/* 35*/ { BARCODE_UPCE, "123054", ZINT_ERROR_INVALID_DATA, "" }, // If last digit (emode) 4, 4th can't be 0 (BS 787 Table 5 NOTE 2) /* 35*/ { BARCODE_UPCE, "123054", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 4, 4th can't be 0 (BS 787 Table 5 NOTE 2) */
/* 36*/ { BARCODE_UPCE, "123154", 0, "01231542" }, /* 36*/ { BARCODE_UPCE, "123154", 0, "01231542" },
/* 37*/ { BARCODE_UPCE, "123405", ZINT_ERROR_INVALID_DATA, "" }, // If last digit (emode) 5, 5th can't be 0 (BS 787 Table 5 NOTE 3) /* 37*/ { BARCODE_UPCE, "123405", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 5, 5th can't be 0 (BS 787 Table 5 NOTE 3) */
/* 38*/ { BARCODE_UPCE, "123455", 0, "01234558" }, /* 38*/ { BARCODE_UPCE, "123455", 0, "01234558" },
/* 39*/ { BARCODE_UPCE, "123406", ZINT_ERROR_INVALID_DATA, "" }, // If last digit (emode) 6, 5th can't be 0 (BS 787 Table 5 NOTE 3) /* 39*/ { BARCODE_UPCE, "123406", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 6, 5th can't be 0 (BS 787 Table 5 NOTE 3) */
/* 40*/ { BARCODE_UPCE, "123456", 0, "01234565" }, /* 40*/ { BARCODE_UPCE, "123456", 0, "01234565" },
/* 41*/ { BARCODE_UPCE, "123407", ZINT_ERROR_INVALID_DATA, "" }, // If last digit (emode) 7, 5th can't be 0 (BS 787 Table 5 NOTE 3) /* 41*/ { BARCODE_UPCE, "123407", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 7, 5th can't be 0 (BS 787 Table 5 NOTE 3) */
/* 42*/ { BARCODE_UPCE, "123457", 0, "01234572" }, /* 42*/ { BARCODE_UPCE, "123457", 0, "01234572" },
/* 43*/ { BARCODE_UPCE, "123408", ZINT_ERROR_INVALID_DATA, "" }, // If last digit (emode) 8, 5th can't be 0 (BS 787 Table 5 NOTE 3) /* 43*/ { BARCODE_UPCE, "123408", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 8, 5th can't be 0 (BS 787 Table 5 NOTE 3) */
/* 44*/ { BARCODE_UPCE, "123458", 0, "01234589" }, /* 44*/ { BARCODE_UPCE, "123458", 0, "01234589" },
/* 45*/ { BARCODE_UPCE, "123409", ZINT_ERROR_INVALID_DATA, "" }, // If last digit (emode) 9, 5th can't be 0 (BS 787 Table 5 NOTE 3) /* 45*/ { BARCODE_UPCE, "123409", ZINT_ERROR_INVALID_DATA, "" }, /* If last digit (emode) 9, 5th can't be 0 (BS 787 Table 5 NOTE 3) */
/* 46*/ { BARCODE_UPCE, "123459", 0, "01234596" }, /* 46*/ { BARCODE_UPCE, "123459", 0, "01234596" },
/* 47*/ { BARCODE_UPCE, "000000", 0, "00000000" }, /* 47*/ { BARCODE_UPCE, "000000", 0, "00000000" },
/* 48*/ { BARCODE_UPCE, "000001", 0, "00000019" }, /* 48*/ { BARCODE_UPCE, "000001", 0, "00000019" },
@ -100,14 +102,14 @@ static void test_upce_input(int index, int debug) {
char cmp_buf[4096]; char cmp_buf[4096];
char cmp_msg[1024]; char cmp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_upce_input"); testStart("test_upce_input");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -147,15 +149,16 @@ static void test_upce_input(int index, int debug) {
testFinish(); testFinish();
} }
// Note requires ZINT_SANITIZE to be set /* Note requires ZINT_SANITIZE to be set */
static void test_upca_print(int index, int debug) { static void test_upca_print(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
char *data; char *data;
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_UPCA, "01234567890", 0 }, /* 0*/ { BARCODE_UPCA, "01234567890", 0 },
}; };
@ -167,7 +170,7 @@ static void test_upca_print(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -189,18 +192,19 @@ static void test_upca_print(int index, int debug) {
testFinish(); testFinish();
} }
static void test_upca_input(int index, int debug) { static void test_upca_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
char *data; char *data;
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_UPCA, "12345678901", 0 }, /* 0*/ { BARCODE_UPCA, "12345678901", 0 },
/* 1*/ { BARCODE_UPCA, "1234567890", 0 }, /* 1*/ { BARCODE_UPCA, "1234567890", 0 },
/* 2*/ { BARCODE_UPCA, "123456789012", 0 }, // UPC-A accepts CHK /* 2*/ { BARCODE_UPCA, "123456789012", 0 }, /* UPC-A accepts CHK */
/* 3*/ { BARCODE_UPCA, "123456789011", ZINT_ERROR_INVALID_CHECK }, /* 3*/ { BARCODE_UPCA, "123456789011", ZINT_ERROR_INVALID_CHECK },
/* 4*/ { BARCODE_UPCA, "1234567890123", ZINT_ERROR_TOO_LONG }, /* 4*/ { BARCODE_UPCA, "1234567890123", ZINT_ERROR_TOO_LONG },
/* 5*/ { BARCODE_UPCA, "123456789012A", ZINT_ERROR_INVALID_DATA }, /* 5*/ { BARCODE_UPCA, "123456789012A", ZINT_ERROR_INVALID_DATA },
@ -242,7 +246,7 @@ static void test_upca_input(int index, int debug) {
/* 41*/ { BARCODE_UPCA_CHK, "12348", 0 }, /* 41*/ { BARCODE_UPCA_CHK, "12348", 0 },
/* 42*/ { BARCODE_UPCA_CHK, "1234", ZINT_ERROR_INVALID_CHECK }, /* 42*/ { BARCODE_UPCA_CHK, "1234", ZINT_ERROR_INVALID_CHECK },
/* 43*/ { BARCODE_UPCA_CHK, "1236", 0 }, /* 43*/ { BARCODE_UPCA_CHK, "1236", 0 },
/* 44*/ { BARCODE_UPCA_CHK, "123", 0 }, // Happens to be correct check digit /* 44*/ { BARCODE_UPCA_CHK, "123", 0 }, /* Happens to be correct check digit */
/* 45*/ { BARCODE_UPCA_CHK, "124", ZINT_ERROR_INVALID_CHECK }, /* 45*/ { BARCODE_UPCA_CHK, "124", ZINT_ERROR_INVALID_CHECK },
/* 46*/ { BARCODE_UPCA_CHK, "12", ZINT_ERROR_INVALID_CHECK }, /* 46*/ { BARCODE_UPCA_CHK, "12", ZINT_ERROR_INVALID_CHECK },
/* 47*/ { BARCODE_UPCA_CHK, "17", 0 }, /* 47*/ { BARCODE_UPCA_CHK, "17", 0 },
@ -282,7 +286,7 @@ static void test_upca_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -298,7 +302,8 @@ static void test_upca_input(int index, int debug) {
testFinish(); testFinish();
} }
static void test_eanx_input(int index, int generate, int debug) { static void test_eanx_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -307,7 +312,7 @@ static void test_eanx_input(int index, int generate, int debug) {
char *ret_errtxt; char *ret_errtxt;
char *comment; char *comment;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_EANX, "123456789012", 0, "", "" }, /* 0*/ { BARCODE_EANX, "123456789012", 0, "", "" },
/* 1*/ { BARCODE_EANX, "12345678901A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character in data (digits and \"+\" only)", "" }, /* 1*/ { BARCODE_EANX, "12345678901A", ZINT_ERROR_INVALID_DATA, "Error 284: Invalid character in data (digits and \"+\" only)", "" },
@ -450,7 +455,7 @@ static void test_eanx_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -459,7 +464,7 @@ static void test_eanx_input(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, \"%s\", %s, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { %s, \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), data[i].data, testUtilErrorName(data[i].ret), i, testUtilBarcodeName(data[i].symbology), data[i].data, testUtilErrorName(data[i].ret),
testUtilEscape(symbol->errtxt, (int) strlen(symbol->errtxt), errtxt_escaped, sizeof(errtxt_escaped)), testUtilEscape(symbol->errtxt, (int) strlen(symbol->errtxt), errtxt_escaped, sizeof(errtxt_escaped)),
@ -475,7 +480,8 @@ static void test_eanx_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_isbn_input(int index, int generate, int debug) { static void test_isbn_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
char *data; char *data;
@ -484,7 +490,7 @@ static void test_isbn_input(int index, int generate, int debug) {
char *ret_errtxt; char *ret_errtxt;
char *comment; char *comment;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "0", 0, 0, "", "Left zero-padded if < 10 chars" }, /* 0*/ { "0", 0, 0, "", "Left zero-padded if < 10 chars" },
/* 1*/ { "1", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '1', expecting '0'", "" }, /* 1*/ { "1", ZINT_ERROR_INVALID_CHECK, -1, "Error 281: Invalid SBN check digit '1', expecting '0'", "" },
@ -602,8 +608,7 @@ static void test_isbn_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -612,7 +617,7 @@ static void test_isbn_input(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { \"%s\", %s, %d, \"%s\", \"%s\" },\n", printf(" /*%3d*/ { \"%s\", %s, %d, \"%s\", \"%s\" },\n",
i, data[i].data, testUtilErrorName(data[i].ret_encode), data[i].ret_vector, i, data[i].data, testUtilErrorName(data[i].ret_encode), data[i].ret_vector,
testUtilEscape(symbol->errtxt, (int) strlen(symbol->errtxt), errtxt_escaped, sizeof(errtxt_escaped)), testUtilEscape(symbol->errtxt, (int) strlen(symbol->errtxt), errtxt_escaped, sizeof(errtxt_escaped)),
@ -633,7 +638,8 @@ static void test_isbn_input(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_hrt(int index, int debug) { static void test_hrt(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -641,25 +647,25 @@ static void test_hrt(int index, int debug) {
int ret; int ret;
char *expected; char *expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_EANX, "12345678901", 0, "0123456789012" }, /* 0*/ { BARCODE_EANX, "12345678901", 0, "0123456789012" },
/* 1*/ { BARCODE_EANX, "123456789012", 0, "1234567890128" }, /* 1*/ { BARCODE_EANX, "123456789012", 0, "1234567890128" },
/* 2*/ { BARCODE_EANX, "1234567890128", 0, "1234567890128" }, // EANX accepts CHK (treated as such if no leading zeroes required) /* 2*/ { BARCODE_EANX, "1234567890128", 0, "1234567890128" }, /* EANX accepts CHK (treated as such if no leading zeroes required) */
/* 3*/ { BARCODE_EANX_CHK, "1234567890128", 0, "1234567890128" }, /* 3*/ { BARCODE_EANX_CHK, "1234567890128", 0, "1234567890128" },
/* 4*/ { BARCODE_EANX_CHK, "123456789012", 0, "0123456789012" }, // '2' happens to be correct check digit for "012345678901" /* 4*/ { BARCODE_EANX_CHK, "123456789012", 0, "0123456789012" }, /* '2' happens to be correct check digit for "012345678901" */
/* 5*/ { BARCODE_EANX, "1234567890128+1", 0, "1234567890128+01" }, /* 5*/ { BARCODE_EANX, "1234567890128+1", 0, "1234567890128+01" },
/* 6*/ { BARCODE_EANX_CHK, "1234567890128+1", 0, "1234567890128+01" }, /* 6*/ { BARCODE_EANX_CHK, "1234567890128+1", 0, "1234567890128+01" },
/* 7*/ { BARCODE_EANX, "12345678", 0, "0000123456784" }, /* 7*/ { BARCODE_EANX, "12345678", 0, "0000123456784" },
/* 8*/ { BARCODE_EANX, "1234567", 0, "12345670" }, // EAN-8 /* 8*/ { BARCODE_EANX, "1234567", 0, "12345670" }, /* EAN-8 */
/* 9*/ { BARCODE_EANX_CHK, "12345670", 0, "12345670" }, // EAN-8 /* 9*/ { BARCODE_EANX_CHK, "12345670", 0, "12345670" }, /* EAN-8 */
/* 10*/ { BARCODE_EANX, "123456", 0, "01234565" }, // EAN-8 /* 10*/ { BARCODE_EANX, "123456", 0, "01234565" }, /* EAN-8 */
/* 11*/ { BARCODE_EANX_CHK, "123457", 0, "00123457" }, // EAN-8 /* 11*/ { BARCODE_EANX_CHK, "123457", 0, "00123457" }, /* EAN-8 */
/* 12*/ { BARCODE_EANX, "12345", 0, "12345" }, // EAN-5 /* 12*/ { BARCODE_EANX, "12345", 0, "12345" }, /* EAN-5 */
/* 13*/ { BARCODE_EANX, "123", 0, "00123" }, // EAN-5 /* 13*/ { BARCODE_EANX, "123", 0, "00123" }, /* EAN-5 */
/* 14*/ { BARCODE_EANX, "12", 0, "12" }, // EAN-2 /* 14*/ { BARCODE_EANX, "12", 0, "12" }, /* EAN-2 */
/* 15*/ { BARCODE_EANX, "1", 0, "01" }, // EAN-2 /* 15*/ { BARCODE_EANX, "1", 0, "01" }, /* EAN-2 */
/* 16*/ { BARCODE_EANX, "0", 0, "00" }, // EAN-2 /* 16*/ { BARCODE_EANX, "0", 0, "00" }, /* EAN-2 */
/* 17*/ { BARCODE_ISBNX, "0", 0, "9780000000002" }, /* 17*/ { BARCODE_ISBNX, "0", 0, "9780000000002" },
/* 18*/ { BARCODE_ISBNX, "123456789X", 0, "9781234567897" }, /* 18*/ { BARCODE_ISBNX, "123456789X", 0, "9781234567897" },
/* 19*/ { BARCODE_ISBNX, "9781234567897", 0, "9781234567897" }, /* 19*/ { BARCODE_ISBNX, "9781234567897", 0, "9781234567897" },
@ -671,28 +677,28 @@ static void test_hrt(int index, int debug) {
/* 25*/ { BARCODE_UPCA_CHK, "123456789050+1", 0, "123456789050+01" }, /* 25*/ { BARCODE_UPCA_CHK, "123456789050+1", 0, "123456789050+01" },
/* 26*/ { BARCODE_UPCA, "123456789050+123", 0, "123456789050+00123" }, /* 26*/ { BARCODE_UPCA, "123456789050+123", 0, "123456789050+00123" },
/* 27*/ { BARCODE_UPCA_CHK, "123456789050+123", 0, "123456789050+00123" }, /* 27*/ { BARCODE_UPCA_CHK, "123456789050+123", 0, "123456789050+00123" },
/* 28*/ { BARCODE_UPCE, "12345", 0, "00123457" }, // equivalent: 00123400005, hrt: 00123457, Check digit: 7 /* 28*/ { BARCODE_UPCE, "12345", 0, "00123457" }, /* equivalent: 00123400005, hrt: 00123457, Check digit: 7 */
/* 29*/ { BARCODE_UPCE_CHK, "12344", 0, "00012344" }, // equivalent: 00012000003, hrt: 00012344, Check digit: 4 /* 29*/ { BARCODE_UPCE_CHK, "12344", 0, "00012344" }, /* equivalent: 00012000003, hrt: 00012344, Check digit: 4 */
/* 30*/ { BARCODE_UPCE, "123456", 0, "01234565" }, // equivalent: 01234500006, hrt: 01234565, Check digit: 5 /* 30*/ { BARCODE_UPCE, "123456", 0, "01234565" }, /* equivalent: 01234500006, hrt: 01234565, Check digit: 5 */
/* 31*/ { BARCODE_UPCE_CHK, "123457", 0, "00123457" }, // equivalent: 00123400005, hrt: 00123457, Check digit: 7 /* 31*/ { BARCODE_UPCE_CHK, "123457", 0, "00123457" }, /* equivalent: 00123400005, hrt: 00123457, Check digit: 7 */
/* 32*/ { BARCODE_UPCE, "1234567", 0, "12345670" }, // equivalent: 12345600007, hrt: 12345670, Check digit: 0 /* 32*/ { BARCODE_UPCE, "1234567", 0, "12345670" }, /* equivalent: 12345600007, hrt: 12345670, Check digit: 0 */
/* 33*/ { BARCODE_UPCE_CHK, "1234565", 0, "01234565" }, // equivalent: 01234500006, hrt: 01234565, Check digit: 5 /* 33*/ { BARCODE_UPCE_CHK, "1234565", 0, "01234565" }, /* equivalent: 01234500006, hrt: 01234565, Check digit: 5 */
/* 34*/ { BARCODE_UPCE_CHK, "12345670", 0, "12345670" }, // equivalent: 12345600007, hrt: 12345670, Check digit: 0 /* 34*/ { BARCODE_UPCE_CHK, "12345670", 0, "12345670" }, /* equivalent: 12345600007, hrt: 12345670, Check digit: 0 */
/* 35*/ { BARCODE_UPCE, "2345678", 0, "03456781" }, // 2 ignored, equivalent: 03456700008, hrt: 03456781, Check digit: 1 /* 35*/ { BARCODE_UPCE, "2345678", 0, "03456781" }, /* 2 ignored, equivalent: 03456700008, hrt: 03456781, Check digit: 1 */
/* 36*/ { BARCODE_UPCE_CHK, "23456781", 0, "03456781" }, // 2 ignored, equivalent: 03456700008, hrt: 03456781, Check digit: 1 /* 36*/ { BARCODE_UPCE_CHK, "23456781", 0, "03456781" }, /* 2 ignored, equivalent: 03456700008, hrt: 03456781, Check digit: 1 */
/* 37*/ { BARCODE_UPCE, "123455", 0, "01234558" }, // equivalent: 01234500005, hrt: 01234558, Check digit: 8 (BS 797 Rule 3 (a)) /* 37*/ { BARCODE_UPCE, "123455", 0, "01234558" }, /* equivalent: 01234500005, hrt: 01234558, Check digit: 8 (BS 797 Rule 3 (a)) */
/* 38*/ { BARCODE_UPCE_CHK, "1234558", 0, "01234558" }, // equivalent: 01234500005, hrt: 01234558, Check digit: 8 (BS 797 Rule 3 (a)) /* 38*/ { BARCODE_UPCE_CHK, "1234558", 0, "01234558" }, /* equivalent: 01234500005, hrt: 01234558, Check digit: 8 (BS 797 Rule 3 (a)) */
/* 39*/ { BARCODE_UPCE, "456784", 0, "04567840" }, // equivalent: 04567000008, hrt: 04567840, Check digit: 0 (BS 797 Rule 3 (b)) /* 39*/ { BARCODE_UPCE, "456784", 0, "04567840" }, /* equivalent: 04567000008, hrt: 04567840, Check digit: 0 (BS 797 Rule 3 (b)) */
/* 40*/ { BARCODE_UPCE_CHK, "4567840", 0, "04567840" }, // equivalent: 04567000008, hrt: 04567840, Check digit: 0 (BS 797 Rule 3 (b)) /* 40*/ { BARCODE_UPCE_CHK, "4567840", 0, "04567840" }, /* equivalent: 04567000008, hrt: 04567840, Check digit: 0 (BS 797 Rule 3 (b)) */
/* 41*/ { BARCODE_UPCE, "345670", 0, "03456703" }, // equivalent: 03400000567, hrt: 03456703, Check digit: 3 (BS 797 Rule 3 (c)) /* 41*/ { BARCODE_UPCE, "345670", 0, "03456703" }, /* equivalent: 03400000567, hrt: 03456703, Check digit: 3 (BS 797 Rule 3 (c)) */
/* 42*/ { BARCODE_UPCE_CHK, "3456703", 0, "03456703" }, // equivalent: 03400000567, hrt: 03456703, Check digit: 3 (BS 797 Rule 3 (c)) /* 42*/ { BARCODE_UPCE_CHK, "3456703", 0, "03456703" }, /* equivalent: 03400000567, hrt: 03456703, Check digit: 3 (BS 797 Rule 3 (c)) */
/* 43*/ { BARCODE_UPCE, "984753", 0, "09847531" }, // equivalent: 09840000075, hrt: 09847531, Check digit: 1 (BS 797 Rule 3 (d)) /* 43*/ { BARCODE_UPCE, "984753", 0, "09847531" }, /* equivalent: 09840000075, hrt: 09847531, Check digit: 1 (BS 797 Rule 3 (d)) */
/* 44*/ { BARCODE_UPCE_CHK, "9847531", 0, "09847531" }, // equivalent: 09840000075, hrt: 09847531, Check digit: 1 (BS 797 Rule 3 (d)) /* 44*/ { BARCODE_UPCE_CHK, "9847531", 0, "09847531" }, /* equivalent: 09840000075, hrt: 09847531, Check digit: 1 (BS 797 Rule 3 (d)) */
/* 45*/ { BARCODE_UPCE, "123453", 0, "01234531" }, /* 45*/ { BARCODE_UPCE, "123453", 0, "01234531" },
/* 46*/ { BARCODE_UPCE, "000000", 0, "00000000" }, /* 46*/ { BARCODE_UPCE, "000000", 0, "00000000" },
/* 47*/ { BARCODE_UPCE, "0000000", 0, "00000000" }, /* 47*/ { BARCODE_UPCE, "0000000", 0, "00000000" },
/* 48*/ { BARCODE_UPCE, "1000000", 0, "10000007" }, /* 48*/ { BARCODE_UPCE, "1000000", 0, "10000007" },
/* 49*/ { BARCODE_UPCE, "2000000", 0, "00000000" }, // First char 2-9 ignored, replaced with 0 /* 49*/ { BARCODE_UPCE, "2000000", 0, "00000000" }, /* First char 2-9 ignored, replaced with 0 */
/* 50*/ { BARCODE_UPCE, "3000000", 0, "00000000" }, /* 50*/ { BARCODE_UPCE, "3000000", 0, "00000000" },
/* 51*/ { BARCODE_UPCE, "8000000", 0, "00000000" }, /* 51*/ { BARCODE_UPCE, "8000000", 0, "00000000" },
/* 52*/ { BARCODE_UPCE, "9000000", 0, "00000000" }, /* 52*/ { BARCODE_UPCE, "9000000", 0, "00000000" },
@ -709,7 +715,7 @@ static void test_hrt(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -727,7 +733,8 @@ static void test_hrt(int index, int debug) {
testFinish(); testFinish();
} }
static void test_vector_same(int index, int debug) { static void test_vector_same(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -737,8 +744,8 @@ static void test_vector_same(int index, int debug) {
}; };
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_UPCE, "123456", 0, 0 }, /* 0*/ { BARCODE_UPCE, "123456", 0, 0 },
/* 1*/ { BARCODE_UPCE_CHK, "1234565", 0, 0 }, // 5 is correct check digit /* 1*/ { BARCODE_UPCE_CHK, "1234565", 0, 0 }, /* 5 is correct check digit */
/* 2*/ { BARCODE_ISBNX, "0195049969", 0, 0 }, // 9 is correct check digit /* 2*/ { BARCODE_ISBNX, "0195049969", 0, 0 }, /* 9 is correct check digit */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -751,7 +758,7 @@ static void test_vector_same(int index, int debug) {
int vectors_size = ARRAY_SIZE(vectors); int vectors_size = ARRAY_SIZE(vectors);
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
for (j = 0; j < vectors_size; j++) { for (j = 0; j < vectors_size; j++) {
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
@ -786,9 +793,10 @@ static void test_vector_same(int index, int debug) {
testFinish(); testFinish();
} }
// https://www.isbn-international.org/content/isbn-users-manual ISBN Users' Manual /* https://www.isbn-international.org/content/isbn-users-manual ISBN Users' Manual */
// https://bisg.org/page/BarcodingGuidelines BISG Barcode Guidelines for the US Book Industry (BISG BGUSBI) /* https://bisg.org/page/BarcodingGuidelines BISG Barcode Guidelines for the US Book Industry (BISG BGUSBI) */
static void test_encode(int index, int generate, int debug) { static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -919,14 +927,14 @@ static void test_encode(int index, int generate, int debug) {
char cmp_buf[4096]; char cmp_buf[4096];
char cmp_msg[1024]; char cmp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); // Only do ZXing-C++ test if asked, too slow otherwise int do_zxingcpp = (debug & ZINT_DEBUG_TEST_ZXINGCPP) && testUtilHaveZXingCPPDecoder(); /* Only do ZXing-C++ test if asked, too slow otherwise */
testStart("test_encode"); testStart("test_encode");
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -936,7 +944,7 @@ static void test_encode(int index, int generate, int debug) {
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), data[i].option_2, data[i].data, testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); i, testUtilBarcodeName(data[i].symbology), data[i].option_2, data[i].data, testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
testUtilModulesPrint(symbol, " ", "\n"); testUtilModulesPrint(symbol, " ", "\n");
@ -979,8 +987,9 @@ static void test_encode(int index, int generate, int debug) {
testFinish(); testFinish();
} }
// #181 Christian Hartlage OSS-Fuzz /* #181 Christian Hartlage OSS-Fuzz */
static void test_fuzz(int index, int debug) { static void test_fuzz(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -988,7 +997,7 @@ static void test_fuzz(int index, int debug) {
int length; int length;
int ret; int ret;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_EANX, "55++15", -1, ZINT_ERROR_INVALID_DATA }, /* 0*/ { BARCODE_EANX, "55++15", -1, ZINT_ERROR_INVALID_DATA },
/* 1*/ { BARCODE_EANX, "+123456789012345678", -1, ZINT_ERROR_TOO_LONG }, /* 1*/ { BARCODE_EANX, "+123456789012345678", -1, ZINT_ERROR_TOO_LONG },
@ -1000,7 +1009,7 @@ static void test_fuzz(int index, int debug) {
/* 7*/ { BARCODE_ISBNX, "+123456789012345678", -1, ZINT_ERROR_TOO_LONG }, /* 7*/ { BARCODE_ISBNX, "+123456789012345678", -1, ZINT_ERROR_TOO_LONG },
/* 8*/ { BARCODE_EANX, "+12345", -1, 0 }, /* 8*/ { BARCODE_EANX, "+12345", -1, 0 },
/* 9*/ { BARCODE_EANX, "+123456", -1, ZINT_ERROR_TOO_LONG }, /* 9*/ { BARCODE_EANX, "+123456", -1, ZINT_ERROR_TOO_LONG },
/*10*/ { BARCODE_EANX, "000002000000200+203", -1, ZINT_ERROR_TOO_LONG }, // #218 Jan Schrewe CI-Fuzz /*10*/ { BARCODE_EANX, "000002000000200+203", -1, ZINT_ERROR_TOO_LONG }, /* #218 Jan Schrewe CI-Fuzz */
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -1010,7 +1019,7 @@ static void test_fuzz(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1032,8 +1041,9 @@ static void test_fuzz(int index, int debug) {
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000) #define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
#define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC) #define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC)
// Not a real test, just performance indicator /* Not a real test, just performance indicator */
static void test_perf(int index, int debug) { static void test_perf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1045,7 +1055,7 @@ static void test_perf(int index, int debug) {
int expected_width; int expected_width;
char *comment; char *comment;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_EANX, -1, "123456789012+12345", 0, 1, 149, "EAN-13 add-on 5" }, /* 0*/ { BARCODE_EANX, -1, "123456789012+12345", 0, 1, 149, "EAN-13 add-on 5" },
/* 1*/ { BARCODE_EANX, -1, "123456789012", 0, 1, 95, "EAN-13 no add-on" }, /* 1*/ { BARCODE_EANX, -1, "123456789012", 0, 1, 95, "EAN-13 no add-on" },
@ -1078,7 +1088,7 @@ static void test_perf(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0; diff_create = diff_encode = diff_buffer = diff_buf_inter = diff_print = 0;
@ -1108,7 +1118,7 @@ static void test_perf(int index, int debug) {
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/); ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buf_inter += clock() - start; diff_buf_inter += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt); assert_zero(ret, "i:%d ZBarcode_Buffer OUT_BUFFER_INTERMEDIATE ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; // Undo symbol->output_options &= ~OUT_BUFFER_INTERMEDIATE; /* Undo */
start = clock(); start = clock();
ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/); ret = ZBarcode_Print(symbol, 0 /*rotate_angle*/);
@ -1128,7 +1138,7 @@ static void test_perf(int index, int debug) {
total_buf_inter += diff_buf_inter; total_buf_inter += diff_buf_inter;
total_print += diff_print; total_print += diff_print;
} }
if (index == -1) { if (p_ctx->index == -1) {
printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals", printf("%*s: encode % 8gms, buffer % 8gms, buf_inter % 8gms, print % 8gms, create % 8gms\n", comment_max, "totals",
TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create)); TEST_PERF_TIME(total_encode), TEST_PERF_TIME(total_buffer), TEST_PERF_TIME(total_buf_inter), TEST_PERF_TIME(total_print), TEST_PERF_TIME(total_create));
} }
@ -1136,17 +1146,17 @@ static void test_perf(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_upce_input", test_upce_input, 1, 0, 1 }, { "test_upce_input", test_upce_input },
{ "test_upca_print", test_upca_print, 1, 0, 1 }, { "test_upca_print", test_upca_print },
{ "test_upca_input", test_upca_input, 1, 0, 1 }, { "test_upca_input", test_upca_input },
{ "test_eanx_input", test_eanx_input, 1, 1, 1 }, { "test_eanx_input", test_eanx_input },
{ "test_isbn_input", test_isbn_input, 1, 1, 1 }, { "test_isbn_input", test_isbn_input },
{ "test_hrt", test_hrt, 1, 0, 1 }, { "test_hrt", test_hrt },
{ "test_vector_same", test_vector_same, 1, 0, 1 }, { "test_vector_same", test_vector_same },
{ "test_encode", test_encode, 1, 1, 1 }, { "test_encode", test_encode },
{ "test_fuzz", test_fuzz, 1, 0, 1 }, { "test_fuzz", test_fuzz },
{ "test_perf", test_perf, 1, 0, 1 }, { "test_perf", test_perf },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -38,7 +38,7 @@ static struct zint_vector_rect *find_rect(struct zint_symbol *symbol, float x, f
return NULL; return NULL;
} }
for (rect = symbol->vector->rectangles; rect != NULL; rect = rect->next) { for (rect = symbol->vector->rectangles; rect != NULL; rect = rect->next) {
//printf("x %.8g, y %.8g, width %.8g, height %.8g\n", rect->x, rect->y, rect->width, rect->height); /* printf("x %.8g, y %.8g, width %.8g, height %.8g\n", rect->x, rect->y, rect->width, rect->height); */
if (rect->x == stripf(x) && rect->y == stripf(y)) { if (rect->x == stripf(x) && rect->y == stripf(y)) {
if (height && width) { if (height && width) {
if (rect->height == stripf(height) && rect->width == stripf(width)) { if (rect->height == stripf(height) && rect->width == stripf(width)) {
@ -68,7 +68,7 @@ static struct zint_vector_circle *find_circle(struct zint_symbol *symbol, float
return NULL; return NULL;
} }
for (circle = symbol->vector->circles; circle != NULL; circle = circle->next) { for (circle = symbol->vector->circles; circle != NULL; circle = circle->next) {
//printf("x %.8g, y %.8g, diamter %.8g\n", circle->x, circle->y, circle->diameter); /* printf("x %.8g, y %.8g, diamter %.8g\n", circle->x, circle->y, circle->diameter); */
if (circle->x == stripf(x) && circle->y == stripf(y)) { if (circle->x == stripf(x) && circle->y == stripf(y)) {
if (diameter) { if (diameter) {
if (circle->diameter == stripf(diameter)) { if (circle->diameter == stripf(diameter)) {
@ -83,7 +83,8 @@ static struct zint_vector_circle *find_circle(struct zint_symbol *symbol, float
return circle; return circle;
} }
static void test_options(int index, int debug) { static void test_options(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -113,7 +114,7 @@ static void test_options(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -145,7 +146,8 @@ static void test_options(int index, int debug) {
testFinish(); testFinish();
} }
static void test_buffer_vector(int index, int generate, int debug) { static void test_buffer_vector(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -300,7 +302,7 @@ static void test_buffer_vector(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -324,7 +326,7 @@ static void test_buffer_vector(int index, int generate, int debug) {
assert_zero(ret, "i:%d ZBarcode_Buffer_Vector(%d) ret %d != 0\n", i, data[i].symbology, ret); assert_zero(ret, "i:%d ZBarcode_Buffer_Vector(%d) ret %d != 0\n", i, data[i].symbology, ret);
assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%d) vector NULL\n", i, data[i].symbology); assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%d) vector NULL\n", i, data[i].symbology);
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, \"%s\", \"%s\", %.8g, %d, %d, %.8g, %.8g },\n", printf(" /*%3d*/ { %s, \"%s\", \"%s\", %.8g, %d, %d, %.8g, %.8g },\n",
i, testUtilBarcodeName(data[i].symbology), data[i].data, data[i].composite, i, testUtilBarcodeName(data[i].symbology), data[i].data, data[i].composite,
symbol->height, symbol->rows, symbol->width, symbol->vector->width, symbol->vector->height); symbol->height, symbol->rows, symbol->width, symbol->vector->width, symbol->vector->height);
@ -344,7 +346,8 @@ static void test_buffer_vector(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_upcean_hrt(int index, int debug) { static void test_upcean_hrt(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -411,7 +414,7 @@ static void test_upcean_hrt(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -440,7 +443,7 @@ static void test_upcean_hrt(int index, int debug) {
assert_equal(symbol->vector->height, data[i].expected_vector_height, "i:%d (%s) symbol->vector->height %.8g != %.8g\n", assert_equal(symbol->vector->height, data[i].expected_vector_height, "i:%d (%s) symbol->vector->height %.8g != %.8g\n",
i, testUtilBarcodeName(data[i].symbology), symbol->vector->height, data[i].expected_vector_height); i, testUtilBarcodeName(data[i].symbology), symbol->vector->height, data[i].expected_vector_height);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) {
sprintf(symbol->outfile, "test_upcean_hrt%d.svg", i); sprintf(symbol->outfile, "test_upcean_hrt%d.svg", i);
ZBarcode_Print(symbol, 0); ZBarcode_Print(symbol, 0);
} }
@ -465,7 +468,8 @@ static void test_upcean_hrt(int index, int debug) {
testFinish(); testFinish();
} }
static void test_row_separator(int index, int debug) { static void test_row_separator(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -504,7 +508,7 @@ static void test_row_separator(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -534,7 +538,8 @@ static void test_row_separator(int index, int debug) {
testFinish(); testFinish();
} }
static void test_stacking(int index, int debug) { static void test_stacking(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -570,7 +575,7 @@ static void test_stacking(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int length2; int length2;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -592,7 +597,7 @@ static void test_stacking(int index, int debug) {
assert_equal(symbol->width, data[i].expected_width, "i:%d (%d) symbol->width %d != %d\n", i, data[i].symbology, symbol->width, data[i].expected_width); assert_equal(symbol->width, data[i].expected_width, "i:%d (%d) symbol->width %d != %d\n", i, data[i].symbology, symbol->width, data[i].expected_width);
if (data[i].expected_separator_y != -1) { if (data[i].expected_separator_y != -1) {
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) {
sprintf(symbol->outfile, "test_stacking_%d.svg", i); sprintf(symbol->outfile, "test_stacking_%d.svg", i);
ZBarcode_Print(symbol, 0); ZBarcode_Print(symbol, 0);
} }
@ -615,7 +620,8 @@ static void test_stacking(int index, int debug) {
testFinish(); testFinish();
} }
static void test_output_options(int index, int debug) { static void test_output_options(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -699,7 +705,7 @@ static void test_output_options(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -724,7 +730,7 @@ static void test_output_options(int index, int debug) {
if (ret < ZINT_ERROR) { if (ret < ZINT_ERROR) {
assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%d) vector NULL\n", i, data[i].symbology); assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%d) vector NULL\n", i, data[i].symbology);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) {
sprintf(symbol->outfile, "test_output_options_%d.svg", i); sprintf(symbol->outfile, "test_output_options_%d.svg", i);
ZBarcode_Print(symbol, 0); ZBarcode_Print(symbol, 0);
} }
@ -755,7 +761,8 @@ static void test_output_options(int index, int debug) {
} }
/* Checks that symbol lead-in (composite offset) isn't used to calc string position for non-composite barcodes */ /* Checks that symbol lead-in (composite offset) isn't used to calc string position for non-composite barcodes */
static void test_noncomposite_string_x(int index, int debug) { static void test_noncomposite_string_x(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -778,7 +785,7 @@ static void test_noncomposite_string_x(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -808,7 +815,8 @@ static void test_noncomposite_string_x(int index, int debug) {
} }
/* Checks UPCA/UPCE main_symbol_width_x (used for addon formatting) set whether whitespace width set or not */ /* Checks UPCA/UPCE main_symbol_width_x (used for addon formatting) set whether whitespace width set or not */
static void test_upcean_whitespace_width(int index, int debug) { static void test_upcean_whitespace_width(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -838,7 +846,7 @@ static void test_upcean_whitespace_width(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -857,7 +865,7 @@ static void test_upcean_whitespace_width(int index, int debug) {
assert_zero(ret, "i:%d ZBarcode_Buffer_Vector(%d) ret %d != 0\n", i, data[i].symbology, ret); assert_zero(ret, "i:%d ZBarcode_Buffer_Vector(%d) ret %d != 0\n", i, data[i].symbology, ret);
assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%d) vector NULL\n", i, data[i].symbology); assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%d) vector NULL\n", i, data[i].symbology);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) {
sprintf(symbol->outfile, "test_upcean_whitespace_width_%d.svg", i); sprintf(symbol->outfile, "test_upcean_whitespace_width_%d.svg", i);
ZBarcode_Print(symbol, 0); ZBarcode_Print(symbol, 0);
} }
@ -880,7 +888,8 @@ static void test_upcean_whitespace_width(int index, int debug) {
testFinish(); testFinish();
} }
static void test_scale(int index, int debug) { static void test_scale(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -925,7 +934,7 @@ static void test_scale(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -955,7 +964,7 @@ static void test_scale(int index, int debug) {
assert_equal(ret, data[i].ret_vector, "i:%d ZBarcode_Buffer_Vector(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret_vector, symbol->errtxt); assert_equal(ret, data[i].ret_vector, "i:%d ZBarcode_Buffer_Vector(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret_vector, symbol->errtxt);
assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%d) vector NULL\n", i, data[i].symbology); assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%d) vector NULL\n", i, data[i].symbology);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) {
sprintf(symbol->outfile, "test_scale_%d.svg", i); sprintf(symbol->outfile, "test_scale_%d.svg", i);
ZBarcode_Print(symbol, 0); ZBarcode_Print(symbol, 0);
} }
@ -986,7 +995,8 @@ static void test_scale(int index, int debug) {
testFinish(); testFinish();
} }
static void test_guard_descent(int index, int debug) { static void test_guard_descent(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1051,7 +1061,7 @@ static void test_guard_descent(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1070,7 +1080,7 @@ static void test_guard_descent(int index, int debug) {
if (ret < ZINT_ERROR) { if (ret < ZINT_ERROR) {
assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%d) vector NULL\n", i, data[i].symbology); assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%d) vector NULL\n", i, data[i].symbology);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { /* ZINT_DEBUG_TEST_PRINT 16 */ if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { /* ZINT_DEBUG_TEST_PRINT 16 */
sprintf(symbol->outfile, "test_guard_descent_%d.svg", i); sprintf(symbol->outfile, "test_guard_descent_%d.svg", i);
ZBarcode_Print(symbol, 0); ZBarcode_Print(symbol, 0);
} }
@ -1095,7 +1105,8 @@ static void test_guard_descent(int index, int debug) {
testFinish(); testFinish();
} }
static void test_quiet_zones(int index, int debug) { static void test_quiet_zones(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -1407,7 +1418,7 @@ static void test_quiet_zones(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -1435,7 +1446,7 @@ static void test_quiet_zones(int index, int debug) {
if (ret < ZINT_ERROR) { if (ret < ZINT_ERROR) {
assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%d) vector NULL\n", i, data[i].symbology); assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%d) vector NULL\n", i, data[i].symbology);
if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { /* ZINT_DEBUG_TEST_PRINT 16 */ if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { /* ZINT_DEBUG_TEST_PRINT 16 */
sprintf(symbol->outfile, "test_quiet_zones_%d.svg", i); sprintf(symbol->outfile, "test_quiet_zones_%d.svg", i);
ZBarcode_Print(symbol, 0); ZBarcode_Print(symbol, 0);
} }
@ -1466,7 +1477,8 @@ static void test_quiet_zones(int index, int debug) {
testFinish(); testFinish();
} }
static void test_height(int index, int generate, int debug) { static void test_height(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -2105,8 +2117,7 @@ static void test_height(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -2137,7 +2148,7 @@ static void test_height(int index, int generate, int debug) {
assert_zero(ret, "i:%d ZBarcode_Buffer_Vector(%s) ret %d != 0 (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt); assert_zero(ret, "i:%d ZBarcode_Buffer_Vector(%s) ret %d != 0 (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt);
assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%s) vector NULL\n", i, testUtilBarcodeName(data[i].symbology)); assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%s) vector NULL\n", i, testUtilBarcodeName(data[i].symbology));
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %.5g, \"%s\", \"%s\", %s, %.8g, %d, %d, %.8g, %.8g, \"%s\" },\n", printf(" /*%3d*/ { %s, %s, %.5g, \"%s\", \"%s\", %s, %.8g, %d, %d, %.8g, %.8g, \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilOutputOptionsName(data[i].output_options), i, testUtilBarcodeName(data[i].symbology), testUtilOutputOptionsName(data[i].output_options),
data[i].height, data[i].data, data[i].composite, testUtilErrorName(data[i].ret), data[i].height, data[i].data, data[i].composite, testUtilErrorName(data[i].ret),
@ -2158,7 +2169,8 @@ static void test_height(int index, int generate, int debug) {
testFinish(); testFinish();
} }
static void test_height_per_row(int index, int generate, int debug) { static void test_height_per_row(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int symbology; int symbology;
@ -2268,8 +2280,7 @@ static void test_height_per_row(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i);
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
@ -2297,7 +2308,7 @@ static void test_height_per_row(int index, int generate, int debug) {
assert_zero(ret, "i:%d ZBarcode_Buffer_Vector(%s) ret %d != 0 (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt); assert_zero(ret, "i:%d ZBarcode_Buffer_Vector(%s) ret %d != 0 (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt);
assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%s) vector NULL\n", i, testUtilBarcodeName(data[i].symbology)); assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%s) vector NULL\n", i, testUtilBarcodeName(data[i].symbology));
if (generate) { if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %d, %d, %d, %.5g, %.5g, \"%s\", \"%s\", %s, %.8g, %d, %d, %.8g, %.8g, \"%s\" },\n", printf(" /*%3d*/ { %s, %s, %d, %d, %d, %.5g, %.5g, \"%s\", \"%s\", %s, %.8g, %d, %d, %.8g, %.8g, \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode),
data[i].option_1, data[i].option_2, data[i].option_3, data[i].height, data[i].scale, data[i].option_1, data[i].option_2, data[i].option_3, data[i].height, data[i].scale,
@ -2321,20 +2332,20 @@ static void test_height_per_row(int index, int generate, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_options", test_options, 1, 0, 1 }, { "test_options", test_options },
{ "test_buffer_vector", test_buffer_vector, 1, 1, 1 }, { "test_buffer_vector", test_buffer_vector },
{ "test_upcean_hrt", test_upcean_hrt, 1, 0, 1 }, { "test_upcean_hrt", test_upcean_hrt },
{ "test_row_separator", test_row_separator, 1, 0, 1 }, { "test_row_separator", test_row_separator },
{ "test_stacking", test_stacking, 1, 0, 1 }, { "test_stacking", test_stacking },
{ "test_output_options", test_output_options, 1, 0, 1 }, { "test_output_options", test_output_options },
{ "test_noncomposite_string_x", test_noncomposite_string_x, 1, 0, 1 }, { "test_noncomposite_string_x", test_noncomposite_string_x },
{ "test_upcean_whitespace_width", test_upcean_whitespace_width, 1, 0, 1 }, { "test_upcean_whitespace_width", test_upcean_whitespace_width },
{ "test_scale", test_scale, 1, 0, 1 }, { "test_scale", test_scale },
{ "test_guard_descent", test_guard_descent, 1, 0, 1 }, { "test_guard_descent", test_guard_descent },
{ "test_quiet_zones", test_quiet_zones, 1, 0, 1 }, { "test_quiet_zones", test_quiet_zones },
{ "test_height", test_height, 1, 1, 1 }, { "test_height", test_height },
{ "test_height_per_row", test_height_per_row, 1, 1, 1 }, { "test_height_per_row", test_height_per_row },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));

View File

@ -64,7 +64,7 @@ static const char *testFunc = NULL;
/* Visual C++ 6 doesn't support variadic args to macros, so make do with functions, which have inferior behaviour, /* Visual C++ 6 doesn't support variadic args to macros, so make do with functions, which have inferior behaviour,
e.g. don't exit on failure, `assert_equal()` type-specific */ e.g. don't exit on failure, `assert_equal()` type-specific */
#if _MSC_VER == 1200 /* VC6 */ #if (defined(_MSC_VER) && _MSC_VER == 1200) || (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199000L) /* VC6 or C89 */
#include <stdarg.h> #include <stdarg.h>
void assert_zero(int exp, const char *fmt, ...) { void assert_zero(int exp, const char *fmt, ...) {
assertionNum++; assertionNum++;
@ -174,32 +174,84 @@ void testReport(void) {
} }
} }
/* Verifies that a string `src` (length <= 9) only uses digits. On success returns value in `p_val` */
static int validate_int(const char src[], int *p_val) {
int val = 0;
int i;
const int length = (int) strlen(src);
if (length > 9) { /* Prevent overflow */
return 0;
}
for (i = 0; i < length; i++) {
if (src[i] < '0' || src[i] > '9') {
return 0;
}
val *= 10;
val += src[i] - '0';
}
*p_val = val;
return 1;
}
/* Verifies that a string `src` only uses digits or a comma-separated range of digits.
On success returns value in `p_val` and if present a range end value in `p_val_end` */
static int validate_int_range(const char src[], int *p_val, int *p_val_end) {
int val = 0;
int val_end = -1;
const int length = (int) strlen(src);
int i, j;
for (i = 0; i < length; i++) {
if (src[i] < '0' || src[i] > '9') {
if (src[i] != ',') {
return 0;
}
val_end = 0;
for (j = i + 1; j < length; j++) {
if (src[j] < '0' || src[j] > '9') {
return 0;
}
if (j - (i + 1) >= 9) { /* Prevent overflow */
return 0;
}
val_end *= 10;
val_end += src[j] - '0';
}
break;
}
if (i >= 9) { /* Prevent overflow */
return 0;
}
val *= 10;
val += src[i] - '0';
}
*p_val = val;
*p_val_end = val_end;
return 1;
}
/* Begin test program, parse args */ /* Begin test program, parse args */
void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size) { void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size) {
int i, opt, ran; int i, ran;
long long_opt; char *optarg;
char *optarg_endptr = NULL;
int debug = 0;
char *func = NULL; char *func = NULL;
char func_buf[256 + 5]; char func_buf[256 + 5];
int index = -1; testCtx ctx;
int generate = 0;
typedef void (*func_void)(void); ctx.index = ctx.index_end = ctx.exclude = ctx.exclude_end = -1;
typedef void (*func_debug)(int debug); ctx.generate = ctx.debug = 0;
typedef void (*func_index)(int index);
typedef void (*func_index_debug)(int index, int debug);
typedef void (*func_generate)(int generate);
typedef void (*func_generate_debug)(int generate, int debug);
typedef void (*func_index_generate)(int index, int generate);
typedef void (*func_index_generate_debug)(int index, int generate, int debug);
if (argc) { if (argc) {
char *filename = strrchr(argv[0], '/'); const char *filename;
#ifdef _WIN32 #ifdef _WIN32
if (filename == NULL) { if ((filename = strrchr(argv[0], '\\')) == NULL) {
filename = strrchr(argv[0], '\\'); filename = strrchr(argv[0], '/');
} }
#else
filename = strrchr(argv[0], '/');
#endif #endif
if (filename) { if (filename) {
assertionFilename = filename + 1; assertionFilename = filename + 1;
@ -208,19 +260,22 @@ void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size) {
} }
} }
while ((opt = getopt(argc, argv, "d:f:gi:")) != -1) { for (i = 1; i < argc; i++) {
switch (opt) { if (strcmp(argv[i], "-d") == 0) {
case 'd': if (i + 1 == argc) {
errno = 0; fprintf(stderr, "testRun: -d debug value missing, ignored\n");
long_opt = strtol(optarg, &optarg_endptr, 10);
if (errno || optarg_endptr == optarg || long_opt < 0 || long_opt > INT_MAX) {
fprintf(stderr, "testRun: -d debug value invalid\n");
debug = 0;
} else { } else {
debug = long_opt; optarg = argv[++i];
if (!validate_int(optarg, &ctx.debug)) {
fprintf(stderr, "testRun: -d debug value invalid, ignored\n");
ctx.debug = 0;
} }
break; }
case 'f': } else if (strcmp(argv[i], "-f") == 0) {
if (i + 1 == argc) {
fprintf(stderr, "testRun: -f func value missing, ignored\n");
} else {
optarg = argv[++i];
if (strlen(optarg) < 256) { if (strlen(optarg) < 256) {
if (strncmp(optarg, "test_", 5) == 0) { if (strncmp(optarg, "test_", 5) == 0) {
strcpy(func_buf, optarg); strcpy(func_buf, optarg);
@ -230,23 +285,34 @@ void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size) {
} }
func = func_buf; func = func_buf;
} else { } else {
fprintf(stderr, "testRun: -f func value too long\n"); fprintf(stderr, "testRun: -f func value too long, ignored\n");
func = NULL; func = NULL;
} }
break;
case 'g':
generate = 1;
break;
case 'i':
errno = 0;
long_opt = strtol(optarg, &optarg_endptr, 10);
if (errno || optarg_endptr == optarg || long_opt < 0 || long_opt > INT_MAX) {
fprintf(stderr, "testRun: -i index value invalid\n");
index = -1;
} else {
index = long_opt;
} }
break; } else if (strcmp(argv[i], "-g") == 0) {
ctx.generate = 1;
} else if (strcmp(argv[i], "-i") == 0) {
if (i + 1 == argc) {
fprintf(stderr, "testRun: -i index value missing, ignored\n");
} else {
optarg = argv[++i];
if (!validate_int_range(optarg, &ctx.index, &ctx.index_end)) {
fprintf(stderr, "testRun: -i index value invalid, ignored\n");
ctx.index = ctx.index_end = -1;
}
}
} else if (strcmp(argv[i], "-x") == 0) {
if (i + 1 == argc) {
fprintf(stderr, "testRun: -x exclude value missing, ignored\n");
} else {
optarg = argv[++i];
if (!validate_int_range(optarg, &ctx.exclude, &ctx.exclude_end)) {
fprintf(stderr, "testRun: -x exclude value invalid, ignored\n");
ctx.exclude = ctx.exclude_end = -1;
}
}
} else {
fprintf(stderr, "testRun: unknown arg '%s', ignored\n", argv[i]);
} }
} }
@ -255,35 +321,7 @@ void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size) {
if (func && strcmp(func, funcs[i].name) != 0) { if (func && strcmp(func, funcs[i].name) != 0) {
continue; continue;
} }
if (funcs[i].has_index && funcs[i].has_generate && funcs[i].has_debug) { (*funcs[i].func)(&ctx);
(*(func_index_generate_debug)funcs[i].func)(index, generate, debug);
} else if (funcs[i].has_index && funcs[i].has_generate) {
if (debug) fprintf(stderr, "testRun %s: -d ignored\n", funcs[i].name);
(*(func_index_generate)funcs[i].func)(index, generate);
} else if (funcs[i].has_index && funcs[i].has_debug) {
if (generate) fprintf(stderr, "testRun %s: -g ignored\n", funcs[i].name);
(*(func_index_debug)funcs[i].func)(index, debug);
} else if (funcs[i].has_index) {
if (generate) fprintf(stderr, "testRun %s: -g ignored\n", funcs[i].name);
if (debug) fprintf(stderr, "testRun %s: -d ignored\n", funcs[i].name);
(*(func_index)funcs[i].func)(index);
} else if (funcs[i].has_generate && funcs[i].has_debug) {
if (index != -1) fprintf(stderr, "testRun %s: -i index ignored\n", funcs[i].name);
(*(func_generate_debug)funcs[i].func)(generate, debug);
} else if (funcs[i].has_generate) {
if (index != -1) fprintf(stderr, "testRun %s: -i index ignored\n", funcs[i].name);
if (debug) fprintf(stderr, "testRun %s: -d ignored\n", funcs[i].name);
(*(func_generate)funcs[i].func)(generate);
} else if (funcs[i].has_debug) {
if (index != -1) fprintf(stderr, "testRun %s: -i index ignored\n", funcs[i].name);
if (generate) fprintf(stderr, "testRun %s -g ignored\n", funcs[i].name);
(*(func_debug)funcs[i].func)(debug);
} else {
if (index != -1) fprintf(stderr, "testRun %s: -i index ignored\n", funcs[i].name);
if (generate) fprintf(stderr, "testRun %s -g ignored\n", funcs[i].name);
if (debug) fprintf(stderr, "testRun %s: -d ignored\n", funcs[i].name);
(*(func_void)funcs[i].func)();
}
ran++; ran++;
} }
@ -292,6 +330,32 @@ void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size) {
} }
} }
/* Call in a dataset loop to determine if a datum should be tested according to -i & -x args */
int testContinue(const testCtx *const p_ctx, const int i) {
if (p_ctx->index != -1) {
if (p_ctx->index_end != -1) {
if (i < p_ctx->index || (p_ctx->index_end && i > p_ctx->index_end)) {
return 1;
}
} else if (i != p_ctx->index) {
return 1;
}
}
if (p_ctx->exclude != -1) {
if (p_ctx->exclude_end != -1) {
if (i >= p_ctx->exclude && (p_ctx->exclude_end == 0 || i <= p_ctx->exclude_end)) {
return 1;
}
} else if (i == p_ctx->exclude) {
return 1;
}
}
if ((p_ctx->debug & ZINT_DEBUG_TEST_PRINT) && !(p_ctx->debug & ZINT_DEBUG_TEST_LESS_NOISY)) {
printf("i:%d\n", i);
}
return 0;
}
/* Helper to set common symbol fields */ /* Helper to set common symbol fields */
int testUtilSetSymbol(struct zint_symbol *symbol, int symbology, int input_mode, int eci, int option_1, int option_2, int testUtilSetSymbol(struct zint_symbol *symbol, int symbology, int input_mode, int eci, int option_1, int option_2,
int option_3, int output_options, char *data, int length, int debug) { int option_3, int output_options, char *data, int length, int debug) {

View File

@ -37,6 +37,10 @@
#ifndef Z_TESTCOMMON_H #ifndef Z_TESTCOMMON_H
#define Z_TESTCOMMON_H #define Z_TESTCOMMON_H
#ifdef __cplusplus
extern "C" {
#endif
#define ZINT_DEBUG_TEST_PRINT 16 #define ZINT_DEBUG_TEST_PRINT 16
#define ZINT_DEBUG_TEST_LESS_NOISY 32 #define ZINT_DEBUG_TEST_LESS_NOISY 32
#define ZINT_DEBUG_TEST_KEEP_OUTFILE 64 #define ZINT_DEBUG_TEST_KEEP_OUTFILE 64
@ -53,6 +57,10 @@
#define testutil_pclose(stream) _pclose(stream) #define testutil_pclose(stream) _pclose(stream)
#else #else
#include <unistd.h> #include <unistd.h>
# if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199000L /* C89 */
extern FILE *popen(const char *command, const char *type);
extern int pclose(FILE *stream);
# endif
#define testutil_popen(command, mode) popen(command, mode) #define testutil_popen(command, mode) popen(command, mode)
#define testutil_pclose(stream) pclose(stream) #define testutil_pclose(stream) pclose(stream)
#endif #endif
@ -64,15 +72,11 @@
# pragma warning(disable: 4305) /* truncation from 'double' to 'float' */ # pragma warning(disable: 4305) /* truncation from 'double' to 'float' */
#endif #endif
#ifdef __cplusplus
extern "C" {
#endif
extern int assertionFailed; extern int assertionFailed;
extern int assertionNum; extern int assertionNum;
extern const char *assertionFilename; extern const char *assertionFilename;
#if _MSC_VER < 1900 /* MSVC 2015 */ #if defined(_MSC_VER) && _MSC_VER < 1900 /* MSVC 2015 */
#define testStart(__arg__) (testStartReal("", __arg__)) #define testStart(__arg__) (testStartReal("", __arg__))
#else #else
#define testStart(__arg__) (testStartReal(__func__, __arg__)) #define testStart(__arg__) (testStartReal(__func__, __arg__))
@ -82,19 +86,29 @@ void testFinish(void);
void testSkip(const char *msg); void testSkip(const char *msg);
void testReport(void); void testReport(void);
typedef struct s_testCtx {
int index;
int index_end;
int exclude;
int exclude_end;
int generate;
int debug;
} testCtx;
typedef void (*testFunc_t)(const testCtx *const p_ctx);
typedef struct s_testFunction { typedef struct s_testFunction {
const char *name; void *func; int has_index; int has_generate; int has_debug; const char *name; testFunc_t func;
} testFunction; } testFunction;
void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size); void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size);
int testContinue(const testCtx *const p_ctx, const int i);
#if _MSC_VER == 1200 /* VC6 */ #if (defined(_MSC_VER) &&_MSC_VER == 1200) || (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199000L) /* VC6 or C89 */
void assert_zero(int exp, const char *fmt, ...); void assert_zero(int exp, const char *fmt, ...);
void assert_nonzero(int exp, const char *fmt, ...); void assert_nonzero(int exp, const char *fmt, ...);
void assert_null(const void *exp, const char *fmt, ...); void assert_null(const void *exp, const char *fmt, ...);
void assert_nonnull(const void *exp, const char *fmt, ...); void assert_nonnull(const void *exp, const char *fmt, ...);
void assert_equal(int e1, int e2, const char *fmt, ...); void assert_equal(int e1, int e2, const char *fmt, ...);
void assert_equalu64(uint64_t e1, uint64_t e2, const char *fmt, ...); void assert_equalu64(uint64_t e1, uint64_t e2, const char *fmt, ...);
void assert_notequal(int e1, int e2, ...); void assert_notequal(int e1, int e2, const char *fmt, ...);
#else #else
#define assert_exp(__exp__, ...) \ #define assert_exp(__exp__, ...) \
{ assertionNum++; if (!(__exp__)) { assertionFailed++; printf("%s:%d ", assertionFilename, __LINE__); \ { assertionNum++; if (!(__exp__)) { assertionFailed++; printf("%s:%d ", assertionFilename, __LINE__); \

View File

@ -269,7 +269,8 @@ static void arg_output_options(char *cmd, int output_options) {
} }
// Tests args that can be detected with `--dump` // Tests args that can be detected with `--dump`
static void test_dump_args(int index, int debug) { static void test_dump_args(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int b; int b;
@ -354,7 +355,7 @@ static void test_dump_args(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
strcpy(cmd, "zint --dump"); strcpy(cmd, "zint --dump");
if (debug & ZINT_DEBUG_PRINT) { if (debug & ZINT_DEBUG_PRINT) {
@ -398,7 +399,8 @@ static void test_dump_args(int index, int debug) {
} }
// Tests segs // Tests segs
static void test_dump_segs(int index, int debug) { static void test_dump_segs(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int b; int b;
@ -431,7 +433,7 @@ static void test_dump_segs(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
strcpy(cmd, "zint --dump"); strcpy(cmd, "zint --dump");
if (debug & ZINT_DEBUG_PRINT) { if (debug & ZINT_DEBUG_PRINT) {
@ -468,7 +470,8 @@ static void test_dump_segs(int index, int debug) {
testFinish(); testFinish();
} }
static void test_input(int index, int debug) { static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
#define TEST_INPUT_LONG "test_67890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" #define TEST_INPUT_LONG "test_67890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
@ -527,8 +530,7 @@ static void test_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
int j; int j;
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
#ifdef _WIN32 #ifdef _WIN32
if (data[i].outfile && (int) strlen(data[i].outfile) > 50) { if (data[i].outfile && (int) strlen(data[i].outfile) > 50) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("%d not Windows compatible (outfile length %d > 50)\n", i, (int) strlen(data[i].outfile)); if (debug & ZINT_DEBUG_TEST_PRINT) printf("%d not Windows compatible (outfile length %d > 50)\n", i, (int) strlen(data[i].outfile));
@ -564,7 +566,8 @@ static void test_input(int index, int debug) {
testFinish(); testFinish();
} }
static void test_stdin_input(int index, int debug) { static void test_stdin_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int b; int b;
@ -588,7 +591,7 @@ static void test_stdin_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
sprintf(cmd, "echo '%s' | zint", data[i].data); sprintf(cmd, "echo '%s' | zint", data[i].data);
if (debug & ZINT_DEBUG_PRINT) { if (debug & ZINT_DEBUG_PRINT) {
@ -609,7 +612,8 @@ static void test_stdin_input(int index, int debug) {
} }
// Note ordering of `--batch` before/after data/input args affects error messages // Note ordering of `--batch` before/after data/input args affects error messages
static void test_batch_input(int index, int debug) { static void test_batch_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int b; int b;
@ -640,7 +644,7 @@ static void test_batch_input(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
strcpy(cmd, "zint --dump --batch"); strcpy(cmd, "zint --dump --batch");
if (debug & ZINT_DEBUG_PRINT) { if (debug & ZINT_DEBUG_PRINT) {
@ -668,7 +672,8 @@ static void test_batch_input(int index, int debug) {
testFinish(); testFinish();
} }
static void test_batch_large(int index, int debug) { static void test_batch_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int b; int b;
@ -703,8 +708,7 @@ static void test_batch_large(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
strcpy(cmd, "zint --batch --filetype=gif"); strcpy(cmd, "zint --batch --filetype=gif");
if (debug & ZINT_DEBUG_PRINT) { if (debug & ZINT_DEBUG_PRINT) {
@ -733,7 +737,8 @@ static void test_batch_large(int index, int debug) {
testFinish(); testFinish();
} }
static void test_checks(int index, int debug) { static void test_checks(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int addongap; int addongap;
@ -809,7 +814,7 @@ static void test_checks(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
strcpy(cmd, "zint -d 1 --filetype=gif"); strcpy(cmd, "zint -d 1 --filetype=gif");
if (debug & ZINT_DEBUG_PRINT) { if (debug & ZINT_DEBUG_PRINT) {
@ -849,7 +854,8 @@ static void test_checks(int index, int debug) {
testFinish(); testFinish();
} }
static void test_barcode_symbology(int index, int debug) { static void test_barcode_symbology(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
const char *bname; const char *bname;
@ -1070,7 +1076,7 @@ static void test_barcode_symbology(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
strcpy(cmd, "zint --filetype=gif"); strcpy(cmd, "zint --filetype=gif");
strcat(cmd, " --verbose"); strcat(cmd, " --verbose");
@ -1091,7 +1097,8 @@ static void test_barcode_symbology(int index, int debug) {
testFinish(); testFinish();
} }
static void test_other_opts(int index, int debug) { static void test_other_opts(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int b; int b;
@ -1168,7 +1175,7 @@ static void test_other_opts(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
strcpy(cmd, "zint"); strcpy(cmd, "zint");
@ -1197,7 +1204,8 @@ static void test_other_opts(int index, int debug) {
testFinish(); testFinish();
} }
static void test_exit_status(int index, int debug) { static void test_exit_status(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item { struct item {
int b; int b;
@ -1232,7 +1240,7 @@ static void test_exit_status(int index, int debug) {
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (testContinue(p_ctx, i)) continue;
strcpy(cmd, "zint"); strcpy(cmd, "zint");
*buf = '\0'; *buf = '\0';
@ -1260,17 +1268,17 @@ static void test_exit_status(int index, int debug) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func */
{ "test_dump_args", test_dump_args, 1, 0, 1 }, { "test_dump_args", test_dump_args },
{ "test_dump_segs", test_dump_segs, 1, 0, 1 }, { "test_dump_segs", test_dump_segs },
{ "test_input", test_input, 1, 0, 1 }, { "test_input", test_input },
{ "test_stdin_input", test_stdin_input, 1, 0, 1 }, { "test_stdin_input", test_stdin_input },
{ "test_batch_input", test_batch_input, 1, 0, 1 }, { "test_batch_input", test_batch_input },
{ "test_batch_large", test_batch_large, 1, 0, 1 }, { "test_batch_large", test_batch_large },
{ "test_checks", test_checks, 1, 0, 1 }, { "test_checks", test_checks },
{ "test_barcode_symbology", test_barcode_symbology, 1, 0, 1 }, { "test_barcode_symbology", test_barcode_symbology },
{ "test_other_opts", test_other_opts, 1, 0, 1 }, { "test_other_opts", test_other_opts },
{ "test_exit_status", test_exit_status, 1, 0, 1 }, { "test_exit_status", test_exit_status },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));