CODABLOCKF inter-row bindings too short fix; -Wextra; tests

This commit is contained in:
gitlost
2020-04-03 19:40:59 +01:00
parent dc56c5ed0f
commit 2d0b966de6
12 changed files with 479 additions and 34 deletions

View File

@ -71,11 +71,13 @@ zint_add_test(library, test_library)
zint_add_test(mailmark, test_mailmark)
zint_add_test(maxicode, test_maxicode)
zint_add_test(pdf417, test_pdf417)
zint_add_test(png, test_png)
zint_add_test(postal, test_postal)
zint_add_test(qr, test_qr)
zint_add_test(raster, test_raster)
zint_add_test(rss, test_rss)
zint_add_test(sjis, test_sjis)
zint_add_test(svg, test_svg)
zint_add_test(telepen, test_telepen)
zint_add_test(upcean, test_upcean)
zint_add_test(vector, test_vector)

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

View File

@ -0,0 +1,63 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="210" height="68" version="1.1"
xmlns="http://www.w3.org/2000/svg">
<desc>Zint Generated Symbol
</desc>
<g id="barcode" fill="#000000">
<rect x="0" y="0" width="210" height="68" fill="#FFFFFF" />
<rect x="4.00" y="4.00" width="4.00" height="60.00" />
<rect x="10.00" y="4.00" width="2.00" height="60.00" />
<rect x="20.00" y="4.00" width="2.00" height="60.00" />
<rect x="26.00" y="4.00" width="2.00" height="60.00" />
<rect x="30.00" y="4.00" width="8.00" height="60.00" />
<rect x="40.00" y="4.00" width="6.00" height="60.00" />
<rect x="48.00" y="4.00" width="2.00" height="20.00" />
<rect x="54.00" y="4.00" width="2.00" height="20.00" />
<rect x="58.00" y="4.00" width="4.00" height="20.00" />
<rect x="70.00" y="4.00" width="2.00" height="60.00" />
<rect x="74.00" y="4.00" width="2.00" height="60.00" />
<rect x="82.00" y="4.00" width="4.00" height="60.00" />
<rect x="92.00" y="4.00" width="2.00" height="60.00" />
<rect x="96.00" y="4.00" width="2.00" height="40.00" />
<rect x="104.00" y="4.00" width="4.00" height="40.00" />
<rect x="114.00" y="4.00" width="2.00" height="40.00" />
<rect x="118.00" y="4.00" width="2.00" height="40.00" />
<rect x="126.00" y="4.00" width="4.00" height="40.00" />
<rect x="136.00" y="4.00" width="2.00" height="40.00" />
<rect x="140.00" y="4.00" width="2.00" height="40.00" />
<rect x="148.00" y="4.00" width="4.00" height="40.00" />
<rect x="158.00" y="4.00" width="4.00" height="20.00" />
<rect x="164.00" y="4.00" width="4.00" height="20.00" />
<rect x="172.00" y="4.00" width="4.00" height="20.00" />
<rect x="180.00" y="4.00" width="4.00" height="60.00" />
<rect x="190.00" y="4.00" width="6.00" height="60.00" />
<rect x="198.00" y="4.00" width="2.00" height="60.00" />
<rect x="202.00" y="4.00" width="4.00" height="60.00" />
<rect x="48.00" y="24.00" width="4.00" height="20.00" />
<rect x="58.00" y="24.00" width="2.00" height="20.00" />
<rect x="64.00" y="24.00" width="2.00" height="20.00" />
<rect x="158.00" y="24.00" width="8.00" height="20.00" />
<rect x="168.00" y="24.00" width="2.00" height="40.00" />
<rect x="176.00" y="24.00" width="2.00" height="20.00" />
<rect x="48.00" y="44.00" width="2.00" height="20.00" />
<rect x="52.00" y="44.00" width="4.00" height="20.00" />
<rect x="60.00" y="44.00" width="6.00" height="20.00" />
<rect x="96.00" y="44.00" width="6.00" height="20.00" />
<rect x="104.00" y="44.00" width="8.00" height="20.00" />
<rect x="114.00" y="44.00" width="4.00" height="20.00" />
<rect x="122.00" y="44.00" width="4.00" height="20.00" />
<rect x="128.00" y="44.00" width="4.00" height="20.00" />
<rect x="136.00" y="44.00" width="4.00" height="20.00" />
<rect x="144.00" y="44.00" width="6.00" height="20.00" />
<rect x="154.00" y="44.00" width="2.00" height="20.00" />
<rect x="158.00" y="44.00" width="4.00" height="20.00" />
<rect x="174.00" y="44.00" width="2.00" height="20.00" />
<rect x="26.00" y="22.00" width="158.00" height="4.00" />
<rect x="26.00" y="42.00" width="158.00" height="4.00" />
<rect x="4.00" y="0.00" width="202.00" height="4.00" />
<rect x="4.00" y="64.00" width="202.00" height="4.00" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -0,0 +1,41 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="180" height="118" version="1.1"
xmlns="http://www.w3.org/2000/svg">
<desc>Zint Generated Symbol
</desc>
<g id="barcode" fill="#000000">
<rect x="0" y="0" width="180" height="118" fill="#FFFFFF" />
<rect x="0.00" y="0.00" width="4.00" height="100.00" />
<rect x="6.00" y="0.00" width="2.00" height="100.00" />
<rect x="12.00" y="0.00" width="2.00" height="100.00" />
<rect x="22.00" y="0.00" width="6.00" height="100.00" />
<rect x="32.00" y="0.00" width="4.00" height="100.00" />
<rect x="38.00" y="0.00" width="2.00" height="100.00" />
<rect x="44.00" y="0.00" width="4.00" height="100.00" />
<rect x="50.00" y="0.00" width="4.00" height="100.00" />
<rect x="56.00" y="0.00" width="4.00" height="100.00" />
<rect x="66.00" y="0.00" width="4.00" height="100.00" />
<rect x="74.00" y="0.00" width="4.00" height="100.00" />
<rect x="82.00" y="0.00" width="4.00" height="100.00" />
<rect x="88.00" y="0.00" width="2.00" height="100.00" />
<rect x="94.00" y="0.00" width="4.00" height="100.00" />
<rect x="102.00" y="0.00" width="2.00" height="100.00" />
<rect x="110.00" y="0.00" width="2.00" height="100.00" />
<rect x="116.00" y="0.00" width="4.00" height="100.00" />
<rect x="126.00" y="0.00" width="2.00" height="100.00" />
<rect x="132.00" y="0.00" width="4.00" height="100.00" />
<rect x="138.00" y="0.00" width="6.00" height="100.00" />
<rect x="146.00" y="0.00" width="2.00" height="100.00" />
<rect x="154.00" y="0.00" width="4.00" height="100.00" />
<rect x="164.00" y="0.00" width="6.00" height="100.00" />
<rect x="172.00" y="0.00" width="2.00" height="100.00" />
<rect x="176.00" y="0.00" width="4.00" height="100.00" />
<text x="90.00" y="118.00" text-anchor="middle"
font-family="Helvetica" font-size="18.0" fill="#000000" >
&lt;&gt;&quot;&amp;&apos;
</text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2019 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -29,6 +29,8 @@
*/
/* vim: set ts=4 sw=4 et : */
//#define TEST_ENCODE_GENERATE_EXPECTED 1
#include "testcommon.h"
static void test_options(void)
@ -69,6 +71,105 @@ static void test_options(void)
testFinish();
}
static void test_encode(void)
{
testStart("");
int ret;
struct item {
int input_mode;
int option_1;
int option_2;
unsigned char* data;
int ret;
int expected_rows;
int expected_width;
char* comment;
char* expected;
};
struct item data[] = {
/* 0*/ { UNICODE_MODE, -1, -1, "AIM", 0, 1, 68, "Same as CODE128",
"11010010000101000110001100010001010111011000101110110001100011101011"
},
/* 1*/ { UNICODE_MODE, -1, -1, "AAAAAAAAA", 0, 4, 90, "",
"110100001001011110111010010000110101000110001010001100010100011000110010001001100011101011"
"110100001001011110111011000100100101000110001010001100010100011000100100110001100011101011"
"110100001001011110111010110011100101000110001010001100010100011000100010011001100011101011"
"110100001001011101111010111011000101111011101001011000010010011110111001001101100011101011"
},
/* 2*/ { UNICODE_MODE, 3, -1, "AAAAAAAAA", 0, 3, 101, "Verified manually against tec-it (bwipp differs)",
"11010000100101111011101001011000010100011000101000110001010001100010100011000110110011001100011101011"
"11010000100101111011101100010010010100011000101000110001010001100010100011000111101000101100011101011"
"11010000100101111011101011001110010100011000101110111101100110110011001110010110001001001100011101011"
},
/* 3*/ { UNICODE_MODE, -1, -1, "AAAAAAAAAAAAAAA", 0, 6, 90, "",
"110100001001011110111010000100110101000110001010001100010100011000100110011101100011101011"
"110100001001011110111011000100100101000110001010001100010100011000100100110001100011101011"
"110100001001011110111010110011100101000110001010001100010100011000100010011001100011101011"
"110100001001011110111010011011100101000110001010001100010100011000100110001001100011101011"
"110100001001011110111010011001110101000110001010001100010100011000110010010001100011101011"
"110100001001011101111010001110110101111011101000110001010111101000110111101101100011101011"
},
/* 4*/ { UNICODE_MODE, -1, 14, "AAAAAAAAAAAAAAA", 0, 2, 156, "",
"110100001001011110111010100001100101000110001010001100010100011000101000110001010001100010100011000101000110001010001100010100011000110001000101100011101011"
"110100001001011110111011000100100101000110001010001100010100011000101000110001010001100010100011000101110111101110111101011011000110111000101101100011101011"
},
/* 5*/ { UNICODE_MODE, 3, -1, "AAAAAAAAAAAAAAA", 0, 3, 123, "Differs from tec-it (and bwipp); TODO: verify",
"110100001001011110111010010110000101000110001010001100010100011000101000110001010001100010100011000101111001001100011101011"
"110100001001011110111011000100100101000110001010001100010100011000101000110001010001100010100011000110000101001100011101011"
"110100001001011110111010110011100101000110001010001100010100011000101110111101110111101011011000110110110001101100011101011"
},
};
int data_size = sizeof(data) / sizeof(struct item);
char escaped[1024];
for (int i = 0; i < data_size; i++) {
struct zint_symbol* symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = BARCODE_CODABLOCKF;
symbol->input_mode = data[i].input_mode;
if (data[i].option_1 != -1) {
symbol->option_1 = data[i].option_1;
}
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
//symbol->debug = ZINT_DEBUG_PRINT;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_ENCODE_GENERATE_EXPECTED
printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
#else
if (ret < 5) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
if (ret == 0) {
int width, row;
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
}
}
#endif
ZBarcode_Delete(symbol);
}
testFinish();
}
// #181 Christian Hartlage OSS-Fuzz
static void test_fuzz(void)
{
@ -109,6 +210,7 @@ static void test_fuzz(void)
int main()
{
test_options();
test_encode();
test_fuzz();
testReport();

118
backend/tests/test_png.c Normal file
View File

@ -0,0 +1,118 @@
/*
libzint - the open source barcode library
Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include "testcommon.h"
#include <sys/stat.h>
//#define TEST_PRINT_GENERATE_EXPECTED 1
static void test_print(void)
{
testStart("");
int ret;
struct item {
int symbology;
int option_1;
int option_2;
unsigned char* data;
char* expected_file;
};
struct item data[] = {
/* 0*/ { BARCODE_CODE128, -1, -1, "AIM", "../data/png/code128_aim.png" },
/* 1*/ { BARCODE_CODABLOCKF, 3, -1, "AAAAAAAAA", "../data/png/codablockf_3rows.png" },
};
int data_size = sizeof(data) / sizeof(struct item);
char* data_dir = "../data/png";
char* png = "out.png";
char escaped[1024];
int escaped_size = 1024;
#ifdef TEST_PRINT_GENERATE_EXPECTED
if (!testUtilExists(data_dir)) {
ret = mkdir(data_dir, 0755);
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
}
#endif
for (int i = 0; i < data_size; i++) {
struct zint_symbol* symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
if (data[i].option_1 != -1) {
symbol->option_1 = data[i].option_1;
}
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_zero(ret, "i:%d %s ZBarcode_Encode ret %d != 0 %s\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt);
strcpy(symbol->outfile, png);
ret = ZBarcode_Print(symbol, 0);
assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret);
#ifdef TEST_PRINT_GENERATE_EXPECTED
printf(" /*%2d*/ { %s, \"%s\", \"%s\"},\n", i, testUtilBarcodeName(data[i].symbology), testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].expected_file);
ret = rename(symbol->outfile, data[i].expected_file);
assert_zero(ret, "i:%d rename(%s, %s) ret %d != 0\n", i, symbol->outfile, data[i].expected_file, ret);
#else
assert_nonzero(testUtilExists(symbol->outfile), "i:%d testUtilExists(%s) == 0\n", i, symbol->outfile);
ret = testUtilCmpPngs(symbol->outfile, data[i].expected_file);
assert_zero(ret, "i:%d %s testUtilCmpPngs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, data[i].expected_file, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
#endif
ZBarcode_Delete(symbol);
}
testFinish();
}
int main()
{
test_print();
testReport();
return 0;
}

118
backend/tests/test_svg.c Normal file
View File

@ -0,0 +1,118 @@
/*
libzint - the open source barcode library
Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include "testcommon.h"
#include <sys/stat.h>
//#define TEST_PRINT_GENERATE_EXPECTED 1
static void test_print(void)
{
testStart("");
int ret;
struct item {
int symbology;
int option_1;
int option_2;
unsigned char* data;
char* expected_file;
};
struct item data[] = {
/* 0*/ { BARCODE_CODE128, -1, -1, "<>\"&'", "../data/svg/code128_amperands.svg" },
/* 1*/ { BARCODE_CODABLOCKF, 3, -1, "AAAAAAAAA", "../data/svg/codablockf_3rows.svg" },
};
int data_size = sizeof(data) / sizeof(struct item);
char* data_dir = "../data/svg";
char* svg = "out.svg";
char escaped[1024];
int escaped_size = 1024;
#ifdef TEST_PRINT_GENERATE_EXPECTED
if (!testUtilExists(data_dir)) {
ret = mkdir(data_dir, 0755);
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
}
#endif
for (int i = 0; i < data_size; i++) {
struct zint_symbol* symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
if (data[i].option_1 != -1) {
symbol->option_1 = data[i].option_1;
}
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_zero(ret, "i:%d %s ZBarcode_Encode ret %d != 0 %s\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt);
strcpy(symbol->outfile, svg);
ret = ZBarcode_Print(symbol, 0);
assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret);
#ifdef TEST_PRINT_GENERATE_EXPECTED
printf(" /*%2d*/ { %s, \"%s\", \"%s\"},\n", i, testUtilBarcodeName(data[i].symbology), testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].expected_file);
ret = rename(symbol->outfile, data[i].expected_file);
assert_zero(ret, "i:%d rename(%s, %s) ret %d != 0\n", i, symbol->outfile, data[i].expected_file, ret);
#else
assert_nonzero(testUtilExists(symbol->outfile), "i:%d testUtilExists(%s) == 0\n", i, symbol->outfile);
ret = testUtilCmpSvgs(symbol->outfile, data[i].expected_file);
assert_zero(ret, "i:%d %s testUtilCmpSvgs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, data[i].expected_file, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
#endif
ZBarcode_Delete(symbol);
}
testFinish();
}
int main()
{
test_print();
testReport();
return 0;
}

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2019 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008 - 2020 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -142,6 +142,7 @@ static void test_buffer_vector(void)
/* 89*/ { BARCODE_CODEONE, "12345678901234567890", "", 22, 22, 22, 44.0, 44.0 },
/* 90*/ { BARCODE_GRIDMATRIX, "ABC", "", 18, 18, 18, 36.0, 36.0 },
/* 91*/ { BARCODE_UPNQR, "1234567890AB", "", 77, 77, 77, 154.0, 154.0 },
/* 92*/ { BARCODE_RMQR, "12345", "", 11, 11, 27, 54.0, 22.0 },
};
int data_size = sizeof(data) / sizeof(struct item);