mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Add BARCODE_MEMORY_FILE
to symbol->output_options
to allow
outputting to in-memory buffer `symbol->memfile` instead of to file `symbol->outfile`, ticket #301 Add "README.clang-tidy" and ".clang-tidy" options file Suppress some warnings
This commit is contained in:
@ -58,6 +58,7 @@ zint_add_test(dmatrix test_dmatrix)
|
||||
zint_add_test(dotcode test_dotcode)
|
||||
zint_add_test(eci test_eci)
|
||||
zint_add_test(emf test_emf)
|
||||
zint_add_test(filemem test_filemem)
|
||||
zint_add_test(gb18030 test_gb18030)
|
||||
zint_add_test(gb2312 test_gb2312)
|
||||
zint_add_test(gif test_gif)
|
||||
|
@ -155,6 +155,8 @@ static void test_print(const testCtx *const p_ctx) {
|
||||
char expected_file[4096];
|
||||
char escaped[1024];
|
||||
int escaped_size = 1024;
|
||||
unsigned char filebuf[32768];
|
||||
int filebuf_size;
|
||||
|
||||
const char *const have_identify = testUtilHaveIdentify();
|
||||
|
||||
@ -220,7 +222,23 @@ static void test_print(const testCtx *const p_ctx) {
|
||||
|
||||
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(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||
|
||||
ret = testUtilReadFile(symbol->outfile, filebuf, sizeof(filebuf), &filebuf_size); /* For BARCODE_MEMORY_FILE */
|
||||
assert_zero(ret, "i:%d %s testUtilReadFile(%s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret);
|
||||
|
||||
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
|
||||
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||
}
|
||||
|
||||
symbol->output_options |= BARCODE_MEMORY_FILE;
|
||||
ret = ZBarcode_Print(symbol, 0);
|
||||
assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0 (%s)\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret, symbol->errtxt);
|
||||
assert_nonnull(symbol->memfile, "i:%d %s memfile NULL\n", i, testUtilBarcodeName(data[i].symbology));
|
||||
assert_equal(symbol->memfile_size, filebuf_size, "i:%d %s memfile_size %d != %d\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), symbol->memfile_size, filebuf_size);
|
||||
assert_zero(memcmp(symbol->memfile, filebuf, symbol->memfile_size), "i:%d %s memcmp(memfile, filebuf) != 0\n",
|
||||
i, testUtilBarcodeName(data[i].symbology));
|
||||
}
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
|
@ -590,7 +590,7 @@ static void test_fuzz(const testCtx *const p_ctx) {
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { -1, -1, "\034\034I", 3, 0, 1, "" },
|
||||
/* 1*/ { 6, -2147483648,
|
||||
/* 1*/ { 6, -2147483647 - 1 /*Suppress MSVC warning C4146*/,
|
||||
"\134\000\377\153\143\163\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061\061"
|
||||
"\071\065\062\000\000\000\000\061\061\061\061\061\061\366\366\366\366\366\366\366\366\366\366\007\366\366\366\366\366\366\366\061\061\061\061\061\061\061\061\061"
|
||||
"\061\061\061\061\061\061\061\323\323\323\323\000\200\135\000\362\000\000\000\000\000\050\000\000\000\000\162\162\162\162\034\153\143\163\061\061\061\061\061\061"
|
||||
|
@ -104,6 +104,8 @@ static void test_print(const testCtx *const p_ctx) {
|
||||
char expected_file[1024];
|
||||
char escaped[1024];
|
||||
int escaped_size = 1024;
|
||||
unsigned char filebuf[32768];
|
||||
int filebuf_size;
|
||||
|
||||
int have_libreoffice = 0;
|
||||
if (p_ctx->generate) {
|
||||
@ -182,7 +184,23 @@ static void test_print(const testCtx *const p_ctx) {
|
||||
|
||||
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);
|
||||
if (p_ctx->index == -1) assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||
|
||||
ret = testUtilReadFile(symbol->outfile, filebuf, sizeof(filebuf), &filebuf_size); /* For BARCODE_MEMORY_FILE */
|
||||
assert_zero(ret, "i:%d %s testUtilReadFile(%s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret);
|
||||
|
||||
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
|
||||
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||
}
|
||||
|
||||
symbol->output_options |= BARCODE_MEMORY_FILE;
|
||||
ret = ZBarcode_Print(symbol, data[i].rotate_angle);
|
||||
assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0 (%s)\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret, symbol->errtxt);
|
||||
assert_nonnull(symbol->memfile, "i:%d %s memfile NULL\n", i, testUtilBarcodeName(data[i].symbology));
|
||||
assert_equal(symbol->memfile_size, filebuf_size, "i:%d %s memfile_size %d != %d\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), symbol->memfile_size, filebuf_size);
|
||||
assert_zero(memcmp(symbol->memfile, filebuf, symbol->memfile_size), "i:%d %s memcmp(memfile, filebuf) != 0\n",
|
||||
i, testUtilBarcodeName(data[i].symbology));
|
||||
}
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
|
477
backend/tests/test_filemem.c
Normal file
477
backend/tests/test_filemem.c
Normal file
@ -0,0 +1,477 @@
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2023 Robin Stuart <rstuart114@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the project nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
*/
|
||||
/* SPDX-License-Identifier: BSD-3-Clause */
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <sys/stat.h>
|
||||
#include "testcommon.h"
|
||||
#include "../common.h"
|
||||
#include "../filemem.h"
|
||||
|
||||
static void test_svg(const testCtx *const p_ctx) {
|
||||
int debug = p_ctx->debug;
|
||||
|
||||
struct item {
|
||||
int symbology;
|
||||
int output_options;
|
||||
char *outfile;
|
||||
char *data;
|
||||
int length;
|
||||
int ret;
|
||||
|
||||
char *expected;
|
||||
};
|
||||
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
|
||||
struct item data[] = {
|
||||
/* 0*/ { BARCODE_CODE128, BARCODE_MEMORY_FILE, "out.svg", "ABCDEF", -1, 0,
|
||||
"<?xml version=\"1.0\" standalone=\"no\"?>\n"
|
||||
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"
|
||||
"<svg width=\"202\" height=\"117\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n"
|
||||
" <desc>Zint Generated Symbol</desc>\n"
|
||||
" <g id=\"barcode\" fill=\"#000000\">\n"
|
||||
" <rect x=\"0\" y=\"0\" width=\"202\" height=\"117\" fill=\"#FFFFFF\"/>\n"
|
||||
" <path d=\"M0 0h4v100h-4ZM6 0h2v100h-2ZM12 0h2v100h-2ZM22 0h2v100h-2ZM26 0h2v100h-2ZM34 0h4v100h-4ZM44 0h2v100h-2ZM52 0h2v100h-2ZM56 0h4v100h-4ZM66 0h2v100h-2ZM74 0h2v100h-2ZM82 0h4v100h-4ZM88 0h2v100h-2ZM92 0h4v100h-4ZM102 0h2v100h-2ZM110 0h2v100h-2ZM118 0h4v100h-4ZM124 0h2v100h-2ZM132 0h2v100h-2ZM140 0h4v100h-4ZM150 0h2v100h-2ZM154 0h2v100h-2ZM158 0h4v100h-4ZM168 0h6v100h-6ZM176 0h4v100h-4ZM186 0h6v100h-6ZM194 0h2v100h-2ZM198 0h4v100h-4Z\"/>\n"
|
||||
" <text x=\"101\" y=\"113.34\" text-anchor=\"middle\" font-family=\"Arimo, Arial, sans-serif\" font-size=\"14\">\n"
|
||||
" ABCDEF\n"
|
||||
" </text>\n"
|
||||
" </g>\n"
|
||||
"</svg>\n"
|
||||
},
|
||||
};
|
||||
int data_size = ARRAY_SIZE(data);
|
||||
int i, length, ret;
|
||||
struct zint_symbol *symbol = NULL;
|
||||
|
||||
testStartSymbol("test_svg", &symbol);
|
||||
|
||||
for (i = 0; i < data_size; i++) {
|
||||
|
||||
if (testContinue(p_ctx, i)) continue;
|
||||
|
||||
symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, data[i].output_options, data[i].data, data[i].length, debug);
|
||||
strcpy(symbol->outfile, data[i].outfile);
|
||||
|
||||
ret = ZBarcode_Encode_and_Print(symbol, TU(data[i].data), length, 0);
|
||||
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_and_Print(%d) ret %d != %d (%s)\n",
|
||||
i, data[i].symbology, ret, data[i].ret, symbol->errtxt);
|
||||
|
||||
if (ret < ZINT_ERROR) {
|
||||
const int expected_size = (int) strlen(data[i].expected);
|
||||
|
||||
assert_nonnull(symbol->memfile, "i:%d memfile NULL (%s)\n", i, symbol->errtxt);
|
||||
|
||||
assert_equal(symbol->memfile_size, expected_size, "i:%d memfile_size %d != %d (%s)\n",
|
||||
i, symbol->memfile_size, expected_size, symbol->errtxt);
|
||||
ret = memcmp(symbol->memfile, data[i].expected, symbol->memfile_size);
|
||||
assert_zero(ret, "i:%d memcmp() %d != 0\n", i, ret);
|
||||
} else {
|
||||
assert_null(symbol->memfile, "i:%d memfile != NULL (%s)\n", i, symbol->errtxt);
|
||||
assert_zero(symbol->memfile_size, "i:%d memfile_size != 0 (%s)\n", i, symbol->errtxt);
|
||||
}
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
}
|
||||
|
||||
testFinish();
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
extern FILE *fmemopen(void *buf, size_t size, const char *mode);
|
||||
#endif
|
||||
|
||||
static void test_putsf(const testCtx *const p_ctx) {
|
||||
int debug = p_ctx->debug;
|
||||
|
||||
struct item {
|
||||
const char *prefix;
|
||||
int dp;
|
||||
float arg;
|
||||
const char *locale;
|
||||
const char *expected;
|
||||
};
|
||||
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
|
||||
struct item data[] = {
|
||||
/* 0*/ { "", 2, 1234.123, "", "1234.12" },
|
||||
/* 1*/ { "", 3, 1234.123, "", "1234.123" },
|
||||
/* 2*/ { "prefix ", 4, 1234.123, "", "prefix 1234.123" },
|
||||
/* 3*/ { "", 2, -1234.126, "", "-1234.13" },
|
||||
/* 4*/ { "", 2, 1234.1, "", "1234.1" },
|
||||
/* 5*/ { "", 3, 1234.1, "", "1234.1" },
|
||||
/* 6*/ { "", 4, 1234.1, "", "1234.1" },
|
||||
/* 7*/ { "", 2, 1234.0, "", "1234" },
|
||||
/* 8*/ { "", 2, -1234.0, "", "-1234" },
|
||||
/* 9*/ { "", 3, 1234.1234, "de_DE.UTF-8", "1234.123" },
|
||||
/* 10*/ { "", 4, -1234.1234, "de_DE.UTF-8", "-1234.1234" },
|
||||
/* 11*/ { "prefix ", 4, -1234.1234, "de_DE.UTF-8", "prefix -1234.1234" },
|
||||
};
|
||||
int data_size = ARRAY_SIZE(data);
|
||||
int i, j;
|
||||
|
||||
struct zint_symbol symbol_data = {0};
|
||||
struct zint_symbol *const symbol = &symbol_data;
|
||||
struct filemem fm;
|
||||
struct filemem *const fmp = &fm;
|
||||
#ifndef _WIN32
|
||||
FILE *fp;
|
||||
char buf[512] = {0}; /* Suppress clang-16/17 run-time exception MemorySanitizer: use-of-uninitialized-value */
|
||||
#endif
|
||||
|
||||
testStart("test_putsf");
|
||||
|
||||
for (j = 0; j < 2; j++) { /* 1st `memfile`, then file */
|
||||
#ifdef _WIN32
|
||||
if (j == 1) break; /* Skip file test on Windows */
|
||||
#endif
|
||||
for (i = 0; i < data_size; i++) {
|
||||
const char *locale = NULL;
|
||||
int expected_size;
|
||||
|
||||
if (testContinue(p_ctx, i)) continue;
|
||||
|
||||
ZBarcode_Reset(symbol);
|
||||
if (j == 1) {
|
||||
#ifndef _WIN32
|
||||
buf[0] = '\0';
|
||||
fp = fmemopen(buf, sizeof(buf), "w");
|
||||
assert_nonnull(fp, "%d: fmemopen fail (%d, %s)\n", i, errno, strerror(errno));
|
||||
#endif
|
||||
} else {
|
||||
symbol->output_options |= BARCODE_MEMORY_FILE;
|
||||
}
|
||||
assert_nonzero(fm_open(fmp, symbol, "w"), "i:%d: fm_open fail (%d, %s)\n", i, fmp->err, strerror(fmp->err));
|
||||
if (j == 1) {
|
||||
#ifndef _WIN32
|
||||
/* Hack in `fmemopen()` fp */
|
||||
assert_zero(fclose(fmp->fp), "i:%d fclose(fmp->fp) fail (%d, %s)\n", i, errno, strerror(errno));
|
||||
fmp->fp = fp;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (data[i].locale && data[i].locale[0]) {
|
||||
locale = setlocale(LC_ALL, data[i].locale);
|
||||
if (!locale) { /* May not be available - warn unless quiet mode */
|
||||
if (!(debug & ZINT_DEBUG_TEST_LESS_NOISY)) {
|
||||
printf("i:%d: Warning: locale \"%s\" not available\n", i, data[i].locale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fm_putsf(data[i].prefix, data[i].dp, data[i].arg, fmp);
|
||||
|
||||
assert_nonzero(fm_close(fmp, symbol), "i:%d: fm_close fail (%d, %s)\n", i, fmp->err, strerror(fmp->err));
|
||||
|
||||
if (locale) {
|
||||
assert_nonnull(setlocale(LC_ALL, locale), "i:%d: setlocale(%s) restore fail (%d, %s)\n",
|
||||
i, locale, errno, strerror(errno));
|
||||
}
|
||||
|
||||
if (j == 1) {
|
||||
#ifndef _WIN32
|
||||
assert_zero(strcmp(buf, data[i].expected), "%d: strcmp(%s, %s) != 0\n", i, buf, data[i].expected);
|
||||
#endif
|
||||
} else {
|
||||
expected_size = (int) strlen(data[i].expected);
|
||||
assert_equal(symbol->memfile_size, expected_size, "i:%d: memfile_size %d != expected_size %d\n",
|
||||
i, symbol->memfile_size, expected_size);
|
||||
assert_nonnull(symbol->memfile, "i:%d memfile NULL\n", i);
|
||||
assert_zero(memcmp(symbol->memfile, data[i].expected, expected_size), "i:%d: memcmp(%.*s, %.*s) != 0\n",
|
||||
i, symbol->memfile_size, symbol->memfile, expected_size, data[i].expected);
|
||||
}
|
||||
|
||||
ZBarcode_Clear(symbol);
|
||||
}
|
||||
}
|
||||
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_printf(const testCtx *const p_ctx) {
|
||||
int debug = p_ctx->debug;
|
||||
|
||||
int ret;
|
||||
int j;
|
||||
struct zint_symbol symbol_data = {0};
|
||||
struct zint_symbol *const symbol = &symbol_data;
|
||||
struct filemem fm;
|
||||
struct filemem *const fmp = &fm;
|
||||
const char outfile[] = "test_printf.tst";
|
||||
unsigned char filebuf[32768];
|
||||
int filebuf_size;
|
||||
|
||||
const char fmt1[] = "\n%s%04d\n\032\nwow\n\r\n%.2s\n"; /* '\032' SUB (^Z) */
|
||||
const char expected1[] = "\ngosh0123\n\032\nwow\n\r\nge\n";
|
||||
#ifdef _WIN32
|
||||
/* On Windows, non-binary (i.e. text) files, LF -> LF+CR (note, actual files only, not memfiles) */
|
||||
const char expected1_text_file[] = "\r\ngosh0123\r\n\032\r\nwow\r\n\r\r\nge\r\n";
|
||||
#endif
|
||||
const char *expected;
|
||||
int expected_size;
|
||||
|
||||
(void)debug;
|
||||
|
||||
testStart("test_printf");
|
||||
|
||||
for (j = 0; j < 2; j++) { /* 1st memfile, then file */
|
||||
ZBarcode_Reset(symbol);
|
||||
|
||||
/* Binary */
|
||||
expected = expected1;
|
||||
if (j == 1) {
|
||||
strcpy(symbol->outfile, outfile);
|
||||
} else {
|
||||
symbol->output_options |= BARCODE_MEMORY_FILE;
|
||||
}
|
||||
ret = fm_open(fmp, symbol, "wb");
|
||||
assert_equal(ret, 1, "fm_open ret %d != 1\n", ret);
|
||||
|
||||
ret = fm_printf(fmp, fmt1, "gosh", 123, "gee");
|
||||
assert_equal(ret, 1, "fm_printf ret %d != 1\n", ret);
|
||||
|
||||
ret = fm_close(fmp, symbol);
|
||||
assert_equal(ret, 1, "fm_close ret %d != 1\n", ret);
|
||||
|
||||
expected_size = (int) strlen(expected);
|
||||
|
||||
if (j == 1) {
|
||||
ret = testUtilReadFile(symbol->outfile, filebuf, sizeof(filebuf), &filebuf_size);
|
||||
assert_zero(ret, "testUtilReadFile(%s) %d != 0\n", symbol->outfile, ret);
|
||||
assert_equal((int) filebuf_size, expected_size, "filebuf_size %d != %d\n", filebuf_size, expected_size);
|
||||
assert_zero(memcmp(filebuf, expected, filebuf_size), "memcmp(%.*s, %s) != 0\n",
|
||||
filebuf_size, filebuf, expected);
|
||||
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
|
||||
assert_zero(testUtilRemove(symbol->outfile), "testUtilRemove(%s) != 0\n", symbol->outfile);
|
||||
}
|
||||
} else {
|
||||
assert_nonnull(symbol->memfile, "memfile NULL (%d: %s)\n", fmp->err, strerror(fmp->err));
|
||||
assert_equal(symbol->memfile_size, expected_size, "mempos %d != %d\n",
|
||||
symbol->memfile_size, expected_size);
|
||||
assert_zero(memcmp(symbol->memfile, expected, symbol->memfile_size), "memcmp(%.*s, %s) != 0\n",
|
||||
symbol->memfile_size, symbol->memfile, expected);
|
||||
}
|
||||
|
||||
/* Non-binary */
|
||||
expected = expected1;
|
||||
if (j == 1) {
|
||||
strcpy(symbol->outfile, outfile);
|
||||
#ifdef _WIN32
|
||||
expected = expected1_text_file;
|
||||
#endif
|
||||
} else {
|
||||
symbol->output_options |= BARCODE_MEMORY_FILE;
|
||||
}
|
||||
ret = fm_open(fmp, symbol, "w");
|
||||
assert_equal(ret, 1, "fm_open ret %d != 1\n", ret);
|
||||
|
||||
ret = fm_printf(fmp, fmt1, "gosh", 123, "gee");
|
||||
assert_equal(ret, 1, "fm_printf ret %d != 1\n", ret);
|
||||
|
||||
ret = fm_close(fmp, symbol);
|
||||
assert_equal(ret, 1, "fm_close ret %d != 1\n", ret);
|
||||
|
||||
expected_size = (int) strlen(expected);
|
||||
|
||||
if (j == 1) {
|
||||
ret = testUtilReadFile(symbol->outfile, filebuf, sizeof(filebuf), &filebuf_size);
|
||||
assert_zero(ret, "testUtilReadFile(%s) %d != 0\n", symbol->outfile, ret);
|
||||
assert_equal((int) filebuf_size, expected_size, "filebuf_size %d != %d\n", filebuf_size, expected_size);
|
||||
assert_zero(memcmp(filebuf, expected, filebuf_size), "memcmp(%.*s, %s) != 0\n",
|
||||
filebuf_size, filebuf, expected);
|
||||
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
|
||||
assert_zero(testUtilRemove(symbol->outfile), "testUtilRemove(%s) != 0\n", symbol->outfile);
|
||||
}
|
||||
} else {
|
||||
assert_nonnull(symbol->memfile, "mem NULL (%d: %s)\n", fmp->err, strerror(fmp->err));
|
||||
assert_equal(symbol->memfile_size, expected_size, "mempos %d != %d\n",
|
||||
symbol->memfile_size, expected_size);
|
||||
assert_zero(memcmp(symbol->memfile, expected, symbol->memfile_size), "memcmp(%.*s, %s) != 0\n",
|
||||
symbol->memfile_size, symbol->memfile, expected);
|
||||
}
|
||||
|
||||
ZBarcode_Clear(symbol);
|
||||
}
|
||||
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_seek(const testCtx *const p_ctx) {
|
||||
int debug = p_ctx->debug;
|
||||
|
||||
int ret;
|
||||
int j;
|
||||
struct zint_symbol symbol_data = {0};
|
||||
struct zint_symbol *const symbol = &symbol_data;
|
||||
struct filemem fm;
|
||||
struct filemem *const fmp = &fm;
|
||||
const char outfile[] = "test_seek.tst";
|
||||
|
||||
(void)debug;
|
||||
|
||||
testStart("test_seek");
|
||||
|
||||
for (j = 0; j < 2; j++) { /* 1st memfile, then file */
|
||||
ZBarcode_Reset(symbol);
|
||||
|
||||
if (j == 1) {
|
||||
strcpy(symbol->outfile, outfile);
|
||||
} else {
|
||||
symbol->output_options |= BARCODE_MEMORY_FILE;
|
||||
}
|
||||
ret = fm_open(fmp, symbol, "wb");
|
||||
assert_equal(ret, 1, "j:%d fm_open ret %d != 1\n", j, ret);
|
||||
|
||||
ret = fm_puts("1234567890", fmp);
|
||||
assert_equal(ret, 1, "j:%d fm_puts ret %d != 1\n", j, ret);
|
||||
if (j != 1) {
|
||||
assert_nonnull(fmp->mem, "mem NULL (%d: %s)\n", fmp->err, strerror(fmp->err));
|
||||
assert_equal(fmp->mempos, 10, "mempos %d != 10\n", (int) fmp->mempos);
|
||||
assert_zero(memcmp(fmp->mem, "1234567890", fmp->mempos), "memcmp fail\n");
|
||||
}
|
||||
|
||||
ret = fm_seek(fmp, -10, SEEK_CUR);
|
||||
assert_equal(ret, 1, "j:%d fm_seek ret %d != 1 (%d: %s)\n", j, ret, fmp->err, strerror(fmp->err));
|
||||
ret = fm_error(fmp);
|
||||
assert_zero(ret, "j:%d fm_error ret %d != 0\n", j, ret);
|
||||
ret = (int) fm_tell(fmp);
|
||||
assert_zero(ret, "j:%d fm_tell ret %d != 0\n", j, ret);
|
||||
|
||||
ret = fm_seek(fmp, 0, SEEK_END);
|
||||
assert_equal(ret, 1, "j:%d fm_seek ret %d != 1\n", j, ret);
|
||||
ret = fm_error(fmp);
|
||||
assert_zero(ret, "j:%d fm_error ret %d != 0\n", j, ret);
|
||||
ret = (int) fm_tell(fmp);
|
||||
assert_equal(ret, 10, "j:%d fm_tell ret %d != 10\n", j, ret);
|
||||
|
||||
ret = fm_seek(fmp, -1, SEEK_SET);
|
||||
assert_zero(ret, "j:%d fm_seek ret %d != 1\n", j, ret);
|
||||
assert_equal(fmp->err, EINVAL, "j:%d fmp->err %d (%s) != EINVAL\n", j, fmp->err, strerror(fmp->err));
|
||||
|
||||
ret = fm_close(fmp, symbol);
|
||||
assert_zero(ret, "j:%d fm_close ret %d != 0\n", j, ret);
|
||||
assert_equal(fmp->err, EINVAL, "j:%d fmp->err %d (%s) != EINVAL\n", j, fmp->err, strerror(fmp->err));
|
||||
|
||||
if (j == 1) {
|
||||
assert_zero(testUtilRemove(symbol->outfile), "testUtilRemove(%s) != 0\n", symbol->outfile);
|
||||
}
|
||||
|
||||
ret = fm_open(fmp, symbol, "wb");
|
||||
assert_equal(ret, 1, "j:%d fm_open ret %d != 1\n", j, ret);
|
||||
|
||||
ret = fm_seek(fmp, LONG_MAX, SEEK_CUR);
|
||||
if (j == 1) { /* May work on some file systems */
|
||||
if (ret == 0) {
|
||||
assert_equal(fmp->err, EINVAL, "j:%d fmp->err %d (%s) != EINVAL\n", j, fmp->err, strerror(fmp->err));
|
||||
}
|
||||
} else {
|
||||
assert_zero(ret, "j:%d fm_seek ret %d != 0\n", j, ret);
|
||||
assert_equal(fmp->err, EINVAL, "j:%d fmp->err %d (%s) != EINVAL\n", j, fmp->err, strerror(fmp->err));
|
||||
}
|
||||
|
||||
ret = fm_close(fmp, symbol);
|
||||
if (j == 1) { /* See above */
|
||||
if (ret == 0) {
|
||||
assert_equal(fmp->err, EINVAL, "j:%d fmp->err %d (%s) != EINVAL\n", j, fmp->err, strerror(fmp->err));
|
||||
}
|
||||
} else {
|
||||
assert_zero(ret, "j:%d fm_close ret %d != 0\n", j, ret);
|
||||
assert_equal(fmp->err, EINVAL, "j:%d fmp->err %d (%s) != EINVAL\n", j, fmp->err, strerror(fmp->err));
|
||||
}
|
||||
|
||||
if (j == 1) {
|
||||
assert_zero(testUtilRemove(symbol->outfile), "testUtilRemove(%s) != 0\n", symbol->outfile);
|
||||
}
|
||||
|
||||
ZBarcode_Clear(symbol);
|
||||
}
|
||||
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_large(const testCtx *const p_ctx) {
|
||||
int debug = p_ctx->debug;
|
||||
|
||||
int ret;
|
||||
struct zint_symbol *symbol = NULL;
|
||||
char data[] = "1";
|
||||
int expected_size = 354879;
|
||||
|
||||
(void)debug;
|
||||
|
||||
testStart("test_large");
|
||||
|
||||
symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = BARCODE_HANXIN;
|
||||
symbol->output_options |= BARCODE_MEMORY_FILE;
|
||||
strcpy(symbol->outfile, "out.gif"); /* Use GIF in case ZINT_NO_PNG */
|
||||
symbol->option_2 = 84;
|
||||
symbol->scale = 10.0f; /* Could go up to 86.5 (pixel buffer 0x3FB913B1, file size 8868579) but very very slow */
|
||||
|
||||
ret = ZBarcode_Encode_and_Print(symbol, TU(data), -1, 0);
|
||||
assert_zero(ret, "ZBarcode_Encode_and_Print ret %d != 0 (%s)\n", ret, symbol->errtxt);
|
||||
assert_nonnull(symbol->memfile, "memfile NULL (%s)\n", symbol->errtxt);
|
||||
assert_equal(symbol->memfile_size, expected_size, "memfile_size %d != expected %d\n",
|
||||
symbol->memfile_size, expected_size);
|
||||
|
||||
symbol->scale = 87.0f; /* Too large (pixel buffer > 1GB) */
|
||||
ret = ZBarcode_Print(symbol, 0);
|
||||
assert_equal(ret, ZINT_ERROR_MEMORY, "ZBarcode_Print ret %d != ZINT_ERROR_MEMORY (%s)\n", ret, symbol->errtxt);
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
|
||||
testFinish();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
testFunction funcs[] = { /* name, func */
|
||||
{ "test_svg", test_svg },
|
||||
{ "test_putsf", test_putsf },
|
||||
{ "test_printf", test_printf },
|
||||
{ "test_seek", test_seek },
|
||||
{ "test_large", test_large },
|
||||
};
|
||||
|
||||
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
|
||||
|
||||
testReport();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vim: set ts=4 sw=4 et : */
|
||||
|
@ -191,6 +191,8 @@ static void test_print(const testCtx *const p_ctx) {
|
||||
char expected_file[4096];
|
||||
char escaped[1024];
|
||||
int escaped_size = 1024;
|
||||
unsigned char filebuf[32768];
|
||||
int filebuf_size;
|
||||
|
||||
const char *const have_identify = testUtilHaveIdentify();
|
||||
|
||||
@ -268,7 +270,23 @@ static void test_print(const testCtx *const p_ctx) {
|
||||
|
||||
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(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||
|
||||
ret = testUtilReadFile(symbol->outfile, filebuf, sizeof(filebuf), &filebuf_size); /* For BARCODE_MEMORY_FILE */
|
||||
assert_zero(ret, "i:%d %s testUtilReadFile(%s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret);
|
||||
|
||||
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
|
||||
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||
}
|
||||
|
||||
symbol->output_options |= BARCODE_MEMORY_FILE;
|
||||
ret = ZBarcode_Print(symbol, 0);
|
||||
assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0 (%s)\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret, symbol->errtxt);
|
||||
assert_nonnull(symbol->memfile, "i:%d %s memfile NULL\n", i, testUtilBarcodeName(data[i].symbology));
|
||||
assert_equal(symbol->memfile_size, filebuf_size, "i:%d %s memfile_size %d != %d\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), symbol->memfile_size, filebuf_size);
|
||||
assert_zero(memcmp(symbol->memfile, filebuf, symbol->memfile_size), "i:%d %s memcmp(memfile, filebuf) != 0\n",
|
||||
i, testUtilBarcodeName(data[i].symbology));
|
||||
}
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
|
@ -31,7 +31,6 @@
|
||||
|
||||
#include "testcommon.h"
|
||||
#include "../output.h"
|
||||
#include <locale.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <direct.h>
|
||||
@ -411,82 +410,6 @@ static void test_fopen(const testCtx *const p_ctx) {
|
||||
testFinish();
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
extern FILE *fmemopen(void *buf, size_t size, const char *mode);
|
||||
#endif
|
||||
|
||||
static void test_out_putsf(const testCtx *const p_ctx) {
|
||||
int debug = p_ctx->debug;
|
||||
|
||||
struct item {
|
||||
const char *prefix;
|
||||
int dp;
|
||||
float arg;
|
||||
const char *locale;
|
||||
const char *expected;
|
||||
};
|
||||
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
|
||||
struct item data[] = {
|
||||
/* 0*/ { "", 2, 1234.123, "", "1234.12" },
|
||||
/* 1*/ { "", 3, 1234.123, "", "1234.123" },
|
||||
/* 2*/ { "prefix ", 4, 1234.123, "", "prefix 1234.123" },
|
||||
/* 3*/ { "", 2, -1234.126, "", "-1234.13" },
|
||||
/* 4*/ { "", 2, 1234.1, "", "1234.1" },
|
||||
/* 5*/ { "", 3, 1234.1, "", "1234.1" },
|
||||
/* 6*/ { "", 4, 1234.1, "", "1234.1" },
|
||||
/* 7*/ { "", 2, 1234.0, "", "1234" },
|
||||
/* 8*/ { "", 2, -1234.0, "", "-1234" },
|
||||
/* 9*/ { "", 3, 1234.1234, "de_DE.UTF-8", "1234.123" },
|
||||
/* 10*/ { "", 4, -1234.1234, "de_DE.UTF-8", "-1234.1234" },
|
||||
/* 11*/ { "prefix ", 4, -1234.1234, "de_DE.UTF-8", "prefix -1234.1234" },
|
||||
};
|
||||
int data_size = ARRAY_SIZE(data);
|
||||
int i;
|
||||
|
||||
FILE *fp;
|
||||
char buf[512] = {0}; /* Suppress clang-16/17 run-time exception MemorySanitizer: use-of-uninitialized-value */
|
||||
|
||||
testStart("test_out_putsf");
|
||||
|
||||
#ifdef _WIN32
|
||||
(void)i; (void)fp; (void)buf;
|
||||
testSkip("Test not implemented on Windows");
|
||||
#else
|
||||
|
||||
for (i = 0; i < data_size; i++) {
|
||||
const char *locale = NULL;
|
||||
|
||||
if (testContinue(p_ctx, i)) continue;
|
||||
|
||||
buf[0] = '\0';
|
||||
fp = fmemopen(buf, sizeof(buf), "w");
|
||||
assert_nonnull(fp, "%d: fmemopen fail (%d, %s)\n", i, errno, strerror(errno));
|
||||
|
||||
if (data[i].locale && data[i].locale[0]) {
|
||||
locale = setlocale(LC_ALL, data[i].locale);
|
||||
if (!locale) { /* May not be available - warn unless quiet mode */
|
||||
if (!(debug & ZINT_DEBUG_TEST_LESS_NOISY)) {
|
||||
printf("%d: Warning: locale \"%s\" not available\n", i, data[i].locale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out_putsf(data[i].prefix, data[i].dp, data[i].arg, fp);
|
||||
|
||||
assert_zero(fclose(fp), "%d: fclose fail (%d, %s)\n", i, errno, strerror(errno));
|
||||
|
||||
if (locale) {
|
||||
assert_nonnull(setlocale(LC_ALL, locale), "%d: setlocale(%s) restore fail (%d, %s)\n",
|
||||
i, locale, errno, strerror(errno));
|
||||
}
|
||||
|
||||
assert_zero(strcmp(buf, data[i].expected), "%d: strcmp(%s, %s) != 0\n", i, buf, data[i].expected);
|
||||
}
|
||||
|
||||
testFinish();
|
||||
#endif /* _WIN32 */
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
testFunction funcs[] = { /* name, func */
|
||||
@ -496,7 +419,6 @@ int main(int argc, char *argv[]) {
|
||||
{ "test_quiet_zones", test_quiet_zones },
|
||||
{ "test_set_whitespace_offsets", test_set_whitespace_offsets },
|
||||
{ "test_fopen", test_fopen },
|
||||
{ "test_out_putsf", test_out_putsf },
|
||||
};
|
||||
|
||||
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
|
||||
|
@ -65,6 +65,8 @@ static void test_print(const testCtx *const p_ctx) {
|
||||
char expected_file[4096];
|
||||
char escaped[1024];
|
||||
int escaped_size = 1024;
|
||||
unsigned char filebuf[36864];
|
||||
int filebuf_size;
|
||||
|
||||
const char *const have_identify = testUtilHaveIdentify();
|
||||
|
||||
@ -134,7 +136,23 @@ static void test_print(const testCtx *const p_ctx) {
|
||||
|
||||
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(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||
|
||||
ret = testUtilReadFile(symbol->outfile, filebuf, sizeof(filebuf), &filebuf_size); /* For BARCODE_MEMORY_FILE */
|
||||
assert_zero(ret, "i:%d %s testUtilReadFile(%s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret);
|
||||
|
||||
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
|
||||
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||
}
|
||||
|
||||
symbol->output_options |= BARCODE_MEMORY_FILE;
|
||||
ret = ZBarcode_Print(symbol, 0);
|
||||
assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0 (%s)\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret, symbol->errtxt);
|
||||
assert_nonnull(symbol->memfile, "i:%d %s memfile NULL\n", i, testUtilBarcodeName(data[i].symbology));
|
||||
assert_equal(symbol->memfile_size, filebuf_size, "i:%d %s memfile_size %d != %d\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), symbol->memfile_size, filebuf_size);
|
||||
assert_zero(memcmp(symbol->memfile, filebuf, symbol->memfile_size), "i:%d %s memcmp(memfile, filebuf) != 0\n",
|
||||
i, testUtilBarcodeName(data[i].symbology));
|
||||
}
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
|
@ -144,8 +144,8 @@ static void test_options(const testCtx *const p_ctx) {
|
||||
/* 9*/ { BARCODE_PDF417, -1, 10, -1, 0, { 0, 0, "" }, "12345", 0, 0, 3, 239, "", -1 }, /* ECC auto-set to 2, cols 10 */
|
||||
/* 10*/ { BARCODE_PDF417, 9, -1, -1, 0, { 0, 0, "" }, "12345", ZINT_WARN_INVALID_OPTION, 0, 6, 103, "Warning 460: Security value out of range", -1 }, /* Invalid ECC, auto-set */
|
||||
/* 11*/ { BARCODE_PDF417, -1, 31, -1, 0, { 0, 0, "" }, "12345", ZINT_WARN_INVALID_OPTION, 0, 6, 103, "Warning 461: Number of columns out of range (1 to 30)", 0 }, /* Invalid cols, auto-set */
|
||||
/* 12*/ { BARCODE_PDF417, -1, -1, 2, 0, { 0, 0, "" }, "12345", ZINT_ERROR_INVALID_OPTION, 0, 0, 0, "Error 466: Number of rows out of range (3 to 90)", -1 }, /* Invalid rows, error */
|
||||
/* 13*/ { BARCODE_PDF417, -1, -1, 91, 0, { 0, 0, "" }, "12345", ZINT_ERROR_INVALID_OPTION, 0, 0, 0, "Error 466: Number of rows out of range (3 to 90)", -1 }, /* Invalid rows, error */
|
||||
/* 12*/ { BARCODE_PDF417, -1, -1, 2, 0, { 0, 0, "" }, "12345", ZINT_ERROR_INVALID_OPTION, ZINT_ERROR_INVALID_OPTION, 0, 0, "Error 466: Number of rows out of range (3 to 90)", -1 }, /* Invalid rows, error */
|
||||
/* 13*/ { BARCODE_PDF417, -1, -1, 91, 0, { 0, 0, "" }, "12345", ZINT_ERROR_INVALID_OPTION, ZINT_ERROR_INVALID_OPTION, 0, 0, "Error 466: Number of rows out of range (3 to 90)", -1 }, /* Invalid rows, error */
|
||||
/* 14*/ { BARCODE_PDF417, 9, -1, -1, WARN_FAIL_ALL, { 0, 0, "" }, "12345", ZINT_ERROR_INVALID_OPTION, -1, 0, 0, "Error 460: Security value out of range", -1 }, /* Invalid ECC */
|
||||
/* 15*/ { BARCODE_PDF417, -1, 31, -1, WARN_FAIL_ALL, { 0, 0, "" }, "12345", ZINT_ERROR_INVALID_OPTION, -1, 0, 0, "Error 461: Number of columns out of range (1 to 30)", -1 }, /* Invalid cols */
|
||||
/* 16*/ { BARCODE_PDF417, -1, 30, 31, 0, { 0, 0, "" }, "12345", ZINT_ERROR_INVALID_OPTION, -1, 0, 0, "Error 475: Columns x rows out of range (1 to 928)", -1 }, /* Rows * cols (930) > 928 */
|
||||
@ -160,11 +160,11 @@ static void test_options(const testCtx *const p_ctx) {
|
||||
/* 25*/ { BARCODE_MICROPDF417, -1, 5, -1, WARN_FAIL_ALL, { 0, 0, "" }, "12345", ZINT_ERROR_INVALID_OPTION, -1, 0, 0, "Error 468: Specified width out of range", -1 }, /* Invalid cols */
|
||||
/* 26*/ { BARCODE_MICROPDF417, -1, 5, 3, 0, { 0, 0, "" }, "12345", ZINT_ERROR_INVALID_OPTION, -1, 0, 0, "Error 476: Cannot specify rows for MicroPDF417", -1 }, /* Rows option not available */
|
||||
/* 27*/ { BARCODE_MICROPDF417, -1, 1, -1, 0, { 0, 0, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLM", ZINT_WARN_INVALID_OPTION, 0, 17, 55, "Warning 469: Specified symbol size too small for data", -1 }, /* Cols 1 too small, auto-upped to 2 with warning */
|
||||
/* 28*/ { BARCODE_MICROPDF417, -1, 1, -1, WARN_FAIL_ALL, { 0, 0, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLM", ZINT_ERROR_INVALID_OPTION, 0, 0, 0, "Error 469: Specified symbol size too small for data", -1 }, /* Cols 1 too small */
|
||||
/* 28*/ { BARCODE_MICROPDF417, -1, 1, -1, WARN_FAIL_ALL, { 0, 0, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLM", ZINT_ERROR_INVALID_OPTION, ZINT_ERROR_INVALID_OPTION, 0, 0, "Error 469: Specified symbol size too small for data", -1 }, /* Cols 1 too small */
|
||||
/* 29*/ { BARCODE_MICROPDF417, -1, 2, -1, 0, { 0, 0, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWX", ZINT_WARN_INVALID_OPTION, 0, 15, 99, "Warning 470: Specified symbol size too small for data", -1 }, /* Cols 2 too small, auto-upped to 4 with warning */
|
||||
/* 30*/ { BARCODE_MICROPDF417, -1, 2, -1, WARN_FAIL_ALL, { 0, 0, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWX", ZINT_ERROR_INVALID_OPTION, 0, 0, 0, "Error 470: Specified symbol size too small for data", -1 }, /* Cols 2 too small */
|
||||
/* 30*/ { BARCODE_MICROPDF417, -1, 2, -1, WARN_FAIL_ALL, { 0, 0, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWX", ZINT_ERROR_INVALID_OPTION, ZINT_ERROR_INVALID_OPTION, 0, 0, "Error 470: Specified symbol size too small for data", -1 }, /* Cols 2 too small */
|
||||
/* 31*/ { BARCODE_MICROPDF417, -1, 3, -1, 0, { 0, 0, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKL", ZINT_WARN_INVALID_OPTION, 0, 32, 99, "Warning 471: Specified symbol size too small for data", -1 }, /* Cols 3 too small, auto-upped to 4 with warning */
|
||||
/* 32*/ { BARCODE_MICROPDF417, -1, 3, -1, WARN_FAIL_ALL, { 0, 0, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKL", ZINT_ERROR_INVALID_OPTION, 0, 0, 0, "Error 471: Specified symbol size too small for data", -1 }, /* Cols 3 too small */
|
||||
/* 32*/ { BARCODE_MICROPDF417, -1, 3, -1, WARN_FAIL_ALL, { 0, 0, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKLMOPQRSTUVWXYZABCDEFGHIJKL", ZINT_ERROR_INVALID_OPTION, ZINT_ERROR_INVALID_OPTION, 0, 0, "Error 471: Specified symbol size too small for data", -1 }, /* Cols 3 too small */
|
||||
/* 33*/ { BARCODE_PDF417, -1, 1, -1, 0, { 0, 0, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH", ZINT_WARN_INVALID_OPTION, 0, 89, 103, "Warning 748: Columns increased from 1 to 2", -1 }, /* Cols 1 auto-upped to 2 just fits, now with warning */
|
||||
/* 34*/ { BARCODE_PDF417, -1, 1, -1, 0, { 1, 2, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH", ZINT_WARN_INVALID_OPTION, 0, 67, 120, "Warning 748: Columns increased from 1 to 3", -1 }, /* Cols 1 too small with Structured Append, used to fail, now auto-upped to 3 with warning */
|
||||
/* 35*/ { BARCODE_PDF417, -1, 1, -1, 0, { 1, 2, "" }, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRST", ZINT_WARN_INVALID_OPTION, 0, 89, 103, "Warning 748: Columns increased from 1 to 2", -1 }, /* Cols 1 with Structured Append auto-upped to 2 just fits, now with warning */
|
||||
|
@ -239,6 +239,8 @@ static void test_print(const testCtx *const p_ctx) {
|
||||
char expected_file[1024];
|
||||
char escaped[1024];
|
||||
int escaped_size = 1024;
|
||||
unsigned char filebuf[32768];
|
||||
int filebuf_size;
|
||||
char *text;
|
||||
|
||||
const char *const have_identify = testUtilHaveIdentify();
|
||||
@ -330,7 +332,23 @@ static void test_print(const testCtx *const p_ctx) {
|
||||
assert_zero(ret, "i:%d %s testUtilCmpPngs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
|
||||
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(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||
|
||||
ret = testUtilReadFile(symbol->outfile, filebuf, sizeof(filebuf), &filebuf_size); /* For BARCODE_MEMORY_FILE */
|
||||
assert_zero(ret, "i:%d %s testUtilReadFile(%s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret);
|
||||
|
||||
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
|
||||
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||
}
|
||||
|
||||
symbol->output_options |= BARCODE_MEMORY_FILE;
|
||||
ret = ZBarcode_Print(symbol, 0);
|
||||
assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0 (%s)\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret, symbol->errtxt);
|
||||
assert_nonnull(symbol->memfile, "i:%d %s memfile NULL\n", i, testUtilBarcodeName(data[i].symbology));
|
||||
assert_equal(symbol->memfile_size, filebuf_size, "i:%d %s memfile_size %d != %d\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), symbol->memfile_size, filebuf_size);
|
||||
assert_zero(memcmp(symbol->memfile, filebuf, symbol->memfile_size), "i:%d %s memcmp(memfile, filebuf) != 0\n",
|
||||
i, testUtilBarcodeName(data[i].symbology));
|
||||
}
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
|
@ -117,8 +117,9 @@ static void test_print(const testCtx *const p_ctx) {
|
||||
int i, length, ret;
|
||||
struct zint_symbol *symbol = NULL;
|
||||
|
||||
const char *data_dir = "/backend/tests/data/eps";
|
||||
const char *eps = "out.eps";
|
||||
const char data_dir[] = "/backend/tests/data/eps";
|
||||
const char eps[] = "out.eps";
|
||||
const char memfile[] = "mem.eps";
|
||||
char expected_file[1024];
|
||||
char escaped[1024];
|
||||
int escaped_size = 1024;
|
||||
@ -193,7 +194,25 @@ static void test_print(const testCtx *const p_ctx) {
|
||||
|
||||
ret = testUtilCmpEpss(symbol->outfile, expected_file);
|
||||
assert_zero(ret, "i:%d %s testUtilCmpEpss(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
|
||||
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||
|
||||
symbol->output_options |= BARCODE_MEMORY_FILE;
|
||||
ret = ZBarcode_Print(symbol, data[i].rotate_angle);
|
||||
assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0 (%s)\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret, symbol->errtxt);
|
||||
assert_nonnull(symbol->memfile, "i:%d %s memfile NULL\n", i, testUtilBarcodeName(data[i].symbology));
|
||||
assert_nonzero(symbol->memfile_size, "i:%d %s memfile_size 0\n", i, testUtilBarcodeName(data[i].symbology));
|
||||
|
||||
ret = testUtilWriteFile(memfile, symbol->memfile, symbol->memfile_size, "wb");
|
||||
assert_zero(ret, "%d: testUtilWriteFile(%s) fail ret %d != 0\n", i, memfile, ret);
|
||||
|
||||
ret = testUtilCmpEpss(symbol->outfile, memfile);
|
||||
assert_zero(ret, "i:%d %s testUtilCmpEpss(%s, %s) %d != 0\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), symbol->outfile, memfile, ret);
|
||||
|
||||
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
|
||||
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||
assert_zero(testUtilRemove(memfile), "i:%d testUtilRemove(%s) != 0\n", i, memfile);
|
||||
}
|
||||
}
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
|
@ -144,8 +144,9 @@ static void test_print(const testCtx *const p_ctx) {
|
||||
int i, length, ret;
|
||||
struct zint_symbol *symbol = NULL;
|
||||
|
||||
const char *data_dir = "/backend/tests/data/svg";
|
||||
const char *svg = "out.svg";
|
||||
const char data_dir[] = "/backend/tests/data/svg";
|
||||
const char svg[] = "out.svg";
|
||||
const char memfile[] = "mem.eps";
|
||||
char expected_file[1024];
|
||||
char escaped[1024];
|
||||
int escaped_size = 1024;
|
||||
@ -240,7 +241,25 @@ static void test_print(const testCtx *const p_ctx) {
|
||||
|
||||
ret = testUtilCmpSvgs(symbol->outfile, expected_file);
|
||||
assert_zero(ret, "i:%d %s testUtilCmpSvgs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
|
||||
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||
|
||||
symbol->output_options |= BARCODE_MEMORY_FILE;
|
||||
ret = ZBarcode_Print(symbol, data[i].rotate_angle);
|
||||
assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0 (%s)\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret, symbol->errtxt);
|
||||
assert_nonnull(symbol->memfile, "i:%d %s memfile NULL\n", i, testUtilBarcodeName(data[i].symbology));
|
||||
assert_nonzero(symbol->memfile_size, "i:%d %s memfile_size 0\n", i, testUtilBarcodeName(data[i].symbology));
|
||||
|
||||
ret = testUtilWriteFile(memfile, symbol->memfile, symbol->memfile_size, "wb");
|
||||
assert_zero(ret, "%d: testUtilWriteFile(%s) fail ret %d != 0\n", i, memfile, ret);
|
||||
|
||||
ret = testUtilCmpSvgs(symbol->outfile, memfile);
|
||||
assert_zero(ret, "i:%d %s testUtilCmpSvgs(%s, %s) %d != 0\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), symbol->outfile, memfile, ret);
|
||||
|
||||
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
|
||||
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||
assert_zero(testUtilRemove(memfile), "i:%d testUtilRemove(%s) != 0\n", i, memfile);
|
||||
}
|
||||
}
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
|
@ -214,6 +214,8 @@ static void test_print(const testCtx *const p_ctx) {
|
||||
char expected_file[1024];
|
||||
char escaped[1024];
|
||||
int escaped_size = 1024;
|
||||
unsigned char filebuf[32768];
|
||||
int filebuf_size;
|
||||
char *text;
|
||||
|
||||
int have_tiffinfo = testUtilHaveTiffInfo();
|
||||
@ -301,7 +303,23 @@ static void test_print(const testCtx *const p_ctx) {
|
||||
|
||||
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(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||
|
||||
ret = testUtilReadFile(symbol->outfile, filebuf, sizeof(filebuf), &filebuf_size); /* For BARCODE_MEMORY_FILE */
|
||||
assert_zero(ret, "i:%d %s testUtilReadFile(%s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret);
|
||||
|
||||
if (!(debug & ZINT_DEBUG_TEST_KEEP_OUTFILE)) {
|
||||
assert_zero(testUtilRemove(symbol->outfile), "i:%d testUtilRemove(%s) != 0\n", i, symbol->outfile);
|
||||
}
|
||||
|
||||
symbol->output_options |= BARCODE_MEMORY_FILE;
|
||||
ret = ZBarcode_Print(symbol, 0);
|
||||
assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0 (%s)\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret, symbol->errtxt);
|
||||
assert_nonnull(symbol->memfile, "i:%d %s memfile NULL\n", i, testUtilBarcodeName(data[i].symbology));
|
||||
assert_equal(symbol->memfile_size, filebuf_size, "i:%d %s memfile_size %d != %d\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), symbol->memfile_size, filebuf_size);
|
||||
assert_zero(memcmp(symbol->memfile, filebuf, symbol->memfile_size), "i:%d %s memcmp(memfile, filebuf) != 0\n",
|
||||
i, testUtilBarcodeName(data[i].symbology));
|
||||
}
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
|
@ -1516,6 +1516,67 @@ int testUtilRmROFile(const char *filename) {
|
||||
return testUtilRemove(filename);
|
||||
}
|
||||
|
||||
/* Read file into buffer */
|
||||
int testUtilReadFile(const char *filename, unsigned char *buffer, int buffer_size, int *p_size) {
|
||||
long fileLen;
|
||||
size_t n;
|
||||
size_t nRead = 0;
|
||||
FILE *fp = testUtilOpen(filename, "rb");
|
||||
if (!fp) {
|
||||
return 1;
|
||||
}
|
||||
if (fseek(fp, 0, SEEK_END) != 0) {
|
||||
(void) fclose(fp);
|
||||
return 2;
|
||||
}
|
||||
fileLen = ftell(fp);
|
||||
if (fileLen <= 0 || fileLen == LONG_MAX) {
|
||||
(void) fclose(fp);
|
||||
return 3;
|
||||
}
|
||||
if (fseek(fp, 0, SEEK_SET) != 0) {
|
||||
(void) fclose(fp);
|
||||
return 4;
|
||||
}
|
||||
if (fileLen > (long) buffer_size) {
|
||||
(void) fclose(fp);
|
||||
return 5;
|
||||
}
|
||||
do {
|
||||
n = fread(buffer + nRead, 1, fileLen - nRead, fp);
|
||||
if (ferror(fp)) {
|
||||
(void) fclose(fp);
|
||||
return 6;
|
||||
}
|
||||
nRead += n;
|
||||
} while (!feof(fp) && (0 < n) && ((long) nRead < fileLen));
|
||||
|
||||
if (fclose(fp) != 0) {
|
||||
return 7;
|
||||
}
|
||||
|
||||
*p_size = (int) nRead;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Write file from buffer */
|
||||
int testUtilWriteFile(const char *filename, const unsigned char *buffer, const int buffer_size, const char *mode) {
|
||||
FILE *fp = testUtilOpen(filename, mode);
|
||||
if (!fp) {
|
||||
return 1;
|
||||
}
|
||||
if (fwrite(buffer, 1, buffer_size, fp) == 0) {
|
||||
(void) fclose(fp);
|
||||
return 2;
|
||||
}
|
||||
if (fclose(fp) != 0) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Compare 2 PNG files */
|
||||
int testUtilCmpPngs(const char *png1, const char *png2) {
|
||||
int ret = -1;
|
||||
@ -3945,7 +4006,15 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in
|
||||
int primary_len = (int) strlen(primary);
|
||||
int maxi_len = 0;
|
||||
if (symbol->option_2 >= 1 && symbol->option_2 <= 100) {
|
||||
/* Suppress gcc warning null destination pointer [-Wformat-overflow=] false-positive */
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-overflow="
|
||||
#endif
|
||||
sprintf(maxi, "[)>\03601\035%02d", symbol->option_2 - 1);
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
maxi_len = (int) strlen(maxi);
|
||||
}
|
||||
#if 1
|
||||
|
@ -57,7 +57,7 @@ extern "C" {
|
||||
#define testutil_pclose(stream) _pclose(stream)
|
||||
#else
|
||||
#include <unistd.h>
|
||||
# if defined(ZINT_IS_C89)
|
||||
# if defined(ZINT_IS_C89) || defined(ZINT_IS_C99)
|
||||
extern FILE *popen(const char *command, const char *type);
|
||||
extern int pclose(FILE *stream);
|
||||
# endif
|
||||
@ -174,6 +174,8 @@ int testUtilRmDir(const char *dirname);
|
||||
int testUtilRename(const char *oldpath, const char *newpath);
|
||||
int testUtilCreateROFile(const char *filename);
|
||||
int testUtilRmROFile(const char *filename);
|
||||
int testUtilReadFile(const char *filename, unsigned char *buffer, int buffer_size, int *p_size);
|
||||
int testUtilWriteFile(const char *filename, const unsigned char *buffer, const int buffer_size, const char *mode);
|
||||
|
||||
int testUtilCmpPngs(const char *file1, const char *file2);
|
||||
int testUtilCmpTxts(const char *txt1, const char *txt2);
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user