ULTRA: enable compression for GS1_MODE; compression changes; fixes; tests

This commit is contained in:
gitlost 2020-04-09 22:08:54 +01:00
parent e86d9d1dc8
commit e04f662dc0
21 changed files with 762 additions and 46 deletions

View file

@ -81,5 +81,6 @@ 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(ultra, test_ultra)
zint_add_test(upcean, test_upcean)
zint_add_test(vector, test_vector)

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

View file

@ -1,5 +1,5 @@
%!PS-Adobe-3.0 EPSF-3.0
%%Creator: Zint 2.7.1
%%Creator: Zint 2.8.0
%%Title: Zint Generated Symbol
%%Pages: 0
%%BoundingBox: 0 0 136 118

View file

@ -1,5 +1,5 @@
%!PS-Adobe-3.0 EPSF-3.0
%%Creator: Zint 2.7.1
%%Creator: Zint 2.8.0
%%Title: Zint Generated Symbol
%%Pages: 0
%%BoundingBox: 0 0 26 20

View file

@ -1,5 +1,5 @@
%!PS-Adobe-3.0 EPSF-3.0
%%Creator: Zint 2.7.1
%%Creator: Zint 2.8.0
%%Title: Zint Generated Symbol
%%Pages: 0
%%BoundingBox: 0 0 42 42

View file

@ -0,0 +1,185 @@
%!PS-Adobe-3.0 EPSF-3.0
%%Creator: Zint 2.8.0
%%Title: Zint Generated Symbol
%%Pages: 0
%%BoundingBox: 0 0 26 26
%%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
26.00 0.00 TB 0.00 26.00 TR
TE
0.00 1.00 1.00 setrgbcolor
2.00 22.00 TB 22.00 2.00 TR
TE
2.00 20.00 TB 4.00 2.00 TR
TE
2.00 20.00 TB 14.00 2.00 TR
TE
2.00 18.00 TB 12.00 2.00 TR
TE
2.00 18.00 TB 18.00 2.00 TR
TE
2.00 16.00 TB 14.00 4.00 TR
TE
2.00 14.00 TB 10.00 2.00 TR
TE
2.00 10.00 TB 10.00 4.00 TR
TE
2.00 10.00 TB 18.00 6.00 TR
TE
2.00 8.00 TB 4.00 2.00 TR
TE
2.00 8.00 TB 14.00 2.00 TR
TE
2.00 6.00 TB 10.00 4.00 TR
TE
2.00 6.00 TB 20.00 2.00 TR
TE
2.00 4.00 TB 14.00 2.00 TR
TE
2.00 4.00 TB 22.00 2.00 TR
TE
2.00 2.00 TB 4.00 2.00 TR
TE
1.00 0.00 1.00 setrgbcolor
2.00 22.00 TB 12.00 6.00 TR
TE
2.00 20.00 TB 10.00 2.00 TR
TE
2.00 20.00 TB 18.00 2.00 TR
TE
2.00 16.00 TB 22.00 2.00 TR
TE
2.00 14.00 TB 4.00 2.00 TR
TE
2.00 14.00 TB 12.00 2.00 TR
TE
2.00 14.00 TB 16.00 2.00 TR
TE
2.00 10.00 TB 14.00 2.00 TR
TE
2.00 8.00 TB 10.00 4.00 TR
TE
2.00 8.00 TB 16.00 8.00 TR
TE
2.00 6.00 TB 14.00 2.00 TR
TE
2.00 4.00 TB 4.00 2.00 TR
TE
2.00 4.00 TB 18.00 2.00 TR
TE
2.00 2.00 TB 10.00 4.00 TR
TE
2.00 2.00 TB 16.00 2.00 TR
TE
2.00 2.00 TB 20.00 2.00 TR
TE
1.00 1.00 0.00 setrgbcolor
2.00 22.00 TB 4.00 2.00 TR
TE
2.00 22.00 TB 18.00 4.00 TR
TE
2.00 20.00 TB 12.00 2.00 TR
TE
2.00 18.00 TB 14.00 4.00 TR
TE
2.00 18.00 TB 20.00 4.00 TR
TE
2.00 16.00 TB 4.00 2.00 TR
TE
2.00 16.00 TB 10.00 2.00 TR
TE
2.00 16.00 TB 18.00 2.00 TR
TE
2.00 14.00 TB 20.00 4.00 TR
TE
2.00 6.00 TB 4.00 2.00 TR
TE
2.00 6.00 TB 16.00 4.00 TR
TE
2.00 6.00 TB 22.00 2.00 TR
TE
2.00 4.00 TB 12.00 2.00 TR
TE
2.00 2.00 TB 14.00 2.00 TR
TE
2.00 2.00 TB 22.00 2.00 TR
TE
0.00 1.00 0.00 setrgbcolor
2.00 22.00 TB 10.00 2.00 TR
TE
2.00 20.00 TB 16.00 2.00 TR
TE
2.00 20.00 TB 20.00 4.00 TR
TE
2.00 18.00 TB 4.00 2.00 TR
TE
2.00 18.00 TB 10.00 2.00 TR
TE
2.00 16.00 TB 12.00 2.00 TR
TE
2.00 16.00 TB 20.00 2.00 TR
TE
2.00 14.00 TB 14.00 2.00 TR
TE
2.00 14.00 TB 18.00 2.00 TR
TE
2.00 10.00 TB 4.00 2.00 TR
TE
2.00 10.00 TB 16.00 2.00 TR
TE
2.00 4.00 TB 10.00 2.00 TR
TE
2.00 4.00 TB 16.00 2.00 TR
TE
2.00 4.00 TB 20.00 2.00 TR
TE
2.00 2.00 TB 18.00 2.00 TR
TE
0.00 0.00 0.00 setrgbcolor
2.00 24.00 TB 0.00 26.00 TR
TE
2.00 22.00 TB 0.00 2.00 TR
TE
22.00 2.00 TB 6.00 2.00 TR
TE
10.00 14.00 TB 24.00 2.00 TR
TE
2.00 20.00 TB 0.00 4.00 TR
TE
2.00 18.00 TB 0.00 2.00 TR
TE
2.00 16.00 TB 0.00 4.00 TR
TE
2.00 14.00 TB 0.00 2.00 TR
TE
2.00 12.00 TB 0.00 4.00 TR
TE
2.00 12.00 TB 10.00 2.00 TR
TE
2.00 12.00 TB 14.00 2.00 TR
TE
2.00 12.00 TB 18.00 2.00 TR
TE
2.00 12.00 TB 22.00 4.00 TR
TE
2.00 10.00 TB 0.00 2.00 TR
TE
10.00 2.00 TB 24.00 2.00 TR
TE
2.00 8.00 TB 0.00 4.00 TR
TE
2.00 6.00 TB 0.00 2.00 TR
TE
2.00 4.00 TB 0.00 4.00 TR
TE
2.00 2.00 TB 0.00 2.00 TR
TE
2.00 0.00 TB 0.00 26.00 TR
TE

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

View file

@ -0,0 +1,94 @@
<?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="26" height="26" 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="26" height="26" fill="#FFFFFF" />
<rect x="0.00" y="0.00" width="26.00" height="2.00" fill="#000000" />
<rect x="0.00" y="2.00" width="2.00" height="2.00" fill="#000000" />
<rect x="4.00" y="2.00" width="2.00" height="2.00" fill="#ffff00" />
<rect x="6.00" y="2.00" width="2.00" height="22.00" fill="#000000" />
<rect x="10.00" y="2.00" width="2.00" height="2.00" fill="#00ff00" />
<rect x="12.00" y="2.00" width="6.00" height="2.00" fill="#ff00ff" />
<rect x="18.00" y="2.00" width="4.00" height="2.00" fill="#ffff00" />
<rect x="22.00" y="2.00" width="2.00" height="2.00" fill="#00ffff" />
<rect x="24.00" y="2.00" width="2.00" height="10.00" fill="#000000" />
<rect x="0.00" y="4.00" width="4.00" height="2.00" fill="#000000" />
<rect x="4.00" y="4.00" width="2.00" height="2.00" fill="#00ffff" />
<rect x="10.00" y="4.00" width="2.00" height="2.00" fill="#ff00ff" />
<rect x="12.00" y="4.00" width="2.00" height="2.00" fill="#ffff00" />
<rect x="14.00" y="4.00" width="2.00" height="2.00" fill="#00ffff" />
<rect x="16.00" y="4.00" width="2.00" height="2.00" fill="#00ff00" />
<rect x="18.00" y="4.00" width="2.00" height="2.00" fill="#ff00ff" />
<rect x="20.00" y="4.00" width="4.00" height="2.00" fill="#00ff00" />
<rect x="0.00" y="6.00" width="2.00" height="2.00" fill="#000000" />
<rect x="4.00" y="6.00" width="2.00" height="2.00" fill="#00ff00" />
<rect x="10.00" y="6.00" width="2.00" height="2.00" fill="#00ff00" />
<rect x="12.00" y="6.00" width="2.00" height="2.00" fill="#00ffff" />
<rect x="14.00" y="6.00" width="4.00" height="2.00" fill="#ffff00" />
<rect x="18.00" y="6.00" width="2.00" height="2.00" fill="#00ffff" />
<rect x="20.00" y="6.00" width="4.00" height="2.00" fill="#ffff00" />
<rect x="0.00" y="8.00" width="4.00" height="2.00" fill="#000000" />
<rect x="4.00" y="8.00" width="2.00" height="2.00" fill="#ffff00" />
<rect x="10.00" y="8.00" width="2.00" height="2.00" fill="#ffff00" />
<rect x="12.00" y="8.00" width="2.00" height="2.00" fill="#00ff00" />
<rect x="14.00" y="8.00" width="4.00" height="2.00" fill="#00ffff" />
<rect x="18.00" y="8.00" width="2.00" height="2.00" fill="#ffff00" />
<rect x="20.00" y="8.00" width="2.00" height="2.00" fill="#00ff00" />
<rect x="22.00" y="8.00" width="2.00" height="2.00" fill="#ff00ff" />
<rect x="0.00" y="10.00" width="2.00" height="2.00" fill="#000000" />
<rect x="4.00" y="10.00" width="2.00" height="2.00" fill="#ff00ff" />
<rect x="10.00" y="10.00" width="2.00" height="2.00" fill="#00ffff" />
<rect x="12.00" y="10.00" width="2.00" height="2.00" fill="#ff00ff" />
<rect x="14.00" y="10.00" width="2.00" height="2.00" fill="#00ff00" />
<rect x="16.00" y="10.00" width="2.00" height="2.00" fill="#ff00ff" />
<rect x="18.00" y="10.00" width="2.00" height="2.00" fill="#00ff00" />
<rect x="20.00" y="10.00" width="4.00" height="2.00" fill="#ffff00" />
<rect x="0.00" y="12.00" width="4.00" height="2.00" fill="#000000" />
<rect x="10.00" y="12.00" width="2.00" height="2.00" fill="#000000" />
<rect x="14.00" y="12.00" width="2.00" height="2.00" fill="#000000" />
<rect x="18.00" y="12.00" width="2.00" height="2.00" fill="#000000" />
<rect x="22.00" y="12.00" width="4.00" height="2.00" fill="#000000" />
<rect x="0.00" y="14.00" width="2.00" height="2.00" fill="#000000" />
<rect x="4.00" y="14.00" width="2.00" height="2.00" fill="#00ff00" />
<rect x="10.00" y="14.00" width="4.00" height="2.00" fill="#00ffff" />
<rect x="14.00" y="14.00" width="2.00" height="2.00" fill="#ff00ff" />
<rect x="16.00" y="14.00" width="2.00" height="2.00" fill="#00ff00" />
<rect x="18.00" y="14.00" width="6.00" height="2.00" fill="#00ffff" />
<rect x="24.00" y="14.00" width="2.00" height="10.00" fill="#000000" />
<rect x="0.00" y="16.00" width="4.00" height="2.00" fill="#000000" />
<rect x="4.00" y="16.00" width="2.00" height="2.00" fill="#00ffff" />
<rect x="10.00" y="16.00" width="4.00" height="2.00" fill="#ff00ff" />
<rect x="14.00" y="16.00" width="2.00" height="2.00" fill="#00ffff" />
<rect x="16.00" y="16.00" width="8.00" height="2.00" fill="#ff00ff" />
<rect x="0.00" y="18.00" width="2.00" height="2.00" fill="#000000" />
<rect x="4.00" y="18.00" width="2.00" height="2.00" fill="#ffff00" />
<rect x="10.00" y="18.00" width="4.00" height="2.00" fill="#00ffff" />
<rect x="14.00" y="18.00" width="2.00" height="2.00" fill="#ff00ff" />
<rect x="16.00" y="18.00" width="4.00" height="2.00" fill="#ffff00" />
<rect x="20.00" y="18.00" width="2.00" height="2.00" fill="#00ffff" />
<rect x="22.00" y="18.00" width="2.00" height="2.00" fill="#ffff00" />
<rect x="0.00" y="20.00" width="4.00" height="2.00" fill="#000000" />
<rect x="4.00" y="20.00" width="2.00" height="2.00" fill="#ff00ff" />
<rect x="10.00" y="20.00" width="2.00" height="2.00" fill="#00ff00" />
<rect x="12.00" y="20.00" width="2.00" height="2.00" fill="#ffff00" />
<rect x="14.00" y="20.00" width="2.00" height="2.00" fill="#00ffff" />
<rect x="16.00" y="20.00" width="2.00" height="2.00" fill="#00ff00" />
<rect x="18.00" y="20.00" width="2.00" height="2.00" fill="#ff00ff" />
<rect x="20.00" y="20.00" width="2.00" height="2.00" fill="#00ff00" />
<rect x="22.00" y="20.00" width="2.00" height="2.00" fill="#00ffff" />
<rect x="0.00" y="22.00" width="2.00" height="2.00" fill="#000000" />
<rect x="4.00" y="22.00" width="2.00" height="2.00" fill="#00ffff" />
<rect x="10.00" y="22.00" width="4.00" height="2.00" fill="#ff00ff" />
<rect x="14.00" y="22.00" width="2.00" height="2.00" fill="#ffff00" />
<rect x="16.00" y="22.00" width="2.00" height="2.00" fill="#ff00ff" />
<rect x="18.00" y="22.00" width="2.00" height="2.00" fill="#00ff00" />
<rect x="20.00" y="22.00" width="2.00" height="2.00" fill="#ff00ff" />
<rect x="22.00" y="22.00" width="2.00" height="2.00" fill="#ffff00" />
<rect x="0.00" y="24.00" width="26.00" height="2.00" fill="#000000" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

View file

@ -0,0 +1,13 @@
FF F8
B7 F8
F7 F8
B7 F8
F7 F8
B7 F8
D5 58
B7 F8
F7 F8
B7 F8
F7 F8
B7 F8
FF F8

View file

@ -76,9 +76,39 @@ static void test_utf8_to_unicode(void)
testFinish();
}
static void test_debug_test_codeword_dump_int(void)
{
testStart("");
int ret;
struct item {
int codewords[50];
int length;
char* expected;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 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);
struct zint_symbol symbol;
for (int i = 0; i < data_size; i++) {
debug_test_codeword_dump_int(&symbol, data[i].codewords, data[i].length);
assert_nonzero(strlen(symbol.errtxt) < 92, "i:%d strlen(%s) >= 92 (%zu)\n", i, symbol.errtxt, strlen(symbol.errtxt));
assert_zero(strcmp(symbol.errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0 (%zu, %zu)\n", i, symbol.errtxt, data[i].expected, strlen(symbol.errtxt), strlen(data[i].expected));
}
testFinish();
}
int main()
{
test_utf8_to_unicode();
test_debug_test_codeword_dump_int();
testReport();

View file

@ -34,7 +34,6 @@
//#define TEST_PRINT_GENERATE_EXPECTED 1
//#define TEST_PRINT_OVERWRITE_EXPECTED "bmp,emf,eps,gif,pcx,png,svg,tif,txt"
//#define TEST_PRINT_OVERWRITE_EXPECTED "gif"
static void test_print(void)
{
@ -52,6 +51,7 @@ static void test_print(void)
/* 0*/ { BARCODE_CODE128, -1, -1, "AIM", "code128_aim" },
/* 1*/ { BARCODE_QRCODE, 2, 1, "1234567890", "qr_v1_m" },
/* 2*/ { BARCODE_DOTCODE, -1, -1, "2741", "dotcode_aim_fig7" },
/* 3*/ { BARCODE_ULTRA, -1, -1, "A", "ultracode_a" },
};
int data_size = sizeof(data) / sizeof(struct item);

329
backend/tests/test_ultra.c Normal file
View file

@ -0,0 +1,329 @@
/*
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 : */
//#define TEST_INPUT_GENERATE_EXPECTED 1
//#define TEST_ENCODE_GENERATE_EXPECTED 1
#include "testcommon.h"
static void test_input(void)
{
testStart("");
int ret;
struct item {
int input_mode;
int eci;
int option_1;
int option_3;
unsigned char* data;
int ret;
char* expected;
char* comment;
};
struct item data[] = {
/* 0*/ { UNICODE_MODE, 0, -1, -1, "A", 0, "(2) 257 65", "" },
/* 1*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "A", 0, "(2) 272 65", "" },
/* 2*/ { UNICODE_MODE, 0, -1, -1, "ABC", 0, "(4) 257 65 66 67", "" },
/* 3*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "ABC", 0, "(4) 272 65 66 67", "" },
/* 4*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "ULTRACODE_123456789!", 0, "(17) 272 85 76 84 82 65 67 79 68 69 95 140 162 184 206 57 33", "" },
/* 5*/ { UNICODE_MODE, 0, -1, -1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 0, "(250) 257 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65", "249 chars EC2" },
/* 6*/ { UNICODE_MODE, 0, -1, -1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", ZINT_ERROR_TOO_LONG, "Error 591: Data too long for selected error correction capacity", "250 chars EC2" },
/* 7*/ { UNICODE_MODE, 0, 1, -1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 0, "(274) 257 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65", "273 chars EC0" },
/* 8*/ { UNICODE_MODE, 0, 1, -1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", ZINT_ERROR_TOO_LONG, "Error 591: Data too long for selected error correction capacity", "274 chars EC0" },
/* 9*/ { UNICODE_MODE, 0, -1, -1, "é", 0, "(2) 257 233", "" },
/* 10*/ { UNICODE_MODE, 0, -1, -1, "β", ZINT_WARN_USES_ECI, "Warning (2) 263 226", "" },
/* 11*/ { UNICODE_MODE, 9, -1, -1, "β", 0, "(2) 263 226", "" },
/* 12*/ { UNICODE_MODE, 9, -1, -1, "βAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 0, "(250) 263 226 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65", "249 chars EC2" },
/* 13*/ { UNICODE_MODE, 9, -1, ULTRA_COMPRESSION, "A", 0, "(2) 272 65", "Note ECI ignored and not outputted if ULTRA_COMPRESSION and all ASCII" },
/* 14*/ { UNICODE_MODE, 15, -1, -1, "Ŗ", 0, "(2) 268 170", "" },
/* 15*/ { GS1_MODE, 0, -1, -1, "[01]03453120000011[17]20121125[10]ABCD1234", ZINT_ERROR_INVALID_DATA, "Error 259: Invalid data length for AI (17)", "AIMD/TSC15032-43 G.6 Invalid [17] 4-digit year used in example" },
/* 16*/ { GS1_MODE, 0, -1, -1, "[01]03453120000011[17]121125[10]ABCD1234", 0, "(20) 273 129 131 173 159 148 128 128 139 145 140 139 153 138 65 66 67 68 140 162", "" },
/* 17*/ { GS1_MODE, 0, -1, -1, "[01]03453120000011[17]121125[10]ABCD1234", 0, "(20) 273 129 131 173 159 148 128 128 139 145 140 139 153 138 65 66 67 68 140 162", "" },
/* 18*/ { GS1_MODE, 0, -1, -1, "[17]120508[10]ABCD1234[410]9501101020917", 0, "(21) 273 145 140 133 136 138 65 66 67 68 140 162 272 169 137 178 139 129 130 137 145", "" },
/* 19*/ { GS1_MODE, 0, -1, -1, "[17]120508[10]ABCDEFGHI[410]9501101020917", 0, "(21) 273 145 140 133 136 138 65 66 67 68 140 162 272 169 137 178 139 129 130 137 145", "" },
/* 20*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "ftp://", 0, "(4) 272 280 269 165", "" },
/* 21*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, ".cgi", 0, "(4) 272 280 274 131", "" },
/* 22*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "ftp://a.cgi", 0, "(6) 272 280 269 165 6 107", "" },
};
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_ULTRA;
symbol->input_mode = data[i].input_mode;
symbol->eci = data[i].eci;
if (data[i].option_1 != -1) {
symbol->option_1 = data[i].option_1;
}
if (data[i].option_3 != -1) {
symbol->option_3 = data[i].option_3;
}
//symbol->debug = ZINT_DEBUG_PRINT | ZINT_DEBUG_TEST;
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
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\n", i, ret, data[i].ret);
#ifdef TEST_INPUT_GENERATE_EXPECTED
printf(" /*%3d*/ { %s, %d, %d, %s, \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, testUtilOption3Name(data[i].option_3), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
#else
if (ret < 5) {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
}
#endif
ZBarcode_Delete(symbol);
}
testFinish();
}
static void test_encode(void)
{
testStart("");
int ret;
struct item {
int input_mode;
int eci;
int option_1;
int option_3;
unsigned char* data;
int ret;
int expected_rows;
int expected_width;
char* comment;
char* expected;
};
struct item data[] = {
/* 0*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "ULTRACODE_123456789!", 0, 13, 22, "AIMD/TSC15032-43 Figure G.1 **NOT SAME** different compression",
"7777777777777777777777"
"7057065353533131551057"
"7767053515611616136717"
"7017036661565555363057"
"7767055333616336135717"
"7037036515535515366057"
"7707070707070707070707"
"7067016561133113551017"
"7737035155311665165737"
"7057066561155551653057"
"7767033315616663515717"
"7017051653331136333057"
"7777777777777777777777"
},
/* 1*/ { UNICODE_MODE, 0, -1, -1, "ULTRACODE_123456789!", 0, 13, 24, "AIMD/TSC15032-43 Figure G.1 **NOT SAME** no compression; verified against bwipp",
"777777777777777777777777"
"705706533153313111101157"
"776703361661161666676617"
"703706115156555511303357"
"775705556561633656175517"
"703701311653551535501657"
"770707070707070707070707"
"706701656113311311101117"
"775703333531166566676537"
"701706651315555113303357"
"773705515161666351175517"
"701706166533113663603357"
"777777777777777777777777"
},
/* 2*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "HEIMASÍÐA KENNARAHÁSKÓLA ÍSLANDS", 0, 19, 23, "AIMD/TSC15032-43 Figure G.2 **NOT SAME** different compression",
"77777777777777777777777"
"70070663151561555150557"
"77070315565635366667617"
"70070666656561115530357"
"77570535365656556367117"
"70370153656135163550357"
"77170707070707070707077"
"70570156315513136160357"
"77370533531631615537117"
"70070361155313351360657"
"77670515613665166537117"
"70170651131551335150357"
"77570707070707070707077"
"70670535163551333630617"
"77170111531613611567137"
"70070566665531335610357"
"77070151331365561537137"
"70070333656153153360617"
"77777777777777777777777"
},
/* 3*/ { DATA_MODE, 0, -1, -1, "\110\105\111\115\101\123\315\320\101\040\113\105\116\116\101\122\101\110\301\123\113\323\114\101\040\315\123\114\101\116\104\123", 0, 19, 23, "AIMD/TSC15032-43 Figure G.2 **NOT SAME** no compression; verified against bwipp",
"77777777777777777777777"
"70070633151153313350137"
"77070315666661161167617"
"70070663155553555530557"
"77570531366336136167367"
"70370155555515653350537"
"77170707070707070707077"
"70570135513311133130357"
"77370513331166611617117"
"70070351153555533550557"
"77670613615636356367117"
"70170156336355515530657"
"77570707070707070707077"
"70670615133513355130117"
"77170136511651166517637"
"70070365635335515350557"
"77070613551651656517637"
"70070361115516163130317"
"77777777777777777777777"
},
/* 4*/ { UNICODE_MODE, 10, -1, ULTRA_COMPRESSION, "אולטרה-קוד1234", 0, 13, 19, "AIMD/TSC15032-43 Figure G.3 Same except DCC correct whereas DCC in Figure G.3 is incorrent",
"7777777777777777777"
"7057065565566616657"
"7737053333613351517"
"7067015155551565167"
"7757053333633356657"
"7037066561515535537"
"7707070707070707077"
"7067013561166666517"
"7737031653311131137"
"7017065336156555357"
"7767016565663636117"
"7017051316355311357"
"7777777777777777777"
},
/* 5*/ { DATA_MODE, 0, -1, -1, "\340\345\354\350\370\344\055\367\345\343\061\062\063\064", 0, 13, 20, "AIMD/TSC15032-43 Figure G.3 **NOT SAME** no compression; verified against bwipp",
"77777777777777777777"
"70570611115666161157"
"77670333656133516617"
"70170655165515651157"
"77570516516333565617"
"70370163335155353557"
"77070707070707070707"
"70670153311666661117"
"77370315553111316637"
"70570631611565551357"
"77370166136636365117"
"70170613653553116357"
"77777777777777777777"
},
/* 6*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "https://aimglobal.org/jcrv3tX", 0, 13, 22, "AIMD/TSC15032-43 Figure G.4a **NOT SAME** different compression",
"7777777777777777777777"
"7057065133563156313037"
"7767051556651331566757"
"7017066611513613331017"
"7767053165666351655767"
"7037035651531533133057"
"7707070707070707070707"
"7067015511111161565017"
"7737036635335356151737"
"7057063111116533366057"
"7767031536633116511717"
"7017063363361363356057"
"7777777777777777777777"
},
/* 7*/ { UNICODE_MODE, 0, -1, -1, "A", 0, 13, 13, "Verified against bwipp",
"7777777777777"
"7057063335517"
"7717035163667"
"7067061551557"
"7757056115637"
"7037013636557"
"7707070707077"
"7067011361117"
"7717033133337"
"7057011355157"
"7737065163617"
"7017033536357"
"7777777777777"
},
};
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_ULTRA;
symbol->input_mode = data[i].input_mode;
symbol->eci = data[i].eci;
if (data[i].option_1 != -1) {
symbol->option_1 = data[i].option_1;
}
if (data[i].option_3 != -1) {
symbol->option_3 = data[i].option_3;
}
//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\", %s, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, testUtilOption3Name(data[i].option_3),
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();
}
int main()
{
test_input();
test_encode();
testReport();
return 0;
}

View file

@ -328,6 +328,16 @@ char* testUtilInputModeName(int input_mode) {
return data[input_mode].name;
}
char* testUtilOption3Name(int option_3) {
switch (option_3) {
case DM_SQUARE: return "DM_SQUARE";
case DM_DMRE: return "DM_DMRE";
case ZINT_FULL_MULTIBYTE: return "ZINT_FULL_MULTIBYTE";
case ULTRA_COMPRESSION: return "ULTRA_COMPRESSION";
}
return "-1";
}
int testUtilDAFTConvert(const struct zint_symbol* symbol, char* buffer, int buffer_size)
{
buffer[0] = '\0';
@ -680,7 +690,7 @@ void testUtilModulesDump(const struct zint_symbol* symbol, char* prefix, char* p
}
putchar('"');
for (w = 0; w < symbol->width; w++) {
putchar(module_is_set(symbol, r, w) ? '1' : '0');
putchar(module_is_set(symbol, r, w) + '0');
}
putchar('"');
if (*postfix) {
@ -696,7 +706,7 @@ int testUtilModulesCmp(const struct zint_symbol* symbol, const char* expected, i
int r, w = 0;
for (r = 0; r < symbol->rows && e < ep; r++) {
for (w = 0; w < symbol->width && e < ep; w++) {
if (module_is_set(symbol, r, w) != (*e == '1')) {
if (module_is_set(symbol, r, w) + '0' != *e) {
*row = r;
*width = w;
return 1 /*fail*/;

View file

@ -67,6 +67,7 @@ extern void vector_free(struct zint_symbol *symbol); /* Free vector structures *
char* testUtilBarcodeName(int symbology);
char* testUtilErrorName(int error_number);
char* testUtilInputModeName(int input_mode);
char* testUtilOption3Name(int option_3);
int testUtilDAFTConvert(const struct zint_symbol* symbol, char* buffer, int buffer_size);
char* testUtilEscape(char* buffer, int length, char* escaped, int escaped_size);
char* testUtilReadCSVField(char* buffer, char* field, int field_size);