diff --git a/backend/codablock.c b/backend/codablock.c index bfaf4484..cdaa6073 100644 --- a/backend/codablock.c +++ b/backend/codablock.c @@ -2,7 +2,7 @@ /* libzint - the open source barcode library - Copyright (C) 2016 Harald Oehlmann + Copyright (C) 2016 - 2020 Harald Oehlmann Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -34,7 +34,6 @@ #include #include #include -#include #ifdef _MSC_VER #include #endif @@ -116,7 +115,7 @@ static int GetPossibleCharacterSet(unsigned char C) * int CFollowing The number of characters encodable in CodeC if we * start here. */ -static void CreateCharacterSetTable(CharacterSetTable T[], unsigned char *data,const size_t dataLength) +static void CreateCharacterSetTable(CharacterSetTable T[], unsigned char *data, const int dataLength) { int charCur; int runChar; @@ -147,7 +146,7 @@ static void CreateCharacterSetTable(CharacterSetTable T[], unsigned char *data,c /* CodeC possible */ runChar=charCur; do{ - /* Wether this is FNC1 wether next is */ + /* Whether this is FNC1, whether next is */ /* numeric */ if (T[runChar].CharacterSet==ZTFNC1) /* FNC1 */ @@ -194,19 +193,18 @@ static int RemainingDigits(CharacterSetTable *T, int charCur,int emptyColumns) } /* Find the Character distribution at a given column count. - * If to many rows (>44) are requested the columns is extended. - * A oneLigner may be choosen if shorter. + * If too many rows (>44) are requested the columns are extended. + * A one-liner may be choosen if shorter. * Parameters : * T Pointer on the Characters which fit in the row * If a different count is calculated it is corrected * in the callers workspace. * pFillings Output of filling characters * pSet Output of the character sets used, allocated by me. - * Data The Data string to encode, exceptionnally not an out * Return value Resulting row count */ -static int Columns2Rows(struct zint_symbol *symbol, CharacterSetTable *T, unsigned char *data, const size_t dataLength, +static int Columns2Rows(struct zint_symbol *symbol, CharacterSetTable *T, const int dataLength, int * pRows, int * pUseColumns, int * pSet, int * pFillings) { int useColumns; /* Usable Characters per line */ @@ -398,7 +396,7 @@ static int Columns2Rows(struct zint_symbol *symbol, CharacterSetTable *T, unsign switch (emptyColumns) { case 1: pSet[charCur-1]|=CFill; - /* Glide in following block without break */ + /* fall through */ case 0: ++rowsCur; fillings=useColumns-2+emptyColumns; @@ -429,7 +427,7 @@ static int Columns2Rows(struct zint_symbol *symbol, CharacterSetTable *T, unsign } /* Find columns if row count is given. */ -static int Rows2Columns(struct zint_symbol *symbol, CharacterSetTable *T, unsigned char *data, const size_t dataLength, +static int Rows2Columns(struct zint_symbol *symbol, CharacterSetTable *T, const int dataLength, int * pRows, int * pUseColumns, int * pSet, int * pFillings) { int rowsCur; @@ -440,7 +438,7 @@ static int Rows2Columns(struct zint_symbol *symbol, CharacterSetTable *T, unsign int useColumns; int testColumns; /* To enter into Width2Rows */ int backupColumns = 0; - int fBackupOk = 0; /* The memorysed set is o.k. */ + int fBackupOk = 0; /* The memorised set is o.k. */ int testListSize = 0; int pTestList[62]; #ifndef _MSC_VER @@ -472,7 +470,7 @@ static int Rows2Columns(struct zint_symbol *symbol, CharacterSetTable *T, unsign pTestList[testListSize] = testColumns; testListSize++; useColumns=testColumns; /* Make a copy because it may be modified */ - errorCur = Columns2Rows(symbol, T, data, dataLength, &rowsCur, &useColumns, pSet, &fillings); + errorCur = Columns2Rows(symbol, T, dataLength, &rowsCur, &useColumns, pSet, &fillings); if (errorCur != 0) return errorCur; if (rowsCur<=rowsRequested) { @@ -629,7 +627,7 @@ static void SumASCII(uchar **ppOutPos, int Sum, int CharacterSet) /* Main function called by zint framework */ INTERNAL int codablock(struct zint_symbol *symbol,const unsigned char source[], const size_t length) { - size_t charCur,dataLength; + int charCur, dataLength; int Error; int rows, columns, useColumns; int fillings; @@ -638,8 +636,8 @@ INTERNAL int codablock(struct zint_symbol *symbol,const unsigned char source[], int rowCur; int characterSetCur; int emptyColumns; - char dest[1000]; - int r, c; + char dest[1000]; + int r, c; #ifdef _MSC_VER CharacterSetTable *T; unsigned char *data; @@ -651,7 +649,7 @@ INTERNAL int codablock(struct zint_symbol *symbol,const unsigned char source[], /* option1: rows 0: automatic, 1..44 */ rows = symbol->option_1; if (rows > 44) { - strcpy(symbol->errtxt, "410: Row parameter not in 0..44"); + strcpy(symbol->errtxt, "410: Rows parameter not in 0..44"); return ZINT_ERROR_INVALID_OPTION; } /* option_2: (usable data) columns: 0: automatic, 6..66 */ @@ -677,7 +675,7 @@ INTERNAL int codablock(struct zint_symbol *symbol,const unsigned char source[], dataLength++; } /* Replace all Codes>127 with Code-128 */ - for (charCur=0;charCur127) { data[dataLength] = aFNC4; @@ -711,7 +709,7 @@ INTERNAL int codablock(struct zint_symbol *symbol,const unsigned char source[], columns = 64; } if (symbol->debug & ZINT_DEBUG_PRINT) { - printf("Auto column count for %zu characters:%d\n",dataLength,columns); + printf("Auto column count for %d characters:%d\n", dataLength, columns); } } } @@ -719,20 +717,20 @@ INTERNAL int codablock(struct zint_symbol *symbol,const unsigned char source[], useColumns = columns - 5; if ( rows > 0 ) { /* row count given */ - Error = Rows2Columns(symbol, T, data, dataLength, &rows, &useColumns, pSet, &fillings); + Error = Rows2Columns(symbol, T, dataLength, &rows, &useColumns, pSet, &fillings); } else { /* column count given */ - Error = Columns2Rows(symbol, T, data, dataLength, &rows, &useColumns, pSet, &fillings); + Error = Columns2Rows(symbol, T, dataLength, &rows, &useColumns, pSet, &fillings); } if (Error != 0) { - strcpy(symbol->errtxt, "413: Data string to long"); + strcpy(symbol->errtxt, "413: Data string too long"); return Error; } /* Checksum */ Sum1=Sum2=0; if (rows>1) { - size_t charCur; + int charCur; for (charCur=0 ; charCur0) { /* ? Change character set */ - /* not at first possition (It was then the start set) */ - /* +++ special case for one-ligner */ + /* not at first position (It was then the start set) */ + /* +++ special case for one-liner */ if (emptyColumns + Copyright (C) 2009 - 2020 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -36,7 +36,6 @@ #include #include #endif -#include #include #include "common.h" @@ -684,7 +683,7 @@ static int plot_raster_default(struct zint_symbol *symbol, int rotate_angle, int if (is_extendable(symbol->symbology)) { /* For these symbols use dummy text to ensure formatting is done * properly even if no text is required */ - for (i = 0; i < ustrlen(symbol->text); i++) { + for (i = 0; i < (int) ustrlen(symbol->text); i++) { if (symbol->text[i] == '+') { local_text[i] = '+'; } else { @@ -769,7 +768,7 @@ static int plot_raster_default(struct zint_symbol *symbol, int rotate_angle, int r = 0; /* Isolate add-on text */ if (is_extendable(symbol->symbology)) { - for (i = 0; i < ustrlen(local_text); i++) { + for (i = 0; i < (int) ustrlen(local_text); i++) { if (latch == 1) { addon[r] = local_text[i]; r++; @@ -1069,7 +1068,8 @@ static int plot_raster_default(struct zint_symbol *symbol, int rotate_angle, int } } else { for (r = 1; r < symbol->rows; r++) { - draw_bar(pixelbuf, (xoffset + 11) * 2 , (symbol->width - 25) * 2, ((r * row_height) + textoffset + yoffset - 1) * 2, 2 * 2, image_width, image_height); + /* Avoid 11-module start and stop chars */ + draw_bar(pixelbuf, (xoffset + 11) * 2 , (symbol->width - 22) * 2, ((r * row_height) + textoffset + yoffset - 1) * 2, 2 * 2, image_width, image_height); } } } diff --git a/backend/tests/CMakeLists.txt b/backend/tests/CMakeLists.txt index b397a172..a6858590 100644 --- a/backend/tests/CMakeLists.txt +++ b/backend/tests/CMakeLists.txt @@ -71,11 +71,13 @@ zint_add_test(library, test_library) zint_add_test(mailmark, test_mailmark) zint_add_test(maxicode, test_maxicode) zint_add_test(pdf417, test_pdf417) +zint_add_test(png, test_png) zint_add_test(postal, test_postal) zint_add_test(qr, test_qr) zint_add_test(raster, test_raster) zint_add_test(rss, test_rss) zint_add_test(sjis, test_sjis) +zint_add_test(svg, test_svg) zint_add_test(telepen, test_telepen) zint_add_test(upcean, test_upcean) zint_add_test(vector, test_vector) diff --git a/backend/tests/data/png/codablockf_3rows.png b/backend/tests/data/png/codablockf_3rows.png new file mode 100644 index 00000000..d2b19184 Binary files /dev/null and b/backend/tests/data/png/codablockf_3rows.png differ diff --git a/backend/tests/data/png/code128_aim.png b/backend/tests/data/png/code128_aim.png new file mode 100644 index 00000000..41b9d0bc Binary files /dev/null and b/backend/tests/data/png/code128_aim.png differ diff --git a/backend/tests/data/svg/codablockf_3rows.svg b/backend/tests/data/svg/codablockf_3rows.svg new file mode 100644 index 00000000..bb4c4da1 --- /dev/null +++ b/backend/tests/data/svg/codablockf_3rows.svg @@ -0,0 +1,63 @@ + + + + Zint Generated Symbol + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/backend/tests/data/svg/code128_amperands.svg b/backend/tests/data/svg/code128_amperands.svg new file mode 100644 index 00000000..0c5e1212 --- /dev/null +++ b/backend/tests/data/svg/code128_amperands.svg @@ -0,0 +1,41 @@ + + + + Zint Generated Symbol + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <>"&' + + + diff --git a/backend/tests/test_codablock.c b/backend/tests/test_codablock.c index a9503895..c0eeeaa1 100644 --- a/backend/tests/test_codablock.c +++ b/backend/tests/test_codablock.c @@ -1,6 +1,6 @@ /* libzint - the open source barcode library - Copyright (C) 2008-2019 Robin Stuart + Copyright (C) 2008 - 2020 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -29,6 +29,8 @@ */ /* vim: set ts=4 sw=4 et : */ +//#define TEST_ENCODE_GENERATE_EXPECTED 1 + #include "testcommon.h" static void test_options(void) @@ -69,6 +71,105 @@ static void test_options(void) testFinish(); } +static void test_encode(void) +{ + testStart(""); + + int ret; + struct item { + int input_mode; + int option_1; + int option_2; + unsigned char* data; + int ret; + + int expected_rows; + int expected_width; + char* comment; + char* expected; + }; + struct item data[] = { + /* 0*/ { UNICODE_MODE, -1, -1, "AIM", 0, 1, 68, "Same as CODE128", + "11010010000101000110001100010001010111011000101110110001100011101011" + }, + /* 1*/ { UNICODE_MODE, -1, -1, "AAAAAAAAA", 0, 4, 90, "", + "110100001001011110111010010000110101000110001010001100010100011000110010001001100011101011" + "110100001001011110111011000100100101000110001010001100010100011000100100110001100011101011" + "110100001001011110111010110011100101000110001010001100010100011000100010011001100011101011" + "110100001001011101111010111011000101111011101001011000010010011110111001001101100011101011" + }, + /* 2*/ { UNICODE_MODE, 3, -1, "AAAAAAAAA", 0, 3, 101, "Verified manually against tec-it (bwipp differs)", + "11010000100101111011101001011000010100011000101000110001010001100010100011000110110011001100011101011" + "11010000100101111011101100010010010100011000101000110001010001100010100011000111101000101100011101011" + "11010000100101111011101011001110010100011000101110111101100110110011001110010110001001001100011101011" + }, + /* 3*/ { UNICODE_MODE, -1, -1, "AAAAAAAAAAAAAAA", 0, 6, 90, "", + "110100001001011110111010000100110101000110001010001100010100011000100110011101100011101011" + "110100001001011110111011000100100101000110001010001100010100011000100100110001100011101011" + "110100001001011110111010110011100101000110001010001100010100011000100010011001100011101011" + "110100001001011110111010011011100101000110001010001100010100011000100110001001100011101011" + "110100001001011110111010011001110101000110001010001100010100011000110010010001100011101011" + "110100001001011101111010001110110101111011101000110001010111101000110111101101100011101011" + }, + /* 4*/ { UNICODE_MODE, -1, 14, "AAAAAAAAAAAAAAA", 0, 2, 156, "", + "110100001001011110111010100001100101000110001010001100010100011000101000110001010001100010100011000101000110001010001100010100011000110001000101100011101011" + "110100001001011110111011000100100101000110001010001100010100011000101000110001010001100010100011000101110111101110111101011011000110111000101101100011101011" + }, + /* 5*/ { UNICODE_MODE, 3, -1, "AAAAAAAAAAAAAAA", 0, 3, 123, "Differs from tec-it (and bwipp); TODO: verify", + "110100001001011110111010010110000101000110001010001100010100011000101000110001010001100010100011000101111001001100011101011" + "110100001001011110111011000100100101000110001010001100010100011000101000110001010001100010100011000110000101001100011101011" + "110100001001011110111010110011100101000110001010001100010100011000101110111101110111101011011000110110110001101100011101011" + }, + }; + int data_size = sizeof(data) / sizeof(struct item); + + char escaped[1024]; + + for (int i = 0; i < data_size; i++) { + + struct zint_symbol* symbol = ZBarcode_Create(); + assert_nonnull(symbol, "Symbol not created\n"); + + symbol->symbology = BARCODE_CODABLOCKF; + symbol->input_mode = data[i].input_mode; + 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 = ZINT_DEBUG_PRINT; + + 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 (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); + } + + testFinish(); +} + // #181 Christian Hartlage OSS-Fuzz static void test_fuzz(void) { @@ -109,6 +210,7 @@ static void test_fuzz(void) int main() { test_options(); + test_encode(); test_fuzz(); testReport(); diff --git a/backend/tests/test_png.c b/backend/tests/test_png.c new file mode 100644 index 00000000..412d9aa5 --- /dev/null +++ b/backend/tests/test_png.c @@ -0,0 +1,118 @@ +/* + libzint - the open source barcode library + Copyright (C) 2020 Robin Stuart + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the project nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + */ +/* vim: set ts=4 sw=4 et : */ + +#include "testcommon.h" +#include + +//#define TEST_PRINT_GENERATE_EXPECTED 1 + +static void test_print(void) +{ + testStart(""); + + int ret; + struct item { + int symbology; + int option_1; + int option_2; + unsigned char* data; + char* expected_file; + }; + struct item data[] = { + /* 0*/ { BARCODE_CODE128, -1, -1, "AIM", "../data/png/code128_aim.png" }, + /* 1*/ { BARCODE_CODABLOCKF, 3, -1, "AAAAAAAAA", "../data/png/codablockf_3rows.png" }, + }; + int data_size = sizeof(data) / sizeof(struct item); + + 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); + } + #endif + + for (int i = 0; i < data_size; i++) { + + 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; + } + if (data[i].option_2 != -1) { + symbol->option_2 = data[i].option_2; + } + + int length = strlen(data[i].data); + + 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); + + strcpy(symbol->outfile, png); + 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 + + printf(" /*%2d*/ { %s, \"%s\", \"%s\"},\n", i, testUtilBarcodeName(data[i].symbology), 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); + + ret = testUtilCmpPngs(symbol->outfile, data[i].expected_file); + assert_zero(ret, "i:%d %s testUtilCmpPngs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, data[i].expected_file, ret); + assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile); + + #endif + + ZBarcode_Delete(symbol); + } + + testFinish(); +} + +int main() +{ + test_print(); + + testReport(); + + return 0; +} diff --git a/backend/tests/test_svg.c b/backend/tests/test_svg.c new file mode 100644 index 00000000..0e13dbe2 --- /dev/null +++ b/backend/tests/test_svg.c @@ -0,0 +1,118 @@ +/* + libzint - the open source barcode library + Copyright (C) 2020 Robin Stuart + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the project nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + */ +/* vim: set ts=4 sw=4 et : */ + +#include "testcommon.h" +#include + +//#define TEST_PRINT_GENERATE_EXPECTED 1 + +static void test_print(void) +{ + testStart(""); + + int ret; + struct item { + int symbology; + int option_1; + int option_2; + unsigned char* data; + char* expected_file; + }; + struct item data[] = { + /* 0*/ { BARCODE_CODE128, -1, -1, "<>\"&'", "../data/svg/code128_amperands.svg" }, + /* 1*/ { BARCODE_CODABLOCKF, 3, -1, "AAAAAAAAA", "../data/svg/codablockf_3rows.svg" }, + }; + int data_size = sizeof(data) / sizeof(struct item); + + 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); + } + #endif + + for (int i = 0; i < data_size; i++) { + + 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; + } + if (data[i].option_2 != -1) { + symbol->option_2 = data[i].option_2; + } + + int length = strlen(data[i].data); + + 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); + + strcpy(symbol->outfile, svg); + 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 + + printf(" /*%2d*/ { %s, \"%s\", \"%s\"},\n", i, testUtilBarcodeName(data[i].symbology), 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); + + ret = testUtilCmpSvgs(symbol->outfile, data[i].expected_file); + assert_zero(ret, "i:%d %s testUtilCmpSvgs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, data[i].expected_file, ret); + assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile); + + #endif + + ZBarcode_Delete(symbol); + } + + testFinish(); +} + +int main() +{ + test_print(); + + testReport(); + + return 0; +} diff --git a/backend/tests/test_vector.c b/backend/tests/test_vector.c index b64e3fd3..fe092544 100644 --- a/backend/tests/test_vector.c +++ b/backend/tests/test_vector.c @@ -1,6 +1,6 @@ /* libzint - the open source barcode library - Copyright (C) 2008-2019 Robin Stuart + Copyright (C) 2008 - 2020 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -142,6 +142,7 @@ static void test_buffer_vector(void) /* 89*/ { BARCODE_CODEONE, "12345678901234567890", "", 22, 22, 22, 44.0, 44.0 }, /* 90*/ { BARCODE_GRIDMATRIX, "ABC", "", 18, 18, 18, 36.0, 36.0 }, /* 91*/ { BARCODE_UPNQR, "1234567890AB", "", 77, 77, 77, 154.0, 154.0 }, + /* 92*/ { BARCODE_RMQR, "12345", "", 11, 11, 27, 54.0, 22.0 }, }; int data_size = sizeof(data) / sizeof(struct item); diff --git a/backend/vector.c b/backend/vector.c index 228eddcb..92c64dee 100644 --- a/backend/vector.c +++ b/backend/vector.c @@ -32,7 +32,6 @@ #include #include -#include #include #ifdef _MSC_VER @@ -293,6 +292,9 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ int this_row; int addon_latch = 0; struct zint_vector_string *string; + + (void)rotate_angle; /* Not currently implemented */ + // Sanity check colours to_upper((unsigned char*) symbol->fgcolour); to_upper((unsigned char*) symbol->bgcolour); @@ -792,7 +794,8 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ rectangle = vector_plot_create_rect((float)xoffset, (r * row_height) + yoffset - 1, (float)symbol->width, 2.0f); vector_plot_add_rect(symbol, rectangle, &last_rectangle); } else { - rectangle = vector_plot_create_rect(xoffset + 11.0f, (r * row_height) + yoffset - 1, symbol->width - 25.0f, 2.0); + /* Avoid 11-module start and stop chars */ + rectangle = vector_plot_create_rect(xoffset + 11, (r * row_height) + yoffset - 1, symbol->width - 22, 2.0); vector_plot_add_rect(symbol, rectangle, &last_rectangle); } }