mirror of
https://git.code.sf.net/p/zint/code
synced 2025-05-31 07:08:26 -04:00
CODEONE/DATAMATRIX/MAILMARK/PLESSEY: fix some 32-bit/portability bugs
PLESSEY: add options NCR weighted mod-10, hide check digit(s) in HRT test suite: now runnable under MSVC 2019, 2017, 2015, MinGW/MSYS win32/README: update with MSVC 2019 and CMake instructions
This commit is contained in:
parent
f471bb6e50
commit
4a8cac2a5a
63 changed files with 1189 additions and 983 deletions
|
@ -1,4 +1,4 @@
|
|||
# Copyright (C) 2019 - 2021 Robin Stuart <rstuart114@gmail.com>
|
||||
# Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com>
|
||||
# Adapted from qrencode/tests/CMakeLists.txt
|
||||
# Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
|
||||
# vim: set ts=4 sw=4 et :
|
||||
|
@ -22,6 +22,7 @@ if(NOT EXISTS ${BWIPP_PS})
|
|||
execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xf ${BWIPP_TAR}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tools)
|
||||
endif()
|
||||
configure_file(${BWIPP_PS} ${CMAKE_CURRENT_BINARY_DIR}/tools/bwipp_dump.ps COPYONLY)
|
||||
|
||||
set(testcommon_SRCS testcommon.c testcommon.h)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Zint backend test suite
|
||||
-----------------------
|
||||
|
||||
In order to build the zint testsuite, zint has to be compiled with the
|
||||
In order to build the zint test suite, zint has to be compiled with the
|
||||
ZINT_TEST option enabled:
|
||||
|
||||
cd <project-dir>
|
||||
|
@ -12,50 +12,53 @@ ZINT_TEST option enabled:
|
|||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
In order to run the testsuite, the path of the zint library needs to be
|
||||
communicated to the runtime linker. On UNIX like systems, this is done
|
||||
by exporting LD_LIBRARY_PATH to the path containing the zint library,
|
||||
which is <build-dir>/backend:
|
||||
In order to run the test suite, the path of the zint library may need to be
|
||||
communicated to the runtime linker. On UNIX-like systems, this is done by
|
||||
exporting LD_LIBRARY_PATH to the path containing the zint library, which is
|
||||
<build-dir>/backend:
|
||||
|
||||
cd <project-dir>
|
||||
cd build
|
||||
export LD_LIBRARY_PATH=$(pwd)/backend
|
||||
|
||||
|
||||
Setting LD_LIBRARY_PATH is not required if the zint library to be tested is
|
||||
installed into a system library path ( /usr/lib for example ) prior to running
|
||||
the tests.
|
||||
|
||||
To run all tests (within <build-dir>/backend/tests):
|
||||
|
||||
To run all tests (within <build-dir>):
|
||||
|
||||
ctest
|
||||
|
||||
To run individual tests, eg:
|
||||
For various useful options, e.g. matching (-R) and excluding (-E) tests, see
|
||||
https://cmake.org/cmake/help/latest/manual/ctest.1.html#options
|
||||
|
||||
./test_common
|
||||
./test_vector
|
||||
Tests can also be run individually, eg:
|
||||
|
||||
backend/tests/test_common
|
||||
backend/tests/test_vector
|
||||
|
||||
To run a single test function within an individual test, use '-f <func-name>':
|
||||
|
||||
./test_common -f utf8_to_unicode
|
||||
./test_dotcode -f input
|
||||
backend/tests/test_common -f utf8_to_unicode
|
||||
backend/tests/test_dotcode -f input
|
||||
|
||||
To run a single dataset item in a single test function, use '-i <index>':
|
||||
|
||||
./test_dotcode -f input -i 2
|
||||
backend/tests/test_dotcode -f input -i 2
|
||||
|
||||
To show debug info (if any), use '-d <flag>':
|
||||
|
||||
./test_dotcode -f input -i 2 -d 1
|
||||
backend/tests/test_dotcode -f input -i 2 -d 1
|
||||
|
||||
(for other flags see <project-dir>/backend/tests/testcommon.h)
|
||||
|
||||
To generate test data, use '-g':
|
||||
|
||||
./test_dotcode -f encode -g
|
||||
backend/tests/test_dotcode -f encode -g
|
||||
|
||||
To run a test against BWIPP (if any), use '-d 128':
|
||||
|
||||
./test_composite -d 128
|
||||
backend/tests/test_composite -d 128
|
||||
|
||||
(see also <project-dir>/backend/tests/tools/run_bwipp_tests.sh)
|
||||
|
||||
|
@ -64,13 +67,13 @@ To run a test against BWIPP (if any), use '-d 128':
|
|||
If the zint library was built with static linkage support, i.e. ZINT_STATIC
|
||||
is ON, an additional test executable, which uses the zint-static library, will
|
||||
be built. The static variant of each test shares the test name, but has a
|
||||
"-static" suffix. For example,
|
||||
"-static" suffix. For example,
|
||||
|
||||
./test_dotcode
|
||||
backend/tests/test_dotcode
|
||||
|
||||
would run the dotcode test that uses the shared zint library, while
|
||||
|
||||
./test_dotcode-static
|
||||
backend/tests/test_dotcode-static
|
||||
|
||||
runs the same test built against the zint-static library.
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ static void test_big5_utf8(int index) {
|
|||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
|
||||
struct item data[] = {
|
||||
/* 0*/ { "_", -1, 0, 1, { 0xA1C4 }, "" },
|
||||
/* 1*/ { "╴", -1, ZINT_ERROR_INVALID_DATA, -1, {}, "" },
|
||||
/* 1*/ { "╴", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "" },
|
||||
};
|
||||
|
||||
int data_size = sizeof(data) / sizeof(struct item);
|
||||
|
@ -135,7 +135,7 @@ static void test_big5_utf8(int index) {
|
|||
assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol.errtxt);
|
||||
if (ret == 0) {
|
||||
assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length);
|
||||
for (int j = 0; j < (int) ret_length; j++) {
|
||||
for (int j = 0; j < ret_length; j++) {
|
||||
assert_equal(b5data[j], data[i].expected_b5data[j], "i:%d b5data[%d] %04X != %04X\n", i, j, b5data[j], data[i].expected_b5data[j]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,8 +142,8 @@ static void test_print(int index, int generate, int debug) {
|
|||
|
||||
if (generate) {
|
||||
if (!testUtilExists(data_dir)) {
|
||||
ret = mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
|
||||
ret = testutil_mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -780,8 +780,9 @@ static void test_utf8_to_eci_ucs2be(void) {
|
|||
int length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
|
||||
int out_length = length;
|
||||
int eci_length = get_eci_length(data[i].eci, (const unsigned char *) data[i].data, length);
|
||||
char *dest = alloca(eci_length + 1);
|
||||
char dest[1024];
|
||||
|
||||
assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length);
|
||||
ret = utf8_to_eci(data[i].eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length);
|
||||
assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret);
|
||||
if (ret == 0) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com>
|
||||
Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
@ -80,8 +80,8 @@ static void test_print(int index, int generate, int debug) {
|
|||
|
||||
if (generate) {
|
||||
if (!testUtilExists(data_dir)) {
|
||||
ret = mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
|
||||
ret = testutil_mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com>
|
||||
Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
@ -32,6 +32,19 @@
|
|||
#include "testcommon.h"
|
||||
#include "../large.h"
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
# define LX_FMT "I64"
|
||||
# if defined(__clang__)
|
||||
# pragma GCC diagnostic ignored "-Wformat-non-iso"
|
||||
# elif defined(__GNUC__)
|
||||
# pragma GCC diagnostic ignored "-Wformat" /* Unfortunately doesn't seem to be way to only avoid non-ISO warnings */
|
||||
# endif
|
||||
#elif defined(_MSC_VER)
|
||||
# define LX_FMT "ll"
|
||||
#else
|
||||
# define LX_FMT "l"
|
||||
#endif
|
||||
|
||||
#define LI(l, h) { l, h }
|
||||
|
||||
int clz_u64(uint64_t x);
|
||||
|
@ -181,7 +194,7 @@ static void test_clz_u64(int index) {
|
|||
if (index != -1 && i != index) continue;
|
||||
|
||||
ret = clz_u64(data[i].s);
|
||||
assert_equal(ret, data[i].ret, "i:%d 0x%lX 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);
|
||||
}
|
||||
|
||||
testFinish();
|
||||
|
@ -214,9 +227,9 @@ static void test_load(int index) {
|
|||
|
||||
large_load(&data[i].t, &data[i].s);
|
||||
|
||||
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%lX (%s) != expected lo 0x%lX (%s)\n",
|
||||
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n",
|
||||
i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump));
|
||||
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%lX (%s) != expected hi 0x%lX (%s)\n",
|
||||
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n",
|
||||
i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump));
|
||||
}
|
||||
|
||||
|
@ -254,9 +267,9 @@ static void test_load_str_u64(int index) {
|
|||
|
||||
large_load_str_u64(&data[i].t, (unsigned char *) data[i].s, data[i].length == -1 ? (int) strlen(data[i].s) : data[i].length);
|
||||
|
||||
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%lX (%s) != expected lo 0x%lX (%s)\n",
|
||||
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n",
|
||||
i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump));
|
||||
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%lX (%s) != expected hi 0x%lX (%s)\n",
|
||||
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n",
|
||||
i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump));
|
||||
}
|
||||
|
||||
|
@ -297,9 +310,9 @@ static void test_add_u64(int index) {
|
|||
|
||||
large_add_u64(&data[i].t, data[i].s);
|
||||
|
||||
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%lX (%s) != expected lo 0x%lX (%s)\n",
|
||||
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n",
|
||||
i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump));
|
||||
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%lX (%s) != expected hi 0x%lX (%s)\n",
|
||||
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n",
|
||||
i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump));
|
||||
}
|
||||
|
||||
|
@ -340,9 +353,9 @@ static void test_sub_u64(int index) {
|
|||
|
||||
large_sub_u64(&data[i].t, data[i].s);
|
||||
|
||||
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%lX (%s) != expected lo 0x%lX (%s)\n",
|
||||
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n",
|
||||
i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump));
|
||||
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%lX (%s) != expected hi 0x%lX (%s)\n",
|
||||
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n",
|
||||
i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump));
|
||||
}
|
||||
|
||||
|
@ -396,9 +409,9 @@ static void test_mul_u64(int index) {
|
|||
|
||||
large_mul_u64(&data[i].t, data[i].s);
|
||||
|
||||
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%lX (%s) != expected lo 0x%lX (%s)\n",
|
||||
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n",
|
||||
i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump));
|
||||
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%lX (%s) != expected hi 0x%lX (%s)\n",
|
||||
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n",
|
||||
i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump));
|
||||
}
|
||||
|
||||
|
@ -520,10 +533,11 @@ static void test_div_u64(int index) {
|
|||
|
||||
r = large_div_u64(&data[i].t, data[i].s);
|
||||
|
||||
assert_equal(r, data[i].expected_r, "i:%d r %lu (0x%lX) != expected_r %lu (0x%lX)\n", i, r, r, data[i].expected_r, data[i].expected_r);
|
||||
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%lX (%s) != expected lo 0x%lX (%s)\n",
|
||||
assert_equal(r, data[i].expected_r, "i:%d r %" LX_FMT "u (0x%" LX_FMT "X) != expected_r %" LX_FMT "u (0x%" LX_FMT "X)\n",
|
||||
i, r, r, data[i].expected_r, data[i].expected_r);
|
||||
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n",
|
||||
i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump));
|
||||
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%lX (%s) != expected hi 0x%lX (%s)\n",
|
||||
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n",
|
||||
i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump));
|
||||
}
|
||||
|
||||
|
@ -684,9 +698,9 @@ static void test_unset_bit(int index) {
|
|||
|
||||
large_unset_bit(&data[i].t, data[i].s);
|
||||
|
||||
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%lX (%s) != expected lo 0x%lX (%s)\n",
|
||||
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n",
|
||||
i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump));
|
||||
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%lX (%s) != expected hi 0x%lX (%s)\n",
|
||||
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n",
|
||||
i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump));
|
||||
}
|
||||
|
||||
|
@ -848,8 +862,8 @@ static void test_dump(int index) {
|
|||
|
||||
large_dump(&data[i].t, dump);
|
||||
|
||||
assert_zero(strcmp(dump, data[i].expected), "i:%d { %lX, %lX } strcmp(%s, %s) != 0\n",
|
||||
i, (unsigned long) data[i].t.lo, (unsigned long) data[i].t.hi, dump, data[i].expected);
|
||||
assert_zero(strcmp(dump, data[i].expected), "i:%d { %" LX_FMT "X, %" LX_FMT "X } strcmp(%s, %s) != 0\n",
|
||||
i, data[i].t.lo, data[i].t.hi, dump, data[i].expected);
|
||||
}
|
||||
|
||||
testFinish();
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include "testcommon.h"
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
static void test_checks(int index, int debug) {
|
||||
|
||||
|
@ -265,7 +264,7 @@ static void test_escape_char_process(int index, int generate, int debug) {
|
|||
FILE *fp;
|
||||
fp = fopen(input_filename, "wb");
|
||||
assert_nonnull(fp, "i:%d fopen(%s) failed\n", i, input_filename);
|
||||
assert_nonzero(fputs(data[i].data, fp), "i%d fputs(%s) failed\n", i, data[i].data);
|
||||
assert_notequal(fputs(data[i].data, fp), EOF, "i%d fputs(%s) failed == EOF (%d)\n", i, data[i].data, ferror(fp));
|
||||
assert_zero(fclose(fp), "i%d fclose() failed\n", i);
|
||||
|
||||
struct zint_symbol *symbol2 = ZBarcode_Create();
|
||||
|
@ -282,7 +281,7 @@ static void test_escape_char_process(int index, int generate, int debug) {
|
|||
ret = testUtilSymbolCmp(symbol2, symbol);
|
||||
assert_zero(ret, "i:%d testUtilSymbolCmp symbol2 ret %d != 0\n", i, ret);
|
||||
|
||||
assert_zero(remove(input_filename), "i:%d remove(%s) != 0 (%d)\n", i, input_filename, errno);
|
||||
assert_zero(remove(input_filename), "i:%d remove(%s) != 0 (%d: %s)\n", i, input_filename, errno, strerror(errno));
|
||||
|
||||
ZBarcode_Delete(symbol2);
|
||||
}
|
||||
|
@ -334,6 +333,10 @@ static void test_encode_file_length(void) {
|
|||
|
||||
testStart("");
|
||||
|
||||
#ifdef _WIN32
|
||||
testSkip("Test not compatible with Windows");
|
||||
return;
|
||||
#else
|
||||
int ret;
|
||||
char filename[] = "in.bin";
|
||||
char buf[ZINT_MAX_DATA_LEN + 1] = {0};
|
||||
|
@ -346,41 +349,42 @@ static void test_encode_file_length(void) {
|
|||
|
||||
// Empty file
|
||||
fd = creat(filename, S_IRUSR);
|
||||
assert_nonzero(fd, "Empty input file not created\n");
|
||||
assert_zero(close(fd), "Empty close(%s) != 0\n", filename);
|
||||
assert_notequal(fd, -1, "Empty input file (%s) not created == -1 (%d: %s)\n", filename, errno, strerror(errno));
|
||||
assert_zero(close(fd), "Empty close(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
|
||||
|
||||
ret = ZBarcode_Encode_File(symbol, filename);
|
||||
assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File empty ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt);
|
||||
|
||||
assert_zero(remove(filename), "remove(%s) != 0\n", filename);
|
||||
assert_zero(remove(filename), "remove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
|
||||
|
||||
// Too large file
|
||||
fd = creat(filename, S_IRUSR | S_IWUSR);
|
||||
assert_nonzero(fd, "Too large input file not created\n");
|
||||
assert_notequal(fd, -1, "Too large input file (%s) not created == -1 (%d: %s)\n", filename, errno, strerror(errno));
|
||||
ret = write(fd, buf, sizeof(buf));
|
||||
assert_equal(ret, sizeof(buf), "Too large write ret %d != %d\n", ret, (int) sizeof(buf));
|
||||
assert_zero(close(fd), "Too large close(%s) != 0\n", filename);
|
||||
assert_zero(close(fd), "Too large close(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
|
||||
|
||||
ret = ZBarcode_Encode_File(symbol, filename);
|
||||
assert_equal(ret, ZINT_ERROR_TOO_LONG, "ZBarcode_Encode_File too large ret %d != ZINT_ERROR_TOO_LONG (%s)\n", ret, symbol->errtxt);
|
||||
|
||||
assert_zero(remove(filename), "remove(%s) != 0\n", filename);
|
||||
assert_zero(remove(filename), "remove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
|
||||
|
||||
// Unreadable file
|
||||
fd = creat(filename, S_IWUSR);
|
||||
assert_nonzero(fd, "Unreadable input file not created\n");
|
||||
assert_notequal(fd, -1, "Unreadable input file (%s) not created == -1 (%d: %s)\n", filename, errno, strerror(errno));
|
||||
ret = write(fd, buf, 1);
|
||||
assert_equal(ret, 1, "Unreadable write ret %d != 1\n", ret);
|
||||
assert_zero(close(fd), "Unreadable close(%s) != 0\n", filename);
|
||||
assert_zero(close(fd), "Unreadable close(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
|
||||
|
||||
ret = ZBarcode_Encode_File(symbol, filename);
|
||||
assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File unreadable ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt);
|
||||
|
||||
assert_zero(remove(filename), "remove(%s) != 0\n", filename);
|
||||
assert_zero(remove(filename), "remove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
|
||||
testFinish();
|
||||
#endif /* _WIN32 */
|
||||
}
|
||||
|
||||
// #181 Nico Gunkel OSS-Fuzz (buffer not freed on fread() error) Note: unable to reproduce fread() error using this method
|
||||
|
@ -394,13 +398,13 @@ static void test_encode_file_directory(void) {
|
|||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
(void)rmdir(dirname); // In case junk hanging around
|
||||
assert_zero(mkdir(dirname, 0700), "mkdir(%s, 0700) != 0\n", dirname);
|
||||
(void)testutil_rmdir(dirname); // In case junk hanging around
|
||||
assert_zero(testutil_mkdir(dirname, 0700), "testutil_mkdir(%s, 0700) != 0 (%d: %s)\n", dirname, errno, strerror(errno));
|
||||
|
||||
ret = ZBarcode_Encode_File(symbol, dirname);
|
||||
assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt);
|
||||
|
||||
assert_zero(rmdir(dirname), "rmdir(%s) != 0\n", dirname);
|
||||
assert_zero(testutil_rmdir(dirname), "testutil_rmdir(%s) != 0 (%d: %s)\n", dirname, errno, strerror(errno));
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
|
||||
|
|
|
@ -47,18 +47,26 @@ static void test_large(int index, int debug) {
|
|||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
|
||||
struct item data[] = {
|
||||
/* 0*/ { BARCODE_MSI_PLESSEY, -1, "9", 55, 0, 1, 667 },
|
||||
/* 1*/ { BARCODE_MSI_PLESSEY, -1, "9", 56, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 2*/ { BARCODE_MSI_PLESSEY, 1, "9", 18, 0, 1, 235 }, // 1 mod-10 check digit
|
||||
/* 3*/ { BARCODE_MSI_PLESSEY, 1, "9", 19, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 4*/ { BARCODE_MSI_PLESSEY, 2, "9", 18, 0, 1, 247 }, // 2 mod-10 check digits
|
||||
/* 5*/ { BARCODE_MSI_PLESSEY, 2, "9", 19, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 6*/ { BARCODE_MSI_PLESSEY, 3, "9", 55, 0, 1, 679 }, // 1 mod-11 check digit
|
||||
/* 7*/ { BARCODE_MSI_PLESSEY, 3, "9", 56, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 8*/ { BARCODE_MSI_PLESSEY, 4, "9", 18, 0, 1, 247 }, // 1 mod-11 and 1 mod-10 check digit
|
||||
/* 9*/ { BARCODE_MSI_PLESSEY, 4, "9", 19, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 10*/ { BARCODE_PLESSEY, -1, "A", 65, 0, 1, 1107 },
|
||||
/* 11*/ { BARCODE_PLESSEY, -1, "A", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 0*/ { BARCODE_MSI_PLESSEY, -1, "9", 65, 0, 1, 787 },
|
||||
/* 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
|
||||
/* 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
|
||||
/* 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
|
||||
/* 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"
|
||||
/* 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
|
||||
/* 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
|
||||
/* 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
|
||||
/* 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
|
||||
/* 17*/ { BARCODE_MSI_PLESSEY, 6, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 18*/ { BARCODE_PLESSEY, -1, "A", 65, 0, 1, 1107 },
|
||||
/* 19*/ { BARCODE_PLESSEY, -1, "A", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
};
|
||||
int data_size = ARRAY_SIZE(data);
|
||||
|
||||
|
@ -107,16 +115,32 @@ static void test_hrt(int index, int debug) {
|
|||
/* 0*/ { BARCODE_MSI_PLESSEY, -1, "1234567", "1234567" },
|
||||
/* 1*/ { BARCODE_MSI_PLESSEY, 0, "1234567", "1234567" },
|
||||
/* 2*/ { BARCODE_MSI_PLESSEY, 1, "1234567", "12345674" },
|
||||
/* 3*/ { BARCODE_MSI_PLESSEY, 2, "1234567", "123456741" },
|
||||
/* 4*/ { BARCODE_MSI_PLESSEY, 3, "1234567", "12345674" },
|
||||
/* 5*/ { BARCODE_MSI_PLESSEY, 4, "1234567", "123456741" },
|
||||
/* 6*/ { BARCODE_MSI_PLESSEY, 1, "123456", "1234566" },
|
||||
/* 7*/ { BARCODE_MSI_PLESSEY, 2, "123456", "12345666" },
|
||||
/* 8*/ { BARCODE_MSI_PLESSEY, 3, "123456", "1234560" },
|
||||
/* 9*/ { BARCODE_MSI_PLESSEY, 4, "123456", "12345609" },
|
||||
/* 10*/ { BARCODE_MSI_PLESSEY, 3, "2211", "221110" }, // Mod-11 check digit '10'
|
||||
/* 11*/ { BARCODE_MSI_PLESSEY, 4, "2211", "2211100" },
|
||||
/* 12*/ { BARCODE_PLESSEY, -1, "0123456789ABCDEF", "0123456789ABCDEF" },
|
||||
/* 3*/ { BARCODE_MSI_PLESSEY, 1 + 10, "1234567", "1234567" },
|
||||
/* 4*/ { BARCODE_MSI_PLESSEY, 1, "9999999999", "99999999990" },
|
||||
/* 5*/ { BARCODE_MSI_PLESSEY, 2, "1234567", "123456741" },
|
||||
/* 6*/ { BARCODE_MSI_PLESSEY, 2 + 10, "1234567", "1234567" },
|
||||
/* 7*/ { BARCODE_MSI_PLESSEY, 2, "9999999999", "999999999900" },
|
||||
/* 8*/ { BARCODE_MSI_PLESSEY, 3, "1234567", "12345674" },
|
||||
/* 9*/ { BARCODE_MSI_PLESSEY, 3 + 10, "1234567", "1234567" },
|
||||
/* 10*/ { BARCODE_MSI_PLESSEY, 3, "9999999999", "99999999995" },
|
||||
/* 11*/ { BARCODE_MSI_PLESSEY, 4, "1234567", "123456741" },
|
||||
/* 12*/ { BARCODE_MSI_PLESSEY, 4 + 10, "1234567", "1234567" },
|
||||
/* 13*/ { BARCODE_MSI_PLESSEY, 4, "9999999999", "999999999959" },
|
||||
/* 14*/ { BARCODE_MSI_PLESSEY, 5, "1234567", "12345679" },
|
||||
/* 15*/ { BARCODE_MSI_PLESSEY, 5 + 10, "1234567", "1234567" },
|
||||
/* 16*/ { BARCODE_MSI_PLESSEY, 5, "9999999999", "999999999910" },
|
||||
/* 17*/ { BARCODE_MSI_PLESSEY, 6, "1234567", "123456790" },
|
||||
/* 18*/ { BARCODE_MSI_PLESSEY, 6 + 10, "1234567", "1234567" },
|
||||
/* 19*/ { BARCODE_MSI_PLESSEY, 6, "9999999999", "9999999999109" },
|
||||
/* 20*/ { BARCODE_MSI_PLESSEY, 1, "123456", "1234566" },
|
||||
/* 21*/ { BARCODE_MSI_PLESSEY, 2, "123456", "12345666" },
|
||||
/* 22*/ { BARCODE_MSI_PLESSEY, 3, "123456", "1234560" },
|
||||
/* 23*/ { BARCODE_MSI_PLESSEY, 4, "123456", "12345609" },
|
||||
/* 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'
|
||||
/* 26*/ { BARCODE_MSI_PLESSEY, 4, "2211", "2211100" },
|
||||
/* 27*/ { BARCODE_MSI_PLESSEY, 4 + 10, "2211", "2211" },
|
||||
/* 28*/ { BARCODE_PLESSEY, -1, "0123456789ABCDEF", "0123456789ABCDEF" },
|
||||
};
|
||||
int data_size = ARRAY_SIZE(data);
|
||||
|
||||
|
@ -219,16 +243,22 @@ static void test_encode(int index, int generate, int debug) {
|
|||
/* 4*/ { BARCODE_MSI_PLESSEY, 4, "1234567890", 0, 1, 151, "",
|
||||
"1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001001101101001001001101001"
|
||||
},
|
||||
/* 5*/ { BARCODE_MSI_PLESSEY, 3, "2211", 0, 1, 79, "Produces mod-11 '10' check digit; BWIPP (badmod11)",
|
||||
/* 5*/ { BARCODE_MSI_PLESSEY, 5, "1234567890", 0, 1, 139, "",
|
||||
"1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001001001001001"
|
||||
},
|
||||
/* 6*/ { BARCODE_MSI_PLESSEY, 6, "1234567890", 0, 1, 151, "",
|
||||
"1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001001001001001101101101001"
|
||||
},
|
||||
/* 7*/ { BARCODE_MSI_PLESSEY, 3, "2211", 0, 1, 79, "Produces mod-11 '10' check digit; BWIPP (badmod11)",
|
||||
"1101001001101001001001101001001001001101001001001101001001001101001001001001001"
|
||||
},
|
||||
/* 6*/ { BARCODE_MSI_PLESSEY, 4, "2211", 0, 1, 91, "BWIPP (badmod11)",
|
||||
/* 8*/ { BARCODE_MSI_PLESSEY, 4, "2211", 0, 1, 91, "BWIPP (badmod11)",
|
||||
"1101001001101001001001101001001001001101001001001101001001001101001001001001001001001001001"
|
||||
},
|
||||
/* 7*/ { BARCODE_PLESSEY, -1, "0123456789ABCDEF", 0, 1, 323, "",
|
||||
/* 9*/ { BARCODE_PLESSEY, -1, "0123456789ABCDEF", 0, 1, 323, "",
|
||||
"11101110100011101000100010001000111010001000100010001110100010001110111010001000100010001110100011101000111010001000111011101000111011101110100010001000100011101110100010001110100011101000111011101110100011101000100011101110111010001110111010001110111011101110111011101110111010001000111010001000100010001110001000101110111"
|
||||
},
|
||||
/* 8*/ { BARCODE_MSI_PLESSEY, 4, "999999999999999999", 0, 1, 247, "Max value; #209 check buffer not overrun",
|
||||
/* 10*/ { BARCODE_MSI_PLESSEY, 4, "999999999999999999", 0, 1, 247, "Max value (previously); #209 check buffer not overrun",
|
||||
"1101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001001001001001101001"
|
||||
},
|
||||
};
|
||||
|
|
|
@ -196,8 +196,8 @@ static void test_print(int index, int generate, int debug) {
|
|||
|
||||
if (generate) {
|
||||
if (!testUtilExists(data_dir)) {
|
||||
ret = mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
|
||||
ret = testutil_mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,13 +81,13 @@ static void test_print(int index, int generate, int debug) {
|
|||
if (generate) {
|
||||
strcpy(data_dir, "data");
|
||||
if (!testUtilExists(data_dir)) {
|
||||
ret = mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
|
||||
ret = testutil_mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
|
||||
}
|
||||
strcat(data_dir, "/print");
|
||||
if (!testUtilExists(data_dir)) {
|
||||
ret = mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
|
||||
ret = testutil_mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,8 +100,8 @@ static void test_print(int index, int generate, int debug) {
|
|||
|
||||
if (generate) {
|
||||
if (!testUtilExists(data_dir)) {
|
||||
ret = mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
|
||||
ret = testutil_mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com>
|
||||
Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
@ -71,8 +71,8 @@ static void test_print(int index, int generate, int debug) {
|
|||
|
||||
if (generate) {
|
||||
if (!testUtilExists(data_dir)) {
|
||||
ret = mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
|
||||
ret = testutil_mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -111,8 +111,8 @@ static void test_print(int index, int generate, int debug) {
|
|||
|
||||
if (generate) {
|
||||
if (!testUtilExists(data_dir)) {
|
||||
ret = mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
|
||||
ret = testutil_mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -190,8 +190,8 @@ static void test_print(int index, int generate, int debug) {
|
|||
|
||||
if (generate) {
|
||||
if (!testUtilExists(data_dir)) {
|
||||
ret = mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
|
||||
ret = testutil_mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -529,9 +529,9 @@ static void test_stacking(int index, int debug) {
|
|||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
|
||||
struct item data[] = {
|
||||
/* 0*/ { BARCODE_CODE128, -1, -1, -1, "A", "B", 50, 2, 46, 92, 116.1, -1, -1, -1 },
|
||||
/* 1*/ { BARCODE_CODE128, BARCODE_BIND, -1, -1, "A", "B", 50, 2, 46, 92, 116.1, 49, 0, 2 },
|
||||
/* 2*/ { BARCODE_CODE128, BARCODE_BIND, -1, 2, "A", "B", 50, 2, 46, 92, 116.1, 48, 0, 4 },
|
||||
/* 0*/ { BARCODE_CODE128, -1, -1, -1, "A", "B", 50, 2, 46, 92, 116, -1, -1, -1 },
|
||||
/* 1*/ { BARCODE_CODE128, BARCODE_BIND, -1, -1, "A", "B", 50, 2, 46, 92, 116, 49, 0, 2 },
|
||||
/* 2*/ { BARCODE_CODE128, BARCODE_BIND, -1, 2, "A", "B", 50, 2, 46, 92, 116, 48, 0, 4 },
|
||||
};
|
||||
int data_size = ARRAY_SIZE(data);
|
||||
|
||||
|
|
|
@ -34,6 +34,14 @@
|
|||
*/
|
||||
|
||||
#include "testcommon.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <malloc.h>
|
||||
#define testutil_alloca(nmemb) _alloca(nmemb)
|
||||
#else
|
||||
#define testutil_alloca(nmemb) alloca(nmemb)
|
||||
#endif
|
||||
|
||||
#include "../eci.h"
|
||||
#ifndef NO_PNG
|
||||
#include <png.h>
|
||||
|
@ -1178,7 +1186,7 @@ void testUtilBitmapPrint(const struct zint_symbol *symbol, const char *prefix, c
|
|||
|
||||
int testUtilBitmapCmp(const struct zint_symbol *symbol, const char *expected, int *row, int *column) {
|
||||
static char colour[] = { '0', 'C', 'M', 'B', 'Y', 'G', 'R', '1' };
|
||||
int r, c, i, j;
|
||||
int r, c = -1, i, j;
|
||||
const char *e = expected;
|
||||
const char *ep = expected + strlen(expected);
|
||||
char buf[7];
|
||||
|
@ -2017,7 +2025,7 @@ static char *testUtilBwippEscape(char *bwipp_data, int bwipp_data_size, const ch
|
|||
/* Escape single quote also to avoid having to do proper shell escaping TODO: proper shell escaping */
|
||||
if (*d < 0x20 || *d >= 0x7F || *d == '^' || *d == '"' || *d == '\'') {
|
||||
if (b + 4 >= be) {
|
||||
fprintf(stderr, "testUtilBwippEscape: bwipp_data buffer full\n");
|
||||
fprintf(stderr, "testUtilBwippEscape: double quote bwipp_data buffer full (%d)\n", bwipp_data_size);
|
||||
return NULL;
|
||||
}
|
||||
sprintf(b, "^%03u", *d++);
|
||||
|
@ -2044,7 +2052,7 @@ static char *testUtilBwippEscape(char *bwipp_data, int bwipp_data_size, const ch
|
|||
default: fprintf(stderr, "testUtilBwippEscape: unknown escape %c\n", *d); return NULL; break;
|
||||
}
|
||||
if (b + 4 >= be) {
|
||||
fprintf(stderr, "testUtilBwippEscape: bwipp_data buffer full\n");
|
||||
fprintf(stderr, "testUtilBwippEscape: loop bwipp_data buffer full (%d)\n", bwipp_data_size);
|
||||
return NULL;
|
||||
}
|
||||
sprintf(b, "^%03d", val);
|
||||
|
@ -2057,7 +2065,7 @@ static char *testUtilBwippEscape(char *bwipp_data, int bwipp_data_size, const ch
|
|||
}
|
||||
|
||||
if (b == be && d < de) {
|
||||
fprintf(stderr, "testUtilBwippEscape: bwipp_data buffer full\n");
|
||||
fprintf(stderr, "testUtilBwippEscape: end bwipp_data buffer full (%d)\n", bwipp_data_size);
|
||||
return NULL;
|
||||
}
|
||||
*b = '\0';
|
||||
|
@ -2086,10 +2094,10 @@ static void testUtilISBNHyphenate(char *bwipp_data, int addon_posn) {
|
|||
#define GS_INITIAL_LEN 35 /* Length of cmd up to -q */
|
||||
|
||||
int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, const char *data, int length, const char *primary, char *buffer, int buffer_size) {
|
||||
const char *cmd_fmt = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%s' ../tools/bwipp_dump.ps";
|
||||
const char *cmd_opts_fmt = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%s' -so='%s' ../tools/bwipp_dump.ps";
|
||||
const char *cmd_fmt2 = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%.2043s' -sd2='%s' ../tools/bwipp_dump.ps"; // If data > 2K
|
||||
const char *cmd_opts_fmt2 = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%.2043s' -sd2='%s' -so='%s' ../tools/bwipp_dump.ps";
|
||||
const char *cmd_fmt = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%s' backend/tests/tools/bwipp_dump.ps";
|
||||
const char *cmd_opts_fmt = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%s' -so='%s' backend/tests/tools/bwipp_dump.ps";
|
||||
const char *cmd_fmt2 = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%.2043s' -sd2='%s' backend/tests/tools/bwipp_dump.ps"; // If data > 2K
|
||||
const char *cmd_opts_fmt2 = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%.2043s' -sd2='%s' -so='%s' backend/tests/tools/bwipp_dump.ps";
|
||||
|
||||
int symbology = symbol->symbology;
|
||||
int data_len = length == -1 ? (int) strlen(data) : length;
|
||||
|
@ -2097,13 +2105,14 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
|
|||
int max_data_len = 4 + primary_len + 1 + 1 + data_len * 4 + 64; /* 4 AI prefix + primary + '|' + leading zero + escaped data + fudge */
|
||||
|
||||
int eci_length = get_eci_length(symbol->eci, (const unsigned char *) data, data_len);
|
||||
char *converted = alloca(eci_length + 1);
|
||||
char *cmd = alloca(max_data_len + 1024);
|
||||
char *converted = (char *) testutil_alloca(eci_length + 1);
|
||||
char *cmd = (char *) testutil_alloca(max_data_len + 1024);
|
||||
const char *bwipp_barcode = NULL;
|
||||
char *bwipp_opts = NULL;
|
||||
char *bwipp_data = alloca(max_data_len + 1);
|
||||
int bwipp_data_size = max_data_len + 1;
|
||||
char *bwipp_data = (char *) testutil_alloca(bwipp_data_size);
|
||||
char bwipp_opts_buf[512];
|
||||
int *bwipp_row_height = alloca(sizeof(int) * symbol->rows);
|
||||
int *bwipp_row_height = (int *) testutil_alloca(sizeof(int) * symbol->rows);
|
||||
int linear_row_height;
|
||||
int gs1_cvt;
|
||||
int user_mask;
|
||||
|
@ -2227,7 +2236,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (testUtilBwippEscape(bwipp_data, sizeof(bwipp_data), data, data_len, symbol->input_mode & ESCAPE_MODE, eci, &parse, &parsefnc) == NULL) {
|
||||
if (testUtilBwippEscape(bwipp_data, bwipp_data_size, data, data_len, symbol->input_mode & ESCAPE_MODE, eci, &parse, &parsefnc) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (parse) {
|
||||
|
@ -2285,12 +2294,19 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
|
|||
sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sincludecheck", strlen(bwipp_opts_buf) ? " " : "");
|
||||
|
||||
const char *checktype = NULL;
|
||||
if (option_2 >= 11 && option_2 <= 16) {
|
||||
option_2 -= 10; /* Remove no-check indicator */
|
||||
}
|
||||
if (option_2 == 2) {
|
||||
checktype = "mod1010";
|
||||
} else if (option_2 == 3) {
|
||||
checktype = "mod11 badmod11";
|
||||
} else if (option_2 == 4) {
|
||||
checktype = "mod1110 badmod11";
|
||||
} else if (option_2 == 5) {
|
||||
checktype = "ncrmod11 badmod11";
|
||||
} else if (option_2 == 6) {
|
||||
checktype = "ncrmod1110 badmod11";
|
||||
}
|
||||
if (checktype) {
|
||||
sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%schecktype=%s", strlen(bwipp_opts_buf) ? " " : "", checktype);
|
||||
|
@ -2480,7 +2496,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
|
|||
}
|
||||
}
|
||||
if (option_2 > 0) {
|
||||
char scm_vv_buf[16];
|
||||
char scm_vv_buf[32];
|
||||
sprintf(scm_vv_buf, "[)>^03001^029%02d", option_2); /* [)>\R01\Gvv */
|
||||
memmove(bwipp_data + 15, bwipp_data, strlen(bwipp_data) + 1);
|
||||
memcpy(bwipp_data, scm_vv_buf, 15);
|
||||
|
@ -2621,7 +2637,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
|
|||
printf("i:%d testUtilBwipp: cmd %s\n", index, cmd);
|
||||
}
|
||||
|
||||
fp = popen(cmd, "r");
|
||||
fp = testutil_popen(cmd, "r");
|
||||
if (!fp) {
|
||||
fprintf(stderr, "i:%d testUtilBwipp: failed to run '%s'\n", index, cmd);
|
||||
return -1;
|
||||
|
@ -2630,13 +2646,13 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
|
|||
for (r = 0; r < symbol->rows; r++) {
|
||||
if (b + symbol->width > be) {
|
||||
fprintf(stderr, "i:%d testUtilBwipp: row %d, width %d, row width iteration overrun (%s)\n", index, r, symbol->width, cmd);
|
||||
pclose(fp);
|
||||
testutil_pclose(fp);
|
||||
return -1;
|
||||
}
|
||||
cnt = fread(b, 1, symbol->width, fp);
|
||||
if (cnt != symbol->width) {
|
||||
fprintf(stderr, "i:%d testUtilBwipp: failed to read symbol->width %d bytes, cnt %d (%s)\n", index, symbol->width, cnt, cmd);
|
||||
pclose(fp);
|
||||
testutil_pclose(fp);
|
||||
return -1;
|
||||
}
|
||||
b += cnt;
|
||||
|
@ -2645,7 +2661,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
|
|||
if (cnt != symbol->width) {
|
||||
fprintf(stderr, "i:%d testUtilBwipp: failed to read/ignore symbol->width %d bytes, cnt %d, h %d, bwipp_row_height[%d] %d, symbol->row_height[%d] %d (%s)\n",
|
||||
index, symbol->width, cnt, h, r, bwipp_row_height[r], r, symbol->row_height[r], cmd);
|
||||
pclose(fp);
|
||||
testutil_pclose(fp);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -2654,11 +2670,11 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
|
|||
|
||||
if (fgetc(fp) != EOF) {
|
||||
fprintf(stderr, "i:%d testUtilBwipp: failed to read full stream (%s)\n", index, cmd);
|
||||
pclose(fp);
|
||||
testutil_pclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pclose(fp);
|
||||
testutil_pclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -42,17 +42,38 @@
|
|||
#define ZINT_DEBUG_TEST_BWIPP 128
|
||||
#define ZINT_DEBUG_TEST_PERFORMANCE 256
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <malloc.h>
|
||||
#define alloca(nmemb) _malloca(nmemb)
|
||||
#define popen(command, mode) _popen(command, mode)
|
||||
#define pclose(stream) _pclose(stream)
|
||||
#ifdef _MSC_VER
|
||||
#define testutil_popen(command, mode) _popen(command, mode)
|
||||
#define testutil_pclose(stream) _pclose(stream)
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#define testutil_popen(command, mode) popen(command, mode)
|
||||
#define testutil_pclose(stream) pclose(stream)
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#define testutil_mkdir(path, mode) _mkdir(path)
|
||||
#define testutil_rmdir(path) _rmdir(path)
|
||||
#else
|
||||
#define testutil_mkdir(path, mode) mkdir(path, mode)
|
||||
#define testutil_rmdir(path) rmdir(path)
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "../common.h"
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic ignored "-Wpedantic"
|
||||
# pragma clang diagnostic ignored "-Woverlength-strings"
|
||||
#elif defined(__GNUC__)
|
||||
# pragma GCC diagnostic ignored "-Wpedantic"
|
||||
# pragma GCC diagnostic ignored "-Woverlength-strings"
|
||||
#elif defined(_MSC_VER)
|
||||
# pragma warning(disable: 4305) /* truncation from 'double' to 'float' */
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -72,7 +93,9 @@ void testFinish(void);
|
|||
void testSkip(const char *msg);
|
||||
void testReport();
|
||||
|
||||
typedef struct s_testFunction { const char *name; void *func; int has_index; int has_generate; int has_debug; } testFunction;
|
||||
typedef struct s_testFunction {
|
||||
const char *name; void *func; int has_index; int has_generate; int has_debug;
|
||||
} testFunction;
|
||||
void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size);
|
||||
|
||||
#define assert_exp(__exp__, ...) \
|
||||
|
@ -89,7 +112,8 @@ void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size);
|
|||
|
||||
INTERNAL void vector_free(struct zint_symbol *symbol); /* Free vector structures */
|
||||
|
||||
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 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);
|
||||
const char *testUtilBarcodeName(int symbology);
|
||||
const char *testUtilErrorName(int error_number);
|
||||
const char *testUtilInputModeName(int input_mode);
|
||||
|
@ -129,10 +153,13 @@ int testUtilHaveVnu();
|
|||
int testUtilVerifyVnu(char *filename, int debug);
|
||||
int testUtilHaveTiffInfo();
|
||||
int testUtilVerifyTiffInfo(char *filename, int debug);
|
||||
int testUtilCanBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, int debug);
|
||||
int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, const char *data, int length, const char *primary, char *buffer, int buffer_size);
|
||||
int testUtilCanBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3,
|
||||
int debug);
|
||||
int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3,
|
||||
const char *data, int length, const char *primary, char *buffer, int buffer_size);
|
||||
int testUtilBwippCmp(const struct zint_symbol *symbol, char *msg, const char *bwipp_buf, const char *expected);
|
||||
int testUtilBwippCmpRow(const struct zint_symbol *symbol, int row, char *msg, const char *bwipp_buf, const char *expected);
|
||||
int testUtilBwippCmpRow(const struct zint_symbol *symbol, int row, char *msg, const char *bwipp_buf,
|
||||
const char *expected);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -6,10 +6,10 @@ set -e
|
|||
function run_bwipp_test() {
|
||||
if [ -z "$2" ]; then
|
||||
echo -e "\n$1"
|
||||
./$1 -d $(expr 128 + 16 + 32) || exit 1
|
||||
backend/tests/$1 -d $(expr 128 + 16 + 32) || exit 1
|
||||
else
|
||||
echo -e "\n$1 -f $2"
|
||||
./$1 -f "$2" -d $(expr 128 + 16 + 32) || exit 1
|
||||
backend/tests/$1 -f "$2" -d $(expr 128 + 16 + 32) || exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue