mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Test suite: add testRun allowing args; testSkip; haveIdentify/etc; general tidy-up
This commit is contained in:
parent
3fea67890b
commit
5eafa2e094
@ -2,46 +2,46 @@
|
||||
# Adapted from qrencode/tests/CMakeLists.txt
|
||||
# Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
|
||||
|
||||
cmake_minimum_required (VERSION 3.9)
|
||||
cmake_minimum_required(VERSION 3.9)
|
||||
|
||||
enable_testing()
|
||||
|
||||
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
|
||||
|
||||
set(ZINT_DEBUG FALSE CACHE BOOL "Set debug compile flag")
|
||||
set(ZINT_SANITIZE FALSE CACHE BOOL "Set sanitize compile/link flags")
|
||||
set(ZINT_TEST FALSE CACHE BOOL "Set test compile flag")
|
||||
|
||||
find_package (LibZint 2.7.1 REQUIRED)
|
||||
find_package(LibZint 2.7.1 REQUIRED)
|
||||
find_package(PNG)
|
||||
|
||||
if (PNG_FOUND)
|
||||
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)
|
||||
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
||||
if(ZINT_DEBUG)
|
||||
add_compile_options("-g")
|
||||
endif (ZINT_DEBUG)
|
||||
if (ZINT_SANITIZE)
|
||||
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)
|
||||
if (ZINT_TEST)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined -fsanitize=address")
|
||||
endif()
|
||||
if(ZINT_TEST)
|
||||
add_definitions("-DZINT_TEST")
|
||||
endif (ZINT_TEST)
|
||||
endif ()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_library(testcommon
|
||||
testcommon.c testcommon.h)
|
||||
if (PNG_FOUND)
|
||||
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})
|
||||
|
@ -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>
|
||||
|
@ -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,14 +32,14 @@
|
||||
#include "testcommon.h"
|
||||
|
||||
// #181 Christian Hartlage 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;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int ret;
|
||||
};
|
||||
@ -56,10 +56,14 @@ static void test_fuzz(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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();
|
||||
|
||||
|
@ -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;
|
||||
@ -43,13 +41,13 @@ static void test_encode(void)
|
||||
int input_mode;
|
||||
int option_1;
|
||||
int option_2;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
char* expected;
|
||||
char *comment;
|
||||
char *expected;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { BARCODE_AZTEC, UNICODE_MODE, -1, -1, "123456789012", 0, 15, 15, "ISO/IEC 24778:2008 Figure 1 (left)",
|
||||
@ -408,7 +406,9 @@ static void test_encode(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = data[i].symbology;
|
||||
@ -419,31 +419,31 @@ 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
|
||||
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
|
||||
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);
|
||||
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 {
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
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,14 +452,14 @@ 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;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int input_mode;
|
||||
int option_1;
|
||||
@ -873,7 +873,9 @@ static void test_fuzz(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = data[i].symbology;
|
||||
@ -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();
|
||||
|
||||
|
@ -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,20 +30,20 @@
|
||||
|
||||
#include "testcommon.h"
|
||||
|
||||
static void test_encode(void)
|
||||
{
|
||||
static void test_encode(int index, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int option_2;
|
||||
int ret_encode;
|
||||
float w;
|
||||
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++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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();
|
||||
|
||||
|
@ -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;
|
||||
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++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = BARCODE_CODABLOCKF;
|
||||
symbol->option_1 = data[i].option_1;
|
||||
symbol->option_2 = data[i].option_2;
|
||||
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;
|
||||
@ -80,13 +85,13 @@ static void test_encode(void)
|
||||
int input_mode;
|
||||
int option_1;
|
||||
int option_2;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
char* expected;
|
||||
char *comment;
|
||||
char *expected;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { UNICODE_MODE, -1, -1, "AIM", 0, 1, 68, "Same as CODE128",
|
||||
@ -127,7 +132,9 @@ static void test_encode(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = BARCODE_CODABLOCKF;
|
||||
@ -138,31 +145,31 @@ 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
|
||||
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
|
||||
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);
|
||||
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 {
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
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,13 +178,13 @@ 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;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int ret;
|
||||
};
|
||||
@ -189,10 +196,14 @@ static void test_fuzz(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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();
|
||||
|
||||
|
@ -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;
|
||||
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++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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();
|
||||
|
||||
|
@ -31,17 +31,15 @@
|
||||
|
||||
#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;
|
||||
struct item {
|
||||
int symbology;
|
||||
int input_mode;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int ret;
|
||||
};
|
||||
@ -62,11 +60,14 @@ static void test_input(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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;
|
||||
@ -88,19 +89,19 @@ static void test_encode(void)
|
||||
int symbology;
|
||||
int input_mode;
|
||||
int output_options;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
char* expected;
|
||||
char *comment;
|
||||
char *expected;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 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,7 +120,9 @@ static void test_encode(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = data[i].symbology;
|
||||
@ -127,30 +130,31 @@ 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
|
||||
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
|
||||
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);
|
||||
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 {
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
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();
|
||||
|
||||
|
@ -31,19 +31,19 @@
|
||||
|
||||
#include "testcommon.h"
|
||||
|
||||
static void test_utf8_to_unicode(void)
|
||||
{
|
||||
static void test_utf8_to_unicode(int index, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int disallow_4byte;
|
||||
int ret;
|
||||
size_t ret_length;
|
||||
int expected_vals[20];
|
||||
char* comment;
|
||||
char *comment;
|
||||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
|
||||
struct item data[] = {
|
||||
@ -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,15 +79,15 @@ 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;
|
||||
struct item {
|
||||
int codewords[50];
|
||||
int length;
|
||||
char* expected;
|
||||
char *expected;
|
||||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
|
||||
struct item data[] = {
|
||||
@ -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();
|
||||
|
||||
|
@ -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,23 +31,15 @@
|
||||
|
||||
#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;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char* composite;
|
||||
unsigned char *data;
|
||||
unsigned char *composite;
|
||||
int ret;
|
||||
|
||||
int expected_rows;
|
||||
@ -84,10 +76,14 @@ static void test_eanx_leading_zeroes(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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,15 +114,15 @@ 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;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char* composite;
|
||||
unsigned char *data;
|
||||
unsigned char *composite;
|
||||
int option_1;
|
||||
int option_2;
|
||||
int option_3;
|
||||
@ -135,8 +130,8 @@ static void test_examples(void)
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
unsigned char* expected;
|
||||
char *comment;
|
||||
unsigned char *expected;
|
||||
};
|
||||
// Verified manually against GS1 General Specifications 19.1 and ISO/IEC 24723:2010, with noted exceptions
|
||||
struct item data[] = {
|
||||
@ -297,13 +292,17 @@ static void test_examples(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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->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,19 +312,18 @@ 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
|
||||
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
|
||||
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 {
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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,15 +331,15 @@ 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;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char* composite;
|
||||
unsigned char *data;
|
||||
unsigned char *composite;
|
||||
int option_1;
|
||||
int option_2;
|
||||
int option_3;
|
||||
@ -349,8 +347,8 @@ static void test_odd_numbered_numeric(void)
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
unsigned char* expected;
|
||||
char *comment;
|
||||
unsigned char *expected;
|
||||
};
|
||||
// Verified manually against tec-it.com and bwipp
|
||||
struct item data[] = {
|
||||
@ -451,13 +449,17 @@ static void test_odd_numbered_numeric(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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->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,19 +469,18 @@ 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
|
||||
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
|
||||
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 {
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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,15 +488,15 @@ 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;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char* composite;
|
||||
unsigned char *data;
|
||||
unsigned char *composite;
|
||||
int option_1;
|
||||
int option_2;
|
||||
int option_3;
|
||||
@ -503,8 +504,8 @@ static void test_ean128_cc_shift(void)
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
unsigned char* expected;
|
||||
char *comment;
|
||||
unsigned char *expected;
|
||||
};
|
||||
// Verified manually with bwipp (tec-it.com seems to be off by 2 for top shifts > 1)
|
||||
struct item data[] = {
|
||||
@ -553,13 +554,17 @@ static void test_ean128_cc_shift(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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->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,19 +574,18 @@ 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
|
||||
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
|
||||
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 {
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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,19 +593,19 @@ 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;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char* composite;
|
||||
unsigned char *data;
|
||||
unsigned char *composite;
|
||||
int ret;
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
char *comment;
|
||||
};
|
||||
// Verified manually with bwipp (except very large tests)
|
||||
struct item data[] = {
|
||||
@ -623,11 +627,15 @@ static void test_ean128_cc_width(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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
|
||||
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
|
||||
|
||||
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
|
||||
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 {
|
||||
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);
|
||||
}
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
}
|
||||
@ -653,15 +660,15 @@ 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;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char* composite;
|
||||
unsigned char *data;
|
||||
unsigned char *composite;
|
||||
int option_1;
|
||||
int option_2;
|
||||
int option_3;
|
||||
@ -669,8 +676,8 @@ static void test_encodation_0(void)
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
unsigned char* expected;
|
||||
char *comment;
|
||||
unsigned char *expected;
|
||||
};
|
||||
// Verified manually against tec-it.com (with noted exception) and/or bwipp
|
||||
struct item data[] = {
|
||||
@ -1086,13 +1093,17 @@ static void test_encodation_0(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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->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,19 +1113,18 @@ 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
|
||||
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
|
||||
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 {
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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,15 +1132,15 @@ 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;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char* composite;
|
||||
unsigned char *data;
|
||||
unsigned char *composite;
|
||||
int option_1;
|
||||
int option_2;
|
||||
int option_3;
|
||||
@ -1138,8 +1148,8 @@ static void test_encodation_10(void)
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
unsigned char* expected;
|
||||
char *comment;
|
||||
unsigned char *expected;
|
||||
};
|
||||
// Verified manually against bwipp (and with noted exceptions, tec-it.com)
|
||||
struct item data[] = {
|
||||
@ -1214,13 +1224,17 @@ static void test_encodation_10(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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->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,19 +1244,18 @@ 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
|
||||
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
|
||||
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 {
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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,15 +1263,15 @@ 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("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char* composite;
|
||||
unsigned char *data;
|
||||
unsigned char *composite;
|
||||
int option_1;
|
||||
int option_2;
|
||||
int option_3;
|
||||
@ -1266,8 +1279,8 @@ static void test_encodation_11(void)
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
unsigned char* expected;
|
||||
char *comment;
|
||||
unsigned char *expected;
|
||||
};
|
||||
// Verified manually against tec-it.com (with noted exception) (bwipp 2019-10-13 has some issues with encodation 11 so not used)
|
||||
struct item data[] = {
|
||||
@ -1574,13 +1587,17 @@ static void test_encodation_11(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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->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,19 +1607,18 @@ 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
|
||||
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
|
||||
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 {
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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,16 +1627,16 @@ 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("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
unsigned char* composite;
|
||||
unsigned char *composite;
|
||||
int ret;
|
||||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
|
||||
@ -1635,10 +1651,14 @@ static void test_fuzz(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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();
|
||||
|
||||
|
@ -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,21 +31,19 @@
|
||||
|
||||
#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;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int eci;
|
||||
int input_mode;
|
||||
int output_options;
|
||||
int ret;
|
||||
char* comment;
|
||||
char *comment;
|
||||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
|
||||
struct item data[] = {
|
||||
@ -56,13 +54,16 @@ static void test_buffer(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = BARCODE_DATAMATRIX;
|
||||
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,19 +76,19 @@ static void test_buffer(void)
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_encode(void)
|
||||
{
|
||||
static void test_encode(int index, int generate, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
char* expected;
|
||||
char *comment;
|
||||
char *expected;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { "1234abcd", 0, 14, 14, "",
|
||||
@ -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,32 +162,35 @@ static void test_encode(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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
|
||||
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
|
||||
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);
|
||||
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 {
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
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();
|
||||
|
||||
|
@ -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
|
||||
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
|
||||
if (ret < 5) {
|
||||
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].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 {
|
||||
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,31 +371,31 @@ 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
|
||||
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
|
||||
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);
|
||||
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 {
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
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();
|
||||
|
||||
|
@ -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,17 +31,18 @@
|
||||
|
||||
#include "testcommon.h"
|
||||
|
||||
static void test_bom(void)
|
||||
{
|
||||
static void test_bom(int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = BARCODE_QRCODE;
|
||||
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,15 +84,16 @@ 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();
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
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;
|
||||
@ -116,10 +118,10 @@ static void test_reduced_charset_input(void)
|
||||
int symbology;
|
||||
int input_mode;
|
||||
int eci;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
int expected_eci;
|
||||
char* comment;
|
||||
char *comment;
|
||||
};
|
||||
// é U+00E9 in ISO 8859-1 plus other ISO 8859 (but not in ISO 8859-7 or ISO 8859-11), Win 1250 plus other Win, not in Shift JIS
|
||||
// β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in Shift JIS
|
||||
@ -214,12 +216,15 @@ static void test_reduced_charset_input(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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();
|
||||
|
||||
|
@ -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,18 +146,18 @@ static void test_gb18030_wctomb_zint(void)
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_gb18030_utf8tomb(void)
|
||||
{
|
||||
static void test_gb18030_utf8tomb(int index) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int ret;
|
||||
size_t ret_length;
|
||||
unsigned int expected_gbdata[30];
|
||||
char* comment;
|
||||
char *comment;
|
||||
};
|
||||
// é U+00E9 in ISO 8859-1 plus other ISO 8859 (but not in ISO 8859-7 or ISO 8859-11), Win 1250 plus other Win, in GB 18030 0xA8A6, UTF-8 C3A9
|
||||
// β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in GB 18030 0xA6C2, UTF-8 CEB2
|
||||
@ -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,20 +205,20 @@ static void test_gb18030_utf8tomb(void)
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_gb18030_utf8tosb(void)
|
||||
{
|
||||
static void test_gb18030_utf8tosb(int index) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int eci;
|
||||
int full_multibyte;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int ret;
|
||||
size_t ret_length;
|
||||
unsigned int expected_gbdata[30];
|
||||
char* comment;
|
||||
char *comment;
|
||||
};
|
||||
// é U+00E9 in ISO 8859-1 0xE9, Win 1250 plus other Win, in HANXIN Chinese mode first byte range 0x81..FE
|
||||
// β U+03B2 in ISO 8859-7 Greek 0xE2 (but not other ISO 8859 or Win page)
|
||||
@ -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,19 +280,19 @@ static void test_gb18030_utf8tosb(void)
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_gb18030_cpy(void)
|
||||
{
|
||||
static void test_gb18030_cpy(int index) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int full_multibyte;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int ret;
|
||||
size_t ret_length;
|
||||
unsigned int expected_gbdata[30];
|
||||
char* comment;
|
||||
char *comment;
|
||||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
|
||||
struct item data[] = {
|
||||
@ -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();
|
||||
|
||||
|
@ -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,18 +87,18 @@ static void test_gb2312_wctomb_zint(void)
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_gb2312_utf8tomb(void)
|
||||
{
|
||||
static void test_gb2312_utf8tomb(int index) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int ret;
|
||||
size_t ret_length;
|
||||
unsigned int expected_gbdata[20];
|
||||
char* comment;
|
||||
char *comment;
|
||||
};
|
||||
// é U+00E9 in ISO 8859-1 plus other ISO 8859 (but not in ISO 8859-7 or ISO 8859-11), Win 1250 plus other Win, in GB 2312 0xA8A6, UTF-8 C3A9
|
||||
// β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in GB 2312 0xA6C2, UTF-8 CEB2
|
||||
@ -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,20 +146,20 @@ static void test_gb2312_utf8tomb(void)
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_gb2312_utf8tosb(void)
|
||||
{
|
||||
static void test_gb2312_utf8tosb(int index) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int eci;
|
||||
int full_multibyte;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int ret;
|
||||
size_t ret_length;
|
||||
unsigned int expected_gbdata[20];
|
||||
char* comment;
|
||||
char *comment;
|
||||
};
|
||||
// é U+00E9 in ISO 8859-1 0xE9, Win 1250 plus other Win, in GRIDMATRIX Chinese mode first byte range 0xA1..A9, 0xB0..F7
|
||||
// β U+03B2 in ISO 8859-7 Greek 0xE2 (but not other ISO 8859 or Win page)
|
||||
@ -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,19 +219,19 @@ static void test_gb2312_utf8tosb(void)
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_gb2312_cpy(void)
|
||||
{
|
||||
static void test_gb2312_cpy(int index) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int full_multibyte;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int ret;
|
||||
size_t ret_length;
|
||||
unsigned int expected_gbdata[20];
|
||||
char* comment;
|
||||
char *comment;
|
||||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
|
||||
struct item data[] = {
|
||||
@ -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();
|
||||
|
||||
|
@ -31,16 +31,13 @@
|
||||
|
||||
#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;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int option_1;
|
||||
int option_2;
|
||||
int ret_encode;
|
||||
@ -66,12 +63,16 @@ static void test_options(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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;
|
||||
@ -99,11 +100,11 @@ static void test_input(void)
|
||||
int input_mode;
|
||||
int eci;
|
||||
int option_3;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
int expected_eci;
|
||||
char* expected;
|
||||
char* comment;
|
||||
char *expected;
|
||||
char *comment;
|
||||
};
|
||||
// é U+00E9 in ISO 8859-1 plus other ISO 8859 (but not in ISO 8859-7 or ISO 8859-11), Win 1250 plus other Win, in GB 2312 0xA8A6, UTF-8 C3A9
|
||||
// β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in GB 2312 0xA6C2, UTF-8 CEB2
|
||||
@ -170,7 +171,9 @@ static void test_input(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = BARCODE_GRIDMATRIX;
|
||||
@ -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
|
||||
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
|
||||
if (ret < 5) {
|
||||
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 {
|
||||
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);
|
||||
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,13 +208,13 @@ static void test_input(void)
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_encode(void)
|
||||
{
|
||||
static void test_encode(int index, int generate, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int input_mode;
|
||||
int option_1;
|
||||
int option_2;
|
||||
@ -218,8 +222,8 @@ static void test_encode(void)
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
char* expected;
|
||||
char *comment;
|
||||
char *expected;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { "1234", UNICODE_MODE, -1, -1, 0, 18, 18, "",
|
||||
@ -323,7 +327,9 @@ static void test_encode(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = BARCODE_GRIDMATRIX;
|
||||
@ -334,30 +340,31 @@ 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
|
||||
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
|
||||
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);
|
||||
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 {
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
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();
|
||||
|
||||
|
@ -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,25 +190,25 @@ static void test_gs1_reduce(void) {
|
||||
|
||||
ret = ZBarcode_Encode(symbol, text, length);
|
||||
|
||||
#ifdef TEST_GS1_REDUCE_GENERATE_EXPECTED
|
||||
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);
|
||||
testUtilModulesDump(symbol, " ", "\n");
|
||||
printf(" },\n");
|
||||
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);
|
||||
testUtilModulesDump(symbol, " ", "\n");
|
||||
printf(" },\n");
|
||||
} else {
|
||||
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 {
|
||||
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
|
||||
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
|
||||
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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();
|
||||
|
||||
|
@ -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,16 +31,13 @@
|
||||
|
||||
#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;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int option_1;
|
||||
int option_2;
|
||||
int ret_encode;
|
||||
@ -66,7 +63,9 @@ static void test_options(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = BARCODE_HANXIN;
|
||||
@ -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;
|
||||
@ -104,12 +104,12 @@ static void test_input(void)
|
||||
int input_mode;
|
||||
int eci;
|
||||
int option_3;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int ret;
|
||||
int expected_eci;
|
||||
char* expected;
|
||||
char* comment;
|
||||
char *expected;
|
||||
char *comment;
|
||||
};
|
||||
// é U+00E9 in ISO 8859-1 plus other ISO 8859 (but not in ISO 8859-7 or ISO 8859-11), Win 1250 plus other Win, in GB 18030 0xA8A6, UTF-8 C3A9
|
||||
// β U+03B2 in ISO 8859-7 Greek 0xE2 (but not other ISO 8859 or Win page), in GB 18030 0xA6C2, UTF-8 CEB2
|
||||
@ -162,7 +162,9 @@ static void test_input(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = BARCODE_HANXIN;
|
||||
@ -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
|
||||
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
|
||||
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);
|
||||
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 {
|
||||
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,13 +198,13 @@ static void test_input(void)
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_encode(void)
|
||||
{
|
||||
static void test_encode(int index, int generate, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int input_mode;
|
||||
int option_1;
|
||||
int option_2;
|
||||
@ -210,8 +212,8 @@ static void test_encode(void)
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
char* expected;
|
||||
char *comment;
|
||||
char *expected;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { "1234", UNICODE_MODE, -1, -1, 0, 23, 23, "",
|
||||
@ -369,7 +371,9 @@ static void test_encode(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = BARCODE_HANXIN;
|
||||
@ -380,30 +384,31 @@ 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
|
||||
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
|
||||
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);
|
||||
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 {
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
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();
|
||||
|
||||
|
@ -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,11 +36,11 @@
|
||||
|
||||
#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");
|
||||
FILE *fd = fopen("../data/imail/usps/uspsIMbEncoderTestCases.csv", "r");
|
||||
assert_nonnull(fd, "open ../data/imail/usps/uspsIMbEncoderTestCases.csv");
|
||||
|
||||
char buffer[1024];
|
||||
@ -58,15 +58,18 @@ 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
|
||||
|
||||
id[0] = tracking_code[0] = routing_code[0] = expected_daft[0] = return_code[0] = '\0';
|
||||
|
||||
char* b = testUtilReadCSVField(buffer, id, sizeof(id));
|
||||
char *b = testUtilReadCSVField(buffer, id, sizeof(id));
|
||||
assert_nonnull(b, "lc:%d id b == NULL", lc);
|
||||
assert_equal(*b, ',', "lc:%d id *b %c != ','", lc, *b);
|
||||
|
||||
@ -92,10 +95,11 @@ static void test_csv(void)
|
||||
|
||||
assert_nonzero(strlen(data), "lc:%d strlen(data) == 0", lc);
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
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();
|
||||
|
||||
|
@ -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,21 +34,21 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void test_checks(void)
|
||||
{
|
||||
static void test_checks(int index, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int input_mode;
|
||||
int eci;
|
||||
float dot_size;
|
||||
int ret;
|
||||
|
||||
char* expected;
|
||||
char *expected;
|
||||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
|
||||
struct item data[] = {
|
||||
@ -65,13 +65,15 @@ static void test_checks(void)
|
||||
};
|
||||
int data_size = sizeof(data) / sizeof(struct item);
|
||||
|
||||
char* text;
|
||||
char* primary;
|
||||
char *text;
|
||||
char *primary;
|
||||
char escaped_primary[1024];
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = data[i].symbology;
|
||||
@ -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,13 +102,13 @@ static void test_checks(void)
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_input_mode(void)
|
||||
{
|
||||
static void test_input_mode(int index, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int input_mode;
|
||||
int ret;
|
||||
|
||||
@ -128,11 +132,14 @@ static void test_input_mode(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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,15 +154,15 @@ 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;
|
||||
char filename[] = "in.bin";
|
||||
int fd;
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
(void)remove(filename); // In case junk hanging around
|
||||
@ -174,15 +181,15 @@ 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;
|
||||
char dirname[] = "in_dir";
|
||||
int fd;
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
(void)rmdir(dirname); // In case junk hanging around
|
||||
@ -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();
|
||||
|
||||
|
@ -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,20 +30,20 @@
|
||||
|
||||
#include "testcommon.h"
|
||||
|
||||
static void test_encode_vector(void)
|
||||
{
|
||||
static void test_encode_vector(int index, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret_encode;
|
||||
float w;
|
||||
float h;
|
||||
int ret_vector;
|
||||
unsigned char* expected_daft;
|
||||
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++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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();
|
||||
|
||||
|
@ -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,16 +31,13 @@
|
||||
|
||||
#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;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
float w;
|
||||
float h;
|
||||
@ -48,11 +45,11 @@ static void test_best_supported_set(void)
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
unsigned char* expected;
|
||||
char *comment;
|
||||
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,33 +91,36 @@ static void test_best_supported_set(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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,
|
||||
data[i].w, data[i].h, data[i].ret_vector, symbol->rows, symbol->width, data[i].comment);
|
||||
testUtilModulesDump(symbol, " ", "\n");
|
||||
printf(" },\n");
|
||||
#else
|
||||
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 {
|
||||
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);
|
||||
|
||||
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);
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d\n", i, ret, width, row);
|
||||
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d\n", i, ret, width, row);
|
||||
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
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++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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();
|
||||
|
||||
|
@ -31,25 +31,24 @@
|
||||
|
||||
#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();
|
||||
return;
|
||||
}
|
||||
if (!testUtilHaveIdentify()) {
|
||||
testSkip("ImageMagick identify not available");
|
||||
return;
|
||||
}
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int symbology;
|
||||
int option_1;
|
||||
int option_2;
|
||||
char* fgcolour;
|
||||
char* bgcolour;
|
||||
float scale;
|
||||
unsigned char* data;
|
||||
char *fgcolour;
|
||||
char *bgcolour;
|
||||
float scale;
|
||||
unsigned char *data;
|
||||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
|
||||
struct item data[] = {
|
||||
@ -64,53 +63,61 @@ 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++) {
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
symbol->symbology = data[i].symbology;
|
||||
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;
|
||||
}
|
||||
if (data[i].fgcolour != NULL) {
|
||||
strcpy(symbol->fgcolour, data[i].fgcolour);
|
||||
}
|
||||
if (data[i].bgcolour != NULL) {
|
||||
strcpy(symbol->bgcolour, data[i].bgcolour);
|
||||
}
|
||||
if (data[i].scale != 0) {
|
||||
symbol->scale = data[i].scale;
|
||||
}
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
int length = strlen(data[i].data);
|
||||
symbol->symbology = data[i].symbology;
|
||||
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;
|
||||
}
|
||||
if (data[i].fgcolour != NULL) {
|
||||
strcpy(symbol->fgcolour, data[i].fgcolour);
|
||||
}
|
||||
if (data[i].bgcolour != NULL) {
|
||||
strcpy(symbol->bgcolour, data[i].bgcolour);
|
||||
}
|
||||
if (data[i].scale != 0) {
|
||||
symbol->scale = data[i].scale;
|
||||
}
|
||||
symbol->debug |= debug;
|
||||
|
||||
ret = ZBarcode_Encode(symbol, data[i].data, length);
|
||||
assert_zero(ret, "i:%d %s ZBarcode_Encode ret %d != 0 %s\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt);
|
||||
int length = strlen(data[i].data);
|
||||
|
||||
char* filename = "out.pcx";
|
||||
strcpy(symbol->outfile, filename);
|
||||
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 = ZBarcode_Encode(symbol, data[i].data, length);
|
||||
assert_zero(ret, "i:%d %s ZBarcode_Encode ret %d != 0 %s\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt);
|
||||
|
||||
//ret = system("identify out.pcx > /dev/null");
|
||||
ret = system("identify out.pcx");
|
||||
assert_zero(ret, "i:%d %s identify %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret);
|
||||
char *filename = "out.pcx";
|
||||
strcpy(symbol->outfile, filename);
|
||||
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);
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
}
|
||||
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();
|
||||
|
||||
|
@ -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++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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,25 +118,26 @@ 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;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
char* expected;
|
||||
char *comment;
|
||||
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++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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,30 +170,31 @@ 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);
|
||||
testUtilModulesDump(symbol, " ", "\n");
|
||||
printf(" },\n");
|
||||
#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);
|
||||
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 {
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
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,14 +203,14 @@ 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;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int option_1;
|
||||
int ret;
|
||||
@ -460,13 +467,17 @@ static void test_fuzz(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = data[i].symbology;
|
||||
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();
|
||||
|
||||
|
@ -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;
|
||||
@ -47,24 +130,26 @@ static void test_print(void)
|
||||
char* expected_file;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { BARCODE_CODABLOCKF, 3, -1, "AAAAAAAAA", "../data/png/codablockf_3rows.png"},
|
||||
/* 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 (!testUtilExists(data_dir)) {
|
||||
ret = mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
|
||||
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);
|
||||
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
|
||||
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
@ -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,13 @@
|
||||
|
||||
#include "testcommon.h"
|
||||
|
||||
static void test_koreapost(void)
|
||||
{
|
||||
static void test_koreapost(int index, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret_encode;
|
||||
int ret_vector;
|
||||
|
||||
@ -52,10 +52,14 @@ static void test_koreapost(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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,20 +80,20 @@ static void test_koreapost(void)
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_japanpost(void)
|
||||
{
|
||||
static void test_japanpost(int index, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret_encode;
|
||||
int ret_vector;
|
||||
|
||||
int expected_height;
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
char *comment;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { "123", 0, 0, 8, 3, 133, "Check 3" },
|
||||
@ -100,10 +104,14 @@ static void test_japanpost(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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();
|
||||
|
||||
|
@ -32,20 +32,23 @@
|
||||
#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;
|
||||
int option_1;
|
||||
int option_2;
|
||||
unsigned char* data;
|
||||
char* expected_file;
|
||||
unsigned char *data;
|
||||
char *expected_file;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { BARCODE_CODE128, -1, -1, "AIM", "code128_aim" },
|
||||
@ -55,7 +58,7 @@ static void test_print(void)
|
||||
};
|
||||
int data_size = sizeof(data) / sizeof(struct item);
|
||||
|
||||
char* exts[] = { "bmp", "emf", "eps", "gif", "pcx", "png", "svg", "tif", "txt" };
|
||||
char *exts[] = { "bmp", "emf", "eps", "gif", "pcx", "png", "svg", "tif", "txt" };
|
||||
int exts_len = sizeof(exts) / sizeof(char*);
|
||||
|
||||
char data_dir[1024];
|
||||
@ -64,33 +67,35 @@ static void test_print(void)
|
||||
char escaped[1024];
|
||||
int escaped_size = 1024;
|
||||
|
||||
#ifdef TEST_PRINT_GENERATE_EXPECTED
|
||||
strcpy(data_dir, "../data");
|
||||
if (!testUtilExists(data_dir)) {
|
||||
ret = mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
|
||||
if (generate) {
|
||||
strcpy(data_dir, "../data");
|
||||
if (!testUtilExists(data_dir)) {
|
||||
ret = mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
|
||||
}
|
||||
strcat(data_dir, "/print");
|
||||
if (!testUtilExists(data_dir)) {
|
||||
ret = mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
|
||||
}
|
||||
}
|
||||
strcat(data_dir, "/print");
|
||||
if (!testUtilExists(data_dir)) {
|
||||
ret = mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
|
||||
}
|
||||
#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 (!testUtilExists(data_dir)) {
|
||||
ret = mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
|
||||
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++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = data[i].symbology;
|
||||
@ -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,42 +124,54 @@ 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 (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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
#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) {
|
||||
ret = testUtilCmpEpss(symbol->outfile, expected_file);
|
||||
assert_zero(ret, "i:%d %s testUtilCmpEpss(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
|
||||
} else if (strcmp(exts[j], "png") == 0) {
|
||||
ret = testUtilCmpPngs(symbol->outfile, expected_file);
|
||||
assert_zero(ret, "i:%d %s testUtilCmpPngs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
|
||||
} else if (strcmp(exts[j], "svg") == 0) {
|
||||
ret = testUtilCmpSvgs(symbol->outfile, expected_file);
|
||||
assert_zero(ret, "i:%d %s testUtilCmpSvgs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
|
||||
} else if (strcmp(exts[j], "txt") == 0) {
|
||||
ret = testUtilCmpTxts(symbol->outfile, expected_file);
|
||||
assert_zero(ret, "i:%d %s testUtilCmpTxts(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
|
||||
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);
|
||||
}
|
||||
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 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 {
|
||||
ret = testUtilCmpBins(symbol->outfile, expected_file);
|
||||
assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
|
||||
assert_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) {
|
||||
ret = testUtilCmpEpss(symbol->outfile, expected_file);
|
||||
assert_zero(ret, "i:%d %s testUtilCmpEpss(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
|
||||
} else if (strcmp(exts[j], "png") == 0) {
|
||||
ret = testUtilCmpPngs(symbol->outfile, expected_file);
|
||||
assert_zero(ret, "i:%d %s testUtilCmpPngs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
|
||||
} else if (strcmp(exts[j], "svg") == 0) {
|
||||
ret = testUtilCmpSvgs(symbol->outfile, expected_file);
|
||||
assert_zero(ret, "i:%d %s testUtilCmpSvgs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
|
||||
} else if (strcmp(exts[j], "txt") == 0) {
|
||||
ret = testUtilCmpTxts(symbol->outfile, expected_file);
|
||||
assert_zero(ret, "i:%d %s testUtilCmpTxts(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
|
||||
} else {
|
||||
ret = testUtilCmpBins(symbol->outfile, expected_file);
|
||||
assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);
|
||||
}
|
||||
|
||||
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -31,15 +31,15 @@
|
||||
|
||||
#include "testcommon.h"
|
||||
|
||||
static void test_chk_extendable(void)
|
||||
{
|
||||
static void test_chk_extendable(int index, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int symbology;
|
||||
int show_hrt;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
|
||||
int expected_height;
|
||||
@ -61,13 +61,17 @@ static void test_chk_extendable(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = data[i].symbology;
|
||||
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();
|
||||
|
||||
|
@ -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,19 +31,14 @@
|
||||
|
||||
#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;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret_encode;
|
||||
float w;
|
||||
float h;
|
||||
@ -51,7 +46,7 @@ static void test_binary_div_modulo_divisor(void)
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
unsigned char* expected;
|
||||
unsigned char *expected;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { BARCODE_RSS14, "1234567890123", 0, 100, 30, 0, 1, 96, "010111010010000001001110000000010100001011111010110100011001100101111111110001011011000111000101" },
|
||||
@ -70,31 +65,34 @@ static void test_binary_div_modulo_divisor(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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
|
||||
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
|
||||
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 {
|
||||
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);
|
||||
|
||||
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);
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d\n", i, ret, width, row);
|
||||
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d\n", i, ret, width, row);
|
||||
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
}
|
||||
@ -103,20 +101,20 @@ 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;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
unsigned char* expected;
|
||||
char *comment;
|
||||
unsigned char *expected;
|
||||
};
|
||||
// Verified manually against GS1 General Specifications 19.1 and ISO/IEC 24724:2011
|
||||
struct item data[] = {
|
||||
@ -196,36 +194,39 @@ static void test_examples(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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 (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);
|
||||
testUtilModulesDump(symbol, " ", "\n");
|
||||
printf(" },\n");
|
||||
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);
|
||||
testUtilModulesDump(symbol, " ", "\n");
|
||||
printf(" },\n");
|
||||
} else {
|
||||
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 {
|
||||
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
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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,20 +235,20 @@ 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;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
unsigned char* expected;
|
||||
char *comment;
|
||||
unsigned char *expected;
|
||||
};
|
||||
// Verified manually against bwipp and tec-it.com (bottom separator differs from tec-it.com where noted)
|
||||
struct item data[] = {
|
||||
@ -502,36 +503,39 @@ static void test_general_field(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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 (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);
|
||||
testUtilModulesDump(symbol, " ", "\n");
|
||||
printf(" },\n");
|
||||
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);
|
||||
testUtilModulesDump(symbol, " ", "\n");
|
||||
printf(" },\n");
|
||||
} else {
|
||||
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 {
|
||||
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
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
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,18 +543,18 @@ 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;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
char *comment;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { "[91]1", 0, 1, 102, "Minimum digit" },
|
||||
@ -566,23 +570,26 @@ static void test_binary_buffer_size(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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
|
||||
printf(" /*%2d*/ { \"%s\", %s, %d, %d, \"%s\" },\n",
|
||||
i, data[i].data, testUtilErrorName(ret), symbol->rows, symbol->width, data[i].comment);
|
||||
#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
|
||||
if (generate) {
|
||||
printf(" /*%2d*/ { \"%s\", %s, %d, %d, \"%s\" },\n",
|
||||
i, data[i].data, testUtilErrorName(ret), symbol->rows, symbol->width, data[i].comment);
|
||||
} 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);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
@ -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,18 +106,18 @@ static void test_sjis_wctomb_zint(void)
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_sjis_utf8tomb(void)
|
||||
{
|
||||
static void test_sjis_utf8tomb(int index) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int ret;
|
||||
size_t ret_length;
|
||||
unsigned int expected_jisdata[20];
|
||||
char* comment;
|
||||
char *comment;
|
||||
};
|
||||
// é U+00E9 in ISO 8859-1 plus other ISO 8859 (but not in ISO 8859-7 or ISO 8859-11), Win 1250 plus other Win, not in Shift JIS, UTF-8 C3A9
|
||||
// β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in Shift JIS 0x83C0, UTF-8 CEB2
|
||||
@ -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,20 +164,20 @@ static void test_sjis_utf8tomb(void)
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_sjis_utf8tosb(void)
|
||||
{
|
||||
static void test_sjis_utf8tosb(int index) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int eci;
|
||||
int full_multibyte;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int ret;
|
||||
size_t ret_length;
|
||||
unsigned int expected_jisdata[20];
|
||||
char* comment;
|
||||
char *comment;
|
||||
};
|
||||
// é U+00E9 in ISO 8859-1 0xE9, Win 1250 plus other Win, in QR Kanji mode first byte range 0x81..9F, 0xE0..EB
|
||||
// β U+03B2 in ISO 8859-7 Greek 0xE2 (but not other ISO 8859 or Win page)
|
||||
@ -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,19 +230,19 @@ static void test_sjis_utf8tosb(void)
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_sjis_cpy(void)
|
||||
{
|
||||
static void test_sjis_cpy(int index) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int full_multibyte;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int ret;
|
||||
size_t ret_length;
|
||||
unsigned int expected_jisdata[20];
|
||||
char* comment;
|
||||
char *comment;
|
||||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
|
||||
struct item data[] = {
|
||||
@ -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();
|
||||
|
||||
|
@ -32,19 +32,19 @@
|
||||
#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;
|
||||
int option_1;
|
||||
int option_2;
|
||||
unsigned char* data;
|
||||
char* expected_file;
|
||||
unsigned char *data;
|
||||
char *expected_file;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { BARCODE_CODE128, -1, -1, "<>\"&'", "../data/svg/code128_amperands.svg" },
|
||||
@ -52,21 +52,23 @@ static void test_print(void)
|
||||
};
|
||||
int data_size = sizeof(data) / sizeof(struct item);
|
||||
|
||||
char* data_dir = "../data/svg";
|
||||
char* svg = "out.svg";
|
||||
char *data_dir = "../data/svg";
|
||||
char *svg = "out.svg";
|
||||
char escaped[1024];
|
||||
int escaped_size = 1024;
|
||||
|
||||
#ifdef TEST_PRINT_GENERATE_EXPECTED
|
||||
if (!testUtilExists(data_dir)) {
|
||||
ret = mkdir(data_dir, 0755);
|
||||
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
|
||||
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++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = data[i].symbology;
|
||||
@ -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);
|
||||
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);
|
||||
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);
|
||||
|
||||
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);
|
||||
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
|
||||
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
@ -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,14 +32,14 @@
|
||||
#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;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int ret;
|
||||
};
|
||||
@ -57,14 +57,15 @@ static void test_fuzz(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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();
|
||||
|
||||
|
@ -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;
|
||||
@ -44,10 +41,10 @@ static void test_input(void)
|
||||
int eci;
|
||||
int option_1;
|
||||
int option_3;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
char* expected;
|
||||
char* comment;
|
||||
char *expected;
|
||||
char *comment;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { UNICODE_MODE, 0, -1, -1, "A", 0, "(2) 257 65", "" },
|
||||
@ -98,7 +95,9 @@ static void test_input(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = BARCODE_ULTRA;
|
||||
@ -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
|
||||
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
|
||||
if (ret < 5) {
|
||||
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].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 {
|
||||
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;
|
||||
@ -144,13 +143,13 @@ static void test_encode(void)
|
||||
int eci;
|
||||
int option_1;
|
||||
int option_3;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
|
||||
int expected_rows;
|
||||
int expected_width;
|
||||
char* comment;
|
||||
char* expected;
|
||||
char *comment;
|
||||
char *expected;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "ULTRACODE_123456789!", 0, 13, 22, "AIMD/TSC15032-43 Figure G.1 **NOT SAME** different compression",
|
||||
@ -433,7 +432,9 @@ static void test_encode(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_symbol *symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
symbol->symbology = BARCODE_ULTRA;
|
||||
@ -445,31 +446,31 @@ 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
|
||||
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
|
||||
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);
|
||||
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 {
|
||||
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);
|
||||
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
|
||||
if (ret == 0) {
|
||||
int width, row;
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
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();
|
||||
|
||||
|
@ -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,14 +31,14 @@
|
||||
|
||||
#include "testcommon.h"
|
||||
|
||||
static void test_upce_length(void)
|
||||
{
|
||||
static void test_upce_length(int index, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
|
||||
@ -63,10 +63,14 @@ static void test_upce_length(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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,14 +83,14 @@ 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;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret;
|
||||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
|
||||
@ -97,10 +101,14 @@ static void test_upca_print(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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,13 +126,13 @@ static void test_upca_print(void)
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_isbn(void)
|
||||
{
|
||||
static void test_isbn(int index, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret_encode;
|
||||
int ret_vector;
|
||||
};
|
||||
@ -175,10 +183,14 @@ static void test_isbn(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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,14 +207,14 @@ static void test_isbn(void)
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_vector_same(void)
|
||||
{
|
||||
static void test_vector_same(int index, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int ret_encode;
|
||||
int ret_vector;
|
||||
};
|
||||
@ -215,14 +227,18 @@ static void test_vector_same(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_vector* vectors[4];
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
struct zint_vector *vectors[4];
|
||||
int vectors_size = sizeof(vectors) / sizeof(struct zint_vector*);
|
||||
|
||||
for (int j = 0; j < vectors_size; j++) {
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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);
|
||||
@ -253,14 +269,14 @@ 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;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
int ret;
|
||||
};
|
||||
@ -281,10 +297,14 @@ static void test_fuzz(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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();
|
||||
|
||||
|
@ -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,17 +31,15 @@
|
||||
|
||||
#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;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
char* composite;
|
||||
unsigned char *data;
|
||||
char *composite;
|
||||
|
||||
int expected_height;
|
||||
int expected_rows;
|
||||
@ -146,15 +144,18 @@ static void test_buffer_vector(void)
|
||||
};
|
||||
int data_size = sizeof(data) / sizeof(struct item);
|
||||
|
||||
char* text;
|
||||
char *text;
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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,22 +172,19 @@ 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
|
||||
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
|
||||
|
||||
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);
|
||||
assert_equal(symbol->vector->width, data[i].expected_vector_width, "i:%d (%s) symbol->vector->width %f != %f\n",
|
||||
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
|
||||
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 {
|
||||
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);
|
||||
assert_equal(symbol->vector->width, data[i].expected_vector_width, "i:%d (%s) symbol->vector->width %f != %f\n",
|
||||
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);
|
||||
}
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
}
|
||||
@ -195,14 +193,14 @@ 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;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
|
||||
int expected_width;
|
||||
float expected_string_x;
|
||||
@ -217,11 +215,14 @@ static void test_noncomposite_string_x(void)
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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,14 +245,14 @@ 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;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char *data;
|
||||
int whitespace_width;
|
||||
|
||||
int expected_width;
|
||||
@ -268,17 +269,20 @@ static void test_upcean_whitespace_width(void)
|
||||
};
|
||||
int data_size = sizeof(data) / sizeof(struct item);
|
||||
|
||||
struct zint_vector_string* string;
|
||||
struct zint_vector_string *string;
|
||||
int string_cnt;
|
||||
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
|
||||
struct zint_symbol* symbol = ZBarcode_Create();
|
||||
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();
|
||||
|
||||
|
@ -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,20 +89,144 @@ void testFinish(void)
|
||||
}
|
||||
}
|
||||
|
||||
void testReport()
|
||||
{
|
||||
if ( failed ) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
char* testUtilBarcodeName(int symbology) {
|
||||
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;
|
||||
char* name;
|
||||
char *name;
|
||||
int val;
|
||||
};
|
||||
struct item data[] = {
|
||||
@ -265,10 +389,10 @@ char* testUtilBarcodeName(int symbology) {
|
||||
return data[symbology].name;
|
||||
}
|
||||
|
||||
char* testUtilErrorName(int error_number) {
|
||||
char *testUtilErrorName(int error_number) {
|
||||
struct item {
|
||||
int define;
|
||||
char* name;
|
||||
char *name;
|
||||
int val;
|
||||
};
|
||||
struct item data[] = {
|
||||
@ -297,10 +421,10 @@ char* testUtilErrorName(int error_number) {
|
||||
return data[error_number].name;
|
||||
}
|
||||
|
||||
char* testUtilInputModeName(int input_mode) {
|
||||
char *testUtilInputModeName(int input_mode) {
|
||||
struct item {
|
||||
int define;
|
||||
char* name;
|
||||
char *name;
|
||||
int val;
|
||||
};
|
||||
struct item data[] = {
|
||||
@ -328,7 +452,7 @@ char* testUtilInputModeName(int input_mode) {
|
||||
return data[input_mode].name;
|
||||
}
|
||||
|
||||
char* testUtilOption3Name(int option_3) {
|
||||
char *testUtilOption3Name(int option_3) {
|
||||
switch (option_3) {
|
||||
case DM_SQUARE: return "DM_SQUARE";
|
||||
case DM_DMRE: return "DM_DMRE";
|
||||
@ -338,10 +462,9 @@ 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;
|
||||
char *b = buffer;
|
||||
for (int i = 0; i < symbol->width && b < buffer + buffer_size; i += 2) {
|
||||
if (module_is_set(symbol, 0, i) && module_is_set(symbol, 2, i)) {
|
||||
*b++ = 'F';
|
||||
@ -374,11 +497,10 @@ 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;
|
||||
unsigned char *b = buffer;
|
||||
unsigned char *be = buffer + length;
|
||||
int non_utf8 = !testUtilIsValidUTF8(buffer, length);
|
||||
|
||||
for (i = 0; b < be && i < escaped_size; b++) {
|
||||
@ -410,10 +532,9 @@ 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;
|
||||
char *b = buffer;
|
||||
for (i = 0; i < field_size && *b && *b != ',' && *b != '\n' && *b != '\r'; i++) {
|
||||
field[i] = *b++;
|
||||
}
|
||||
@ -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;
|
||||
@ -471,21 +590,21 @@ struct zint_vector* testUtilVectorCpy(const struct zint_vector* in)
|
||||
out->circles = NULL;
|
||||
out->hexagons = NULL;
|
||||
|
||||
struct zint_vector_rect* rect;
|
||||
struct zint_vector_string* string;
|
||||
struct zint_vector_circle* circle;
|
||||
struct zint_vector_hexagon* hexagon;
|
||||
struct zint_vector_rect *rect;
|
||||
struct zint_vector_string *string;
|
||||
struct zint_vector_circle *circle;
|
||||
struct zint_vector_hexagon *hexagon;
|
||||
|
||||
struct zint_vector_rect** outrect;
|
||||
struct zint_vector_string** outstring;
|
||||
struct zint_vector_circle** outcircle;
|
||||
struct zint_vector_hexagon** outhexagon;
|
||||
struct zint_vector_rect **outrect;
|
||||
struct zint_vector_string **outstring;
|
||||
struct zint_vector_circle **outcircle;
|
||||
struct zint_vector_hexagon **outhexagon;
|
||||
|
||||
// Copy rectangles
|
||||
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,17 +649,16 @@ struct zint_vector* testUtilVectorCpy(const struct zint_vector* in)
|
||||
return out;
|
||||
}
|
||||
|
||||
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;
|
||||
struct zint_vector_hexagon* ahexagon;
|
||||
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;
|
||||
struct zint_vector_hexagon *ahexagon;
|
||||
|
||||
struct zint_vector_rect* brect;
|
||||
struct zint_vector_string* bstring;
|
||||
struct zint_vector_circle* bcircle;
|
||||
struct zint_vector_hexagon* bhexagon;
|
||||
struct zint_vector_rect *brect;
|
||||
struct zint_vector_string *bstring;
|
||||
struct zint_vector_circle *bcircle;
|
||||
struct zint_vector_hexagon *bhexagon;
|
||||
|
||||
if (a->width != b->width) {
|
||||
return 1;
|
||||
@ -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,10 +815,9 @@ 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)
|
||||
{
|
||||
const char* e = expected;
|
||||
const char* ep = expected + strlen(expected);
|
||||
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;
|
||||
for (r = 0; r < symbol->rows && e < ep; r++) {
|
||||
for (w = 0; w < symbol->width && e < ep; w++) {
|
||||
@ -719,14 +834,13 @@ 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'};
|
||||
int space = 0;
|
||||
char* d = dump;
|
||||
char* de = dump + dump_size;
|
||||
char *d = dump;
|
||||
char *de = dump + dump_size;
|
||||
|
||||
for (r = 0; r < symbol->rows && d < de; r++) {
|
||||
int byt = 0;
|
||||
@ -758,9 +872,8 @@ int testUtilModulesDumpHex(const struct zint_symbol* symbol, char dump[], int du
|
||||
return d - dump;
|
||||
}
|
||||
|
||||
int testUtilExists(char* filename)
|
||||
{
|
||||
FILE* fp = fopen(filename, "r");
|
||||
int testUtilExists(char *filename) {
|
||||
FILE *fp = fopen(filename, "r");
|
||||
if (fp == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@ -768,12 +881,11 @@ 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;
|
||||
FILE* fp2;
|
||||
FILE *fp1;
|
||||
FILE *fp2;
|
||||
png_structp png_ptr1, png_ptr2;
|
||||
png_infop info_ptr1, info_ptr2;
|
||||
int width1, height1, width2, height2;
|
||||
@ -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,11 +1074,10 @@ 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;
|
||||
FILE *fp1;
|
||||
FILE *fp2;
|
||||
char buf1[1024];
|
||||
char buf2[1024];
|
||||
size_t len1 = 0, len2 = 0;
|
||||
@ -1013,11 +1124,10 @@ 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;
|
||||
FILE *fp1;
|
||||
FILE *fp2;
|
||||
char buf1[1024];
|
||||
char buf2[1024];
|
||||
size_t len1 = 0, len2 = 0;
|
||||
@ -1054,16 +1164,14 @@ 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;
|
||||
FILE *fp1;
|
||||
FILE *fp2;
|
||||
char buf1[1024];
|
||||
char buf2[1024];
|
||||
size_t len1 = 0, len2 = 0;
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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,10 +52,14 @@ 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;}}
|
||||
{assertionNum++; if (!(__exp__)) {assertionFailed++; printf(__VA_ARGS__); testFinish(); return;}}
|
||||
|
||||
#define assert_zero(__exp__, ...) assert_exp((__exp__) == 0, __VA_ARGS__)
|
||||
#define assert_nonzero(__exp__, ...) assert_exp((__exp__) != 0, __VA_ARGS__)
|
||||
@ -64,25 +72,31 @@ void testReport();
|
||||
|
||||
extern void vector_free(struct zint_symbol *symbol); /* Free vector structures */
|
||||
|
||||
char* testUtilBarcodeName(int symbology);
|
||||
char* testUtilErrorName(int error_number);
|
||||
char* testUtilInputModeName(int input_mode);
|
||||
char* testUtilOption3Name(int option_3);
|
||||
int testUtilDAFTConvert(const struct zint_symbol* symbol, char* buffer, int buffer_size);
|
||||
char* testUtilEscape(char* buffer, int length, char* escaped, int escaped_size);
|
||||
char* testUtilReadCSVField(char* buffer, char* field, int field_size);
|
||||
int testUtilSymbolCmp(const struct zint_symbol* a, const struct zint_symbol* b);
|
||||
struct zint_vector* testUtilVectorCpy(const struct zint_vector* in);
|
||||
int testUtilVectorCmp(const struct zint_vector* a, const struct zint_vector* b);
|
||||
void testUtilLargeDump(const char* name, const short reg[]);
|
||||
void testUtilModulesDump(const struct zint_symbol* symbol, char* prefix, char* postfix);
|
||||
int testUtilModulesCmp(const struct zint_symbol* symbol, const char* expected, int* row, int* width);
|
||||
int testUtilModulesDumpHex(const struct zint_symbol* symbol, char dump[], int dump_size);
|
||||
int testUtilExists(char* filename);
|
||||
int testUtilCmpPngs(char* file1, char* file2);
|
||||
int testUtilCmpTxts(char* txt1, char* txt2);
|
||||
int testUtilCmpBins(char* bin1, char* bin2);
|
||||
int testUtilCmpSvgs(char* svg1, char* svg2);
|
||||
int testUtilCmpEpss(char* eps1, char* eps2);
|
||||
char *testUtilBarcodeName(int symbology);
|
||||
char *testUtilErrorName(int error_number);
|
||||
char *testUtilInputModeName(int input_mode);
|
||||
char *testUtilOption3Name(int option_3);
|
||||
int testUtilDAFTConvert(const struct zint_symbol *symbol, char *buffer, int buffer_size);
|
||||
char *testUtilEscape(char *buffer, int length, char *escaped, int escaped_size);
|
||||
char *testUtilReadCSVField(char *buffer, char *field, int field_size);
|
||||
int testUtilSymbolCmp(const struct zint_symbol *a, const struct zint_symbol *b);
|
||||
struct zint_vector *testUtilVectorCpy(const struct zint_vector *in);
|
||||
int testUtilVectorCmp(const struct zint_vector *a, const struct zint_vector *b);
|
||||
void testUtilLargeDump(const char *name, const short reg[]);
|
||||
void testUtilModulesDump(const struct zint_symbol *symbol, char *prefix, char *postfix);
|
||||
int testUtilModulesCmp(const struct zint_symbol *symbol, const char *expected, int *row, int *width);
|
||||
int testUtilModulesDumpHex(const struct zint_symbol *symbol, char dump[], int dump_size);
|
||||
int testUtilExists(char *filename);
|
||||
int testUtilCmpPngs(char *file1, char *file2);
|
||||
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 */
|
||||
|
Loading…
Reference in New Issue
Block a user