diff --git a/backend/library.c b/backend/library.c index bbb1c243..e356a099 100644 --- a/backend/library.c +++ b/backend/library.c @@ -210,9 +210,8 @@ STATIC_UNLESS_ZINT_TEST int error_tag(char error_string[100], int error_number) if (error_number != 0) { const char *fmt = error_number >= ZINT_ERROR ? "Error %.93s" : "Warning %.91s"; /* Truncate if too long */ char error_buffer[100]; - strcpy(error_buffer, error_string); - - sprintf(error_string, fmt, error_buffer); + sprintf(error_buffer, fmt, error_string); + strcpy(error_string, error_buffer); } return error_number; diff --git a/backend/raster.c b/backend/raster.c index a4f0c44e..0ccb2859 100644 --- a/backend/raster.c +++ b/backend/raster.c @@ -455,10 +455,7 @@ static void draw_circle(unsigned char *pixelbuf, const int image_width, const in const int y_squared = y * y; for (x = -radius_i; x <= radius_i; x++) { if ((x * x) + y_squared <= radius_squared) { - if ((y + y0 >= 0) && (y + y0 < image_height) - && (x + x0 >= 0) && (x + x0 < image_width)) { - *(pixelbuf + ((y + y0) * image_width) + (x + x0)) = fill; - } + draw_pt(pixelbuf, image_width, image_height, x0 + x, y0 + y, fill); } } } @@ -800,33 +797,34 @@ static int plot_raster_dotty(struct zint_symbol *symbol, const int rotate_angle, int scale_width, scale_height; int error_number = 0; float xoffset, yoffset, roffset, boffset; - float dot_overspill; - float dotoffset; - float dotradius_scaled; - int dot_overspill_scaled; + float dot_offset_scaled; + float dot_radius_scaled; + int dot_radius_scaled_i; + int dot_overspill_scaled_i; if (scaler < 2.0f) { scaler = 2.0f; } - - symbol->height = symbol->rows; // This is true because only 2d matrix symbols are processed here + dot_radius_scaled = (symbol->dot_size * scaler) / 2.0f; + dot_radius_scaled_i = (int) floorf(dot_radius_scaled); output_set_whitespace_offsets(symbol, &xoffset, &yoffset, &roffset, &boffset); - dot_overspill = symbol->dot_size - 1.0f; /* Allow for exceeding 1X */ - if (dot_overspill < 0.0f) { - dotoffset = -dot_overspill / 2.0f; - dot_overspill_scaled = 0; - } else { - dotoffset = 0.0f; - dot_overspill_scaled = dot_overspill * scaler; + /* TODO: Revisit this overspill stuff, it's hacky */ + if (symbol->dot_size < 1.0f) { + dot_overspill_scaled_i = 0; + /* Offset (1 - dot_size) / 2 + dot_radius == (1 - dot_size + dot_size) / 2 == 1 / 2 */ + dot_offset_scaled = scaler / 2.0f; + } else { /* Allow for exceeding 1X */ + dot_overspill_scaled_i = (int) ceilf((symbol->dot_size - 1.0f) * scaler); + dot_offset_scaled = dot_radius_scaled; } - if (dot_overspill_scaled == 0) { - dot_overspill_scaled = 1; + if (dot_overspill_scaled_i == 0) { + dot_overspill_scaled_i = 1; } - scale_width = (symbol->width + xoffset + roffset) * scaler + dot_overspill_scaled; - scale_height = (symbol->height + yoffset + boffset) * scaler + dot_overspill_scaled; + scale_width = (int) floorf((symbol->width + xoffset + roffset) * scaler + dot_overspill_scaled_i); + scale_height = (int) floorf((symbol->height + yoffset + boffset) * scaler + dot_overspill_scaled_i); /* Apply scale options by creating another pixel buffer */ if (!(scaled_pixelbuf = (unsigned char *) malloc((size_t) scale_width * scale_height))) { @@ -836,21 +834,18 @@ static int plot_raster_dotty(struct zint_symbol *symbol, const int rotate_angle, memset(scaled_pixelbuf, DEFAULT_PAPER, (size_t) scale_width * scale_height); /* Plot the body of the symbol to the pixel buffer */ - dotradius_scaled = (symbol->dot_size * scaler) / 2.0f; for (r = 0; r < symbol->rows; r++) { - float row_scaled = (r + dotoffset + yoffset) * scaler + dotradius_scaled; + int row_scaled = (int) floorf((r + yoffset) * scaler + dot_offset_scaled); for (i = 0; i < symbol->width; i++) { if (module_is_set(symbol, r, i)) { draw_circle(scaled_pixelbuf, scale_width, scale_height, - (int) floorf((i + dotoffset + xoffset) * scaler + dotradius_scaled), - (int) floorf(row_scaled), - (int) floorf(dotradius_scaled), - DEFAULT_INK); + (int) floorf((i + xoffset) * scaler + dot_offset_scaled), + row_scaled, dot_radius_scaled_i, DEFAULT_INK); } } } - draw_bind_box(symbol, scaled_pixelbuf, xoffset, roffset, 0 /*textoffset*/, dot_overspill_scaled, + draw_bind_box(symbol, scaled_pixelbuf, xoffset, roffset, 0 /*textoffset*/, dot_overspill_scaled_i, scale_width, scale_height, (int) floorf(scaler)); error_number = save_raster_image_to_file(symbol, scale_height, scale_width, scaled_pixelbuf, rotate_angle, diff --git a/backend/tests/data/eps/dotcode_1.0.eps b/backend/tests/data/eps/dotcode_1.0.eps new file mode 100644 index 00000000..96eac8b1 --- /dev/null +++ b/backend/tests/data/eps/dotcode_1.0.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 22 16 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +16.00 0.00 TB 0.00 22.00 TR +TE +0.00 0.00 0.00 setrgbcolor +1.00 15.00 0.80 TD +9.00 15.00 0.80 TD +13.00 15.00 0.80 TD +17.00 15.00 0.80 TD +21.00 15.00 0.80 TD +7.00 13.00 0.80 TD +11.00 13.00 0.80 TD +15.00 13.00 0.80 TD +1.00 11.00 0.80 TD +5.00 11.00 0.80 TD +13.00 11.00 0.80 TD +17.00 11.00 0.80 TD +21.00 11.00 0.80 TD +3.00 9.00 0.80 TD +1.00 7.00 0.80 TD +21.00 7.00 0.80 TD +3.00 5.00 0.80 TD +7.00 5.00 0.80 TD +11.00 5.00 0.80 TD +15.00 5.00 0.80 TD +1.00 3.00 0.80 TD +5.00 3.00 0.80 TD +17.00 3.00 0.80 TD +21.00 3.00 0.80 TD +3.00 1.00 0.80 TD +7.00 1.00 0.80 TD +15.00 1.00 0.80 TD +19.00 1.00 0.80 TD diff --git a/backend/tests/data/eps/dotcode_1.0_ds0.1.eps b/backend/tests/data/eps/dotcode_1.0_ds0.1.eps new file mode 100644 index 00000000..3e501953 --- /dev/null +++ b/backend/tests/data/eps/dotcode_1.0_ds0.1.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 22 16 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +16.00 0.00 TB 0.00 22.00 TR +TE +0.00 0.00 0.00 setrgbcolor +1.00 15.00 0.10 TD +9.00 15.00 0.10 TD +13.00 15.00 0.10 TD +17.00 15.00 0.10 TD +21.00 15.00 0.10 TD +7.00 13.00 0.10 TD +11.00 13.00 0.10 TD +15.00 13.00 0.10 TD +1.00 11.00 0.10 TD +5.00 11.00 0.10 TD +13.00 11.00 0.10 TD +17.00 11.00 0.10 TD +21.00 11.00 0.10 TD +3.00 9.00 0.10 TD +1.00 7.00 0.10 TD +21.00 7.00 0.10 TD +3.00 5.00 0.10 TD +7.00 5.00 0.10 TD +11.00 5.00 0.10 TD +15.00 5.00 0.10 TD +1.00 3.00 0.10 TD +5.00 3.00 0.10 TD +17.00 3.00 0.10 TD +21.00 3.00 0.10 TD +3.00 1.00 0.10 TD +7.00 1.00 0.10 TD +15.00 1.00 0.10 TD +19.00 1.00 0.10 TD diff --git a/backend/tests/data/eps/dotcode_1.0_ds1.1.eps b/backend/tests/data/eps/dotcode_1.0_ds1.1.eps new file mode 100644 index 00000000..428fc2f8 --- /dev/null +++ b/backend/tests/data/eps/dotcode_1.0_ds1.1.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 23 17 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +16.40 0.00 TB 0.00 22.40 TR +TE +0.00 0.00 0.00 setrgbcolor +1.20 15.20 1.10 TD +9.20 15.20 1.10 TD +13.20 15.20 1.10 TD +17.20 15.20 1.10 TD +21.20 15.20 1.10 TD +7.20 13.20 1.10 TD +11.20 13.20 1.10 TD +15.20 13.20 1.10 TD +1.20 11.20 1.10 TD +5.20 11.20 1.10 TD +13.20 11.20 1.10 TD +17.20 11.20 1.10 TD +21.20 11.20 1.10 TD +3.20 9.20 1.10 TD +1.20 7.20 1.10 TD +21.20 7.20 1.10 TD +3.20 5.20 1.10 TD +7.20 5.20 1.10 TD +11.20 5.20 1.10 TD +15.20 5.20 1.10 TD +1.20 3.20 1.10 TD +5.20 3.20 1.10 TD +17.20 3.20 1.10 TD +21.20 3.20 1.10 TD +3.20 1.20 1.10 TD +7.20 1.20 1.10 TD +15.20 1.20 1.10 TD +19.20 1.20 1.10 TD diff --git a/backend/tests/data/eps/dotcode_1.5.eps b/backend/tests/data/eps/dotcode_1.5.eps new file mode 100644 index 00000000..33adeb32 --- /dev/null +++ b/backend/tests/data/eps/dotcode_1.5.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 33 24 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +24.00 0.00 TB 0.00 33.00 TR +TE +0.00 0.00 0.00 setrgbcolor +1.50 22.50 1.20 TD +13.50 22.50 1.20 TD +19.50 22.50 1.20 TD +25.50 22.50 1.20 TD +31.50 22.50 1.20 TD +10.50 19.50 1.20 TD +16.50 19.50 1.20 TD +22.50 19.50 1.20 TD +1.50 16.50 1.20 TD +7.50 16.50 1.20 TD +19.50 16.50 1.20 TD +25.50 16.50 1.20 TD +31.50 16.50 1.20 TD +4.50 13.50 1.20 TD +1.50 10.50 1.20 TD +31.50 10.50 1.20 TD +4.50 7.50 1.20 TD +10.50 7.50 1.20 TD +16.50 7.50 1.20 TD +22.50 7.50 1.20 TD +1.50 4.50 1.20 TD +7.50 4.50 1.20 TD +25.50 4.50 1.20 TD +31.50 4.50 1.20 TD +4.50 1.50 1.20 TD +10.50 1.50 1.20 TD +22.50 1.50 1.20 TD +28.50 1.50 1.20 TD diff --git a/backend/tests/data/eps/dotcode_1.5_ds0.4.eps b/backend/tests/data/eps/dotcode_1.5_ds0.4.eps new file mode 100644 index 00000000..7e7668fd --- /dev/null +++ b/backend/tests/data/eps/dotcode_1.5_ds0.4.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 33 24 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +24.00 0.00 TB 0.00 33.00 TR +TE +0.00 0.00 0.00 setrgbcolor +1.50 22.50 0.60 TD +13.50 22.50 0.60 TD +19.50 22.50 0.60 TD +25.50 22.50 0.60 TD +31.50 22.50 0.60 TD +10.50 19.50 0.60 TD +16.50 19.50 0.60 TD +22.50 19.50 0.60 TD +1.50 16.50 0.60 TD +7.50 16.50 0.60 TD +19.50 16.50 0.60 TD +25.50 16.50 0.60 TD +31.50 16.50 0.60 TD +4.50 13.50 0.60 TD +1.50 10.50 0.60 TD +31.50 10.50 0.60 TD +4.50 7.50 0.60 TD +10.50 7.50 0.60 TD +16.50 7.50 0.60 TD +22.50 7.50 0.60 TD +1.50 4.50 0.60 TD +7.50 4.50 0.60 TD +25.50 4.50 0.60 TD +31.50 4.50 0.60 TD +4.50 1.50 0.60 TD +10.50 1.50 0.60 TD +22.50 1.50 0.60 TD +28.50 1.50 0.60 TD diff --git a/backend/tests/data/eps/dotcode_1.5_ds1.1.eps b/backend/tests/data/eps/dotcode_1.5_ds1.1.eps new file mode 100644 index 00000000..048e954a --- /dev/null +++ b/backend/tests/data/eps/dotcode_1.5_ds1.1.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 34 25 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +24.60 0.00 TB 0.00 33.60 TR +TE +0.00 0.00 0.00 setrgbcolor +1.80 22.80 1.65 TD +13.80 22.80 1.65 TD +19.80 22.80 1.65 TD +25.80 22.80 1.65 TD +31.80 22.80 1.65 TD +10.80 19.80 1.65 TD +16.80 19.80 1.65 TD +22.80 19.80 1.65 TD +1.80 16.80 1.65 TD +7.80 16.80 1.65 TD +19.80 16.80 1.65 TD +25.80 16.80 1.65 TD +31.80 16.80 1.65 TD +4.80 13.80 1.65 TD +1.80 10.80 1.65 TD +31.80 10.80 1.65 TD +4.80 7.80 1.65 TD +10.80 7.80 1.65 TD +16.80 7.80 1.65 TD +22.80 7.80 1.65 TD +1.80 4.80 1.65 TD +7.80 4.80 1.65 TD +25.80 4.80 1.65 TD +31.80 4.80 1.65 TD +4.80 1.80 1.65 TD +10.80 1.80 1.65 TD +22.80 1.80 1.65 TD +28.80 1.80 1.65 TD diff --git a/backend/tests/data/eps/dotcode_1.5_ds2.1.eps b/backend/tests/data/eps/dotcode_1.5_ds2.1.eps new file mode 100644 index 00000000..7a3c0e54 --- /dev/null +++ b/backend/tests/data/eps/dotcode_1.5_ds2.1.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 37 28 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +27.60 0.00 TB 0.00 36.60 TR +TE +0.00 0.00 0.00 setrgbcolor +3.30 24.30 3.15 TD +15.30 24.30 3.15 TD +21.30 24.30 3.15 TD +27.30 24.30 3.15 TD +33.30 24.30 3.15 TD +12.30 21.30 3.15 TD +18.30 21.30 3.15 TD +24.30 21.30 3.15 TD +3.30 18.30 3.15 TD +9.30 18.30 3.15 TD +21.30 18.30 3.15 TD +27.30 18.30 3.15 TD +33.30 18.30 3.15 TD +6.30 15.30 3.15 TD +3.30 12.30 3.15 TD +33.30 12.30 3.15 TD +6.30 9.30 3.15 TD +12.30 9.30 3.15 TD +18.30 9.30 3.15 TD +24.30 9.30 3.15 TD +3.30 6.30 3.15 TD +9.30 6.30 3.15 TD +27.30 6.30 3.15 TD +33.30 6.30 3.15 TD +6.30 3.30 3.15 TD +12.30 3.30 3.15 TD +24.30 3.30 3.15 TD +30.30 3.30 3.15 TD diff --git a/backend/tests/data/eps/dotcode_2.0.eps b/backend/tests/data/eps/dotcode_2.0.eps new file mode 100644 index 00000000..b3792d55 --- /dev/null +++ b/backend/tests/data/eps/dotcode_2.0.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 44 32 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +32.00 0.00 TB 0.00 44.00 TR +TE +0.00 0.00 0.00 setrgbcolor +2.00 30.00 1.60 TD +18.00 30.00 1.60 TD +26.00 30.00 1.60 TD +34.00 30.00 1.60 TD +42.00 30.00 1.60 TD +14.00 26.00 1.60 TD +22.00 26.00 1.60 TD +30.00 26.00 1.60 TD +2.00 22.00 1.60 TD +10.00 22.00 1.60 TD +26.00 22.00 1.60 TD +34.00 22.00 1.60 TD +42.00 22.00 1.60 TD +6.00 18.00 1.60 TD +2.00 14.00 1.60 TD +42.00 14.00 1.60 TD +6.00 10.00 1.60 TD +14.00 10.00 1.60 TD +22.00 10.00 1.60 TD +30.00 10.00 1.60 TD +2.00 6.00 1.60 TD +10.00 6.00 1.60 TD +34.00 6.00 1.60 TD +42.00 6.00 1.60 TD +6.00 2.00 1.60 TD +14.00 2.00 1.60 TD +30.00 2.00 1.60 TD +38.00 2.00 1.60 TD diff --git a/backend/tests/data/eps/dotcode_2.0_ds0.9.eps b/backend/tests/data/eps/dotcode_2.0_ds0.9.eps new file mode 100644 index 00000000..5124bcaf --- /dev/null +++ b/backend/tests/data/eps/dotcode_2.0_ds0.9.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 44 32 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +32.00 0.00 TB 0.00 44.00 TR +TE +0.00 0.00 0.00 setrgbcolor +2.00 30.00 1.80 TD +18.00 30.00 1.80 TD +26.00 30.00 1.80 TD +34.00 30.00 1.80 TD +42.00 30.00 1.80 TD +14.00 26.00 1.80 TD +22.00 26.00 1.80 TD +30.00 26.00 1.80 TD +2.00 22.00 1.80 TD +10.00 22.00 1.80 TD +26.00 22.00 1.80 TD +34.00 22.00 1.80 TD +42.00 22.00 1.80 TD +6.00 18.00 1.80 TD +2.00 14.00 1.80 TD +42.00 14.00 1.80 TD +6.00 10.00 1.80 TD +14.00 10.00 1.80 TD +22.00 10.00 1.80 TD +30.00 10.00 1.80 TD +2.00 6.00 1.80 TD +10.00 6.00 1.80 TD +34.00 6.00 1.80 TD +42.00 6.00 1.80 TD +6.00 2.00 1.80 TD +14.00 2.00 1.80 TD +30.00 2.00 1.80 TD +38.00 2.00 1.80 TD diff --git a/backend/tests/data/eps/dotcode_2.0_ds1.1.eps b/backend/tests/data/eps/dotcode_2.0_ds1.1.eps new file mode 100644 index 00000000..0a640d68 --- /dev/null +++ b/backend/tests/data/eps/dotcode_2.0_ds1.1.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 45 33 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +32.80 0.00 TB 0.00 44.80 TR +TE +0.00 0.00 0.00 setrgbcolor +2.40 30.40 2.20 TD +18.40 30.40 2.20 TD +26.40 30.40 2.20 TD +34.40 30.40 2.20 TD +42.40 30.40 2.20 TD +14.40 26.40 2.20 TD +22.40 26.40 2.20 TD +30.40 26.40 2.20 TD +2.40 22.40 2.20 TD +10.40 22.40 2.20 TD +26.40 22.40 2.20 TD +34.40 22.40 2.20 TD +42.40 22.40 2.20 TD +6.40 18.40 2.20 TD +2.40 14.40 2.20 TD +42.40 14.40 2.20 TD +6.40 10.40 2.20 TD +14.40 10.40 2.20 TD +22.40 10.40 2.20 TD +30.40 10.40 2.20 TD +2.40 6.40 2.20 TD +10.40 6.40 2.20 TD +34.40 6.40 2.20 TD +42.40 6.40 2.20 TD +6.40 2.40 2.20 TD +14.40 2.40 2.20 TD +30.40 2.40 2.20 TD +38.40 2.40 2.20 TD diff --git a/backend/tests/data/eps/dotcode_3.0.eps b/backend/tests/data/eps/dotcode_3.0.eps new file mode 100644 index 00000000..8c3a9d73 --- /dev/null +++ b/backend/tests/data/eps/dotcode_3.0.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 66 48 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +48.00 0.00 TB 0.00 66.00 TR +TE +0.00 0.00 0.00 setrgbcolor +3.00 45.00 2.40 TD +27.00 45.00 2.40 TD +39.00 45.00 2.40 TD +51.00 45.00 2.40 TD +63.00 45.00 2.40 TD +21.00 39.00 2.40 TD +33.00 39.00 2.40 TD +45.00 39.00 2.40 TD +3.00 33.00 2.40 TD +15.00 33.00 2.40 TD +39.00 33.00 2.40 TD +51.00 33.00 2.40 TD +63.00 33.00 2.40 TD +9.00 27.00 2.40 TD +3.00 21.00 2.40 TD +63.00 21.00 2.40 TD +9.00 15.00 2.40 TD +21.00 15.00 2.40 TD +33.00 15.00 2.40 TD +45.00 15.00 2.40 TD +3.00 9.00 2.40 TD +15.00 9.00 2.40 TD +51.00 9.00 2.40 TD +63.00 9.00 2.40 TD +9.00 3.00 2.40 TD +21.00 3.00 2.40 TD +45.00 3.00 2.40 TD +57.00 3.00 2.40 TD diff --git a/backend/tests/data/eps/dotcode_3.0_ds0.4.eps b/backend/tests/data/eps/dotcode_3.0_ds0.4.eps new file mode 100644 index 00000000..760c1380 --- /dev/null +++ b/backend/tests/data/eps/dotcode_3.0_ds0.4.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 66 48 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +48.00 0.00 TB 0.00 66.00 TR +TE +0.00 0.00 0.00 setrgbcolor +3.00 45.00 1.20 TD +27.00 45.00 1.20 TD +39.00 45.00 1.20 TD +51.00 45.00 1.20 TD +63.00 45.00 1.20 TD +21.00 39.00 1.20 TD +33.00 39.00 1.20 TD +45.00 39.00 1.20 TD +3.00 33.00 1.20 TD +15.00 33.00 1.20 TD +39.00 33.00 1.20 TD +51.00 33.00 1.20 TD +63.00 33.00 1.20 TD +9.00 27.00 1.20 TD +3.00 21.00 1.20 TD +63.00 21.00 1.20 TD +9.00 15.00 1.20 TD +21.00 15.00 1.20 TD +33.00 15.00 1.20 TD +45.00 15.00 1.20 TD +3.00 9.00 1.20 TD +15.00 9.00 1.20 TD +51.00 9.00 1.20 TD +63.00 9.00 1.20 TD +9.00 3.00 1.20 TD +21.00 3.00 1.20 TD +45.00 3.00 1.20 TD +57.00 3.00 1.20 TD diff --git a/backend/tests/data/eps/dotcode_3.0_ds1.1.eps b/backend/tests/data/eps/dotcode_3.0_ds1.1.eps new file mode 100644 index 00000000..4f0fc43e --- /dev/null +++ b/backend/tests/data/eps/dotcode_3.0_ds1.1.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 68 50 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +49.20 0.00 TB 0.00 67.20 TR +TE +0.00 0.00 0.00 setrgbcolor +3.60 45.60 3.30 TD +27.60 45.60 3.30 TD +39.60 45.60 3.30 TD +51.60 45.60 3.30 TD +63.60 45.60 3.30 TD +21.60 39.60 3.30 TD +33.60 39.60 3.30 TD +45.60 39.60 3.30 TD +3.60 33.60 3.30 TD +15.60 33.60 3.30 TD +39.60 33.60 3.30 TD +51.60 33.60 3.30 TD +63.60 33.60 3.30 TD +9.60 27.60 3.30 TD +3.60 21.60 3.30 TD +63.60 21.60 3.30 TD +9.60 15.60 3.30 TD +21.60 15.60 3.30 TD +33.60 15.60 3.30 TD +45.60 15.60 3.30 TD +3.60 9.60 3.30 TD +15.60 9.60 3.30 TD +51.60 9.60 3.30 TD +63.60 9.60 3.30 TD +9.60 3.60 3.30 TD +21.60 3.60 3.30 TD +45.60 3.60 3.30 TD +57.60 3.60 3.30 TD diff --git a/backend/tests/data/eps/dotcode_3.5.eps b/backend/tests/data/eps/dotcode_3.5.eps new file mode 100644 index 00000000..6ada2860 --- /dev/null +++ b/backend/tests/data/eps/dotcode_3.5.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 77 56 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +56.00 0.00 TB 0.00 77.00 TR +TE +0.00 0.00 0.00 setrgbcolor +3.50 52.50 2.80 TD +31.50 52.50 2.80 TD +45.50 52.50 2.80 TD +59.50 52.50 2.80 TD +73.50 52.50 2.80 TD +24.50 45.50 2.80 TD +38.50 45.50 2.80 TD +52.50 45.50 2.80 TD +3.50 38.50 2.80 TD +17.50 38.50 2.80 TD +45.50 38.50 2.80 TD +59.50 38.50 2.80 TD +73.50 38.50 2.80 TD +10.50 31.50 2.80 TD +3.50 24.50 2.80 TD +73.50 24.50 2.80 TD +10.50 17.50 2.80 TD +24.50 17.50 2.80 TD +38.50 17.50 2.80 TD +52.50 17.50 2.80 TD +3.50 10.50 2.80 TD +17.50 10.50 2.80 TD +59.50 10.50 2.80 TD +73.50 10.50 2.80 TD +10.50 3.50 2.80 TD +24.50 3.50 2.80 TD +52.50 3.50 2.80 TD +66.50 3.50 2.80 TD diff --git a/backend/tests/data/eps/dotcode_3.5_ds0.4.eps b/backend/tests/data/eps/dotcode_3.5_ds0.4.eps new file mode 100644 index 00000000..d0a42f49 --- /dev/null +++ b/backend/tests/data/eps/dotcode_3.5_ds0.4.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 77 56 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +56.00 0.00 TB 0.00 77.00 TR +TE +0.00 0.00 0.00 setrgbcolor +3.50 52.50 1.40 TD +31.50 52.50 1.40 TD +45.50 52.50 1.40 TD +59.50 52.50 1.40 TD +73.50 52.50 1.40 TD +24.50 45.50 1.40 TD +38.50 45.50 1.40 TD +52.50 45.50 1.40 TD +3.50 38.50 1.40 TD +17.50 38.50 1.40 TD +45.50 38.50 1.40 TD +59.50 38.50 1.40 TD +73.50 38.50 1.40 TD +10.50 31.50 1.40 TD +3.50 24.50 1.40 TD +73.50 24.50 1.40 TD +10.50 17.50 1.40 TD +24.50 17.50 1.40 TD +38.50 17.50 1.40 TD +52.50 17.50 1.40 TD +3.50 10.50 1.40 TD +17.50 10.50 1.40 TD +59.50 10.50 1.40 TD +73.50 10.50 1.40 TD +10.50 3.50 1.40 TD +24.50 3.50 1.40 TD +52.50 3.50 1.40 TD +66.50 3.50 1.40 TD diff --git a/backend/tests/data/eps/dotcode_3.5_ds1.1.eps b/backend/tests/data/eps/dotcode_3.5_ds1.1.eps new file mode 100644 index 00000000..e5a9ac2d --- /dev/null +++ b/backend/tests/data/eps/dotcode_3.5_ds1.1.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 79 58 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +57.40 0.00 TB 0.00 78.40 TR +TE +0.00 0.00 0.00 setrgbcolor +4.20 53.20 3.85 TD +32.20 53.20 3.85 TD +46.20 53.20 3.85 TD +60.20 53.20 3.85 TD +74.20 53.20 3.85 TD +25.20 46.20 3.85 TD +39.20 46.20 3.85 TD +53.20 46.20 3.85 TD +4.20 39.20 3.85 TD +18.20 39.20 3.85 TD +46.20 39.20 3.85 TD +60.20 39.20 3.85 TD +74.20 39.20 3.85 TD +11.20 32.20 3.85 TD +4.20 25.20 3.85 TD +74.20 25.20 3.85 TD +11.20 18.20 3.85 TD +25.20 18.20 3.85 TD +39.20 18.20 3.85 TD +53.20 18.20 3.85 TD +4.20 11.20 3.85 TD +18.20 11.20 3.85 TD +60.20 11.20 3.85 TD +74.20 11.20 3.85 TD +11.20 4.20 3.85 TD +25.20 4.20 3.85 TD +53.20 4.20 3.85 TD +67.20 4.20 3.85 TD diff --git a/backend/tests/data/eps/dotcode_5.0.eps b/backend/tests/data/eps/dotcode_5.0.eps new file mode 100644 index 00000000..e9047e04 --- /dev/null +++ b/backend/tests/data/eps/dotcode_5.0.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 110 80 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +80.00 0.00 TB 0.00 110.00 TR +TE +0.00 0.00 0.00 setrgbcolor +5.00 75.00 4.00 TD +45.00 75.00 4.00 TD +65.00 75.00 4.00 TD +85.00 75.00 4.00 TD +105.00 75.00 4.00 TD +35.00 65.00 4.00 TD +55.00 65.00 4.00 TD +75.00 65.00 4.00 TD +5.00 55.00 4.00 TD +25.00 55.00 4.00 TD +65.00 55.00 4.00 TD +85.00 55.00 4.00 TD +105.00 55.00 4.00 TD +15.00 45.00 4.00 TD +5.00 35.00 4.00 TD +105.00 35.00 4.00 TD +15.00 25.00 4.00 TD +35.00 25.00 4.00 TD +55.00 25.00 4.00 TD +75.00 25.00 4.00 TD +5.00 15.00 4.00 TD +25.00 15.00 4.00 TD +85.00 15.00 4.00 TD +105.00 15.00 4.00 TD +15.00 5.00 4.00 TD +35.00 5.00 4.00 TD +75.00 5.00 4.00 TD +95.00 5.00 4.00 TD diff --git a/backend/tests/data/eps/dotcode_5.0_ds0.2.eps b/backend/tests/data/eps/dotcode_5.0_ds0.2.eps new file mode 100644 index 00000000..8e9f9286 --- /dev/null +++ b/backend/tests/data/eps/dotcode_5.0_ds0.2.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 110 80 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +80.00 0.00 TB 0.00 110.00 TR +TE +0.00 0.00 0.00 setrgbcolor +5.00 75.00 1.00 TD +45.00 75.00 1.00 TD +65.00 75.00 1.00 TD +85.00 75.00 1.00 TD +105.00 75.00 1.00 TD +35.00 65.00 1.00 TD +55.00 65.00 1.00 TD +75.00 65.00 1.00 TD +5.00 55.00 1.00 TD +25.00 55.00 1.00 TD +65.00 55.00 1.00 TD +85.00 55.00 1.00 TD +105.00 55.00 1.00 TD +15.00 45.00 1.00 TD +5.00 35.00 1.00 TD +105.00 35.00 1.00 TD +15.00 25.00 1.00 TD +35.00 25.00 1.00 TD +55.00 25.00 1.00 TD +75.00 25.00 1.00 TD +5.00 15.00 1.00 TD +25.00 15.00 1.00 TD +85.00 15.00 1.00 TD +105.00 15.00 1.00 TD +15.00 5.00 1.00 TD +35.00 5.00 1.00 TD +75.00 5.00 1.00 TD +95.00 5.00 1.00 TD diff --git a/backend/tests/data/eps/dotcode_5.0_ds1.1.eps b/backend/tests/data/eps/dotcode_5.0_ds1.1.eps new file mode 100644 index 00000000..bb998931 --- /dev/null +++ b/backend/tests/data/eps/dotcode_5.0_ds1.1.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 112 82 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +82.00 0.00 TB 0.00 112.00 TR +TE +0.00 0.00 0.00 setrgbcolor +6.00 76.00 5.50 TD +46.00 76.00 5.50 TD +66.00 76.00 5.50 TD +86.00 76.00 5.50 TD +106.00 76.00 5.50 TD +36.00 66.00 5.50 TD +56.00 66.00 5.50 TD +76.00 66.00 5.50 TD +6.00 56.00 5.50 TD +26.00 56.00 5.50 TD +66.00 56.00 5.50 TD +86.00 56.00 5.50 TD +106.00 56.00 5.50 TD +16.00 46.00 5.50 TD +6.00 36.00 5.50 TD +106.00 36.00 5.50 TD +16.00 26.00 5.50 TD +36.00 26.00 5.50 TD +56.00 26.00 5.50 TD +76.00 26.00 5.50 TD +6.00 16.00 5.50 TD +26.00 16.00 5.50 TD +86.00 16.00 5.50 TD +106.00 16.00 5.50 TD +16.00 6.00 5.50 TD +36.00 6.00 5.50 TD +76.00 6.00 5.50 TD +96.00 6.00 5.50 TD diff --git a/backend/tests/data/eps/dotcode_5.0_ds1.7.eps b/backend/tests/data/eps/dotcode_5.0_ds1.7.eps new file mode 100644 index 00000000..661db552 --- /dev/null +++ b/backend/tests/data/eps/dotcode_5.0_ds1.7.eps @@ -0,0 +1,45 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: Zint 2.9.1.9 +%%Title: Zint Generated Symbol +%%Pages: 0 +%%BoundingBox: 0 0 118 88 +%%EndComments +/TL { setlinewidth moveto lineto stroke } bind def +/TD { newpath 0 360 arc fill } bind def +/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def +/TB { 2 copy } bind def +/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def +/TE { pop pop } bind def +newpath +1.00 1.00 1.00 setrgbcolor +88.00 0.00 TB 0.00 118.00 TR +TE +0.00 0.00 0.00 setrgbcolor +9.00 79.00 8.50 TD +49.00 79.00 8.50 TD +69.00 79.00 8.50 TD +89.00 79.00 8.50 TD +109.00 79.00 8.50 TD +39.00 69.00 8.50 TD +59.00 69.00 8.50 TD +79.00 69.00 8.50 TD +9.00 59.00 8.50 TD +29.00 59.00 8.50 TD +69.00 59.00 8.50 TD +89.00 59.00 8.50 TD +109.00 59.00 8.50 TD +19.00 49.00 8.50 TD +9.00 39.00 8.50 TD +109.00 39.00 8.50 TD +19.00 29.00 8.50 TD +39.00 29.00 8.50 TD +59.00 29.00 8.50 TD +79.00 29.00 8.50 TD +9.00 19.00 8.50 TD +29.00 19.00 8.50 TD +89.00 19.00 8.50 TD +109.00 19.00 8.50 TD +19.00 9.00 8.50 TD +39.00 9.00 8.50 TD +79.00 9.00 8.50 TD +99.00 9.00 8.50 TD diff --git a/backend/tests/data/gif/dotcode_1.0.gif b/backend/tests/data/gif/dotcode_1.0.gif new file mode 100644 index 00000000..263069fc Binary files /dev/null and b/backend/tests/data/gif/dotcode_1.0.gif differ diff --git a/backend/tests/data/gif/dotcode_1.0_ds0.1.gif b/backend/tests/data/gif/dotcode_1.0_ds0.1.gif new file mode 100644 index 00000000..263069fc Binary files /dev/null and b/backend/tests/data/gif/dotcode_1.0_ds0.1.gif differ diff --git a/backend/tests/data/gif/dotcode_1.0_ds1.1.gif b/backend/tests/data/gif/dotcode_1.0_ds1.1.gif new file mode 100644 index 00000000..56d79eb4 Binary files /dev/null and b/backend/tests/data/gif/dotcode_1.0_ds1.1.gif differ diff --git a/backend/tests/data/gif/dotcode_1.5.gif b/backend/tests/data/gif/dotcode_1.5.gif new file mode 100644 index 00000000..5eaefbdb Binary files /dev/null and b/backend/tests/data/gif/dotcode_1.5.gif differ diff --git a/backend/tests/data/gif/dotcode_1.5_ds0.4.gif b/backend/tests/data/gif/dotcode_1.5_ds0.4.gif new file mode 100644 index 00000000..82ff18b5 Binary files /dev/null and b/backend/tests/data/gif/dotcode_1.5_ds0.4.gif differ diff --git a/backend/tests/data/gif/dotcode_1.5_ds1.1.gif b/backend/tests/data/gif/dotcode_1.5_ds1.1.gif new file mode 100644 index 00000000..5eaefbdb Binary files /dev/null and b/backend/tests/data/gif/dotcode_1.5_ds1.1.gif differ diff --git a/backend/tests/data/gif/dotcode_1.5_ds2.1.gif b/backend/tests/data/gif/dotcode_1.5_ds2.1.gif new file mode 100644 index 00000000..808e481d Binary files /dev/null and b/backend/tests/data/gif/dotcode_1.5_ds2.1.gif differ diff --git a/backend/tests/data/gif/dotcode_2.0.gif b/backend/tests/data/gif/dotcode_2.0.gif new file mode 100644 index 00000000..22c451dd Binary files /dev/null and b/backend/tests/data/gif/dotcode_2.0.gif differ diff --git a/backend/tests/data/gif/dotcode_2.0_ds0.9.gif b/backend/tests/data/gif/dotcode_2.0_ds0.9.gif new file mode 100644 index 00000000..22c451dd Binary files /dev/null and b/backend/tests/data/gif/dotcode_2.0_ds0.9.gif differ diff --git a/backend/tests/data/gif/dotcode_2.0_ds1.1.gif b/backend/tests/data/gif/dotcode_2.0_ds1.1.gif new file mode 100644 index 00000000..1f57e90b Binary files /dev/null and b/backend/tests/data/gif/dotcode_2.0_ds1.1.gif differ diff --git a/backend/tests/data/gif/dotcode_3.0.gif b/backend/tests/data/gif/dotcode_3.0.gif new file mode 100644 index 00000000..5b6acba4 Binary files /dev/null and b/backend/tests/data/gif/dotcode_3.0.gif differ diff --git a/backend/tests/data/gif/dotcode_3.0_ds0.4.gif b/backend/tests/data/gif/dotcode_3.0_ds0.4.gif new file mode 100644 index 00000000..35a9790d Binary files /dev/null and b/backend/tests/data/gif/dotcode_3.0_ds0.4.gif differ diff --git a/backend/tests/data/gif/dotcode_3.0_ds1.1.gif b/backend/tests/data/gif/dotcode_3.0_ds1.1.gif new file mode 100644 index 00000000..8283c192 Binary files /dev/null and b/backend/tests/data/gif/dotcode_3.0_ds1.1.gif differ diff --git a/backend/tests/data/gif/dotcode_3.5.gif b/backend/tests/data/gif/dotcode_3.5.gif new file mode 100644 index 00000000..d03f23b5 Binary files /dev/null and b/backend/tests/data/gif/dotcode_3.5.gif differ diff --git a/backend/tests/data/gif/dotcode_3.5_ds0.4.gif b/backend/tests/data/gif/dotcode_3.5_ds0.4.gif new file mode 100644 index 00000000..65cded9b Binary files /dev/null and b/backend/tests/data/gif/dotcode_3.5_ds0.4.gif differ diff --git a/backend/tests/data/gif/dotcode_3.5_ds1.1.gif b/backend/tests/data/gif/dotcode_3.5_ds1.1.gif new file mode 100644 index 00000000..373c4128 Binary files /dev/null and b/backend/tests/data/gif/dotcode_3.5_ds1.1.gif differ diff --git a/backend/tests/data/gif/dotcode_5.0.gif b/backend/tests/data/gif/dotcode_5.0.gif new file mode 100644 index 00000000..2fa8a803 Binary files /dev/null and b/backend/tests/data/gif/dotcode_5.0.gif differ diff --git a/backend/tests/data/gif/dotcode_5.0_ds0.2.gif b/backend/tests/data/gif/dotcode_5.0_ds0.2.gif new file mode 100644 index 00000000..ab9a8f23 Binary files /dev/null and b/backend/tests/data/gif/dotcode_5.0_ds0.2.gif differ diff --git a/backend/tests/data/gif/dotcode_5.0_ds1.1.gif b/backend/tests/data/gif/dotcode_5.0_ds1.1.gif new file mode 100644 index 00000000..d4bd2d17 Binary files /dev/null and b/backend/tests/data/gif/dotcode_5.0_ds1.1.gif differ diff --git a/backend/tests/data/gif/dotcode_5.0_ds1.7.gif b/backend/tests/data/gif/dotcode_5.0_ds1.7.gif new file mode 100644 index 00000000..faa69848 Binary files /dev/null and b/backend/tests/data/gif/dotcode_5.0_ds1.7.gif differ diff --git a/backend/tests/test_2of5.c b/backend/tests/test_2of5.c index 743179f9..1b56a437 100644 --- a/backend/tests/test_2of5.c +++ b/backend/tests/test_2of5.c @@ -33,9 +33,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int option_2; @@ -75,20 +72,24 @@ static void test_large(int index, int debug) { /* 25*/ { BARCODE_ITF14, -1, "1", 14, ZINT_ERROR_TOO_LONG, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[4096]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -106,9 +107,6 @@ static void test_large(int index, int debug) { static void test_hrt(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int option_2; @@ -143,15 +141,19 @@ static void test_hrt(int index, int debug) { /* 23*/ { BARCODE_ITF14, -1, "1234567890123", "12345678901231" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_hrt"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt); @@ -166,9 +168,6 @@ static void test_hrt(int index, int debug) { static void test_input(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -188,15 +187,19 @@ static void test_input(int index, int debug) { /* 7*/ { BARCODE_ITF14, "A", ZINT_ERROR_INVALID_DATA, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -214,11 +217,6 @@ static void test_input(int index, int debug) { 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; int option_2; @@ -301,15 +299,21 @@ static void test_encode(int index, int generate, int debug) { char escaped[1024]; char bwipp_buf[4096]; char bwipp_msg[1024]; + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -322,10 +326,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); diff --git a/backend/tests/test_auspost.c b/backend/tests/test_auspost.c index 9c089fb5..f3fb7203 100644 --- a/backend/tests/test_auspost.c +++ b/backend/tests/test_auspost.c @@ -33,9 +33,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *pattern; @@ -64,20 +61,24 @@ static void test_large(int index, int debug) { /* 15*/ { BARCODE_AUSREDIRECT, "1", 9, ZINT_ERROR_TOO_LONG, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[64]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -95,9 +96,6 @@ static void test_large(int index, int debug) { static void test_hrt(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -109,15 +107,19 @@ static void test_hrt(int index, int debug) { /* 0*/ { BARCODE_AUSPOST, "12345678901234567890123", "" }, // None }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_hrt"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt); @@ -132,9 +134,6 @@ static void test_hrt(int index, int debug) { static void test_input(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -164,15 +163,19 @@ static void test_input(int index, int debug) { /* 17*/ { BARCODE_AUSPOST, "1234567", ZINT_ERROR_TOO_LONG, -1, -1 }, // No leading zeroes added }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -192,11 +195,6 @@ static void test_input(int index, int debug) { // https://auspost.com.au/content/dam/auspost_corp/media/documents/customer-barcode-technical-specifications-aug2012.pdf 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; char *data; @@ -250,19 +248,25 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -275,10 +279,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); @@ -302,9 +307,6 @@ static void test_encode(int index, int generate, int debug) { // #181 Christian Hartlage OSS-Fuzz static void test_fuzz(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -321,15 +323,19 @@ static void test_fuzz(int index, int debug) { /* 5*/ { BARCODE_AUSREDIRECT, "1\000\000\000", 4, ZINT_ERROR_INVALID_DATA }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_fuzz"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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_aztec.c b/backend/tests/test_aztec.c index ca87038a..7c494042 100644 --- a/backend/tests/test_aztec.c +++ b/backend/tests/test_aztec.c @@ -33,9 +33,6 @@ static void test_options(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int input_mode; @@ -64,15 +61,19 @@ static void test_options(int index, int debug) { /* 11*/ { BARCODE_AZTEC, -1, READER_INIT, -1, 2, "A", 0, 19, 19 }, // Compact 2 layers gets set to full 1 layer if READER_INIT set }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_options"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + 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, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -90,11 +91,8 @@ static void test_options(int index, int debug) { 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; int input_mode; @@ -2266,19 +2264,23 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; char bwipp_buf[32768]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, data[i].option_1, data[i].option_2, -1, data[i].output_options, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, data[i].option_1, data[i].option_2, -1, data[i].output_options, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -2292,10 +2294,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); @@ -2323,9 +2326,6 @@ static void test_encode(int index, int generate, int debug) { // #181 Nico Gunkel OSS-Fuzz static void test_fuzz(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -2739,15 +2739,19 @@ static void test_fuzz(int index, int debug) { 2080, -1, 1, ZINT_ERROR_TOO_LONG }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_fuzz"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + 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, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -2765,11 +2769,6 @@ static void test_fuzz(int index, int debug) { // Not a real test, just performance indicator static void test_perf(int index, int debug) { - if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ - return; - } - - int ret; struct item { int symbology; int input_mode; @@ -2823,20 +2822,27 @@ static void test_perf(int index, int debug) { 0, 11, 11, "3 chars, AZRUNE" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer; - for (int i = 0; i < data_size; i++) { + if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ + return; + } + + for (i = 0; i < data_size; i++) { + int j; 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(); + for (j = 0; j < TEST_PERF_ITERATIONS; j++) { + 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); + 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 --git a/backend/tests/test_big5.c b/backend/tests/test_big5.c index 92ad0a2d..be75986d 100644 --- a/backend/tests/test_big5.c +++ b/backend/tests/test_big5.c @@ -35,13 +35,14 @@ // As control convert to Big5 using simple table generated from https://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/OTHER/BIG5.TXT plus simple processing static int big5_wctomb_zint2(unsigned int *r, unsigned int wc) { - if (wc < 0x80) { - return 0; - } int tab_length = ARRAY_SIZE(test_big5_tab); int start_i = test_big5_tab_ind[wc >> 10]; int end_i = start_i + 0x800 > tab_length ? tab_length : start_i + 0x800; - for (int i = start_i; i < end_i; i += 2) { + int i; + if (wc < 0x80) { + return 0; + } + for (i = start_i; i < end_i; i += 2) { if (test_big5_tab[i + 1] == wc) { *r = test_big5_tab[i]; return *r > 0xFF ? 2 : 1; @@ -52,12 +53,13 @@ static int big5_wctomb_zint2(unsigned int *r, unsigned int wc) { static void test_big5_wctomb_zint(void) { - testStart(""); - + unsigned int i; int ret, ret2; unsigned int val, val2; - for (unsigned int i = 0; i < 0xFFFE; i++) { + testStart("test_big5_wctomb_zint"); + + for (i = 0; i < 0xFFFE; i++) { if (i >= 0xD800 && i < 0xE000) { // UTF-16 surrogates continue; } @@ -100,9 +102,6 @@ static int big5_utf8(struct zint_symbol *symbol, const unsigned char source[], i } static void test_big5_utf8(int index) { - testStart(""); - - int ret; struct item { char *data; int length; @@ -118,24 +117,28 @@ static void test_big5_utf8(int index) { /* 0*/ { "_", -1, 0, 1, { 0xA1C4 }, "" }, /* 1*/ { "╴", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "" }, }; - - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length, ret; struct zint_symbol symbol; unsigned int b5data[20]; - for (int i = 0; i < data_size; i++) { + testStart("test_big5_utf8"); + + for (i = 0; i < data_size; i++) { + int ret_length; if (index != -1 && i != index) continue; - int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - int ret_length = length; + length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; + ret_length = length; ret = big5_utf8(&symbol, (unsigned char *) data[i].data, &ret_length, b5data); assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol.errtxt); if (ret == 0) { + int j; assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < ret_length; j++) { + for (j = 0; j < ret_length; j++) { assert_equal(b5data[j], data[i].expected_b5data[j], "i:%d b5data[%d] %04X != %04X\n", i, j, b5data[j], data[i].expected_b5data[j]); } } diff --git a/backend/tests/test_bmp.c b/backend/tests/test_bmp.c index 283d7c8e..69753e85 100644 --- a/backend/tests/test_bmp.c +++ b/backend/tests/test_bmp.c @@ -36,14 +36,6 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) static void test_pixel_plot(int index, int debug) { - testStart(""); - - if (!testUtilHaveIdentify()) { - testSkip("ImageMagick identify not available"); - return; - } - - int ret; struct item { int width; int height; @@ -64,16 +56,26 @@ static void test_pixel_plot(int index, int debug) { /* 9*/ { 8, 2, "CBMWKRYGGYRKWMBC", 0 }, }; int data_size = ARRAY_SIZE(data); + int i, ret; + struct zint_symbol *symbol; char *bmp = "out.bmp"; char data_buf[8 * 2 + 1]; - for (int i = 0; i < data_size; i++) { + testStart("test_pixel_plot"); + + if (!testUtilHaveIdentify()) { + testSkip("ImageMagick identify not available"); + return; + } + + for (i = 0; i < data_size; i++) { + int size; if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); strcpy(symbol->outfile, bmp); @@ -82,7 +84,7 @@ static void test_pixel_plot(int index, int debug) { symbol->bitmap_height = data[i].height; symbol->debug |= debug; - int size = data[i].width * data[i].height; + size = data[i].width * data[i].height; assert_nonzero(size < (int) sizeof(data_buf), "i:%d bmp_pixel_plot size %d < sizeof(data_buf) %d\n", i, size, (int) sizeof(data_buf)); if (data[i].repeat) { @@ -112,11 +114,6 @@ static void test_pixel_plot(int index, int debug) { static void test_print(int index, int generate, int debug) { - testStart(""); - - int have_identify = testUtilHaveIdentify(); - - int ret; struct item { int symbology; int whitespace_width; @@ -134,6 +131,8 @@ static void test_print(int index, int generate, int debug) { /* 2*/ { BARCODE_PDF417COMP, 2, 2, -1, -1, "", "", "123", "pdf417comp_hvwsp2.bmp" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; const char *data_dir = "/backend/tests/data/bmp"; const char *bmp = "out.bmp"; @@ -141,23 +140,27 @@ static void test_print(int index, int generate, int debug) { char escaped[1024]; int escaped_size = 1024; + int have_identify = testUtilHaveIdentify(); + + testStart("test_print"); + if (generate) { char data_dir_path[1024]; assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); - if (!testUtilExists(data_dir_path)) { - ret = testutil_mkdir(data_dir_path, 0755); - assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir_path, ret, errno, strerror(errno)); + if (!testUtilDirExists(data_dir_path)) { + ret = testUtilMkDir(data_dir_path); + assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_dir_path, ret, errno, strerror(errno)); } } - for (int i = 0; i < data_size; i++) { + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol* symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); if (data[i].whitespace_width != -1) { symbol->whitespace_width = data[i].whitespace_width; } @@ -185,8 +188,8 @@ static void test_print(int index, int generate, int debug) { i, testUtilBarcodeName(data[i].symbology), data[i].whitespace_width, data[i].whitespace_height, data[i].option_1, data[i].option_2, data[i].fgcolour, data[i].bgcolour, 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); + ret = testUtilRename(symbol->outfile, expected_file); + assert_zero(ret, "i:%d testUtilRename(%s, %s) ret %d != 0 (%d: %s)\n", i, symbol->outfile, expected_file, ret, errno, strerror(errno)); 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); diff --git a/backend/tests/test_channel.c b/backend/tests/test_channel.c index 37d203bd..07776797 100644 --- a/backend/tests/test_channel.c +++ b/backend/tests/test_channel.c @@ -33,9 +33,6 @@ static void test_input(int index, int debug) { - testStart(""); - - int ret; struct item { int option_2; char *data; @@ -94,15 +91,19 @@ static void test_input(int index, int debug) { /* 46*/ { 9, "7742863", ZINT_ERROR_INVALID_DATA, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_CHANNEL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_CHANNEL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); @@ -120,11 +121,8 @@ static void test_input(int index, int debug) { 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 option_2; char *data; @@ -348,19 +346,23 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_CHANNEL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_CHANNEL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -373,10 +375,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); @@ -400,22 +403,23 @@ static void test_encode(int index, int generate, int debug) { // Dummy to generate pre-calculated tables for channels 7/8 static void test_generate(int generate) { - if (!generate) { - return; - } - - int ret; struct item { char *data; }; struct item data[] = { { "576688" }, { "7742862" } }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { - struct zint_symbol *symbol = ZBarcode_Create(); + if (!generate) { + return; + } + + for (i = 0; i < data_size; i++) { + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_CHANNEL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, 0); + length = testUtilSetSymbol(symbol, BARCODE_CHANNEL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, 0); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 (%s)\n", i, ret, symbol->errtxt); diff --git a/backend/tests/test_codablock.c b/backend/tests/test_codablock.c index 93aed67b..5b1c84d8 100644 --- a/backend/tests/test_codablock.c +++ b/backend/tests/test_codablock.c @@ -33,9 +33,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { char *pattern; int length; @@ -56,20 +53,24 @@ static void test_large(int index, int debug) { /* 7*/ { "\351", 2726 / 2 + 1, ZINT_ERROR_TOO_LONG, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[2726 * 2 + 2]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); - int length = testUtilSetSymbol(symbol, BARCODE_CODABLOCKF, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODABLOCKF, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -87,9 +88,6 @@ static void test_large(int index, int debug) { static void test_options(int index, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int option_1; @@ -128,15 +126,19 @@ static void test_options(int index, int debug) { /* 23*/ { GS1_MODE, 1, -1, "A", ZINT_ERROR_INVALID_OPTION, -1, -1, "Check for CODE128" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_options"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_CODABLOCKF, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODABLOCKF, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -154,9 +156,6 @@ static void test_options(int index, int debug) { static void test_reader_init(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int symbology; int input_mode; @@ -173,19 +172,23 @@ static void test_reader_init(int index, int generate, int debug) { /* 1*/ { BARCODE_HIBC_BLOCKF, UNICODE_MODE, READER_INIT, "123456", 0, 3, 101, "67 64 41 60 0B 11 12 22 6A 67 63 2B 22 38 64 2A 1B 6A 67 64 0C 63 64 2B 2F 52 6A", "CodeB FNC3 + 1 2 / CodeC 34 56 CodeB J" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_reader_init"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -211,9 +214,6 @@ static void test_reader_init(int index, int generate, int debug) { static void test_input(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int symbology; int input_mode; @@ -280,19 +280,23 @@ static void test_input(int index, int generate, int debug) { /* 37*/ { BARCODE_HIBC_BLOCKF, UNICODE_MODE, -1, "A99912345/$$52001510X3", -1, 0, 6, 101, "(54) 67 64 44 0B 21 19 19 3A 6A 67 63 2B 5B 17 2D 64 24 6A 67 64 0C 0F 04 04 15 16 6A 67", "" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -318,11 +322,6 @@ static void test_input(int index, int generate, int debug) { 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; int option_1; @@ -412,19 +411,25 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, UNICODE_MODE, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, UNICODE_MODE, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -437,10 +442,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); @@ -468,9 +474,6 @@ static void test_encode(int index, int generate, int debug) { // #181 Christian Hartlage OSS-Fuzz static void test_fuzz(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int length; @@ -480,16 +483,20 @@ static void test_fuzz(int index, int debug) { struct item data[] = { /* 0*/ { "\034\034I", 3, 0 }, }; - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_fuzz"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_CODABLOCKF, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODABLOCKF, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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_code.c b/backend/tests/test_code.c index 65b3e3fd..b256e2d7 100644 --- a/backend/tests/test_code.c +++ b/backend/tests/test_code.c @@ -33,9 +33,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int option_2; @@ -73,20 +70,24 @@ static void test_large(int index, int debug) { /* 23*/ { BARCODE_HIBC_39, -1, "1", 67, ZINT_ERROR_TOO_LONG, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[4096]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -104,9 +105,6 @@ static void test_large(int index, int debug) { static void test_hrt(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int option_2; @@ -146,15 +144,19 @@ static void test_hrt(int index, int debug) { /* 26*/ { BARCODE_HIBC_39, -1, "123456789", -1, "*+1234567890*" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_hrt"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt); @@ -169,9 +171,6 @@ static void test_hrt(int index, int debug) { static void test_input(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int option_2; @@ -213,15 +212,19 @@ static void test_input(int index, int debug) { /* 27*/ { BARCODE_HIBC_39, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -239,11 +242,6 @@ static void test_input(int index, int debug) { 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; int option_2; @@ -337,19 +335,25 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -362,10 +366,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); diff --git a/backend/tests/test_code1.c b/backend/tests/test_code1.c index c39ff6c2..629e1f0c 100644 --- a/backend/tests/test_code1.c +++ b/backend/tests/test_code1.c @@ -33,9 +33,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { int option_2; char *pattern; @@ -161,21 +158,25 @@ static void test_large(int index, int debug) { /*111*/ { 10, "\200", 37, ZINT_ERROR_TOO_LONG, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[4096]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); - int length = testUtilSetSymbol(symbol, BARCODE_CODEONE, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODEONE, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -193,9 +194,6 @@ static void test_large(int index, int debug) { static void test_input(int index, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int eci; @@ -238,16 +236,20 @@ static void test_input(int index, int debug) { /* 26*/ { -1, -1, 11, "1", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 513: Invalid symbol size", }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_CODEONE, data[i].input_mode, data[i].eci, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODEONE, data[i].input_mode, data[i].eci, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -266,11 +268,6 @@ static void test_input(int index, int debug) { 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 input_mode; int eci; @@ -2502,20 +2499,26 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[8192]; char bwipp_buf[32768]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_CODEONE, data[i].input_mode, data[i].eci, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODEONE, data[i].input_mode, data[i].eci, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -2533,12 +2536,13 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, testUtilEscape(data[i].data, length, escaped, sizeof(escaped))); assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, testUtilEscape(data[i].data, length, escaped, sizeof(escaped))); - 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, testUtilEscape(data[i].data, length, escaped, sizeof(escaped))); @@ -2567,9 +2571,6 @@ static void test_encode(int index, int generate, int debug) { // #181 Nico Gunkel OSS-Fuzz static void test_fuzz(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int length; @@ -2579,20 +2580,24 @@ static void test_fuzz(int index, int debug) { struct item data[] = { /* 0*/ { "3333P33B\035333V3333333333333\0363", -1, 0 }, }; - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_fuzz"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->symbology = BARCODE_CODEONE; symbol->debug |= debug; - int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; + length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; ret = ZBarcode_Encode(symbol, (unsigned char *) 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_code128.c b/backend/tests/test_code128.c index e7ed215b..bbb2ad0b 100644 --- a/backend/tests/test_code128.c +++ b/backend/tests/test_code128.c @@ -35,9 +35,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *pattern; @@ -68,14 +65,18 @@ static void test_large(int index, int debug) { /* 17*/ { BARCODE_HIBC_128, "1", 111, ZINT_ERROR_TOO_LONG, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[4096]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); if (data[i].length != -1) { @@ -85,7 +86,7 @@ static void test_large(int index, int debug) { strcpy(data_buf, data[i].pattern); } - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -104,9 +105,6 @@ int hrt_cpy_iso8859_1(struct zint_symbol *symbol, const unsigned char *source, i static void test_hrt_cpy_iso8859_1(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int length; @@ -134,18 +132,23 @@ static void test_hrt_cpy_iso8859_1(int index, int debug) { /* 13*/ { "\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351", -1, 126, "ééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé", "128 \351 (truncated)" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; struct zint_symbol symbol; + + testStart("test_hrt_cpy_iso8859_1"); + symbol.debug |= debug; - for (int i = 0; i < data_size; i++) { + for (i = 0; i < data_size; i++) { + int j; if (index != -1 && i != index) continue; - int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; + length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; ret = hrt_cpy_iso8859_1(&symbol, (unsigned char *) data[i].data, length); - for (int j = 0; j < ret; j++) { + for (j = 0; j < ret; j++) { //fprintf(stderr, "symbol.text[%d] %2X\n", j, symbol.text[j]); } assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); @@ -159,9 +162,6 @@ static void test_hrt_cpy_iso8859_1(int index, int debug) { static void test_hrt(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int input_mode; @@ -186,15 +186,19 @@ static void test_hrt(int index, int debug) { // BARCODE_GS1_128, BARCODE_EAN14, BARCODE_NVE18 hrt tested in test_gs1.c }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_hrt"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt); @@ -209,9 +213,6 @@ static void test_hrt(int index, int debug) { static void test_reader_init(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int symbology; int input_mode; @@ -233,19 +234,23 @@ static void test_reader_init(int index, int generate, int debug) { /* 6*/ { BARCODE_HIBC_128, UNICODE_MODE, READER_INIT, "A", 0, 1, 79, "(7) 104 96 11 33 24 5 106", "StartA FNC3 + A 8 (check) (Not sensible, use CODE128)" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_reader_init"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -271,9 +276,6 @@ static void test_reader_init(int index, int generate, int debug) { static void test_input(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; char *data; @@ -328,19 +330,23 @@ static void test_input(int index, int generate, int debug) { /* 33*/ { UNICODE_MODE, "aééééébcdefééé", -1, 0, 255, "(23) 104 65 100 100 73 73 73 73 73 100 100 66 67 68 69 70 100 100 73 73 73 67 106", "StartB a Latch é (5) Unlatch b c d e f Latch é (3)" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_CODE128, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODE128, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -364,9 +370,6 @@ static void test_input(int index, int generate, int debug) { static void test_ean128_input(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; char *data; @@ -398,21 +401,26 @@ static void test_ean128_input(int index, int generate, int debug) { /* 19*/ { GS1_MODE, "[90]12345[90]1234[90]1", 0, 211, "(19) 105 102 90 12 34 100 21 99 102 90 12 34 102 100 25 99 1 30 106", "StartC FNC1 90 12 34 CodeB 5 CodeC FNC1 90 12 34 FNC1 CodeB 9 CodeC 01" }, /* 20*/ { GS1_MODE, "[90]1A[90]1", 0, 134, "(12) 104 102 25 16 17 33 102 25 99 1 65 106", "StartB FNC1 9 0 1 A FNC1 9 CodeC 01" }, /* 21*/ { GS1_MODE, "[90]12A[90]123", 0, 145, "(13) 105 102 90 12 100 33 102 25 99 1 23 25 106", "StartC FNC1 90 12 CodeB A FNC1 9 CodeC 01 23" }, - /* 22*/ { GS1_MODE, "[90]123[90]A234[90]123", 0, 244, "(22) 105 102 90 12 100 19 99 102 90 100 33 18 99 34 102 100 25 99 1 23 37 106", "StartC FNC1 90 12 CodeB 3 CodeC FNC1 90 CodeB A 2 CodeC 34 FNC1 CodeB 9 CodeC 01 23" } }; + /* 22*/ { GS1_MODE, "[90]123[90]A234[90]123", 0, 244, "(22) 105 102 90 12 100 19 99 102 90 100 33 18 99 34 102 100 25 99 1 23 37 106", "StartC FNC1 90 12 CodeB 3 CodeC FNC1 90 CodeB A 2 CodeC 34 FNC1 CodeB 9 CodeC 01 23" }, + }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_ean128_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_GS1_128, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_GS1_128, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -436,9 +444,6 @@ static void test_ean128_input(int index, int generate, int debug) { static void test_hibc_input(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { char *data; int ret; @@ -451,19 +456,23 @@ static void test_hibc_input(int index, int generate, int debug) { /* 1*/ { "A99912345/$$52001510X3", 0, 255, "(23) 104 11 33 99 99 91 23 45 100 15 4 4 99 52 0 15 10 100 56 19 19 53 106", "Check digit 3" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_hibc_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_HIBC_128, UNICODE_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_HIBC_128, UNICODE_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -487,11 +496,6 @@ static void test_hibc_input(int index, int generate, int debug) { 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; int input_mode; @@ -635,19 +639,25 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -660,10 +670,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); diff --git a/backend/tests/test_code16k.c b/backend/tests/test_code16k.c index 0f665d1f..151836d2 100644 --- a/backend/tests/test_code16k.c +++ b/backend/tests/test_code16k.c @@ -33,9 +33,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { char *pattern; int length; @@ -51,20 +48,24 @@ static void test_large(int index, int debug) { /* 3*/ { "0", 155, ZINT_ERROR_TOO_LONG, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[4096]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); - int length = testUtilSetSymbol(symbol, BARCODE_CODE16K, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODE16K, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -82,9 +83,6 @@ static void test_large(int index, int debug) { static void test_reader_init(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int output_options; @@ -102,19 +100,23 @@ static void test_reader_init(int index, int generate, int debug) { /* 3*/ { GS1_MODE, READER_INIT, "[90]1", ZINT_ERROR_INVALID_OPTION, 0, 0, "Error 422: Cannot use both GS1 mode and Reader Initialisation", "" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_reader_init"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_CODE16K, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODE16K, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -140,9 +142,6 @@ static void test_reader_init(int index, int generate, int debug) { static void test_input(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; char *data; @@ -182,19 +181,23 @@ static void test_input(int index, int generate, int debug) { /* 18*/ { UNICODE_MODE, "aééééébcdeé", -1, 0, 4, 70, "(20) 15 65 100 73 100 73 100 73 100 73 100 73 66 67 68 69 100 73 14 69", "ModeB a FNC4 é (5) b c d e FNC4 é" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_CODE16K, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODE16K, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -219,11 +222,6 @@ static void test_input(int index, int generate, int debug) { 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 input_mode; char *data; @@ -247,19 +245,25 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_CODE16K, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODE16K, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -272,10 +276,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); diff --git a/backend/tests/test_code49.c b/backend/tests/test_code49.c index e85d26a9..ece99420 100644 --- a/backend/tests/test_code49.c +++ b/backend/tests/test_code49.c @@ -33,9 +33,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { char *pattern; int length; @@ -51,20 +48,24 @@ static void test_large(int index, int debug) { /* 3*/ { "0", 82, ZINT_ERROR_TOO_LONG, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[4096]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); - int length = testUtilSetSymbol(symbol, BARCODE_CODE49, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODE49, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -82,9 +83,6 @@ static void test_large(int index, int debug) { static void test_input(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; char *data; @@ -115,19 +113,23 @@ static void test_input(int index, int generate, int debug) { /* 14*/ { GS1_MODE | GS1PARENS_MODE, "(90)12345(91)AB12345", -1, 0, 4, 70, "(32) 45 48 47 15 4 7 9 28 48 45 9 1 10 11 48 25 5 17 9 48 48 48 48 27 48 48 37 39 26 8 14", "FNC1 NS 9012345 (C18 28) NS FNC1 9 1 A B NS (C28 25) 12345 Pad (4) (C38 27) (Start 0, Alpha)" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_CODE49, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODE49, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -152,11 +154,6 @@ static void test_input(int index, int generate, int debug) { 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 input_mode; char *data; @@ -181,19 +178,25 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_CODE49, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODE49, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -206,10 +209,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); diff --git a/backend/tests/test_common.c b/backend/tests/test_common.c index d8f0c0a5..260b10e1 100644 --- a/backend/tests/test_common.c +++ b/backend/tests/test_common.c @@ -1,6 +1,6 @@ /* libzint - the open source barcode library - Copyright (C) 2019 - 2020 Robin Stuart + Copyright (C) 2019 - 2021 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -33,9 +33,6 @@ static void test_utf8_to_unicode(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int length; @@ -53,24 +50,30 @@ static void test_utf8_to_unicode(int index, int debug) { /* 3*/ { "\360\220\200\200", -1, 1, ZINT_ERROR_INVALID_DATA, -1, {0}, "Four-byte F0908080" }, /* 4*/ { "a\200b", -1, 1, ZINT_ERROR_INVALID_DATA, -1, {0}, "Orphan continuation 0x80" }, }; - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length, ret; unsigned int vals[20]; struct zint_symbol symbol; + + testStart("test_utf8_to_unicode"); + symbol.debug |= debug; - for (int i = 0; i < data_size; i++) { + for (i = 0; i < data_size; i++) { + int ret_length; if (index != -1 && i != index) continue; - int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - int ret_length = length; + length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; + ret_length = length; ret = utf8_to_unicode(&symbol, (unsigned char *) data[i].data, vals, &ret_length, data[i].disallow_4byte); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { + int j; assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < ret_length; j++) { + for (j = 0; j < ret_length; j++) { assert_equal(vals[j], data[i].expected_vals[j], "i:%d vals[%d] %04X != %04X\n", i, j, vals[j], data[i].expected_vals[j]); } } @@ -81,9 +84,6 @@ static void test_utf8_to_unicode(int index, int debug) { static void test_is_valid_utf8(int index) { - testStart(""); - - int ret; struct item { char* data; int length; @@ -104,12 +104,15 @@ static void test_is_valid_utf8(int index) { /* 8*/ { "\355\240\200", -1, 0, "Surrogate 0xEDA080" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; - for (int i = 0; i < data_size; i++) { + testStart("test_is_valid_utf8"); + + for (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; + length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; ret = is_valid_utf8((const unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); @@ -120,8 +123,6 @@ static void test_is_valid_utf8(int index) { static void test_debug_test_codeword_dump_int(int index, int debug) { - testStart(""); - struct item { int codewords[50]; int length; @@ -132,12 +133,16 @@ static void test_debug_test_codeword_dump_int(int index, int debug) { /* 0*/ { { 2147483647, -2147483646, 2147483647, 0, 2147483647, 2147483647, 2147483647, 2147483647, 123456 }, 10, "(10) 2147483647 -2147483646 2147483647 0 2147483647 2147483647 2147483647 2147483647 123456" }, /* 1*/ { { 2147483647, -2147483646, 2147483647, 0, 2147483647, 2147483647, 2147483647, 2147483647, 1234567 }, 10, "(10) 2147483647 -2147483646 2147483647 0 2147483647 2147483647 2147483647 2147483647" }, }; - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i; struct zint_symbol symbol; + + testStart("test_debug_test_codeword_dump_int"); + symbol.debug |= debug; - for (int i = 0; i < data_size; i++) { + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; diff --git a/backend/tests/test_composite.c b/backend/tests/test_composite.c index 066c9f62..46422c4e 100644 --- a/backend/tests/test_composite.c +++ b/backend/tests/test_composite.c @@ -33,9 +33,6 @@ static void test_eanx_leading_zeroes(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -76,19 +73,23 @@ static void test_eanx_leading_zeroes(int index, int debug) { /*26*/ { BARCODE_EANX_CC, "1234567890128+12345", "[21]A12345678", 0, 7, 153 }, // EAN-13 + CHK + EAN-5 }; int data_size = ARRAY_SIZE(data); + int i, length, composite_length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_eanx_leading_zeroes"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - int composite_length = strlen(data[i].composite); + composite_length = strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -135,11 +136,6 @@ static void test_helper_generate(const struct zint_symbol *symbol, int ret, int // Replicate examples from GS1 General Specifications 21.0.1 and ISO/IEC 24723:2010 static void test_examples(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; int option_1; @@ -1061,7 +1057,7 @@ static void test_examples(int index, int generate, int debug) { "000000000101100011000010100010011001001101001100011011101001110001110100100111101011001000010010100110001100100111001010000100010111001000100111000101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" "000000011010011100111101011101100110110010110011100100010110001110001011011000010100110111101101011001110011011000110101111011101000110111011000111010110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, - /*54*/ { BARCODE_GS1_128_CC, 3, "[01]12345678901231", "[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[95]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[96]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[97]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[98]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[99]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[95]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[96]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[97]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[98]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[99]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[95]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[96]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[97]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[98]123456789012345678901234567890123456789012345", 0, 32, 579, "Example with CC-C 30 cols, 30 rows (max)", + /*54*/ { BARCODE_GS1_128_CC, 3, "[01]12345678901231", "[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[95]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[96]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[97]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[98]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[99]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[95]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[96]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[97]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[98]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[99]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[94]1234567890123456789012" "34567890123456789012345678901234567890123456789012345678901234567890[95]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[96]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[97]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[98]123456789012345678901234567890123456789012345", 0, 32, 579, "Example with CC-C 30 cols, 30 rows (max)", "111111110101010001010100000100000010001110111000100111011111011101001100011100011010011111011010011110111011001000011001011011110011100011110111101010000110000110010100001111100101011111010001011000110000101000001100011001100100010000110011010011110111110101100011000010001100110110110000011111011110010110110010001000011001001011100011100011001000010011000100010110000011001000100001000001011011110011101000100001001000010001111101101001111010111001110010000111101001001111001001000010010000011100110111011110101101100010000001110101000111000010101111011110000111111101000101001" "111111110101010001111101011011100011100110011101000101111010111100001111000100110110011111101001001110111001101110010001001100111110001010101111000010000111100100011011001011010011111100011110011011010000100111011111101001111100110110011010001110100111110111010000111011001001110100111110011000110111101000110000100001110101000111001011111010101111100110000111110001010110001110000001011001011111011010000100100000100011110101101011100000100010111100010111100100010000111101001001101111110110011111011001100110111001011100110001110000010011001011111010100001100111111101000101001" "111111110101010001010111000111111010110100000111000100010000010111101000110100000111011111101001100100111110100111000101011100010001100011101110101111000110010010001111101001001000001111011101101011111000101100000110111101000111101000010011011101000011100100110110111100001100010010111110011101101111110100100111100011011001000111001000011011001001101111110111010111111011001110011110010111010011110001100110101110000010110001011000001001110010110110000111100100001000010111101101100110011111010101101111100000100101110011111101000011001000111011111101011001000111111101000101001" @@ -1227,23 +1223,29 @@ static void test_examples(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, composite_length, ret; + struct zint_symbol *symbol; char bwipp_buf[32768]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_examples"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - int composite_length = strlen(data[i].composite); + composite_length = strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -1251,10 +1253,11 @@ static void test_examples(int index, int generate, int debug) { if (generate) { test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].comment, -1 /*bwipp_cmp*/); } else { + int width, row; + 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); - 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); @@ -1276,11 +1279,6 @@ static void test_examples(int index, int generate, int debug) { static void test_odd_numbered_numeric(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; int option_1; @@ -1389,23 +1387,29 @@ static void test_odd_numbered_numeric(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, composite_length, ret; + struct zint_symbol *symbol; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_odd_numbered_numeric"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - int composite_length = strlen(data[i].composite); + composite_length = strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -1413,10 +1417,11 @@ static void test_odd_numbered_numeric(int index, int generate, int debug) { if (generate) { test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].comment, -1 /*bwipp_cmp*/); } else { + int width, row; + 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); - 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); @@ -1438,11 +1443,6 @@ static void test_odd_numbered_numeric(int index, int generate, int debug) { static void test_ean128_cc_shift(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; int option_1; @@ -1516,22 +1516,28 @@ static void test_ean128_cc_shift(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, composite_length, ret; + struct zint_symbol *symbol; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_ean128_cc_shift"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - int composite_length = strlen(data[i].composite); + composite_length = strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -1539,10 +1545,11 @@ static void test_ean128_cc_shift(int index, int generate, int debug) { if (generate) { test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].comment, data[i].bwipp_cmp); } else { + int width, row; + 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); - 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); @@ -1568,9 +1575,6 @@ static void test_ean128_cc_shift(int index, int generate, int debug) { static void test_ean128_cc_width(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { char *data; char *composite; @@ -1593,23 +1597,27 @@ static void test_ean128_cc_width(int index, int generate, int debug) { /* 8*/ { "[91]123A1234A", "[02]13012345678909", 0, 5, 174, "" }, /* 9*/ { "[91]123A1234A1", "[02]13012345678909", 0, 5, 188, "" }, /*10*/ { "[91]123A1234A12", "[02]13012345678909", 0, 5, 205, "" }, - /*11*/ { "[00]123456789012345675", "[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[91]1234567890", 0, 32, 579, "With composite 2372 digits == max" }, - /*12*/ { "[00]123456789012345675", "[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[91]12345678901", ZINT_ERROR_TOO_LONG, 0, 0, "With composite 2373 digits > max" }, + /*11*/ { "[00]123456789012345675", "[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345" "675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[91]1234567890", 0, 32, 579, "With composite 2372 digits == max" }, + /*12*/ { "[00]123456789012345675", "[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345" "675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[91]12345678901", ZINT_ERROR_TOO_LONG, 0, 0, "With composite 2373 digits > max" }, }; int data_size = ARRAY_SIZE(data); + int i, length, composite_length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_ean128_cc_width"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_GS1_128_CC, -1 /*input_mode*/, -1 /*eci*/, 3, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_GS1_128_CC, -1 /*input_mode*/, -1 /*eci*/, 3, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - int composite_length = strlen(data[i].composite); + composite_length = strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -1631,11 +1639,6 @@ static void test_ean128_cc_width(int index, int generate, int debug) { // Test general-purpose data compaction static void test_encodation_0(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; int option_1; @@ -2059,22 +2062,28 @@ static void test_encodation_0(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, composite_length, ret; + struct zint_symbol *symbol; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encodation_0"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - int composite_length = strlen(data[i].composite); + composite_length = strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -2082,10 +2091,11 @@ static void test_encodation_0(int index, int generate, int debug) { if (generate) { test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].comment, -1 /*bwipp_cmp*/); } else { + int width, row; + 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); - 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); @@ -2107,11 +2117,6 @@ static void test_encodation_0(int index, int generate, int debug) { static void test_encodation_10(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; int option_1; @@ -2194,22 +2199,28 @@ static void test_encodation_10(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, composite_length, ret; + struct zint_symbol *symbol; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encodation_10"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - int composite_length = strlen(data[i].composite); + composite_length = strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -2217,10 +2228,11 @@ static void test_encodation_10(int index, int generate, int debug) { if (generate) { test_helper_generate(symbol, ret, i, data[i].data, data[i].composite, data[i].option_1, data[i].comment, -1 /*bwipp_cmp*/); } else { + int width, row; + 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); - 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); @@ -2241,11 +2253,7 @@ static void test_encodation_10(int index, int generate, int debug) { } static void test_encodation_11(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; int option_1; @@ -2572,22 +2580,28 @@ static void test_encodation_11(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, composite_length, ret; + struct zint_symbol *symbol; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encodation_11"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - int composite_length = strlen(data[i].composite); + composite_length = strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -2621,11 +2635,7 @@ static void test_encodation_11(int index, int generate, int debug) { } static void test_addongap(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; int option_1; @@ -2720,24 +2730,30 @@ static void test_addongap(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, composite_length, ret; + struct zint_symbol *symbol; char bwipp_buf[8192]; char bwipp_msg[1024]; char *composite = "[91]12"; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_addongap"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - int composite_length = strlen(composite); + composite_length = strlen(composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -2749,10 +2765,11 @@ static void test_addongap(int index, int generate, int debug) { testUtilModulesPrint(symbol, " ", "\n"); printf(" },\n"); } else { + int width, row; + 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); - 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); @@ -2774,9 +2791,6 @@ static void test_addongap(int index, int generate, int debug) { static void test_gs1parens(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int input_mode; @@ -2813,19 +2827,23 @@ static void test_gs1parens(int index, int debug) { /* 21*/ { BARCODE_DBAR_EXPSTK_CC, GS1PARENS_MODE, "(01)12345678901231(3103)001234", "(21)A12345678", 0, 9, 102 }, }; int data_size = ARRAY_SIZE(data); + int i, length, composite_length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_gs1parens"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - int composite_length = strlen(data[i].composite); + composite_length = strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -2843,9 +2861,7 @@ static void test_gs1parens(int index, int debug) { // #181 Christian Hartlage OSS-Fuzz static void test_fuzz(int index, int debug) { - testStart(""); - int ret; struct item { int symbology; char *data; @@ -2862,19 +2878,23 @@ static void test_fuzz(int index, int debug) { /* 4*/ { BARCODE_EANX_CC, "+123456", -1, "[21]A12345678", ZINT_ERROR_TOO_LONG }, }; int data_size = ARRAY_SIZE(data); + int i, length, composite_length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_fuzz"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - int composite_length = strlen(data[i].composite); + composite_length = strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -2892,11 +2912,6 @@ static void test_fuzz(int index, int debug) { // Not a real test, just performance indicator static void test_perf(int index, int debug) { - if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ - return; - } - - int ret; struct item { int symbology; int option_1; @@ -2928,24 +2943,30 @@ static void test_perf(int index, int debug) { 0, 32, 205, "564 chars CC-C" }, }; int data_size = ARRAY_SIZE(data); + int i, length, composite_length, ret; clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer; - for (int i = 0; i < data_size; i++) { + if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ + return; + } + + for (i = 0; i < data_size; i++) { + int j; if (index != -1 && i != index) continue; diff_encode = diff_buffer = 0; - for (int j = 0; j < TEST_PERF_ITERATIONS; j++) { + for (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, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - int composite_length = strlen(data[i].composite); + composite_length = strlen(data[i].composite); start = clock(); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); diff --git a/backend/tests/test_dmatrix.c b/backend/tests/test_dmatrix.c index b09031b3..3a33440b 100644 --- a/backend/tests/test_dmatrix.c +++ b/backend/tests/test_dmatrix.c @@ -33,9 +33,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int option_2; @@ -346,20 +343,24 @@ static void test_large(int index, int debug) { /*295*/ { BARCODE_DATAMATRIX, 48, "\200", 117, ZINT_ERROR_TOO_LONG, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[3118]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -378,9 +379,6 @@ static void test_large(int index, int debug) { // Note need ZINT_SANITIZE set for these static void test_buffer(int index, int debug) { - testStart(""); - - int ret; struct item { int eci; int input_mode; @@ -395,15 +393,19 @@ static void test_buffer(int index, int debug) { /* 1*/ { 3, UNICODE_MODE, 0, "000106j 05 Galeria A Nação0000000000", 0, "From Okapi, consecutive use of upper shift; #176" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_buffer"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_DATAMATRIX, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, -1, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_DATAMATRIX, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, -1, data[i].output_options, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); @@ -416,9 +418,6 @@ static void test_buffer(int index, int debug) { static void test_options(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int input_mode; @@ -448,15 +447,19 @@ static void test_options(int index, int debug) { /* 12*/ { BARCODE_DATAMATRIX, GS1_MODE | GS1PARENS_MODE, -1, -1, -1, "(90)12", 0, 10, 10 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_options"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + 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, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -474,9 +477,6 @@ static void test_options(int index, int debug) { static void test_reader_init(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int symbology; int input_mode; @@ -493,19 +493,23 @@ static void test_reader_init(int index, int generate, int debug) { /* 1*/ { BARCODE_DATAMATRIX, GS1_MODE, READER_INIT, "[91]A", ZINT_ERROR_INVALID_OPTION, 0, 0, "Error 521: Cannot encode in GS1 mode and Reader Initialisation at the same time", "" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_reader_init"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -531,11 +535,6 @@ static void test_reader_init(int index, int generate, int debug) { static void test_input(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 input_mode; int eci; @@ -645,21 +644,27 @@ static void test_input(int index, int generate, int debug) { /* 91*/ { UNICODE_MODE | ESCAPE_MODE, -1, -1, -1, "[)>\\R05\\GA\\R\\E", 0, 0, 10, 10, "EC 42 81 5D 17 49 F6 B6", "Macro05 A41" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[8192]; char bwipp_buf[32768]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_DATAMATRIX, data[i].input_mode, data[i].eci, -1 /*option_1*/, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_DATAMATRIX, data[i].input_mode, data[i].eci, -1 /*option_1*/, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -697,11 +702,6 @@ static void test_input(int index, int generate, int debug) { 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; int input_mode; @@ -2043,19 +2043,25 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[8192]; char bwipp_buf[32768]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, -1 /*option_1*/, data[i].option_2, data[i].option_3, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, -1 /*option_1*/, data[i].option_2, data[i].option_3, data[i].output_options, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); @@ -2069,10 +2075,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); @@ -2104,11 +2111,6 @@ static void test_encode(int index, int generate, int debug) { // Not a real test, just performance indicator static void test_perf(int index, int debug) { - if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ - return; - } - - int ret; struct item { int symbology; int input_mode; @@ -2158,20 +2160,26 @@ static void test_perf(int index, int debug) { 0, 120, 120, "960 chars, byte" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer; - for (int i = 0; i < data_size; i++) { + if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ + return; + } + + for (i = 0; i < data_size; i++) { + int j; if (index != -1 && i != index) continue; diff_encode = diff_buffer = 0; - for (int j = 0; j < TEST_PERF_ITERATIONS; j++) { + for (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); + 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 --git a/backend/tests/test_dotcode.c b/backend/tests/test_dotcode.c index 660cd8df..e51c4389 100644 --- a/backend/tests/test_dotcode.c +++ b/backend/tests/test_dotcode.c @@ -33,9 +33,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { int option_2; char datum; @@ -51,19 +48,23 @@ static void test_large(int index, int debug) { /* 4*/ { 30, '\001', 71, 0 }, // Codeword length 72, ECC length 39, for ND + 1 == 112 }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[4096]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); memset(data_buf, data[i].datum, data[i].length); - int length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -76,9 +77,6 @@ static void test_large(int index, int debug) { static void test_options(int index, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int output_options; @@ -103,15 +101,19 @@ static void test_options(int index, int debug) { /* 9*/ { -1, -1, 201, "12345678901234567890123456789012345678901234567890123456789012345678901234567890", ZINT_ERROR_INVALID_OPTION, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_options"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -129,9 +131,6 @@ static void test_options(int index, int debug) { static void test_input(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int eci; @@ -181,19 +180,23 @@ static void test_input(int index, int generate, int debug) { /* 36*/ { UNICODE_MODE, -1, "\001abc\011\015\012\036", -1, 0, "65 41 65 41 42 43 61 60 64", "LatchA (0x65) SOH 6xShiftB (0x65) a b c HT CR/LF RS" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -216,11 +219,6 @@ static void test_input(int index, int generate, int debug) { 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 input_mode; int option_2; @@ -732,19 +730,25 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, data[i].input_mode, -1 /*eci*/, -1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, data[i].input_mode, -1 /*eci*/, -1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -758,10 +762,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); @@ -789,9 +794,6 @@ static void test_encode(int index, int generate, int debug) { // #181 Christian Hartlage / Nico Gunkel OSS-Fuzz static void test_fuzz(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int length; @@ -824,15 +826,19 @@ static void test_fuzz(int index, int debug) { /* 6*/ { "\237", -1, DATA_MODE, 0 }, // As above L1090 }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_fuzz"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_DOTCODE, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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_eci.c b/backend/tests/test_eci.c index ed3f2b05..403efa57 100644 --- a/backend/tests/test_eci.c +++ b/backend/tests/test_eci.c @@ -34,20 +34,7 @@ static void test_bom(int debug) { - testStart(""); - - 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->option_3 = 5 << 8; // Mask 100 (instead of automatic 010) - symbol->debug |= debug; - char data[] = "\xEF\xBB\xBF‹"; // U+FEFF BOM, with U+2039 (only in Windows pages) - int length = strlen(data); char expected[] = "111111100001001111111" @@ -72,12 +59,29 @@ static void test_bom(int debug) { "100000100010011010111" "111111100101101000101"; - int ret; + int length, ret; + struct zint_symbol *symbol; + + int width, height; + + testStart("test_bom"); + + 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->option_3 = 5 << 8; // Mask 100 (instead of automatic 010) + symbol->debug |= debug; + + length = (int) strlen(data); + ret = ZBarcode_Encode(symbol, (unsigned char *) data, length); assert_equal(ret, ZINT_WARN_USES_ECI, "ZBarcode_Encode ret %d != ZINT_WARN_USES_ECI\n", ret); assert_equal(symbol->eci, 21, "eci %d != 21\n", symbol->eci); // ECI 21 == Windows-1250 - int width, height; ret = testUtilModulesCmp(symbol, expected, &width, &height); assert_equal(ret, 0, "testUtilModulesEqual ret %d != 0, width %d, height %d\n", ret, width, height); @@ -88,19 +92,21 @@ static void test_bom(int debug) { static void test_iso_8859_16(int debug) { - testStart(""); + char data[] = "Ț"; // U+021A only in ISO 8859-16 + int length, ret; + struct zint_symbol *symbol; - struct zint_symbol *symbol = ZBarcode_Create(); + testStart("test_iso_8859_16"); + + 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); + length = (int) strlen(data); - int ret; ret = ZBarcode_Encode(symbol, (unsigned char *) data, length); assert_equal(ret, ZINT_WARN_USES_ECI, "ZBarcode_Encode ret %d != ZINT_WARN_USES_ECI\n", ret); assert_equal(symbol->eci, 18, "eci %d != 18\n", symbol->eci); // ECI 18 == ISO 8859-16 @@ -113,9 +119,6 @@ static void test_iso_8859_16(int debug) { // Only testing standard non-extended barcodes here, ie not QRCODE, MICROQR, GRIDMATRIX, HANXIN or UPNQR static void test_reduced_charset_input(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int input_mode; @@ -374,15 +377,19 @@ static void test_reduced_charset_input(int index, int debug) { /*237*/ { BARCODE_ULTRA, UNICODE_MODE, 30, "가가", 0, 30, "U+AC00 in EUC-KR" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_reduced_charset_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -637,9 +644,6 @@ static const unsigned short int windows_1256[] = { static void test_utf8_to_eci_sb(int index) { - testStart(""); - - int ret; struct item { int eci; const unsigned short *tab; @@ -667,29 +671,34 @@ static void test_utf8_to_eci_sb(int index) { /* 18*/ { 24, windows_1256 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; unsigned char source[5]; unsigned char dest[2] = {0}; - for (int i = 0; i < data_size; i++) { + testStart("test_utf8_to_eci_sb"); + + for (i = 0; i < data_size; i++) { + int j; if (index != -1 && i != index) continue; - for (int j = 0; j < 128; j++) { + for (j = 0; j < 128; j++) { int k = j + 128; if (data[i].tab[j]) { - int length = to_utf8(data[i].tab[j], source); + length = to_utf8(data[i].tab[j], source); assert_nonzero(length, "i:%d to_utf8 length %d == 0\n", i, length); ret = utf8_to_eci(data[i].eci, source, dest, &length); assert_zero(ret, "i:%d utf8_to_eci ret %d != 0\n", i, ret); assert_equal(*dest, k, "i:%d j:%d eci:%d codepoint:0x%x *dest 0x%X (%d) != 0x%X (%d)\n", i, j, data[i].eci, data[i].tab[j], *dest, *dest, k, k); } else { - int length = to_utf8(k, source); + length = to_utf8(k, source); assert_nonzero(length, "i:%d to_utf8 length %d == 0\n", i, length); ret = utf8_to_eci(data[i].eci, source, dest, &length); if (ret == 0) { // Should be mapping for this codepoint in another entry int found = 0; - for (int m = 0; m < 128; m++) { + int m; + for (m = 0; m < 128; m++) { if (data[i].tab[m] == k) { found = 1; break; @@ -708,9 +717,6 @@ static void test_utf8_to_eci_sb(int index) { static void test_utf8_to_eci_ascii(void) { - testStart(""); - - int ret; struct item { int eci; char *data; @@ -739,12 +745,16 @@ static void test_utf8_to_eci_ascii(void) { /* 17*/ { 170, "\302\200", -1, ZINT_ERROR_INVALID_DATA }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; char dest[128]; - for (int i = 0; i < data_size; i++) { - int length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); - int out_length = length; + testStart("test_utf8_to_eci_ascii"); + + for (i = 0; i < data_size; i++) { + int out_length; + length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); + out_length = length; ret = utf8_to_eci(data[i].eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { @@ -756,9 +766,6 @@ static void test_utf8_to_eci_ascii(void) { static void test_utf8_to_eci_ucs2be(void) { - testStart(""); - - int ret; struct item { int eci; char *data; @@ -775,13 +782,18 @@ static void test_utf8_to_eci_ucs2be(void) { /* 4*/ { 25, "\355\240\200", -1, ZINT_ERROR_INVALID_DATA, -1 }, // U+D800 surrogate not allowed }; int data_size = ARRAY_SIZE(data); + int i, length, ret; - for (int i = 0; i < data_size; i++) { - int length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); - int out_length = length; - int eci_length = get_eci_length(data[i].eci, (const unsigned char *) data[i].data, length); + testStart("test_utf8_to_eci_ucs2be"); + + for (i = 0; i < data_size; i++) { + int out_length, eci_length; char dest[1024]; + length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); + out_length = length; + eci_length = get_eci_length(data[i].eci, (const unsigned char *) data[i].data, length); + assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length); ret = utf8_to_eci(data[i].eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); @@ -794,9 +806,6 @@ static void test_utf8_to_eci_ucs2be(void) { static void test_get_best_eci(int index) { - testStart(""); - - int ret; struct item { const char *data; int length; @@ -814,12 +823,15 @@ static void test_get_best_eci(int index) { /* 7*/ { "AB\200", -1, 0 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; - for (int i = 0; i < data_size; i++) { + testStart("test_get_best_eci"); + + for (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; + length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; ret = get_best_eci((const unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d get_best_eci ret %d != %d\n", i, ret, data[i].ret); diff --git a/backend/tests/test_emf.c b/backend/tests/test_emf.c index 962c22db..754f9681 100644 --- a/backend/tests/test_emf.c +++ b/backend/tests/test_emf.c @@ -34,14 +34,6 @@ static void test_print(int index, int generate, int debug) { - testStart(""); - - int have_libreoffice = 0; - if (generate) { - have_libreoffice = testUtilHaveLibreOffice(); - } - - int ret; struct item { int symbology; int input_mode; @@ -72,6 +64,8 @@ static void test_print(int index, int generate, int debug) { /* 12*/ { BARCODE_MAXICODE, -1, -1, -1, -1, -1, "E0E0E0", "700070", 0, "THIS IS A 93 CHARACTER CODE SET A MESSAGE THAT FILLS A MODE 4, UNAPPENDED, MAXICODE SYMBOL...", "maxicode_#185.emf", "#185 Maxicode scaling" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; const char *data_dir = "/backend/tests/data/emf"; const char *emf = "out.emf"; @@ -79,23 +73,30 @@ static void test_print(int index, int generate, int debug) { char escaped[1024]; int escaped_size = 1024; + int have_libreoffice = 0; + if (generate) { + have_libreoffice = testUtilHaveLibreOffice(); + } + + testStart("test_print"); + if (generate) { char data_dir_path[1024]; assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); - if (!testUtilExists(data_dir_path)) { - ret = testutil_mkdir(data_dir_path, 0755); - assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir_path, ret, errno, strerror(errno)); + if (!testUtilDirExists(data_dir_path)) { + ret = testUtilMkDir(data_dir_path); + assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_dir_path, ret, errno, strerror(errno)); } } - for (int i = 0; i < data_size; i++) { + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol* symbol = ZBarcode_Create(); + 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, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug); if (data[i].whitespace_width != -1) { symbol->whitespace_width = data[i].whitespace_width; } @@ -121,8 +122,8 @@ static void test_print(int index, int generate, int debug) { testUtilOutputOptionsName(data[i].output_options), data[i].whitespace_width, data[i].option_1, data[i].option_2, data[i].fgcolour, data[i].bgcolour, data[i].rotate_angle, testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].expected_file, data[i].comment); - ret = rename(symbol->outfile, expected_file); - assert_zero(ret, "i:%d rename(%s, %s) ret %d != 0\n", i, symbol->outfile, expected_file, ret); + ret = testUtilRename(symbol->outfile, expected_file); + assert_zero(ret, "i:%d testUtilRename(%s, %s) ret %d != 0\n", i, symbol->outfile, expected_file, ret); if (have_libreoffice) { // Note this will fail (on Ubuntu anyway) if LibreOffice Base/Calc/Impress/Writer running (i.e. anything but LibreOffice Draw) // Doesn't seem to be a way to force Draw invocation through the command line diff --git a/backend/tests/test_gb18030.c b/backend/tests/test_gb18030.c index fc1a4e50..0f44cd20 100644 --- a/backend/tests/test_gb18030.c +++ b/backend/tests/test_gb18030.c @@ -39,6 +39,9 @@ // 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) { unsigned int c; + int tab_length, start_i, end_i; + int i; + // 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. *r1 = 0xA8BC; @@ -106,10 +109,10 @@ static int gb18030_wctomb_zint2(unsigned int *r1, unsigned int *r2, unsigned int *r2 = 0x8130 + (c % 10) + 0x100 * (c / 10); return 4; } - int tab_length = sizeof(test_gb18030_tab) / sizeof(unsigned int); - int start_i = test_gb18030_tab_ind[wc >> 10]; - int end_i = start_i + 0x800 > tab_length ? tab_length : start_i + 0x800; - for (int i = start_i; i < end_i; i += 2) { + tab_length = ARRAY_SIZE(test_gb18030_tab); + start_i = test_gb18030_tab_ind[wc >> 10]; + end_i = start_i + 0x800 > tab_length ? tab_length : start_i + 0x800; + for (i = start_i; i < end_i; i += 2) { if (test_gb18030_tab[i + 1] == wc) { c = test_gb18030_tab[i]; if (c <= 0xFFFF) { @@ -126,12 +129,13 @@ static int gb18030_wctomb_zint2(unsigned int *r1, unsigned int *r2, unsigned int static void test_gb18030_wctomb_zint(void) { - testStart(""); - int ret, ret2; unsigned int val1_1, val1_2, val2_1, val2_2; + unsigned int i; - for (unsigned int i = 0; i < 0x10400; i++) { // Don't bother with U+10400..U+10FFFF, programmatically filled + testStart("test_gb18030_wctomb_zint"); + + for (i = 0; i < 0x10400; i++) { // Don't bother with U+10400..U+10FFFF, programmatically filled if (i >= 0xD800 && i <= 0xDFFF) { // UTF-16 surrogates continue; } @@ -150,9 +154,6 @@ static void test_gb18030_wctomb_zint(void) { static void test_gb18030_utf8(int index) { - testStart(""); - - int ret; struct item { char *data; int length; @@ -181,24 +182,28 @@ static void test_gb18030_utf8(int index) { /* 7*/ { "—", -1, 0, 1, { 0xA1AA }, "GB 18030 subset mapping" }, /* 8*/ { "aβc・·—é—Z", -1, 0, 10, { 'a', 0xA6C2, 'c', 0x8139, 0xA739, 0xA1A4, 0xA1AA, 0xA8A6, 0xA1AA, 'Z' }, "" }, }; - - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length, ret; struct zint_symbol symbol; unsigned int gbdata[30]; - for (int i = 0; i < data_size; i++) { + testStart("test_gb18030_utf8"); + + for (i = 0; i < data_size; i++) { + int ret_length; if (index != -1 && i != index) continue; - int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - int ret_length = length; + length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; + ret_length = length; ret = gb18030_utf8(&symbol, (unsigned char *) 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) { + int j; assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < (int) ret_length; j++) { + for (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]); } } @@ -209,9 +214,6 @@ static void test_gb18030_utf8(int index) { static void test_gb18030_utf8_to_eci(int index) { - testStart(""); - - int ret; struct item { int eci; int full_multibyte; @@ -283,23 +285,27 @@ static void test_gb18030_utf8_to_eci(int index) { /* 50*/ { 30, 0, "詰", -1, 0, 2, { 0x7D + 0x80, 0x7E + 0x80 }, "EUC-KR U+8A70 (0xFDFE)" }, /* 51*/ { 30, 1, "詰", -1, 0, 1, { 0x7D7E + 0x8080 }, "All EUC-KR in GB 18030 Hanzi mode range" }, }; - - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length, ret; unsigned int gbdata[30]; - for (int i = 0; i < data_size; i++) { + testStart("test_gb18030_utf8_to_eci"); + + for (i = 0; i < data_size; i++) { + int ret_length; if (index != -1 && i != index) continue; - int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - int ret_length = length; + length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; + ret_length = length; ret = gb18030_utf8_to_eci(data[i].eci, (unsigned char *) 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) { + int j; assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < (int) ret_length; j++) { + for (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]); } } @@ -310,8 +316,6 @@ static void test_gb18030_utf8_to_eci(int index) { static void test_gb18030_cpy(int index) { - testStart(""); - struct item { int full_multibyte; char *data; @@ -334,21 +338,25 @@ static void test_gb18030_cpy(int index) { /* 8*/ { 0, "\241\240\241\376\367\376\367\377\2012\2013", -1, 0, 12, { 0xA1, 0xA0, 0xA1, 0xFE, 0xF7, 0xFE, 0xF7, 0xFF, 0x81, 0x32, 0x81, 0x33 }, "" }, /* 9*/ { 1, "\241\240\241\376\367\376\367\377\2012\2013", -1, 0, 7, { 0xA1A0, 0xA1FE, 0xF7FE, 0xF7, 0xFF, 0x8132, 0x8133 }, "" }, }; - - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length; unsigned int gbdata[30]; - for (int i = 0; i < data_size; i++) { + testStart("test_gb18030_cpy"); + + for (i = 0; i < data_size; i++) { + int ret_length; + int j; if (index != -1 && i != index) continue; - int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - int ret_length = length; + length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; + ret_length = length; gb18030_cpy((unsigned char *) data[i].data, &ret_length, gbdata, data[i].full_multibyte); assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < (int) ret_length; j++) { + for (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 79ef3b51..cb76cd44 100644 --- a/backend/tests/test_gb2312.c +++ b/backend/tests/test_gb2312.c @@ -36,14 +36,17 @@ // 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) { + int tab_length, start_i, end_i; + int i; + // Shortcut if ((wc > 0x0451 && wc < 0x2015) || (wc > 0x3229 && wc < 0x4E00) || (wc > 0x9FA0 && wc < 0xFF01) || wc > 0xFFE5) { return 0; } - int tab_length = sizeof(test_gb2312_tab) / sizeof(unsigned int); - int start_i = test_gb2312_tab_ind[wc >> 10]; - int end_i = start_i + 0x800 > tab_length ? tab_length : start_i + 0x800; - for (int i = start_i; i < end_i; i += 2) { + tab_length = ARRAY_SIZE(test_gb2312_tab); + start_i = test_gb2312_tab_ind[wc >> 10]; + end_i = start_i + 0x800 > tab_length ? tab_length : start_i + 0x800; + for (i = start_i; i < end_i; i += 2) { if (test_gb2312_tab[i + 1] == wc) { *r = test_gb2312_tab[i] + 0x8080; // Table in GB 2312 not EUC-CN return 2; @@ -54,12 +57,13 @@ static int gb2312_wctomb_zint2(unsigned int *r, unsigned int wc) { static void test_gb2312_wctomb_zint(void) { - testStart(""); - int ret, ret2; unsigned int val, val2; + unsigned int i; - for (unsigned int i = 0; i < 0xFFFE; i++) { + testStart("test_gb2312_wctomb_zint"); + + for (i = 0; i < 0xFFFE; i++) { if (i < 0x80) { // ASCII is straight through and not dealt with by gb2312_wctomb_zint() continue; } @@ -90,9 +94,6 @@ static void test_gb2312_wctomb_zint(void) { static void test_gb2312_utf8(int index) { - testStart(""); - - int ret; struct item { char *data; int length; @@ -121,24 +122,28 @@ static void test_gb2312_utf8(int index) { /* 7*/ { "—", -1, 0, 1, { 0xA1AA }, "GB 18030 subset mapping" }, /* 8*/ { "aβc・·—é—Z", -1, 0, 9, { 'a', 0xA6C2, 'c', 0xA1A4, 0xA1A4, 0xA1AA, 0xA8A6, 0xA1AA, 'Z' }, "" }, }; - - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length, ret; struct zint_symbol symbol; unsigned int gbdata[20]; - for (int i = 0; i < data_size; i++) { + testStart("test_gb2312_utf8"); + + for (i = 0; i < data_size; i++) { + int ret_length; if (index != -1 && i != index) continue; - int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - int ret_length = length; + length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; + ret_length = length; ret = gb2312_utf8(&symbol, (unsigned char *) 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) { + int j; assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < (int) ret_length; j++) { + for (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]); } } @@ -149,9 +154,6 @@ static void test_gb2312_utf8(int index) { static void test_gb2312_utf8_to_eci(int index) { - testStart(""); - - int ret; struct item { int eci; int full_multibyte; @@ -221,23 +223,27 @@ static void test_gb2312_utf8_to_eci(int index) { /* 42*/ { 30, 0, "詰", -1, 0, 2, { 0x7D + 0x80, 0x7E + 0x80 }, "EUC-KR U+8A70 (0xFDFE)" }, /* 43*/ { 30, 1, "詰", -1, 0, 2, { 0x7D + 0x80, 0x7E + 0x80 }, "EUC-KR 0xFDFE > 0xF7FE so not in GB 2312 Hanzi mode range" }, }; - - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length, ret; unsigned int gbdata[20]; - for (int i = 0; i < data_size; i++) { + testStart("test_gb2312_utf8_to_eci"); + + for (i = 0; i < data_size; i++) { + int ret_length; if (index != -1 && i != index) continue; - int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - int ret_length = length; + length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; + ret_length = length; ret = gb2312_utf8_to_eci(data[i].eci, (unsigned char *) 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) { + int j; assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < (int) ret_length; j++) { + for (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]); } } @@ -248,8 +254,6 @@ static void test_gb2312_utf8_to_eci(int index) { static void test_gb2312_cpy(int index) { - testStart(""); - struct item { int full_multibyte; char *data; @@ -272,21 +276,25 @@ static void test_gb2312_cpy(int index) { /* 8*/ { 0, "\241\240\241\376\367\376\367\377", -1, 0, 8, { 0xA1, 0xA0, 0xA1, 0xFE, 0xF7, 0xFE, 0xF7, 0xFF }, "" }, /* 9*/ { 1, "\241\240\241\376\367\376\367\377", -1, 0, 6, { 0xA1, 0xA0, 0xA1FE, 0xF7FE, 0xF7, 0xFF }, "" }, }; - - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length; unsigned int gbdata[20]; - for (int i = 0; i < data_size; i++) { + testStart("test_gb2312_cpy"); + + for (i = 0; i < data_size; i++) { + int ret_length; + int j; if (index != -1 && i != index) continue; - int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - int ret_length = length; + length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; + ret_length = length; gb2312_cpy((unsigned char *) data[i].data, &ret_length, gbdata, data[i].full_multibyte); assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < (int) ret_length; j++) { + for (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_gif.c b/backend/tests/test_gif.c index 37d2c832..1664a1fa 100644 --- a/backend/tests/test_gif.c +++ b/backend/tests/test_gif.c @@ -1,6 +1,6 @@ /* libzint - the open source barcode library - Copyright (C) 2020 Robin Stuart + Copyright (C) 2020 - 2021 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -35,14 +35,6 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) static void test_pixel_plot(int index, int debug) { - testStart(""); - - if (!testUtilHaveIdentify()) { - testSkip("ImageMagick identify not available"); - return; - } - - int ret; struct item { int width; int height; @@ -63,16 +55,26 @@ static void test_pixel_plot(int index, int debug) { /* 9*/ { 19, 32, "WWCWBWMWRWYWGWKCCWCMCRCYCGCKBWBCBBMBRBYBGBKMWMCMBMMRMYMGMKRWRCRBRMRRYRGRKYWYCYBYMYRYYGYKGWGCGBGMGRGYGGKKWK", 1 }, // Two LZW blocks, last size 1 }; int data_size = ARRAY_SIZE(data); + int i, ret; + struct zint_symbol *symbol; char *gif = "out.gif"; char data_buf[19 * 32 + 1]; // 19 * 32 == 608 - for (int i = 0; i < data_size; i++) { + testStart("test_pixel_plot"); + + if (!testUtilHaveIdentify()) { + testSkip("ImageMagick identify not available"); + return; + } + + for (i = 0; i < data_size; i++) { + int size; if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); strcpy(symbol->outfile, gif); @@ -81,7 +83,7 @@ static void test_pixel_plot(int index, int debug) { symbol->bitmap_height = data[i].height; symbol->debug |= debug; - int size = data[i].width * data[i].height; + size = data[i].width * data[i].height; assert_nonzero(size < (int) sizeof(data_buf), "i:%d gif_pixel_plot size %d < sizeof(data_buf) %d\n", i, size, (int) sizeof(data_buf)); if (data[i].repeat) { @@ -109,10 +111,133 @@ static void test_pixel_plot(int index, int debug) { testFinish(); } +static void test_print(int index, int generate, int debug) { + + struct item { + int symbology; + int whitespace_width; + int whitespace_height; + int option_1; + int option_2; + float scale; + float dot_size; + char *fgcolour; + char *bgcolour; + char *data; + char *expected_file; + }; + struct item data[] = { + /* 0*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 0, 0, "", "", "12", "dotcode_1.0.gif" }, + /* 1*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 0, 0.1, "", "", "12", "dotcode_1.0_ds0.1.gif" }, + /* 2*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 0, 1.1, "", "", "12", "dotcode_1.0_ds1.1.gif" }, + /* 3*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 1.5, 0, "", "", "12", "dotcode_1.5.gif" }, + /* 4*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 1.5, 0.4, "", "", "12", "dotcode_1.5_ds0.4.gif" }, + /* 5*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 1.5, 1.1, "", "", "12", "dotcode_1.5_ds1.1.gif" }, + /* 6*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 1.5, 2.1, "", "", "12", "dotcode_1.5_ds2.1.gif" }, + /* 7*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 2, 0, "", "", "12", "dotcode_2.0.gif" }, + /* 8*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 2, 0.9, "", "", "12", "dotcode_2.0_ds0.9.gif" }, + /* 9*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 2, 1.1, "", "", "12", "dotcode_2.0_ds1.1.gif" }, + /* 10*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 3, 0, "", "", "12", "dotcode_3.0.gif" }, + /* 11*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 3, 0.4, "", "", "12", "dotcode_3.0_ds0.4.gif" }, + /* 12*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 3, 1.1, "", "", "12", "dotcode_3.0_ds1.1.gif" }, + /* 13*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 3.5, 0, "", "", "12", "dotcode_3.5.gif" }, + /* 14*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 3.5, 0.4, "", "", "12", "dotcode_3.5_ds0.4.gif" }, + /* 15*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 3.5, 1.1, "", "", "12", "dotcode_3.5_ds1.1.gif" }, + /* 16*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 5, 0, "", "", "12", "dotcode_5.0.gif" }, + /* 17*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 5, 0.2, "", "", "12", "dotcode_5.0_ds0.2.gif" }, + /* 18*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 5, 1.1, "", "", "12", "dotcode_5.0_ds1.1.gif" }, + /* 19*/ { BARCODE_DOTCODE, -1, -1, -1, -1, 5, 1.7, "", "", "12", "dotcode_5.0_ds1.7.gif" }, + }; + int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; + + const char *data_dir = "/backend/tests/data/gif"; + const char *gif = "out.gif"; + char expected_file[4096]; + char escaped[1024]; + int escaped_size = 1024; + + int have_identify = testUtilHaveIdentify(); + + testStart("test_print"); + + if (generate) { + char data_dir_path[1024]; + assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); + if (!testUtilDirExists(data_dir_path)) { + ret = testUtilMkDir(data_dir_path); + assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_dir_path, ret, errno, strerror(errno)); + } + } + + for (i = 0; i < data_size; i++) { + + if (index != -1 && i != index) continue; + + symbol = ZBarcode_Create(); + assert_nonnull(symbol, "Symbol not created\n"); + + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + if (data[i].whitespace_width != -1) { + symbol->whitespace_width = data[i].whitespace_width; + } + if (data[i].whitespace_height != -1) { + symbol->whitespace_height = data[i].whitespace_height; + } + if (data[i].scale) { + symbol->scale = data[i].scale; + } + if (data[i].dot_size) { + symbol->dot_size = data[i].dot_size; + } + if (*data[i].fgcolour) { + strcpy(symbol->fgcolour, data[i].fgcolour); + } + if (*data[i].bgcolour) { + strcpy(symbol->bgcolour, data[i].bgcolour); + } + + ret = ZBarcode_Encode(symbol, (unsigned char *) 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, gif); + 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); + + assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i); + + if (generate) { + printf(" /*%3d*/ { %s, %d, %d, %d, %d, %.5g, %.5g, \"%s\", \"%s\", \"%s\", \"%s\" },\n", + i, testUtilBarcodeName(data[i].symbology), data[i].whitespace_width, data[i].whitespace_height, + data[i].option_1, data[i].option_2, data[i].scale, data[i].dot_size, data[i].fgcolour, data[i].bgcolour, + testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].expected_file); + ret = testUtilRename(symbol->outfile, expected_file); + assert_zero(ret, "i:%d testUtilRename(%s, %s) ret %d != 0\n", i, symbol->outfile, expected_file, ret); + 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 { + assert_nonzero(testUtilExists(symbol->outfile), "i:%d testUtilExists(%s) == 0\n", i, symbol->outfile); + assert_nonzero(testUtilExists(expected_file), "i:%d testUtilExists(%s) == 0\n", i, expected_file); + + 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); + } + + ZBarcode_Delete(symbol); + } + + testFinish(); +} + 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)); diff --git a/backend/tests/test_gridmtx.c b/backend/tests/test_gridmtx.c index 84fd3b7c..417743fd 100644 --- a/backend/tests/test_gridmtx.c +++ b/backend/tests/test_gridmtx.c @@ -33,9 +33,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { char *pattern; int length; @@ -53,20 +50,24 @@ static void test_large(int index, int debug) { /* 4*/ { "\200", 1144, ZINT_ERROR_TOO_LONG, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[2753]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); - int length = testUtilSetSymbol(symbol, BARCODE_GRIDMATRIX, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_GRIDMATRIX, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -84,9 +85,6 @@ static void test_large(int index, int debug) { static void test_options(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int option_1; @@ -111,15 +109,19 @@ static void test_options(int index, int debug) { /* 11*/ { "123456789012345678", 6, 0, 0, 0, 30 }, // ECC > max ECC 5 so ignored and auto-settings version 2, ECC 4 used }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_options"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_GRIDMATRIX, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_GRIDMATRIX, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt); @@ -139,9 +141,6 @@ static void test_options(int index, int debug) { static void test_input(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int eci; @@ -248,19 +247,23 @@ static void test_input(int index, int generate, int debug) { /* 87*/ { UNICODE_MODE, 900, -1, "é", 0, 900, "63 42 18 01 61 6A 20", "ECI-900 B2 (no conversion)" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_GRIDMATRIX, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_GRIDMATRIX, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); @@ -286,9 +289,6 @@ static void test_input(int index, int generate, int debug) { static void test_encode(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { char *data; int input_mode; @@ -400,15 +400,19 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_GRIDMATRIX, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_GRIDMATRIX, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -445,11 +449,6 @@ static void test_encode(int index, int generate, int debug) { // Not a real test, just performance indicator static void test_perf(int index, int debug) { - if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ - return; - } - - int ret; struct item { int symbology; int input_mode; @@ -480,20 +479,27 @@ static void test_perf(int index, int debug) { 0, 162, 162, "970 chars, mixed modes" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer; - for (int i = 0; i < data_size; i++) { + if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ + return; + } + + for (i = 0; i < data_size; i++) { + int j; 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(); + for (j = 0; j < TEST_PERF_ITERATIONS; j++) { + 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); + 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 --git a/backend/tests/test_gs1.c b/backend/tests/test_gs1.c index 7a7b31ba..2f84fd08 100644 --- a/backend/tests/test_gs1.c +++ b/backend/tests/test_gs1.c @@ -36,11 +36,6 @@ */ static void test_gs1_reduce(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; int input_mode; @@ -195,17 +190,23 @@ static void test_gs1_reduce(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char *text; char bwipp_buf[8196]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_gs1_reduce"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); if (strlen(data[i].composite)) { @@ -214,7 +215,7 @@ static void test_gs1_reduce(int index, int generate, int debug) { } else { text = data[i].data; } - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, text, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, text, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); @@ -255,9 +256,6 @@ static void test_gs1_reduce(int index, int generate, int debug) { static void test_hrt(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -290,14 +288,18 @@ static void test_hrt(int index, int debug) { /* 19*/ { BARCODE_DBAR_EXPSTK_CC, "[01]12345678901231[20]12", "[21]12345", 0, "" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char *text; - for (int i = 0; i < data_size; i++) { + testStart("test_hrt"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); if (strlen(data[i].composite)) { @@ -306,7 +308,7 @@ static void test_hrt(int index, int debug) { } else { text = data[i].data; } - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, text, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, text, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, data[i].ret, ret, symbol->errtxt); @@ -323,9 +325,6 @@ static void test_hrt(int index, int debug) { static void test_gs1_verify(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int ret; @@ -1311,18 +1310,22 @@ static void test_gs1_verify(int index, int debug) { /*975*/ { "[253]12345678901284[01]12345678901231[3901]12345678901234[20]12", 0, "25312345678901284[0112345678901231390112345678901234[2012" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char reduced[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_gs1_verify"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = strlen(data[i].data); + length = strlen(data[i].data); ret = gs1_verify(symbol, (unsigned char *) data[i].data, length, (unsigned char *) reduced); assert_equal(ret, data[i].ret, "i:%d ret %d != %d (length %d \"%s\") %s\n", i, ret, data[i].ret, length, data[i].data, symbol->errtxt); @@ -1339,9 +1342,6 @@ static void test_gs1_verify(int index, int debug) { static void test_gs1_lint(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int ret; @@ -1715,18 +1715,22 @@ static void test_gs1_lint(int index, int debug) { /*362*/ { "[8112]A61234567890121234560123456", ZINT_WARN_NONCOMPLIANT, "8112A61234567890121234560123456", "261: AI (8112) position 1: Non-numeric Coupon Format" }, // couponposoffer }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char reduced[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_gs1_lint"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = strlen(data[i].data); + length = strlen(data[i].data); ret = gs1_verify(symbol, (unsigned char *) data[i].data, length, (unsigned char *) reduced); assert_equal(ret, data[i].ret, "i:%d ret %d != %d (length %d \"%s\") %s\n", i, ret, data[i].ret, length, data[i].data, symbol->errtxt); @@ -1744,9 +1748,6 @@ static void test_gs1_lint(int index, int debug) { static void test_input_mode(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -1803,15 +1804,19 @@ static void test_input_mode(int index, int debug) { /* 42*/ { BARCODE_QRCODE, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char *text; struct zint_symbol previous_symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_input_mode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); if (strlen(data[i].composite)) { @@ -1820,7 +1825,7 @@ static void test_input_mode(int index, int debug) { } else { text = data[i].data; } - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, data[i].output_options, text, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, data[i].output_options, text, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) text, 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_hanxin.c b/backend/tests/test_hanxin.c index c98a14dc..40c6f038 100644 --- a/backend/tests/test_hanxin.c +++ b/backend/tests/test_hanxin.c @@ -33,9 +33,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { char *pattern; int length; @@ -53,20 +50,24 @@ static void test_large(int index, int debug) { /* 4*/ { "\200", 3262, ZINT_ERROR_TOO_LONG, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[7829]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); - int length = testUtilSetSymbol(symbol, BARCODE_HANXIN, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_HANXIN, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -84,9 +85,6 @@ static void test_large(int index, int debug) { static void test_options(int index, int debug) { - testStart(""); - - int ret; struct item { int option_1; int option_2; @@ -111,15 +109,19 @@ static void test_options(int index, int debug) { /* 11*/ { -1, -1, "1234567890123456789012345678901234567890123", 0, 0, 25 }, // Version auto-set to 2, ECC auto-set to 2 }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_options"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_HANXIN, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_HANXIN, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt); @@ -139,9 +141,6 @@ static void test_options(int index, int debug) { static void test_input(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int eci; @@ -244,19 +243,23 @@ static void test_input(int index, int generate, int debug) { /* 78*/ { UNICODE_MODE, 900, -1, "é", -1, 0, 900, "88 38 43 00 16 1D 48 00 00", "ECI-900 B2 (no conversion)" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_HANXIN, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, data[i].option_3, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_HANXIN, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, data[i].option_3, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -281,9 +284,6 @@ static void test_input(int index, int generate, int debug) { static void test_encode(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int option_1; @@ -1085,7 +1085,7 @@ static void test_encode(int index, int generate, int debug) { "1110101000010110101111100111011100000010111011110111001101000101010111000001011011001010101011010000000110000011001001000011001101010101000000001" "1110101010101010101111111111111111101010101010101010101111111111111111101010101010101010101111111111111111101010101010101010101111111111001111111" }, - /* 17*/ { UNICODE_MODE | ESCAPE_MODE, -1, 84, -1, "本标准规定了一种矩阵式二维条码——汉信码的码制以及编译码方法。本标准中对汉信码的码图方案、信息编码方法、纠错编译码算法、信息排布方法、参考译码算法等内容进行了详细的描述,汉信码可高效表示《GB 18030—2000 信息技术 信息交换用汉字编码字符集基本集的扩充》中的汉字信息,并具有数据容量大、抗畸变和抗污损能力强、外观美观等特点,适合于在我国各行业的广泛应用。 测试文本,测试人:施煜,边峥,修兴强,袁娲,测试目的:汉字表示,测试版本:84\015\012本标准规定了一种矩阵式二维条码——汉信码的码制以及编译码方法。本标准中对汉信码的码图方案、信息编码方法、纠错编译码算法、信息排布方法、参考译码算法等内容进行了详细的描述,汉信码可高效表示《GB 18030—2000 信息技术 信息交换用汉字编码字符集基本集的扩充》中的汉字信息,并具有数据容量大、抗畸变和抗污损能力强、外观美观等特点,适合于在我国各行业的广泛应用。 测试文本,测试人:施煜,边峥,修兴强,袁娲,测试目的:汉字表示,测试版本:84\015\012本标准规定了一种矩阵式二维条码——汉信码的码制以及编译码方法。本标准中对汉信码的码图方案、信息编码方法、纠错编译码算法、信息排布方法、参考译码算法等内容进行了详细的描述,汉信码可高效表示《GB 18030—2000 信息技术 信息交换用汉字编码字符集基本集的扩充》中的汉字信息,并具有数据容量大、抗畸变和抗污损能力强、外观美观等特点,适合于在我国各行业的广泛应用。 测试文本,测试人:施煜,边峥,修兴强,袁娲,测试目的:汉字表示,测试版本:40本标准规定了一种矩阵式二维条码——汉信码的码制以及编译码方法。本标准中对汉信码的码图方案、信息编码方法、纠错编译码算法、信息排布方法、参考译码算法等内容进行了详细的描述,汉信码可高效表示《GB 18030—2000 信息技术 信息交换用汉字编码字符集基本集的扩充》中的汉字信息,并具有数据容量大、抗畸变和抗污损能力强、外观美观等特点,适合于在我国各行业的广泛应用。 测试文本,测试人:施煜,边峥,修兴强,袁娲,测试目的:汉字表示,测试版本:84\015\012", 0, 189, 189, "ISO 20830 Draft Figure 9 **NOT SAME** different encodation, Binary mode not used by figure", + /* 17*/ { UNICODE_MODE | ESCAPE_MODE, -1, 84, -1, "本标准规定了一种矩阵式二维条码——汉信码的码制以及编译码方法。本标准中对汉信码的码图方案、信息编码方法、纠错编译码算法、信息排布方法、参考译码算法等内容进行了详细的描述,汉信码可高效表示《GB 18030—2000 信息技术 信息交换用汉字编码字符集基本集的扩充》中的汉字信息,并具有数据容量大、抗畸变和抗污损能力强、外观美观等特点,适合于在我国各行业的广泛应用。 测试文本,测试人:施煜,边峥,修兴强,袁娲,测试目的:汉字表示,测试版本:84\015\012本标准规定了一种矩阵式二维条码——汉信码的码制以及编译码方法。本标准中对汉信码的码图方案、信息编码方法、纠错编译码算法、信息排布方法、参考译码算法等内容进行了详细的描述,汉信码可高效表示《GB 18030—2000 信息技术 信息交换用汉字编码字符集基本集的扩充》中的汉字信息,并具有数据容量大、抗畸变和抗污损能力强、外观美观等特点,适合于在我国各行业的广泛应用。 测试文本,测试人:施煜,边峥,修兴强,袁娲,测试目的:汉字表示,测试版本:84\015\012本标准规定了一种矩阵式二维条码——汉信码的码制以及编译码方法。本标准中对汉信码的码图方案、信息编码方法、纠错编译码算法、信息排布方法、参考译码算法等内容进行了详细的描述,汉信码可高效表示《GB 18030—2000 信息技术 信息交换用汉字编码字符集基本集的扩充》中的汉字信息,并具有数据容量大、抗畸变和抗污损能力强、外观美观等特点,适合于在我国各行业的广泛应用。 测试文本,测试人:施煜,边峥,修兴强,袁娲,测试目的:汉字表示,测试版本:40本标准规定了一种矩阵式二维条码——汉信码的码制以及编译码方" "法。本标准中对汉信码的码图方案、信息编码方法、纠错编译码算法、信息排布方法、参考译码算法等内容进行了详细的描述,汉信码可高效表示《GB 18030—2000 信息技术 信息交换用汉字编码字符集基本集的扩充》中的汉字信息,并具有数据容量大、抗畸变和抗污损能力强、外观美观等特点,适合于在我国各行业的广泛应用。 测试文本,测试人:施煜,边峥,修兴强,袁娲,测试目的:汉字表示,测试版本:84\015\012", 0, 189, 189, "ISO 20830 Draft Figure 9 **NOT SAME** different encodation, Binary mode not used by figure", "111111100111111111100010101000011101011111111111111111000111101110100101111111111111111111100101100001010111111111111111101100011011101001011111111111111110100111001010010101111010101111111" "100000001000000000111000010110101000000000000000000011110111100101100000000000000000001000111110110011000000000000000000110001110111000100000000000000000010001110000000010001110110100000001" "101111100010010100101110011110110011111011110000000011110101010100001011100010110000001010100001111001101000000101101000110110001100001101001011001001110011110001101000100110111010001111101" @@ -1447,17 +1447,21 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[8192]; - for (int i = 0; i < data_size; i++) { + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_HANXIN, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_HANXIN, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -1495,11 +1499,6 @@ static void test_encode(int index, int generate, int debug) { // Not a real test, just performance indicator static void test_perf(int index, int debug) { - if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ - return; - } - - int ret; struct item { int symbology; int input_mode; @@ -1547,20 +1546,26 @@ static void test_perf(int index, int debug) { 0, 147, 147, "1470 chars, Region 1 and Text" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer; - for (int i = 0; i < data_size; i++) { + if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ + return; + } + + for (i = 0; i < data_size; i++) { + int j; if (index != -1 && i != index) continue; diff_encode = diff_buffer = 0; - for (int j = 0; j < TEST_PERF_ITERATIONS; j++) { + for (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); + 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 --git a/backend/tests/test_imail.c b/backend/tests/test_imail.c index 19a2a3ac..2d5f60f5 100644 --- a/backend/tests/test_imail.c +++ b/backend/tests/test_imail.c @@ -53,7 +53,7 @@ static void test_csv(int index, int debug) { int ret; int lc = 0; - testStart(""); + testStart("test_csv"); assert_nonzero(testUtilDataPath(csvfile, sizeof(csvfile), "/backend/tests/data/imail/usps/", "uspsIMbEncoderTestCases.csv"), "testUtilDataPath == 0\n"); @@ -62,6 +62,8 @@ static void test_csv(int index, int debug) { assert_nonnull(fd, "fopen(%s) == NULL", csvfile); while (fgets(buffer, sizeof(buffer), fd) != NULL) { + char *b; + struct zint_symbol *symbol; lc++; @@ -75,7 +77,7 @@ static void test_csv(int index, int debug) { id[0] = tracking_code[0] = routing_code[0] = expected_daft[0] = return_code[0] = '\0'; - char *b = testUtilReadCSVField(buffer, id, sizeof(id)); + 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); @@ -101,7 +103,7 @@ static void test_csv(int index, int debug) { assert_nonzero(strlen(data), "lc:%d strlen(data) == 0", lc); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->symbology = BARCODE_USPS_IMAIL; @@ -132,9 +134,6 @@ static void test_csv(int index, int debug) { static void test_hrt(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; char *expected; @@ -144,15 +143,19 @@ static void test_hrt(int index, int debug) { /* 0*/ { "53379777234994544928-51135759461", "" }, // None }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_hrt"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_USPS_IMAIL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_USPS_IMAIL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt); @@ -167,9 +170,6 @@ static void test_hrt(int index, int debug) { static void test_input(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int ret; @@ -193,15 +193,19 @@ static void test_input(int index, int debug) { /* 12*/ { "12345678901234567890-12345678901", 0, 3, 129 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_USPS_IMAIL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_USPS_IMAIL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -219,11 +223,6 @@ static void test_input(int index, int debug) { 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 { char *data; int ret; @@ -241,19 +240,25 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_USPS_IMAIL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_USPS_IMAIL, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -266,10 +271,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); diff --git a/backend/tests/test_iso3166.c b/backend/tests/test_iso3166.c index 1e1ff829..8c509658 100644 --- a/backend/tests/test_iso3166.c +++ b/backend/tests/test_iso3166.c @@ -34,9 +34,6 @@ static void test_numeric(int index) { - testStart(""); - - int ret; struct item { int data; int ret; @@ -378,8 +375,11 @@ static void test_numeric(int index) { /*332*/ { 2000, 0 }, }; int data_size = ARRAY_SIZE(data); + int i, ret; - for (int i = 0; i < data_size; i++) { + testStart("test_numeric"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; @@ -420,17 +420,16 @@ static int bc_iso3166_numeric(int cc) { /*VIR*/ 850, /*BFA*/ 854, /*URY*/ 858, /*UZB*/ 860, /*VEN*/ 862, /*WLF*/ 876, /*WSM*/ 882, /*YEM*/ 887, /*ZMB*/ 894, }; - int s = 0, e = sizeof(codes) / sizeof(codes[0]) - 1; + int s = 0, e = ARRAY_SIZE(codes) - 1; while (s <= e) { int m = (s + e) / 2; - if (codes[m] == cc) { - return 1; - } if (codes[m] < cc) { s = m + 1; - } else { + } else if (codes[m] > cc) { e = m - 1; + } else { + return 1; } } @@ -439,11 +438,11 @@ static int bc_iso3166_numeric(int cc) { static void test_numeric_bc(void) { - testStart(""); + int i, ret, bc_ret; - int ret, bc_ret; + testStart("test_numeric_bc"); - for (int i = 0; i < 1001; i++) { + for (i = 0; i < 1001; i++) { ret = iso3166_numeric(i); bc_ret = bc_iso3166_numeric(i); assert_equal(ret, bc_ret, "i:%d ret %d != bc_ret %d\n", i, ret, bc_ret); @@ -454,9 +453,6 @@ static void test_numeric_bc(void) { static void test_alpha2(int index) { - testStart(""); - - int ret; struct item { const char *data; int ret; @@ -679,8 +675,11 @@ static void test_alpha2(int index) { /*213*/ { "\377", 0 }, }; int data_size = ARRAY_SIZE(data); + int i, ret; - for (int i = 0; i < data_size; i++) { + testStart("test_alpha2"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; @@ -726,13 +725,12 @@ static int bc_iso3166_alpha2(const char *cc) { while (s <= e) { int m = (s + e) / 2; int cmp = strncmp(codes[m], cc, 2); - if (cmp == 0) { - return 1; - } if (cmp < 0) { s = m + 1; - } else { + } else if (cmp > 0) { e = m - 1; + } else { + return 1; } } @@ -741,13 +739,14 @@ static int bc_iso3166_alpha2(const char *cc) { static void test_alpha2_bc(void) { - testStart(""); - - int ret, bc_ret; + int i, ret, bc_ret; char data[2]; - for (int i = 0; i < 128; i++) { - for (int j = 0; j < 128; j++) { + testStart("test_alpha2_bc"); + + for (i = 0; i < 128; i++) { + int j; + for (j = 0; j < 128; j++) { data[0] = i; data[1] = j; ret = iso3166_alpha2(data); diff --git a/backend/tests/test_iso4217.c b/backend/tests/test_iso4217.c index 422c9ef7..f5f7a27c 100644 --- a/backend/tests/test_iso4217.c +++ b/backend/tests/test_iso4217.c @@ -34,9 +34,6 @@ static void test_numeric(int index) { - testStart(""); - - int ret; struct item { int data; int ret; @@ -431,8 +428,11 @@ static void test_numeric(int index) { /*385*/ { 2000, 0 }, }; int data_size = ARRAY_SIZE(data); + int i, ret; - for (int i = 0; i < data_size; i++) { + testStart("test_numeric"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; @@ -466,17 +466,16 @@ static int bc_iso4217_numeric(int cc) { /*UAH*/ 980, /*GEL*/ 981, /*BOV*/ 984, /*PLN*/ 985, /*BRL*/ 986, /*CLF*/ 990, /*XSU*/ 994, /*USN*/ 997, /*XXX*/ 999, }; - int s = 0, e = sizeof(codes) / sizeof(codes[0]) - 1; + int s = 0, e = ARRAY_SIZE(codes) - 1; while (s <= e) { int m = (s + e) / 2; - if (codes[m] == cc) { - return 1; - } if (codes[m] < cc) { s = m + 1; - } else { + } else if (codes[m] > cc) { e = m - 1; + } else { + return 1; } } @@ -485,11 +484,11 @@ static int bc_iso4217_numeric(int cc) { static void test_numeric_bc(void) { - testStart(""); + int i, ret, bc_ret; - int ret, bc_ret; + testStart("test_numeric_bc"); - for (int i = 0; i < 1001; i++) { + for (i = 0; i < 1001; i++) { ret = iso4217_numeric(i); bc_ret = bc_iso4217_numeric(i); assert_equal(ret, bc_ret, "i:%d ret %d != bc_ret %d\n", i, ret, bc_ret); diff --git a/backend/tests/test_ksx1001.c b/backend/tests/test_ksx1001.c index 9040242f..1fecd675 100644 --- a/backend/tests/test_ksx1001.c +++ b/backend/tests/test_ksx1001.c @@ -35,6 +35,9 @@ // As control convert to KS X 1001 using simple table generated from https://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/KSC/KSX1001.TXT plus simple processing static int ksx1001_wctomb_zint2(unsigned int *r, unsigned int wc) { + int tab_length, start_i, end_i; + int i; + if (wc < 0x80) { return 0; } @@ -50,10 +53,10 @@ static int ksx1001_wctomb_zint2(unsigned int *r, unsigned int wc) { *r = 0x2268; return 2; } - int tab_length = ARRAY_SIZE(test_ksx1001_tab); - int start_i = test_ksx1001_tab_ind[wc >> 10]; - int end_i = start_i + 0x800 > tab_length ? tab_length : start_i + 0x800; - for (int i = start_i; i < end_i; i += 2) { + tab_length = ARRAY_SIZE(test_ksx1001_tab); + start_i = test_ksx1001_tab_ind[wc >> 10]; + end_i = start_i + 0x800 > tab_length ? tab_length : start_i + 0x800; + for (i = start_i; i < end_i; i += 2) { if (test_ksx1001_tab[i + 1] == wc) { *r = test_ksx1001_tab[i]; return *r > 0xFF ? 2 : 1; @@ -64,12 +67,13 @@ static int ksx1001_wctomb_zint2(unsigned int *r, unsigned int wc) { static void test_ksx1001_wctomb_zint(void) { - testStart(""); - int ret, ret2; unsigned int val, val2; + unsigned i; - for (unsigned int i = 0; i < 0xFFFE; i++) { + testStart("test_ksx1001_wctomb_zint"); + + for (i = 0; i < 0xFFFE; i++) { if (i >= 0xD800 && i <= 0xDFFF) { // UTF-16 surrogates continue; } diff --git a/backend/tests/test_large.c b/backend/tests/test_large.c index 172fb5c5..81f76cff 100644 --- a/backend/tests/test_large.c +++ b/backend/tests/test_large.c @@ -51,9 +51,6 @@ int clz_u64(uint64_t x); static void test_clz_u64(int index) { - testStart(""); - - int ret; struct item { uint64_t s; int ret; @@ -188,8 +185,11 @@ static void test_clz_u64(int index) { /*125*/ { 0xFFFFFFFFFFFFFFFF, 0 }, }; int data_size = ARRAY_SIZE(data); + int i, ret; - for (int i = 0; i < data_size; i++) { + testStart("test_clz_u64"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; @@ -202,8 +202,6 @@ static void test_clz_u64(int index) { static void test_load(int index) { - testStart(""); - struct item { large_int t; large_int s; @@ -217,19 +215,22 @@ static void test_load(int index) { /* 3*/ { LI(1, 1), LI(2, 3), LI(2, 3) }, }; int data_size = ARRAY_SIZE(data); + int i; char t_dump[35]; char expected_dump[35]; - for (int i = 0; i < data_size; i++) { + testStart("test_load"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; large_load(&data[i].t, &data[i].s); - assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", + assert_equalu64(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump)); - assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", + assert_equalu64(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump)); } @@ -238,8 +239,6 @@ static void test_load(int index) { static void test_load_str_u64(int index) { - testStart(""); - struct item { large_int t; const char *s; @@ -257,19 +256,22 @@ static void test_load_str_u64(int index) { /* 6*/ { LI(2, 2), "123A1X", -1, LI(123, 0) }, // Only reads decimal }; int data_size = ARRAY_SIZE(data); + int i; char t_dump[35]; char expected_dump[35]; - for (int i = 0; i < data_size; i++) { + testStart("test_load_str_u64"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; large_load_str_u64(&data[i].t, (unsigned char *) data[i].s, data[i].length == -1 ? (int) strlen(data[i].s) : data[i].length); - assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", + assert_equalu64(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump)); - assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", + assert_equalu64(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump)); } @@ -278,8 +280,6 @@ static void test_load_str_u64(int index) { static void test_add_u64(int index) { - testStart(""); - struct item { large_int t; uint64_t s; @@ -300,19 +300,22 @@ static void test_add_u64(int index) { /* 10*/ { LI(0x0000000000000001, 0xFFFFFFFFFFFFFFFF), 0xFFFFFFFFFFFFFFFF, LI(0, 0) }, // Overflow }; int data_size = ARRAY_SIZE(data); + int i; char t_dump[35]; char expected_dump[35]; - for (int i = 0; i < data_size; i++) { + testStart("test_add_u64"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; large_add_u64(&data[i].t, data[i].s); - assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", + assert_equalu64(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump)); - assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", + assert_equalu64(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump)); } @@ -321,8 +324,6 @@ static void test_add_u64(int index) { static void test_sub_u64(int index) { - testStart(""); - struct item { large_int t; uint64_t s; @@ -343,19 +344,22 @@ static void test_sub_u64(int index) { /* 10*/ { LI(0, 0), 1, LI(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF) }, }; int data_size = ARRAY_SIZE(data); + int i; char t_dump[35]; char expected_dump[35]; - for (int i = 0; i < data_size; i++) { + testStart("test_sub_u64"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; large_sub_u64(&data[i].t, data[i].s); - assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", + assert_equalu64(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump)); - assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", + assert_equalu64(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump)); } @@ -364,8 +368,6 @@ static void test_sub_u64(int index) { static void test_mul_u64(int index) { - testStart(""); - struct item { large_int t; uint64_t s; @@ -399,19 +401,22 @@ static void test_mul_u64(int index) { /* 23*/ { LI(0xFFFFFFFFFFFFFFFF, 0), 0xFFFFFFFFFFFFFFFF, LI(1, 0xFFFFFFFFFFFFFFFE) }, }; int data_size = ARRAY_SIZE(data); + int i; char t_dump[35]; char expected_dump[35]; - for (int i = 0; i < data_size; i++) { + testStart("test_mul_u64"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; large_mul_u64(&data[i].t, data[i].s); - assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", + assert_equalu64(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump)); - assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", + assert_equalu64(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump)); } @@ -420,8 +425,6 @@ static void test_mul_u64(int index) { static void test_div_u64(int index) { - testStart(""); - uint64_t r; struct item { large_int t; @@ -523,21 +526,24 @@ static void test_div_u64(int index) { /* 89*/ { LI(0x4ABC16A2E5C00736, 0x16907B2A2), 1365, 1, LI(0xD93B96FDAE65FA61, 0x43B5AC) }, }; int data_size = ARRAY_SIZE(data); + int i; char t_dump[35]; char expected_dump[35]; - for (int i = 0; i < data_size; i++) { + testStart("test_div_u64"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; r = large_div_u64(&data[i].t, data[i].s); - assert_equal(r, data[i].expected_r, "i:%d r %" LX_FMT "u (0x%" LX_FMT "X) != expected_r %" LX_FMT "u (0x%" LX_FMT "X)\n", + assert_equalu64(r, data[i].expected_r, "i:%d r %" LX_FMT "u (0x%" LX_FMT "X) != expected_r %" LX_FMT "u (0x%" LX_FMT "X)\n", i, r, r, data[i].expected_r, data[i].expected_r); - assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", + assert_equalu64(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump)); - assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", + assert_equalu64(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump)); } @@ -546,8 +552,6 @@ static void test_div_u64(int index) { static void test_unset_bit(int index) { - testStart(""); - struct item { large_int t; int s; @@ -688,19 +692,22 @@ static void test_unset_bit(int index) { /*130*/ { LI(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 128, LI(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF) }, }; int data_size = ARRAY_SIZE(data); + int i; char t_dump[35]; char expected_dump[35]; - for (int i = 0; i < data_size; i++) { + testStart("test_unset_bit"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; large_unset_bit(&data[i].t, data[i].s); - assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", + assert_equalu64(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump)); - assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", + assert_equalu64(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump)); } @@ -709,8 +716,6 @@ static void test_unset_bit(int index) { static void test_uint_array(int index) { - testStart(""); - struct item { large_int t; int size; @@ -754,6 +759,7 @@ static void test_uint_array(int index) { /* 32*/ { LI(0xFFFFFFFFFFFFFFFF, 0xEFFFFFFFFFFFFFFF), 127, 1, { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } }, // Truncated }; int data_size = ARRAY_SIZE(data); + int i; char t_dump[35]; char uint_dump[130 * 17 + 1]; @@ -765,7 +771,9 @@ static void test_uint_array(int index) { unsigned char uchar_array[130]; unsigned char uchar_expected_array[130]; - for (int i = 0; i < data_size; i++) { + testStart("test_uint_array"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; @@ -778,8 +786,9 @@ static void test_uint_array(int index) { testUtilUIntArrayDump(data[i].expected, data[i].size, uint_expected_dump, sizeof(uint_expected_dump))); if (data[i].bits <= 8) { + int j; memset(uchar_array, 0, sizeof(uchar_array)); - for (int j = 0; j < data[i].size; j++) { + for (j = 0; j < data[i].size; j++) { uchar_expected_array[j] = data[i].expected[j]; } @@ -796,8 +805,6 @@ static void test_uint_array(int index) { static void test_dump(int index) { - testStart(""); - struct item { large_int t; char *expected; @@ -851,10 +858,13 @@ static void test_dump(int index) { /* 44*/ { LI(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" }, }; int data_size = ARRAY_SIZE(data); + int i; char dump[35]; - for (int i = 0; i < data_size; i++) { + testStart("test_dump"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; diff --git a/backend/tests/test_library.c b/backend/tests/test_library.c index 3deadddb..aaac5907 100644 --- a/backend/tests/test_library.c +++ b/backend/tests/test_library.c @@ -32,16 +32,10 @@ #include "testcommon.h" #include #include -#ifdef _WIN32 -#include -#endif #include static void test_checks(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -102,15 +96,19 @@ static void test_checks(int index, int debug) { /* 42*/ { BARCODE_CODE128, "\200", -1, UNICODE_MODE, -1, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 245: Invalid UTF-8", -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_checks"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); if (data[i].dot_size != -1) { symbol->dot_size = data[i].dot_size; } @@ -138,9 +136,6 @@ static void test_checks(int index, int debug) { static void test_input_mode(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int input_mode; @@ -163,15 +158,19 @@ static void test_input_mode(int index, int debug) { /* 10*/ { "[01]12345678901231", GS1_MODE | 0x20, 0, GS1_MODE | 0x20 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_input_mode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_CODE49 /*Supports GS1*/, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODE49 /*Supports GS1*/, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -185,9 +184,6 @@ static void test_input_mode(int index, int debug) { static void test_escape_char_process(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int eci; @@ -227,21 +223,25 @@ static void test_escape_char_process(int index, int generate, int debug) { /* 25*/ { UNICODE_MODE, 28, "\\u5E38", 0, 12, "F1 1D EB 32 61 D9 1C 0C C2 46 C3 B2", 1, "" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; struct zint_symbol previous_symbol; char *input_filename = "test_escape.txt"; - for (int i = 0; i < data_size; i++) { + testStart("test_escape_char_process"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_DATAMATRIX, data[i].input_mode | ESCAPE_MODE, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_DATAMATRIX, data[i].input_mode | ESCAPE_MODE, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -264,19 +264,20 @@ static void test_escape_char_process(int index, int generate, int debug) { if (ret < 5) { // Test from input file - FILE *fp; + struct zint_symbol *symbol2; + fp = fopen(input_filename, "wb"); assert_nonnull(fp, "i:%d fopen(%s) failed\n", i, input_filename); assert_notequal(fputs(data[i].data, fp), EOF, "i%d fputs(%s) failed == EOF (%d)\n", i, data[i].data, ferror(fp)); assert_zero(fclose(fp), "i%d fclose() failed\n", i); - struct zint_symbol *symbol2 = ZBarcode_Create(); + symbol2 = ZBarcode_Create(); assert_nonnull(symbol, "Symbol2 not created\n"); symbol2->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - (void)testUtilSetSymbol(symbol2, BARCODE_DATAMATRIX, data[i].input_mode | ESCAPE_MODE, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + (void) testUtilSetSymbol(symbol2, BARCODE_DATAMATRIX, data[i].input_mode | ESCAPE_MODE, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode_File(symbol2, input_filename); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_File ret %d != %d (%s)\n", i, ret, data[i].ret, symbol2->errtxt); @@ -299,9 +300,6 @@ static void test_escape_char_process(int index, int generate, int debug) { static void test_cap(int index) { - testStart(""); - - unsigned int ret; struct item { int symbology; unsigned cap_flag; @@ -320,8 +318,12 @@ static void test_cap(int index) { /* 8*/ { 0, 0, 0 }, }; int data_size = ARRAY_SIZE(data); + int i; + unsigned int ret; - for (int i = 0; i < data_size; i++) { + testStart("test_cap"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; @@ -333,16 +335,17 @@ static void test_cap(int index) { } static void test_encode_file_empty(void) { - testStart(""); - - FILE *fstream; int ret; + struct zint_symbol *symbol; char filename[] = "in.bin"; + FILE *fstream; - struct zint_symbol *symbol = ZBarcode_Create(); + testStart("test_encode_file_empty"); + + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - (void)remove(filename); // In case junk hanging around + (void) remove(filename); // In case junk hanging around fstream = fopen(filename, "w+"); assert_nonnull(fstream, "fopen(%s) failed (%d)\n", filename, ferror(fstream)); @@ -361,17 +364,18 @@ static void test_encode_file_empty(void) { } static void test_encode_file_too_large(void) { - testStart(""); - + char filename[] = "in.bin"; FILE *fstream; int ret; - char filename[] = "in.bin"; + struct zint_symbol *symbol; char buf[ZINT_MAX_DATA_LEN + 1] = {0}; - struct zint_symbol *symbol = ZBarcode_Create(); + testStart("test_encode_file_too_large"); + + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - (void)remove(filename); // In case junk hanging around + (void) remove(filename); // In case junk hanging around fstream = fopen(filename, "w+"); assert_nonnull(fstream, "fopen(%s) failed (%d)\n", filename, ferror(fstream)); @@ -393,18 +397,22 @@ static void test_encode_file_too_large(void) { // #181 Nico Gunkel OSS-Fuzz static void test_encode_file_unreadable(void) { +#ifndef _WIN32 + int ret; + struct zint_symbol *symbol; + char filename[] = "in.bin"; - testStart(""); + char buf[ZINT_MAX_DATA_LEN + 1] = {0}; + int fd; +#endif + + testStart("test_encode_file_unreadable"); #ifdef _WIN32 testSkip("Test not implemented on Windows"); #else - int ret; - char filename[] = "in.bin"; - char buf[ZINT_MAX_DATA_LEN + 1] = {0}; - int fd; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); // Unreadable file @@ -429,48 +437,39 @@ static void test_encode_file_unreadable(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) { - - testStart(""); - int ret; + struct zint_symbol *symbol; char dirname[] = "in_dir"; - struct zint_symbol *symbol = ZBarcode_Create(); + testStart("test_encode_file_directory"); + + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); -#ifdef _WIN32 - ret = CreateDirectory(dirname, NULL); - assert_zero(!ret, "CreateDirectory(%s) == 0\n", dirname); -#else - (void)rmdir(dirname); // In case junk hanging around - ret = mkdir(dirname, S_IRWXU); - assert_zero(ret, "mkdir(%s, S_IRWXU) != 0 (%d: %s)\n", dirname, errno, strerror(errno)); -#endif + (void) testUtilRmDir(dirname); // In case junk hanging around + ret = testUtilMkDir(dirname); + assert_zero(ret, "testUtilMkDir(%s) %d != 0 (%d: %s)\n", dirname, ret, errno, strerror(errno)); ret = ZBarcode_Encode_File(symbol, dirname); assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt); -#ifdef _WIN32 - ret = RemoveDirectory(dirname); - assert_zero(!ret, "RemoveDirectory(%s) == 0\n", dirname); -#else - ret = rmdir(dirname); - assert_zero(ret, "rmdir(%s) != 0 (%d: %s)\n", dirname, errno, strerror(errno)); -#endif + ret = testUtilRmDir(dirname); + assert_zero(ret, "testUtilRmDir(%s) %d != 0 (%d: %s)\n", dirname, ret, errno, strerror(errno)); + ZBarcode_Delete(symbol); testFinish(); } static void test_bad_args(void) { - - testStart(""); - int ret; + struct zint_symbol *symbol; char *data = "1"; char *filename = "1.png"; char *empty = ""; + testStart("test_bad_args"); + // These just return, no error ZBarcode_Clear(NULL); ZBarcode_Delete(NULL); @@ -497,7 +496,7 @@ static void test_bad_args(void) { assert_equal(ZBarcode_Encode_File_and_Print(NULL, filename, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Print(NULL, filename, 0) != ZINT_ERROR_INVALID_DATA\n"); assert_equal(ZBarcode_Encode_File_and_Buffer(NULL, filename, 0), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File_and_Buffer(NULL, filename, 0) != ZINT_ERROR_INVALID_DATA\n"); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); // NULL data/filename @@ -543,7 +542,7 @@ static void test_bad_args(void) { // Data too big symbol->errtxt[0] = '\0'; assert_equal(ZBarcode_Encode(symbol, (unsigned char *) empty, 17401), ZINT_ERROR_TOO_LONG, "ZBarcode_Encode(symbol, empty, 17401) != ZINT_ERROR_TOO_LONG\n"); - assert_nonzero(strlen(symbol->errtxt), "ZBarcode_Encode(symbol, empty, 17401) no errtxt\n"); + assert_nonzero((int) strlen(symbol->errtxt), "ZBarcode_Encode(symbol, empty, 17401) no errtxt\n"); ZBarcode_Delete(symbol); @@ -552,15 +551,16 @@ static void test_bad_args(void) { static void test_valid_id(void) { - testStart(""); - int ret; const char *name; + int symbol_id; - for (int symbol_id = -1; symbol_id < 160; symbol_id++) { + testStart("test_valid_id"); + + for (symbol_id = -1; symbol_id < 160; symbol_id++) { ret = ZBarcode_ValidID(symbol_id); name = testUtilBarcodeName(symbol_id); - assert_nonnull(name, "testUtilBarcodeName(%d) NULL\n", symbol_id); + assert_nonnull((char *) name, "testUtilBarcodeName(%d) NULL\n", symbol_id); if (ret) { assert_equal(ret, 1, "ZBarcode_Valid(%d) != 1\n", symbol_id); assert_nonzero(*name != '\0', "testUtilBarcodeName(%d) empty when ZBarcode_Valid() true\n", symbol_id); @@ -577,9 +577,6 @@ STATIC_UNLESS_ZINT_TEST int error_tag(char error_string[100], int error_number); static void test_error_tag(int index) { - testStart(""); - - int ret; struct item { int error_number; char* data; @@ -594,14 +591,17 @@ static void test_error_tag(int index) { /* 3*/ { ZINT_ERROR_INVALID_DATA, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", ZINT_ERROR_INVALID_DATA, "Error 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123" }, }; int data_size = ARRAY_SIZE(data); + int i, ret; char errtxt[100]; - for (int i = 0; i < data_size; i++) { + testStart("test_error_tag"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - assert_nonzero(strlen(data[i].data) < 100, "i:%d strlen(data) %d >= 100\n", i, (int) strlen(data[i].data)); + assert_nonzero((int) strlen(data[i].data) < 100, "i:%d strlen(data) %d >= 100\n", i, (int) strlen(data[i].data)); strcpy(errtxt, data[i].data); ret = error_tag(errtxt, data[i].error_number); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); @@ -616,13 +616,13 @@ STATIC_UNLESS_ZINT_TEST void strip_bom(unsigned char *source, int *input_length) static void test_strip_bom(void) { - testStart(""); - - int ret; + int length, ret; char data[] = "\357\273\277A"; // U+FEFF BOM, with "A" - int length; + char bom_only[] = "\357\273\277"; // U+FEFF BOM only char buf[6]; + testStart("test_strip_bom"); + strcpy(buf, data); length = (int) strlen(buf); strip_bom((unsigned char *) buf, &length); @@ -631,8 +631,6 @@ static void test_strip_bom(void) { // BOM not stripped if only data - char bom_only[] = "\357\273\277"; // U+FEFF BOM only - strcpy(buf, bom_only); length = (int) strlen(buf); strip_bom((unsigned char *) buf, &length); diff --git a/backend/tests/test_mailmark.c b/backend/tests/test_mailmark.c index a09c4a5f..ec949991 100644 --- a/backend/tests/test_mailmark.c +++ b/backend/tests/test_mailmark.c @@ -33,9 +33,6 @@ static void test_input(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int ret; @@ -100,15 +97,19 @@ static void test_input(int index, int debug) { /* 53*/ { "01000000000000000C 23JQ4U ", ZINT_ERROR_INVALID_DATA, -1, -1 }, // F N N N L L N L S bad 1st N (non-alpha otherwise matches 2nd pattern) }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_MAILMARK, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_MAILMARK, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -130,9 +131,6 @@ static void test_input(int index, int debug) { // https://www.royalmail.com/sites/default/files/Mailmark-4-state-barcode-L-encoding-and-decoding-instructions-Sept-2015.pdf static void test_encode_vector(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int ret_encode; @@ -165,17 +163,21 @@ static void test_encode_vector(int index, int debug) { /* 19*/ { "22799999999999999C123JQ4U ", 0, 100, 30, 0, "DDATTDDATATTTAFDTAADATDDFFTFFDFFDTFAADDFAADFDFFTFFTFFDFDFTATATFDDFTFFFTFFTDDTF" }, // F N N N L L N L S }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char actual_daft[80]; - for (int i = 0; i < data_size; i++) { + testStart("test_encode_vector"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_MAILMARK, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_MAILMARK, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt); @@ -197,9 +199,6 @@ static void test_encode_vector(int index, int debug) { static void test_encode(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { char *data; int ret; @@ -217,17 +216,21 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_MAILMARK, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_MAILMARK, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -240,10 +243,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); } diff --git a/backend/tests/test_maxicode.c b/backend/tests/test_maxicode.c index 259284de..661a0236 100644 --- a/backend/tests/test_maxicode.c +++ b/backend/tests/test_maxicode.c @@ -33,9 +33,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { int option_1; int option_2; @@ -82,20 +79,24 @@ static void test_large(int index, int debug) { /* 31*/ { 6, -1, "A", 94, "", ZINT_ERROR_TOO_LONG, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[256]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); - int length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); strcpy(symbol->primary, data[i].primary); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); @@ -114,9 +115,6 @@ static void test_large(int index, int debug) { static void test_input(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int eci; @@ -174,19 +172,23 @@ static void test_input(int index, int generate, int debug) { /* 40*/ { UNICODE_MODE, -1, 1, -1, "A", -1, "", ZINT_ERROR_INVALID_OPTION, 0, "Error 550: Invalid MaxiCode Mode", "" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, data[i].input_mode, data[i].eci, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, data[i].input_mode, data[i].eci, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); strcpy(symbol->primary, data[i].primary); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); @@ -212,11 +214,6 @@ static void test_input(int index, int generate, int debug) { 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 input_mode; int option_1; @@ -795,19 +792,25 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); strcpy(symbol->primary, data[i].primary); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); @@ -821,10 +824,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); @@ -851,9 +855,6 @@ static void test_encode(int index, int generate, int debug) { static void test_best_supported_set(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { char *data; int ret; @@ -904,17 +905,21 @@ static void test_best_supported_set(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped_data[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_best_supported_set"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); @@ -926,10 +931,11 @@ static void test_best_supported_set(int index, int generate, int debug) { testUtilModulesPrint(symbol, " ", "\n"); printf(" },\n"); } else { + int width, row; + 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); @@ -946,9 +952,6 @@ static void test_best_supported_set(int index, int generate, int debug) { // #181 Nico Gunkel OSS-Fuzz static void test_fuzz(int index, int debug) { - testStart(""); - - int ret; struct item { int eci; char *data; @@ -965,15 +968,19 @@ static void test_fuzz(int index, int debug) { /* 5*/ { -1, "AaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAa", -1, ZINT_ERROR_TOO_LONG }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_fuzz"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, -1 /*input_mode*/, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, -1 /*input_mode*/, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -991,11 +998,6 @@ static void test_fuzz(int index, int debug) { // Not a real test, just performance indicator static void test_perf(int index, int debug) { - if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ - return; - } - - int ret; struct item { int symbology; int input_mode; @@ -1015,20 +1017,26 @@ static void test_perf(int index, int debug) { "339010000840001", 0, 33, 30, "Mode 2" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer; - for (int i = 0; i < data_size; i++) { + if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ + return; + } + + for (i = 0; i < data_size; i++) { + int j; if (index != -1 && i != index) continue; diff_encode = diff_buffer = 0; - for (int j = 0; j < TEST_PERF_ITERATIONS; j++) { + for (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); + 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); strcpy(symbol->primary, data[i].primary); start = clock(); diff --git a/backend/tests/test_medical.c b/backend/tests/test_medical.c index aad08cd4..aa830959 100644 --- a/backend/tests/test_medical.c +++ b/backend/tests/test_medical.c @@ -33,9 +33,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int option_2; @@ -59,20 +56,24 @@ static void test_large(int index, int debug) { /* 9*/ { BARCODE_CODE32, -1, "1", 9, ZINT_ERROR_TOO_LONG, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[64]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -90,9 +91,6 @@ static void test_large(int index, int debug) { static void test_hrt(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int option_2; @@ -111,15 +109,19 @@ static void test_hrt(int index, int debug) { /* 6*/ { BARCODE_CODE32, -1, "12345678", "A123456788" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_hrt"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt); @@ -134,9 +136,6 @@ static void test_hrt(int index, int debug) { static void test_input(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -175,15 +174,19 @@ static void test_input(int index, int debug) { /* 25*/ { BARCODE_CODE32, "A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 361: Invalid characters in data (digits only)" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -202,11 +205,6 @@ static void test_input(int index, int debug) { 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; int option_2; @@ -253,19 +251,25 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -278,10 +282,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); diff --git a/backend/tests/test_pcx.c b/backend/tests/test_pcx.c index cfdb852a..a9885621 100644 --- a/backend/tests/test_pcx.c +++ b/backend/tests/test_pcx.c @@ -1,6 +1,6 @@ /* libzint - the open source barcode library - Copyright (C) 2020 Robin Stuart + Copyright (C) 2020 - 2021 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -33,14 +33,6 @@ static void test_pcx(int index, int debug) { - testStart(""); - - if (!testUtilHaveIdentify()) { - testSkip("ImageMagick identify not available"); - return; - } - - int ret; struct item { int symbology; int option_1; @@ -64,12 +56,23 @@ static void test_pcx(int index, int debug) { /* 9*/ { BARCODE_ULTRA, -1, -1, "", "", 0, "ULTRACODE_123456789!" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + char *filename = "out.pcx"; + + testStart("test_pcx"); + + if (!testUtilHaveIdentify()) { + testSkip("ImageMagick identify not available"); + return; + } + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->symbology = data[i].symbology; @@ -90,12 +93,11 @@ static void test_pcx(int index, int debug) { } symbol->debug |= debug; - int length = strlen(data[i].data); + length = strlen(data[i].data); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); diff --git a/backend/tests/test_pdf417.c b/backend/tests/test_pdf417.c index 77d83f60..c48a35f7 100644 --- a/backend/tests/test_pdf417.c +++ b/backend/tests/test_pdf417.c @@ -33,9 +33,6 @@ static void test_options(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int option_1; @@ -68,17 +65,21 @@ static void test_options(int index, int debug) { /* 12*/ { BARCODE_MICROPDF417, -1, 1, -1, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLM", ZINT_WARN_INVALID_OPTION, 0, -1, 2, 17, 55, -1 }, // Cols 1 too small, auto-upped to 2 with warning }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; struct zint_symbol previous_symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_options"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt); @@ -113,9 +114,6 @@ static void test_options(int index, int debug) { static void test_reader_init(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int symbology; int input_mode; @@ -132,19 +130,23 @@ static void test_reader_init(int index, int generate, int debug) { /* 1*/ { BARCODE_MICROPDF417, UNICODE_MODE, READER_INIT, "A", 0, 11, 38, "(11) 921 900 29 900 179 499 922 262 777 478 300", "Outputs Test Alpha flag 900" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_reader_init"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -170,9 +172,6 @@ static void test_reader_init(int index, int generate, int debug) { static void test_input(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int symbology; int input_mode; @@ -217,19 +216,23 @@ static void test_input(int index, int generate, int debug) { /* 26*/ { BARCODE_PDF417, UNICODE_MODE, -1, "{} #+ de{} 12{} {} H", 0, 0, 10, 120, "(30) 22 865 807 896 808 470 807 94 865 807 896 808 32 776 839 806 865 807 896 787 900 900", "" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -256,11 +259,6 @@ static void test_input(int index, int generate, int debug) { 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; int eci; @@ -728,19 +726,25 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -754,10 +758,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); @@ -785,9 +790,6 @@ static void test_encode(int index, int generate, int debug) { // #181 Nico Gunkel OSS-Fuzz static void test_fuzz(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -1052,12 +1054,16 @@ static void test_fuzz(int index, int debug) { 251, -1, ZINT_ERROR_TOO_LONG }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_fuzz"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->symbology = data[i].symbology; @@ -1066,7 +1072,7 @@ static void test_fuzz(int index, int debug) { } symbol->debug |= debug; - int length = data[i].length; + length = data[i].length; if (length == -1) { length = strlen(data[i].data); } @@ -1087,11 +1093,6 @@ static void test_fuzz(int index, int debug) { // Not a real test, just performance indicator static void test_perf(int index, int debug) { - if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ - return; - } - - int ret; struct item { int symbology; int input_mode; @@ -1141,20 +1142,26 @@ static void test_perf(int index, int debug) { 0, 51, 358, "960 chars, byte" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer; - for (int i = 0; i < data_size; i++) { + if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ + return; + } + + for (i = 0; i < data_size; i++) { + int j; if (index != -1 && i != index) continue; diff_encode = diff_buffer = 0; - for (int j = 0; j < TEST_PERF_ITERATIONS; j++) { + for (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); + 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 --git a/backend/tests/test_plessey.c b/backend/tests/test_plessey.c index e188e96b..b48991d7 100644 --- a/backend/tests/test_plessey.c +++ b/backend/tests/test_plessey.c @@ -33,9 +33,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int option_2; @@ -69,20 +66,24 @@ static void test_large(int index, int debug) { /* 19*/ { BARCODE_PLESSEY, -1, "A", 66, ZINT_ERROR_TOO_LONG, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[4096]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -100,9 +101,6 @@ static void test_large(int index, int debug) { static void test_hrt(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int option_2; @@ -143,15 +141,19 @@ static void test_hrt(int index, int debug) { /* 28*/ { BARCODE_PLESSEY, -1, "0123456789ABCDEF", "0123456789ABCDEF" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_hrt"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt); @@ -166,9 +168,6 @@ static void test_hrt(int index, int debug) { static void test_input(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int option_2; @@ -185,15 +184,19 @@ static void test_input(int index, int debug) { /* 3*/ { BARCODE_PLESSEY, -1, "G", ZINT_ERROR_INVALID_DATA, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -211,11 +214,6 @@ static void test_input(int index, int debug) { 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; int option_2; @@ -263,19 +261,25 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; char bwipp_buf[4096]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -288,10 +292,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); diff --git a/backend/tests/test_png.c b/backend/tests/test_png.c index 9035a988..102f3b74 100644 --- a/backend/tests/test_png.c +++ b/backend/tests/test_png.c @@ -36,14 +36,6 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) static void test_pixel_plot(int index, int debug) { - testStart(""); - - if (!testUtilHaveIdentify()) { - testSkip("ImageMagick identify not available"); - return; - } - - int ret; struct item { int width; int height; @@ -61,16 +53,26 @@ static void test_pixel_plot(int index, int debug) { /* 6*/ { 8, 2, "CBMWKRYGGYRKWMBC", 0 }, }; int data_size = ARRAY_SIZE(data); + int i, ret; + struct zint_symbol *symbol; char *png = "out.png"; char data_buf[8 * 2 + 1]; - for (int i = 0; i < data_size; i++) { + testStart("test_pixel_plot"); + + if (!testUtilHaveIdentify()) { + testSkip("ImageMagick identify not available"); + return; + } + + for (i = 0; i < data_size; i++) { + int size; if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); strcpy(symbol->outfile, png); @@ -79,7 +81,7 @@ static void test_pixel_plot(int index, int debug) { symbol->bitmap_height = data[i].height; symbol->debug |= debug; - int size = data[i].width * data[i].height; + 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) { @@ -109,11 +111,6 @@ static void test_pixel_plot(int index, int debug) { static void test_print(int index, int generate, int debug) { - testStart(""); - - int have_identify = testUtilHaveIdentify(); - - int ret; struct item { int symbology; int input_mode; @@ -191,6 +188,8 @@ static void test_print(int index, int generate, int debug) { /* 53*/ { BARCODE_USPS_IMAIL, -1, -1, -1, -1, -1, -1, -1, -1, 7.75f, 0, "", "", "12345678901234567890", "", 0, "imail_height7.75.png", "" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; const char *data_dir = "/backend/tests/data/png"; const char *png = "out.png"; @@ -199,23 +198,28 @@ static void test_print(int index, int generate, int debug) { int escaped_size = 1024; char *text; + int have_identify = testUtilHaveIdentify(); + + testStart("test_print"); + if (generate) { char data_dir_path[1024]; assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); - if (!testUtilExists(data_dir_path)) { - ret = testutil_mkdir(data_dir_path, 0755); - assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir_path, ret, errno, strerror(errno)); + if (!testUtilDirExists(data_dir_path)) { + ret = testUtilMkDir(data_dir_path); + assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_dir_path, ret, errno, strerror(errno)); } } - for (int i = 0; i < data_size; i++) { + for (i = 0; i < data_size; i++) { + int text_length; if (index != -1 && i != index) continue; - struct zint_symbol* symbol = ZBarcode_Create(); + 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, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug); if (data[i].show_hrt != -1) { symbol->show_hrt = data[i].show_hrt; } @@ -246,7 +250,7 @@ static void test_print(int index, int generate, int debug) { } else { text = data[i].data; } - int text_length = strlen(text); + text_length = (int) strlen(text); ret = ZBarcode_Encode(symbol, (unsigned char *) text, text_length); assert_equal(ret, data[i].ret, "i:%d %s ZBarcode_Encode ret %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, data[i].ret, symbol->errtxt); @@ -262,8 +266,8 @@ static void test_print(int index, int generate, int debug) { i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].border_width, testUtilOutputOptionsName(data[i].output_options), data[i].whitespace_width, data[i].whitespace_height, data[i].show_hrt, data[i].option_1, data[i].option_2, data[i].height, data[i].scale, data[i].fgcolour, data[i].bgcolour, testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].composite, data[i].expected_file, data[i].comment); - ret = rename(symbol->outfile, expected_file); - assert_zero(ret, "i:%d rename(%s, %s) ret %d != 0\n", i, symbol->outfile, expected_file, ret); + ret = testUtilRename(symbol->outfile, expected_file); + assert_zero(ret, "i:%d testUtilRename(%s, %s) ret %d != 0\n", i, symbol->outfile, expected_file, ret); 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); diff --git a/backend/tests/test_postal.c b/backend/tests/test_postal.c index 695856ee..85c934eb 100644 --- a/backend/tests/test_postal.c +++ b/backend/tests/test_postal.c @@ -37,9 +37,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *pattern; @@ -70,20 +67,24 @@ static void test_large(int index, int debug) { /* 17*/ { BARCODE_DAFT, "D", 51, ZINT_ERROR_TOO_LONG, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[4096]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -101,9 +102,6 @@ static void test_large(int index, int debug) { static void test_koreapost(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int ret_encode; @@ -117,15 +115,19 @@ static void test_koreapost(int index, int debug) { /* 0*/ { "123456", 0, 0, 50, 1, 167 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_koreapost"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_KOREAPOST, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_KOREAPOST, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -147,9 +149,6 @@ static void test_koreapost(int index, int debug) { static void test_japanpost(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int ret_encode; @@ -166,15 +165,19 @@ static void test_japanpost(int index, int debug) { /* 2*/ { "123456", 0, 0, 8, 3, 133, "Check 11" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_japanpost"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_JAPANPOST, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_JAPANPOST, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -196,9 +199,6 @@ static void test_japanpost(int index, int debug) { static void test_input(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -245,15 +245,19 @@ static void test_input(int index, int debug) { /* 34*/ { BARCODE_DAFT, "B", ZINT_ERROR_INVALID_DATA, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -271,11 +275,6 @@ static void test_input(int index, int debug) { 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; char *data; @@ -368,19 +367,25 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -393,10 +398,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); diff --git a/backend/tests/test_print.c b/backend/tests/test_print.c index 8aea197b..83c580d8 100644 --- a/backend/tests/test_print.c +++ b/backend/tests/test_print.c @@ -36,22 +36,6 @@ static void test_print(int index, int generate, int debug) { - testStart(""); - - int have_identify = 0; - int have_libreoffice = 0; - int have_ghostscript = 0; - int have_vnu = 0; - int have_tiffinfo = 0; - if (generate) { - have_identify = testUtilHaveIdentify(); - have_libreoffice = testUtilHaveLibreOffice(); - have_ghostscript = testUtilHaveGhostscript(); - have_vnu = testUtilHaveVnu(); - have_tiffinfo = testUtilHaveTiffInfo(); - } - - int ret; struct item { int symbology; int option_1; @@ -68,6 +52,9 @@ static void test_print(int index, int generate, int debug) { /* 4*/ { BARCODE_MAXICODE, -1, -1, -1, "THIS IS A 93 CHARACTER CODE SET A MESSAGE THAT FILLS A MODE 4, UNAPPENDED, MAXICODE SYMBOL...", "maxicode_fig_2" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; + int j; char *exts[] = { "bmp", "emf", "eps", "gif", "pcx", "png", "svg", "tif", "txt" }; int exts_size = ARRAY_SIZE(exts); @@ -79,25 +66,40 @@ static void test_print(int index, int generate, int debug) { char escaped[1024]; int escaped_size = 1024; + int have_identify = 0; + int have_libreoffice = 0; + int have_ghostscript = 0; + int have_vnu = 0; + int have_tiffinfo = 0; + if (generate) { + have_identify = testUtilHaveIdentify(); + have_libreoffice = testUtilHaveLibreOffice(); + have_ghostscript = testUtilHaveGhostscript(); + have_vnu = testUtilHaveVnu(); + have_tiffinfo = testUtilHaveTiffInfo(); + } + + testStart("test_print"); + assert_nonzero(testUtilDataPath(data_dir, sizeof(data_dir), "/backend/tests/data", NULL), "testUtilDataPath == 0\n"); if (generate) { - if (!testUtilExists(data_dir)) { - ret = testutil_mkdir(data_dir, 0755); - assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno)); + if (!testUtilDirExists(data_dir)) { + ret = testUtilMkDir(data_dir); + assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno)); } assert_nonzero(sizeof(data_dir) > strlen(data_dir) + 6, "sizeof(data_dir) %d <= strlen (%d) + 6\n", (int) sizeof(data_dir), (int) strlen(data_dir)); strcat(data_dir, "/print"); - if (!testUtilExists(data_dir)) { - ret = testutil_mkdir(data_dir, 0755); - assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno)); + if (!testUtilDirExists(data_dir)) { + ret = testUtilMkDir(data_dir); + assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno)); } } else { assert_nonzero(sizeof(data_dir) > strlen(data_dir) + 6, "sizeof(data_dir) %d <= strlen (%d) + 6\n", (int) sizeof(data_dir), (int) strlen(data_dir)); strcat(data_dir, "/print"); } - for (int j = 0; j < exts_size; j++) { + for (j = 0; j < exts_size; j++) { #ifdef NO_PNG if (strcmp(exts[j], "png") == 0) continue; #endif @@ -109,20 +111,20 @@ static void test_print(int index, int generate, int debug) { strcat(data_subdir, exts[j]); if (generate) { - if (!testUtilExists(data_subdir)) { - ret = testutil_mkdir(data_subdir, 0755); - assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_subdir, ret, errno, strerror(errno)); + if (!testUtilDirExists(data_subdir)) { + ret = testUtilMkDir(data_subdir); + assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_subdir, ret, errno, strerror(errno)); } } - for (int i = 0; i < data_size; i++) { + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); if (data[i].scale != -1) { symbol->scale = data[i].scale; } @@ -152,8 +154,8 @@ static void test_print(int index, int generate, int debug) { 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); + ret = testUtilRename(symbol->outfile, expected_file); + assert_zero(ret, "i:%d testUtilRename(%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); diff --git a/backend/tests/test_ps.c b/backend/tests/test_ps.c index 98955abf..cf7f1a67 100644 --- a/backend/tests/test_ps.c +++ b/backend/tests/test_ps.c @@ -34,11 +34,6 @@ static void test_print(int index, int generate, int debug) { - testStart(""); - - int have_ghostscript = testUtilHaveGhostscript(); - - int ret; struct item { int symbology; int input_mode; @@ -46,23 +41,47 @@ static void test_print(int index, int generate, int debug) { int whitespace_width; int option_1; int option_2; + float scale; + float dot_size; char *fgcolour; char *bgcolour; char *data; char *expected_file; }; struct item data[] = { - /* 0*/ { BARCODE_CODE128, UNICODE_MODE, BOLD_TEXT, -1, -1, -1, "", "", "Égjpqy", "code128_egrave_bold.eps" }, - /* 1*/ { BARCODE_CODE39, -1, -1, -1, -1, -1, "147AD0", "FC9630", "123", "code39_fg_bg.eps" }, - /* 2*/ { BARCODE_ULTRA, -1, 1, -1, -1, -1, "147AD0", "FC9630", "123", "ultra_fg_bg.eps" }, - /* 3*/ { BARCODE_EANX, -1, -1, -1, -1, -1, "", "", "9771384524017+12", "ean13_2addon_ggs_5.2.2.5.1-2.eps" }, - /* 4*/ { BARCODE_UPCA, -1, -1, -1, -1, -1, "", "", "012345678905+24", "upca_2addon_ggs_5.2.6.6-5.eps" }, - /* 5*/ { BARCODE_UPCE, -1, -1, -1, -1, -1, "", "", "0123456+12345", "upce_5addon.eps" }, - /* 6*/ { BARCODE_UPCE, -1, SMALL_TEXT | BOLD_TEXT, -1, -1, -1, "", "", "0123456+12345", "upce_5addon_small_bold.eps" }, - /* 7*/ { BARCODE_CODE128, UNICODE_MODE, -1, -1, -1, -1, "", "", "A\\B)ç(D", "code128_escape_latin1.eps" }, - /* 8*/ { BARCODE_DBAR_LTD, -1, BOLD_TEXT, -1, -1, -1, "", "", "1501234567890", "dbar_ltd_24724_fig7_bold.eps" }, + /* 0*/ { BARCODE_CODE128, UNICODE_MODE, BOLD_TEXT, -1, -1, -1, 0, 0, "", "", "Égjpqy", "code128_egrave_bold.eps" }, + /* 1*/ { BARCODE_CODE39, -1, -1, -1, -1, -1, 0, 0, "147AD0", "FC9630", "123", "code39_fg_bg.eps" }, + /* 2*/ { BARCODE_ULTRA, -1, 1, -1, -1, -1, 0, 0, "147AD0", "FC9630", "123", "ultra_fg_bg.eps" }, + /* 3*/ { BARCODE_EANX, -1, -1, -1, -1, -1, 0, 0, "", "", "9771384524017+12", "ean13_2addon_ggs_5.2.2.5.1-2.eps" }, + /* 4*/ { BARCODE_UPCA, -1, -1, -1, -1, -1, 0, 0, "", "", "012345678905+24", "upca_2addon_ggs_5.2.6.6-5.eps" }, + /* 5*/ { BARCODE_UPCE, -1, -1, -1, -1, -1, 0, 0, "", "", "0123456+12345", "upce_5addon.eps" }, + /* 6*/ { BARCODE_UPCE, -1, SMALL_TEXT | BOLD_TEXT, -1, -1, -1, 0, 0, "", "", "0123456+12345", "upce_5addon_small_bold.eps" }, + /* 7*/ { BARCODE_CODE128, UNICODE_MODE, -1, -1, -1, -1, 0, 0, "", "", "A\\B)ç(D", "code128_escape_latin1.eps" }, + /* 8*/ { BARCODE_DBAR_LTD, -1, BOLD_TEXT, -1, -1, -1, 0, 0, "", "", "1501234567890", "dbar_ltd_24724_fig7_bold.eps" }, + /* 9*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 0, 0, "", "", "12", "dotcode_1.0.eps" }, + /* 10*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 0, 0.1, "", "", "12", "dotcode_1.0_ds0.1.eps" }, + /* 11*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 0, 1.1, "", "", "12", "dotcode_1.0_ds1.1.eps" }, + /* 12*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 1.5, 0, "", "", "12", "dotcode_1.5.eps" }, + /* 13*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 1.5, 0.4, "", "", "12", "dotcode_1.5_ds0.4.eps" }, + /* 14*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 1.5, 1.1, "", "", "12", "dotcode_1.5_ds1.1.eps" }, + /* 15*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 1.5, 2.1, "", "", "12", "dotcode_1.5_ds2.1.eps" }, + /* 16*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 2, 0, "", "", "12", "dotcode_2.0.eps" }, + /* 17*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 2, 0.9, "", "", "12", "dotcode_2.0_ds0.9.eps" }, + /* 18*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 2, 1.1, "", "", "12", "dotcode_2.0_ds1.1.eps" }, + /* 19*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 3, 0, "", "", "12", "dotcode_3.0.eps" }, + /* 20*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 3, 0.4, "", "", "12", "dotcode_3.0_ds0.4.eps" }, + /* 21*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 3, 1.1, "", "", "12", "dotcode_3.0_ds1.1.eps" }, + /* 22*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 3.5, 0, "", "", "12", "dotcode_3.5.eps" }, + /* 23*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 3.5, 0.4, "", "", "12", "dotcode_3.5_ds0.4.eps" }, + /* 24*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 3.5, 1.1, "", "", "12", "dotcode_3.5_ds1.1.eps" }, + /* 25*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 5, 0, "", "", "12", "dotcode_5.0.eps" }, + /* 26*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 5, 0.2, "", "", "12", "dotcode_5.0_ds0.2.eps" }, + /* 27*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 5, 1.1, "", "", "12", "dotcode_5.0_ds1.1.eps" }, + /* 28*/ { BARCODE_DOTCODE, -1, -1, -1, -1, -1, 5, 1.7, "", "", "12", "dotcode_5.0_ds1.7.eps" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; const char *data_dir = "/backend/tests/data/eps"; const char *eps = "out.eps"; @@ -70,26 +89,36 @@ static void test_print(int index, int generate, int debug) { char escaped[1024]; int escaped_size = 1024; + int have_ghostscript = testUtilHaveGhostscript(); + + testStart("test_print"); + if (generate) { char data_dir_path[1024]; assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); - if (!testUtilExists(data_dir_path)) { - ret = testutil_mkdir(data_dir_path, 0755); - assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir_path, ret, errno, strerror(errno)); + if (!testUtilDirExists(data_dir_path)) { + ret = testUtilMkDir(data_dir_path); + assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_dir_path, ret, errno, strerror(errno)); } } - for (int i = 0; i < data_size; i++) { + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + 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, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug); if (data[i].whitespace_width != -1) { symbol->whitespace_width = data[i].whitespace_width; } + if (data[i].scale) { + symbol->scale = data[i].scale; + } + if (data[i].dot_size) { + symbol->dot_size = data[i].dot_size; + } if (*data[i].fgcolour) { strcpy(symbol->fgcolour, data[i].fgcolour); } @@ -107,11 +136,12 @@ static void test_print(int index, int generate, int debug) { assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i); if (generate) { - printf(" /*%3d*/ { %s, %s, %s, %d, %d, %d, \"%s\", \"%s\", \"%s\", \"%s\"},\n", + printf(" /*%3d*/ { %s, %s, %s, %d, %d, %d, %.5g, %.5g, \"%s\", \"%s\", \"%s\", \"%s\"},\n", i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options), data[i].whitespace_width, - data[i].option_1, data[i].option_2, data[i].fgcolour, data[i].bgcolour, 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); + data[i].option_1, data[i].option_2, data[i].scale, data[i].dot_size, data[i].fgcolour, data[i].bgcolour, + testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].expected_file); + ret = testUtilRename(symbol->outfile, expected_file); + assert_zero(ret, "i:%d testUtilRename(%s, %s) ret %d != 0\n", i, symbol->outfile, expected_file, ret); 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); @@ -135,8 +165,6 @@ void ps_convert(const unsigned char *string, unsigned char *ps_string); static void test_ps_convert(int index) { - testStart(""); - struct item { char *data; char *expected; @@ -145,10 +173,13 @@ static void test_ps_convert(int index) { /* 0*/ { "1\\(é)2€3", "1\\\\\\(\351\\)23" }, }; int data_size = ARRAY_SIZE(data); + int i; unsigned char converted[256]; - for (int i = 0; i < data_size; i++) { + testStart("test_ps_convert"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; diff --git a/backend/tests/test_qr.c b/backend/tests/test_qr.c index 6a71677a..1ab82f3b 100644 --- a/backend/tests/test_qr.c +++ b/backend/tests/test_qr.c @@ -33,9 +33,6 @@ static void test_qr_options(int index, int debug) { - testStart(""); - - int ret; struct item { int option_1; int option_2; @@ -78,21 +75,25 @@ static void test_qr_options(int index, int debug) { /* 28*/ { 4, -1, "貫やぐ識禁ぱい再2間変字全ノレ没無8裁花ほゃ過法ひなご札17能つーびれ投覧マ勝動エヨ額界よみ作皇ナヲニ打題ヌルヲ掲布益フが。入35能ト権話しこを断兆モヘ細情おじ名4減エヘイハ側機はょが意見想ハ業独案ユヲウ患職ヲ平美さ毎放どぽたけ家没べお化富べ町大シ情魚ッでれ一冬すぼめり。社ト可化モマ試音ばじご育青康演ぴぎ権型固スで能麩ぜらもほ河都しちほラ収90作の年要とだむ部動ま者断チ第41一1米索焦茂げむしれ。測フ物使だて目月国スリカハ夏検にいへ児72告物ゆは載核ロアメヱ登輸どべゃ催行アフエハ議歌ワ河倫剖だ。記タケウ因載ヒイホヤ禁3輩彦関トえび肝区勝ワリロ成禁ぼよ界白ウヒキレ中島べせぜい各安うしぽリ覧生テ基一でむしゃ中新トヒキソ声碁スしび起田ア信大未ゅもばち。", 0, 0, 153, 1 }, // ECC 4, version auto-set 34 /* 29*/ { 4, 34, "貫やぐ識禁ぱい再2間変字全ノレ没無8裁花ほゃ過法ひなご札17能つーびれ投覧マ勝動エヨ額界よみ作皇ナヲニ打題ヌルヲ掲布益フが。入35能ト権話しこを断兆モヘ細情おじ名4減エヘイハ側機はょが意見想ハ業独案ユヲウ患職ヲ平美さ毎放どぽたけ家没べお化富べ町大シ情魚ッでれ一冬すぼめり。社ト可化モマ試音ばじご育青康演ぴぎ権型固スで能麩ぜらもほ河都しちほラ収90作の年要とだむ部動ま者断チ第41一1米索焦茂げむしれ。測フ物使だて目月国スリカハ夏検にいへ児72告物ゆは載核ロアメヱ登輸どべゃ催行アフエハ議歌ワ河倫剖だ。記タケウ因載ヒイホヤ禁3輩彦関トえび肝区勝ワリロ成禁ぼよ界白ウヒキレ中島べせぜい各安うしぽリ覧生テ基一でむしゃ中新トヒキソ声碁スしび起田ア信大未ゅもばち。", 0, 0, 153, 0 }, /* 30*/ { 4, -1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 0, 0, 177, -1 }, // 1852 alphanumerics max for ECC 4 (H) - /* 31*/ { 1, -1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 0, 0, 177, -1 }, // 4296 alphanumerics max for ECC 1 (L) + /* 31*/ { 1, -1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 0, 0, 177, -1 }, // 4296 alphanumerics max for ECC 1 (L) }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; struct zint_symbol previous_symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_qr_options"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_QRCODE, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_QRCODE, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt); @@ -117,9 +118,6 @@ static void test_qr_options(int index, int debug) { static void test_qr_input(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int eci; @@ -273,20 +271,24 @@ static void test_qr_input(int index, int generate, int debug) { /*125*/ { UNICODE_MODE, 900, -1, "é", 0, 900, "78 38 44 02 C3 A9 00 EC 11", "ECI-900 B2 (no conversion)" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_qr_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_QRCODE, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_QRCODE, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); @@ -312,9 +314,6 @@ static void test_qr_input(int index, int generate, int debug) { static void test_qr_gs1(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; char *data; @@ -337,20 +336,24 @@ static void test_qr_gs1(int index, int generate, int debug) { /* 11*/ { GS1_MODE, "[91]%23%%6789%%%34567%%%%234%%%%%", 0, "(34) 52 17 19 6D A8 17 76 A6 D4 22 A5 C7 6A 6D 4D A8 22 C7 39 61 DA 9B 53 6A 6B 01 17 B5", "A31(46)" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_qr_gs1"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_QRCODE, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_QRCODE, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); @@ -372,9 +375,6 @@ static void test_qr_gs1(int index, int generate, int debug) { static void test_qr_optimize(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int option_1; @@ -416,20 +416,24 @@ static void test_qr_optimize(int index, int generate, int debug) { /* 29*/ { UNICODE_MODE, -1, "貫やぐ識禁ぱい再2間変字全ノレ没無8裁花ほゃ過法ひなご札17能つーびれ投覧マ勝動エヨ額界よみ作皇ナヲニ打題ヌルヲ掲布益フが。入35能ト権話しこを断兆モヘ細情おじ名4減エヘイハ側機はょが意見想ハ業独案ユヲウ患職ヲ平美さ毎放どぽたけ家没べお化富べ町大シ情魚ッでれ一冬すぼめり。社ト可化モマ試音ばじご育青康演ぴぎ権型固スで能麩ぜらもほ河都しちほラ収90作の年要とだむ部動ま者断チ第41一1米索焦茂げむしれ。測フ物使だて目月国スリカハ夏検にいへ児72告物ゆは載核ロアメヱ登輸どべゃ催行アフエハ議歌ワ河倫剖だ。記タケウ因載ヒイホヤ禁3輩彦関トえび肝区勝ワリロ成禁ぼよ界白ウヒキレ中島べせぜい各安うしぽリ覧生テ基一でむしゃ中新トヒキソ声碁スしび起田ア信大未ゅもばち。", 0, "(589) 80 20 EA 21 62 09 72 8B D0 2C 14 F0 91 26 10 40 04 A0 08 3A A3 E3 D4 34 C1 30 D6 87", "K8 N1 K8 N1 K10 N2 K33 N2 K16 N1 K89 N2 K14 B5 K28 N2 K40 N1 K65" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_qr_optimize"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_QRCODE, data[i].input_mode, -1 /*eci*/, data[i].option_1, -1, ZINT_FULL_MULTIBYTE, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_QRCODE, data[i].input_mode, -1 /*eci*/, data[i].option_1, -1, ZINT_FULL_MULTIBYTE, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); @@ -450,9 +454,6 @@ static void test_qr_optimize(int index, int generate, int debug) { static void test_qr_encode(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int symbology; int input_mode; @@ -989,7 +990,7 @@ static void test_qr_encode(int index, int generate, int debug) { "10000010010111001111010001100001010001010110110001100000111101011100000010010111101001001100101101111011011001000001101001110" "11111110000000010001110110000001010111011111000000111111010101110100101000110111000101101011001100000101101101101001100111111" }, - /* 15*/ { BARCODE_QRCODE, UNICODE_MODE, 4, 40, -1, "点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点", 0, 177, 177, "Max capacity ECC 4 Version 40 784 kanji", + /* 15*/ { BARCODE_QRCODE, UNICODE_MODE, 4, 40, -1, "点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点" "点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点", 0, 177, 177, "Max capacity ECC 4 Version 40 784 kanji", "111111101010001111111101101110111010110111001110101000010001011011011101001110110011111011010000010101001010011110010000010110111111001001011111101000010010111111001010001111111" "100000101010110001001000101111011001001100100110110000000111110101111011110001101110000111000100101111010011001111100111111001001011011011110011011111111001000010010010101000001" "101110101001001101111001110010010100000000111001001011111000001001111111101010000111011010011010010001111010111001100011000011110100101110001010110001011110011011011010001011101" @@ -1263,16 +1264,20 @@ static void test_qr_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_qr_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + 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, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -1310,11 +1315,6 @@ static void test_qr_encode(int index, int generate, int debug) { // Not a real test, just performance indicator static void test_qr_perf(int index, int debug) { - if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ - return; - } - - int ret; struct item { int symbology; int input_mode; @@ -1344,20 +1344,26 @@ static void test_qr_perf(int index, int debug) { 0, 105, 105, "963 chars, Mixed modes" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer; - for (int i = 0; i < data_size; i++) { + if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ + return; + } + + for (i = 0; i < data_size; i++) { + int j; if (index != -1 && i != index) continue; diff_encode = diff_buffer = 0; - for (int j = 0; j < TEST_PERF_ITERATIONS; j++) { + for (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); + 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); @@ -1387,9 +1393,6 @@ static void test_qr_perf(int index, int debug) { static void test_microqr_options(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int option_1; @@ -1452,17 +1455,21 @@ static void test_microqr_options(int index, int debug) { /* 48*/ { "ABCDEFGHIJABC", 3, 4, 0, 0, 17, -1 }, // 13 alphanumerics, ECC 3 (Q), version 4 }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; struct zint_symbol previous_symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_microqr_options"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_MICROQR, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_MICROQR, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt); @@ -1487,9 +1494,6 @@ static void test_microqr_options(int index, int debug) { static void test_microqr_input(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int option_3; @@ -1555,19 +1559,23 @@ static void test_microqr_input(int index, int generate, int debug) { /* 40*/ { UNICODE_MODE, 200, "áA", 0, "CE 00 40 00 EC 11 EC 11 00", "K1 (ISO 8859-1) (full multibyte)" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_microqr_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_MICROQR, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_MICROQR, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); @@ -1591,9 +1599,6 @@ static void test_microqr_input(int index, int generate, int debug) { // Check MICROQR padding (4-bit final codeword for M1 and M3 in particular) static void test_microqr_padding(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { char *data; int option_1; @@ -1629,14 +1634,18 @@ static void test_microqr_padding(int index, int generate, int debug) { /* 24*/ { "ABCDEFGHIJKLM", 3, 0, "2D 39 A8 A5 42 AE 16 7A E6 56", "M4-Q, bits left 0" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_microqr_padding"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->symbology = BARCODE_MICROQR; @@ -1647,7 +1656,7 @@ static void test_microqr_padding(int index, int generate, int debug) { symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug |= debug; - int length = strlen(data[i].data); + length = strlen(data[i].data); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -1670,9 +1679,6 @@ static void test_microqr_padding(int index, int generate, int debug) { static void test_microqr_optimize(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int option_1; @@ -1699,19 +1705,23 @@ static void test_microqr_optimize(int index, int generate, int debug) { /* 12*/ { DATA_MODE, 1, -1, ZINT_FULL_MULTIBYTE | (1 << 8), "\223\137", 0, "CB 67 C0 00 EC 11 EC 11 EC 11 00", "K1" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_microqr_optimize"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_MICROQR, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_MICROQR, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -1733,9 +1743,6 @@ static void test_microqr_optimize(int index, int generate, int debug) { static void test_microqr_encode(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int option_1; @@ -2010,15 +2017,19 @@ static void test_microqr_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_microqr_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_MICROQR, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_MICROQR, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -2052,11 +2063,6 @@ static void test_microqr_encode(int index, int generate, int debug) { // 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; @@ -2076,20 +2082,26 @@ static void test_microqr_perf(int index, int debug) { /* 3*/ { BARCODE_MICROQR, UNICODE_MODE, 1, 4, "12345678901234567890123456789012345", 0, 17, 17, "Max 35 numbers, M4-L" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer; - for (int i = 0; i < data_size; i++) { + if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */ + return; + } + + for (i = 0; i < data_size; i++) { + int j; if (index != -1 && i != index) continue; diff_encode = diff_buffer = 0; - for (int j = 0; j < TEST_PERF_ITERATIONS; j++) { + for (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); + 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); @@ -2119,9 +2131,6 @@ static void test_microqr_perf(int index, int debug) { static void test_upnqr_input(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; char *data; @@ -2139,19 +2148,23 @@ static void test_upnqr_input(int index, int generate, int debug) { /* 2*/ { UNICODE_MODE, "β", ZINT_ERROR_INVALID_DATA, "Error 572: Invalid characters in input data", "β not in ISO 8859-2" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_upnqr_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_UPNQR, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_UPNQR, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); @@ -2175,9 +2188,6 @@ static void test_upnqr_input(int index, int generate, int debug) { static void test_upnqr_encode(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; char *data; @@ -2273,15 +2283,19 @@ static void test_upnqr_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_upnqr_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_UPNQR, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_UPNQR, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -2313,9 +2327,6 @@ static void test_upnqr_encode(int index, int generate, int debug) { static void test_rmqr_options(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int option_1; @@ -2395,15 +2406,19 @@ static void test_rmqr_options(int index, int debug) { /* 65*/ { "点茗点", -1, 39, ZINT_ERROR_INVALID_OPTION, -1, 0, 0 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_rmqr_options"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_RMQR, UNICODE_MODE, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_RMQR, UNICODE_MODE, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt); @@ -2424,9 +2439,6 @@ static void test_rmqr_options(int index, int debug) { static void test_rmqr_input(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int option_3; @@ -2458,19 +2470,23 @@ static void test_rmqr_input(int index, int generate, int debug) { /* 11*/ { UNICODE_MODE, 200, "áA", 0, "8E 00 40 EC 11", "K1 (ISO 8859-1) (full multibyte)" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_rmqr_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_RMQR, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_RMQR, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); @@ -2493,9 +2509,6 @@ static void test_rmqr_input(int index, int generate, int debug) { static void test_rmqr_gs1(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; char *data; @@ -2519,19 +2532,23 @@ static void test_rmqr_gs1(int index, int generate, int debug) { /* 12*/ { GS1_MODE, "[91]%23%%6789%%%34567%%%%234%%%%%", 0, "(33) AA 63 2D B5 02 EE D4 DA 84 54 B8 ED 4D A9 B5 04 58 E7 2C 3B 53 6A 6D 4D 60 22 F6 A3", "A27(38) B4" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_rmqr_gs1"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_RMQR, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_RMQR, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); @@ -2553,9 +2570,6 @@ static void test_rmqr_gs1(int index, int generate, int debug) { static void test_rmqr_optimize(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; char *data; @@ -2589,19 +2603,23 @@ static void test_rmqr_optimize(int index, int generate, int debug) { /* 21*/ { UNICODE_MODE, "貫やぐ識禁ぱい再2間変字全ノレ没無8裁花ほゃ過法ひなご札17能つーびれ投覧マ勝動エヨ額界よみ作皇ナヲニ打題ヌルヲ掲布益フが。入35能ト権話しこを断兆モヘ細情おじ名4減エヘイハ側機", -1, 0, "(152) 82 0E A2 16 20 97 28 BD 02 C1 4F 09 12 61 08 04 A0 83 AA 3E 3D 43 4C 13 0D 68 73 1F", "K8 N1 K8 N1 K10 N2 K33 N2 K16 N1 K7" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_rmqr_optimize"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_RMQR, data[i].input_mode, -1 /*eci*/, data[i].option_1, -1, ZINT_FULL_MULTIBYTE, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_RMQR, data[i].input_mode, -1 /*eci*/, data[i].option_1, -1, ZINT_FULL_MULTIBYTE, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -2622,9 +2640,6 @@ static void test_rmqr_optimize(int index, int generate, int debug) { static void test_rmqr_encode(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; char *data; @@ -2668,15 +2683,19 @@ static void test_rmqr_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_rmqr_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_RMQR, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_RMQR, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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_raster.c b/backend/tests/test_raster.c index 62363623..35eacb3f 100644 --- a/backend/tests/test_raster.c +++ b/backend/tests/test_raster.c @@ -43,9 +43,6 @@ static int is_row_column_black(struct zint_symbol *symbol, int row, int column) static void test_options(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *fgcolour; @@ -71,15 +68,19 @@ static void test_options(int index, int debug) { /* 8*/ { BARCODE_CODE128, NULL, "EEFFGG", 0, "A", ZINT_ERROR_INVALID_OPTION, -1, -1, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_options"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_CODE128, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODE128, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); if (data[i].fgcolour) { strcpy(symbol->fgcolour, data[i].fgcolour); @@ -106,9 +107,6 @@ static void test_options(int index, int debug) { static void test_buffer(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -251,15 +249,19 @@ static void test_buffer(int index, int generate, int debug) { /*127*/ { BARCODE_RMQR, "12345", "", 11, 11, 27, 54, 22 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char *text; - for (int i = 0; i < data_size; i++) { + testStart("test_buffer"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i); // ZINT_DEBUG_TEST_PRINT 16 - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->symbology = data[i].symbology; @@ -272,7 +274,7 @@ static void test_buffer(int index, int generate, int debug) { } else { text = data[i].data; } - int length = strlen(text); + length = strlen(text); ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); assert_zero(ret, "i:%d ZBarcode_Encode(%s) ret %d != 0 (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt); @@ -305,9 +307,6 @@ static void test_buffer(int index, int generate, int debug) { static void test_upcean_hrt(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int show_hrt; @@ -362,13 +361,17 @@ static void test_upcean_hrt(int index, int debug) { /* 31*/ { BARCODE_UPCE, 0, "1234567+12345", 0, 50, 1, 105, 238, 110, 104 /*text_row*/, 0, 18, 5, 120, 118 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_upcean_hrt"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i); // ZINT_DEBUG_TEST_PRINT 16 - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->symbology = data[i].symbology; @@ -377,7 +380,7 @@ static void test_upcean_hrt(int index, int debug) { } symbol->debug |= debug; - int length = strlen(data[i].data); + length = strlen(data[i].data); ret = ZBarcode_Encode_and_Buffer(symbol, (unsigned char *) data[i].data, length, 0); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); @@ -403,7 +406,8 @@ static void test_upcean_hrt(int index, int debug) { } else { int text_bits_set = 0; int row = data[i].expected_text_row; - for (int column = data[i].expected_text_col; column < data[i].expected_text_col + data[i].expected_text_len; column++) { + int column; + for (column = data[i].expected_text_col; column < data[i].expected_text_col + data[i].expected_text_len; column++) { if (is_row_column_black(symbol, row, column)) { text_bits_set = 1; break; @@ -419,7 +423,8 @@ static void test_upcean_hrt(int index, int debug) { if (data[i].expected_addon_text_row != -1) { int addon_text_bits_set = 0; int row = data[i].expected_addon_text_row; - for (int column = data[i].expected_addon_text_col; column < data[i].expected_addon_text_col + data[i].expected_addon_text_len; column++) { + int column; + for (column = data[i].expected_addon_text_col; column < data[i].expected_addon_text_col + data[i].expected_addon_text_len; column++) { if (is_row_column_black(symbol, row, column)) { addon_text_bits_set = 1; break; @@ -440,9 +445,6 @@ static void test_upcean_hrt(int index, int debug) { static void test_row_separator(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int border_width; @@ -473,15 +475,21 @@ static void test_row_separator(int index, int debug) { /* 8*/ { BARCODE_CODABLOCKF, 0, -1, -1, "A", 0, 20, 2, 101, 242, 44, 21, 42, 2 }, // Border width zero, same as default }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; + + testStart("test_row_separator"); + + for (i = 0; i < data_size; i++) { + int j, separator_bits_set; - for (int i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); if (data[i].border_width != -1) { symbol->border_width = data[i].border_width; } @@ -498,8 +506,6 @@ static void test_row_separator(int index, int debug) { assert_equal(symbol->bitmap_height, data[i].expected_bitmap_height, "i:%d (%s) symbol->bitmap_height %d != %d\n", i, testUtilBarcodeName(data[i].symbology), symbol->bitmap_height, data[i].expected_bitmap_height); - int j, separator_bits_set; - if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); // ZINT_DEBUG_TEST_PRINT 16 for (j = data[i].expected_separator_row; j < data[i].expected_separator_row + data[i].expected_separator_height; j++) { @@ -525,9 +531,6 @@ static void test_row_separator(int index, int debug) { static void test_stacking(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int output_options; @@ -552,19 +555,26 @@ static void test_stacking(int index, int debug) { /* 2*/ { BARCODE_CODE128, BARCODE_BIND, -1, 2, "A", "B", 50, 2, 46, 92, 116, 48, 4, 4 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; + + testStart("test_stacking"); + + for (i = 0; i < data_size; i++) { + int length2; + int j, separator_bits_set; - for (int i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, data[i].option_3, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, data[i].option_3, data[i].output_options, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ret %d != zero\n", i, ret); - int length2 = strlen(data[i].data2); + length2 = strlen(data[i].data2); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data2, length2); assert_zero(ret, "i:%d ret %d != zero\n", i, ret); @@ -578,8 +588,6 @@ static void test_stacking(int index, int debug) { assert_equal(symbol->bitmap_width, data[i].expected_bitmap_width, "i:%d (%d) symbol->bitmap_width %d != %d\n", i, data[i].symbology, symbol->bitmap_width, data[i].expected_bitmap_width); assert_equal(symbol->bitmap_height, data[i].expected_bitmap_height, "i:%d (%d) symbol->bitmap_height %d != %d\n", i, data[i].symbology, symbol->bitmap_height, data[i].expected_bitmap_height); - int j, separator_bits_set; - if (index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) testUtilBitmapPrint(symbol, NULL, NULL); // ZINT_DEBUG_TEST_PRINT 16 if (data[i].expected_separator_row != -1) { @@ -607,9 +615,6 @@ static void test_stacking(int index, int debug) { static void test_output_options(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int whitespace_width; @@ -711,15 +716,19 @@ static void test_output_options(int index, int debug) { /* 77*/ { BARCODE_ITF14, -1, -1, -1, OUT_BUFFER_INTERMEDIATE, 90, "123", 0, 50, 1, 135, 136, 330, 1, 0, 110 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_output_options"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, data[i].output_options, data[i].data, -1, debug); if (data[i].whitespace_width != -1) { symbol->whitespace_width = data[i].whitespace_width; } @@ -769,9 +778,6 @@ static void test_output_options(int index, int debug) { static void test_draw_string_wrap(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int output_options; @@ -792,16 +798,21 @@ static void test_draw_string_wrap(int index, int debug) { /* 1*/ { BARCODE_CODE128, BOLD_TEXT, "12", " E", 50, 1, 46, 92, 116, 104, 0 }, /* 2*/ { BARCODE_CODE128, SMALL_TEXT, "12", " E", 50, 1, 46, 92, 112, 103, 0 }, }; - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_draw_string_wrap"); + + for (i = 0; i < data_size; i++) { + int text_bits_set, row, column; if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, data[i].output_options, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode(%d) ret %d != 0 (%s)\n", i, data[i].symbology, ret, symbol->errtxt); @@ -824,9 +835,9 @@ static void test_draw_string_wrap(int index, int debug) { ret = ZBarcode_Print(symbol, 0); assert_zero(ret, "i:%d ZBarcode_Print(%d) ret %d != 0\n", i, data[i].symbology, ret); - int text_bits_set = 0; - int row = data[i].expected_no_text_row; - for (int column = data[i].expected_no_text_col; column < data[i].expected_no_text_col + 16; column++) { + text_bits_set = 0; + row = data[i].expected_no_text_row; + for (column = data[i].expected_no_text_col; column < data[i].expected_no_text_col + 16; column++) { if (is_row_column_black(symbol, row, column)) { text_bits_set = 1; break; @@ -842,9 +853,6 @@ static void test_draw_string_wrap(int index, int debug) { static void test_code128_utf8(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; @@ -862,15 +870,20 @@ static void test_code128_utf8(int index, int debug) { /* 0*/ { "é", 50, 1, 57, 114, 116, 110, 53, 6 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_code128_utf8"); + + for (i = 0; i < data_size; i++) { + int text_bits_set, row, column; if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_CODE128, UNICODE_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODE128, UNICODE_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode(%d) ret %d != 0 %s\n", i, BARCODE_CODE128, ret, symbol->errtxt); @@ -890,9 +903,9 @@ static void test_code128_utf8(int index, int debug) { ret = ZBarcode_Print(symbol, 0); assert_zero(ret, "i:%d ZBarcode_Print(%d) ret %d != 0\n", i, BARCODE_CODE128, ret); - int text_bits_set = 0; - int row = data[i].expected_text_row; - for (int column = data[i].expected_text_col; column < data[i].expected_text_col + data[i].expected_text_len; column++) { + text_bits_set = 0; + row = data[i].expected_text_row; + for (column = data[i].expected_text_col; column < data[i].expected_text_col + data[i].expected_text_len; column++) { if (is_row_column_black(symbol, row, column)) { text_bits_set++; } @@ -907,9 +920,6 @@ static void test_code128_utf8(int index, int debug) { static void test_scale(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int option_2; @@ -957,14 +967,19 @@ static void test_scale(int index, int debug) { /* 23*/ { BARCODE_UPCE_CC, -1, -1, -1, 2.0, "1234567", "[17]010615[10]A123456\"", 50, 10, 55, 142 * 2, 116 * 2, 104 * 2 + 1 /*set_row*/, 115 * 2, 11 * 2, 2 * 2 }, // +1 set_row }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char *text; - for (int i = 0; i < data_size; i++) { + testStart("test_scale"); + + for (i = 0; i < data_size; i++) { + int row, column; if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); testUtilSetSymbol(symbol, data[i].symbology, UNICODE_MODE, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug); @@ -980,7 +995,7 @@ static void test_scale(int index, int debug) { } else { text = data[i].data; } - int length = strlen(text); + length = strlen(text); ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); assert_zero(ret, "i:%d ZBarcode_Encode(%d) ret %d != 0 %s\n", i, data[i].symbology, ret, symbol->errtxt); @@ -1004,9 +1019,9 @@ static void test_scale(int index, int debug) { i, data[i].symbology, symbol->bitmap_height, data[i].expected_set_rows); assert_nonzero(data[i].expected_set_rows > data[i].expected_set_row, "i:%d (%d) expected_set_rows %d < expected_set_row %d\n", i, data[i].symbology, data[i].expected_set_rows, data[i].expected_set_row); - for (int row = data[i].expected_set_row; row < data[i].expected_set_rows; row++) { + for (row = data[i].expected_set_row; row < data[i].expected_set_rows; row++) { int bits_set = 0; - for (int column = data[i].expected_set_col; column < data[i].expected_set_col + data[i].expected_set_len; column++) { + for (column = data[i].expected_set_col; column < data[i].expected_set_col + data[i].expected_set_len; column++) { if (is_row_column_black(symbol, row, column)) { bits_set++; } @@ -1021,9 +1036,6 @@ static void test_scale(int index, int debug) { static void test_buffer_plot(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int symbology; int option_1; @@ -1134,19 +1146,23 @@ static void test_buffer_plot(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; int row, column; int fg_len, bg_len; - for (int i = 0; i < data_size; i++) { + testStart("test_buffer_plot"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i); // ZINT_DEBUG_TEST_PRINT 16 - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, UNICODE_MODE, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, UNICODE_MODE, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug); if (data[i].whitespace_width != -1) { symbol->whitespace_width = data[i].whitespace_width; } @@ -1209,9 +1225,6 @@ static void test_buffer_plot(int index, int generate, int debug) { static void test_height(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int symbology; float height; @@ -1632,15 +1645,19 @@ static void test_height(int index, int generate, int debug) { /*401*/ { BARCODE_RMQR, 1, "12345", "", 0, 11, 11, 27, 54, 22, "Fixed width-to-height ratio, symbol->height ignored" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char *text; - for (int i = 0; i < data_size; i++) { + testStart("test_height"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->symbology = data[i].symbology; @@ -1657,7 +1674,7 @@ static void test_height(int index, int generate, int debug) { } else { text = data[i].data; } - int length = strlen(text); + length = strlen(text); ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode(%s) ret %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, data[i].ret, symbol->errtxt); diff --git a/backend/tests/test_reedsol.c b/backend/tests/test_reedsol.c index 6f42c15f..b5f3d2c9 100644 --- a/backend/tests/test_reedsol.c +++ b/backend/tests/test_reedsol.c @@ -1,6 +1,6 @@ /* libzint - the open source barcode library - Copyright (C) 2020 Robin Stuart + Copyright (C) 2020 - 2021 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -79,10 +79,6 @@ static void gen_logs(const unsigned int prime_poly, int logmod, unsigned int *lo // Dummy to generate static log/antilog tables for "backend/reedsol_logs.h" static void test_generate(int generate) { - if (!generate) { - return; - } - struct item { const char *name; int logmod; @@ -99,11 +95,16 @@ static void test_generate(int generate) { { "0x163", 255, 0x163, 0 }, }; int data_size = ARRAY_SIZE(data); + int i; unsigned int logt[4096]; unsigned int alog[8192]; - for (int i = 0; i < data_size; i++) { + if (!generate) { + return; + } + + for (i = 0; i < data_size; i++) { gen_logs(data[i].prime_poly, data[i].logmod, logt, alog); print_logs(data[i].name, data[i].logmod, logt, alog, data[i].u16, i + 1 == data_size); } @@ -111,8 +112,6 @@ static void test_generate(int generate) { static void test_encoding(int index) { - testStart(""); - struct item { unsigned int prime_poly; int nsym; @@ -144,9 +143,12 @@ static void test_encoding(int index) { /* 17*/ { 0x11d, 5, 0, 5, { 0x40, 0x18, 0xAC, 0xC3, 0x00 }, { 0x86, 0x0D, 0x22, 0xAE, 0x30 } }, // QRCODE Annex I.3 }; int data_size = ARRAY_SIZE(data); + int i; - for (int i = 0; i < data_size; i++) { + testStart("test_encoding"); + for (i = 0; i < data_size; i++) { + int j; rs_t rs; unsigned char res[1024]; @@ -156,9 +158,9 @@ static void test_encoding(int index) { rs_init_code(&rs, data[i].nsym, data[i].index); rs_encode(&rs, data[i].datalen, data[i].data, res); - //fprintf(stderr, "res "); for (int j = data[i].nsym - 1; j >= 0; j--) fprintf(stderr, "%d ", res[j]); fprintf(stderr, "\n"); - //fprintf(stderr, "exp "); for (int j = 0; j < data[i].nsym; j++) fprintf(stderr, "%d ", data[i].expected[j]); fprintf(stderr, "\n"); - for (int j = 0; j < data[i].nsym; j++) { + //fprintf(stderr, "res "); for (j = data[i].nsym - 1; j >= 0; j--) fprintf(stderr, "%d ", res[j]); fprintf(stderr, "\n"); + //fprintf(stderr, "exp "); for (j = 0; j < data[i].nsym; j++) fprintf(stderr, "%d ", data[i].expected[j]); fprintf(stderr, "\n"); + for (j = 0; j < data[i].nsym; j++) { int k = data[i].nsym - 1 - j; assert_equal(res[k], data[i].expected[j], "i:%d res[%d] %d != expected[%d] %d\n", i, k, res[k], j, data[i].expected[j]); } @@ -169,8 +171,6 @@ static void test_encoding(int index) { static void test_encoding_uint(int index) { - testStart(""); - struct item { unsigned int prime_poly; int logmod; @@ -187,9 +187,12 @@ static void test_encoding_uint(int index) { /* 1*/ { 0x1069, 4095, 4, 1, 7, { 0xFFF, 0x000, 0x700, 0x7FF, 0xFFF, 0x000, 0x123 }, { 3472, 2350, 3494, 575 } }, }; int data_size = ARRAY_SIZE(data); + int i; - for (int i = 0; i < data_size; i++) { + testStart("test_encoding_uint"); + for (i = 0; i < data_size; i++) { + int j; rs_uint_t rs_uint; unsigned int res[1024]; @@ -200,9 +203,9 @@ static void test_encoding_uint(int index) { rs_uint_encode(&rs_uint, data[i].datalen, data[i].data, res); rs_uint_free(&rs_uint); - //fprintf(stderr, "res "); for (int j = data[i].nsym - 1; j >= 0; j--) fprintf(stderr, "%d ", res[j]); fprintf(stderr, "\n"); - //fprintf(stderr, "exp "); for (int j = 0; j < data[i].nsym; j++) fprintf(stderr, "%d ", data[i].expected[j]); fprintf(stderr, "\n"); - for (int j = 0; j < data[i].nsym; j++) { + //fprintf(stderr, "res "); for (j = data[i].nsym - 1; j >= 0; j--) fprintf(stderr, "%d ", res[j]); fprintf(stderr, "\n"); + //fprintf(stderr, "exp "); for (j = 0; j < data[i].nsym; j++) fprintf(stderr, "%d ", data[i].expected[j]); fprintf(stderr, "\n"); + for (j = 0; j < data[i].nsym; j++) { int k = data[i].nsym - 1 - j; assert_equal(res[k], data[i].expected[j], "i:%d res[%d] %d != expected[%d] %d\n", i, k, res[k], j, data[i].expected[j]); } diff --git a/backend/tests/test_rss.c b/backend/tests/test_rss.c index 90130f88..08a9adca 100644 --- a/backend/tests/test_rss.c +++ b/backend/tests/test_rss.c @@ -33,11 +33,6 @@ static void test_binary_div_modulo_divisor(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; char *data; @@ -122,17 +117,23 @@ static void test_binary_div_modulo_divisor(int index, int generate, int debug) { /* 70*/ { BARCODE_DBAR_LTD_CC, "0987144605916", 100, 30, 6, 79, "0101010101010011111000011111011010110100100101010101010100111110000111110100000" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char *text; char bwipp_buf[1024]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_binary_div_modulo_divisor"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); if (data[i].symbology == BARCODE_DBAR_OMN_CC || data[i].symbology == BARCODE_DBAR_LTD_CC) { @@ -141,7 +142,7 @@ static void test_binary_div_modulo_divisor(int index, int generate, int debug) { } else { text = data[i].data; } - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, text, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, text, -1, debug); ret = ZBarcode_Encode(symbol, (const unsigned char *) text, length); assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 (%s)\n", i, ret, symbol->errtxt); @@ -151,10 +152,11 @@ static void test_binary_div_modulo_divisor(int index, int generate, int debug) { i, testUtilBarcodeName(data[i].symbology), data[i].data, data[i].w, data[i].h, symbol->rows, symbol->width); testUtilModulesPrintRow(symbol, symbol->rows - 1, "", " },\n"); } else { + int 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; ret = testUtilModulesCmpRow(symbol, symbol->rows - 1, data[i].expected, &width); assert_zero(ret, "i:%d testUtilModulesCmpRow ret %d != 0 width %d row %d\n", i, ret, width, symbol->rows - 1); @@ -180,11 +182,6 @@ static void test_binary_div_modulo_divisor(int index, int generate, int debug) { // Replicate examples from GS1 General Specifications 21.0.1 and ISO/IEC 24724:2011 static void test_examples(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; int option_2; @@ -772,19 +769,25 @@ static void test_examples(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char bwipp_buf[4096]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_examples"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (const unsigned char *) 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); @@ -795,10 +798,11 @@ static void test_examples(int index, int generate, int debug) { testUtilModulesPrint(symbol, " ", "\n"); printf(" },\n"); } else { + int width, row; + 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); - 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); @@ -825,9 +829,6 @@ static void test_examples(int index, int generate, int debug) { // Test general-purpose data compaction static void test_general_field(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -1087,15 +1088,19 @@ static void test_general_field(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_general_field"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 (%s)\n", i, ret, symbol->errtxt); @@ -1106,10 +1111,11 @@ static void test_general_field(int index, int generate, int debug) { testUtilModulesPrint(symbol, " ", "\n"); printf(" },\n"); } else { + int width, row; + 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); - 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); } @@ -1122,9 +1128,6 @@ static void test_general_field(int index, int generate, int debug) { static void test_binary_buffer_size(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { char *data; int ret; @@ -1144,15 +1147,19 @@ static void test_binary_buffer_size(int index, int generate, int debug) { /* 7*/ { "[01]92345678901237[3920]123456789012345[00]123456789012345675[91]12345678901234567890", ZINT_ERROR_TOO_LONG, 0, 0, "78 > 01 + 392x + other AIs max" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_binary_buffer_size"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_DBAR_EXP, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_DBAR_EXP, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (const unsigned char *) 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); @@ -1173,9 +1180,6 @@ static void test_binary_buffer_size(int index, int generate, int debug) { static void test_hrt(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -1195,15 +1199,19 @@ static void test_hrt(int index, int debug) { /* 8*/ { BARCODE_DBAR_EXPSTK, "[01]12345678901231", "" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_hrt"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt); @@ -1218,9 +1226,6 @@ static void test_hrt(int index, int debug) { static void test_input(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -1258,15 +1263,19 @@ static void test_input(int index, int debug) { /* 24*/ { BARCODE_DBAR_EXPSTK, "[01]123456789012315", ZINT_ERROR_INVALID_DATA, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (const unsigned char *) 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_sjis.c b/backend/tests/test_sjis.c index 57c57166..34f7f324 100644 --- a/backend/tests/test_sjis.c +++ b/backend/tests/test_sjis.c @@ -35,6 +35,8 @@ // 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) { + int tab_length, start_i, end_i; + int i; if (wc < 0x20 || wc == 0x7F) { *r = wc; return 1; @@ -67,10 +69,10 @@ static int sjis_wctomb_zint2(unsigned int *r, unsigned int wc) { } return 2; } - int tab_length = sizeof(test_sjis_tab) / sizeof(unsigned int); - int start_i = test_sjis_tab_ind[wc >> 10]; - int end_i = start_i + 0x800 > tab_length ? tab_length : start_i + 0x800; - for (int i = start_i; i < end_i; i += 2) { + tab_length = sizeof(test_sjis_tab) / sizeof(unsigned int); + start_i = test_sjis_tab_ind[wc >> 10]; + end_i = start_i + 0x800 > tab_length ? tab_length : start_i + 0x800; + for (i = start_i; i < end_i; i += 2) { if (test_sjis_tab[i + 1] == wc) { *r = test_sjis_tab[i]; return *r > 0xFF ? 2 : 1; @@ -81,12 +83,13 @@ static int sjis_wctomb_zint2(unsigned int *r, unsigned int wc) { static void test_sjis_wctomb_zint(void) { - testStart(""); - int ret, ret2; unsigned int val, val2; + unsigned int i; - for (unsigned int i = 0; i < 0xFFFE; i++) { + testStart("test_sjis_wctomb_zint"); + + for (i = 0; i < 0xFFFE; i++) { if (i >= 0xD800 && i <= 0xDFFF) { // UTF-16 surrogates continue; } @@ -110,9 +113,6 @@ static void test_sjis_wctomb_zint(void) { static void test_sjis_utf8(int index) { - testStart(""); - - int ret; struct item { char *data; int length; @@ -140,24 +140,28 @@ static void test_sjis_utf8(int index) { /* 3*/ { "¥", -1, 0, 1, { 0x5C }, "" }, /* 4*/ { "aβcЖ¥・ソ‾\\\点茗テ", -1, 0, 13, { 'a', 0x83C0, 'c', 0x8447, 0x5C, 0xA5, 0xBF, 0x7E, 0x815F, 0x815F, 0x935F, 0xE4AA, 0x8365 }, "" }, }; - - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length, ret; struct zint_symbol symbol; unsigned int jisdata[20]; - for (int i = 0; i < data_size; i++) { + testStart("test_sjis_utf8"); + + for (i = 0; i < data_size; i++) { + int ret_length; if (index != -1 && i != index) continue; - int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - int ret_length = length; + length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; + ret_length = length; ret = sjis_utf8(&symbol, (unsigned char *) 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) { + int j; assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < (int) ret_length; j++) { + for (j = 0; j < 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]); } } @@ -168,9 +172,6 @@ static void test_sjis_utf8(int index) { static void test_sjis_utf8_to_eci(int index) { - testStart(""); - - int ret; struct item { int eci; int full_multibyte; @@ -230,23 +231,27 @@ static void test_sjis_utf8_to_eci(int index) { /* 35*/ { 30, 0, "詰", -1, 0, 2, { 0x7D + 0x80, 0x7E + 0x80 }, "EUC-KR U+8A70 (0xFDFE)" }, /* 36*/ { 30, 1, "詰", -1, 0, 2, { 0x7D + 0x80, 0x7E + 0x80 }, "EUC-KR > 0xEBBF so not in QR Kanji mode range" }, }; - - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length, ret; unsigned int jisdata[20]; - for (int i = 0; i < data_size; i++) { + testStart("test_sjis_utf8_to_eci"); + + for (i = 0; i < data_size; i++) { + int ret_length; if (index != -1 && i != index) continue; - int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - int ret_length = length; + length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; + ret_length = length; ret = sjis_utf8_to_eci(data[i].eci, (unsigned char *) 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) { + int j; assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < (int) ret_length; j++) { + for (j = 0; j < ret_length; j++) { assert_equal(jisdata[j], data[i].expected_jisdata[j], "i:%d jisdata[%d] 0x%04X != 0x%04X\n", i, j, jisdata[j], data[i].expected_jisdata[j]); } } @@ -257,8 +262,6 @@ static void test_sjis_utf8_to_eci(int index) { static void test_sjis_cpy(int index) { - testStart(""); - struct item { int full_multibyte; char *data; @@ -280,21 +283,25 @@ static void test_sjis_cpy(int index) { /* 7*/ { 0, "\201\077\201\100\237\374\237\375\340\077\340\100\353\277\353\300", -1, 0, 16, { 0x81, 0x3F, 0x81, 0x40, 0x9F, 0xFC, 0x9F, 0xFD, 0xE0, 0x3F, 0xE0, 0x40, 0xEB, 0xBF, 0xEB, 0xC0 }, "" }, /* 8*/ { 1, "\201\077\201\100\237\374\237\375\340\077\340\100\353\277\353\300", -1, 0, 12, { 0x81, 0x3F, 0x8140, 0x9FFC, 0x9F, 0xFD, 0xE0, 0x3F, 0xE040, 0xEBBF, 0xEB, 0xC0 }, "" }, }; - - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length; unsigned int jisdata[20]; - for (int i = 0; i < data_size; i++) { + testStart("test_sjis_cpy"); + + for (i = 0; i < data_size; i++) { + int ret_length; + int j; if (index != -1 && i != index) continue; - int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - int ret_length = length; + length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; + ret_length = length; sjis_cpy((unsigned char *) data[i].data, &ret_length, jisdata, data[i].full_multibyte); assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); - for (int j = 0; j < (int) ret_length; j++) { + for (j = 0; j < 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]); } } diff --git a/backend/tests/test_svg.c b/backend/tests/test_svg.c index 56e30011..f0abf2dc 100644 --- a/backend/tests/test_svg.c +++ b/backend/tests/test_svg.c @@ -34,16 +34,6 @@ static void test_print(int index, int generate, int debug) { - testStart(""); - - int have_libreoffice = 0; - int have_vnu = 0; - if (generate) { - have_libreoffice = testUtilHaveLibreOffice(); - have_vnu = testUtilHaveVnu(); - } - - int ret; struct item { int symbology; int input_mode; @@ -107,6 +97,8 @@ static void test_print(int index, int generate, int debug) { /* 43*/ { BARCODE_USPS_IMAIL, -1, -1, -1, -1, -1, -1, -1, -1, 7.75, "12345678901234567890", "", 0, "imail_height7.75.svg" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; const char *data_dir = "/backend/tests/data/svg"; const char *svg = "out.svg"; @@ -115,23 +107,33 @@ static void test_print(int index, int generate, int debug) { int escaped_size = 1024; char *text; + int have_libreoffice = 0; + int have_vnu = 0; + + testStart("test_print"); + if (generate) { char data_dir_path[1024]; + + have_libreoffice = testUtilHaveLibreOffice(); + have_vnu = testUtilHaveVnu(); + assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); - if (!testUtilExists(data_dir_path)) { - ret = testutil_mkdir(data_dir_path, 0755); - assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir_path, ret, errno, strerror(errno)); + if (!testUtilDirExists(data_dir_path)) { + ret = testUtilMkDir(data_dir_path); + assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_dir_path, ret, errno, strerror(errno)); } } - for (int i = 0; i < data_size; i++) { + for (i = 0; i < data_size; i++) { + int text_length; if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + 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, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug); if (data[i].show_hrt != -1) { symbol->show_hrt = data[i].show_hrt; } @@ -153,7 +155,7 @@ static void test_print(int index, int generate, int debug) { } else { text = data[i].data; } - int text_length = strlen(text); + text_length = strlen(text); ret = ZBarcode_Encode(symbol, (unsigned char *) text, text_length); assert_equal(ret, data[i].ret, "i:%d %s ZBarcode_Encode ret %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, data[i].ret, symbol->errtxt); @@ -169,8 +171,8 @@ static void test_print(int index, int generate, int debug) { i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].border_width, testUtilOutputOptionsName(data[i].output_options), data[i].whitespace_width, data[i].whitespace_height, data[i].show_hrt, data[i].option_1, data[i].option_2, data[i].height, testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].composite, 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); + ret = testUtilRename(symbol->outfile, expected_file); + assert_zero(ret, "i:%d testUtilRename(%s, %s) ret %d != 0\n", i, symbol->outfile, expected_file, ret); if (have_libreoffice) { ret = testUtilVerifyLibreOffice(expected_file, debug); assert_zero(ret, "i:%d %s libreoffice %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret); diff --git a/backend/tests/test_telepen.c b/backend/tests/test_telepen.c index 4b5824d4..cab67119 100644 --- a/backend/tests/test_telepen.c +++ b/backend/tests/test_telepen.c @@ -33,9 +33,6 @@ static void test_large(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *pattern; @@ -52,20 +49,24 @@ static void test_large(int index, int debug) { /* 3*/ { BARCODE_TELEPEN_NUM, "1", 61, ZINT_ERROR_TOO_LONG, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char data_buf[64]; - for (int i = 0; i < data_size; i++) { + testStart("test_large"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data_buf, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -83,9 +84,6 @@ static void test_large(int index, int debug) { static void test_hrt(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -105,15 +103,19 @@ static void test_hrt(int index, int debug) { /* 7*/ { BARCODE_TELEPEN_NUM, "12345", -1, "012345" }, // Adds leading zero if odd }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_hrt"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt); @@ -128,9 +130,6 @@ static void test_hrt(int index, int debug) { static void test_input(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -152,15 +151,19 @@ static void test_input(int index, int debug) { /* 8*/ { BARCODE_TELEPEN_NUM, "1X34567X9X", -1, 0, 1, 128 }, // [0-9]X allowed multiple times }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -180,11 +183,6 @@ static void test_input(int index, int debug) { // E2326U: SB Telepen Barcode Fonts Guide Issue 2 (Apr 2009) https://telepen.co.uk/wp-content/uploads/2018/09/SB-Telepen-Barcode-Fonts-V2.pdf 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; char *data; @@ -226,19 +224,25 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; char bwipp_buf[8192]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -251,10 +255,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < 5) { + int width, row; + 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); - 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); @@ -278,9 +283,6 @@ static void test_encode(int index, int generate, int debug) { // #181 Nico Gunkel OSS-Fuzz static void test_fuzz(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -298,19 +300,23 @@ static void test_fuzz(int index, int debug) { /* 5*/ { BARCODE_TELEPEN_NUM, "00000000000000000000000000000000000000000000000000000000000X", 60, 0 }, /* 6*/ { BARCODE_TELEPEN_NUM, "999999999999999999999999999999999999999999999999999999999999", 60, 0 }, }; - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_fuzz"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->symbology = data[i].symbology; symbol->debug |= debug; - int length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; + length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; ret = ZBarcode_Encode(symbol, (unsigned char *) 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_tif.c b/backend/tests/test_tif.c index c6dfdede..5c51c6cd 100644 --- a/backend/tests/test_tif.c +++ b/backend/tests/test_tif.c @@ -37,12 +37,6 @@ 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) { - testStart(""); - - int have_tiffinfo = testUtilHaveTiffInfo(); - int have_identify = testUtilHaveIdentify(); - - int ret; struct item { int width; int height; @@ -82,15 +76,23 @@ static void test_pixel_plot(int index, int debug) { /* 27*/ { 4, 2049, "10", 1, 0 }, // Strip Count 5, Rows Per Strip 512 ((4 * 512 + 1) * 4 == 8196) }; int data_size = ARRAY_SIZE(data); + int i, ret; + struct zint_symbol *symbol; char *tif = "out.tif"; char data_buf[65536]; - struct zint_symbol *symbol = ZBarcode_Create(); + int have_tiffinfo = testUtilHaveTiffInfo(); + int have_identify = testUtilHaveIdentify(); + + testStart("test_pixel_plot"); + + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - for (int i = 0; i < data_size; i++) { + for (i = 0; i < data_size; i++) { + int size; if (index != -1 && i != index) continue; @@ -102,7 +104,7 @@ static void test_pixel_plot(int index, int debug) { strcpy(symbol->bgcolour, "FFFFFFEE"); symbol->debug |= debug; - int size = data[i].width * data[i].height; + size = data[i].width * data[i].height; assert_nonzero(size < (int) sizeof(data_buf), "i:%d tif_pixel_plot size %d >= sizeof(data_buf) %d\n", i, size, (int) sizeof(data_buf)); if (data[i].repeat) { @@ -139,12 +141,6 @@ static void test_pixel_plot(int index, int debug) { static void test_print(int index, int generate, int debug) { - testStart(""); - - int have_tiffinfo = testUtilHaveTiffInfo(); - int have_identify = testUtilHaveIdentify(); - - int ret; struct item { int symbology; int input_mode; @@ -182,6 +178,8 @@ static void test_print(int index, int generate, int debug) { /* 15*/ { BARCODE_DAFT, -1, -1, -1, -1, -1, -1, -1, 1, 0.5f, "", "", "DAFT", "", "daft_height1_scale0.5.tif", "" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; const char *data_dir = "/backend/tests/data/tif"; const char *tif = "out.tif"; @@ -190,23 +188,29 @@ static void test_print(int index, int generate, int debug) { int escaped_size = 1024; char *text; + int have_tiffinfo = testUtilHaveTiffInfo(); + int have_identify = testUtilHaveIdentify(); + + testStart("test_print"); + if (generate) { char data_dir_path[1024]; assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); - if (!testUtilExists(data_dir_path)) { - ret = testutil_mkdir(data_dir_path, 0755); - assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir_path, ret, errno, strerror(errno)); + if (!testUtilDirExists(data_dir_path)) { + ret = testUtilMkDir(data_dir_path); + assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_dir_path, ret, errno, strerror(errno)); } } - for (int i = 0; i < data_size; i++) { + for (i = 0; i < data_size; i++) { + int text_length; if (index != -1 && i != index) continue; - struct zint_symbol* symbol = ZBarcode_Create(); + 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, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug); if (data[i].show_hrt != -1) { symbol->show_hrt = data[i].show_hrt; } @@ -234,7 +238,7 @@ static void test_print(int index, int generate, int debug) { } else { text = data[i].data; } - int text_length = strlen(text); + text_length = strlen(text); ret = ZBarcode_Encode(symbol, (unsigned char *) text, text_length); assert_zero(ret, "i:%d %s ZBarcode_Encode ret %d != 0 %s\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt); @@ -250,8 +254,8 @@ static void test_print(int index, int generate, int debug) { i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].border_width, testUtilOutputOptionsName(data[i].output_options), data[i].whitespace_width, data[i].show_hrt, data[i].option_1, data[i].option_2, data[i].height, data[i].scale, data[i].fgcolour, data[i].bgcolour, testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].composite, data[i].expected_file, data[i].comment); - ret = rename(symbol->outfile, expected_file); - assert_zero(ret, "i:%d rename(%s, %s) ret %d != 0\n", i, symbol->outfile, expected_file, ret); + ret = testUtilRename(symbol->outfile, expected_file); + assert_zero(ret, "i:%d testUtilRename(%s, %s) ret %d != 0\n", i, symbol->outfile, expected_file, ret); if (have_tiffinfo) { ret = testUtilVerifyTiffInfo(expected_file, debug); assert_zero(ret, "i:%d %s tiffinfo %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret); diff --git a/backend/tests/test_ultra.c b/backend/tests/test_ultra.c index 7f8bb3c3..200f122d 100644 --- a/backend/tests/test_ultra.c +++ b/backend/tests/test_ultra.c @@ -33,9 +33,6 @@ static void test_reader_init(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int output_options; @@ -52,19 +49,23 @@ static void test_reader_init(int index, int generate, int debug) { /* 1*/ { UNICODE_MODE, READER_INIT, ULTRA_COMPRESSION, "A", 0, 13, 14, "(3) 272 271 65", "ASCII FNC3 A Note: draft spec inconsistent and FNC3 may be 272 in ASCII mode (and FNC1 271)" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_reader_init"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_ULTRA, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, data[i].option_3, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_ULTRA, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, data[i].option_3, data[i].output_options, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -90,9 +91,6 @@ static void test_reader_init(int index, int generate, int debug) { static void test_input(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int eci; @@ -152,19 +150,23 @@ static void test_input(int index, int generate, int debug) { /* 45*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "AAaatel:aA", 0, "(10) 272 276 0 42 0 41 118 46 6 156", "Mode: c (10)" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_ULTRA, data[i].input_mode, data[i].eci, data[i].option_1, -1, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_ULTRA, data[i].input_mode, data[i].eci, data[i].option_1, -1, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); @@ -187,9 +189,6 @@ static void test_input(int index, int generate, int debug) { static void test_encode(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int input_mode; int eci; @@ -479,17 +478,21 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char escaped[1024]; - for (int i = 0; i < data_size; i++) { + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_ULTRA, data[i].input_mode, data[i].eci, data[i].option_1, -1, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_ULTRA, data[i].input_mode, data[i].eci, data[i].option_1, -1, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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_upcean.c b/backend/tests/test_upcean.c index dc47c0ba..1d0c9108 100644 --- a/backend/tests/test_upcean.c +++ b/backend/tests/test_upcean.c @@ -33,9 +33,6 @@ static void test_upce_input(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -88,15 +85,19 @@ static void test_upce_input(int index, int debug) { /* 42*/ { BARCODE_UPCE, "000002", 0 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_upce_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -110,9 +111,6 @@ static void test_upce_input(int index, int debug) { // Note requires ZINT_SANITIZE to be set static void test_upca_print(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -123,15 +121,19 @@ static void test_upca_print(int index, int debug) { /* 0*/ { BARCODE_UPCA, "01234567890", 0 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_upca_print"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -150,9 +152,6 @@ static void test_upca_print(int index, int debug) { static void test_upca_input(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -227,15 +226,19 @@ static void test_upca_input(int index, int debug) { /* 64*/ { BARCODE_UPCA_CHK, "0+12345", 0 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_upca_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -248,9 +251,6 @@ static void test_upca_input(int index, int debug) { static void test_eanx_input(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -382,15 +382,19 @@ static void test_eanx_input(int index, int debug) { /*121*/ { BARCODE_EANX_CHK, "1234567890123456789", ZINT_ERROR_TOO_LONG }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_eanx_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -403,9 +407,6 @@ static void test_eanx_input(int index, int debug) { static void test_isbn_input(int index, int debug) { - testStart(""); - - int ret; struct item { char *data; int ret_encode; @@ -470,16 +471,20 @@ static void test_isbn_input(int index, int debug) { /* 54*/ { "9791234567896+123456", ZINT_ERROR_TOO_LONG, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_isbn_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_ISBNX, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_ISBNX, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt); @@ -497,9 +502,6 @@ static void test_isbn_input(int index, int debug) { static void test_vector_same(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -512,19 +514,23 @@ static void test_vector_same(int index, int debug) { /* 2*/ { BARCODE_ISBNX, "0195049969", 0, 0 }, // 9 is correct check digit }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_vector_same"); + + for (i = 0; i < data_size; i++) { + struct zint_vector *vectors[4]; + int vectors_size = ARRAY_SIZE(vectors); + int j; 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(); + for (j = 0; j < vectors_size; j++) { + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt); @@ -538,12 +544,12 @@ static void test_vector_same(int index, int debug) { ZBarcode_Delete(symbol); } - for (int j = 1; j < vectors_size; j++) { + for (j = 1; j < vectors_size; j++) { ret = testUtilVectorCmp(vectors[j - 1], vectors[j]); assert_zero(ret, "i:%d testUtilVectorCmp ret %d != 0\n", i, ret); } - for (int j = 0; j < vectors_size; j++) { + for (j = 0; j < vectors_size; j++) { struct zint_symbol symbol_vector; symbol_vector.vector = vectors[j]; vector_free(&symbol_vector); @@ -557,11 +563,6 @@ static void test_vector_same(int index, int debug) { // https://bisg.org/page/BarcodingGuidelines BISG Barcode Guidelines for the US Book Industry (BISG BGUSBI) 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; int option_2; @@ -684,18 +685,24 @@ static void test_encode(int index, int generate, int debug) { }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char bwipp_buf[4096]; char bwipp_msg[1024]; - for (int i = 0; i < data_size; i++) { + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + testStart("test_encode"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); @@ -707,10 +714,11 @@ static void test_encode(int index, int generate, int debug) { printf(" },\n"); } else { if (ret < ZINT_ERROR) { + int width, row; + 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); - 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); @@ -734,9 +742,6 @@ static void test_encode(int index, int generate, int debug) { // #181 Christian Hartlage OSS-Fuzz static void test_fuzz(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -758,15 +763,19 @@ static void test_fuzz(int index, int debug) { /*10*/ { BARCODE_EANX, "000002000000200+203", -1, ZINT_ERROR_TOO_LONG }, // #218 Jan Schrewe CI-Fuzz }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_fuzz"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); diff --git a/backend/tests/test_vector.c b/backend/tests/test_vector.c index 639ba111..e90699b4 100644 --- a/backend/tests/test_vector.c +++ b/backend/tests/test_vector.c @@ -62,9 +62,6 @@ static struct zint_vector_rect *find_rect(struct zint_symbol *symbol, float x, f static void test_options(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *fgcolour; @@ -86,15 +83,19 @@ static void test_options(int index, int debug) { /* 4*/ { BARCODE_CODE128, NULL, "EEFFGG", 0, "A", ZINT_ERROR_INVALID_OPTION, -1, -1, -1, -1 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_options"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, BARCODE_CODE128, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, BARCODE_CODE128, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); if (data[i].fgcolour) { strcpy(symbol->fgcolour, data[i].fgcolour); @@ -123,9 +124,6 @@ static void test_options(int index, int debug) { static void test_buffer_vector(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -267,15 +265,19 @@ static void test_buffer_vector(int index, int generate, int debug) { /*126*/ { BARCODE_ULTRA, "1234567890", "", 13, 13, 18, 36, 26 }, /*127*/ { BARCODE_RMQR, "12345", "", 11, 11, 27, 54, 22 }, }; - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char *text; - for (int i = 0; i < data_size; i++) { + testStart("test_buffer_vector"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->symbology = data[i].symbology; @@ -288,7 +290,7 @@ static void test_buffer_vector(int index, int generate, int debug) { } else { text = data[i].data; } - int length = strlen(text); + length = strlen(text); ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); assert_zero(ret, "i:%d ZBarcode_Encode(%d) ret %d != 0 %s\n", i, data[i].symbology, ret, symbol->errtxt); @@ -319,9 +321,6 @@ static void test_buffer_vector(int index, int generate, int debug) { static void test_upcean_hrt(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int show_hrt; @@ -379,13 +378,17 @@ static void test_upcean_hrt(int index, int debug) { /* 38*/ { BARCODE_UPCE, -1, "1234567+12345", 0, 50, 1, 105, 238.0, 116.4, 8, 66 }, /* 39*/ { BARCODE_UPCE, 0, "1234567+12345", 0, 50, 1, 105, 238.0, 110, -1, -1 }, }; - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_upcean_hrt"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->symbology = data[i].symbology; @@ -394,7 +397,7 @@ static void test_upcean_hrt(int index, int debug) { } symbol->debug |= debug; - int length = strlen(data[i].data); + length = strlen(data[i].data); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode(%d) ret %d != 0 %s\n", i, data[i].symbology, ret, symbol->errtxt); @@ -439,9 +442,6 @@ static void test_upcean_hrt(int index, int debug) { static void test_row_separator(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int border_width; @@ -470,17 +470,21 @@ static void test_row_separator(int index, int debug) { /* 8*/ { BARCODE_CODABLOCKF, 0, -1, -1, "A", 0, 20, 2, 101, 21, 42, 2 }, // Border width zero, same as default }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; struct zint_vector_rect *rect; - for (int i = 0; i < data_size; i++) { + testStart("test_row_separator"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); if (data[i].border_width != -1) { symbol->border_width = data[i].border_width; } @@ -507,9 +511,6 @@ static void test_row_separator(int index, int debug) { static void test_stacking(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int output_options; @@ -534,21 +535,26 @@ static void test_stacking(int index, int debug) { /* 2*/ { BARCODE_CODE128, BARCODE_BIND, -1, 2, "A", "B", 50, 2, 46, 92, 116, 48, 0, 4 }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; struct zint_vector_rect *rect; - for (int i = 0; i < data_size; i++) { + testStart("test_stacking"); + + for (i = 0; i < data_size; i++) { + int length2; if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, data[i].option_3, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, data[i].option_3, data[i].output_options, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ret %d != zero\n", i, ret); - int length2 = strlen(data[i].data2); + length2 = strlen(data[i].data2); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data2, length2); assert_zero(ret, "i:%d ret %d != zero\n", i, ret); @@ -586,9 +592,6 @@ static void test_stacking(int index, int debug) { static void test_output_options(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; int whitespace_width; @@ -654,17 +657,21 @@ static void test_output_options(int index, int debug) { /* 42*/ { BARCODE_ITF14, -1, -1, 0, BARCODE_BOX, "123", 0, 50, 1, 135, 310, 118.9, 0, 300, 0 }, // No zero-width/height rectangles }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; struct zint_vector_rect *rect; - for (int i = 0; i < data_size; i++) { + testStart("test_output_options"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, data[i].output_options, data[i].data, -1, debug); if (data[i].whitespace_width != -1) { symbol->whitespace_width = data[i].whitespace_width; } @@ -717,9 +724,6 @@ static void test_output_options(int index, int debug) { // Checks that symbol lead-in (composite offset) isn't used to calc string position for non-composite barcodes static void test_noncomposite_string_x(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -733,20 +737,24 @@ static void test_noncomposite_string_x(int index, int debug) { /* 1*/ { BARCODE_DBAR_LTD, "1234567890123", 79, 79 }, /* 2*/ { BARCODE_DBAR_EXP, "[01]12345678901231", 134, 134 }, }; - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; - for (int i = 0; i < data_size; i++) { + testStart("test_noncomposite_string_x"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + 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); + length = strlen(data[i].data); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode(%d) ret %d != 0 %s\n", i, data[i].symbology, ret, symbol->errtxt); @@ -769,9 +777,6 @@ static void test_noncomposite_string_x(int index, int debug) { // Checks UPCA/UPCE main_symbol_width_x (used for addon formatting) set whether whitespace width set or not static void test_upcean_whitespace_width(int index, int debug) { - testStart(""); - - int ret; struct item { int symbology; char *data; @@ -789,16 +794,20 @@ static void test_upcean_whitespace_width(int index, int debug) { /* 2*/ { BARCODE_UPCE, "1234567+12", 0, 78, 184.0, 4, 15.0 }, /* 3*/ { BARCODE_UPCE, "1234567+12", 8, 78, 184.0 + 4 * 8, 4, 15.0 }, // Note: change from previous behaviour where if whitespace < 10 then set to 10 }; - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; struct zint_vector_string *string; int string_cnt; - for (int i = 0; i < data_size; i++) { + testStart("test_upcean_whitespace_width"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->symbology = data[i].symbology; @@ -806,7 +815,7 @@ static void test_upcean_whitespace_width(int index, int debug) { symbol->whitespace_width = data[i].whitespace_width; symbol->debug |= debug; - int length = strlen(data[i].data); + length = strlen(data[i].data); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode(%d) ret %d != 0 %s\n", i, data[i].symbology, ret, symbol->errtxt); @@ -840,9 +849,6 @@ static void test_upcean_whitespace_width(int index, int debug) { static void test_height(int index, int generate, int debug) { - testStart(""); - - int ret; struct item { int symbology; float height; @@ -1263,15 +1269,19 @@ static void test_height(int index, int generate, int debug) { /*401*/ { BARCODE_RMQR, 1, "12345", "", 0, 11, 11, 27, 54, 22, "Fixed width-to-height ratio, symbol->height ignored" }, }; int data_size = ARRAY_SIZE(data); + int i, length, ret; + struct zint_symbol *symbol; char *text; - for (int i = 0; i < data_size; i++) { + testStart("test_height"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d\n", i); - struct zint_symbol *symbol = ZBarcode_Create(); + symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); symbol->symbology = data[i].symbology; @@ -1288,7 +1298,7 @@ static void test_height(int index, int generate, int debug) { } else { text = data[i].data; } - int length = strlen(text); + length = strlen(text); ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode(%s) ret %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, data[i].ret, symbol->errtxt); diff --git a/backend/tests/testcommon.c b/backend/tests/testcommon.c index ab4aac51..9be31689 100644 --- a/backend/tests/testcommon.c +++ b/backend/tests/testcommon.c @@ -42,6 +42,11 @@ #define testutil_alloca(nmemb) alloca(nmemb) #endif +#ifdef _WIN32 +#include +#include +#endif + #include "../eci.h" #ifndef NO_PNG #include @@ -49,9 +54,10 @@ #include #endif #include +#include #include #include -#include +#include static int tests = 0; static int failed = 0; @@ -61,13 +67,63 @@ int assertionNum = 0; static const char *testName = NULL; static const char *testFunc = NULL; +#if _MSC_VER == 1200 +#include +void assert_zero(int exp, const char *fmt, ...) { + assertionNum++; + if (exp != 0) { + va_list args; assertionFailed++; va_start(args, fmt); vprintf(fmt, args); va_end(args); testFinish(); + } +} +void assert_nonzero(int exp, const char *fmt, ...) { + assertionNum++; + if (exp == 0) { + va_list args; assertionFailed++; va_start(args, fmt); vprintf(fmt, args); va_end(args); testFinish(); + } +} +void assert_null(void *exp, const char *fmt, ...) { + assertionNum++; + if (exp != NULL) { + va_list args; assertionFailed++; va_start(args, fmt); vprintf(fmt, args); va_end(args); testFinish(); + } +} +void assert_nonnull(void *exp, const char *fmt, ...) { + assertionNum++; + if (exp == NULL) { + va_list args; assertionFailed++; va_start(args, fmt); vprintf(fmt, args); va_end(args); testFinish(); + } +} +void assert_equal(int e1, int e2, const char *fmt, ...) { + assertionNum++; + if (e1 != e2) { + va_list args; assertionFailed++; va_start(args, fmt); vprintf(fmt, args); va_end(args); testFinish(); + } +} +void assert_equalu64(uint64_t e1, uint64_t e2, const char *fmt, ...) { + assertionNum++; + if (e1 != e2) { + va_list args; assertionFailed++; va_start(args, fmt); vprintf(fmt, args); va_end(args); testFinish(); + } +} +void assert_notequal(int e1, int e2, const char *fmt, ...) { + assertionNum++; + if (e1 == e2) { + va_list args; assertionFailed++; va_start(args, fmt); vprintf(fmt, args); va_end(args); testFinish(); + } +} +#endif + void testStartReal(const char *func, const char *name) { tests++; - testName = name; - testFunc = func; + if (*func && name && *name && strcmp(func, name) == 0) { + testName = ""; + } else { + testName = name; + } + testFunc = func ? func : ""; assertionFailed = 0; assertionNum = 0; - printf("_____%d: %s: %s...\n", tests, func, name); + printf("_____%d: %s: %s...\n", tests, testFunc, testName ? testName : ""); } void testEnd(int result) { @@ -388,7 +444,7 @@ const char *testUtilBarcodeName(int symbology) { { "BARCODE_ULTRA", BARCODE_ULTRA, 144 }, { "BARCODE_RMQR", BARCODE_RMQR, 145 }, }; - static const int data_size = sizeof(data) / sizeof(struct item); + static const int data_size = ARRAY_SIZE(data); if (symbology < 0 || symbology >= data_size) { return ""; @@ -448,7 +504,7 @@ const char *testUtilErrorName(int error_number) { { "ZINT_ERROR_FILE_ACCESS", ZINT_ERROR_FILE_ACCESS, 10 }, { "ZINT_ERROR_MEMORY", ZINT_ERROR_MEMORY, 11 }, }; - static const int data_size = sizeof(data) / sizeof(struct item); + static const int data_size = ARRAY_SIZE(data); if (error_number < 0 || error_number >= data_size) { return ""; @@ -601,9 +657,10 @@ const char *testUtilOutputOptionsName(int output_options) { } int testUtilDAFTConvert(const struct zint_symbol *symbol, char *buffer, int buffer_size) { - buffer[0] = '\0'; + int i; char *b = buffer; - for (int i = 0; i < symbol->width && b < buffer + buffer_size; i += 2) { + *b = '\0'; + for (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'; } else if (module_is_set(symbol, 0, i)) { @@ -699,6 +756,7 @@ void testUtilStrCpyRepeat(char *buffer, char *repeat, int size) { } int testUtilSymbolCmp(const struct zint_symbol *a, const struct zint_symbol *b) { + int i, j; if (a->symbology != b->symbology) { return 1; } @@ -709,16 +767,16 @@ int testUtilSymbolCmp(const struct zint_symbol *a, const struct zint_symbol *b) return 3; } if (a->symbology == BARCODE_ULTRA) { - for (int i = 0; i < a->rows; i++) { - for (int j = 0; j < a->width; j++) { + for (i = 0; i < a->rows; i++) { + for (j = 0; j < a->width; j++) { if (module_colour_is_set(a, i, j) != module_colour_is_set(b, i, j)) { return 4; } } } } else { - for (int i = 0; i < a->rows; i++) { - for (int j = 0; j < a->width; j++) { + for (i = 0; i < a->rows; i++) { + for (j = 0; j < a->width; j++) { if (module_is_set(a, i, j) != module_is_set(b, i, j)) { return 4; } @@ -745,15 +803,6 @@ int testUtilSymbolCmp(const struct zint_symbol *a, const struct zint_symbol *b) } struct zint_vector *testUtilVectorCpy(const struct zint_vector *in) { - struct zint_vector *out = malloc(sizeof(struct zint_vector)); - assert(out != NULL); - out->width = in->width; - out->height = in->height; - out->rectangles = NULL; - out->strings = NULL; - out->circles = NULL; - out->hexagons = NULL; - struct zint_vector_rect *rect; struct zint_vector_string *string; struct zint_vector_circle *circle; @@ -764,6 +813,15 @@ struct zint_vector *testUtilVectorCpy(const struct zint_vector *in) { struct zint_vector_circle **outcircle; struct zint_vector_hexagon **outhexagon; + struct zint_vector *out = malloc(sizeof(struct zint_vector)); + assert(out != NULL); + out->width = in->width; + out->height = in->height; + out->rectangles = NULL; + out->strings = NULL; + out->circles = NULL; + out->hexagons = NULL; + // Copy rectangles rect = in->rectangles; outrect = &(out->rectangles); @@ -1327,6 +1385,41 @@ int testUtilExists(const char *filename) { return 1; } +int testUtilDirExists(const char *dirname) { +#ifdef _WIN32 + DWORD dwAttrib = GetFileAttributes(dirname); + return dwAttrib != (DWORD) -1 && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY); +#else + return testUtilExists(dirname); +#endif +} + +// Returns 0 if successful, non-zero if not +int testUtilMkDir(const char *dirname) { +#ifdef _WIN32 + return CreateDirectory(dirname, NULL) == 0; +#else + return mkdir(dirname, S_IRWXU); +#endif +} + +// Returns 0 if successful, non-zero if not +int testUtilRmDir(const char *dirname) { +#ifdef _WIN32 + return RemoveDirectory(dirname) == 0; +#else + return rmdir(dirname); +#endif +} + +int testUtilRename(const char *oldpath, const char *newpath) { +#ifdef _MSVC + int ret = remove(newpath); + if (ret != 0) return ret; +#endif + return rename(oldpath, newpath); +} + int testUtilCmpPngs(const char *png1, const char *png2) { int ret = -1; #ifdef NO_PNG @@ -2234,6 +2327,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int char cbracket = symbol->input_mode & GS1PARENS_MODE ? ')' : ']'; int addon_posn; int eci; + int i, j, len; bwipp_data[0] = bwipp_opts_buf[0] = '\0'; @@ -2387,9 +2481,9 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int bwipp_opts = bwipp_opts_buf; } else if (symbology == BARCODE_MSI_PLESSEY) { if (option_2 > 0) { + const char *checktype = NULL; sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sincludecheck", strlen(bwipp_opts_buf) ? " " : ""); - const char *checktype = NULL; if (option_2 >= 11 && option_2 <= 16) { option_2 -= 10; /* Remove no-check indicator */ } @@ -2498,7 +2592,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int } else if (symbology == BARCODE_CODEONE) { if ((symbol->input_mode & 0x07) == GS1_MODE) { /* Hack pseudo-GS1 support */ int last_ai, ai_latch = 0; - for (int i = 0, j = 0, len = (int) strlen(bwipp_data); i <= len; i++) { /* Reduce square brackets (include NUL) */ + for (i = 0, j = 0, len = (int) strlen(bwipp_data); i <= len; i++) { /* Reduce square brackets (include NUL) */ if (bwipp_data[i] == obracket) { if (ai_latch == 0) { bwipp_data[j++] = '['; @@ -2511,7 +2605,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int bwipp_data[j++] = bwipp_data[i]; } } - for (int len = (int) strlen(bwipp_data), i = len - 1; i >= 0; i--) { /* Replace square brackets with ^FNC1 */ + for (len = (int) strlen(bwipp_data), i = len - 1; i >= 0; i--) { /* Replace square brackets with ^FNC1 */ if (bwipp_data[i] == '[') { memmove(bwipp_data + i + 5, bwipp_data + i + 1, len - i); memcpy(bwipp_data + i, "^FNC1", 5); @@ -2543,7 +2637,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int if (primary_len == 0) { mode = 4; } else { - for (int i = 0; i < primary_len - 6; i++) { + for (i = 0; i < primary_len - 6; i++) { if (((symbol->primary[i] < '0') || (symbol->primary[i] > '9')) && (symbol->primary[i] != ' ')) { mode = 3; break; @@ -2564,14 +2658,14 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int memcpy(postcode, primary, postcode_len); postcode[postcode_len] = '\0'; if (mode == 2) { - for (int i = 0; i < postcode_len; i++) { + for (i = 0; i < postcode_len; i++) { if (postcode[i] == ' ') { postcode[i] = '\0'; } } } else { postcode[6] = '\0'; - for (int i = postcode_len; i < 6; i++) { + for (i = postcode_len; i < 6; i++) { postcode[i] = ' '; } } diff --git a/backend/tests/testcommon.h b/backend/tests/testcommon.h index 0e713b97..b508d49d 100644 --- a/backend/tests/testcommon.h +++ b/backend/tests/testcommon.h @@ -51,15 +51,6 @@ #define testutil_pclose(stream) pclose(stream) #endif -#ifdef _WIN32 -#include -#define testutil_mkdir(path, mode) _mkdir(path) -#define testutil_rmdir(path) _rmdir(path) -#else -#define testutil_mkdir(path, mode) mkdir(path, mode) -#define testutil_rmdir(path) rmdir(path) -#endif - #include #include #include "../common.h" @@ -85,7 +76,11 @@ extern "C" { extern int assertionFailed; extern int assertionNum; +#if _MSC_VER == 1200 /* VC6 */ +#define testStart(__arg__) (testStartReal("", __arg__)) +#else #define testStart(__arg__) (testStartReal(__func__, __arg__)) +#endif #define testEndExp(__arg__) (testEnd(!(__arg__))) void testStartReal(const char *func, const char *name); void testEnd(int result); @@ -98,6 +93,16 @@ typedef struct s_testFunction { } testFunction; void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size); +#if _MSC_VER == 1200 /* VC6 */ +#include "../ms_stdint.h" +void assert_zero(int exp, const char *fmt, ...); +void assert_nonzero(int exp, const char *fmt, ...); +void assert_null(void *exp, const char *fmt, ...); +void assert_nonnull(void *exp, const char *fmt, ...); +void assert_equal(int e1, int e2, const char *fmt, ...); +void assert_equalu64(uint64_t e1, uint64_t e2, const char *fmt, ...); +void assert_notequal(int e1, int e2, ...); +#else #define assert_exp(__exp__, ...) \ {assertionNum++; if (!(__exp__)) {assertionFailed++; printf(__VA_ARGS__); testFinish(); return;}} @@ -106,9 +111,9 @@ void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size); #define assert_null(__ptr__, ...) assert_exp((__ptr__) == NULL, __VA_ARGS__) #define assert_nonnull(__ptr__, ...) assert_exp((__ptr__) != NULL, __VA_ARGS__) #define assert_equal(__e1__, __e2__, ...) assert_exp((__e1__) == (__e2__), __VA_ARGS__) +#define assert_equalu64 assert_equal #define assert_notequal(__e1__, __e2__, ...) assert_exp((__e1__) != (__e2__), __VA_ARGS__) -#define assert_fail(...) assert_exp(0, __VA_ARGS__) -#define assert_nothing(__exp__, ...) {printf(__VA_ARGS__); __exp__;} +#endif INTERNAL void vector_free(struct zint_symbol *symbol); /* Free vector structures */ @@ -139,6 +144,10 @@ int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const ch void testUtilBitmapPrint(const struct zint_symbol *symbol, const char *prefix, const char *postfix); int testUtilBitmapCmp(const struct zint_symbol *symbol, const char *expected, int *row, int *column); int testUtilExists(const char *filename); +int testUtilDirExists(const char *dirname); +int testUtilMkDir(const char *dirname); +int testUtilRmDir(const char *dirname); +int testUtilRename(const char *oldpath, const char *newpath); int testUtilCmpPngs(const char *file1, const char *file2); int testUtilCmpTxts(const char *txt1, const char *txt2); int testUtilCmpBins(const char *bin1, const char *bin2); diff --git a/backend/vector.c b/backend/vector.c index 2e230c7e..8c21074b 100644 --- a/backend/vector.c +++ b/backend/vector.c @@ -413,7 +413,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ float digit_ascent_factor = 0.25f; /* Assuming digit ascent roughly 25% less than font size */ float text_gap; /* Gap between barcode and text */ float dot_overspill = 0.0f; - float dotoffset = 0.0f; + float dot_offset = 0.0f; int rect_count, last_row_start = 0; int this_row; @@ -475,13 +475,13 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ } if ((symbol->symbology != BARCODE_MAXICODE) && (symbol->output_options & BARCODE_DOTTY_MODE)) { - dot_overspill = symbol->dot_size - 1.0f; /* Allow for exceeding 1X */ - if (dot_overspill < 0.0f) { - dotoffset = -dot_overspill / 2.0f; + if (symbol->dot_size < 1.0f) { dot_overspill = 0.0f; - } else { - dot_overspill += 0.1f; /* Fudge for anti-aliasing */ - dotoffset = 0.05f; + /* Offset (1 - dot_size) / 2 + dot_radius == (1 - dot_size + dot_size) / 2 == 1 / 2 */ + dot_offset = 0.5f; + } else { /* Allow for exceeding 1X */ + dot_overspill = symbol->dot_size - 1.0f + 0.1f; /* Fudge for anti-aliasing */ + dot_offset = symbol->dot_size / 2.0f + 0.05f; /* Fudge for anti-aliasing */ } } @@ -548,12 +548,13 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ } // Dotty mode } else if (symbol->output_options & BARCODE_DOTTY_MODE) { - float dotradius = symbol->dot_size / 2.0f; for (r = 0; r < symbol->rows; r++) { for (i = 0; i < symbol->width; i++) { if (module_is_set(symbol, r, i)) { - struct zint_vector_circle *circle = vector_plot_create_circle(i + dotradius + dotoffset + xoffset, - r + dotradius + dotoffset + yoffset, symbol->dot_size, 0); + struct zint_vector_circle *circle = vector_plot_create_circle( + i + dot_offset + xoffset, + r + dot_offset + yoffset, + symbol->dot_size, 0); vector_plot_add_circle(symbol, circle, &last_circle); } } diff --git a/frontend/tests/test_args.c b/frontend/tests/test_args.c index 9fcd750f..71c009bc 100644 --- a/frontend/tests/test_args.c +++ b/frontend/tests/test_args.c @@ -226,8 +226,6 @@ static void arg_output_options(char *cmd, int output_options) { // Tests args that can be detected with `--dump` static void test_dump_args(int index, int debug) { - testStart(""); - struct item { int b; char *data; @@ -295,6 +293,7 @@ static void test_dump_args(int index, int debug) { /* 39*/ { BARCODE_HANXIN, "é", NULL, NULL, NULL, DATA_MODE, -1, 0, -1, 0, -1, 1, 4, -1, NULL, -1, -1, 0, -1, "FE 8A FE\n80 28 02\nBE E8 FA\nA0 94 0A\nAE 3E EA\nAE D2 EA\nAE 74 EA\n00 AA 00\n15 B4 AA\n0B 48 74\nA2 4A A4\nB5 56 2C\nA8 5A A8\n9F 18 50\nAA 07 50\n00 A6 00\nFE 20 EA\n02 C2 EA\nFA C4 EA\n0A 42 0A\nEA 52 FA\nEA 24 02\nEA AA FE" }, }; int data_size = ARRAY_SIZE(data); + int i; char cmd[4096]; char buf[4096]; @@ -304,7 +303,9 @@ static void test_dump_args(int index, int debug) { int have_input1; int have_input2; - for (int i = 0; i < data_size; i++) { + testStart("test_dump_args"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; @@ -351,8 +352,6 @@ static void test_dump_args(int index, int debug) { static void test_input(int index, int debug) { - testStart(""); - #ifdef _WIN32 #define TEST_INPUT_LONG "test_678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234" #else @@ -391,6 +390,7 @@ static void test_input(int index, int debug) { /* 15*/ { BARCODE_CODE128, 1, -1, 0, "eps", "123\n", "test_batch.ps", 1, "test_batch.eps" }, }; int data_size = ARRAY_SIZE(data); + int i; char cmd[4096]; char buf[4096]; @@ -398,7 +398,10 @@ static void test_input(int index, int debug) { char *input_filename = "test_input.txt"; char *outfile; - for (int i = 0; i < data_size; i++) { + testStart("test_input"); + + for (i = 0; i < data_size; i++) { + int j; if (index != -1 && i != index) continue; if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i); @@ -419,7 +422,7 @@ static void test_input(int index, int debug) { assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i), "i:%d exec(%s) NULL\n", i, cmd); outfile = data[i].expected; - for (int j = 0; j < data[i].num_expected; j++) { + for (j = 0; j < data[i].num_expected; j++) { assert_nonzero(testUtilExists(outfile), "i:%d j:%d testUtilExists(%s) != 1\n", i, j, outfile); assert_zero(remove(outfile), "i:%d j:%d remove(%s) != 0 (%d: %s)\n", i, j, outfile, errno, strerror(errno)); outfile += strlen(outfile) + 1; @@ -433,8 +436,6 @@ static void test_input(int index, int debug) { static void test_stdin_input(int index, int debug) { - testStart(""); - struct item { int b; char *data; @@ -446,13 +447,16 @@ static void test_stdin_input(int index, int debug) { /* 0*/ { BARCODE_CODE128, "123", "-", "test_stdin_input.gif" }, }; int data_size = ARRAY_SIZE(data); + int i; char cmd[4096]; char buf[4096]; char *input_filename = "-"; - for (int i = 0; i < data_size; i++) { + testStart("test_stdin_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; @@ -477,8 +481,6 @@ static void test_stdin_input(int index, int debug) { // Note ordering of `--batch` before/after data/input args affects error messages static void test_batch_input(int index, int debug) { - testStart(""); - struct item { int b; char *data; @@ -494,6 +496,7 @@ static void test_batch_input(int index, int debug) { /* 3*/ { BARCODE_CODE128, NULL, "123\n456\n", "789\n", "Warning 143: Can only define one input file in batch mode, ignoring 'test_batch_input2.txt'\nD2 13 9B 39 65 C8 C9 8E B\nD2 19 3B 72 67 4E 4D 8E B" }, }; int data_size = ARRAY_SIZE(data); + int i; char cmd[4096]; char buf[4096]; @@ -503,7 +506,9 @@ static void test_batch_input(int index, int debug) { int have_input1; int have_input2; - for (int i = 0; i < data_size; i++) { + testStart("test_batch_input"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; @@ -535,13 +540,6 @@ static void test_batch_input(int index, int debug) { static void test_batch_large(int index, int debug) { - testStart(""); - -#ifdef _WIN32 - testSkip("Test not compatible with Windows"); - return; -#endif - struct item { int b; int mirror; @@ -557,6 +555,7 @@ static void test_batch_large(int index, int debug) { /* 2*/ { BARCODE_HANXIN, 0, "1", 7828, NULL }, }; int data_size = ARRAY_SIZE(data); + int i; char cmd[16384]; char data_buf[8192]; @@ -565,7 +564,14 @@ static void test_batch_large(int index, int debug) { char *input_filename = "test_batch_large.txt"; int have_input; - for (int i = 0; i < data_size; i++) { + testStart("test_batch_large"); + +#ifdef _WIN32 + testSkip("Test not compatible with Windows"); + return; +#endif + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i); @@ -599,8 +605,6 @@ static void test_batch_large(int index, int debug) { static void test_checks(int index, int debug) { - testStart(""); - struct item { int addongap; int border; @@ -661,12 +665,15 @@ static void test_checks(int index, int debug) { /* 33*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1001, "Warning 121: Horizontal whitespace value out of range (0 to 1000), ignoring" }, }; int data_size = ARRAY_SIZE(data); + int i; char cmd[4096]; char buf[4096]; char *outfilename = "out.gif"; - for (int i = 0; i < data_size; i++) { + testStart("test_checks"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; @@ -709,8 +716,6 @@ static void test_checks(int index, int debug) { static void test_barcode_symbology(int index, int debug) { - testStart(""); - struct item { const char *bname; const char *data; @@ -843,12 +848,15 @@ static void test_barcode_symbology(int index, int debug) { /*120*/ { "\177", "1", NULL, 1, "Error 119: Invalid barcode type '\177'" }, }; int data_size = ARRAY_SIZE(data); + int i; char cmd[4096]; char buf[8192]; char *outfilename = "out.gif"; - for (int i = 0; i < data_size; i++) { + testStart("test_barcode_symbology"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; @@ -873,8 +881,6 @@ static void test_barcode_symbology(int index, int debug) { static void test_other_opts(int index, int debug) { - testStart(""); - struct item { int b; char *data; @@ -909,10 +915,14 @@ static void test_other_opts(int index, int debug) { /* 20*/ { BARCODE_GS1_128, "[00]376104250021234568", -1, " --werror", NULL, "Warning 261: AI (00) position 18: Bad checksum '8', expected '9'" }, }; int data_size = ARRAY_SIZE(data); + int i; + char cmd[4096]; char buf[8192]; - for (int i = 0; i < data_size; i++) { + testStart("test_other_opts"); + + for (i = 0; i < data_size; i++) { if (index != -1 && i != index) continue;