From 129fa81c41bd2ee7fbc9737aaf9afa3fb2bcc314 Mon Sep 17 00:00:00 2001 From: gitlost Date: Mon, 6 Apr 2020 21:26:13 +0100 Subject: [PATCH] Fix PCX issue with odd bitmap width; tests; comment GRIDMATRIX byte count --- backend/gridmtx.c | 2 + backend/pcx.c | 40 ++--- backend/tests/CMakeLists.txt | 3 +- backend/tests/data/print/emf/code128_aim.emf | Bin 916 -> 916 bytes .../tests/data/print/emf/dotcode_aim_fig7.emf | Bin 1180 -> 1180 bytes backend/tests/data/print/emf/qr_v1_m.emf | Bin 2212 -> 2212 bytes backend/tests/data/print/pcx/code128_aim.pcx | Bin 23132 -> 23012 bytes .../tests/data/print/pcx/dotcode_aim_fig7.pcx | Bin 698 -> 668 bytes backend/tests/test_gb18030.c | 12 +- backend/tests/test_gb2312.c | 12 +- backend/tests/test_hanxin.c | 2 +- backend/tests/test_pcx.c | 118 ++++++++++++++ backend/tests/test_print.c | 146 +++++++++--------- backend/tests/test_sjis.c | 12 +- 14 files changed, 238 insertions(+), 109 deletions(-) create mode 100644 backend/tests/test_pcx.c 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 f1aa5a167af54d24eeee3e0c3ea4f67b957d4d5c..18e06e11567b7c2e7962a626eba4e9c96c4ec9be 100644 GIT binary patch delta 80 zcmbQjK81ZkhUWkO{~6dA7#P%nSOSQdfEWfq;%Y!F1H@btCpPmk0vW16%mWgbtjMU$ O$OI&XH%BnqFaZGkM+(UR delta 80 zcmbQjK81Zkh9(0LumQ0;5K90t6A**I|NsBN;%Y#)3=lI3@l2ip^9+1FfMMh;t NMj$D?IfBuK2>`Q73cCOR diff --git a/backend/tests/data/print/emf/dotcode_aim_fig7.emf b/backend/tests/data/print/emf/dotcode_aim_fig7.emf index a836388f3a40eb644a187aced61f58c1733fbe5c..b687e6d5eb0f44ab9822992eb9423898cdd1725d 100644 GIT binary patch delta 74 zcmbQkIfrvXhUWkO{~6dA7#P%nSOSQdfEWfq;%Y!F1H@btCra}&0vW16%mWtKsm#c< I@$P`0D9yLIsgCw diff --git a/backend/tests/data/print/emf/qr_v1_m.emf b/backend/tests/data/print/emf/qr_v1_m.emf index ab2e90c6437c16486c9d2a8abb5b3950d4128381..443e51e5ba19d5b909eb7b51058ad2e759578213 100644 GIT binary patch delta 74 zcmZ1?xI}P5hUWkO{~6dA7#P%nSOSQdfEWfq;%Y!F1H@btCrWcN0vW16%rn`MNqFK3 M5k{tscaO6J0M}RyPXGV_ delta 74 zcmZ1?xI}P5h9(0LumQ0;5K90t6A**I|NsBN;%Y#)3=lI3kUd#B3?W2vo{G4faBEKhAb=PWO_+NNkrd)9k7>se0QSbWpk zH|sJ#Epy6z^0s6I5mm%Yvp_5m3-HszloWv?Py~uV5hwyhuwP)mVDSJ&pa>L!B2Wa1 zKoRmS5DUZtvp_5m3%Uoa5v&oc5pV%6zy-LVtD=9CZ~-pB1-Jkg-~wEL3%Unz0WQD= zxBwU60$k8l(S89gzy-Jf7vKV1fD3Rz_W&-y1-Jkg-~wEL3%V-WFTe%302kl_T!0I3 z0WRnszy-Jf7vKV1fD7)&1ufDsFPpAEar)%g4&}4ON15Ay_3su(+m=Hs`_mz}HM-np znok477?+NlP4Sd9pLA}kuJ<-h>6rc5J#!rId###{f7&0(P*=b6;=t>ct#j%2`+osv C^A|?| literal 23132 zcmeI)VM@d>5QgC_B8X?%>v;yfR%3S&k5q*?v)$0{A87><;VGm|r%6g?)A`Wm zhZ4tgc`C=l@sRml$K6ZWUuk*6SZb?fjPw>M^XE2RQ|4z|ZRdEF_Pp=;yw7~v#-gRQ zZ`OH!n#Yv!L!B2Wa1V7aphM8u;7t{<5=65N(ghjf34lc9dyzhHn4=F*KEVyIY@zuzj=w)rK>2emKyTTJDjst z(NX>-Bdm-kaG*ZMxbHY4a&@VODhsD?qd-k5AbioJ0(zQbNUu+s_@~1gXyB*J>Z2QB n2<1LIPXwpBb)q-Th^cdA&9vT~a;E?Lp2oopO1FPdebug = 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]); } }