diff --git a/backend/gridmtx.c b/backend/gridmtx.c index a91a7253..627057d3 100644 --- a/backend/gridmtx.c +++ b/backend/gridmtx.c @@ -230,6 +230,8 @@ static void define_mode(char* mode, const unsigned int gbdata[], const size_t le /* Add the length indicator for byte encoded blocks */ static void add_byte_count(char binary[], const size_t byte_count_posn, const int byte_count) { + /* AIMD014 6.3.7: "Let L be the number of bytes of input data to be encoded in the 8-bit binary data set. + * First output (L-1) as a 9-bit binary prefix to record the number of bytes..." */ bin_append_posn(byte_count - 1, 9, binary, byte_count_posn); } diff --git a/backend/pcx.c b/backend/pcx.c index e7b91d2d..22bd3bdd 100644 --- a/backend/pcx.c +++ b/backend/pcx.c @@ -1,8 +1,9 @@ /* pcx.c - Handles output to ZSoft PCX file */ +/* ZSoft PCX File Format Technical Reference Manual http://bespin.org/~qz/pc-gpe/pcx.txt */ /* libzint - the open source barcode library - Copyright (C) 2009-2017 Robin Stuart + 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 @@ -32,7 +33,6 @@ /* vim: set ts=4 sw=4 et : */ #include -#include #include #include "common.h" #include "pcx.h" /* PCX header structure */ @@ -43,24 +43,26 @@ #include #endif -#define SSET "0123456789ABCDEF" - INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) { int fgred, fggrn, fgblu, bgred, bggrn, bgblu; int row, column, i, colour; int run_count; FILE *pcx_file; pcx_header_t header; + int bytes_per_line = symbol->bitmap_width + (symbol->bitmap_width & 1); // Must be even + unsigned char previous; #ifdef _MSC_VER unsigned char* rle_row; #endif #ifndef _MSC_VER - unsigned char rle_row[symbol->bitmap_width]; + unsigned char rle_row[bytes_per_line]; #else - rle_row = (unsigned char *) _alloca((symbol->bitmap_width * 6) * sizeof (unsigned char)); + rle_row = (unsigned char *) _alloca(bytes_per_line); #endif /* _MSC_VER */ + rle_row[bytes_per_line - 1] = 0; // Will remain zero if bitmap_width odd + fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]); fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]); @@ -87,11 +89,7 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) { header.reserved = 0; header.number_of_planes = 3; - if (symbol->bitmap_width % 2) { - header.bytes_per_line = symbol->bitmap_width + 1; - } else { - header.bytes_per_line = symbol->bitmap_width; - } + header.bytes_per_line = bytes_per_line; header.palette_info = 1; // Colour header.horiz_screen_size = 0; @@ -192,23 +190,29 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, char *pixelbuf) { } } + /* Based on ImageMagick/coders/pcx.c PCXWritePixels() + * Copyright 1999-2020 ImageMagick Studio LLC */ + previous = rle_row[0]; run_count = 1; - for (column = 1; column < symbol->bitmap_width; column++) { - if ((rle_row[column - 1] == rle_row[column]) && (run_count < 63)) { + for (column = 1; column < bytes_per_line; column++) { // Note going up to bytes_per_line + if ((previous == rle_row[column]) && (run_count < 63)) { run_count++; } else { - run_count += 0xc0; - fputc(run_count, pcx_file); - fputc(rle_row[column - 1], pcx_file); + if (run_count > 1 || (previous & 0xc0) == 0xc0) { + run_count += 0xc0; + fputc(run_count, pcx_file); + } + fputc(previous, pcx_file); + previous = rle_row[column]; run_count = 1; } } - if (run_count > 1) { + if (run_count > 1 || (previous & 0xc0) == 0xc0) { run_count += 0xc0; fputc(run_count, pcx_file); - fputc(rle_row[column - 1], pcx_file); } + fputc(previous, pcx_file); } } diff --git a/backend/tests/CMakeLists.txt b/backend/tests/CMakeLists.txt index 2d408e1a..e4dee5d0 100644 --- a/backend/tests/CMakeLists.txt +++ b/backend/tests/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2019 Robin Stuart +# Copyright (C) 2019 - 2020 Robin Stuart # Adapted from qrencode/tests/CMakeLists.txt # Copyright (C) 2006-2017 Kentaro Fukuchi @@ -70,6 +70,7 @@ zint_add_test(imail, test_imail) zint_add_test(library, test_library) zint_add_test(mailmark, test_mailmark) zint_add_test(maxicode, test_maxicode) +zint_add_test(pcx, test_pcx) zint_add_test(pdf417, test_pdf417) zint_add_test(png, test_png) zint_add_test(postal, test_postal) diff --git a/backend/tests/data/print/emf/code128_aim.emf b/backend/tests/data/print/emf/code128_aim.emf index f1aa5a16..18e06e11 100644 Binary files a/backend/tests/data/print/emf/code128_aim.emf and b/backend/tests/data/print/emf/code128_aim.emf differ diff --git a/backend/tests/data/print/emf/dotcode_aim_fig7.emf b/backend/tests/data/print/emf/dotcode_aim_fig7.emf index a836388f..b687e6d5 100644 Binary files a/backend/tests/data/print/emf/dotcode_aim_fig7.emf and b/backend/tests/data/print/emf/dotcode_aim_fig7.emf differ diff --git a/backend/tests/data/print/emf/qr_v1_m.emf b/backend/tests/data/print/emf/qr_v1_m.emf index ab2e90c6..443e51e5 100644 Binary files a/backend/tests/data/print/emf/qr_v1_m.emf and b/backend/tests/data/print/emf/qr_v1_m.emf differ diff --git a/backend/tests/data/print/pcx/code128_aim.pcx b/backend/tests/data/print/pcx/code128_aim.pcx index 0050e1ea..d26466d4 100644 Binary files a/backend/tests/data/print/pcx/code128_aim.pcx and b/backend/tests/data/print/pcx/code128_aim.pcx differ diff --git a/backend/tests/data/print/pcx/dotcode_aim_fig7.pcx b/backend/tests/data/print/pcx/dotcode_aim_fig7.pcx index dc3efc8e..9fa0bfe6 100644 Binary files a/backend/tests/data/print/pcx/dotcode_aim_fig7.pcx and b/backend/tests/data/print/pcx/dotcode_aim_fig7.pcx differ diff --git a/backend/tests/test_gb18030.c b/backend/tests/test_gb18030.c index 4ffb3d29..5492694e 100644 --- a/backend/tests/test_gb18030.c +++ b/backend/tests/test_gb18030.c @@ -188,14 +188,14 @@ static void test_gb18030_utf8tomb(void) for (int i = 0; i < data_size; i++) { - int length = data[i].length == -1 ? strlen(data[i].data) : data[i].length; + int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; size_t ret_length = length; ret = gb18030_utf8tomb(&symbol, data[i].data, &ret_length, gbdata); assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol.errtxt); if (ret == 0) { assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %zu != %zu\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < ret_length; j++) { + for (int j = 0; j < (int) ret_length; j++) { assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] 0x%04X != 0x%04X\n", i, j, gbdata[j], data[i].expected_gbdata[j]); } } @@ -261,14 +261,14 @@ static void test_gb18030_utf8tosb(void) for (int i = 0; i < data_size; i++) { - int length = data[i].length == -1 ? strlen(data[i].data) : data[i].length; + int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; size_t ret_length = length; ret = gb18030_utf8tosb(data[i].eci, data[i].data, &ret_length, gbdata, data[i].full_multibyte); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %zu != %zu\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < ret_length; j++) { + for (int j = 0; j < (int) ret_length; j++) { assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] %04X != %04X\n", i, j, gbdata[j], data[i].expected_gbdata[j]); } } @@ -311,12 +311,12 @@ static void test_gb18030_cpy(void) for (int i = 0; i < data_size; i++) { - int length = data[i].length == -1 ? strlen(data[i].data) : data[i].length; + int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; size_t ret_length = length; gb18030_cpy(data[i].data, &ret_length, gbdata, data[i].full_multibyte); assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %zu != %zu\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < ret_length; j++) { + for (int j = 0; j < (int) ret_length; j++) { assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] %04X != %04X\n", i, j, gbdata[j], data[i].expected_gbdata[j]); } } diff --git a/backend/tests/test_gb2312.c b/backend/tests/test_gb2312.c index f1797aa4..b731fcc3 100644 --- a/backend/tests/test_gb2312.c +++ b/backend/tests/test_gb2312.c @@ -129,14 +129,14 @@ static void test_gb2312_utf8tomb(void) for (int i = 0; i < data_size; i++) { - int length = data[i].length == -1 ? strlen(data[i].data) : data[i].length; + int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; size_t ret_length = length; ret = gb2312_utf8tomb(&symbol, data[i].data, &ret_length, gbdata); assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol.errtxt); if (ret == 0) { assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %zu != %zu\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < ret_length; j++) { + for (int j = 0; j < (int) ret_length; j++) { assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] %04X != %04X\n", i, j, gbdata[j], data[i].expected_gbdata[j]); } } @@ -200,14 +200,14 @@ static void test_gb2312_utf8tosb(void) for (int i = 0; i < data_size; i++) { - int length = data[i].length == -1 ? strlen(data[i].data) : data[i].length; + int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; size_t ret_length = length; ret = gb2312_utf8tosb(data[i].eci, data[i].data, &ret_length, gbdata, data[i].full_multibyte); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %zu != %zu\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < ret_length; j++) { + for (int j = 0; j < (int) ret_length; j++) { assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] %04X != %04X\n", i, j, gbdata[j], data[i].expected_gbdata[j]); } } @@ -250,12 +250,12 @@ static void test_gb2312_cpy(void) for (int i = 0; i < data_size; i++) { - int length = data[i].length == -1 ? strlen(data[i].data) : data[i].length; + int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; size_t ret_length = length; gb2312_cpy(data[i].data, &ret_length, gbdata, data[i].full_multibyte); assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %zu != %zu\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < ret_length; j++) { + for (int j = 0; j < (int) ret_length; j++) { assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] %04X != %04X\n", i, j, gbdata[j], data[i].expected_gbdata[j]); } } diff --git a/backend/tests/test_hanxin.c b/backend/tests/test_hanxin.c index b318cec4..04c8e1b4 100644 --- a/backend/tests/test_hanxin.c +++ b/backend/tests/test_hanxin.c @@ -173,7 +173,7 @@ static void test_input(void) } symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = data[i].length == -1 ? strlen(data[i].data) : data[i].length; + 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); diff --git a/backend/tests/test_pcx.c b/backend/tests/test_pcx.c new file mode 100644 index 00000000..061e5c64 --- /dev/null +++ b/backend/tests/test_pcx.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" + +static void test_pcx(void) +{ + testStart(""); + + if (system("identify --version > /dev/null") != 0) { + printf("SKIPPED. ImageMagick identify not available\n"); + testFinish(); + return; + } + + int ret; + struct item { + int symbology; + int option_1; + int option_2; + char* fgcolour; + char* bgcolour; + float scale; + unsigned char* data; + }; + // s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) + struct item data[] = { + /* 0*/ { BARCODE_CODE128, -1, -1, NULL, NULL, 0, "AIM" }, + /* 1*/ { BARCODE_QRCODE, 2, 1, NULL, NULL, 0, "1234567890" }, + /* 2*/ { BARCODE_DOTCODE, -1, -1, NULL, NULL, 0, "2741" }, + /* 3*/ { BARCODE_MAXICODE, -1, -1, NULL, NULL, 0, "1" }, + /* 4*/ { BARCODE_GRIDMATRIX, -1, -1, NULL, NULL, 0.75, "Grid Matrix" }, + /* 5*/ { BARCODE_CODABLOCKF, -1, 20, "FFFFFF", "000000", 0, "1234567890123456789012345678901234567890" }, + /* 6*/ { BARCODE_CODE128, -1, -1, "C3C3C3", NULL, 0, "AIM" }, + /* 7*/ { BARCODE_QRCODE, 2, 1, NULL, "D2E3F4", 0, "1234567890" }, + /* 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); + + 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; + } + 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; + } + + 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); + + 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 = 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); + + ZBarcode_Delete(symbol); + } + + testFinish(); +} + +int main() +{ + test_pcx(); + + testReport(); + + return 0; +} diff --git a/backend/tests/test_print.c b/backend/tests/test_print.c index d92f899e..78c8f81f 100644 --- a/backend/tests/test_print.c +++ b/backend/tests/test_print.c @@ -32,7 +32,9 @@ #include "testcommon.h" #include -//#define TEST_PRINT_GENERATE_EXPECTED 1 +//#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 "" static void test_print(void) { @@ -47,112 +49,114 @@ static void test_print(void) char* expected_file; }; struct item data[] = { - /* 0*/ { BARCODE_CODE128, -1, -1, "AIM", "code128_aim"}, - /* 1*/ { BARCODE_QRCODE, 2, 1, "1234567890", "qr_v1_m"}, - /* 2*/ { BARCODE_DOTCODE, -1, -1, "2741", "dotcode_aim_fig7"}, + /* 0*/ { BARCODE_CODE128, -1, -1, "AIM", "code128_aim" }, + /* 1*/ { BARCODE_QRCODE, 2, 1, "1234567890", "qr_v1_m" }, + /* 2*/ { BARCODE_DOTCODE, -1, -1, "2741", "dotcode_aim_fig7" }, }; int data_size = sizeof(data) / sizeof(struct item); - char* exts[] = { "bmp", "emf", "eps", "gif", "pcx", "png", "svg", "tif", "txt" }; - int exts_len = sizeof(exts) / sizeof(char*); + char* exts[] = { "bmp", "emf", "eps", "gif", "pcx", "png", "svg", "tif", "txt" }; + int exts_len = sizeof(exts) / sizeof(char*); - char data_dir[1024]; - char expected_file[1024]; + char data_dir[1024]; + char expected_file[1024]; char escaped[1024]; int escaped_size = 1024; #ifdef TEST_PRINT_GENERATE_EXPECTED - strcpy(data_dir, "../data"); + 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"); + 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]); + 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); - } - #endif + #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++) { + for (int i = 0; i < data_size; i++) { - struct zint_symbol* symbol = ZBarcode_Create(); - assert_nonnull(symbol, "Symbol not created\n"); + 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; - } + 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); + 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); + 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, "out."); - strcat(symbol->outfile, exts[j]); + strcpy(symbol->outfile, "out."); + strcat(symbol->outfile, exts[j]); - strcpy(expected_file, data_dir); - strcat(expected_file, "/"); - strcat(expected_file, data[i].expected_file); - strcat(expected_file, "."); - strcat(expected_file, exts[j]); + strcpy(expected_file, data_dir); + strcat(expected_file, "/"); + strcat(expected_file, data[i].expected_file); + strcat(expected_file, "."); + strcat(expected_file, exts[j]); - 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); + 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 + #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); - } - 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 (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 + #else - assert_nonzero(testUtilExists(symbol->outfile), "i:%d j:%d %s testUtilExists(%s) == 0\n", i, j, exts[j], symbol->outfile); + 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); - } + 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 + #endif - ZBarcode_Delete(symbol); - } - } + ZBarcode_Delete(symbol); + } + } testFinish(); } diff --git a/backend/tests/test_sjis.c b/backend/tests/test_sjis.c index d78be088..72bbe3f0 100644 --- a/backend/tests/test_sjis.c +++ b/backend/tests/test_sjis.c @@ -147,14 +147,14 @@ static void test_sjis_utf8tomb(void) for (int i = 0; i < data_size; i++) { - int length = data[i].length == -1 ? strlen(data[i].data) : data[i].length; + int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; size_t ret_length = length; ret = sjis_utf8tomb(&symbol, data[i].data, &ret_length, jisdata); assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol.errtxt); if (ret == 0) { assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %zu != %zu\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < ret_length; j++) { + for (int j = 0; j < (int) ret_length; j++) { assert_equal(jisdata[j], data[i].expected_jisdata[j], "i:%d jisdata[%d] %04X != %04X\n", i, j, jisdata[j], data[i].expected_jisdata[j]); } } @@ -211,14 +211,14 @@ static void test_sjis_utf8tosb(void) for (int i = 0; i < data_size; i++) { - int length = data[i].length == -1 ? strlen(data[i].data) : data[i].length; + int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; size_t ret_length = length; ret = sjis_utf8tosb(data[i].eci, data[i].data, &ret_length, jisdata, data[i].full_multibyte); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %zu != %zu\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < ret_length; j++) { + for (int j = 0; j < (int) ret_length; j++) { assert_equal(jisdata[j], data[i].expected_jisdata[j], "i:%d jisdata[%d] %04X != %04X\n", i, j, jisdata[j], data[i].expected_jisdata[j]); } } @@ -260,12 +260,12 @@ static void test_sjis_cpy(void) for (int i = 0; i < data_size; i++) { - int length = data[i].length == -1 ? strlen(data[i].data) : data[i].length; + int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; size_t ret_length = length; sjis_cpy(data[i].data, &ret_length, jisdata, data[i].full_multibyte); assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %zu != %zu\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < ret_length; j++) { + for (int j = 0; j < (int) ret_length; j++) { assert_equal(jisdata[j], data[i].expected_jisdata[j], "i:%d jisdata[%d] %04X != %04X\n", i, j, jisdata[j], data[i].expected_jisdata[j]); } }