mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Always parse input as GS1 for EAN128 and RSS_EXP
This commit is contained in:
@ -49,7 +49,9 @@ endmacro(zint_add_test)
|
||||
zint_add_test(channel, test_channel)
|
||||
zint_add_test(composite, test_composite)
|
||||
zint_add_test(eci, test_eci)
|
||||
zint_add_test(gs1, test_gs1)
|
||||
zint_add_test(imail, test_imail)
|
||||
zint_add_test(library, test_library)
|
||||
zint_add_test(mailmark, test_mailmark)
|
||||
zint_add_test(maxicode, test_maxicode)
|
||||
zint_add_test(postal, test_postal)
|
||||
|
277
backend/tests/test_gs1.c
Normal file
277
backend/tests/test_gs1.c
Normal file
@ -0,0 +1,277 @@
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2008-2019 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"
|
||||
|
||||
//#define TEST_GS1_REDUCE_GENERATE_EXPECTED
|
||||
|
||||
/*
|
||||
* Check that EAN128 and RSS_EXP based symbologies reduce GS1 data
|
||||
*/
|
||||
static void test_gs1_reduce(void)
|
||||
{
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int symbology;
|
||||
int input_mode;
|
||||
unsigned char* data;
|
||||
unsigned char* primary;
|
||||
int ret;
|
||||
|
||||
char* comment;
|
||||
unsigned char* expected;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { BARCODE_EAN128, -1, "12345678901234", "", ZINT_ERROR_INVALID_DATA, "GS1 data required", "" },
|
||||
/* 1*/ { BARCODE_EAN128, -1, "[01]12345678901234", "", 0, "Input mode ignored",
|
||||
"11010011100111101011101100110110010110011100100010110001110001011011000010100110111101101011001110010001011000111010111101100011101011"
|
||||
},
|
||||
/* 2*/ { BARCODE_EAN128, GS1_MODE, "[01]12345678901234", "", 0, "Input mode ignored",
|
||||
"11010011100111101011101100110110010110011100100010110001110001011011000010100110111101101011001110010001011000111010111101100011101011"
|
||||
},
|
||||
/* 3*/ { BARCODE_EAN128, UNICODE_MODE, "[01]12345678901234", "", 0, "Input mode ignored",
|
||||
"11010011100111101011101100110110010110011100100010110001110001011011000010100110111101101011001110010001011000111010111101100011101011"
|
||||
},
|
||||
/* 4*/ { BARCODE_EAN128_CC, -1, "[01]12345678901234", "[21]1234", 0, "Input mode ignored",
|
||||
"1101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010000000000000000000000000000000000000000000000"
|
||||
"1101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010000000000000000000000000000000000000000000000"
|
||||
"1101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010000000000000000000000000000000000000000000000"
|
||||
"0010110001100001010001001100100110100110001101110100111000111010010011110101100100001001010011000110111010011100010100001011010000110011100010100"
|
||||
"1101001110011110101110110011011001011001110010001011000111000101101100001010011011110110101100111001000101100011101011110100101111001100011101011"
|
||||
},
|
||||
/* 5*/ { BARCODE_EAN128_CC, GS1_MODE, "[01]12345678901234", "[21]1234", 0, "Input mode ignored",
|
||||
"1101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010000000000000000000000000000000000000000000000"
|
||||
"1101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010000000000000000000000000000000000000000000000"
|
||||
"1101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010000000000000000000000000000000000000000000000"
|
||||
"0010110001100001010001001100100110100110001101110100111000111010010011110101100100001001010011000110111010011100010100001011010000110011100010100"
|
||||
"1101001110011110101110110011011001011001110010001011000111000101101100001010011011110110101100111001000101100011101011110100101111001100011101011"
|
||||
},
|
||||
/* 6*/ { BARCODE_EAN128_CC, UNICODE_MODE, "[01]12345678901234", "[21]1234", 0, "Input mode ignored",
|
||||
"1101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010000000000000000000000000000000000000000000000"
|
||||
"1101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010000000000000000000000000000000000000000000000"
|
||||
"1101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010000000000000000000000000000000000000000000000"
|
||||
"0010110001100001010001001100100110100110001101110100111000111010010011110101100100001001010011000110111010011100010100001011010000110011100010100"
|
||||
"1101001110011110101110110011011001011001110010001011000111000101101100001010011011110110101100111001000101100011101011110100101111001100011101011"
|
||||
},
|
||||
/* 7*/ { BARCODE_EAN14, -1, "1234567890123", "", 0, "Input mode ignored",
|
||||
"11010011100111101011101100110110010110011100100010110001110001011011000010100110111101101011001110011011000110100001100101100011101011"
|
||||
},
|
||||
/* 8*/ { BARCODE_EAN14, GS1_MODE, "1234567890123", "", 0, "Input mode ignored",
|
||||
"11010011100111101011101100110110010110011100100010110001110001011011000010100110111101101011001110011011000110100001100101100011101011"
|
||||
},
|
||||
/* 9*/ { BARCODE_EAN14, UNICODE_MODE, "1234567890123", "", 0, "Input mode ignored",
|
||||
"11010011100111101011101100110110010110011100100010110001110001011011000010100110111101101011001110011011000110100001100101100011101011"
|
||||
},
|
||||
/*10*/ { BARCODE_NVE18, -1, "12345678901234567", "", 0, "Input mode ignored",
|
||||
"110100111001111010111011011001100101100111001000101100011100010110110000101001101111011010110011100100010110001110001011011000010010101101110001100011101011"
|
||||
},
|
||||
/*11*/ { BARCODE_NVE18, GS1_MODE, "12345678901234567", "", 0, "Input mode ignored",
|
||||
"110100111001111010111011011001100101100111001000101100011100010110110000101001101111011010110011100100010110001110001011011000010010101101110001100011101011"
|
||||
},
|
||||
/*12*/ { BARCODE_NVE18, UNICODE_MODE, "12345678901234567", "", 0, "Input mode ignored",
|
||||
"110100111001111010111011011001100101100111001000101100011100010110110000101001101111011010110011100100010110001110001011011000010010101101110001100011101011"
|
||||
},
|
||||
/*13*/ { BARCODE_RSS_EXP, -1, "2012", "", ZINT_ERROR_INVALID_DATA, "GS1 data required", "" },
|
||||
/*14*/ { BARCODE_RSS_EXP, -1, "[20]12", "", 0, "Input mode ignored",
|
||||
"0101010100000000011011111111000010101011000000010001011111001011100010111100000000101"
|
||||
},
|
||||
/*15*/ { BARCODE_RSS_EXP, GS1_MODE, "[20]12", "", 0, "Input mode ignored",
|
||||
"0101010100000000011011111111000010101011000000010001011111001011100010111100000000101"
|
||||
},
|
||||
/*16*/ { BARCODE_RSS_EXP, UNICODE_MODE, "[20]12", "", 0, "Input mode ignored",
|
||||
"0101010100000000011011111111000010101011000000010001011111001011100010111100000000101"
|
||||
},
|
||||
/*17*/ { BARCODE_RSS_EXP_CC, -1, "[20]12", "[21]1234", 0, "Input mode ignored",
|
||||
"00110110111011010000100000110100110011101100001001110100110000101000110001001001101100000011011000101"
|
||||
"00110110110011111010001001100110101110010000001001100100100111100101111001110101100100000011001000101"
|
||||
"00110110100010111110011000010100111101000000101001100110101110111001111001001111011000011011101000101"
|
||||
"00001010111111111001000000001010010001100100011101101000001101000111010000111111100000000000000000000"
|
||||
"01010101000000000110111111110000101110011011100010010111110010111000101111000000001010000000000000000"
|
||||
},
|
||||
/*18*/ { BARCODE_RSS_EXP_CC, GS1_MODE, "[20]12", "[21]1234", 0, "Input mode ignored",
|
||||
"00110110111011010000100000110100110011101100001001110100110000101000110001001001101100000011011000101"
|
||||
"00110110110011111010001001100110101110010000001001100100100111100101111001110101100100000011001000101"
|
||||
"00110110100010111110011000010100111101000000101001100110101110111001111001001111011000011011101000101"
|
||||
"00001010111111111001000000001010010001100100011101101000001101000111010000111111100000000000000000000"
|
||||
"01010101000000000110111111110000101110011011100010010111110010111000101111000000001010000000000000000"
|
||||
},
|
||||
/*19*/ { BARCODE_RSS_EXP_CC, UNICODE_MODE, "[20]12", "[21]1234", 0, "Input mode ignored",
|
||||
"00110110111011010000100000110100110011101100001001110100110000101000110001001001101100000011011000101"
|
||||
"00110110110011111010001001100110101110010000001001100100100111100101111001110101100100000011001000101"
|
||||
"00110110100010111110011000010100111101000000101001100110101110111001111001001111011000011011101000101"
|
||||
"00001010111111111001000000001010010001100100011101101000001101000111010000111111100000000000000000000"
|
||||
"01010101000000000110111111110000101110011011100010010111110010111000101111000000001010000000000000000"
|
||||
},
|
||||
/*20*/ { BARCODE_RSS_EXPSTACK, -1, "12", "", ZINT_ERROR_INVALID_DATA, "GS1 data required", "" },
|
||||
/*21*/ { BARCODE_RSS_EXPSTACK, -1, "[20]12", "", 0, "Input mode ignored",
|
||||
"010010000010000101101111111100001010000010000110010101111100101110001011110000000010101111100001011101"
|
||||
},
|
||||
/*22*/ { BARCODE_RSS_EXPSTACK, GS1_MODE, "[20]12", "", 0, "Input mode ignored",
|
||||
"010010000010000101101111111100001010000010000110010101111100101110001011110000000010101111100001011101"
|
||||
},
|
||||
/*23*/ { BARCODE_RSS_EXPSTACK, UNICODE_MODE, "[20]12", "", 0, "Input mode ignored",
|
||||
"010010000010000101101111111100001010000010000110010101111100101110001011110000000010101111100001011101"
|
||||
},
|
||||
/*24*/ { BARCODE_RSS_EXPSTACK_CC, -1, "12", "[21]1234", ZINT_ERROR_INVALID_DATA, "GS1 data required", "" },
|
||||
/*25*/ { BARCODE_RSS_EXPSTACK_CC, -1, "[20]12", "[21]1234", 0, "Input mode ignored",
|
||||
"001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010"
|
||||
"001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010"
|
||||
"001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010"
|
||||
"000001111111010110010000000010100100111001100001011010000011010001100100001010101001010000011110100000"
|
||||
"010010000000101001101111111100001011000110011110100101111100101110001011110000000010101111100001011101"
|
||||
},
|
||||
/*26*/ { BARCODE_RSS_EXPSTACK_CC, GS1_MODE, "[20]12", "[21]1234", 0, "Input mode ignored",
|
||||
"001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010"
|
||||
"001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010"
|
||||
"001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010"
|
||||
"000001111111010110010000000010100100111001100001011010000011010001100100001010101001010000011110100000"
|
||||
"010010000000101001101111111100001011000110011110100101111100101110001011110000000010101111100001011101"
|
||||
},
|
||||
/*27*/ { BARCODE_RSS_EXPSTACK_CC, UNICODE_MODE, "[20]12", "[21]1234", 0, "Input mode ignored",
|
||||
"001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010"
|
||||
"001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010"
|
||||
"001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010"
|
||||
"000001111111010110010000000010100100111001100001011010000011010001100100001010101001010000011110100000"
|
||||
"010010000000101001101111111100001011000110011110100101111100101110001011110000000010101111100001011101"
|
||||
},
|
||||
};
|
||||
int data_size = sizeof(data) / sizeof(struct item);
|
||||
|
||||
char* text;
|
||||
|
||||
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].input_mode != -1) {
|
||||
symbol->input_mode = data[i].input_mode;
|
||||
}
|
||||
|
||||
if (strlen(data[i].primary)) {
|
||||
text = data[i].primary;
|
||||
strcpy(symbol->primary, data[i].data);
|
||||
} else {
|
||||
text = data[i].data;
|
||||
}
|
||||
int length = strlen(text);
|
||||
|
||||
ret = ZBarcode_Encode(symbol, text, length);
|
||||
|
||||
#ifdef TEST_GS1_REDUCE_GENERATE_EXPECTED
|
||||
if (data[i].ret == 0) {
|
||||
printf(" /*%2d*/ { %s, %s, \"%s\", \"%s\", %d, \"%s\",\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].data, data[i].primary, data[i].ret, data[i].comment);
|
||||
testUtilModulesDump(symbol, " ", "\n");
|
||||
printf(" },\n");
|
||||
} else {
|
||||
printf(" /*%2d*/ { %s, %s, \"%s\", \"%s\", %s, \"%s\", \"\" },\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].data, data[i].primary, testUtilErrorName(data[i].ret), data[i].comment);
|
||||
}
|
||||
#else
|
||||
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
|
||||
|
||||
if (ret == 0) {
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
}
|
||||
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_hrt(void)
|
||||
{
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
unsigned char* primary;
|
||||
|
||||
unsigned char* expected;
|
||||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
|
||||
struct item data[] = {
|
||||
/* 0*/ { BARCODE_EAN128, "[01]12345678901234[20]12", "", "(01)12345678901234(20)12" },
|
||||
/* 1*/ { BARCODE_EAN128_CC, "[01]12345678901234[20]12", "[21]12345", "(01)12345678901234(20)12" },
|
||||
/* 2*/ { BARCODE_RSS_EXP, "[01]12345678901234[20]12", "", "(01)12345678901234(20)12" },
|
||||
/* 3*/ { BARCODE_RSS_EXP_CC, "[01]12345678901234", "[21]12345", "(01)12345678901234" },
|
||||
/* 4*/ { BARCODE_RSS_EXPSTACK, "[20]12", "", "(20)12" },
|
||||
/* 5*/ { BARCODE_RSS_EXPSTACK_CC, "[20]12", "[21]12345", "(20)12" },
|
||||
};
|
||||
int data_size = sizeof(data) / sizeof(struct item);
|
||||
|
||||
char* text;
|
||||
|
||||
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 (strlen(data[i].primary)) {
|
||||
text = data[i].primary;
|
||||
strcpy(symbol->primary, data[i].data);
|
||||
} else {
|
||||
text = data[i].data;
|
||||
}
|
||||
int length = strlen(text);
|
||||
|
||||
ret = ZBarcode_Encode(symbol, text, length);
|
||||
assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt);
|
||||
|
||||
assert_zero(strcmp(symbol->text, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->text, data[i].expected);
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
}
|
||||
|
||||
testFinish();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_gs1_reduce();
|
||||
test_hrt();
|
||||
|
||||
testReport();
|
||||
|
||||
return 0;
|
||||
}
|
105
backend/tests/test_library.c
Normal file
105
backend/tests/test_library.c
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2008-2019 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"
|
||||
|
||||
static void test_checks(void)
|
||||
{
|
||||
testStart("");
|
||||
|
||||
int ret;
|
||||
struct item {
|
||||
int symbology;
|
||||
unsigned char* data;
|
||||
int length;
|
||||
int input_mode;
|
||||
int eci;
|
||||
float dot_size;
|
||||
int ret;
|
||||
|
||||
char* expected;
|
||||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
|
||||
struct item data[] = {
|
||||
/* 0*/ { BARCODE_CODE128, "1234", -1, -1, 3, -1, ZINT_ERROR_INVALID_OPTION, "Error 217: Symbology does not support ECI switching" },
|
||||
/* 1*/ { BARCODE_CODE128, "1234", -1, -1, 0, -1, 0, "" },
|
||||
/* 2*/ { BARCODE_QRCODE, "1234", -1, -1, 3, -1, 0, "" },
|
||||
/* 3*/ { BARCODE_QRCODE, "1234", -1, -1, 999999 + 1, -1, ZINT_ERROR_INVALID_OPTION, "Error 218: Invalid ECI mode" },
|
||||
/* 4*/ { BARCODE_CODE128, "1234", -1, -1, -1, 20.1, ZINT_ERROR_INVALID_OPTION, "Error 221: Invalid dot size" },
|
||||
/* 5*/ { BARCODE_CODE128, "1234", -1, GS1_MODE, -1, -1, ZINT_ERROR_INVALID_OPTION, "Error 220: Selected symbology does not support GS1 mode" },
|
||||
/* 6*/ { BARCODE_EAN128, "[21]12\0004", 8, GS1_MODE, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 262: NUL characters not permitted in GS1 mode" },
|
||||
/* 7*/ { BARCODE_EAN128, "[21]12é4", -1, GS1_MODE, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 250: Extended ASCII characters are not supported by GS1" },
|
||||
/* 8*/ { BARCODE_EAN128, "[21]12\0074", -1, GS1_MODE, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 251: Control characters are not supported by GS1" },
|
||||
/* 9*/ { BARCODE_EAN128, "[21]1234", -1, GS1_MODE, -1, -1, 0, "" },
|
||||
};
|
||||
int data_size = sizeof(data) / sizeof(struct item);
|
||||
|
||||
char* text;
|
||||
char* primary;
|
||||
char escaped_primary[1024];
|
||||
|
||||
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].input_mode != -1) {
|
||||
symbol->input_mode = data[i].input_mode;
|
||||
}
|
||||
if (data[i].eci != -1) {
|
||||
symbol->eci = data[i].eci;
|
||||
}
|
||||
if (data[i].dot_size != -1) {
|
||||
symbol->dot_size = data[i].dot_size;
|
||||
}
|
||||
int length = data[i].length == -1 ? strlen(data[i].data) : data[i].length;
|
||||
|
||||
ret = ZBarcode_Encode(symbol, data[i].data, length);
|
||||
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode(%d) ret %d != %d (%s)\n", i, data[i].symbology, ret, data[i].ret, symbol->errtxt);
|
||||
|
||||
ret = strcmp(symbol->errtxt, data[i].expected);
|
||||
assert_zero(ret, "i:%d (%d) strcmp(%s, %s) %d != 0\n", i, data[i].symbology, symbol->errtxt, data[i].expected, ret);
|
||||
|
||||
ZBarcode_Delete(symbol);
|
||||
}
|
||||
|
||||
testFinish();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_checks();
|
||||
|
||||
testReport();
|
||||
|
||||
return 0;
|
||||
}
|
@ -27,6 +27,7 @@
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
*/
|
||||
/* vim: set ts=4 sw=4 et : */
|
||||
/*
|
||||
* Adapted from qrencode/tests/common.c
|
||||
* Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
|
||||
@ -252,11 +253,10 @@ char* testUtilBarcodeName(int symbology) {
|
||||
{ BARCODE_GRIDMATRIX, "BARCODE_GRIDMATRIX", 142 },
|
||||
{ BARCODE_UPNQR, "BARCODE_UPNQR", 143 },
|
||||
{ BARCODE_ULTRA, "BARCODE_ULTRA", 144 },
|
||||
{ -1, "", 145 },
|
||||
};
|
||||
int data_size = sizeof(data) / sizeof(struct item);
|
||||
|
||||
if (symbology < 0 || symbology > data_size) {
|
||||
if (symbology < 0 || symbology >= data_size) {
|
||||
return "";
|
||||
}
|
||||
if (data[symbology].val != symbology || (data[symbology].define != -1 && data[symbology].define != symbology)) { // Self-check
|
||||
@ -266,6 +266,69 @@ char* testUtilBarcodeName(int symbology) {
|
||||
return data[symbology].name;
|
||||
}
|
||||
|
||||
char* testUtilErrorName(int error_number) {
|
||||
struct item {
|
||||
int define;
|
||||
char* name;
|
||||
int val;
|
||||
};
|
||||
struct item data[] = {
|
||||
{ -1, "", 0 },
|
||||
{ -1, "", 1 },
|
||||
{ ZINT_WARN_INVALID_OPTION, "ZINT_WARN_INVALID_OPTION", 2 },
|
||||
{ ZINT_WARN_USES_ECI, "ZINT_WARN_USES_ECI", 3 },
|
||||
{ -1, "", 4 },
|
||||
{ ZINT_ERROR_TOO_LONG, "ZINT_ERROR_TOO_LONG", 5 },
|
||||
{ ZINT_ERROR_INVALID_DATA, "ZINT_ERROR_INVALID_DATA", 6 },
|
||||
{ ZINT_ERROR_INVALID_CHECK, "ZINT_ERROR_INVALID_CHECK", 7 },
|
||||
{ ZINT_ERROR_INVALID_OPTION, "ZINT_ERROR_INVALID_OPTION", 8 },
|
||||
{ ZINT_ERROR_ENCODING_PROBLEM, "ZINT_ERROR_ENCODING_PROBLEM", 9 },
|
||||
{ ZINT_ERROR_FILE_ACCESS, "ZINT_ERROR_FILE_ACCESS", 10 },
|
||||
{ ZINT_ERROR_MEMORY, "ZINT_ERROR_MEMORY", 11 },
|
||||
};
|
||||
int data_size = sizeof(data) / sizeof(struct item);
|
||||
|
||||
if (error_number < 0 || error_number >= data_size) {
|
||||
return "";
|
||||
}
|
||||
if (data[error_number].val != error_number || (data[error_number].define != -1 && data[error_number].define != error_number)) { // Self-check
|
||||
fprintf(stderr, "testUtilErrorName data table out of sync (%d)\n", error_number);
|
||||
abort();
|
||||
}
|
||||
return data[error_number].name;
|
||||
}
|
||||
|
||||
char* testUtilInputModeName(int input_mode) {
|
||||
struct item {
|
||||
int define;
|
||||
char* name;
|
||||
int val;
|
||||
};
|
||||
struct item data[] = {
|
||||
{ DATA_MODE, "DATA_MODE", 0 },
|
||||
{ UNICODE_MODE, "UNICODE_MODE", 1 },
|
||||
{ GS1_MODE, "GS1_MODE", 2 },
|
||||
{ -1, "", 3 },
|
||||
{ -1, "", 4 },
|
||||
{ -1, "", 5 },
|
||||
{ -1, "", 6 },
|
||||
{ -1, "", 7 },
|
||||
{ DATA_MODE | ESCAPE_MODE, "DATA_MODE | ESCAPE_MODE", 8 },
|
||||
{ UNICODE_MODE | ESCAPE_MODE, "UNICODE_MODE | ESCAPE_MODE", 9 },
|
||||
{ GS1_MODE | ESCAPE_MODE, "GS1_MODE | ESCAPE_MODE", 10 },
|
||||
};
|
||||
int data_size = sizeof(data) / sizeof(struct item);
|
||||
|
||||
if (input_mode < 0 || input_mode >= data_size) {
|
||||
return input_mode == -1 ? "-1" : "";
|
||||
}
|
||||
if (data[input_mode].val != input_mode || (data[input_mode].define != -1 && data[input_mode].define != input_mode)) { // Self-check
|
||||
fprintf(stderr, "testUtilInputModeName data table out of sync (%d)\n", input_mode);
|
||||
abort();
|
||||
}
|
||||
return data[input_mode].name;
|
||||
}
|
||||
|
||||
int testUtilDAFTConvert(const struct zint_symbol* symbol, char* buffer, int buffer_size)
|
||||
{
|
||||
buffer[0] = '\0';
|
||||
|
@ -27,6 +27,7 @@
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
*/
|
||||
/* vim: set ts=4 sw=4 et : */
|
||||
/*
|
||||
* Adapted from qrencode/tests/common.h
|
||||
* Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
|
||||
@ -66,6 +67,8 @@ void testReport();
|
||||
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);
|
||||
int testUtilDAFTConvert(const struct zint_symbol* symbol, char* buffer, int buffer_size);
|
||||
char* testUtilEscape(char* buffer, char* escaped, int escaped_size);
|
||||
char* testUtilReadCSVField(char* buffer, char* field, int field_size);
|
||||
|
Reference in New Issue
Block a user