Add GS1PARENS_MODE (input_mode) to allow inputting GS1 AIs in parentheses

This commit is contained in:
gitlost 2021-05-15 12:23:46 +01:00
parent 6fb0d077bc
commit 79d3c1dc7a
38 changed files with 672 additions and 359 deletions

View file

@ -305,6 +305,10 @@ INTERNAL int c39(struct zint_symbol *symbol, unsigned char source[], int length)
}
}
if (symbol->debug) {
printf("Barspaces: %s\n", dest);
}
expand(symbol, dest);
if (symbol->symbology == BARCODE_CODE39) {

View file

@ -1041,7 +1041,7 @@ INTERNAL int nve_18(struct zint_symbol *symbol, unsigned char source[], int leng
}
zeroes = 17 - length;
ustrcpy(ean128_equiv, "[00]");
ustrcpy(ean128_equiv, symbol->input_mode & GS1PARENS_MODE ? "(00)" : "[00]");
memset(ean128_equiv + 4, '0', zeroes);
ustrcpy(ean128_equiv + 4 + zeroes, source);
@ -1079,7 +1079,7 @@ INTERNAL int ean_14(struct zint_symbol *symbol, unsigned char source[], int leng
}
zeroes = 13 - length;
ustrcpy(ean128_equiv, "[01]");
ustrcpy(ean128_equiv, symbol->input_mode & GS1PARENS_MODE ? "(01)" : "[01]");
memset(ean128_equiv + 4, '0', zeroes);
ustrcpy(ean128_equiv + 4 + zeroes, source);

View file

@ -1247,13 +1247,14 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour
return 0;
}
static int linear_dummy_run(unsigned char *source, const int length, char *errtxt) {
static int linear_dummy_run(int input_mode, unsigned char *source, const int length, char *errtxt) {
struct zint_symbol *dummy;
int error_number;
int linear_width;
dummy = ZBarcode_Create();
dummy->symbology = BARCODE_GS1_128_CC;
dummy->input_mode = input_mode;
dummy->option_1 = 3;
error_number = ean_128(dummy, source, length);
linear_width = dummy->width;
@ -1304,7 +1305,7 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l
if (symbol->symbology == BARCODE_GS1_128_CC) {
/* Do a test run of encoding the linear component to establish its width */
linear_width = linear_dummy_run((unsigned char *) symbol->primary, pri_len, symbol->errtxt);
linear_width = linear_dummy_run(symbol->input_mode, (unsigned char *) symbol->primary, pri_len, symbol->errtxt);
if (linear_width == 0) {
strcat(symbol->errtxt, " in linear component");
return ZINT_ERROR_INVALID_DATA;
@ -1424,6 +1425,7 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l
linear = ZBarcode_Create(); /* Symbol contains the 2D component and Linear contains the rest */
linear->symbology = symbol->symbology;
linear->input_mode = symbol->input_mode;
linear->option_2 = symbol->option_2;
linear->debug = symbol->debug;

View file

@ -243,7 +243,7 @@ static int isc40text(const int current_mode, const unsigned char input) {
}
/* Return true (1) if a character is valid in X12 set */
static int isX12(const int input) {
static int isX12(const unsigned char input) {
if (isc40(input)) {
return 1;

View file

@ -1187,7 +1187,9 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[]
int bracket_level, max_bracket_level, ai_length, max_ai_length, min_ai_length;
int ai_count;
int error_value = 0;
int ai_max = chr_cnt(source, src_len, '[') + 1; /* Plus 1 so non-zero */
char obracket = symbol->input_mode & GS1PARENS_MODE ? '(' : '[';
char cbracket = symbol->input_mode & GS1PARENS_MODE ? ')' : ']';
int ai_max = chr_cnt(source, src_len, obracket) + 1; /* Plus 1 so non-zero */
#ifndef _MSC_VER
int ai_value[ai_max], ai_location[ai_max], data_location[ai_max], data_length[ai_max];
#else
@ -1217,7 +1219,7 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[]
}
}
if (source[0] != '[') {
if (source[0] != obracket) {
strcpy(symbol->errtxt, "252: Data does not start with an AI");
if (symbol->warn_level != WARN_ZPL_COMPAT) {
return ZINT_ERROR_INVALID_DATA;
@ -1236,14 +1238,14 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[]
ai_latch = 0;
for (i = 0; i < src_len; i++) {
ai_length += j;
if (((j == 1) && (source[i] != ']')) && ((source[i] < '0') || (source[i] > '9'))) {
if (((j == 1) && (source[i] != cbracket)) && ((source[i] < '0') || (source[i] > '9'))) {
ai_latch = 1;
}
if (source[i] == '[') {
if (source[i] == obracket) {
bracket_level++;
j = 1;
}
if (source[i] == ']') {
if (source[i] == cbracket) {
bracket_level--;
if (ai_length < min_ai_length) {
min_ai_length = ai_length;
@ -1292,13 +1294,13 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[]
ai_count = 0;
for (i = 1; i < src_len; i++) {
if (source[i - 1] == '[') {
if (source[i - 1] == obracket) {
ai_location[ai_count] = i;
j = 0;
do {
ai_string[j] = source[i + j];
j++;
} while (ai_string[j - 1] != ']');
} while (ai_string[j - 1] != cbracket);
ai_string[j - 1] = '\0';
ai_value[ai_count] = atoi(ai_string);
ai_count++;
@ -1315,7 +1317,7 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[]
}
data_length[i] = 0;
while ((data_location[i] + data_length[i] < src_len)
&& (source[data_location[i] + data_length[i]] != '[')) {
&& (source[data_location[i] + data_length[i]] != obracket)) {
data_length[i]++;
}
if (data_length[i] == 0) {
@ -1352,10 +1354,10 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[]
j = 0;
ai_latch = 1;
for (i = 0; i < src_len; i++) {
if ((source[i] != '[') && (source[i] != ']')) {
if ((source[i] != obracket) && (source[i] != cbracket)) {
reduced[j++] = source[i];
}
if (source[i] == '[') {
if (source[i] == obracket) {
/* Start of an AI string */
if (ai_latch == 0) {
reduced[j++] = '[';

View file

@ -39,6 +39,7 @@
#include "common.h"
#include "eci.h"
#include "gs1.h"
#include "zfiletypes.h"
#define TECHNETIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"
@ -49,10 +50,10 @@ typedef int static_assert_int_at_least_32bits[CHAR_BIT != 8 || sizeof(int) < 4 ?
struct zint_symbol *ZBarcode_Create() {
struct zint_symbol *symbol;
symbol = (struct zint_symbol*) malloc(sizeof (*symbol));
symbol = (struct zint_symbol *) malloc(sizeof(*symbol));
if (!symbol) return NULL;
memset(symbol, 0, sizeof (*symbol));
memset(symbol, 0, sizeof(*symbol));
symbol->symbology = BARCODE_CODE128;
strcpy(symbol->fgcolour, "000000");
@ -952,7 +953,7 @@ static int escape_char_process(struct zint_symbol *symbol, unsigned char *input_
#ifndef _MSC_VER
unsigned char escaped_string[*length + 1];
#else
unsigned char* escaped_string = (unsigned char*) _alloca(*length + 1);
unsigned char *escaped_string = (unsigned char *) _alloca(*length + 1);
#endif
in_posn = 0;

View file

@ -45,6 +45,7 @@
#include <assert.h>
#include "common.h"
#include "output.h"
#include "zfiletypes.h"
#include "font.h" /* Font for human readable text */

View file

@ -56,10 +56,12 @@ static void test_options(int index, int debug) {
/* 3*/ { BARCODE_AZTEC, -1, -1, -1, 36, "1234567890", 0, 151, 151 },
/* 4*/ { BARCODE_AZTEC, -1, -1, -1, 37, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1 },
/* 5*/ { BARCODE_AZTEC, GS1_MODE, READER_INIT, -1, -1, "[91]A", ZINT_ERROR_INVALID_OPTION, -1, -1 },
/* 6*/ { BARCODE_AZTEC, -1, READER_INIT, -1, 26, "A", 0, 109, 109 }, // 22 layers
/* 7*/ { BARCODE_AZTEC, -1, READER_INIT, -1, 27, "A", ZINT_ERROR_TOO_LONG, -1, -1 }, // 23 layers
/* 8*/ { BARCODE_AZTEC, -1, READER_INIT, -1, 1, "A", 0, 15, 15 }, // Compact 1 layer
/* 9*/ { BARCODE_AZTEC, -1, READER_INIT, -1, 2, "A", 0, 19, 19 }, // Compact 2 layers gets set to full 1 layer if READER_INIT set
/* 6*/ { BARCODE_AZTEC, GS1_MODE, -1, -1, -1, "[91]A", 0, 15, 15 },
/* 7*/ { BARCODE_AZTEC, GS1_MODE | GS1PARENS_MODE, -1, -1, -1, "(91)A", 0, 15, 15 },
/* 8*/ { BARCODE_AZTEC, -1, READER_INIT, -1, 26, "A", 0, 109, 109 }, // 22 layers
/* 9*/ { BARCODE_AZTEC, -1, READER_INIT, -1, 27, "A", ZINT_ERROR_TOO_LONG, -1, -1 }, // 23 layers
/* 10*/ { BARCODE_AZTEC, -1, READER_INIT, -1, 1, "A", 0, 15, 15 }, // Compact 1 layer
/* 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);

View file

@ -216,25 +216,26 @@ static void test_input(int index, int debug) {
/* 4*/ { -1, -1, 1, "1", -1, 0, 16, 18, "", },
/* 5*/ { -1, -1, 1, "ABCDEFGHIJKLMN", -1, ZINT_ERROR_TOO_LONG, -1, -1, "Error 518: Input too long for selected symbol size", },
/* 6*/ { GS1_MODE, -1, 1, "[01]12345678901231", -1, 0, 16, 18, "", },
/* 7*/ { -1, 3, 1, "1", -1, 0, 16, 18, "", },
/* 8*/ { UNICODE_MODE, 3, 1, "é", -1, 0, 16, 18, "", },
/* 9*/ { GS1_MODE, 3, 1, "[01]12345678901231", -1, ZINT_WARN_INVALID_OPTION, 16, 18, "Warning 512: ECI ignored for GS1 mode", },
/* 10*/ { -1, -1, 9, "123456789012345678", -1, 0, 8, 31, "", },
/* 11*/ { -1, -1, 9, "12345678901234567A", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 515: Invalid input data (Version S encodes numeric input only)", },
/* 12*/ { -1, -1, 9, "1234567890123456789", -1, ZINT_ERROR_TOO_LONG, -1, -1, "Error 514: Input data too long for Version S", },
/* 13*/ { GS1_MODE, -1, 9, "[01]12345678901231", -1, ZINT_WARN_INVALID_OPTION, 8, 31, "Warning 511: ECI and GS1 mode ignored for Version S", },
/* 14*/ { -1, 3, 9, "1", -1, ZINT_WARN_INVALID_OPTION, 8, 11, "Warning 511: ECI and GS1 mode ignored for Version S", },
/* 15*/ { -1, -1, 10, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", -1, 0, 16, 49, "", },
/* 16*/ { -1, -1, 10, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901", -1, ZINT_ERROR_TOO_LONG, -1, -1, "Error 519: Input data too long for Version T", },
/* 17*/ { -1, -1, 10, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", -1, 0, 16, 49, "", },
/* 18*/ { -1, -1, 10, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", -1, ZINT_ERROR_TOO_LONG, -1, -1, "Error 516: Input data too long for Version T", },
/* 19*/ { -1, -1, 10, "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 38, 0, 16, 49, "", },
/* 20*/ { -1, 3, 10, "1234567890123456789012345678901234567890123456789012345678901234567890123456", -1, 0, 16, 49, "", },
/* 21*/ { -1, 3, 10, "12345678901234567890123456789012345678901234567890123456789012345678901234567", -1, ZINT_ERROR_TOO_LONG, -1, -1, "Error 516: Input data too long for Version T", },
/* 22*/ { -1, 3, 10, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234", -1, ZINT_ERROR_TOO_LONG, -1, -1, "Error 519: Input data too long for Version T", },
/* 23*/ { GS1_MODE, -1, 10, "[01]12345678901231", -1, 0, 16, 17, "", },
/* 24*/ { GS1_MODE, 3, 10, "[01]12345678901231", -1, ZINT_WARN_INVALID_OPTION, 16, 17, "Warning 512: ECI ignored for GS1 mode", },
/* 25*/ { -1, -1, 11, "1", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 513: Invalid symbol size", },
/* 7*/ { GS1_MODE | GS1PARENS_MODE, -1, 1, "(01)12345678901231", -1, 0, 16, 18, "", },
/* 8*/ { -1, 3, 1, "1", -1, 0, 16, 18, "", },
/* 9*/ { UNICODE_MODE, 3, 1, "é", -1, 0, 16, 18, "", },
/* 10*/ { GS1_MODE, 3, 1, "[01]12345678901231", -1, ZINT_WARN_INVALID_OPTION, 16, 18, "Warning 512: ECI ignored for GS1 mode", },
/* 11*/ { -1, -1, 9, "123456789012345678", -1, 0, 8, 31, "", },
/* 12*/ { -1, -1, 9, "12345678901234567A", -1, ZINT_ERROR_INVALID_DATA, -1, -1, "Error 515: Invalid input data (Version S encodes numeric input only)", },
/* 13*/ { -1, -1, 9, "1234567890123456789", -1, ZINT_ERROR_TOO_LONG, -1, -1, "Error 514: Input data too long for Version S", },
/* 14*/ { GS1_MODE, -1, 9, "[01]12345678901231", -1, ZINT_WARN_INVALID_OPTION, 8, 31, "Warning 511: ECI and GS1 mode ignored for Version S", },
/* 15*/ { -1, 3, 9, "1", -1, ZINT_WARN_INVALID_OPTION, 8, 11, "Warning 511: ECI and GS1 mode ignored for Version S", },
/* 16*/ { -1, -1, 10, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", -1, 0, 16, 49, "", },
/* 17*/ { -1, -1, 10, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901", -1, ZINT_ERROR_TOO_LONG, -1, -1, "Error 519: Input data too long for Version T", },
/* 18*/ { -1, -1, 10, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", -1, 0, 16, 49, "", },
/* 19*/ { -1, -1, 10, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", -1, ZINT_ERROR_TOO_LONG, -1, -1, "Error 516: Input data too long for Version T", },
/* 20*/ { -1, -1, 10, "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 38, 0, 16, 49, "", },
/* 21*/ { -1, 3, 10, "1234567890123456789012345678901234567890123456789012345678901234567890123456", -1, 0, 16, 49, "", },
/* 22*/ { -1, 3, 10, "12345678901234567890123456789012345678901234567890123456789012345678901234567", -1, ZINT_ERROR_TOO_LONG, -1, -1, "Error 516: Input data too long for Version T", },
/* 23*/ { -1, 3, 10, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234", -1, ZINT_ERROR_TOO_LONG, -1, -1, "Error 519: Input data too long for Version T", },
/* 24*/ { GS1_MODE, -1, 10, "[01]12345678901231", -1, 0, 16, 17, "", },
/* 25*/ { GS1_MODE, 3, 10, "[01]12345678901231", -1, ZINT_WARN_INVALID_OPTION, 16, 17, "Warning 512: ECI ignored for GS1 mode", },
/* 26*/ { -1, -1, 11, "1", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 513: Invalid symbol size", },
};
int data_size = ARRAY_SIZE(data);

View file

@ -368,6 +368,7 @@ static void test_ean128_input(int index, int generate, int debug) {
int ret;
struct item {
int input_mode;
char *data;
int ret;
int expected_width;
@ -375,28 +376,29 @@ static void test_ean128_input(int index, int generate, int debug) {
char *comment;
};
struct item data[] = {
/* 0*/ { "[90]1[90]1", 0, 123, "(11) 105 102 90 100 17 102 25 99 1 56 106", "StartC FNC1 90 CodeB 1 FNC1 9" },
/* 1*/ { "[90]1[90]12", 0, 123, "(11) 105 102 90 100 17 99 102 90 12 13 106", "StartC FNC1 90 CodeB 1 CodeC FNC1 90 12" },
/* 2*/ { "[90]1[90]123", 0, 134, "(12) 105 102 90 100 17 102 25 99 1 23 57 106", "StartC FNC1 90 CodeB 1 FNC1 9 CodeC 01 23" },
/* 3*/ { "[90]12[90]1", 0, 123, "(11) 105 102 90 12 102 100 25 99 1 19 106", "StartC FNC1 90 12 FNC1 CodeB 9 CodeC 01" },
/* 4*/ { "[90]12[90]12", 0, 101, "(9) 105 102 90 12 102 90 12 14 106", "StartC FNC1 90 12 FNC1 90 12" },
/* 5*/ { "[90]12[90]123", 0, 134, "(12) 105 102 90 12 102 100 25 99 1 23 20 106", "StartC FNC1 90 12 FNC1 CodeB 9 CodeC 01 23" },
/* 6*/ { "[90]123[90]1", 0, 134, "(12) 105 102 90 12 100 19 102 25 99 1 34 106", "StartC FNC1 90 12 CodeB 3 FNC1 9 CodeC 01" },
/* 7*/ { "[90]123[90]1234", 0, 145, "(13) 105 102 90 12 100 19 99 102 90 12 34 98 106", "StartC FNC1 90 12 CodeB 3 CodeC FNC1 90 12 34" },
/* 8*/ { "[90]1[90]1[90]1", 0, 178, "(16) 105 102 90 100 17 102 25 99 1 102 100 25 99 1 51 106", "StartC FNC1 90 CodeB 1 FNC1 9 CodeC 01 FNC1 CodeB 9 CodeC 01" },
/* 9*/ { "[90]1[90]12[90]1", 0, 178, "(16) 105 102 90 100 17 99 102 90 12 102 100 25 99 1 8 106", "StartC FNC1 90 CodeB 1 CodeC FNC1 90 12 FNC1 CodeB 9 CodeC 01" },
/* 10*/ { "[90]1[90]123[90]1", 0, 189, "(17) 105 102 90 100 17 102 25 99 1 23 102 100 25 99 1 70 106", "StartC FNC1 90 CodeB 1 FNC1 9 CodeC 01 23 FNC1 CodeB 9 CodeC 01" },
/* 11*/ { "[90]12[90]123[90]1", 0, 189, "(17) 105 102 90 12 102 100 25 99 1 23 102 100 25 99 1 33 106", "StartC FNC1 90 12 FNC1 CodeB 9 CodeC 01 23 FNC1 CodeB 9 CodeC 01" },
/* 12*/ { "[90]12[90]123[90]12", 0, 167, "(15) 105 102 90 12 102 100 25 99 1 23 102 90 12 11 106", "StartC FNC1 90 12 FNC1 CodeB 9 CodeC 01 23 FNC1 90 12" },
/* 13*/ { "[90]123[90]1[90]1", 0, 189, "(17) 105 102 90 12 100 19 102 25 99 1 102 100 25 99 1 47 106", "StartC FNC1 90 12 CodeB 3 FNC1 9 CodeC 01 FNC1 CodeB 9 CodeC 01" },
/* 14*/ { "[90]123[90]12[90]1", 0, 189, "(17) 105 102 90 12 100 19 99 102 90 12 102 100 25 99 1 80 106", "StartC FNC1 90 12 CodeB 3 CodeC FNC1 90 12 FNC1 CodeB 9 CodeC 01" },
/* 15*/ { "[90]123[90]123[90]12", 0, 178, "(16) 105 102 90 12 100 19 102 25 99 1 23 102 90 12 47 106", "StartC FNC1 90 12 CodeB 3 FNC1 9 CodeC 01 23 FNC1 90 12" },
/* 16*/ { "[90]123[90]1234[90]1", 0, 200, "(18) 105 102 90 12 100 19 99 102 90 12 34 102 100 25 99 1 26 106", "StartC FNC1 90 12 CodeB 3 CodeC FNC1 90 12 34 FNC1 CodeB 9 CodeC 01" },
/* 17*/ { "[90]123[90]1234[90]123", 0, 211, "(19) 105 102 90 12 100 19 99 102 90 12 34 102 100 25 99 1 23 85 106", "StartC FNC1 90 12 CodeB 3 CodeC FNC1 90 12 34 FNC1 CodeB 9 CodeC 01 23" },
/* 18*/ { "[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" },
/* 19*/ { "[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" },
/* 20*/ { "[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" },
/* 21*/ { "[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" } };
/* 0*/ { GS1_MODE, "[90]1[90]1", 0, 123, "(11) 105 102 90 100 17 102 25 99 1 56 106", "StartC FNC1 90 CodeB 1 FNC1 9" },
/* 1*/ { GS1_MODE | GS1PARENS_MODE, "(90)1(90)1", 0, 123, "(11) 105 102 90 100 17 102 25 99 1 56 106", "StartC FNC1 90 CodeB 1 FNC1 9" },
/* 2*/ { GS1_MODE, "[90]1[90]12", 0, 123, "(11) 105 102 90 100 17 99 102 90 12 13 106", "StartC FNC1 90 CodeB 1 CodeC FNC1 90 12" },
/* 3*/ { GS1_MODE, "[90]1[90]123", 0, 134, "(12) 105 102 90 100 17 102 25 99 1 23 57 106", "StartC FNC1 90 CodeB 1 FNC1 9 CodeC 01 23" },
/* 4*/ { GS1_MODE, "[90]12[90]1", 0, 123, "(11) 105 102 90 12 102 100 25 99 1 19 106", "StartC FNC1 90 12 FNC1 CodeB 9 CodeC 01" },
/* 5*/ { GS1_MODE, "[90]12[90]12", 0, 101, "(9) 105 102 90 12 102 90 12 14 106", "StartC FNC1 90 12 FNC1 90 12" },
/* 6*/ { GS1_MODE, "[90]12[90]123", 0, 134, "(12) 105 102 90 12 102 100 25 99 1 23 20 106", "StartC FNC1 90 12 FNC1 CodeB 9 CodeC 01 23" },
/* 7*/ { GS1_MODE, "[90]123[90]1", 0, 134, "(12) 105 102 90 12 100 19 102 25 99 1 34 106", "StartC FNC1 90 12 CodeB 3 FNC1 9 CodeC 01" },
/* 8*/ { GS1_MODE, "[90]123[90]1234", 0, 145, "(13) 105 102 90 12 100 19 99 102 90 12 34 98 106", "StartC FNC1 90 12 CodeB 3 CodeC FNC1 90 12 34" },
/* 9*/ { GS1_MODE, "[90]1[90]1[90]1", 0, 178, "(16) 105 102 90 100 17 102 25 99 1 102 100 25 99 1 51 106", "StartC FNC1 90 CodeB 1 FNC1 9 CodeC 01 FNC1 CodeB 9 CodeC 01" },
/* 10*/ { GS1_MODE, "[90]1[90]12[90]1", 0, 178, "(16) 105 102 90 100 17 99 102 90 12 102 100 25 99 1 8 106", "StartC FNC1 90 CodeB 1 CodeC FNC1 90 12 FNC1 CodeB 9 CodeC 01" },
/* 11*/ { GS1_MODE, "[90]1[90]123[90]1", 0, 189, "(17) 105 102 90 100 17 102 25 99 1 23 102 100 25 99 1 70 106", "StartC FNC1 90 CodeB 1 FNC1 9 CodeC 01 23 FNC1 CodeB 9 CodeC 01" },
/* 12*/ { GS1_MODE, "[90]12[90]123[90]1", 0, 189, "(17) 105 102 90 12 102 100 25 99 1 23 102 100 25 99 1 33 106", "StartC FNC1 90 12 FNC1 CodeB 9 CodeC 01 23 FNC1 CodeB 9 CodeC 01" },
/* 13*/ { GS1_MODE, "[90]12[90]123[90]12", 0, 167, "(15) 105 102 90 12 102 100 25 99 1 23 102 90 12 11 106", "StartC FNC1 90 12 FNC1 CodeB 9 CodeC 01 23 FNC1 90 12" },
/* 14*/ { GS1_MODE, "[90]123[90]1[90]1", 0, 189, "(17) 105 102 90 12 100 19 102 25 99 1 102 100 25 99 1 47 106", "StartC FNC1 90 12 CodeB 3 FNC1 9 CodeC 01 FNC1 CodeB 9 CodeC 01" },
/* 15*/ { GS1_MODE, "[90]123[90]12[90]1", 0, 189, "(17) 105 102 90 12 100 19 99 102 90 12 102 100 25 99 1 80 106", "StartC FNC1 90 12 CodeB 3 CodeC FNC1 90 12 FNC1 CodeB 9 CodeC 01" },
/* 16*/ { GS1_MODE, "[90]123[90]123[90]12", 0, 178, "(16) 105 102 90 12 100 19 102 25 99 1 23 102 90 12 47 106", "StartC FNC1 90 12 CodeB 3 FNC1 9 CodeC 01 23 FNC1 90 12" },
/* 17*/ { GS1_MODE, "[90]123[90]1234[90]1", 0, 200, "(18) 105 102 90 12 100 19 99 102 90 12 34 102 100 25 99 1 26 106", "StartC FNC1 90 12 CodeB 3 CodeC FNC1 90 12 34 FNC1 CodeB 9 CodeC 01" },
/* 18*/ { GS1_MODE, "[90]123[90]1234[90]123", 0, 211, "(19) 105 102 90 12 100 19 99 102 90 12 34 102 100 25 99 1 23 85 106", "StartC FNC1 90 12 CodeB 3 CodeC FNC1 90 12 34 FNC1 CodeB 9 CodeC 01 23" },
/* 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" } };
int data_size = ARRAY_SIZE(data);
char escaped[1024];
@ -410,14 +412,14 @@ static void test_ean128_input(int index, int generate, int debug) {
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
int length = testUtilSetSymbol(symbol, BARCODE_GS1_128, GS1_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
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);
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);
if (generate) {
printf(" /*%3d*/ { \"%s\", %s, %d, \"%s\", \"%s\" },\n",
i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
printf(" /*%3d*/ { %s, \"%s\", %s, %d, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].comment);
} else {
if (ret < ZINT_ERROR) {

View file

@ -166,19 +166,20 @@ static void test_input(int index, int generate, int debug) {
/* 2*/ { UNICODE_MODE, "12", -1, 0, 2, 70, "(10) 2 12 103 103 103 103 103 103 98 27", "ModeC 12 Pad (6)" },
/* 3*/ { GS1_MODE, "[90]A", -1, 0, 2, 70, "(10) 3 25 16 33 103 103 103 103 83 20", "ModeBFNC1 9 0 A Pad (4)" },
/* 4*/ { GS1_MODE, "[90]12", -1, 0, 2, 70, "(10) 4 90 12 103 103 103 103 103 79 62", "ModeCFNC1 90 12 Pad (5)" },
/* 5*/ { UNICODE_MODE, "a0123456789", -1, 0, 2, 70, "(10) 5 65 1 23 45 67 89 103 27 86", "ModeC1SB a 01 23 45 67 89 Pad" },
/* 6*/ { UNICODE_MODE, "ab0123456789", -1, 0, 2, 70, "(10) 6 65 66 1 23 45 67 89 19 42", "ModeC2SB a b 01 23 45 67 89" },
/* 7*/ { UNICODE_MODE, "1234\037a", -1, 0, 2, 70, "(10) 2 12 34 101 95 98 65 103 67 53", "ModeC 12 34 CodeA US 1SB a Pad" },
/* 8*/ { UNICODE_MODE, "\000\037ß", 4, 0, 2, 70, "(10) 0 64 95 101 63 103 103 103 75 11", "ModeA NUL US FNC4 ß Pad (3)" },
/* 9*/ { UNICODE_MODE, "\000\037é", 4, 0, 2, 70, "(10) 0 64 95 101 98 73 103 103 75 6", "ModeA NUL US FNC4 1SB é Pad (2)" },
/* 10*/ { UNICODE_MODE, "\000\037éa", 5, 0, 2, 70, "(10) 0 64 95 100 100 73 65 103 99 69", "ModeA NUL US CodeB FNC4 é a Pad" },
/* 11*/ { UNICODE_MODE, "abß", -1, 0, 2, 70, "(10) 1 65 66 100 63 103 103 103 66 56", "ModeB a b FNC4 ß Pad (3)" },
/* 12*/ { DATA_MODE, "\141\142\237", -1, 0, 2, 70, "(10) 1 65 66 100 98 95 103 103 6 71", "ModeB a b FNC4 1SA APC Pad (2)" },
/* 13*/ { DATA_MODE, "\141\142\237\037", -1, 0, 2, 70, "(10) 1 65 66 101 101 95 95 103 72 93", "ModeB a b CodeA FNC4 APC US Pad" },
/* 14*/ { UNICODE_MODE, "ééé", -1, 0, 2, 70, "(10) 1 100 73 100 73 100 73 103 105 106", "ModeB FNC4 é FNC4 é FNC4 é Pad" },
/* 15*/ { UNICODE_MODE, "aééééb", -1, 0, 3, 70, "(15) 8 65 100 73 100 73 100 73 100 73 66 103 103 39 83", "ModeB a FNC4 é (4) b Pad (2)" },
/* 16*/ { UNICODE_MODE, "aéééééb", -1, 0, 3, 70, "(15) 8 65 100 73 100 73 100 73 100 73 100 73 66 74 106", "ModeB a FNC4 é (5) b" },
/* 17*/ { 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 é" },
/* 5*/ { GS1_MODE | GS1PARENS_MODE, "(90)12", -1, 0, 2, 70, "(10) 4 90 12 103 103 103 103 103 79 62", "ModeCFNC1 90 12 Pad (5)" },
/* 6*/ { UNICODE_MODE, "a0123456789", -1, 0, 2, 70, "(10) 5 65 1 23 45 67 89 103 27 86", "ModeC1SB a 01 23 45 67 89 Pad" },
/* 7*/ { UNICODE_MODE, "ab0123456789", -1, 0, 2, 70, "(10) 6 65 66 1 23 45 67 89 19 42", "ModeC2SB a b 01 23 45 67 89" },
/* 8*/ { UNICODE_MODE, "1234\037a", -1, 0, 2, 70, "(10) 2 12 34 101 95 98 65 103 67 53", "ModeC 12 34 CodeA US 1SB a Pad" },
/* 9*/ { UNICODE_MODE, "\000\037ß", 4, 0, 2, 70, "(10) 0 64 95 101 63 103 103 103 75 11", "ModeA NUL US FNC4 ß Pad (3)" },
/* 10*/ { UNICODE_MODE, "\000\037é", 4, 0, 2, 70, "(10) 0 64 95 101 98 73 103 103 75 6", "ModeA NUL US FNC4 1SB é Pad (2)" },
/* 11*/ { UNICODE_MODE, "\000\037éa", 5, 0, 2, 70, "(10) 0 64 95 100 100 73 65 103 99 69", "ModeA NUL US CodeB FNC4 é a Pad" },
/* 12*/ { UNICODE_MODE, "abß", -1, 0, 2, 70, "(10) 1 65 66 100 63 103 103 103 66 56", "ModeB a b FNC4 ß Pad (3)" },
/* 13*/ { DATA_MODE, "\141\142\237", -1, 0, 2, 70, "(10) 1 65 66 100 98 95 103 103 6 71", "ModeB a b FNC4 1SA APC Pad (2)" },
/* 14*/ { DATA_MODE, "\141\142\237\037", -1, 0, 2, 70, "(10) 1 65 66 101 101 95 95 103 72 93", "ModeB a b CodeA FNC4 APC US Pad" },
/* 15*/ { UNICODE_MODE, "ééé", -1, 0, 2, 70, "(10) 1 100 73 100 73 100 73 103 105 106", "ModeB FNC4 é FNC4 é FNC4 é Pad" },
/* 16*/ { UNICODE_MODE, "aééééb", -1, 0, 3, 70, "(15) 8 65 100 73 100 73 100 73 100 73 66 103 103 39 83", "ModeB a FNC4 é (4) b Pad (2)" },
/* 17*/ { UNICODE_MODE, "aéééééb", -1, 0, 3, 70, "(15) 8 65 100 73 100 73 100 73 100 73 100 73 66 74 106", "ModeB a FNC4 é (5) b" },
/* 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);

View file

@ -112,6 +112,7 @@ static void test_input(int index, int generate, int debug) {
/* 11*/ { UNICODE_MODE, "\000A\000a\000", 5, 0, 2, 70, "(16) 38 10 43 38 44 10 43 30 38 48 25 23 38 32 4 12", "NUL A S1 NUL S2 a S1 (C18 30) NUL (Start 4, Alphanumeric S1)" },
/* 12*/ { UNICODE_MODE, "1234\037aA12345A", -1, 0, 3, 70, "(24) 1 2 3 4 43 5 44 4 10 10 48 5 17 9 48 0 10 48 19 2 13 32 7 33", "1 2 3 4 S1 US S2 (C18 4) a A NS 12345 NS (C28 0) A (Start 0, Alpha)" },
/* 13*/ { GS1_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)" },
/* 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);

View file

@ -2772,6 +2772,75 @@ static void test_addongap(int index, int generate, int debug) {
testFinish();
}
static void test_gs1parens(int index, int debug) {
testStart("");
int ret;
struct item {
int symbology;
int input_mode;
char *data;
char *composite;
int ret;
int expected_rows;
int expected_width;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { BARCODE_EANX_CC, -1, "1234567", "[21]A12345678", 0, 8, 72 }, // EAN-8
/* 1*/ { BARCODE_EANX_CC, GS1PARENS_MODE, "1234567", "(21)A12345678", 0, 8, 72 }, // EAN-8
/* 2*/ { BARCODE_EANX_CC, -1, "123456789012", "[21]A12345678", 0, 7, 99 }, // EAN-13
/* 3*/ { BARCODE_EANX_CC, GS1PARENS_MODE, "123456789012", "(21)A12345678", 0, 7, 99 }, // EAN-13
/* 4*/ { BARCODE_GS1_128_CC, -1, "[01]12345678901231", "[21]A12345678", 0, 5, 145 },
/* 5*/ { BARCODE_GS1_128_CC, GS1PARENS_MODE, "(01)12345678901231", "(21)A12345678", 0, 5, 145 },
/* 6*/ { BARCODE_DBAR_OMN_CC, -1, "12345678901231", "[21]A12345678", 0, 5, 100 },
/* 7*/ { BARCODE_DBAR_OMN_CC, GS1PARENS_MODE, "12345678901231", "(21)A12345678", 0, 5, 100 },
/* 8*/ { BARCODE_DBAR_LTD_CC, -1, "12345678901231", "[21]A12345678", 0, 6, 79 },
/* 9*/ { BARCODE_DBAR_LTD_CC, GS1PARENS_MODE, "12345678901231", "(21)A12345678", 0, 6, 79 },
/* 10*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231[3103]001234", "[21]A12345678", 0, 5, 200 },
/* 11*/ { BARCODE_DBAR_EXP_CC, GS1PARENS_MODE, "(01)12345678901231(3103)001234", "(21)A12345678", 0, 5, 200 },
/* 12*/ { BARCODE_UPCA_CC, -1, "12345678901", "[21]A12345678", 0, 7, 99 },
/* 13*/ { BARCODE_UPCA_CC, GS1PARENS_MODE, "12345678901", "(21)A12345678", 0, 7, 99 },
/* 14*/ { BARCODE_UPCE_CC, -1, "1234567", "[21]A12345678", 0, 9, 55 },
/* 15*/ { BARCODE_UPCE_CC, GS1PARENS_MODE, "1234567", "(21)A12345678", 0, 9, 55 },
/* 16*/ { BARCODE_DBAR_STK_CC, -1, "12345678901231", "[21]A12345678", 0, 9, 56 },
/* 17*/ { BARCODE_DBAR_STK_CC, GS1PARENS_MODE, "12345678901231", "(21)A12345678", 0, 9, 56 },
/* 18*/ { BARCODE_DBAR_OMNSTK_CC, -1, "12345678901231", "[21]A12345678", 0, 11, 56 },
/* 19*/ { BARCODE_DBAR_OMNSTK_CC, GS1PARENS_MODE, "12345678901231", "(21)A12345678", 0, 11, 56 },
/* 20*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231[3103]001234", "[21]A12345678", 0, 9, 102 },
/* 21*/ { BARCODE_DBAR_EXPSTK_CC, GS1PARENS_MODE, "(01)12345678901231(3103)001234", "(21)A12345678", 0, 9, 102 },
};
int data_size = ARRAY_SIZE(data);
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
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*/, -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);
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);
if (ret < ZINT_ERROR) {
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);
}
ZBarcode_Delete(symbol);
}
testFinish();
}
// #181 Christian Hartlage OSS-Fuzz
static void test_fuzz(int index, int debug) {
testStart("");
@ -2916,6 +2985,7 @@ int main(int argc, char *argv[]) {
{ "test_encodation_10", test_encodation_10, 1, 1, 1 },
{ "test_encodation_11", test_encodation_11, 1, 1, 1 },
{ "test_addongap", test_addongap, 1, 1, 1 },
{ "test_gs1parens", test_gs1parens, 1, 0, 1 },
{ "test_fuzz", test_fuzz, 1, 0, 1 },
{ "test_perf", test_perf, 1, 0, 1 },
};

View file

@ -421,6 +421,7 @@ static void test_options(int index, int debug) {
int ret;
struct item {
int symbology;
int input_mode;
int option_1;
int option_2;
int option_3;
@ -432,17 +433,19 @@ static void test_options(int index, int debug) {
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { BARCODE_DATAMATRIX, -1, -1, -1, "1", 0, 10, 10 },
/* 1*/ { BARCODE_DATAMATRIX, 2, -1, -1, "1", ZINT_ERROR_INVALID_OPTION, -1, -1 },
/* 2*/ { BARCODE_DATAMATRIX, -1, 1, -1, "1", 0, 10, 10 },
/* 3*/ { BARCODE_DATAMATRIX, -1, 2, -1, "1", 0, 12, 12 },
/* 4*/ { BARCODE_DATAMATRIX, -1, 48, -1, "1", 0, 26, 64 },
/* 5*/ { BARCODE_DATAMATRIX, -1, 49, -1, "1", 0, 10, 10 }, // Ignored
/* 6*/ { BARCODE_DATAMATRIX, -1, -1, -1, "ABCDEFGHIJK", 0, 8, 32 },
/* 7*/ { BARCODE_DATAMATRIX, -1, -1, DM_SQUARE, "ABCDEFGHIJK", 0, 16, 16 },
/* 8*/ { BARCODE_DATAMATRIX, -1, -1, -1, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTU", 0, 32, 32 },
/* 9*/ { BARCODE_DATAMATRIX, -1, -1, DM_DMRE, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTU", 0, 20, 44 },
/* 10*/ { BARCODE_DATAMATRIX, -1, -1, 9999, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTU", 0, 32, 32 }, // Ignored
/* 0*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, "1", 0, 10, 10 },
/* 1*/ { BARCODE_DATAMATRIX, -1, 2, -1, -1, "1", ZINT_ERROR_INVALID_OPTION, -1, -1 },
/* 2*/ { BARCODE_DATAMATRIX, -1, -1, 1, -1, "1", 0, 10, 10 },
/* 3*/ { BARCODE_DATAMATRIX, -1, -1, 2, -1, "1", 0, 12, 12 },
/* 4*/ { BARCODE_DATAMATRIX, -1, -1, 48, -1, "1", 0, 26, 64 },
/* 5*/ { BARCODE_DATAMATRIX, -1, -1, 49, -1, "1", 0, 10, 10 }, // Ignored
/* 6*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, "ABCDEFGHIJK", 0, 8, 32 },
/* 7*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_SQUARE, "ABCDEFGHIJK", 0, 16, 16 },
/* 8*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTU", 0, 32, 32 },
/* 9*/ { BARCODE_DATAMATRIX, -1, -1, -1, DM_DMRE, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTU", 0, 20, 44 },
/* 10*/ { BARCODE_DATAMATRIX, -1, -1, -1, 9999, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTU", 0, 32, 32 }, // Ignored
/* 11*/ { BARCODE_DATAMATRIX, GS1_MODE, -1, -1, -1, "[90]12", 0, 10, 10 },
/* 12*/ { BARCODE_DATAMATRIX, GS1_MODE | GS1PARENS_MODE, -1, -1, -1, "(90)12", 0, 10, 10 },
};
int data_size = ARRAY_SIZE(data);
@ -453,7 +456,7 @@ static void test_options(int index, int debug) {
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, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug);
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);
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);

View file

@ -71,17 +71,18 @@ static void test_input(int index, int generate, int debug) {
/* 22*/ { UNICODE_MODE, -1, "1712345610", -1, 0, "6B 64 0C 22 38", "FNC1 (0x6B) 17..10 12 34 56" },
/* 23*/ { GS1_MODE, -1, "[17]123456[10]123", -1, ZINT_WARN_NONCOMPLIANT, "Warning 64 0C 22 38 0C 66 13", "17..10 12 34 56 12 ShiftB (0x66) 3" },
/* 24*/ { GS1_MODE, -1, "[90]ABC[90]abc[90]123", -1, 0, "5A 6A 21 22 23 6B 19 10 41 42 43 6B 19 67 01 17", "90 LatchB (0x6A) A B C FNC1 (0x6B) 9 0 a b c FNC1 (0x6B) 9 2xShitfC (0x67) 01 23" },
/* 25*/ { UNICODE_MODE, -1, "99aA[{00\000", 9, 0, "6B 63 6A 41 21 3B 5B 10 10 65 40", "FNC1 (0x6B) 99 LatchB (0x6A) a A [ { 0 0 ShiftA (0x65) NUL" },
/* 26*/ { UNICODE_MODE, -1, "\015\012", -1, 0, "66 60", "ShiftB (0x66) CR/LF" },
/* 27*/ { UNICODE_MODE, -1, "A\015\012", -1, 0, "67 21 60", "2xShiftB (0x67) A CR/LF" },
/* 28*/ { UNICODE_MODE, -1, "\015\015\012", -1, 0, "65 4D 4D 4A", "LatchA (0x65) CR CR LF" },
/* 29*/ { UNICODE_MODE, -1, "ABCDE12345678", -1, 0, "6A 21 22 23 24 25 69 0C 22 38 4E", "LatchB (0x6A) A B C D 4xShiftC 12 34 56 78" },
/* 30*/ { UNICODE_MODE, -1, "\000ABCD1234567890", 15, 0, "65 40 21 22 23 24 6A 0C 22 38 4E 5A", "LatchA (0x65) NULL A B C D LatchC (0x6A) 12 34 56 78 90" },
/* 31*/ { DATA_MODE, -1, "\141\142\143\144\145\200\201\202\203\204\377", -1, 0, "6A 41 42 43 44 45 70 31 5A 35 21 5A 5F 02 31", "LatchB (0x6A) a b c d e BinaryLatch (0x70) 0x80 0x81 0x82 0x83 0x84 0xFF" },
/* 32*/ { DATA_MODE, -1, "\200\061\062\240\063\064\201\202\065\066", -1, 0, "6E 40 0C 6F 00 22 70 03 10 42 6E 15 16", "UpperShiftA (0x6E) NUL 12 UpperShiftB (0x6F) SP 34 BinaryLatch (0x70) 0x81 0x82 TermB (0x6E) 5 6" },
/* 33*/ { DATA_MODE, -1, "\200\201\202\203\061\062\063\064", -1, 0, "70 13 56 0A 59 2C 67 0C 22", "BinaryLatch (0x70) 0x80 0x81 0x82 0x83 Intr2xShiftC (0x67) 12 3" },
/* 34*/ { DATA_MODE, -1, "\001\200\201\202\203\204\200\201\202\203\204", -1, 0, "65 41 70 31 5A 35 21 5A 5F 31 5A 35 21 5A 5F", "LatchA (0x65) SOH BinaryLatch (0x70) 0x80 0x81 0x82 0x83 0x80 0x81 0x82 0x83" },
/* 35*/ { 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" },
/* 25*/ { GS1_MODE | GS1PARENS_MODE, -1, "(90)ABC(90)abc(90)123", -1, 0, "5A 6A 21 22 23 6B 19 10 41 42 43 6B 19 67 01 17", "90 LatchB (0x6A) A B C FNC1 (0x6B) 9 0 a b c FNC1 (0x6B) 9 2xShitfC (0x67) 01 23" },
/* 26*/ { UNICODE_MODE, -1, "99aA[{00\000", 9, 0, "6B 63 6A 41 21 3B 5B 10 10 65 40", "FNC1 (0x6B) 99 LatchB (0x6A) a A [ { 0 0 ShiftA (0x65) NUL" },
/* 27*/ { UNICODE_MODE, -1, "\015\012", -1, 0, "66 60", "ShiftB (0x66) CR/LF" },
/* 28*/ { UNICODE_MODE, -1, "A\015\012", -1, 0, "67 21 60", "2xShiftB (0x67) A CR/LF" },
/* 29*/ { UNICODE_MODE, -1, "\015\015\012", -1, 0, "65 4D 4D 4A", "LatchA (0x65) CR CR LF" },
/* 30*/ { UNICODE_MODE, -1, "ABCDE12345678", -1, 0, "6A 21 22 23 24 25 69 0C 22 38 4E", "LatchB (0x6A) A B C D 4xShiftC 12 34 56 78" },
/* 31*/ { UNICODE_MODE, -1, "\000ABCD1234567890", 15, 0, "65 40 21 22 23 24 6A 0C 22 38 4E 5A", "LatchA (0x65) NULL A B C D LatchC (0x6A) 12 34 56 78 90" },
/* 32*/ { DATA_MODE, -1, "\141\142\143\144\145\200\201\202\203\204\377", -1, 0, "6A 41 42 43 44 45 70 31 5A 35 21 5A 5F 02 31", "LatchB (0x6A) a b c d e BinaryLatch (0x70) 0x80 0x81 0x82 0x83 0x84 0xFF" },
/* 33*/ { DATA_MODE, -1, "\200\061\062\240\063\064\201\202\065\066", -1, 0, "6E 40 0C 6F 00 22 70 03 10 42 6E 15 16", "UpperShiftA (0x6E) NUL 12 UpperShiftB (0x6F) SP 34 BinaryLatch (0x70) 0x81 0x82 TermB (0x6E) 5 6" },
/* 34*/ { DATA_MODE, -1, "\200\201\202\203\061\062\063\064", -1, 0, "70 13 56 0A 59 2C 67 0C 22", "BinaryLatch (0x70) 0x80 0x81 0x82 0x83 Intr2xShiftC (0x67) 12 3" },
/* 35*/ { DATA_MODE, -1, "\001\200\201\202\203\204\200\201\202\203\204", -1, 0, "65 41 70 31 5A 35 21 5A 5F 31 5A 35 21 5A 5F", "LatchA (0x65) SOH BinaryLatch (0x70) 0x80 0x81 0x82 0x83 0x80 0x81 0x82 0x83" },
/* 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);

View file

@ -62,102 +62,131 @@ static void test_gs1_reduce(int index, int generate, int debug) {
/* 3*/ { BARCODE_GS1_128, UNICODE_MODE, "[01]12345678901231", "", 0, "Input mode ignored",
"11010011100111101011101100110110010110011100100010110001110001011011000010100110111101101011001110011011000110100001100101100011101011"
},
/* 4*/ { BARCODE_GS1_128_CC, -1, "[01]12345678901231", "[21]1234", 0, "Input mode ignored",
/* 4*/ { BARCODE_GS1_128, GS1PARENS_MODE, "(01)12345678901231", "", 0, "Input mode ignored (parentheses instead of square brackets)",
"11010011100111101011101100110110010110011100100010110001110001011011000010100110111101101011001110011011000110100001100101100011101011"
},
/* 5*/ { BARCODE_GS1_128_CC, -1, "[01]12345678901231", "[21]1234", 0, "Input mode ignored",
"0000000000000000000001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010000000000000000000000000"
"0000000000000000000001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010000000000000000000000000"
"0000000000000000000001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010000000000000000000000000"
"0010110001100001010001001100100110100110001101110100111000111010010011110101100100001001010011000110010011100100010100001000101001110011100010100"
"1101001110011110101110110011011001011001110010001011000111000101101100001010011011110110101100111001101100011011101011110111010110001100011101011"
},
/* 5*/ { BARCODE_GS1_128_CC, GS1_MODE, "[01]12345678901231", "[21]1234", 0, "Input mode ignored",
/* 6*/ { BARCODE_GS1_128_CC, GS1_MODE, "[01]12345678901231", "[21]1234", 0, "Input mode ignored",
"0000000000000000000001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010000000000000000000000000"
"0000000000000000000001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010000000000000000000000000"
"0000000000000000000001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010000000000000000000000000"
"0010110001100001010001001100100110100110001101110100111000111010010011110101100100001001010011000110010011100100010100001000101001110011100010100"
"1101001110011110101110110011011001011001110010001011000111000101101100001010011011110110101100111001101100011011101011110111010110001100011101011"
},
/* 6*/ { BARCODE_GS1_128_CC, UNICODE_MODE, "[01]12345678901231", "[21]1234", 0, "Input mode ignored",
/* 7*/ { BARCODE_GS1_128_CC, UNICODE_MODE, "[01]12345678901231", "[21]1234", 0, "Input mode ignored",
"0000000000000000000001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010000000000000000000000000"
"0000000000000000000001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010000000000000000000000000"
"0000000000000000000001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010000000000000000000000000"
"0010110001100001010001001100100110100110001101110100111000111010010011110101100100001001010011000110010011100100010100001000101001110011100010100"
"1101001110011110101110110011011001011001110010001011000111000101101100001010011011110110101100111001101100011011101011110111010110001100011101011"
},
/* 7*/ { BARCODE_EAN14, -1, "1234567890123", "", 0, "Input mode ignored; verified manually against tec-it",
/* 8*/ { BARCODE_GS1_128_CC, GS1PARENS_MODE, "(01)12345678901231", "(21)1234", 0, "Input mode ignored (parentheses instead of square brackets)",
"0000000000000000000001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010000000000000000000000000"
"0000000000000000000001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010000000000000000000000000"
"0000000000000000000001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010000000000000000000000000"
"0010110001100001010001001100100110100110001101110100111000111010010011110101100100001001010011000110010011100100010100001000101001110011100010100"
"1101001110011110101110110011011001011001110010001011000111000101101100001010011011110110101100111001101100011011101011110111010110001100011101011"
},
/* 9*/ { BARCODE_EAN14, -1, "1234567890123", "", 0, "Input mode ignored; verified manually against tec-it",
"11010011100111101011101100110110010110011100100010110001110001011011000010100110111101101011001110011011000110100001100101100011101011"
},
/* 8*/ { BARCODE_EAN14, GS1_MODE, "1234567890123", "", 0, "Input mode ignored",
/*10*/ { BARCODE_EAN14, GS1_MODE, "1234567890123", "", 0, "Input mode ignored",
"11010011100111101011101100110110010110011100100010110001110001011011000010100110111101101011001110011011000110100001100101100011101011"
},
/* 9*/ { BARCODE_EAN14, UNICODE_MODE, "1234567890123", "", 0, "Input mode ignored",
/*11*/ { BARCODE_EAN14, UNICODE_MODE, "1234567890123", "", 0, "Input mode ignored",
"11010011100111101011101100110110010110011100100010110001110001011011000010100110111101101011001110011011000110100001100101100011101011"
},
/*10*/ { BARCODE_NVE18, -1, "12345678901234567", "", 0, "Input mode ignored; verified manually against tec-it",
/*12*/ { BARCODE_EAN14, GS1PARENS_MODE, "1234567890123", "", 0, "Input mode ignored (parentheses instead of square brackets)",
"11010011100111101011101100110110010110011100100010110001110001011011000010100110111101101011001110011011000110100001100101100011101011"
},
/*13*/ { BARCODE_NVE18, -1, "12345678901234567", "", 0, "Input mode ignored; verified manually against tec-it",
"110100111001111010111011011001100101100111001000101100011100010110110000101001101111011010110011100100010110001110001011011000010010101101110001100011101011"
},
/*11*/ { BARCODE_NVE18, GS1_MODE, "12345678901234567", "", 0, "Input mode ignored",
/*14*/ { BARCODE_NVE18, GS1_MODE, "12345678901234567", "", 0, "Input mode ignored",
"110100111001111010111011011001100101100111001000101100011100010110110000101001101111011010110011100100010110001110001011011000010010101101110001100011101011"
},
/*12*/ { BARCODE_NVE18, UNICODE_MODE, "12345678901234567", "", 0, "Input mode ignored",
/*15*/ { BARCODE_NVE18, UNICODE_MODE, "12345678901234567", "", 0, "Input mode ignored",
"110100111001111010111011011001100101100111001000101100011100010110110000101001101111011010110011100100010110001110001011011000010010101101110001100011101011"
},
/*13*/ { BARCODE_DBAR_EXP, -1, "2012", "", ZINT_ERROR_INVALID_DATA, "GS1 data required", "" },
/*14*/ { BARCODE_DBAR_EXP, -1, "[20]12", "", 0, "Input mode ignored",
/*16*/ { BARCODE_NVE18, GS1PARENS_MODE, "12345678901234567", "", 0, "Input mode ignored (parentheses instead of square brackets)",
"110100111001111010111011011001100101100111001000101100011100010110110000101001101111011010110011100100010110001110001011011000010010101101110001100011101011"
},
/*17*/ { BARCODE_DBAR_EXP, -1, "2012", "", ZINT_ERROR_INVALID_DATA, "GS1 data required", "" },
/*18*/ { BARCODE_DBAR_EXP, -1, "[20]12", "", 0, "Input mode ignored",
"010010000010000101101111111100001010000010000110010101111100101110001011110000000010101111100001011101"
},
/*15*/ { BARCODE_DBAR_EXP, GS1_MODE, "[20]12", "", 0, "Input mode ignored",
/*19*/ { BARCODE_DBAR_EXP, GS1PARENS_MODE, "(20)12", "", 0, "Input mode ignored (parentheses instead of square brackets)",
"010010000010000101101111111100001010000010000110010101111100101110001011110000000010101111100001011101"
},
/*16*/ { BARCODE_DBAR_EXP, UNICODE_MODE, "[20]12", "", 0, "Input mode ignored",
/*20*/ { BARCODE_DBAR_EXP, GS1_MODE, "[20]12", "", 0, "Input mode ignored",
"010010000010000101101111111100001010000010000110010101111100101110001011110000000010101111100001011101"
},
/*17*/ { BARCODE_DBAR_EXP_CC, -1, "[20]12", "[21]1234", 0, "Input mode ignored; verified manually against tec-it",
/*21*/ { BARCODE_DBAR_EXP, GS1_MODE | GS1PARENS_MODE, "(20)12", "", 0, "Input mode ignored (parentheses instead of square brackets)",
"010010000010000101101111111100001010000010000110010101111100101110001011110000000010101111100001011101"
},
/*22*/ { BARCODE_DBAR_EXP, UNICODE_MODE, "[20]12", "", 0, "Input mode ignored",
"010010000010000101101111111100001010000010000110010101111100101110001011110000000010101111100001011101"
},
/*23*/ { BARCODE_DBAR_EXP_CC, -1, "[20]12", "[21]1234", 0, "Input mode ignored; verified manually against tec-it",
"001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010"
"001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010"
"001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010"
"000001111111010110010000000010100100111001100001011010000011010001110100001010101001010000011110100000"
"010010000000101001101111111100001011000110011110100101111100101110001011110000000010101111100001011101"
},
/*18*/ { BARCODE_DBAR_EXP_CC, GS1_MODE, "[20]12", "[21]1234", 0, "Input mode ignored",
/*24*/ { BARCODE_DBAR_EXP_CC, GS1_MODE, "[20]12", "[21]1234", 0, "Input mode ignored",
"001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010"
"001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010"
"001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010"
"000001111111010110010000000010100100111001100001011010000011010001110100001010101001010000011110100000"
"010010000000101001101111111100001011000110011110100101111100101110001011110000000010101111100001011101"
},
/*19*/ { BARCODE_DBAR_EXP_CC, UNICODE_MODE, "[20]12", "[21]1234", 0, "Input mode ignored",
/*25*/ { BARCODE_DBAR_EXP_CC, UNICODE_MODE, "[20]12", "[21]1234", 0, "Input mode ignored",
"001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010"
"001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010"
"001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010"
"000001111111010110010000000010100100111001100001011010000011010001110100001010101001010000011110100000"
"010010000000101001101111111100001011000110011110100101111100101110001011110000000010101111100001011101"
},
/*20*/ { BARCODE_DBAR_EXPSTK, -1, "12", "", ZINT_ERROR_INVALID_DATA, "GS1 data required", "" },
/*21*/ { BARCODE_DBAR_EXPSTK, -1, "[20]12", "", 0, "Input mode ignored",
/*26*/ { BARCODE_DBAR_EXPSTK, -1, "12", "", ZINT_ERROR_INVALID_DATA, "GS1 data required", "" },
/*27*/ { BARCODE_DBAR_EXPSTK, -1, "[20]12", "", 0, "Input mode ignored",
"010010000010000101101111111100001010000010000110010101111100101110001011110000000010101111100001011101"
},
/*22*/ { BARCODE_DBAR_EXPSTK, GS1_MODE, "[20]12", "", 0, "Input mode ignored",
/*28*/ { BARCODE_DBAR_EXPSTK, GS1_MODE, "[20]12", "", 0, "Input mode ignored",
"010010000010000101101111111100001010000010000110010101111100101110001011110000000010101111100001011101"
},
/*23*/ { BARCODE_DBAR_EXPSTK, UNICODE_MODE, "[20]12", "", 0, "Input mode ignored",
/*29*/ { BARCODE_DBAR_EXPSTK, UNICODE_MODE, "[20]12", "", 0, "Input mode ignored",
"010010000010000101101111111100001010000010000110010101111100101110001011110000000010101111100001011101"
},
/*24*/ { BARCODE_DBAR_EXPSTK_CC, -1, "12", "[21]1234", ZINT_ERROR_INVALID_DATA, "GS1 data required", "" },
/*25*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[20]12", "[21]1234", 0, "Input mode ignored; verified manually against tec-it (same as BARCODE_DBAR_EXP_CC above)",
/*30*/ { BARCODE_DBAR_EXPSTK_CC, -1, "12", "[21]1234", ZINT_ERROR_INVALID_DATA, "GS1 data required", "" },
/*31*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[20]12", "[21]1234", 0, "Input mode ignored; verified manually against tec-it (same as BARCODE_DBAR_EXP_CC above)",
"001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010"
"001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010"
"001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010"
"000001111111010110010000000010100100111001100001011010000011010001110100001010101001010000011110100000"
"010010000000101001101111111100001011000110011110100101111100101110001011110000000010101111100001011101"
},
/*26*/ { BARCODE_DBAR_EXPSTK_CC, GS1_MODE, "[20]12", "[21]1234", 0, "Input mode ignored",
/*32*/ { BARCODE_DBAR_EXPSTK_CC, GS1PARENS_MODE, "(20)12", "(21)1234", 0, "Input mode ignored (parentheses instead of square brackets)",
"001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010"
"001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010"
"001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010"
"000001111111010110010000000010100100111001100001011010000011010001110100001010101001010000011110100000"
"010010000000101001101111111100001011000110011110100101111100101110001011110000000010101111100001011101"
},
/*27*/ { BARCODE_DBAR_EXPSTK_CC, UNICODE_MODE, "[20]12", "[21]1234", 0, "Input mode ignored",
/*33*/ { BARCODE_DBAR_EXPSTK_CC, GS1_MODE, "[20]12", "[21]1234", 0, "Input mode ignored",
"001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010"
"001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010"
"001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010"
"000001111111010110010000000010100100111001100001011010000011010001110100001010101001010000011110100000"
"010010000000101001101111111100001011000110011110100101111100101110001011110000000010101111100001011101"
},
/*34*/ { BARCODE_DBAR_EXPSTK_CC, UNICODE_MODE, "[20]12", "[21]1234", 0, "Input mode ignored",
"001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010"
"001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010"
"001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010"
@ -1731,40 +1760,47 @@ static void test_input_mode(int index, int debug) {
struct item data[] = {
/* 0*/ { BARCODE_AZTEC, "[01]12345678901231", "", GS1_MODE, -1 , 0, 0 },
/* 1*/ { BARCODE_AZTEC, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, -1, 0, 1 },
/* 2*/ { BARCODE_AZTEC, "[01]12345678901231", "", GS1_MODE, READER_INIT, ZINT_ERROR_INVALID_OPTION, 0 },
/* 3*/ { BARCODE_AZTEC, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, READER_INIT, ZINT_ERROR_INVALID_OPTION, 0 },
/* 4*/ { BARCODE_AZTEC, "1234", "", GS1_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 5*/ { BARCODE_AZTEC, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 6*/ { BARCODE_CODABLOCKF, "[01]12345678901231", "", GS1_MODE, -1, ZINT_ERROR_INVALID_OPTION, 0 },
/* 7*/ { BARCODE_CODABLOCKF, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_OPTION, 0 },
/* 8*/ { BARCODE_CODABLOCKF, "1234", "", GS1_MODE, -1, ZINT_ERROR_INVALID_OPTION, 0 },
/* 9*/ { BARCODE_CODABLOCKF, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_OPTION, 0 },
/* 10*/ { BARCODE_CODEONE, "[01]12345678901231", "", GS1_MODE, -1, 0, 0 },
/* 11*/ { BARCODE_CODEONE, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, -1, 0, 1 },
/* 12*/ { BARCODE_CODEONE, "1234", "", GS1_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 13*/ { BARCODE_CODEONE, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 14*/ { BARCODE_CODE16K, "[01]12345678901231", "", GS1_MODE, -1, 0, 0 },
/* 15*/ { BARCODE_CODE16K, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, -1, 0, 1 },
/* 16*/ { BARCODE_CODE16K, "1234", "", GS1_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 17*/ { BARCODE_CODE16K, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 18*/ { BARCODE_CODE49, "[01]12345678901231", "", GS1_MODE, -1, 0, 0 },
/* 19*/ { BARCODE_CODE49, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, -1, 0, 1 },
/* 20*/ { BARCODE_CODE49, "1234", "", GS1_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 21*/ { BARCODE_CODE49, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 22*/ { BARCODE_DATAMATRIX, "[01]12345678901231", "", GS1_MODE, -1, 0, 0 },
/* 23*/ { BARCODE_DATAMATRIX, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, -1, 0, 1 },
/* 24*/ { BARCODE_DATAMATRIX, "[01]12345678901231", "", GS1_MODE, READER_INIT, ZINT_ERROR_INVALID_OPTION, 0 },
/* 25*/ { BARCODE_DATAMATRIX, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, READER_INIT, ZINT_ERROR_INVALID_OPTION, 0 },
/* 26*/ { BARCODE_DATAMATRIX, "1234", "", GS1_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 27*/ { BARCODE_DATAMATRIX, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 28*/ { BARCODE_DOTCODE, "[01]12345678901231", "", GS1_MODE, -1, 0, 0 },
/* 29*/ { BARCODE_DOTCODE, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, -1, 0, 1 },
/* 30*/ { BARCODE_DOTCODE, "1234", "", GS1_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 31*/ { BARCODE_DOTCODE, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 32*/ { BARCODE_QRCODE, "[01]12345678901231", "", GS1_MODE, -1, 0, 0 },
/* 33*/ { BARCODE_QRCODE, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, -1, 0, 1 },
/* 34*/ { BARCODE_QRCODE, "1234", "", GS1_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 35*/ { BARCODE_QRCODE, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 2*/ { BARCODE_AZTEC, "(01)12345678901231", "", GS1_MODE | ESCAPE_MODE | GS1PARENS_MODE, -1, 0, 1 },
/* 3*/ { BARCODE_AZTEC, "[01]12345678901231", "", GS1_MODE, READER_INIT, ZINT_ERROR_INVALID_OPTION, 0 },
/* 4*/ { BARCODE_AZTEC, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, READER_INIT, ZINT_ERROR_INVALID_OPTION, 0 },
/* 5*/ { BARCODE_AZTEC, "1234", "", GS1_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 6*/ { BARCODE_AZTEC, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 7*/ { BARCODE_CODABLOCKF, "[01]12345678901231", "", GS1_MODE, -1, ZINT_ERROR_INVALID_OPTION, 0 },
/* 8*/ { BARCODE_CODABLOCKF, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_OPTION, 0 },
/* 9*/ { BARCODE_CODABLOCKF, "1234", "", GS1_MODE, -1, ZINT_ERROR_INVALID_OPTION, 0 },
/* 10*/ { BARCODE_CODABLOCKF, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_OPTION, 0 },
/* 11*/ { BARCODE_CODEONE, "[01]12345678901231", "", GS1_MODE, -1, 0, 0 },
/* 12*/ { BARCODE_CODEONE, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, -1, 0, 1 },
/* 13*/ { BARCODE_CODEONE, "(01)12345678901231", "", GS1_MODE | ESCAPE_MODE | GS1PARENS_MODE, -1, 0, 1 },
/* 14*/ { BARCODE_CODEONE, "1234", "", GS1_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 15*/ { BARCODE_CODEONE, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 16*/ { BARCODE_CODE16K, "[01]12345678901231", "", GS1_MODE, -1, 0, 0 },
/* 17*/ { BARCODE_CODE16K, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, -1, 0, 1 },
/* 18*/ { BARCODE_CODE16K, "(01)12345678901231", "", GS1_MODE | ESCAPE_MODE | GS1PARENS_MODE, -1, 0, 1 },
/* 19*/ { BARCODE_CODE16K, "1234", "", GS1_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 20*/ { BARCODE_CODE16K, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 21*/ { BARCODE_CODE49, "[01]12345678901231", "", GS1_MODE, -1, 0, 0 },
/* 22*/ { BARCODE_CODE49, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, -1, 0, 1 },
/* 23*/ { BARCODE_CODE49, "(01)12345678901231", "", GS1_MODE | ESCAPE_MODE | GS1PARENS_MODE, -1, 0, 1 },
/* 24*/ { BARCODE_CODE49, "1234", "", GS1_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 25*/ { BARCODE_CODE49, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 26*/ { BARCODE_DATAMATRIX, "[01]12345678901231", "", GS1_MODE, -1, 0, 0 },
/* 27*/ { BARCODE_DATAMATRIX, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, -1, 0, 1 },
/* 28*/ { BARCODE_DATAMATRIX, "(01)12345678901231", "", GS1_MODE | ESCAPE_MODE | GS1PARENS_MODE, -1, 0, 1 },
/* 29*/ { BARCODE_DATAMATRIX, "[01]12345678901231", "", GS1_MODE, READER_INIT, ZINT_ERROR_INVALID_OPTION, 0 },
/* 30*/ { BARCODE_DATAMATRIX, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, READER_INIT, ZINT_ERROR_INVALID_OPTION, 0 },
/* 31*/ { BARCODE_DATAMATRIX, "1234", "", GS1_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 32*/ { BARCODE_DATAMATRIX, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 33*/ { BARCODE_DOTCODE, "[01]12345678901231", "", GS1_MODE, -1, 0, 0 },
/* 34*/ { BARCODE_DOTCODE, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, -1, 0, 1 },
/* 35*/ { BARCODE_DOTCODE, "(01)12345678901231", "", GS1_MODE | ESCAPE_MODE | GS1PARENS_MODE, -1, 0, 1 },
/* 36*/ { BARCODE_DOTCODE, "1234", "", GS1_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 37*/ { BARCODE_DOTCODE, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 38*/ { BARCODE_QRCODE, "[01]12345678901231", "", GS1_MODE, -1, 0, 0 },
/* 39*/ { BARCODE_QRCODE, "[01]12345678901231", "", GS1_MODE | ESCAPE_MODE, -1, 0, 1 },
/* 40*/ { BARCODE_QRCODE, "(01)12345678901231", "", GS1_MODE | ESCAPE_MODE | GS1PARENS_MODE, -1, 0, 1 },
/* 41*/ { BARCODE_QRCODE, "1234", "", GS1_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
/* 42*/ { BARCODE_QRCODE, "1234", "", GS1_MODE | ESCAPE_MODE, -1, ZINT_ERROR_INVALID_DATA, 0 },
};
int data_size = ARRAY_SIZE(data);

View file

@ -233,7 +233,7 @@ static void test_encode(int index, int generate, int debug) {
char *expected;
};
struct item data[] = {
/* 0*/ { -1, -1, -1, "THIS IS A 93 CHARACTER CODE SET A MESSAGE THAT FILLS A MODE 4, UNAPPENDED, MAXICODE SYMBOL...", -1, "", 0, 33, 30, 1, "ISO/IEC 16023:2000 Figure 2, same",
/* 0*/ { -1, -1, -1, "THIS IS A 93 CHARACTER CODE SET A MESSAGE THAT FILLS A MODE 4, UNAPPENDED, MAXICODE SYMBOL...", -1, "", 0, 33, 30, 1, "ISO/IEC 16023:2000 Figure 2 (and L1), same",
"011111010000001000001000100111"
"000100000001000000001010000000"
"001011001100100110110010010010"

View file

@ -316,22 +316,25 @@ static void test_qr_gs1(int index, int generate, int debug) {
int ret;
struct item {
int input_mode;
char *data;
int ret;
char *expected;
char *comment;
};
struct item data[] = {
/* 0*/ { "[01]12345678901231", 0, "51 04 00 B3 AA 37 DE 87 B1", "N16" },
/* 1*/ { "[01]04912345123459[15]970331[30]128[10]ABC123", 0, "51 07 40 A7 AC EA 80 15 9E 4F CA 52 D2 D3 84 09 D5 E0 28 FD 82 F0 C0 EC 11 EC 11 EC", "N29 A9" },
/* 2*/ { "[91]12%[20]12", 0, "52 05 99 60 5F B5 35 80 01 08 00 EC 11", "A10(11)" },
/* 3*/ { "[91]123%[20]12", 0, "52 06 19 60 5E 2B 76 A0 5A 05 E0 EC 11", "A11(12)" },
/* 4*/ { "[91]1234%[20]12", 0, "52 06 99 60 5E 22 F6 A6 B0 00 21 00 EC", "A12(13)" },
/* 5*/ { "[91]12345%[20]12", 0, "51 01 F8 F3 A9 48 0F B5 35 80 01 08 00", "N7 A6(7) (same bit count as A13(14))" },
/* 6*/ { "[91]%%[20]12", 0, "52 05 99 6D A9 B5 35 80 01 08 00 EC 11", "A9(11)" },
/* 7*/ { "[91]%%%[20]12", 0, "52 06 99 6D A9 B5 36 A6 B0 00 21 00 EC", "A10(13)" },
/* 8*/ { "[91]A%%%%1234567890123AA%", 0, "52 05 99 63 D1 B5 36 A6 D4 98 40 D1 ED C8 C5 40 C3 20 21 CC DA 80", "A7(11) N13 A3(4)" },
/* 9*/ { "[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)" },
/* 0*/ { GS1_MODE, "[01]12345678901231", 0, "51 04 00 B3 AA 37 DE 87 B1", "N16" },
/* 1*/ { GS1_MODE | GS1PARENS_MODE, "(01)12345678901231", 0, "51 04 00 B3 AA 37 DE 87 B1", "N16" },
/* 2*/ { GS1_MODE, "[01]04912345123459[15]970331[30]128[10]ABC123", 0, "51 07 40 A7 AC EA 80 15 9E 4F CA 52 D2 D3 84 09 D5 E0 28 FD 82 F0 C0 EC 11 EC 11 EC", "N29 A9" },
/* 3*/ { GS1_MODE | GS1PARENS_MODE, "(01)04912345123459(15)970331(30)128(10)ABC123", 0, "51 07 40 A7 AC EA 80 15 9E 4F CA 52 D2 D3 84 09 D5 E0 28 FD 82 F0 C0 EC 11 EC 11 EC", "N29 A9" },
/* 4*/ { GS1_MODE, "[91]12%[20]12", 0, "52 05 99 60 5F B5 35 80 01 08 00 EC 11", "A10(11)" },
/* 5*/ { GS1_MODE, "[91]123%[20]12", 0, "52 06 19 60 5E 2B 76 A0 5A 05 E0 EC 11", "A11(12)" },
/* 6*/ { GS1_MODE, "[91]1234%[20]12", 0, "52 06 99 60 5E 22 F6 A6 B0 00 21 00 EC", "A12(13)" },
/* 7*/ { GS1_MODE, "[91]12345%[20]12", 0, "51 01 F8 F3 A9 48 0F B5 35 80 01 08 00", "N7 A6(7) (same bit count as A13(14))" },
/* 8*/ { GS1_MODE, "[91]%%[20]12", 0, "52 05 99 6D A9 B5 35 80 01 08 00 EC 11", "A9(11)" },
/* 9*/ { GS1_MODE, "[91]%%%[20]12", 0, "52 06 99 6D A9 B5 36 A6 B0 00 21 00 EC", "A10(13)" },
/* 10*/ { GS1_MODE, "[91]A%%%%1234567890123AA%", 0, "52 05 99 63 D1 B5 36 A6 D4 98 40 D1 ED C8 C5 40 C3 20 21 CC DA 80", "A7(11) N13 A3(4)" },
/* 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);
@ -347,14 +350,14 @@ static void test_qr_gs1(int index, int generate, int debug) {
debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
int length = testUtilSetSymbol(symbol, BARCODE_QRCODE, GS1_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
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);
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);
if (generate) {
printf(" /*%3d*/ { \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
printf(" /*%3d*/ { %s, \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
} else {
if (ret < ZINT_ERROR) {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
@ -2494,23 +2497,26 @@ static void test_rmqr_gs1(int index, int generate, int debug) {
int ret;
struct item {
int input_mode;
char *data;
int ret;
char *expected;
char *comment;
};
struct item data[] = {
/* 0*/ { "[01]12345678901231", 0, "A6 00 59 D5 1B EF 43 D8 80 EC 11 EC", "N16" },
/* 1*/ { "[01]04912345123459[15]970331[30]128[10]ABC123", 0, "A5 D0 29 EB 3A A0 05 67 93 F2 94 B4 B4 E2 4E AF 01 47 EC 17 86", "N29 A9" },
/* 2*/ { "[91]12%[20]12", 0, "A4 9C 79 32 25 1D 24 32 48 00 EC 11", "N4 B2 N4" },
/* 3*/ { "[91]123%[20]12", 0, "A4 BC 79 74 3D A9 31 21 92 40 EC 11", "N5 A2 N4" },
/* 4*/ { "[91]1234%[20]12", 0, "A4 DC 79 D4 C8 94 74 90 C9 20 EC 11", "N6 B2 N4" },
/* 5*/ { "[91]12345%[20]12", 0, "A4 FC 79 D4 A8 7B 52 62 43 24 80 EC", "N7 A2(3) N4" },
/* 6*/ { "[91]1A%[20]12", 0, "A8 E6 58 1B ED 49 89 0C 92 00 EC 11", "A6(7) N4" },
/* 7*/ { "[91]%%[20]12", 0, "A4 56 D9 92 92 8E 92 19 24 00 EC 11", "N2 B3 N4" },
/* 8*/ { "[91]%%%[20]12", 0, "A4 56 DA 12 92 92 8E 92 19 24 00 EC", "N2 B4 N4" },
/* 9*/ { "[91]A%%%%12345678A%A", 0, "A8 A6 58 F4 4C C6 4A 4A 4A 48 1E DC 89 C8 87 A3 5C 00 EC", "A4(5) B3 N8 A3(4)" },
/* 10*/ { "[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" },
/* 0*/ { GS1_MODE, "[01]12345678901231", 0, "A6 00 59 D5 1B EF 43 D8 80 EC 11 EC", "N16" },
/* 1*/ { GS1_MODE | GS1PARENS_MODE, "(01)12345678901231", 0, "A6 00 59 D5 1B EF 43 D8 80 EC 11 EC", "N16" },
/* 2*/ { GS1_MODE, "[01]04912345123459[15]970331[30]128[10]ABC123", 0, "A5 D0 29 EB 3A A0 05 67 93 F2 94 B4 B4 E2 4E AF 01 47 EC 17 86", "N29 A9" },
/* 3*/ { GS1_MODE | GS1PARENS_MODE, "(01)04912345123459(15)970331(30)128(10)ABC123", 0, "A5 D0 29 EB 3A A0 05 67 93 F2 94 B4 B4 E2 4E AF 01 47 EC 17 86", "N29 A9" },
/* 4*/ { GS1_MODE, "[91]12%[20]12", 0, "A4 9C 79 32 25 1D 24 32 48 00 EC 11", "N4 B2 N4" },
/* 5*/ { GS1_MODE, "[91]123%[20]12", 0, "A4 BC 79 74 3D A9 31 21 92 40 EC 11", "N5 A2 N4" },
/* 6*/ { GS1_MODE, "[91]1234%[20]12", 0, "A4 DC 79 D4 C8 94 74 90 C9 20 EC 11", "N6 B2 N4" },
/* 7*/ { GS1_MODE, "[91]12345%[20]12", 0, "A4 FC 79 D4 A8 7B 52 62 43 24 80 EC", "N7 A2(3) N4" },
/* 8*/ { GS1_MODE, "[91]1A%[20]12", 0, "A8 E6 58 1B ED 49 89 0C 92 00 EC 11", "A6(7) N4" },
/* 9*/ { GS1_MODE, "[91]%%[20]12", 0, "A4 56 D9 92 92 8E 92 19 24 00 EC 11", "N2 B3 N4" },
/* 10*/ { GS1_MODE, "[91]%%%[20]12", 0, "A4 56 DA 12 92 92 8E 92 19 24 00 EC", "N2 B4 N4" },
/* 11*/ { GS1_MODE, "[91]A%%%%12345678A%A", 0, "A8 A6 58 F4 4C C6 4A 4A 4A 48 1E DC 89 C8 87 A3 5C 00 EC", "A4(5) B3 N8 A3(4)" },
/* 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);
@ -2525,14 +2531,14 @@ static void test_rmqr_gs1(int index, int generate, int debug) {
debug |= ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
int length = testUtilSetSymbol(symbol, BARCODE_RMQR, GS1_MODE, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
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);
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);
if (generate) {
printf(" /*%3d*/ { \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
printf(" /*%3d*/ { %s, \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->errtxt, data[i].comment);
} else {
if (ret < ZINT_ERROR) {
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);

View file

@ -140,15 +140,16 @@ static void test_input(int index, int generate, int debug) {
/* 33*/ { 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", "Mode: a (34); Figure G.6 uses C43 for 6 of last 7 chars (same codeword count)" },
/* 34*/ { 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", "Mode: a (35)" },
/* 35*/ { GS1_MODE, 0, -1, -1, "[17]120508[10]ABCDEFGHI[410]9501101020917", 0, "(24) 273 145 140 133 136 138 65 66 67 68 69 70 71 72 73 272 169 137 178 139 129 130 137 145", "Mode: a (36)" },
/* 36*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "ftp://", 0, "(4) 272 278 269 165", "Mode: c (6)" },
/* 37*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, ".cgi", 0, "(4) 272 278 274 131", "Mode: c (4)" },
/* 38*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "ftp://a.cgi", 0, "(6) 272 280 269 123 274 131", "Mode: c (11)" },
/* 39*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "e: file:f.shtml !", 0, "(12) 272 280 30 94 236 235 72 233 39 52 267 250", "Mode: c (17)" },
/* 40*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "Aaatel:", 0, "(6) 272 280 262 76 6 89", "Mode: c (7)" },
/* 41*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "Aatel:a", 0, "(6) 272 280 262 76 271 161", "Mode: c (7)" },
/* 42*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "Atel:aAa", 0, "(8) 272 275 6 89 275 148 0 42", "Mode: c (8)" },
/* 43*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "tel:AAaa", 0, "(8) 272 275 271 161 6 28 262 118", "Mode: c (8)" },
/* 44*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "AAaatel:aA", 0, "(10) 272 276 0 42 0 41 118 46 6 156", "Mode: c (10)" },
/* 36*/ { GS1_MODE | GS1PARENS_MODE, 0, -1, -1, "(17)120508(10)ABCDEFGHI(410)9501101020917", 0, "(24) 273 145 140 133 136 138 65 66 67 68 69 70 71 72 73 272 169 137 178 139 129 130 137 145", "Mode: a (36)" },
/* 37*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "ftp://", 0, "(4) 272 278 269 165", "Mode: c (6)" },
/* 38*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, ".cgi", 0, "(4) 272 278 274 131", "Mode: c (4)" },
/* 39*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "ftp://a.cgi", 0, "(6) 272 280 269 123 274 131", "Mode: c (11)" },
/* 40*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "e: file:f.shtml !", 0, "(12) 272 280 30 94 236 235 72 233 39 52 267 250", "Mode: c (17)" },
/* 41*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "Aaatel:", 0, "(6) 272 280 262 76 6 89", "Mode: c (7)" },
/* 42*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "Aatel:a", 0, "(6) 272 280 262 76 271 161", "Mode: c (7)" },
/* 43*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "Atel:aAa", 0, "(8) 272 275 6 89 275 148 0 42", "Mode: c (8)" },
/* 44*/ { UNICODE_MODE, 0, -1, ULTRA_COMPRESSION, "tel:AAaa", 0, "(8) 272 275 271 161 6 28 262 118", "Mode: c (8)" },
/* 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);

View file

@ -40,6 +40,7 @@
#include <zlib.h>
#include <setjmp.h>
#endif
#include <assert.h>
#include <limits.h>
#include <unistd.h>
#include <errno.h>
@ -452,34 +453,51 @@ const char *testUtilErrorName(int error_number) {
}
const char *testUtilInputModeName(int input_mode) {
static char buf[512];
struct item {
const char *name;
int define;
int val;
};
static const 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 },
{ "ESCAPE_MODE", ESCAPE_MODE, 8 },
{ "GS1PARENS_MODE", GS1PARENS_MODE, 16 },
};
static const int data_size = sizeof(data) / sizeof(struct item);
static const int data_size = ARRAY_SIZE(data);
int set, i;
if (input_mode < 0 || input_mode >= data_size) {
return input_mode == -1 ? "-1" : "";
if (input_mode < 0) {
return "-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);
buf[0] = '\0';
if ((input_mode & 0x7) & UNICODE_MODE) {
strcpy(buf, "UNICODE_MODE");
set = UNICODE_MODE;
} else if ((input_mode & 0x7) & GS1_MODE) {
strcpy(buf, "GS1_MODE");
set = GS1_MODE;
} else {
set = DATA_MODE;
}
for (i = 0; i < data_size; i++) {
if (data[i].define != data[i].val) { // Self-check
fprintf(stderr, "testUtilInputModeName: data table out of sync (%d)\n", i);
abort();
}
if (input_mode & data[i].define) {
if (*buf) {
strcat(buf, " | ");
}
strcat(buf, data[i].name);
set |= data[i].define;
}
}
if (set != input_mode) {
fprintf(stderr, "testUtilInputModeName: unknown input mode %d (%d)\n", input_mode & set, input_mode);
abort();
}
return data[input_mode].name;
return buf;
}
const char *testUtilOption3Name(int option_3) {
@ -720,6 +738,7 @@ 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;
@ -742,6 +761,7 @@ struct zint_vector *testUtilVectorCpy(const struct zint_vector *in) {
outrect = &(out->rectangles);
while (rect) {
*outrect = malloc(sizeof(struct zint_vector_rect));
assert(*outrect != NULL);
memcpy(*outrect, rect, sizeof(struct zint_vector_rect));
outrect = &((*outrect)->next);
rect = rect->next;
@ -753,8 +773,10 @@ struct zint_vector *testUtilVectorCpy(const struct zint_vector *in) {
outstring = &(out->strings);
while (string) {
*outstring = malloc(sizeof(struct zint_vector_string));
assert(*outstring != NULL);
memcpy(*outstring, string, sizeof(struct zint_vector_string));
(*outstring)->text = malloc(sizeof(unsigned char) * (ustrlen(string->text) + 1));
assert((*outstring)->text != NULL);
ustrcpy((*outstring)->text, string->text);
outstring = &((*outstring)->next);
string = string->next;
@ -766,6 +788,7 @@ struct zint_vector *testUtilVectorCpy(const struct zint_vector *in) {
outcircle = &(out->circles);
while (circle) {
*outcircle = malloc(sizeof(struct zint_vector_circle));
assert(*outcircle != NULL);
memcpy(*outcircle, circle, sizeof(struct zint_vector_circle));
outcircle = &((*outcircle)->next);
circle = circle->next;
@ -777,6 +800,7 @@ struct zint_vector *testUtilVectorCpy(const struct zint_vector *in) {
outhexagon = &(out->hexagons);
while (hexagon) {
*outhexagon = malloc(sizeof(struct zint_vector_hexagon));
assert(*outhexagon != NULL);
memcpy(*outhexagon, hexagon, sizeof(struct zint_vector_hexagon));
outhexagon = &((*outhexagon)->next);
hexagon = hexagon->next;
@ -2094,6 +2118,8 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
int upcean = is_extendable(symbology);
int upca = symbology == BARCODE_UPCA || symbology == BARCODE_UPCA_CHK || symbology == BARCODE_UPCA_CC;
char obracket = symbol->input_mode & GS1PARENS_MODE ? '(' : '[';
char cbracket = symbol->input_mode & GS1PARENS_MODE ? ')' : ']';
int addon_posn;
int eci;
@ -2146,7 +2172,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
fprintf(stderr, "i:%d testUtilBwipp: no primary data given %s\n", index, testUtilBarcodeName(symbology));
return -1;
}
if (*primary != '[' && !upcean) {
if (*primary != obracket && !upcean) {
strcat(bwipp_data, "(01)");
}
strcat(bwipp_data, primary);
@ -2175,7 +2201,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
}
} else {
if (gs1_cvt) {
if (*data != '[' && !upcean) {
if (*data != obracket && !upcean) {
strcat(bwipp_data, symbology == BARCODE_NVE18 ? "(00)" : "(01)");
}
strcat(bwipp_data, data);
@ -2355,7 +2381,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
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) */
if (bwipp_data[i] == '[') {
if (bwipp_data[i] == obracket) {
if (ai_latch == 0) {
bwipp_data[j++] = '[';
}
@ -2363,7 +2389,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
if ((last_ai >= 0 && last_ai <= 4) || (last_ai >= 11 && last_ai <= 20) || last_ai == 23 || (last_ai >= 31 && last_ai <= 36) || last_ai == 41) {
ai_latch = 1;
}
} else if (bwipp_data[i] != ']') {
} else if (bwipp_data[i] != cbracket) {
bwipp_data[j++] = bwipp_data[i];
}
}

View file

@ -43,6 +43,7 @@
#include "common.h"
#include "output.h"
#include "zfiletypes.h"
INTERNAL int ps_plot(struct zint_symbol *symbol);
INTERNAL int svg_plot(struct zint_symbol *symbol);

48
backend/zfiletypes.h Normal file
View file

@ -0,0 +1,48 @@
/* filetypes.h - file type flags
libzint - the open source barcode library
Copyright (C) 2021 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 : */
#ifndef ZFILETYPES_H
#define ZFILETYPES_H
// File types
#define OUT_BUFFER 0
#define OUT_SVG_FILE 10
#define OUT_EPS_FILE 20
#define OUT_EMF_FILE 30
#define OUT_PNG_FILE 100
#define OUT_BMP_FILE 120
#define OUT_GIF_FILE 140
#define OUT_PCX_FILE 160
#define OUT_JPG_FILE 180
#define OUT_TIF_FILE 200
#endif /* ZFILETYPES_H */

View file

@ -75,14 +75,14 @@ extern "C" {
struct zint_symbol {
int symbology;
int height;
int whitespace_width;
int border_width;
int height; /* Height in X-dims (ignored for fixed-width barcodes) */
int whitespace_width; /* Width in X-dims of whitespace to left/right of barcode */
int border_width; /* Size of border in X-dims */
int output_options;
char fgcolour[10];
char *fgcolor; // pointer to fgcolour
char bgcolour[10];
char *bgcolor; // pointer to bgcolour
char fgcolour[10]; /* Foreground as RGB/RGBA hexadecimal string */
char bgcolour[10]; /* Background as RGB/RGBA hexadecimal string */
char *fgcolor; /* Pointer to fgcolour */
char *bgcolor; /* Pointer to bgcolour */
char outfile[256];
float scale;
int option_1;
@ -110,6 +110,7 @@ extern "C" {
int warn_level;
};
// Symbologies (symbology)
/* Tbarcode 7 codes */
#define BARCODE_CODE11 1
#define BARCODE_C25STANDARD 2
@ -234,7 +235,7 @@ extern "C" {
#define BARCODE_ULTRA 144
#define BARCODE_RMQR 145
// Output options
// Output options (output_options)
#define BARCODE_NO_ASCII 1
#define BARCODE_BIND 2
#define BARCODE_BOX 4
@ -247,11 +248,12 @@ extern "C" {
#define GS1_GS_SEPARATOR 512
#define OUT_BUFFER_INTERMEDIATE 1024
// Input data types
// Input data types (input_mode)
#define DATA_MODE 0
#define UNICODE_MODE 1
#define GS1_MODE 2
#define ESCAPE_MODE 8
#define GS1PARENS_MODE 16
// Data Matrix specific options (option_3)
#define DM_SQUARE 100
@ -263,7 +265,7 @@ extern "C" {
// Ultracode specific option (option_3)
#define ULTRA_COMPRESSION 128
// Warning and error conditions
// Warning and error conditions (return values)
#define ZINT_WARN_INVALID_OPTION 2
#define ZINT_WARN_USES_ECI 3
#define ZINT_WARN_NONCOMPLIANT 4
@ -277,24 +279,12 @@ extern "C" {
#define ZINT_ERROR_MEMORY 11
#define ZINT_ERROR_FILE_WRITE 12
// File types
#define OUT_BUFFER 0
#define OUT_SVG_FILE 10
#define OUT_EPS_FILE 20
#define OUT_EMF_FILE 30
#define OUT_PNG_FILE 100
#define OUT_BMP_FILE 120
#define OUT_GIF_FILE 140
#define OUT_PCX_FILE 160
#define OUT_JPG_FILE 180
#define OUT_TIF_FILE 200
// Warning warn
// Warning warn (warn_level)
#define WARN_DEFAULT 0
#define WARN_ZPL_COMPAT 1
#define WARN_FAIL_ALL 2
// Capability flags
// Capability flags (cap_flag)
#define ZINT_CAP_HRT 0x0001
#define ZINT_CAP_STACKABLE 0x0002
#define ZINT_CAP_EXTENDABLE 0x0004
@ -310,7 +300,7 @@ extern "C" {
// The largest amount of data that can be encoded is 4350 4-byte UTF-8 chars in Han Xin Code
#define ZINT_MAX_DATA_LEN 17400
// Debug flags
// Debug flags (debug)
#define ZINT_DEBUG_PRINT 1
#define ZINT_DEBUG_TEST 2
@ -333,15 +323,19 @@ extern "C" {
ZINT_EXTERN int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int in_length);
ZINT_EXTERN int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename);
ZINT_EXTERN int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle);
ZINT_EXTERN int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle);
ZINT_EXTERN int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length,
int rotate_angle);
ZINT_EXTERN int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, char *filename, int rotate_angle);
ZINT_EXTERN int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle);
ZINT_EXTERN int ZBarcode_Buffer_Vector(struct zint_symbol *symbol, int rotate_angle);
ZINT_EXTERN int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle);
ZINT_EXTERN int ZBarcode_Encode_and_Buffer_Vector(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle);
ZINT_EXTERN int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input, int length,
int rotate_angle);
ZINT_EXTERN int ZBarcode_Encode_and_Buffer_Vector(struct zint_symbol *symbol, unsigned char *input, int length,
int rotate_angle);
ZINT_EXTERN int ZBarcode_Encode_File_and_Buffer(struct zint_symbol *symbol, char *filename, int rotate_angle);
ZINT_EXTERN int ZBarcode_Encode_File_and_Buffer_Vector(struct zint_symbol *symbol, char *filename, int rotate_angle);
ZINT_EXTERN int ZBarcode_Encode_File_and_Buffer_Vector(struct zint_symbol *symbol, char *filename,
int rotate_angle);
ZINT_EXTERN int ZBarcode_ValidID(int symbol_id);
ZINT_EXTERN unsigned int ZBarcode_Cap(int symbol_id, unsigned int cap_flag);