Test suite: add testRun allowing args; testSkip; haveIdentify/etc; general tidy-up

This commit is contained in:
gitlost 2020-05-05 22:28:25 +01:00
parent 3fea67890b
commit 5eafa2e094
38 changed files with 2211 additions and 1518 deletions

View File

@ -17,31 +17,31 @@ find_package(PNG)
if(PNG_FOUND)
include_directories(${PNG_INCLUDES})
else (PNG_FOUND)
else()
add_definitions(-DNO_PNG)
endif (PNG_FOUND)
endif()
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
if(ZINT_DEBUG)
add_compile_options("-g")
endif (ZINT_DEBUG)
endif()
if(ZINT_SANITIZE)
add_compile_options("-fsanitize=undefined")
add_compile_options("-fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined -fsanitize=address")
endif (ZINT_SANITIZE)
endif()
if(ZINT_TEST)
add_definitions("-DZINT_TEST")
endif (ZINT_TEST)
endif()
endif()
add_library(testcommon
testcommon.c testcommon.h)
if(PNG_FOUND)
target_link_libraries(testcommon ZINT::ZINT ${PNG_LIBRARIES})
else (PNG_FOUND)
else()
target_link_libraries(testcommon ZINT::ZINT)
endif (PNG_FOUND)
endif()
macro(zint_add_test test_name test_command)
set(ADDITIONAL_LIBS "${ARGN}" ${LIBRARY_FLAGS})

View File

@ -20,15 +20,36 @@ Then make the tests:
(ZINT_TEST is needed to export INTERNAL functions for use and testing.)
To run all tests:
------------------------------------------------------------------------------
make test
To run all tests (within <project-dir>/backend/tests/build):
ctest
To run individual tests, eg:
./test_common
./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
To run a single dataset item in a single test function, use '-i <index>':
./test_dotcode -f input -i 2
To show debug info (if any), use '-d <flag>':
./test_dotcode -f input -i 2 -d 1
To generate test data, use '-g':
./test_dotcode -f encode -g
------------------------------------------------------------------------------
To make with gcc sanitize, first set for libzint and make:
cd <project-dir>

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2020 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,8 +32,8 @@
#include "testcommon.h"
// #181 Christian Hartlage OSS-Fuzz
static void test_fuzz(void)
{
static void test_fuzz(int index, int debug) {
testStart("");
int ret;
@ -56,10 +56,14 @@ static void test_fuzz(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->debug |= debug;
int length = data[i].length;
if (length == -1) {
length = strlen(data[i].data);
@ -74,9 +78,13 @@ static void test_fuzz(void)
testFinish();
}
int main()
{
test_fuzz();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_fuzz", test_fuzz, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -29,12 +29,10 @@
*/
/* vim: set ts=4 sw=4 et : */
//#define TEST_ENCODE_GENERATE_EXPECTED 1
#include "testcommon.h"
static void test_encode(void)
{
static void test_encode(int index, int generate, int debug) {
testStart("");
int ret;
@ -408,6 +406,8 @@ static void test_encode(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -419,20 +419,20 @@ static void test_encode(void)
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
//symbol->debug = ZINT_DEBUG_PRINT;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_ENCODE_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, %s, %d, %d, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2,
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
#else
} else {
if (ret < 5) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
@ -443,7 +443,7 @@ static void test_encode(void)
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
}
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -452,8 +452,8 @@ static void test_encode(void)
}
// #181 Nico Gunkel OSS-Fuzz
static void test_fuzz(void)
{
static void test_fuzz(int index, int debug) {
testStart("");
int ret;
@ -873,6 +873,8 @@ static void test_fuzz(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -887,6 +889,7 @@ static void test_fuzz(void)
if (data[i].option_1 != -1) {
symbol->option_1 = data[i].option_1;
}
symbol->debug |= debug;
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
@ -897,10 +900,14 @@ static void test_fuzz(void)
testFinish();
}
int main()
{
test_encode();
test_fuzz();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_encode", test_encode, 1, 1, 1 },
{ "test_fuzz", test_fuzz, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2019 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -30,8 +30,8 @@
#include "testcommon.h"
static void test_encode(void)
{
static void test_encode(int index, int debug) {
testStart("");
int ret;
@ -43,7 +43,7 @@ static void test_encode(void)
float h;
int ret_vector;
};
// Vi} :s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { "0", 0, 0, 100, 30, 0 },
/* 1*/ { "1", 1, 0, 100, 30, 0 },
@ -67,11 +67,15 @@ static void test_encode(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_CHANNEL;
symbol->option_2 = data[i].option_2;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
@ -88,9 +92,13 @@ static void test_encode(void)
testFinish();
}
int main()
{
test_encode();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_encode", test_encode, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008 - 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -29,36 +29,41 @@
*/
/* vim: set ts=4 sw=4 et : */
//#define TEST_ENCODE_GENERATE_EXPECTED 1
#include "testcommon.h"
static void test_options(void)
{
static void test_options(int index, int debug) {
testStart("");
int ret;
struct item {
unsigned char* data;
int option_1;
int option_2;
unsigned char *data;
int ret;
char *comment;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { "é", -1, -1, 0, "" },
/* 0*/ { -1, -1, "é", 0, "" },
};
int data_size = sizeof(data) / sizeof(struct item);
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_CODABLOCKF;
if (data[i].option_1 != -1) {
symbol->option_1 = data[i].option_1;
}
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
@ -71,8 +76,8 @@ static void test_options(void)
testFinish();
}
static void test_encode(void)
{
static void test_encode(int index, int generate, int debug) {
testStart("");
int ret;
@ -127,6 +132,8 @@ static void test_encode(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -138,20 +145,20 @@ static void test_encode(void)
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
//symbol->debug = ZINT_DEBUG_PRINT;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_ENCODE_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
#else
} else {
if (ret < 5) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
@ -162,7 +169,7 @@ static void test_encode(void)
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
}
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -171,8 +178,8 @@ static void test_encode(void)
}
// #181 Christian Hartlage OSS-Fuzz
static void test_fuzz(void)
{
static void test_fuzz(int index, int debug) {
testStart("");
int ret;
@ -189,10 +196,14 @@ static void test_fuzz(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_CODABLOCKF;
symbol->debug |= debug;
int length = data[i].length;
if (length == -1) {
length = strlen(data[i].data);
@ -207,11 +218,15 @@ static void test_fuzz(void)
testFinish();
}
int main()
{
test_options();
test_encode();
test_fuzz();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_options", test_options, 1, 0, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
{ "test_fuzz", test_fuzz, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -32,33 +32,33 @@
#include "testcommon.h"
// #181 Nico Gunkel OSS-Fuzz
static void test_fuzz(void)
{
static void test_fuzz(int index, int debug) {
testStart("");
int ret;
struct item {
int symbology;
unsigned char *data;
int length;
int ret;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { BARCODE_CODEONE, "3333P33B\035333V3333333333333\0363", -1, 0 },
/* 0*/ { "3333P33B\035333V3333333333333\0363", -1, 0 },
};
int data_size = sizeof(data) / sizeof(struct item);
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
int length = data[i].length;
if (length == -1) {
length = strlen(data[i].data);
}
symbol->symbology = BARCODE_CODEONE;
symbol->debug |= debug;
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
@ -69,9 +69,13 @@ static void test_fuzz(void)
testFinish();
}
int main()
{
test_fuzz();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_fuzz", test_fuzz, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -31,10 +31,8 @@
#include "testcommon.h"
//#define TEST_ENCODE_GENERATE_EXPECTED 1
static void test_input(int index, int debug) {
static void test_input(void)
{
testStart("");
int ret;
@ -62,11 +60,14 @@ static void test_input(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->input_mode = data[i].input_mode;
symbol->debug |= debug;
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
@ -79,8 +80,8 @@ static void test_input(void)
testFinish();
}
static void test_encode(void)
{
static void test_encode(int index, int generate, int debug) {
testStart("");
int ret;
@ -100,7 +101,7 @@ static void test_encode(void)
/* 0*/ { BARCODE_CODE128, UNICODE_MODE, -1, "AIM", 0, 1, 68, "ISO/IEC 15417:2007 Figure 1",
"11010010000101000110001100010001010111011000101110110001100011101011"
},
/* 1*/ { BARCODE_CODE128B, UNICODE_MODE, -1, "AIM", 0, 1, 68, "",
/* 1*/ { BARCODE_CODE128B, UNICODE_MODE, -1, "AIM", 0, 1, 68, "128B same",
"11010010000101000110001100010001010111011000101110110001100011101011"
},
/* 2*/ { BARCODE_CODE128, UNICODE_MODE, 16, "AIM", 0, 1, 79, "READER_INIT",
@ -119,6 +120,8 @@ static void test_encode(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -127,19 +130,20 @@ static void test_encode(void)
if (data[i].output_options != -1) {
symbol->output_options = data[i].output_options;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_ENCODE_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, %s, %d, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].output_options, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
#else
} else {
if (ret < 5) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
@ -150,7 +154,7 @@ static void test_encode(void)
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
}
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -158,10 +162,14 @@ static void test_encode(void)
testFinish();
}
int main()
{
test_input();
test_encode();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_input", test_input, 1, 0, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -31,8 +31,8 @@
#include "testcommon.h"
static void test_utf8_to_unicode(void)
{
static void test_utf8_to_unicode(int index, int debug) {
testStart("");
int ret;
@ -57,9 +57,12 @@ static void test_utf8_to_unicode(void)
int vals[20];
struct zint_symbol symbol;
symbol.debug |= debug;
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
size_t ret_length = length;
@ -76,8 +79,8 @@ static void test_utf8_to_unicode(void)
testFinish();
}
static void test_debug_test_codeword_dump_int(void)
{
static void test_debug_test_codeword_dump_int(int index, int debug) {
testStart("");
int ret;
@ -94,9 +97,12 @@ static void test_debug_test_codeword_dump_int(void)
int data_size = sizeof(data) / sizeof(struct item);
struct zint_symbol symbol;
symbol.debug |= debug;
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
debug_test_codeword_dump_int(&symbol, data[i].codewords, data[i].length);
assert_nonzero(strlen(symbol.errtxt) < 92, "i:%d strlen(%s) >= 92 (%zu)\n", i, symbol.errtxt, strlen(symbol.errtxt));
assert_zero(strcmp(symbol.errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0 (%zu, %zu)\n", i, symbol.errtxt, data[i].expected, strlen(symbol.errtxt), strlen(data[i].expected));
@ -105,10 +111,14 @@ static void test_debug_test_codeword_dump_int(void)
testFinish();
}
int main()
{
test_utf8_to_unicode();
test_debug_test_codeword_dump_int();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_utf8_to_unicode", test_utf8_to_unicode, 1, 0, 1 },
{ "test_debug_test_codeword_dump_int", test_debug_test_codeword_dump_int, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2019 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -31,16 +31,8 @@
#include "testcommon.h"
//#define TEST_EXAMPLES_GENERATE_EXPECTED 1
//#define TEST_ODD_NUMBERED_NUMERIC_GENERATE_EXPECTED 1
//#define TEST_EAN128_CC_SHIFT_GENERATE_EXPECTED 1
//#define TEST_EAN128_CC_WIDTH_GENERATE_EXPECTED 1
//#define TEST_ENCODATION_0_GENERATE_EXPECTED 1
//#define TEST_ENCODATION_10_GENERATE_EXPECTED 1
//#define TEST_ENCODATION_11_GENERATE_EXPECTED 1
static void test_eanx_leading_zeroes(int index, int debug) {
static void test_eanx_leading_zeroes(void)
{
testStart("");
int ret;
@ -84,10 +76,14 @@ static void test_eanx_leading_zeroes(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->debug |= debug;
int length = strlen(data[i].data);
assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data);
@ -105,8 +101,7 @@ static void test_eanx_leading_zeroes(void)
testFinish();
}
static void test_helper_generate(const struct zint_symbol* symbol, int ret, int i, unsigned char* data, unsigned char* composite, int option_1, int option_2, int option_3, char* comment)
{
static void test_helper_generate(const struct zint_symbol *symbol, int ret, int i, unsigned char *data, unsigned char *composite, int option_1, int option_2, int option_3, char *comment) {
if (ret == 0) {
printf(" /*%2d*/ { %s, \"%s\", \"%s\", %d, %d, %d, %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(symbol->symbology), data, composite, option_1, option_2, option_3, ret, symbol->rows, symbol->width, comment);
@ -119,8 +114,8 @@ static void test_helper_generate(const struct zint_symbol* symbol, int ret, int
}
// Replicate examples from GS1 General Specifications 19.1 and ISO/IEC 24723:2010
static void test_examples(void)
{
static void test_examples(int index, int generate, int debug) {
testStart("");
int ret;
@ -297,6 +292,8 @@ static void test_examples(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -304,6 +301,8 @@ static void test_examples(void)
symbol->option_1 = data[i].option_1;
symbol->option_2 = data[i].option_2;
symbol->option_3 = data[i].option_3;
symbol->debug |= debug;
int length = strlen(data[i].data);
assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data);
@ -313,10 +312,9 @@ static void test_examples(void)
ret = ZBarcode_Encode(symbol, data[i].composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_EXAMPLES_GENERATE_EXPECTED
if (generate) {
test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].option_2, data[i].option_3, data[i].comment);
#else
} else {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d %s symbol->rows %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d %s symbol->width %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->width, data[i].expected_width, data[i].data);
@ -325,7 +323,7 @@ static void test_examples(void)
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -333,8 +331,8 @@ static void test_examples(void)
testFinish();
}
static void test_odd_numbered_numeric(void)
{
static void test_odd_numbered_numeric(int index, int generate, int debug) {
testStart("");
int ret;
@ -451,6 +449,8 @@ static void test_odd_numbered_numeric(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -458,6 +458,8 @@ static void test_odd_numbered_numeric(void)
symbol->option_1 = data[i].option_1;
symbol->option_2 = data[i].option_2;
symbol->option_3 = data[i].option_3;
symbol->debug |= debug;
int length = strlen(data[i].data);
assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data);
@ -467,10 +469,9 @@ static void test_odd_numbered_numeric(void)
ret = ZBarcode_Encode(symbol, data[i].composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_ODD_NUMBERED_NUMERIC_GENERATE_EXPECTED
if (generate) {
test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].option_2, data[i].option_3, data[i].comment);
#else
} else {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d %s symbol->rows %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d %s symbol->width %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->width, data[i].expected_width, data[i].data);
@ -479,7 +480,7 @@ static void test_odd_numbered_numeric(void)
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -487,8 +488,8 @@ static void test_odd_numbered_numeric(void)
testFinish();
}
static void test_ean128_cc_shift(void)
{
static void test_ean128_cc_shift(int index, int generate, int debug) {
testStart("");
int ret;
@ -553,6 +554,8 @@ static void test_ean128_cc_shift(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -560,6 +563,8 @@ static void test_ean128_cc_shift(void)
symbol->option_1 = data[i].option_1;
symbol->option_2 = data[i].option_2;
symbol->option_3 = data[i].option_3;
symbol->debug |= debug;
int length = strlen(data[i].data);
assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data);
@ -569,10 +574,9 @@ static void test_ean128_cc_shift(void)
ret = ZBarcode_Encode(symbol, data[i].composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_EAN128_CC_SHIFT_GENERATE_EXPECTED
if (generate) {
test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].option_2, data[i].option_3, data[i].comment);
#else
} else {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d %s symbol->rows %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d %s symbol->width %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->width, data[i].expected_width, data[i].data);
@ -581,7 +585,7 @@ static void test_ean128_cc_shift(void)
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -589,8 +593,8 @@ static void test_ean128_cc_shift(void)
testFinish();
}
static void test_ean128_cc_width(void)
{
static void test_ean128_cc_width(int index, int generate, int debug) {
testStart("");
int ret;
@ -623,11 +627,15 @@ static void test_ean128_cc_width(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_EAN128_CC;
symbol->option_1 = 3;
symbol->debug |= debug;
int length = strlen(data[i].data);
assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data);
@ -637,14 +645,13 @@ static void test_ean128_cc_width(void)
ret = ZBarcode_Encode(symbol, data[i].composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_EAN128_CC_WIDTH_GENERATE_EXPECTED
if (generate) {
printf(" /*%2d*/ { \"%s\", \"%s\", %s, %d, %d, \"%s\" },\n",
i, data[i].data, data[i].composite, testUtilErrorName(ret), symbol->rows, symbol->width, data[i].comment);
#else
} else {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
#endif
}
ZBarcode_Delete(symbol);
}
@ -653,8 +660,8 @@ static void test_ean128_cc_width(void)
}
// Test general-purpose data compaction
static void test_encodation_0(void)
{
static void test_encodation_0(int index, int generate, int debug) {
testStart("");
int ret;
@ -1086,6 +1093,8 @@ static void test_encodation_0(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -1093,6 +1102,8 @@ static void test_encodation_0(void)
symbol->option_1 = data[i].option_1;
symbol->option_2 = data[i].option_2;
symbol->option_3 = data[i].option_3;
symbol->debug |= debug;
int length = strlen(data[i].data);
assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data);
@ -1102,10 +1113,9 @@ static void test_encodation_0(void)
ret = ZBarcode_Encode(symbol, data[i].composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_ENCODATION_0_GENERATE_EXPECTED
if (generate) {
test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].option_2, data[i].option_3, data[i].comment);
#else
} else {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d %s symbol->rows %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d %s symbol->width %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->width, data[i].expected_width, data[i].data);
@ -1114,7 +1124,7 @@ static void test_encodation_0(void)
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -1122,8 +1132,8 @@ static void test_encodation_0(void)
testFinish();
}
static void test_encodation_10(void)
{
static void test_encodation_10(int index, int generate, int debug) {
testStart("");
int ret;
@ -1214,6 +1224,8 @@ static void test_encodation_10(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -1221,6 +1233,8 @@ static void test_encodation_10(void)
symbol->option_1 = data[i].option_1;
symbol->option_2 = data[i].option_2;
symbol->option_3 = data[i].option_3;
symbol->debug |= debug;
int length = strlen(data[i].data);
assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data);
@ -1230,10 +1244,9 @@ static void test_encodation_10(void)
ret = ZBarcode_Encode(symbol, data[i].composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_ENCODATION_10_GENERATE_EXPECTED
if (generate) {
test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].option_2, data[i].option_3, data[i].comment);
#else
} else {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d %s symbol->rows %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d %s symbol->width %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->width, data[i].expected_width, data[i].data);
@ -1242,7 +1255,7 @@ static void test_encodation_10(void)
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -1250,7 +1263,7 @@ static void test_encodation_10(void)
testFinish();
}
static void test_encodation_11(void)
static void test_encodation_11(int index, int generate, int debug)
{
testStart("");
@ -1574,6 +1587,8 @@ static void test_encodation_11(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -1581,6 +1596,8 @@ static void test_encodation_11(void)
symbol->option_1 = data[i].option_1;
symbol->option_2 = data[i].option_2;
symbol->option_3 = data[i].option_3;
symbol->debug |= debug;
int length = strlen(data[i].data);
assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data);
@ -1590,10 +1607,9 @@ static void test_encodation_11(void)
ret = ZBarcode_Encode(symbol, data[i].composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_ENCODATION_11_GENERATE_EXPECTED
if (generate) {
test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].option_2, data[i].option_3, data[i].comment);
#else
} else {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d %s symbol->rows %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d %s symbol->width %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->width, data[i].expected_width, data[i].data);
@ -1602,7 +1618,7 @@ static void test_encodation_11(void)
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -1611,7 +1627,7 @@ static void test_encodation_11(void)
}
// #181 Christian Hartlage OSS-Fuzz
static void test_fuzz(void)
static void test_fuzz(int index, int debug)
{
testStart("");
@ -1635,10 +1651,14 @@ static void test_fuzz(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->debug |= debug;
int length = data[i].length;
if (length == -1) {
length = strlen(data[i].data);
@ -1657,17 +1677,21 @@ static void test_fuzz(void)
testFinish();
}
int main()
{
test_eanx_leading_zeroes();
test_examples();
test_odd_numbered_numeric();
test_ean128_cc_shift();
test_ean128_cc_width();
test_encodation_0();
test_encodation_10();
test_encodation_11();
test_fuzz();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_eanx_leading_zeroes", test_eanx_leading_zeroes, 1, 0, 1 },
{ "test_examples", test_examples, 1, 1, 1 },
{ "test_odd_numbered_numeric", test_odd_numbered_numeric, 1, 1, 1 },
{ "test_ean128_cc_shift", test_ean128_cc_shift, 1, 1, 1 },
{ "test_ean128_cc_width", test_ean128_cc_width, 1, 1, 1 },
{ "test_encodation_0", test_encodation_0, 1, 1, 1 },
{ "test_encodation_10", test_encodation_10, 1, 1, 1 },
{ "test_encodation_11", test_encodation_11, 1, 1, 1 },
{ "test_fuzz", test_fuzz, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2019 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -31,11 +31,9 @@
#include "testcommon.h"
//#define TEST_ENCODE_GENERATE_EXPECTED 1
// Note need ZINT_SANITIZE set for these
static void test_buffer(void)
{
static void test_buffer(int index, int debug) {
testStart("");
int ret;
@ -56,6 +54,8 @@ static void test_buffer(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -63,6 +63,7 @@ static void test_buffer(void)
symbol->input_mode = data[i].input_mode;
symbol->eci = data[i].eci;
symbol->output_options = data[i].output_options;
symbol->debug |= debug;
int length = strlen(data[i].data);
@ -75,8 +76,8 @@ static void test_buffer(void)
testFinish();
}
static void test_encode(void)
{
static void test_encode(int index, int generate, int debug) {
testStart("");
int ret;
@ -126,7 +127,19 @@ static void test_encode(void)
"100011000000100100"
"111111111111111111"
},
/* 2*/ { "30Q324343430794<OQQ", 0, 16, 16, "ISO 16022:2006 Figure R.1",
/* 2*/ { "123456", 0, 10, 10, "ISO 16022:2006 Figure O.2",
"1010101010"
"1100101101"
"1100000100"
"1100011101"
"1100001000"
"1000001111"
"1110110000"
"1111011001"
"1001110100"
"1111111111"
},
/* 3*/ { "30Q324343430794<OQQ", 0, 16, 16, "ISO 16022:2006 Figure R.1",
"1010101010101010"
"1010101010000001"
"1010101011101100"
@ -149,21 +162,24 @@ static void test_encode(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_DATAMATRIX;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
#ifdef TEST_ENCODE_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { \"%s\", %s, %d, %d, \"%s\",\n", i, data[i].data, testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
#else
} else {
if (ret < 5) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
@ -174,7 +190,7 @@ static void test_encode(void)
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
}
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -182,10 +198,14 @@ static void test_encode(void)
testFinish();
}
int main()
{
test_buffer();
test_encode();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_buffer", test_buffer, 1, 0, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -31,10 +31,8 @@
#include "testcommon.h"
//#define TEST_INPUT_GENERATE_EXPECTED 1
//#define TEST_ENCODE_GENERATE_EXPECTED 1
static void test_input(int index, int generate, int debug) {
static void test_input(void) {
testStart("");
int ret;
@ -91,6 +89,8 @@ static void test_input(void) {
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -100,22 +100,22 @@ static void test_input(void) {
symbol->eci = data[i].eci;
}
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
//symbol->debug |= ZINT_DEBUG_PRINT;
symbol->debug |= debug;
int length = data[i].length != -1 ? data[i].length : strlen(data[i].data);
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_INPUT_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, %d, \"%s\", %d, %s, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
data[i].length, testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
#else
} else {
if (ret < 5) {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -123,7 +123,8 @@ static void test_input(void) {
testFinish();
}
static void test_encode(void) {
static void test_encode(int index, int generate, int debug) {
testStart("");
int ret;
@ -360,6 +361,8 @@ static void test_encode(void) {
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -368,20 +371,20 @@ static void test_encode(void) {
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
//symbol->debug = ZINT_DEBUG_PRINT;
symbol->debug |= debug;
int length = data[i].length != -1 ? data[i].length : strlen(data[i].data);
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_ENCODE_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, %d, \"%s\", %d, %s, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length,
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
#else
} else {
if (ret < 5) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
@ -392,7 +395,7 @@ static void test_encode(void) {
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
}
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -401,7 +404,8 @@ static void test_encode(void) {
}
// #181 Christian Hartlage / Nico Gunkel OSS-Fuzz
static void test_fuzz(void) {
static void test_fuzz(int index, int debug) {
testStart("");
int ret;
@ -440,17 +444,18 @@ static void test_fuzz(void) {
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_DOTCODE;
int length = data[i].length;
if (length == -1) {
length = strlen(data[i].data);
}
if (data[i].input_mode != -1) {
symbol->input_mode = data[i].input_mode;
}
symbol->debug |= debug;
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
@ -461,7 +466,8 @@ static void test_fuzz(void) {
testFinish();
}
static void test_large(void) {
static void test_large(int index, int debug) {
testStart("");
int ret;
@ -484,13 +490,15 @@ static void test_large(void) {
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_DOTCODE;
symbol->input_mode = DATA_MODE;
symbol->option_2 = data[i].option_2;
//symbol->debug = ZINT_DEBUG_PRINT;
symbol->debug |= debug;
int length = data[i].length;
@ -505,11 +513,16 @@ static void test_large(void) {
testFinish();
}
int main() {
test_input();
test_encode();
test_fuzz();
test_large();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_input", test_input, 1, 1, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
{ "test_fuzz", test_fuzz, 1, 0, 1 },
{ "test_large", test_large, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2019 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -31,8 +31,8 @@
#include "testcommon.h"
static void test_bom(void)
{
static void test_bom(int debug) {
testStart("");
struct zint_symbol *symbol = ZBarcode_Create();
@ -42,6 +42,7 @@ static void test_bom(void)
symbol->input_mode = UNICODE_MODE;
symbol->option_1 = 4;
symbol->option_2 = 1;
symbol->debug |= debug;
char data[] = "\xEF\xBB\xBF"; // U+FEFF BOM, with U+2039 (only in Windows pages)
int length = strlen(data);
@ -83,8 +84,8 @@ static void test_bom(void)
testFinish();
}
static void test_iso_8859_16(void)
{
static void test_iso_8859_16(int debug) {
testStart("");
struct zint_symbol *symbol = ZBarcode_Create();
@ -92,6 +93,7 @@ static void test_iso_8859_16(void)
symbol->symbology = BARCODE_QRCODE;
symbol->input_mode = UNICODE_MODE;
symbol->debug |= debug;
char data[] = "Ț"; // U+021A only in ISO 8859-16
int length = strlen(data);
@ -107,8 +109,8 @@ static void test_iso_8859_16(void)
}
// Only testing standard non-extended barcodes here, ie not QRCODE, MICROQR, GRIDMATRIX, HANXIN or UPNQR
static void test_reduced_charset_input(void)
{
static void test_reduced_charset_input(int index, int debug) {
testStart("");
int ret;
@ -214,12 +216,15 @@ static void test_reduced_charset_input(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->input_mode = data[i].input_mode;
symbol->eci = data[i].eci;
symbol->debug |= debug;
int length = strlen(data[i].data);
@ -236,11 +241,15 @@ static void test_reduced_charset_input(void)
testFinish();
}
int main()
{
test_bom();
test_iso_8859_16();
test_reduced_charset_input();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_bom", test_bom, 0, 0, 1 },
{ "test_iso_8859_16", test_iso_8859_16, 0, 0, 1 },
{ "test_reduced_charset_input", test_reduced_charset_input, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -37,8 +37,7 @@
// The version of GB18030.TXT is libiconv-1.11/GB18030.TXT taken from https://haible.de/bruno/charsets/conversion-tables/GB18030.html
// The generated file backend/tests/test_gb18030_tab.h does not include U+10000..10FFFF codepoints to save space.
// See also backend/tests/tools/data/GB18030.TXT.README and backend/tests/tools/gen_test_tab.php.
static int gb18030_wctomb_zint2(unsigned int* r1, unsigned int* r2, unsigned int wc)
{
static int gb18030_wctomb_zint2(unsigned int *r1, unsigned int *r2, unsigned int wc) {
unsigned int c;
// GB18030 two-byte extension (libiconv-1.16/lib/gb18030ext.h)
if (wc == 0x1E3F) { // GB 18030-2005 change, was PUA U+E7C7 below, see Table 3-39, p.111, Lunde 2nd ed.
@ -123,8 +122,8 @@ static int gb18030_wctomb_zint2(unsigned int* r1, unsigned int* r2, unsigned int
return 0;
}
static void test_gb18030_wctomb_zint(void)
{
static void test_gb18030_wctomb_zint(void) {
testStart("");
int ret, ret2;
@ -147,8 +146,8 @@ static void test_gb18030_wctomb_zint(void)
testFinish();
}
static void test_gb18030_utf8tomb(void)
{
static void test_gb18030_utf8tomb(int index) {
testStart("");
int ret;
@ -188,6 +187,8 @@ static void test_gb18030_utf8tomb(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
size_t ret_length = length;
@ -204,8 +205,8 @@ static void test_gb18030_utf8tomb(void)
testFinish();
}
static void test_gb18030_utf8tosb(void)
{
static void test_gb18030_utf8tosb(int index) {
testStart("");
int ret;
@ -261,6 +262,8 @@ static void test_gb18030_utf8tosb(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
size_t ret_length = length;
@ -277,8 +280,8 @@ static void test_gb18030_utf8tosb(void)
testFinish();
}
static void test_gb18030_cpy(void)
{
static void test_gb18030_cpy(int index) {
testStart("");
int ret;
@ -311,6 +314,8 @@ static void test_gb18030_cpy(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
size_t ret_length = length;
@ -324,12 +329,16 @@ static void test_gb18030_cpy(void)
testFinish();
}
int main()
{
test_gb18030_wctomb_zint();
test_gb18030_utf8tomb();
test_gb18030_utf8tosb();
test_gb18030_cpy();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_gb18030_wctomb_zint", test_gb18030_wctomb_zint, 0, 0, 0 },
{ "test_gb18030_utf8tomb", test_gb18030_utf8tomb, 1, 0, 0 },
{ "test_gb18030_utf8tosb", test_gb18030_utf8tosb, 1, 0, 0 },
{ "test_gb18030_cpy", test_gb18030_cpy, 1, 0, 0 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -35,8 +35,7 @@
// As control convert to GB 2312 using simple table generated from unicode.org GB2312.TXT plus simple processing
// GB2312.TXT no longer on unicode.org site but available from https://haible.de/bruno/charsets/conversion-tables/GB2312.html
static int gb2312_wctomb_zint2(unsigned int* r, unsigned int wc)
{
static int gb2312_wctomb_zint2(unsigned int *r, unsigned int wc) {
// Shortcut
if ((wc > 0x0451 && wc < 0x2015) || (wc > 0x3229 && wc < 0x4E00) || (wc > 0x9FA0 && wc < 0xFF01) || wc > 0xFFE5) {
return 0;
@ -51,8 +50,8 @@ static int gb2312_wctomb_zint2(unsigned int* r, unsigned int wc)
return 0;
}
static void test_gb2312_wctomb_zint(void)
{
static void test_gb2312_wctomb_zint(void) {
testStart("");
int ret, ret2;
@ -88,8 +87,8 @@ static void test_gb2312_wctomb_zint(void)
testFinish();
}
static void test_gb2312_utf8tomb(void)
{
static void test_gb2312_utf8tomb(int index) {
testStart("");
int ret;
@ -129,6 +128,8 @@ static void test_gb2312_utf8tomb(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
size_t ret_length = length;
@ -145,8 +146,8 @@ static void test_gb2312_utf8tomb(void)
testFinish();
}
static void test_gb2312_utf8tosb(void)
{
static void test_gb2312_utf8tosb(int index) {
testStart("");
int ret;
@ -200,6 +201,8 @@ static void test_gb2312_utf8tosb(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
size_t ret_length = length;
@ -216,8 +219,8 @@ static void test_gb2312_utf8tosb(void)
testFinish();
}
static void test_gb2312_cpy(void)
{
static void test_gb2312_cpy(int index) {
testStart("");
int ret;
@ -250,6 +253,8 @@ static void test_gb2312_cpy(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
size_t ret_length = length;
@ -263,12 +268,16 @@ static void test_gb2312_cpy(void)
testFinish();
}
int main()
{
test_gb2312_wctomb_zint();
test_gb2312_utf8tomb();
test_gb2312_utf8tosb();
test_gb2312_cpy();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_gb2312_wctomb_zint", test_gb2312_wctomb_zint, 0, 0, 0 },
{ "test_gb2312_utf8tomb", test_gb2312_utf8tomb, 1, 0, 0 },
{ "test_gb2312_utf8tosb", test_gb2312_utf8tosb, 1, 0, 0 },
{ "test_gb2312_cpy", test_gb2312_cpy, 1, 0, 0 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -31,11 +31,8 @@
#include "testcommon.h"
//#define TEST_INPUT_GENERATE_EXPECTED 1
//#define TEST_ENCODE_GENERATE_EXPECTED 1
static void test_options(int index, int debug) {
static void test_options(void)
{
testStart("");
int ret;
@ -66,12 +63,16 @@ static void test_options(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_GRIDMATRIX;
symbol->option_1 = data[i].option_1;
symbol->option_2 = data[i].option_2;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
@ -90,8 +91,8 @@ static void test_options(void)
testFinish();
}
static void test_input(void)
{
static void test_input(int index, int generate, int debug) {
testStart("");
int ret;
@ -170,6 +171,8 @@ static void test_input(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -180,23 +183,24 @@ static void test_input(void)
symbol->option_3 = data[i].option_3;
}
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
#ifdef TEST_INPUT_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, %d, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_3, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), ret < 5 ? symbol->eci : -1, symbol->errtxt, data[i].comment);
#else
} else {
if (ret < 5) {
assert_equal(symbol->eci, data[i].expected_eci, "i:%d eci %d != %d\n", i, symbol->eci, data[i].expected_eci);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -204,8 +208,8 @@ static void test_input(void)
testFinish();
}
static void test_encode(void)
{
static void test_encode(int index, int generate, int debug) {
testStart("");
int ret;
@ -323,6 +327,8 @@ static void test_encode(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -334,19 +340,20 @@ static void test_encode(void)
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_ENCODE_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { \"%s\", %s, %d, %d, %s, %d, %d, \"%s\",\n",
i, data[i].data, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, testUtilErrorName(data[i].ret),
symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
#else
} else {
if (ret < 5) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
@ -357,7 +364,7 @@ static void test_encode(void)
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
}
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -365,11 +372,15 @@ static void test_encode(void)
testFinish();
}
int main()
{
test_options();
test_input();
test_encode();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_options", test_options, 1, 0, 1 },
{ "test_input", test_input, 1, 1, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -31,12 +31,11 @@
#include "testcommon.h"
//#define TEST_GS1_REDUCE_GENERATE_EXPECTED
/*
* Check that EAN128 and RSS_EXP based symbologies reduce GS1 data
*/
static void test_gs1_reduce(void) {
static void test_gs1_reduce(int index, int generate, int debug) {
testStart("");
int ret;
@ -170,6 +169,8 @@ static void test_gs1_reduce(void) {
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -177,6 +178,7 @@ static void test_gs1_reduce(void) {
if (data[i].input_mode != -1) {
symbol->input_mode = data[i].input_mode;
}
symbol->debug |= debug;
if (strlen(data[i].composite)) {
text = data[i].composite;
@ -188,7 +190,7 @@ static void test_gs1_reduce(void) {
ret = ZBarcode_Encode(symbol, text, length);
#ifdef TEST_GS1_REDUCE_GENERATE_EXPECTED
if (generate) {
if (data[i].ret == 0) {
printf(" /*%2d*/ { %s, %s, \"%s\", \"%s\", %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].data, data[i].composite, data[i].ret, data[i].comment);
@ -198,7 +200,7 @@ static void test_gs1_reduce(void) {
printf(" /*%2d*/ { %s, %s, \"%s\", \"%s\", %s, \"%s\", \"\" },\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].data, data[i].composite, testUtilErrorName(data[i].ret), data[i].comment);
}
#else
} else {
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
if (ret == 0) {
@ -206,7 +208,7 @@ static void test_gs1_reduce(void) {
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -214,7 +216,8 @@ static void test_gs1_reduce(void) {
testFinish();
}
static void test_hrt(void) {
static void test_hrt(int index, int debug) {
testStart("");
int ret;
@ -238,10 +241,13 @@ static void test_hrt(void) {
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->debug |= debug;
if (strlen(data[i].composite)) {
text = data[i].composite;
@ -264,7 +270,8 @@ static void test_hrt(void) {
extern int gs1_verify(struct zint_symbol *symbol, const unsigned char source[], const size_t src_len, char reduced[]);
static void test_gs1_verify(void) {
static void test_gs1_verify(int index) {
testStart("");
int ret;
@ -765,6 +772,8 @@ static void test_gs1_verify(void) {
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -783,7 +792,8 @@ static void test_gs1_verify(void) {
testFinish();
}
static void test_input_mode(void) {
static void test_input_mode(int index, int debug) {
testStart("");
int ret;
@ -842,6 +852,8 @@ static void test_input_mode(void) {
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -850,6 +862,7 @@ static void test_input_mode(void) {
if (data[i].output_options != -1) {
symbol->output_options = data[i].output_options;
}
symbol->debug |= debug;
if (strlen(data[i].composite)) {
text = data[i].composite;
@ -861,7 +874,7 @@ static void test_input_mode(void) {
ret = ZBarcode_Encode(symbol, text, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
if (data[i].compare_previous) {
if (index == -1 && data[i].compare_previous) {
ret = testUtilSymbolCmp(symbol, &previous_symbol);
assert_zero(ret, "i:%d testUtilSymbolCmp ret %d != 0\n", i, ret);
}
@ -873,11 +886,16 @@ static void test_input_mode(void) {
testFinish();
}
int main() {
test_gs1_reduce();
test_hrt();
test_gs1_verify();
test_input_mode();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_gs1_reduce", test_gs1_reduce, 1, 1, 1 },
{ "test_hrt", test_hrt, 1, 0, 1 },
{ "test_gs1_verify", test_gs1_verify, 1, 0, 0 },
{ "test_input_mode", test_input_mode, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -31,11 +31,8 @@
#include "testcommon.h"
//#define TEST_INPUT_GENERATE_EXPECTED 1
//#define TEST_ENCODE_GENERATE_EXPECTED 1
static void test_options(int index, int debug) {
static void test_options(void)
{
testStart("");
int ret;
@ -66,6 +63,8 @@ static void test_options(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -76,6 +75,7 @@ static void test_options(void)
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
@ -95,8 +95,8 @@ static void test_options(void)
testFinish();
}
static void test_input(void)
{
static void test_input(int index, int generate, int debug) {
testStart("");
int ret;
@ -162,6 +162,8 @@ static void test_input(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -172,23 +174,23 @@ static void test_input(void)
symbol->option_3 = data[i].option_3;
}
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
symbol->debug |= debug;
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_INPUT_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, %d, %d, \"%s\", %d, %s, %d, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_3, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length,
testUtilErrorName(data[i].ret), ret < 5 ? symbol->eci : -1, symbol->errtxt, data[i].comment);
#else
} else {
if (ret < 5) {
assert_equal(symbol->eci, data[i].expected_eci, "i:%d eci %d != %d\n", i, symbol->eci, data[i].expected_eci);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -196,8 +198,8 @@ static void test_input(void)
testFinish();
}
static void test_encode(void)
{
static void test_encode(int index, int generate, int debug) {
testStart("");
int ret;
@ -369,6 +371,8 @@ static void test_encode(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -380,19 +384,20 @@ static void test_encode(void)
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_ENCODE_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { \"%s\", %s, %d, %d, %s, %d, %d, \"%s\",\n",
i, data[i].data, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, testUtilErrorName(data[i].ret),
symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
#else
} else {
if (ret < 5) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
@ -403,7 +408,7 @@ static void test_encode(void)
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
}
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -411,11 +416,15 @@ static void test_encode(void)
testFinish();
}
int main()
{
test_options();
test_input();
test_encode();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_options", test_options, 1, 0, 1 },
{ "test_input", test_input, 1, 1, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2019 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -36,8 +36,8 @@
#define TEST_IMAIL_CSV_MAX 500
static void test_csv(void)
{
static void test_csv(int index, int debug) {
testStart("");
FILE *fd = fopen("../data/imail/usps/uspsIMbEncoderTestCases.csv", "r");
@ -58,8 +58,11 @@ static void test_csv(void)
while (fgets(buffer, sizeof(buffer), fd) != NULL) {
lc++;
if (index != -1 && lc != index) continue;
#ifdef TEST_IMAIL_CSV_MAX
if (lc > TEST_IMAIL_CSV_MAX) {
if (lc > TEST_IMAIL_CSV_MAX && index == -1) {
break;
}
#endif
@ -96,6 +99,7 @@ static void test_csv(void)
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_ONECODE;
symbol->debug |= debug;
ret = ZBarcode_Encode(symbol, data, strlen(data));
@ -120,9 +124,13 @@ static void test_csv(void)
testFinish();
}
int main()
{
test_csv();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_csv", test_csv, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -34,8 +34,8 @@
#include <sys/stat.h>
#include <unistd.h>
static void test_checks(void)
{
static void test_checks(int index, int debug) {
testStart("");
int ret;
@ -71,6 +71,8 @@ static void test_checks(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -84,6 +86,8 @@ static void test_checks(void)
if (data[i].dot_size != -1) {
symbol->dot_size = data[i].dot_size;
}
symbol->debug |= debug;
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret = ZBarcode_Encode(symbol, data[i].data, length);
@ -98,8 +102,8 @@ static void test_checks(void)
testFinish();
}
static void test_input_mode(void)
{
static void test_input_mode(int index, int debug) {
testStart("");
int ret;
@ -128,11 +132,14 @@ static void test_input_mode(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_CODE49; // Supports GS1
symbol->input_mode = data[i].input_mode;
symbol->debug |= debug;
int length = strlen(data[i].data);
@ -147,8 +154,8 @@ static void test_input_mode(void)
}
// #181 Nico Gunkel OSS-Fuzz
static void test_encode_file_zero_length(void)
{
static void test_encode_file_zero_length(void) {
testStart("");
int ret;
@ -174,8 +181,8 @@ static void test_encode_file_zero_length(void)
}
// #181 Nico Gunkel OSS-Fuzz (buffer not freed on fread() error) Note: unable to reproduce fread() error using this method
static void test_encode_file_directory(void)
{
static void test_encode_file_directory(void) {
testStart("");
int ret;
@ -198,12 +205,16 @@ static void test_encode_file_directory(void)
testFinish();
}
int main()
{
test_checks();
test_input_mode();
test_encode_file_zero_length();
test_encode_file_directory();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_checks", test_checks, 1, 0, 1 },
{ "test_input_mode", test_input_mode, 1, 0, 1 },
{ "test_encode_file_zero_length", test_encode_file_zero_length, 0, 0, 0 },
{ "test_encode_file_directory", test_encode_file_directory, 0, 0, 0 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2019 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -30,8 +30,8 @@
#include "testcommon.h"
static void test_encode_vector(void)
{
static void test_encode_vector(int index, int debug) {
testStart("");
int ret;
@ -43,7 +43,7 @@ static void test_encode_vector(void)
int ret_vector;
unsigned char *expected_daft;
};
// Vi} :s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { "0100000000000AA000AA0A", 0, 100, 30, 0, "TFATTADAAATAFAFADFTAFATDTTDTTAAFTTFFTTDFTTFFTTAFADFDFAAFTDDFDADDAA" },
/* 1*/ { "0100000000009JA500AA0A", 0, 100, 30, 0, "TAFTTDADATTFDTFDFDFDTAATADADTTTATTFTDDDDTATDATDFTFFATAFFAFADAFFTDT" },
@ -58,10 +58,14 @@ static void test_encode_vector(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_MAILMARK;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
@ -82,9 +86,13 @@ static void test_encode_vector(void)
testFinish();
}
int main()
{
test_encode_vector();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_encode_vector", test_encode_vector, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -31,15 +31,12 @@
#include "testcommon.h"
//#define TEST_BEST_SUPPORTED_SET_GENERATE_EXPECTED 1
static void test_best_supported_set(int index, int generate, int debug) {
static void test_best_supported_set(void)
{
testStart("");
int ret;
struct item {
int symbology;
unsigned char *data;
int ret;
float w;
@ -52,7 +49,7 @@ static void test_best_supported_set(void)
unsigned char *expected;
};
struct item data[] = {
/* 0*/ { BARCODE_MAXICODE, "am.//ab,\034TA# z\015!", 0, 100, 100, 0, 33, 30, "TODO: Better data and verify expected",
/* 0*/ { "am.//ab,\034TA# z\015!", 0, 100, 100, 0, 33, 30, "TODO: Better data and verify expected",
"111010000101111000111101010111"
"111110000000010100111000000000"
"110000101100110100111010101011"
@ -94,23 +91,26 @@ static void test_best_supported_set(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->symbology = BARCODE_MAXICODE;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
#ifdef TEST_BEST_SUPPORTED_SET_GENERATE_EXPECTED
printf(" /*%2d*/ { %s, \"%s\", %d, %.0f, %.0f, %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), testUtilEscape(data[i].data, length, escaped_data, sizeof(escaped_data)), ret,
if (generate) {
printf(" /*%2d*/ { \"%s\", %d, %.0f, %.0f, %d, %d, %d, \"%s\",\n",
i, testUtilEscape(data[i].data, length, escaped_data, sizeof(escaped_data)), ret,
data[i].w, data[i].h, data[i].ret_vector, symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
#else
} else {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
@ -120,7 +120,7 @@ static void test_best_supported_set(void)
ret = ZBarcode_Buffer_Vector(symbol, 0);
assert_equal(ret, data[i].ret_vector, "i:%d ZBarcode_Buffer_Vector ret %d != %d\n", i, ret, data[i].ret_vector);
#endif
}
ZBarcode_Delete(symbol);
}
@ -129,33 +129,36 @@ static void test_best_supported_set(void)
}
// #181 Nico Gunkel OSS-Fuzz
static void test_fuzz(void)
{
static void test_fuzz(int index, int debug) {
testStart("");
int ret;
struct item {
int symbology;
unsigned char *data;
int length;
int ret;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { BARCODE_MAXICODE, "\223\223\223\223\223\200\000\060\060\020\122\104\060\343\000\000\040\104\104\104\104\177\377\040\000\324\336\000\000\000\000\104\060\060\060\060\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\060\104\104\000\000\000\040\104\104\104\104\177\377\377\377\324\336\000\000\000\000\104\377\104\001\104\104\104\104\104\104\233\233\060\060\060\060\060\060\060\060\060\325\074", 107, ZINT_ERROR_TOO_LONG }, // Original OSS-Fuzz triggering data
/* 1*/ { BARCODE_MAXICODE, "AaAaAaAaAaAaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA123456789", -1, ZINT_ERROR_TOO_LONG }, // Add 6 lowercase a's so 6 SHIFTS inserted so 6 + 138 (max input len) = 144 and numbers come at end of buffer
/* 2*/ { BARCODE_MAXICODE, "AaAaAaAaAaAaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA123456789A", -1, ZINT_ERROR_TOO_LONG },
/* 3*/ { BARCODE_MAXICODE, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678", -1, ZINT_ERROR_TOO_LONG }, // First 6 chars ignored for number compaction so max numeric digits appears to be 135 not 138 (for mode 4 anyway) TODO: investigate further
/* 4*/ { BARCODE_MAXICODE, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345", -1, 0 },
/* 0*/ { "\223\223\223\223\223\200\000\060\060\020\122\104\060\343\000\000\040\104\104\104\104\177\377\040\000\324\336\000\000\000\000\104\060\060\060\060\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\104\060\104\104\000\000\000\040\104\104\104\104\177\377\377\377\324\336\000\000\000\000\104\377\104\001\104\104\104\104\104\104\233\233\060\060\060\060\060\060\060\060\060\325\074", 107, ZINT_ERROR_TOO_LONG }, // Original OSS-Fuzz triggering data
/* 1*/ { "AaAaAaAaAaAaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA123456789", -1, ZINT_ERROR_TOO_LONG }, // Add 6 lowercase a's so 6 SHIFTS inserted so 6 + 138 (max input len) = 144 and numbers come at end of buffer
/* 2*/ { "AaAaAaAaAaAaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA123456789A", -1, ZINT_ERROR_TOO_LONG },
/* 3*/ { "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678", -1, ZINT_ERROR_TOO_LONG }, // First 6 chars ignored for number compaction so max numeric digits appears to be 135 not 138 (for mode 4 anyway) TODO: investigate further
/* 4*/ { "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345", -1, 0 },
};
int data_size = sizeof(data) / sizeof(struct item);
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->symbology = BARCODE_MAXICODE;
symbol->debug |= debug;
int length = data[i].length;
if (length == -1) {
length = strlen(data[i].data);
@ -170,10 +173,14 @@ static void test_fuzz(void)
testFinish();
}
int main()
{
test_best_supported_set();
test_fuzz();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_best_supported_set", test_best_supported_set, 1, 1, 1 },
{ "test_fuzz", test_fuzz, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -31,13 +31,12 @@
#include "testcommon.h"
static void test_pcx(void)
{
static void test_pcx(int index, int debug) {
testStart("");
if (system("identify --version > /dev/null") != 0) {
printf("SKIPPED. ImageMagick identify not available\n");
testFinish();
if (!testUtilHaveIdentify()) {
testSkip("ImageMagick identify not available");
return;
}
@ -64,10 +63,12 @@ static void test_pcx(void)
/* 8*/ { BARCODE_DOTCODE, -1, -1, "C2C100", "E0E1F2", 0, "2741" },
/* 9*/ { BARCODE_ULTRA, -1, -1, NULL, NULL, 0, "ULTRACODE_123456789!" },
};
int data_size = sizeof(data) / sizeof(struct item);
int data_size = ARRAY_SIZE(data);
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -87,6 +88,7 @@ static void test_pcx(void)
if (data[i].scale != 0) {
symbol->scale = data[i].scale;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
@ -98,19 +100,24 @@ static void test_pcx(void)
ret = ZBarcode_Print(symbol, 0);
assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret);
//ret = system("identify out.pcx > /dev/null");
ret = system("identify out.pcx");
ret = testUtilVerifyIdentify(symbol->outfile, debug);
assert_zero(ret, "i:%d %s identify %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
ZBarcode_Delete(symbol);
}
testFinish();
}
int main()
{
test_pcx();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_pcx", test_pcx, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -31,18 +31,17 @@
#include "testcommon.h"
//#define TEST_PDF417_ENCODE_GENERATE_EXPECTED 1
static void test_options(int index, int debug) {
static void test_pdf417_options(void)
{
testStart("");
int ret;
struct item {
unsigned char* data;
int symbology;
int option_1;
int option_2;
int option_3;
unsigned char *data;
int ret_encode;
int ret_vector;
@ -54,14 +53,14 @@ static void test_pdf417_options(void)
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { "12345", -1, -1, -1, 0, 0, 2, 2, 6, 103, -1 }, // ECC auto-set to 2, cols auto-set to 2
/* 1*/ { "12345", -1, -1, 928, 0, 0, 2, 2, 6, 103, 0 }, // Option 3 ignored
/* 2*/ { "12345", -1, -1, 300, 0, 0, 2, 2, 6, 103, 0 }, // Option 3 ignored
/* 3*/ { "12345", 3, -1, -1, 0, 0, 3, 3, 7, 120, -1 }, // ECC 3, cols auto-set to 3
/* 4*/ { "12345", 3, 2, -1, 0, 0, 3, 2, 10, 103, -1 }, // ECC 3, cols 2
/* 5*/ { "12345", 8, 2, -1, ZINT_ERROR_TOO_LONG, -1, 8, 3, 0, 0, -1 }, // ECC 8, cols 2, fails
/* 6*/ { "12345", 7, 2, -1, 0, 0, 7, 3, 87, 120, -1 }, // ECC 7, cols 2 auto-upped to 3
/* 7*/ { "12345", -1, 10, -1, 0, 0, 2, 10, 3, 239, -1 }, // ECC auto-set to 2, cols 10
/* 0*/ { BARCODE_PDF417, -1, -1, -1, "12345", 0, 0, 2, 2, 6, 103, -1 }, // ECC auto-set to 2, cols auto-set to 2
/* 1*/ { BARCODE_PDF417, -1, -1, 928, "12345", 0, 0, 2, 2, 6, 103, 0 }, // Option 3 ignored
/* 2*/ { BARCODE_PDF417, -1, -1, 300, "12345", 0, 0, 2, 2, 6, 103, 0 }, // Option 3 ignored
/* 3*/ { BARCODE_PDF417, 3, -1, -1, "12345", 0, 0, 3, 3, 7, 120, -1 }, // ECC 3, cols auto-set to 3
/* 4*/ { BARCODE_PDF417, 3, 2, -1, "12345", 0, 0, 3, 2, 10, 103, -1 }, // ECC 3, cols 2
/* 5*/ { BARCODE_PDF417, 8, 2, -1, "12345", ZINT_ERROR_TOO_LONG, -1, 8, 3, 0, 0, -1 }, // ECC 8, cols 2, fails
/* 6*/ { BARCODE_PDF417, 7, 2, -1, "12345", 0, 0, 7, 3, 87, 120, -1 }, // ECC 7, cols 2 auto-upped to 3
/* 7*/ { BARCODE_PDF417, -1, 10, -1, "12345", 0, 0, 2, 10, 3, 239, -1 }, // ECC auto-set to 2, cols 10
};
int data_size = sizeof(data) / sizeof(struct item);
@ -69,10 +68,12 @@ static void test_pdf417_options(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_PDF417;
symbol->symbology = data[i].symbology;
if (data[i].option_1 != -1) {
symbol->option_1 = data[i].option_1;
}
@ -82,6 +83,8 @@ static void test_pdf417_options(void)
if (data[i].option_3 != -1) {
symbol->option_3 = data[i].option_3;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
@ -98,7 +101,7 @@ static void test_pdf417_options(void)
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
if (data[i].compare_previous != -1) {
if (index == -1 && data[i].compare_previous != -1) {
ret = testUtilSymbolCmp(symbol, &previous_symbol);
assert_equal(!ret, !data[i].compare_previous, "i:%d testUtilSymbolCmp !ret %d != %d\n", i, ret, data[i].compare_previous);
}
@ -115,16 +118,17 @@ static void test_pdf417_options(void)
testFinish();
}
static void test_pdf417_encode(void)
{
static void test_encode(int index, int generate, int debug) {
testStart("");
int ret;
struct item {
int symbology;
int input_mode;
unsigned char* data;
int option_1;
int option_2;
unsigned char *data;
int ret;
int expected_rows;
@ -133,7 +137,7 @@ static void test_pdf417_encode(void)
char *expected;
};
struct item data[] = {
/* 0*/ { UNICODE_MODE, "PDF417 Symbology Standard", 2, 2, 0, 13, 103, "ISO 15438:2015 Figure 1 **NOT SAME** TODO: investigate",
/* 0*/ { BARCODE_PDF417, UNICODE_MODE, 2, 2, "PDF417 Symbology Standard", 0, 13, 103, "ISO 15438:2015 Figure 1 **NOT SAME** TODO: investigate",
"1111111101010100011110101001111000101011000110000001000011000110010011110101011110000111111101000101001"
"1111111101010100011111010100011000110110000011110101101000011100010011111101010011100111111101000101001"
"1111111101010100011101010111111000111010000111110101011001101111000011010100011111000111111101000101001"
@ -153,10 +157,12 @@ static void test_pdf417_encode(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_PDF417;
symbol->symbology = data[i].symbology;
symbol->input_mode = data[i].input_mode;
if (data[i].option_1 != -1) {
symbol->option_1 = data[i].option_1;
@ -164,19 +170,20 @@ static void test_pdf417_encode(void)
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_PDF417_ENCODE_GENERATE_EXPECTED
printf(" /*%3d*/ { %s, \"%s\", %d, %d, %s, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].data, data[i].option_1, data[i].option_2, testUtilErrorName(data[i].ret),
symbol->rows, symbol->width, data[i].comment);
if (generate) {
printf(" /*%3d*/ { %s, %s, %d, %d, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2,
data[i].data, testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
#else
} else {
if (ret < 5) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
@ -187,7 +194,7 @@ static void test_pdf417_encode(void)
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
}
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -196,8 +203,8 @@ static void test_pdf417_encode(void)
}
// #181 Nico Gunkel OSS-Fuzz
static void test_fuzz(void)
{
static void test_fuzz(int index, int debug) {
testStart("");
int ret;
@ -460,6 +467,8 @@ static void test_fuzz(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -467,6 +476,8 @@ static void test_fuzz(void)
if (data[i].option_1 != -1) {
symbol->option_1 = data[i].option_1;
}
symbol->debug |= debug;
int length = data[i].length;
if (length == -1) {
length = strlen(data[i].data);
@ -481,12 +492,15 @@ static void test_fuzz(void)
testFinish();
}
int main()
{
test_pdf417_options();
test_pdf417_encode();
int main(int argc, char *argv[]) {
test_fuzz();
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_options", test_options, 1, 0, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
{ "test_fuzz", test_fuzz, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -32,12 +32,95 @@
#include "testcommon.h"
#include <sys/stat.h>
//#define TEST_PRINT_GENERATE_EXPECTED 1
extern int png_pixel_plot(struct zint_symbol *symbol, char *pixelbuf);
static void test_pixel_plot(int index, int debug) {
static void test_print(void)
{
testStart("");
if (!testUtilHaveIdentify()) {
testSkip("ImageMagick identify not available");
return;
}
int ret;
struct item {
int width;
int height;
unsigned char *pattern;
int repeat;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { 1, 1, "1", 0 },
/* 1*/ { 2, 1, "11", 0 },
/* 2*/ { 2, 2, "10", 1 },
/* 3*/ { 3, 1, "101", 0 },
/* 4*/ { 3, 2, "101010", 0 },
/* 5*/ { 3, 3, "101010101", 0 },
/* 6*/ { 8, 2, "CBMWKRYGGYRKWMBC", 0 },
};
int data_size = ARRAY_SIZE(data);
char *png = "out.png";
char escaped[1024];
int escaped_size = 1024;
char data_buf[2731 * 5 + 1];
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
strcpy(symbol->outfile, png);
symbol->bitmap_width = data[i].width;
symbol->bitmap_height = data[i].height;
int size = data[i].width * data[i].height;
assert_nonzero(size < (int) sizeof(data_buf), "i:%d png_pixel_plot size %d < sizeof(data_buf) %d\n", i, size, (int) sizeof(data_buf));
if (data[i].repeat) {
int len = strlen(data[i].pattern);
for (int j = 0; j < size; j += len) {
memcpy(data_buf + j, data[i].pattern, len);
}
if (size % len) {
memcpy(data_buf + size - size % len, data[i].pattern, size % len);
}
data_buf[size] = '\0';
} else {
strcpy(data_buf, data[i].pattern);
}
assert_equal(size, (int) strlen(data_buf), "i:%d png_pixel_plot size %d != strlen(data_buf) %d\n", i, size, (int) strlen(data_buf));
symbol->bitmap = data_buf;
ret = png_pixel_plot(symbol, data_buf);
assert_zero(ret, "i:%d png_pixel_plot ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
ret = testUtilVerifyIdentify(symbol->outfile, debug);
assert_zero(ret, "i:%d identify %s ret %d != 0\n", i, symbol->outfile, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
symbol->bitmap = NULL;
ZBarcode_Delete(symbol);
}
testFinish();
}
static void test_print(int index, int generate, int debug) {
testStart("");
int have_identify = testUtilHaveIdentify();
int ret;
struct item {
int symbology;
@ -49,22 +132,24 @@ static void test_print(void)
struct item data[] = {
/* 0*/ { BARCODE_CODABLOCKF, 3, -1, "AAAAAAAAA", "../data/png/codablockf_3rows.png" },
};
int data_size = sizeof(data) / sizeof(struct item);
int data_size = ARRAY_SIZE(data);
char* data_dir = "../data/png";
char* png = "out.png";
char escaped[1024];
int escaped_size = 1024;
#ifdef TEST_PRINT_GENERATE_EXPECTED
if (generate) {
if (!testUtilExists(data_dir)) {
ret = mkdir(data_dir, 0755);
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
}
#endif
}
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol* symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -75,6 +160,7 @@ static void test_print(void)
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
@ -85,23 +171,24 @@ static void test_print(void)
ret = ZBarcode_Print(symbol, 0);
assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret);
#ifdef TEST_PRINT_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, %d, %d, \"%s\", \"%s\"},\n",
i, testUtilBarcodeName(data[i].symbology), data[i].option_1, data[i].option_2, testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].expected_file);
i, testUtilBarcodeName(data[i].symbology), data[i].option_1, data[i].option_2,
testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].expected_file);
ret = rename(symbol->outfile, data[i].expected_file);
assert_zero(ret, "i:%d rename(%s, %s) ret %d != 0\n", i, symbol->outfile, data[i].expected_file, ret);
#else
if (have_identify) {
ret = testUtilVerifyIdentify(data[i].expected_file, debug);
assert_zero(ret, "i:%d %s identify %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), data[i].expected_file, ret);
}
} else {
assert_nonzero(testUtilExists(symbol->outfile), "i:%d testUtilExists(%s) == 0\n", i, symbol->outfile);
assert_nonzero(testUtilExists(data[i].expected_file), "i:%d testUtilExists(%s) == 0\n", i, data[i].expected_file);
ret = testUtilCmpPngs(symbol->outfile, data[i].expected_file);
assert_zero(ret, "i:%d %s testUtilCmpPngs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, data[i].expected_file, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
#endif
}
ZBarcode_Delete(symbol);
}
@ -109,9 +196,14 @@ static void test_print(void)
testFinish();
}
int main()
{
test_print();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_pixel_plot", test_pixel_plot, 1, 0, 1 },
{ "test_print", test_print, 1, 1, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2019 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -31,8 +31,8 @@
#include "testcommon.h"
static void test_koreapost(void)
{
static void test_koreapost(int index, int debug) {
testStart("");
int ret;
@ -52,10 +52,14 @@ static void test_koreapost(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_KOREAPOST;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
@ -76,8 +80,8 @@ static void test_koreapost(void)
testFinish();
}
static void test_japanpost(void)
{
static void test_japanpost(int index, int debug) {
testStart("");
int ret;
@ -100,10 +104,14 @@ static void test_japanpost(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_JAPANPOST;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
@ -124,10 +132,14 @@ static void test_japanpost(void)
testFinish();
}
int main()
{
test_koreapost();
test_japanpost();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_koreapost", test_koreapost, 1, 0, 1 },
{ "test_japanpost", test_japanpost, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -32,13 +32,16 @@
#include "testcommon.h"
#include <sys/stat.h>
//#define TEST_PRINT_GENERATE_EXPECTED 1
//#define TEST_PRINT_OVERWRITE_EXPECTED "bmp,emf,eps,gif,pcx,png,svg,tif,txt"
#define TEST_PRINT_OVERWRITE_EXPECTED "bmp,emf,eps,gif,pcx,png,svg,tif,txt"
static void test_print(int index, int generate, int debug) {
static void test_print(void)
{
testStart("");
int have_identify = testUtilHaveIdentify();
int have_inkscape = testUtilHaveInkscape();
int have_ghostscript = testUtilHaveGhostscript();
int ret;
struct item {
int symbology;
@ -64,7 +67,7 @@ static void test_print(void)
char escaped[1024];
int escaped_size = 1024;
#ifdef TEST_PRINT_GENERATE_EXPECTED
if (generate) {
strcpy(data_dir, "../data");
if (!testUtilExists(data_dir)) {
ret = mkdir(data_dir, 0755);
@ -75,21 +78,23 @@ static void test_print(void)
ret = mkdir(data_dir, 0755);
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
}
#endif
}
for (int j = 0; j < exts_len; j++) {
strcpy(data_dir, "../data/print/");
strcat(data_dir, exts[j]);
#ifdef TEST_PRINT_GENERATE_EXPECTED
if (generate) {
if (!testUtilExists(data_dir)) {
ret = mkdir(data_dir, 0755);
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
}
#endif
}
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -100,6 +105,7 @@ static void test_print(void)
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
@ -118,8 +124,7 @@ static void test_print(void)
ret = ZBarcode_Print(symbol, 0);
assert_zero(ret, "i:%d j:%d %s %s ZBarcode_Print %s ret %d != 0\n", i, j, exts[j], testUtilBarcodeName(data[i].symbology), symbol->outfile, ret);
#ifdef TEST_PRINT_GENERATE_EXPECTED
if (generate) {
if (j == 0) {
printf(" /*%3d*/ { %s, %d, %d, \"%s\", \"%s\" },\n",
i, testUtilBarcodeName(data[i].symbology), data[i].option_1, data[i].option_2, testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].expected_file);
@ -127,10 +132,24 @@ static void test_print(void)
if (strstr(TEST_PRINT_OVERWRITE_EXPECTED, exts[j])) {
ret = rename(symbol->outfile, expected_file);
assert_zero(ret, "i:%d rename(%s, %s) ret %d != 0\n", i, symbol->outfile, expected_file, ret);
if (strcmp(exts[j], "eps") == 0) {
if (have_ghostscript) {
ret = testUtilVerifyGhostscript(expected_file, debug);
assert_zero(ret, "i:%d %s ghostscript %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret);
}
#else
} else if (strcmp(exts[j], "svg") == 0 || strcmp(exts[j], "emf") == 0) {
if (have_inkscape) {
ret = testUtilVerifyInkscape(expected_file, debug);
assert_zero(ret, "i:%d %s inkscape %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret);
}
} else if (strcmp(exts[j], "txt") != 0) { // I.e. rasters
if (have_identify) {
ret = testUtilVerifyIdentify(expected_file, debug);
assert_zero(ret, "i:%d %s identify %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret);
}
}
}
} else {
assert_nonzero(testUtilExists(symbol->outfile), "i:%d j:%d %s testUtilExists(%s) == 0\n", i, j, exts[j], symbol->outfile);
if (strcmp(exts[j], "eps") == 0) {
@ -151,8 +170,7 @@ static void test_print(void)
}
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
#endif
}
ZBarcode_Delete(symbol);
}
@ -161,9 +179,13 @@ static void test_print(void)
testFinish();
}
int main()
{
test_print();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_print", test_print, 1, 1, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -31,23 +31,8 @@
#include "testcommon.h"
//#define TEST_QR_INPUT_GENERATE_EXPECTED 1
//#define TEST_QR_GS1_GENERATE_EXPECTED 1
//#define TEST_QR_OPTIMIZE_GENERATE_EXPECTED 1
//#define TEST_QR_ENCODE_GENERATE_EXPECTED 1
//#define TEST_MICROQR_INPUT_GENERATE_EXPECTED 1
//#define TEST_MICROQR_PADDING_GENERATE_EXPECTED 1
//#define TEST_MICROQR_OPTIMIZE_GENERATE_EXPECTED 1
//#define TEST_MICROQR_ENCODE_GENERATE_EXPECTED 1
//#define TEST_UPNQR_INPUT_GENERATE_EXPECTED 1
//#define TEST_UPNQR_ENCODE_GENERATE_EXPECTED 1
//#define TEST_RMQR_INPUT_GENERATE_EXPECTED 1
//#define TEST_RMQR_GS1_GENERATE_EXPECTED 1
//#define TEST_RMQR_OPTIMIZE_GENERATE_EXPECTED 1
//#define TEST_RMQR_ENCODE_GENERATE_EXPECTED 1
static void test_qr_options(int index, int debug) {
static void test_qr_options(void)
{
testStart("");
int ret;
@ -101,6 +86,8 @@ static void test_qr_options(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -111,11 +98,13 @@ static void test_qr_options(void)
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt);
if (data[i].compare_previous != -1) {
if (index == -1 && data[i].compare_previous != -1) {
ret = testUtilSymbolCmp(symbol, &previous_symbol);
assert_equal(!ret, !data[i].compare_previous, "i:%d testUtilSymbolCmp !ret %d != %d\n", i, ret, data[i].compare_previous);
}
@ -134,8 +123,8 @@ static void test_qr_options(void)
testFinish();
}
static void test_qr_input(void)
{
static void test_qr_input(int index, int generate, int debug) {
testStart("");
int ret;
@ -260,6 +249,8 @@ static void test_qr_input(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -270,23 +261,24 @@ static void test_qr_input(void)
symbol->option_3 = data[i].option_3;
}
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
#ifdef TEST_QR_INPUT_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, %d, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_3, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), ret < 5 ? symbol->eci : -1, symbol->errtxt, data[i].comment);
#else
} else {
if (ret < 5) {
assert_equal(symbol->eci, data[i].expected_eci, "i:%d eci %d != %d\n", i, symbol->eci, data[i].expected_eci);
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -294,8 +286,8 @@ static void test_qr_input(void)
testFinish();
}
static void test_qr_gs1(void)
{
static void test_qr_gs1(int index, int generate, int debug) {
testStart("");
int ret;
@ -323,27 +315,29 @@ static void test_qr_gs1(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_QRCODE;
symbol->input_mode = GS1_MODE;
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
#ifdef TEST_QR_GS1_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
#else
} else {
if (ret < 5) {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -351,8 +345,8 @@ static void test_qr_gs1(void)
testFinish();
}
static void test_qr_optimize(void)
{
static void test_qr_optimize(int index, int generate, int debug) {
testStart("");
int ret;
@ -402,6 +396,8 @@ static void test_qr_optimize(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -412,19 +408,20 @@ static void test_qr_optimize(void)
}
symbol->option_3 = ZINT_FULL_MULTIBYTE;
symbol->debug = ZINT_DEBUG_TEST;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
#ifdef TEST_QR_OPTIMIZE_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, \"%s\", %d, %s, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].option_1,
testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
#else
} else {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
#endif
}
ZBarcode_Delete(symbol);
}
@ -432,8 +429,8 @@ static void test_qr_optimize(void)
testFinish();
}
static void test_qr_encode(void)
{
static void test_qr_encode(int index, int generate, int debug) {
testStart("");
int ret;
@ -894,6 +891,8 @@ static void test_qr_encode(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -905,19 +904,20 @@ static void test_qr_encode(void)
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_QR_ENCODE_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, \"%s\", %d, %d, %s, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].data, data[i].option_1, data[i].option_2, testUtilErrorName(data[i].ret),
symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
#else
} else {
if (ret < 5) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
@ -928,7 +928,7 @@ static void test_qr_encode(void)
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
}
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -936,8 +936,8 @@ static void test_qr_encode(void)
testFinish();
}
static void test_microqr_options(void)
{
static void test_microqr_options(int index, int debug) {
testStart("");
int ret;
@ -1008,6 +1008,8 @@ static void test_microqr_options(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -1018,11 +1020,13 @@ static void test_microqr_options(void)
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt);
if (data[i].compare_previous != -1) {
if (index == -1 && data[i].compare_previous != -1) {
ret = testUtilSymbolCmp(symbol, &previous_symbol);
assert_equal(!ret, !data[i].compare_previous, "i:%d testUtilSymbolCmp !ret %d != %d\n", i, ret, data[i].compare_previous);
}
@ -1041,8 +1045,8 @@ static void test_microqr_options(void)
testFinish();
}
static void test_microqr_input(void)
{
static void test_microqr_input(int index, int generate, int debug) {
testStart("");
int ret;
@ -1116,6 +1120,8 @@ static void test_microqr_input(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -1125,21 +1131,22 @@ static void test_microqr_input(void)
symbol->option_3 = data[i].option_3;
}
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
#ifdef TEST_MICROQR_INPUT_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, %d, \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_3, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
#else
} else {
if (ret < 5) {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -1148,8 +1155,8 @@ static void test_microqr_input(void)
}
// Check MICROQR padding (4-bit final codeword for M1 and M3 in particular)
static void test_microqr_padding(void)
{
static void test_microqr_padding(int index, int generate, int debug) {
testStart("");
int ret;
@ -1193,6 +1200,8 @@ static void test_microqr_padding(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -1202,21 +1211,22 @@ static void test_microqr_padding(void)
symbol->option_1 = data[i].option_1;
}
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_MICROQR_PADDING_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { \"%s\", %d, %s, \"%s\", \"%s\" },\n",
i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].option_1,
testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
#else
} else {
if (ret < 5) {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -1224,8 +1234,8 @@ static void test_microqr_padding(void)
testFinish();
}
static void test_microqr_optimize(void)
{
static void test_microqr_optimize(int index, int generate, int debug) {
testStart("");
int ret;
@ -1256,6 +1266,8 @@ static void test_microqr_optimize(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -1269,19 +1281,20 @@ static void test_microqr_optimize(void)
}
symbol->option_3 = ZINT_FULL_MULTIBYTE;
symbol->debug = ZINT_DEBUG_TEST;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_MICROQR_OPTIMIZE_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, \"%s\", %d, %d, %s, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].option_1, data[i].option_2,
testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
#else
} else {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
#endif
}
ZBarcode_Delete(symbol);
}
@ -1289,8 +1302,8 @@ static void test_microqr_optimize(void)
testFinish();
}
static void test_microqr_encode(void)
{
static void test_microqr_encode(int index, int generate, int debug) {
testStart("");
int ret;
@ -1465,6 +1478,8 @@ static void test_microqr_encode(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -1476,19 +1491,20 @@ static void test_microqr_encode(void)
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_MICROQR_ENCODE_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, \"%s\", %d, %d, %s, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].data, data[i].option_1, data[i].option_2, testUtilErrorName(data[i].ret),
symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
#else
} else {
if (ret < 5) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
@ -1499,7 +1515,7 @@ static void test_microqr_encode(void)
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
}
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -1507,8 +1523,8 @@ static void test_microqr_encode(void)
testFinish();
}
static void test_upnqr_input(void)
{
static void test_upnqr_input(int index, int generate, int debug) {
testStart("");
int ret;
@ -1534,12 +1550,15 @@ static void test_upnqr_input(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_UPNQR;
symbol->input_mode = data[i].input_mode;
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
symbol->debug |= debug;
int length = strlen(data[i].data);
@ -1547,15 +1566,15 @@ static void test_upnqr_input(void)
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
assert_equal(symbol->eci, 4, "i:%d ZBarcode_Encode symbol->eci %d != 4\n", i, symbol->eci);
#ifdef TEST_UPNQR_INPUT_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret),
symbol->errtxt, data[i].comment);
#else
} else {
if (ret < 5) {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -1563,8 +1582,8 @@ static void test_upnqr_input(void)
testFinish();
}
static void test_upnqr_encode(void)
{
static void test_upnqr_encode(int index, int generate, int debug) {
testStart("");
int ret;
@ -1666,6 +1685,8 @@ static void test_upnqr_encode(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -1677,19 +1698,20 @@ static void test_upnqr_encode(void)
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_UPNQR_ENCODE_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, \"%s\", %d, %d, %s, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].data, data[i].option_1, data[i].option_2, testUtilErrorName(data[i].ret),
symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
#else
} else {
if (ret < 5) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
@ -1700,7 +1722,7 @@ static void test_upnqr_encode(void)
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
}
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -1708,8 +1730,8 @@ static void test_upnqr_encode(void)
testFinish();
}
static void test_rmqr_options(void)
{
static void test_rmqr_options(int index, int debug) {
testStart("");
int ret;
@ -1795,6 +1817,8 @@ static void test_rmqr_options(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -1806,6 +1830,8 @@ static void test_rmqr_options(void)
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
@ -1824,8 +1850,8 @@ static void test_rmqr_options(void)
testFinish();
}
static void test_rmqr_input(void)
{
static void test_rmqr_input(int index, int generate, int debug) {
testStart("");
int ret;
@ -1865,6 +1891,8 @@ static void test_rmqr_input(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -1874,21 +1902,22 @@ static void test_rmqr_input(void)
symbol->option_3 = data[i].option_3;
}
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
#ifdef TEST_RMQR_INPUT_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, %d, \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_3, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
#else
} else {
if (ret < 5) {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -1896,8 +1925,8 @@ static void test_rmqr_input(void)
testFinish();
}
static void test_rmqr_gs1(void)
{
static void test_rmqr_gs1(int index, int generate, int debug) {
testStart("");
int ret;
@ -1926,27 +1955,29 @@ static void test_rmqr_gs1(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_RMQR;
symbol->input_mode = GS1_MODE;
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
#ifdef TEST_RMQR_GS1_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
#else
} else {
if (ret < 5) {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -1954,8 +1985,8 @@ static void test_rmqr_gs1(void)
testFinish();
}
static void test_rmqr_optimize(void)
{
static void test_rmqr_optimize(int index, int generate, int debug) {
testStart("");
int ret;
@ -1997,6 +2028,8 @@ static void test_rmqr_optimize(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -2007,19 +2040,20 @@ static void test_rmqr_optimize(void)
}
symbol->option_3 = ZINT_FULL_MULTIBYTE;
symbol->debug = ZINT_DEBUG_TEST;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_RMQR_OPTIMIZE_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, \"%s\", %d, %s, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].option_1,
testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
#else
} else {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
#endif
}
ZBarcode_Delete(symbol);
}
@ -2027,8 +2061,8 @@ static void test_rmqr_optimize(void)
testFinish();
}
static void test_rmqr_encode(void)
{
static void test_rmqr_encode(int index, int generate, int debug) {
testStart("");
int ret;
@ -2078,6 +2112,8 @@ static void test_rmqr_encode(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -2089,19 +2125,20 @@ static void test_rmqr_encode(void)
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_RMQR_ENCODE_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, \"%s\", %d, %d, %s, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].data, data[i].option_1, data[i].option_2, testUtilErrorName(data[i].ret),
symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
#else
} else {
if (ret < 5) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
@ -2112,7 +2149,7 @@ static void test_rmqr_encode(void)
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
}
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -2120,28 +2157,32 @@ static void test_rmqr_encode(void)
testFinish();
}
int main()
{
test_qr_options();
test_qr_input();
test_qr_gs1();
test_qr_optimize();
test_qr_encode();
int main(int argc, char *argv[]) {
test_microqr_options();
test_microqr_input();
test_microqr_padding();
test_microqr_optimize();
test_microqr_encode();
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_qr_options", test_qr_options, 1, 0, 1 },
{ "test_qr_input", test_qr_input, 1, 1, 1 },
{ "test_qr_gs1", test_qr_gs1, 1, 1, 1 },
{ "test_qr_optimize", test_qr_optimize, 1, 1, 1 },
{ "test_qr_encode", test_qr_encode, 1, 1, 1 },
test_upnqr_input();
test_upnqr_encode();
{ "test_microqr_options", test_microqr_options, 1, 0, 1 },
{ "test_microqr_input", test_microqr_input, 1, 1, 1 },
{ "test_microqr_padding", test_microqr_padding, 1, 1, 1 },
{ "test_microqr_optimize", test_microqr_optimize, 1, 1, 1 },
{ "test_microqr_encode", test_microqr_encode, 1, 1, 1 },
test_rmqr_options();
test_rmqr_input();
test_rmqr_gs1();
test_rmqr_optimize();
test_rmqr_encode();
{ "test_upnqr_input", test_upnqr_input, 1, 1, 1 },
{ "test_upnqr_encode", test_upnqr_encode, 1, 1, 1 },
{ "test_rmqr_options", test_rmqr_options, 1, 0, 1 },
{ "test_rmqr_input", test_rmqr_input, 1, 1, 1 },
{ "test_rmqr_gs1", test_rmqr_gs1, 1, 1, 1 },
{ "test_rmqr_optimize", test_rmqr_optimize, 1, 1, 1 },
{ "test_rmqr_encode", test_rmqr_encode, 1, 1, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -31,8 +31,8 @@
#include "testcommon.h"
static void test_chk_extendable(void)
{
static void test_chk_extendable(int index, int debug) {
testStart("");
int ret;
@ -61,6 +61,8 @@ static void test_chk_extendable(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -68,6 +70,8 @@ static void test_chk_extendable(void)
if (data[i].show_hrt != -1) {
symbol->show_hrt = data[i].show_hrt;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode_and_Buffer(symbol, data[i].data, length, 0);
@ -101,9 +105,13 @@ static void test_chk_extendable(void)
testFinish();
}
int main()
{
test_chk_extendable();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_chk_extendable", test_chk_extendable, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2019 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -31,13 +31,8 @@
#include "testcommon.h"
//#define TEST_RSS_BINARY_DIV_MODULO_DIVISOR_GENERATE_EXPECTED 1
//#define TEST_EXAMPLES_GENERATE_EXPECTED 1
//#define TEST_GENERAL_FIELD_GENERATE_EXPECTED 1
//#define TEST_BINARY_BUFFER_SIZE_GENERATE_EXPECTED 1
static void test_binary_div_modulo_divisor(int index, int generate, int debug) {
static void test_binary_div_modulo_divisor(void)
{
testStart("");
int ret;
@ -70,21 +65,24 @@ static void test_binary_div_modulo_divisor(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret_encode);
#ifdef TEST_RSS_BINARY_DIV_MODULO_DIVISOR_GENERATE_EXPECTED
if (generate) {
printf(" /*%2d*/ { %s, \"%s\", %d, %.0f, %.0f, %d, %d, %d, ",
i, testUtilBarcodeName(data[i].symbology), data[i].data, ret, data[i].w, data[i].h, data[i].ret_vector, symbol->rows, symbol->width);
testUtilModulesDump(symbol, "", " },\n");
#else
} else {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
@ -94,7 +92,7 @@ static void test_binary_div_modulo_divisor(void)
ret = ZBarcode_Buffer_Vector(symbol, 0);
assert_equal(ret, data[i].ret_vector, "i:%d ZBarcode_Buffer_Vector ret %d != %d\n", i, ret, data[i].ret_vector);
#endif
}
ZBarcode_Delete(symbol);
}
@ -103,8 +101,8 @@ static void test_binary_div_modulo_divisor(void)
}
// Replicate examples from GS1 General Specifications 19.1 and ISO/IEC 24724:2011
static void test_examples(void)
{
static void test_examples(int index, int generate, int debug) {
testStart("");
int ret;
@ -196,16 +194,20 @@ static void test_examples(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_EXAMPLES_GENERATE_EXPECTED
if (generate) {
if (ret == 0) {
printf(" /*%2d*/ { %s, \"%s\", %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(symbol->symbology), data[i].data, ret, symbol->rows, symbol->width, data[i].comment);
@ -215,8 +217,7 @@ static void test_examples(void)
printf(" /*%2d*/ { %s, \"%s\", %s, %d, %d, \"%s\", \"\" },\n",
i, testUtilBarcodeName(symbol->symbology), data[i].data, testUtilErrorName(ret), symbol->rows, symbol->width, data[i].comment);
}
#else
} else {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d %s symbol->rows %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d %s symbol->width %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->width, data[i].expected_width, data[i].data);
@ -225,7 +226,7 @@ static void test_examples(void)
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -234,8 +235,8 @@ static void test_examples(void)
}
// Test general-purpose data compaction
static void test_general_field(void)
{
static void test_general_field(int index, int generate, int debug) {
testStart("");
int ret;
@ -502,16 +503,20 @@ static void test_general_field(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_GENERAL_FIELD_GENERATE_EXPECTED
if (generate) {
if (ret == 0) {
printf(" /*%2d*/ { %s, \"%s\", %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(symbol->symbology), data[i].data, ret, symbol->rows, symbol->width, data[i].comment);
@ -521,8 +526,7 @@ static void test_general_field(void)
printf(" /*%2d*/ { %s, \"%s\", %s, %d, %d, \"%s\", \"\" },\n",
i, testUtilBarcodeName(symbol->symbology), data[i].data, testUtilErrorName(ret), symbol->rows, symbol->width, data[i].comment);
}
#else
} else {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d %s symbol->rows %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d %s symbol->width %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->width, data[i].expected_width, data[i].data);
@ -531,7 +535,7 @@ static void test_general_field(void)
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -539,8 +543,8 @@ static void test_general_field(void)
testFinish();
}
static void test_binary_buffer_size(void)
{
static void test_binary_buffer_size(int index, int generate, int debug) {
testStart("");
int ret;
@ -566,23 +570,26 @@ static void test_binary_buffer_size(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_RSS_EXP;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_BINARY_BUFFER_SIZE_GENERATE_EXPECTED
if (generate) {
printf(" /*%2d*/ { \"%s\", %s, %d, %d, \"%s\" },\n",
i, data[i].data, testUtilErrorName(ret), symbol->rows, symbol->width, data[i].comment);
#else
} else {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
#endif
}
ZBarcode_Delete(symbol);
}
@ -590,12 +597,16 @@ static void test_binary_buffer_size(void)
testFinish();
}
int main()
{
test_binary_div_modulo_divisor();
test_examples();
test_general_field();
test_binary_buffer_size();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_binary_div_modulo_divisor", test_binary_div_modulo_divisor, 1, 1, 1 },
{ "test_examples", test_examples, 1, 1, 1 },
{ "test_general_field", test_general_field, 1, 1, 1 },
{ "test_binary_buffer_size", test_binary_buffer_size, 1, 1, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -34,8 +34,7 @@
#include "../sjis.h"
// As control convert to Shift JIS using simple table generated from https://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/JIS/SHIFTJIS.TXT plus simple processing
static int sjis_wctomb_zint2(unsigned int* r, unsigned int wc)
{
static int sjis_wctomb_zint2(unsigned int *r, unsigned int wc) {
if (wc < 0x20 || wc == 0x7F) {
*r = wc;
return 1;
@ -78,8 +77,8 @@ static int sjis_wctomb_zint2(unsigned int* r, unsigned int wc)
return 0;
}
static void test_sjis_wctomb_zint(void)
{
static void test_sjis_wctomb_zint(void) {
testStart("");
int ret, ret2;
@ -107,8 +106,8 @@ static void test_sjis_wctomb_zint(void)
testFinish();
}
static void test_sjis_utf8tomb(void)
{
static void test_sjis_utf8tomb(int index) {
testStart("");
int ret;
@ -147,6 +146,8 @@ static void test_sjis_utf8tomb(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
size_t ret_length = length;
@ -163,8 +164,8 @@ static void test_sjis_utf8tomb(void)
testFinish();
}
static void test_sjis_utf8tosb(void)
{
static void test_sjis_utf8tosb(int index) {
testStart("");
int ret;
@ -211,6 +212,8 @@ static void test_sjis_utf8tosb(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
size_t ret_length = length;
@ -227,8 +230,8 @@ static void test_sjis_utf8tosb(void)
testFinish();
}
static void test_sjis_cpy(void)
{
static void test_sjis_cpy(int index) {
testStart("");
int ret;
@ -260,6 +263,8 @@ static void test_sjis_cpy(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
size_t ret_length = length;
@ -273,12 +278,16 @@ static void test_sjis_cpy(void)
testFinish();
}
int main()
{
test_sjis_wctomb_zint();
test_sjis_utf8tomb();
test_sjis_utf8tosb();
test_sjis_cpy();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_sjis_wctomb_zint", test_sjis_wctomb_zint, 0, 0, 0 },
{ "test_sjis_utf8tomb", test_sjis_utf8tomb, 1, 0, 0 },
{ "test_sjis_utf8tosb", test_sjis_utf8tosb, 1, 0, 0 },
{ "test_sjis_cpy", test_sjis_cpy, 1, 0, 0 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -32,12 +32,12 @@
#include "testcommon.h"
#include <sys/stat.h>
//#define TEST_PRINT_GENERATE_EXPECTED 1
static void test_print(int index, int generate, int debug) {
static void test_print(void)
{
testStart("");
int have_inkscape = testUtilHaveInkscape();
int ret;
struct item {
int symbology;
@ -57,15 +57,17 @@ static void test_print(void)
char escaped[1024];
int escaped_size = 1024;
#ifdef TEST_PRINT_GENERATE_EXPECTED
if (generate) {
if (!testUtilExists(data_dir)) {
ret = mkdir(data_dir, 0755);
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
}
#endif
}
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -76,6 +78,7 @@ static void test_print(void)
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
symbol->debug |= debug;
int length = strlen(data[i].data);
@ -86,23 +89,24 @@ static void test_print(void)
ret = ZBarcode_Print(symbol, 0);
assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret);
#ifdef TEST_PRINT_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, %d, %d, \"%s\", \"%s\"},\n",
i, testUtilBarcodeName(data[i].symbology), data[i].option_1, data[i].option_2, testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].expected_file);
i, testUtilBarcodeName(data[i].symbology), data[i].option_1, data[i].option_2,
testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].expected_file);
ret = rename(symbol->outfile, data[i].expected_file);
assert_zero(ret, "i:%d rename(%s, %s) ret %d != 0\n", i, symbol->outfile, data[i].expected_file, ret);
#else
if (have_inkscape) {
ret = testUtilVerifyInkscape(data[i].expected_file, debug);
assert_zero(ret, "i:%d %s inkscape %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), data[i].expected_file, ret);
}
} else {
assert_nonzero(testUtilExists(symbol->outfile), "i:%d testUtilExists(%s) == 0\n", i, symbol->outfile);
assert_nonzero(testUtilExists(data[i].expected_file), "i:%d testUtilExists(%s) == 0\n", i, data[i].expected_file);
ret = testUtilCmpSvgs(symbol->outfile, data[i].expected_file);
assert_zero(ret, "i:%d %s testUtilCmpSvgs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, data[i].expected_file, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
#endif
}
ZBarcode_Delete(symbol);
}
@ -110,9 +114,13 @@ static void test_print(void)
testFinish();
}
int main()
{
test_print();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_print", test_print, 1, 1, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2020 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,8 +32,8 @@
#include "testcommon.h"
// #181 Nico Gunkel OSS-Fuzz
static void test_fuzz(void)
{
static void test_fuzz(int index, int debug) {
testStart("");
int ret;
@ -57,14 +57,15 @@ static void test_fuzz(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
int length = data[i].length;
if (length == -1) {
length = strlen(data[i].data);
}
symbol->debug |= debug;
int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
@ -75,9 +76,13 @@ static void test_fuzz(void)
testFinish();
}
int main()
{
test_fuzz();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_fuzz", test_fuzz, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -29,13 +29,10 @@
*/
/* vim: set ts=4 sw=4 et : */
//#define TEST_INPUT_GENERATE_EXPECTED 1
//#define TEST_ENCODE_GENERATE_EXPECTED 1
#include "testcommon.h"
static void test_input(void)
{
static void test_input(int index, int generate, int debug) {
testStart("");
int ret;
@ -98,6 +95,8 @@ static void test_input(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -111,22 +110,22 @@ static void test_input(void)
symbol->option_3 = data[i].option_3;
}
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
//symbol->debug |= ZINT_DEBUG_PRINT;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret);
#ifdef TEST_INPUT_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, %d, %d, %s, \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, testUtilOption3Name(data[i].option_3), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
#else
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, testUtilOption3Name(data[i].option_3),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
} else {
if (ret < 5) {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -134,8 +133,8 @@ static void test_input(void)
testFinish();
}
static void test_encode(void)
{
static void test_encode(int index, int generate, int debug) {
testStart("");
int ret;
@ -433,6 +432,8 @@ static void test_encode(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -445,20 +446,20 @@ static void test_encode(void)
if (data[i].option_3 != -1) {
symbol->option_3 = data[i].option_3;
}
//symbol->debug = ZINT_DEBUG_PRINT;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_ENCODE_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, %d, %d, %s, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, testUtilOption3Name(data[i].option_3),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
#else
} else {
if (ret < 5) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
@ -469,7 +470,7 @@ static void test_encode(void)
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
}
}
#endif
}
ZBarcode_Delete(symbol);
}
@ -477,10 +478,14 @@ static void test_encode(void)
testFinish();
}
int main()
{
test_input();
test_encode();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_input", test_input, 1, 1, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2019 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -31,8 +31,8 @@
#include "testcommon.h"
static void test_upce_length(void)
{
static void test_upce_length(int index, int debug) {
testStart("");
int ret;
@ -63,10 +63,14 @@ static void test_upce_length(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
@ -79,8 +83,8 @@ static void test_upce_length(void)
}
// Note requires ZINT_SANITIZE to be set
static void test_upca_print(void)
{
static void test_upca_print(int index, int debug) {
testStart("");
int ret;
@ -97,10 +101,14 @@ static void test_upca_print(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
@ -118,8 +126,8 @@ static void test_upca_print(void)
testFinish();
}
static void test_isbn(void)
{
static void test_isbn(int index, int debug) {
testStart("");
int ret;
@ -175,10 +183,14 @@ static void test_isbn(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_ISBNX;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
@ -195,8 +207,8 @@ static void test_isbn(void)
testFinish();
}
static void test_vector_same(void)
{
static void test_vector_same(int index, int debug) {
testStart("");
int ret;
@ -215,6 +227,8 @@ static void test_vector_same(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_vector *vectors[4];
int vectors_size = sizeof(vectors) / sizeof(struct zint_vector*);
@ -223,6 +237,8 @@ static void test_vector_same(void)
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->debug |= debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
@ -253,8 +269,8 @@ static void test_vector_same(void)
}
// #181 Christian Hartlage OSS-Fuzz
static void test_fuzz(void)
{
static void test_fuzz(int index, int debug) {
testStart("");
int ret;
@ -281,10 +297,14 @@ static void test_fuzz(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->debug |= debug;
int length = data[i].length;
if (length == -1) {
length = strlen(data[i].data);
@ -299,13 +319,17 @@ static void test_fuzz(void)
testFinish();
}
int main()
{
test_upce_length();
test_upca_print();
test_isbn();
test_vector_same();
test_fuzz();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_upce_length", test_upce_length, 1, 0, 1 },
{ "test_upca_print", test_upca_print, 1, 0, 1 },
{ "test_isbn", test_isbn, 1, 0, 1 },
{ "test_vector_same", test_vector_same, 1, 0, 1 },
{ "test_fuzz", test_fuzz, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008 - 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -31,10 +31,8 @@
#include "testcommon.h"
//#define TEST_BUFFER_VECTOR_GENERATE_EXPECTED 1
static void test_buffer_vector(int index, int generate, int debug) {
static void test_buffer_vector(void)
{
testStart("");
int ret;
@ -150,11 +148,14 @@ static void test_buffer_vector(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->input_mode = UNICODE_MODE;
symbol->debug |= debug;
if (strlen(data[i].composite)) {
text = data[i].composite;
@ -171,13 +172,11 @@ static void test_buffer_vector(void)
assert_zero(ret, "i:%d ZBarcode_Buffer_Vector(%d) ret %d != 0\n", i, data[i].symbology, ret);
assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%d) vector NULL\n", i, data[i].symbology);
#ifdef TEST_BUFFER_VECTOR_GENERATE_EXPECTED
if (generate) {
printf(" /*%3d*/ { %s, \"%s\", \"%s\", %d, %d, %d, %.1f, %.1f },\n",
i, testUtilBarcodeName(data[i].symbology), data[i].data, data[i].composite,
symbol->height, symbol->rows, symbol->width, symbol->vector->width, symbol->vector->height);
#else
} else {
assert_equal(symbol->height, data[i].expected_height, "i:%d (%s) symbol->height %d != %d\n", i, testUtilBarcodeName(data[i].symbology), symbol->height, data[i].expected_height);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d (%s) symbol->rows %d != %d\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d (%s) symbol->width %d != %d\n", i, testUtilBarcodeName(data[i].symbology), symbol->width, data[i].expected_width);
@ -185,8 +184,7 @@ static void test_buffer_vector(void)
i, testUtilBarcodeName(data[i].symbology), symbol->vector->width, data[i].expected_vector_width);
assert_equal(symbol->vector->height, data[i].expected_vector_height, "i:%d (%s) symbol->vector->height %f != %f\n",
i, testUtilBarcodeName(data[i].symbology), symbol->vector->height, data[i].expected_vector_height);
#endif
}
ZBarcode_Delete(symbol);
}
@ -195,8 +193,8 @@ static void test_buffer_vector(void)
}
// Checks that symbol lead-in (composite offset) isn't used to calc string position for non-composite barcodes
static void test_noncomposite_string_x(void)
{
static void test_noncomposite_string_x(int index, int debug) {
testStart("");
int ret;
@ -217,11 +215,14 @@ static void test_noncomposite_string_x(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->input_mode = UNICODE_MODE;
symbol->debug |= debug;
int length = strlen(data[i].data);
@ -244,8 +245,8 @@ static void test_noncomposite_string_x(void)
}
// Checks UPCA/UPCE main_symbol_width_x (used for addon formatting) set whether whitespace width set or not
static void test_upcean_whitespace_width(void)
{
static void test_upcean_whitespace_width(int index, int debug) {
testStart("");
int ret;
@ -273,12 +274,15 @@ static void test_upcean_whitespace_width(void)
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->input_mode = UNICODE_MODE;
symbol->whitespace_width = data[i].whitespace_width;
symbol->debug |= debug;
int length = strlen(data[i].data);
@ -307,11 +311,15 @@ static void test_upcean_whitespace_width(void)
testFinish();
}
int main()
{
test_buffer_vector();
test_noncomposite_string_x();
test_upcean_whitespace_width();
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_buffer_vector", test_buffer_vector, 1, 1, 1 },
{ "test_noncomposite_string_x", test_noncomposite_string_x, 1, 0, 1 },
{ "test_upcean_whitespace_width", test_upcean_whitespace_width, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
testReport();

View File

@ -39,18 +39,20 @@
#include <zlib.h>
#include <setjmp.h>
#endif
#include <unistd.h>
#include <errno.h>
extern int module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord);
static int tests = 0;
static int failed = 0;
static int skipped = 0;
int assertionFailed = 0;
int assertionNum = 0;
static const char *testName = NULL;
static const char *testFunc = NULL;
void testStartReal(const char *func, const char *name)
{
void testStartReal(const char *func, const char *name) {
tests++;
testName = name;
testFunc = func;
@ -59,8 +61,7 @@ void testStartReal(const char *func, const char *name)
printf("_____%d: %s: %s...\n", tests, func, name);
}
void testEnd(int result)
{
void testEnd(int result) {
if (testName[0]) {
printf(".....%d: %s: %s ", tests, testFunc, testName);
} else {
@ -74,8 +75,7 @@ void testEnd(int result)
}
}
void testFinish(void)
{
void testFinish(void) {
if (testName[0]) {
printf(".....%d: %s: %s ", tests, testFunc, testName);
} else {
@ -89,16 +89,140 @@ void testFinish(void)
}
}
void testReport()
{
void testSkip(const char *msg) {
skipped++;
if (testName[0]) {
printf(".....%d: %s: %s ", tests, testFunc, testName);
} else {
printf(".....%d: %s: ", tests, testFunc);
}
if (assertionFailed) {
printf("FAILED. (%d assertions failed.)\n", assertionFailed);
failed++;
} else {
printf("SKIPPED. %s. (%d assertions passed.)\n", msg, assertionNum);
}
}
void testReport() {
if (failed && skipped) {
printf("Total %d tests, %d skipped, %d fails.\n", tests, skipped, failed);
exit(-1);
}
if (failed) {
printf("Total %d tests, %d fails.\n", tests, failed);
exit(-1);
}
if (skipped) {
printf("Total %d tests, %d skipped.\n", tests, skipped);
} else {
printf("Total %d tests, all passed.\n", tests);
}
}
void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size) {
int i, opt, ran;
long long_opt;
char *optarg_endptr = NULL;
int debug = 0;
char *func = NULL;
char func_buf[256 + 5];
int index = -1;
int generate = 0;
typedef void (*func_void)(void);
typedef void (*func_debug)(int debug);
typedef void (*func_index)(int index);
typedef void (*func_index_debug)(int index, int debug);
typedef void (*func_generate)(int generate);
typedef void (*func_generate_debug)(int generate, int debug);
typedef void (*func_index_generate)(int index, int generate);
typedef void (*func_index_generate_debug)(int index, int generate, int debug);
while ((opt = getopt(argc, argv, "d:f:gi:")) != -1) {
switch (opt) {
case 'd':
errno = 0;
long_opt = strtol(optarg, &optarg_endptr, 10);
if (errno || optarg_endptr == optarg || long_opt < 0 || long_opt > INT_MAX) {
fprintf(stderr, "testRun: -d debug value invalid\n");
debug = 0;
} else {
debug = long_opt;
}
break;
case 'f':
if (strlen(optarg) < 256) {
if (strncmp(optarg, "test_", 5) == 0) {
strcpy(func_buf, optarg);
} else {
strcpy(func_buf, "test_");
strcat(func_buf, optarg);
}
func = func_buf;
} else {
fprintf(stderr, "testRun: -f func value too long\n");
func = NULL;
}
break;
case 'g':
generate = 1;
break;
case 'i':
errno = 0;
long_opt = strtol(optarg, &optarg_endptr, 10);
if (errno || optarg_endptr == optarg || long_opt < 0 || long_opt > INT_MAX) {
fprintf(stderr, "testRun: -i index value invalid\n");
index = -1;
} else {
index = long_opt;
}
break;
}
}
ran = 0;
for (i = 0; i < funcs_size; i++) {
if (func && strcmp(func, funcs[i].name) != 0) {
continue;
}
if (funcs[i].has_index && funcs[i].has_generate && funcs[i].has_debug) {
(*(func_index_generate_debug)funcs[i].func)(index, generate, debug);
} else if (funcs[i].has_index && funcs[i].has_generate) {
if (debug) fprintf(stderr, "testRun %s: -d ignored\n", funcs[i].name);
(*(func_index_generate)funcs[i].func)(index, generate);
} else if (funcs[i].has_index && funcs[i].has_debug) {
if (generate) fprintf(stderr, "testRun %s: -g ignored\n", funcs[i].name);
(*(func_index_debug)funcs[i].func)(index, debug);
} else if (funcs[i].has_index) {
if (generate) fprintf(stderr, "testRun %s: -g ignored\n", funcs[i].name);
if (debug) fprintf(stderr, "testRun %s: -d ignored\n", funcs[i].name);
(*(func_index)funcs[i].func)(index);
} else if (funcs[i].has_generate && funcs[i].has_debug) {
if (index != -1) fprintf(stderr, "testRun %s: -i index ignored\n", funcs[i].name);
(*(func_generate_debug)funcs[i].func)(generate, debug);
} else if (funcs[i].has_generate) {
if (index != -1) fprintf(stderr, "testRun %s: -i index ignored\n", funcs[i].name);
if (debug) fprintf(stderr, "testRun %s: -d ignored\n", funcs[i].name);
(*(func_generate)funcs[i].func)(generate);
} else if (funcs[i].has_debug) {
if (index != -1) fprintf(stderr, "testRun %s: -i index ignored\n", funcs[i].name);
if (generate) fprintf(stderr, "testRun %s -g ignored\n", funcs[i].name);
(*(func_debug)funcs[i].func)(debug);
} else {
if (index != -1) fprintf(stderr, "testRun %s: -i index ignored\n", funcs[i].name);
if (generate) fprintf(stderr, "testRun %s -g ignored\n", funcs[i].name);
if (debug) fprintf(stderr, "testRun %s: -d ignored\n", funcs[i].name);
(*(func_void)funcs[i].func)();
}
ran++;
}
if (func && !ran) {
fprintf(stderr, "testRun: unknown -f func arg\n");
}
}
char *testUtilBarcodeName(int symbology) {
struct item {
int define;
@ -338,8 +462,7 @@ char* testUtilOption3Name(int option_3) {
return "-1";
}
int testUtilDAFTConvert(const struct zint_symbol* symbol, char* buffer, int buffer_size)
{
int testUtilDAFTConvert(const struct zint_symbol *symbol, char *buffer, int buffer_size) {
buffer[0] = '\0';
char *b = buffer;
for (int i = 0; i < symbol->width && b < buffer + buffer_size; i += 2) {
@ -374,8 +497,7 @@ int testUtilIsValidUTF8(const unsigned char str[], const size_t length) {
return state == 0;
}
char* testUtilEscape(char* buffer, int length, char* escaped, int escaped_size)
{
char *testUtilEscape(char *buffer, int length, char *escaped, int escaped_size) {
int i;
unsigned char *b = buffer;
unsigned char *be = buffer + length;
@ -410,8 +532,7 @@ char* testUtilEscape(char* buffer, int length, char* escaped, int escaped_size)
return escaped;
}
char* testUtilReadCSVField(char* buffer, char* field, int field_size)
{
char *testUtilReadCSVField(char *buffer, char *field, int field_size) {
int i;
char *b = buffer;
for (i = 0; i < field_size && *b && *b != ',' && *b != '\n' && *b != '\r'; i++) {
@ -424,8 +545,7 @@ char* testUtilReadCSVField(char* buffer, char* field, int field_size)
return b;
}
int testUtilSymbolCmp(const struct zint_symbol* a, const struct zint_symbol* b)
{
int testUtilSymbolCmp(const struct zint_symbol *a, const struct zint_symbol *b) {
if (a->symbology != b->symbology) {
return 1;
}
@ -461,9 +581,8 @@ int testUtilSymbolCmp(const struct zint_symbol* a, const struct zint_symbol* b)
return 0;
}
struct zint_vector* testUtilVectorCpy(const struct zint_vector* in)
{
struct zint_vector* out = (struct zint_vector*)malloc(sizeof(struct zint_vector));
struct zint_vector *testUtilVectorCpy(const struct zint_vector *in) {
struct zint_vector *out = malloc(sizeof(struct zint_vector));
out->width = in->width;
out->height = in->height;
out->rectangles = NULL;
@ -485,7 +604,7 @@ struct zint_vector* testUtilVectorCpy(const struct zint_vector* in)
rect = in->rectangles;
outrect = &(out->rectangles);
while (rect) {
*outrect = (struct zint_vector_rect*) malloc(sizeof(struct zint_vector_rect));
*outrect = malloc(sizeof(struct zint_vector_rect));
memcpy(*outrect, rect, sizeof(struct zint_vector_rect));
outrect = &((*outrect)->next);
rect = rect->next;
@ -496,9 +615,9 @@ struct zint_vector* testUtilVectorCpy(const struct zint_vector* in)
string = in->strings;
outstring = &(out->strings);
while (string) {
*outstring = (struct zint_vector_string*) malloc(sizeof(struct zint_vector_string));
*outstring = malloc(sizeof(struct zint_vector_string));
memcpy(*outstring, string, sizeof(struct zint_vector_string));
(*outstring)->text = (unsigned char*) malloc(sizeof(unsigned char) * (ustrlen(string->text) + 1));
(*outstring)->text = malloc(sizeof(unsigned char) * (ustrlen(string->text) + 1));
ustrcpy((*outstring)->text, string->text);
outstring = &((*outstring)->next);
string = string->next;
@ -509,7 +628,7 @@ struct zint_vector* testUtilVectorCpy(const struct zint_vector* in)
circle = in->circles;
outcircle = &(out->circles);
while (circle) {
*outcircle = (struct zint_vector_circle*) malloc(sizeof(struct zint_vector_circle));
*outcircle = malloc(sizeof(struct zint_vector_circle));
memcpy(*outcircle, circle, sizeof(struct zint_vector_circle));
outcircle = &((*outcircle)->next);
circle = circle->next;
@ -520,7 +639,7 @@ struct zint_vector* testUtilVectorCpy(const struct zint_vector* in)
hexagon = in->hexagons;
outhexagon = &(out->hexagons);
while (hexagon) {
*outhexagon = (struct zint_vector_hexagon*) malloc(sizeof(struct zint_vector_hexagon));
*outhexagon = malloc(sizeof(struct zint_vector_hexagon));
memcpy(*outhexagon, hexagon, sizeof(struct zint_vector_hexagon));
outhexagon = &((*outhexagon)->next);
hexagon = hexagon->next;
@ -530,8 +649,7 @@ struct zint_vector* testUtilVectorCpy(const struct zint_vector* in)
return out;
}
int testUtilVectorCmp(const struct zint_vector* a, const struct zint_vector* b)
{
int testUtilVectorCmp(const struct zint_vector *a, const struct zint_vector *b) {
struct zint_vector_rect *arect;
struct zint_vector_string *astring;
struct zint_vector_circle *acircle;
@ -665,8 +783,7 @@ int testUtilVectorCmp(const struct zint_vector* a, const struct zint_vector* b)
return 0;
}
void testUtilLargeDump(const char* name, const short int reg[])
{
void testUtilLargeDump(const char *name, const short int reg[]) {
unsigned words[4];
words[0] = words[1] = words[2] = words[3] = 0;
int w = 0;
@ -681,8 +798,7 @@ void testUtilLargeDump(const char* name, const short int reg[])
printf("%4x 0x%08x%08x%08x %s", words[3], words[2], words[1], words[0], name);
}
void testUtilModulesDump(const struct zint_symbol* symbol, char* prefix, char* postfix)
{
void testUtilModulesDump(const struct zint_symbol *symbol, char *prefix, char *postfix) {
int r, w;
for (r = 0; r < symbol->rows; r++) {
if (*prefix) {
@ -699,8 +815,7 @@ void testUtilModulesDump(const struct zint_symbol* symbol, char* prefix, char* p
}
}
int testUtilModulesCmp(const struct zint_symbol* symbol, const char* expected, int* row, int* width)
{
int testUtilModulesCmp(const struct zint_symbol *symbol, const char *expected, int *row, int *width) {
const char *e = expected;
const char *ep = expected + strlen(expected);
int r, w = 0;
@ -719,8 +834,7 @@ int testUtilModulesCmp(const struct zint_symbol* symbol, const char* expected, i
return e != ep || r != symbol->rows || w != symbol->width ? 1 /*fail*/ : 0 /*success*/;
}
int testUtilModulesDumpHex(const struct zint_symbol* symbol, char dump[], int dump_size)
{
int testUtilModulesDumpHex(const struct zint_symbol *symbol, char dump[], int dump_size) {
int i, r;
char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'A', 'B', 'C', 'D', 'E', 'F'};
@ -758,8 +872,7 @@ int testUtilModulesDumpHex(const struct zint_symbol* symbol, char dump[], int du
return d - dump;
}
int testUtilExists(char* filename)
{
int testUtilExists(char *filename) {
FILE *fp = fopen(filename, "r");
if (fp == NULL) {
return 0;
@ -768,8 +881,7 @@ int testUtilExists(char* filename)
return 1;
}
int testUtilCmpPngs(char* png1, char* png2)
{
int testUtilCmpPngs(char *png1, char *png2) {
int ret = -1;
#ifndef NO_PNG
FILE *fp1;
@ -925,7 +1037,7 @@ int testUtilCmpPngs(char* png1, char* png2)
return 11;
}
row1 = (png_byte*)malloc(rowbytes1);
row1 = malloc(rowbytes1);
if (!row1) {
png_destroy_read_struct(&png_ptr1, &info_ptr1, (png_infopp)NULL);
png_destroy_read_struct(&png_ptr2, &info_ptr2, (png_infopp)NULL);
@ -933,7 +1045,7 @@ int testUtilCmpPngs(char* png1, char* png2)
fclose(fp2);
return 12;
}
row2 = (png_byte*)malloc(rowbytes2);
row2 = malloc(rowbytes2);
if (!row2) {
free(row1);
png_destroy_read_struct(&png_ptr1, &info_ptr1, (png_infopp)NULL);
@ -962,8 +1074,7 @@ int testUtilCmpPngs(char* png1, char* png2)
return ret;
}
int testUtilCmpTxts(char* txt1, char* txt2)
{
int testUtilCmpTxts(char *txt1, char *txt2) {
int ret = -1;
FILE *fp1;
FILE *fp2;
@ -1013,8 +1124,7 @@ int testUtilCmpTxts(char* txt1, char* txt2)
return ret;
}
int testUtilCmpBins(char* bin1, char* bin2)
{
int testUtilCmpBins(char *bin1, char *bin2) {
int ret = -1;
FILE *fp1;
FILE *fp2;
@ -1054,13 +1164,11 @@ int testUtilCmpBins(char* bin1, char* bin2)
return ret;
}
int testUtilCmpSvgs(char* svg1, char* svg2)
{
int testUtilCmpSvgs(char *svg1, char *svg2) {
return testUtilCmpTxts(svg1, svg2);
}
int testUtilCmpEpss(char* eps1, char* eps2)
{
int testUtilCmpEpss(char *eps1, char *eps2) {
int ret = -1;
FILE *fp1;
FILE *fp2;
@ -1122,3 +1230,71 @@ int testUtilCmpEpss(char* eps1, char* eps2)
return ret;
}
int testUtilHaveIdentify() {
return system("identify --version > /dev/null") == 0;
}
int testUtilVerifyIdentify(char *filename, int debug) {
int ret;
char buf[512 + 128];
if (strlen(filename) > 512) {
return -1;
}
// Verbose option does a more thorough check
if (debug & ZINT_DEBUG_PRINT) {
// Verbose very noisy though so for quick check just return default output
if (debug & 4) {
sprintf(buf, "identify %s", filename);
} else {
sprintf(buf, "identify -verbose %s", filename);
}
} else {
sprintf(buf, "identify -verbose %s > /dev/null", filename);
}
return system(buf);
}
int testUtilHaveInkscape() {
return system("inkscape -z -V > /dev/null") == 0;
}
int testUtilVerifyInkscape(char *filename, int debug) {
int ret;
char buf[512 + 128];
if (strlen(filename) > 512) {
return -1;
}
if (debug & ZINT_DEBUG_PRINT) {
sprintf(buf, "inkscape -z -f %s", filename); // Prints nothing unless bad
printf("%s\n", buf);
} else {
sprintf(buf, "inkscape -z -f %s > /dev/null", filename);
}
return system(buf);
}
int testUtilHaveGhostscript() {
return system("gs -v > /dev/null") == 0;
}
int testUtilVerifyGhostscript(char *filename, int debug) {
int ret;
char buf[512 + 128];
if (strlen(filename) > 512) {
return -1;
}
if (debug & ZINT_DEBUG_PRINT) {
sprintf(buf, "gs -dNOPAUSE -dBATCH -sDEVICE=nullpage -q %s", filename); // Prints nothing of interest with or without -q unless bad
printf("%s\n", buf);
} else {
sprintf(buf, "gs -dNOPAUSE -dBATCH -sDEVICE=nullpage -q %s", filename);
}
return system(buf);
}

View File

@ -40,6 +40,10 @@
#include <string.h>
#include "../common.h"
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif
extern int assertionFailed;
extern int assertionNum;
@ -48,8 +52,12 @@ extern int assertionNum;
void testStartReal(const char *func, const char *name);
void testEnd(int result);
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;
void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size);
#define assert_exp(__exp__, ...) \
{assertionNum++; if (!(__exp__)) {assertionFailed++; printf(__VA_ARGS__); testFinish(); return;}}
@ -84,5 +92,11 @@ int testUtilCmpTxts(char* txt1, char* txt2);
int testUtilCmpBins(char *bin1, char *bin2);
int testUtilCmpSvgs(char *svg1, char *svg2);
int testUtilCmpEpss(char *eps1, char *eps2);
int testUtilHaveIdentify();
int testUtilVerifyIdentify(char *filename, int debug);
int testUtilHaveInkscape();
int testUtilVerifyInkscape(char *filename, int debug);
int testUtilHaveGhostscript();
int testUtilVerifyGhostscript(char *filename, int debug);
#endif /* TESTCOMMON_H */