#209 suppress CodeQL warnings except CODEONE; simplifications AZTEC_RUNE, MICROPDF417

This commit is contained in:
gitlost 2020-12-23 10:57:24 +00:00
parent bee5f08f50
commit f62a678d0f
37 changed files with 619 additions and 576 deletions

View file

@ -48,8 +48,8 @@ static void test_large(int index, int debug) {
struct item data[] = {
/* 0*/ { BARCODE_C25STANDARD, "1", 80, 0, 1, 817 },
/* 1*/ { BARCODE_C25STANDARD, "1", 81, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 2*/ { BARCODE_C25INTER, "1", 89, 0, 1, 819 },
/* 3*/ { BARCODE_C25INTER, "1", 90, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 2*/ { BARCODE_C25INTER, "1", 90, 0, 1, 819 },
/* 3*/ { BARCODE_C25INTER, "1", 91, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 4*/ { BARCODE_C25IATA, "1", 45, 0, 1, 639 },
/* 5*/ { BARCODE_C25IATA, "1", 46, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 6*/ { BARCODE_C25LOGIC, "1", 80, 0, 1, 809 },

View file

@ -2022,6 +2022,9 @@ static void test_perf(int index, int debug) {
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ~~~~~~~~~~~~~~~~~~~~~~~~~ ?????????????????????????? 12345678901234567890123456 \377\377\377\377\377\377",
0, 113, 113, "1540 chars, 12-bit words, mixed" },
/* 4*/ { BARCODE_AZRUNE, -1, -1, -1,
"255",
0, 11, 11, "3 chars, AZRUNE" },
};
int data_size = ARRAY_SIZE(data);

View file

@ -32,7 +32,7 @@
#include "testcommon.h"
#include <sys/stat.h>
extern int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf);
INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf);
static void test_pixel_plot(int index, int debug) {

View file

@ -68,8 +68,9 @@ static void test_large(int index, int debug) {
/* 18*/ { BARCODE_VIN, -1, "1", 17, 0, 1, 246 },
/* 19*/ { BARCODE_VIN, -1, "1", 18, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 20*/ { BARCODE_VIN, -1, "1", 16, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 21*/ { BARCODE_HIBC_39, -1, "1", 66, 0, 1, 1119 }, // 68 - 2 ('+' and check digit)
/* 22*/ { BARCODE_HIBC_39, -1, "1", 67, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 21*/ { BARCODE_VIN, 1, "1", 17, 0, 1, 259 },
/* 22*/ { BARCODE_HIBC_39, -1, "1", 66, 0, 1, 1119 }, // 68 - 2 ('+' and check digit)
/* 23*/ { BARCODE_HIBC_39, -1, "1", 67, ZINT_ERROR_TOO_LONG, -1, -1 },
};
int data_size = ARRAY_SIZE(data);

View file

@ -31,7 +31,7 @@
#include "testcommon.h"
extern int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf);
INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf);
static void test_pixel_plot(int index, int debug) {

View file

@ -189,6 +189,8 @@ static void test_encode(int index, int generate, int debug) {
testStart("");
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise
int ret;
struct item {
int symbology;
@ -202,34 +204,39 @@ static void test_encode(int index, int generate, int debug) {
char *expected;
};
struct item data[] = {
/* 0*/ { BARCODE_MSI_PLESSEY, -1, "1234567890", 0, 1, 127, "Verified manually against bwipp and tec-it",
/* 0*/ { BARCODE_MSI_PLESSEY, -1, "1234567890", 0, 1, 127, "Verified manually against tec-it",
"1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001"
},
/* 1*/ { BARCODE_MSI_PLESSEY, 1, "1234567890", 0, 1, 139, "Verified manually against bwipp and tec-it",
/* 1*/ { BARCODE_MSI_PLESSEY, 1, "1234567890", 0, 1, 139, "Verified manually against tec-it",
"1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001001101101001"
},
/* 2*/ { BARCODE_MSI_PLESSEY, 2, "1234567890", 0, 1, 151, "Verified manually against bwipp and tec-it",
/* 2*/ { BARCODE_MSI_PLESSEY, 2, "1234567890", 0, 1, 151, "Verified manually against tec-it",
"1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001001101101001001001101001"
},
/* 3*/ { BARCODE_MSI_PLESSEY, 3, "1234567890", 0, 1, 139, "Verified manually against bwipp",
/* 3*/ { BARCODE_MSI_PLESSEY, 3, "1234567890", 0, 1, 139, "",
"1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001001101101001"
},
/* 4*/ { BARCODE_MSI_PLESSEY, 4, "1234567890", 0, 1, 151, "Verified manually against bwipp",
/* 4*/ { BARCODE_MSI_PLESSEY, 4, "1234567890", 0, 1, 151, "",
"1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001001101101001001001101001"
},
/* 5*/ { BARCODE_MSI_PLESSEY, 3, "2211", 0, 1, 79, "Produces mod-11 '10' check digit; verified manually against bwipp (badmod11)",
/* 5*/ { BARCODE_MSI_PLESSEY, 3, "2211", 0, 1, 79, "Produces mod-11 '10' check digit; BWIPP (badmod11)",
"1101001001101001001001101001001001001101001001001101001001001101001001001001001"
},
/* 6*/ { BARCODE_MSI_PLESSEY, 4, "2211", 0, 1, 91, "Verified manually against bwipp (badmod11)",
/* 6*/ { BARCODE_MSI_PLESSEY, 4, "2211", 0, 1, 91, "BWIPP (badmod11)",
"1101001001101001001001101001001001001101001001001101001001001101001001001001001001001001001"
},
/* 7*/ { BARCODE_PLESSEY, -1, "0123456789ABCDEF", 0, 1, 323, "Verified manually against bwipp",
/* 7*/ { BARCODE_PLESSEY, -1, "0123456789ABCDEF", 0, 1, 323, "",
"11101110100011101000100010001000111010001000100010001110100010001110111010001000100010001110100011101000111010001000111011101000111011101110100010001000100011101110100010001110100011101000111011101110100011101000100011101110111010001110111010001110111011101110111011101110111010001000111010001000100010001110001000101110111"
},
/* 8*/ { BARCODE_MSI_PLESSEY, 4, "999999999999999999", 0, 1, 247, "Max value; #209 check buffer not overrun",
"1101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001001001001001101001"
},
};
int data_size = ARRAY_SIZE(data);
char escaped[1024];
char bwipp_buf[4096];
char bwipp_msg[1024];
for (int i = 0; i < data_size; i++) {
@ -254,10 +261,17 @@ static void test_encode(int index, int generate, int debug) {
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);
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 (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) {
ret = testUtilBwipp(i, symbol, -1, data[i].option_2, -1, data[i].data, length, NULL, bwipp_buf, sizeof(bwipp_buf));
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, bwipp_msg, bwipp_buf, data[i].expected);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, bwipp_msg, bwipp_buf, data[i].expected);
}
}
}

View file

@ -32,7 +32,7 @@
#include "testcommon.h"
#include <sys/stat.h>
extern int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf);
INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf);
static void test_pixel_plot(int index, int debug) {

View file

@ -2025,6 +2025,74 @@ static void test_microqr_encode(int index, int generate, int debug) {
testFinish();
}
// Not a real test, just performance indicator
static void test_microqr_perf(int index, int debug) {
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
int ret;
struct item {
int symbology;
int input_mode;
int option_1;
int option_2;
char *data;
int ret;
int expected_rows;
int expected_width;
char *comment;
};
struct item data[] = {
/* 0*/ { BARCODE_MICROQR, UNICODE_MODE, 1, 1, "12345", 0, 11, 11, "Max 5 numbers, M1" },
/* 1*/ { BARCODE_MICROQR, UNICODE_MODE, 1, 2, "1234567890", 0, 13, 13, "Max 10 numbers, M2-L" },
/* 2*/ { BARCODE_MICROQR, UNICODE_MODE, 1, 3, "123456789012345", 0, 15, 15, "Max 15 numbers, M3-L" },
/* 3*/ { BARCODE_MICROQR, UNICODE_MODE, 1, 4, "12345678901234567890123456789012345", 0, 17, 17, "Max 35 numbers, M4-L" },
};
int data_size = ARRAY_SIZE(data);
clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer;
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
diff_encode = diff_buffer = 0;
for (int j = 0; j < TEST_PERF_ITERATIONS; j++) {
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
start = clock();
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
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);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
ZBarcode_Delete(symbol);
}
printf("%s: diff_encode %gms, diff_buffer %gms\n", data[i].comment, diff_encode * 1000.0 / CLOCKS_PER_SEC, diff_buffer * 1000.0 / CLOCKS_PER_SEC);
total_encode += diff_encode;
total_buffer += diff_buffer;
}
if (index != -1) {
printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
}
}
static void test_upnqr_input(int index, int generate, int debug) {
testStart("");
@ -2674,6 +2742,7 @@ int main(int argc, char *argv[]) {
{ "test_microqr_padding", test_microqr_padding, 1, 1, 1 },
{ "test_microqr_optimize", test_microqr_optimize, 1, 1, 1 },
{ "test_microqr_encode", test_microqr_encode, 1, 1, 1 },
{ "test_microqr_perf", test_microqr_perf, 1, 0, 1 },
{ "test_upnqr_input", test_upnqr_input, 1, 1, 1 },
{ "test_upnqr_encode", test_upnqr_encode, 1, 1, 1 },

View file

@ -31,7 +31,7 @@
#include "testcommon.h"
extern int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf);
INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf);
// For overview when debugging: ./test_tiff -f pixel_plot -d 5
static void test_pixel_plot(int index, int debug) {

View file

@ -29,6 +29,7 @@ run_bwipp_test "test_gs1" "gs1_reduce"
run_bwipp_test "test_imail" "encode"
run_bwipp_test "test_medical" "encode"
run_bwipp_test "test_pdf417" "encode"
run_bwipp_test "test_plessey" "encode"
run_bwipp_test "test_postal" "encode"
run_bwipp_test "test_rss"
run_bwipp_test "test_telepen" "encode"