Uses general_field_encode in rss_binary_string; min 4 chars; bottom separator

This commit is contained in:
gitlost 2019-10-31 02:01:42 +00:00
parent 0fe9051324
commit 1dd4b08986
6 changed files with 483 additions and 397 deletions

View File

@ -90,7 +90,7 @@ static int general_field_next_none(char* general_field, int i, int general_field
} }
/* Attempts to apply encoding rules from sections 7.2.5.5.1 to 7.2.5.5.3 /* Attempts to apply encoding rules from sections 7.2.5.5.1 to 7.2.5.5.3
* of ISO/IEC 24724:2010 (same as sections 5.4.1 to 5.4.3 of ISO/IEC 24723:2010) */ * of ISO/IEC 24724:2011 (same as sections 5.4.1 to 5.4.3 of ISO/IEC 24723:2010) */
int general_field_encode(char* general_field, int* p_mode, int* p_last_digit, char binary_string[]) { int general_field_encode(char* general_field, int* p_mode, int* p_last_digit, char binary_string[]) {
int i, d1, d2; int i, d1, d2;
int mode = *p_mode; int mode = *p_mode;

View File

@ -73,6 +73,7 @@
#include "large.h" #include "large.h"
#include "rss.h" #include "rss.h"
#include "gs1.h" #include "gs1.h"
#include "general_field.h"
/********************************************************************** /**********************************************************************
* combins(n,r): returns the number of Combinations of r selected from n: * combins(n,r): returns the number of Combinations of r selected from n:
@ -1056,132 +1057,14 @@ int rsslimited(struct zint_symbol *symbol, unsigned char source[], int src_len)
return error_number; return error_number;
} }
/* Attempts to apply encoding rules from secions 7.2.5.5.1 to 7.2.5.5.3
* of ISO/IEC 24724:2006 */
int general_rules(char type[]) {
int block[2][200], block_count, i, j, k;
char current;
block_count = 0;
block[0][block_count] = 1;
block[1][block_count] = type[0];
for (i = 1; i < strlen(type); i++) {
char last;
current = type[i];
last = type[i - 1];
if (current == last) {
block[0][block_count] = block[0][block_count] + 1;
} else {
block_count++;
block[0][block_count] = 1;
block[1][block_count] = type[i];
}
}
block_count++;
for (i = 0; i < block_count; i++) {
char next;
current = block[1][i];
next = (block[1][i + 1] & 0xFF);
if ((current == ISOIEC) && (i != (block_count - 1))) {
if ((next == ANY_ENC) && (block[0][i + 1] >= 4)) {
block[1][i + 1] = NUMERIC;
}
if ((next == ANY_ENC) && (block[0][i + 1] < 4)) {
block[1][i + 1] = ISOIEC;
}
if ((next == ALPHA_OR_ISO) && (block[0][i + 1] >= 5)) {
block[1][i + 1] = ALPHA;
}
if ((next == ALPHA_OR_ISO) && (block[0][i + 1] < 5)) {
block[1][i + 1] = ISOIEC;
}
}
if (current == ALPHA_OR_ISO) {
block[1][i] = ALPHA;
current = ALPHA;
}
if ((current == ALPHA) && (i != (block_count - 1))) {
if ((next == ANY_ENC) && (block[0][i + 1] >= 6)) {
block[1][i + 1] = NUMERIC;
}
if ((next == ANY_ENC) && (block[0][i + 1] < 6)) {
if ((i == block_count - 2) && (block[0][i + 1] >= 4)) {
block[1][i + 1] = NUMERIC;
} else {
block[1][i + 1] = ALPHA;
}
}
}
if (current == ANY_ENC) {
block[1][i] = NUMERIC;
}
}
if (block_count > 1) {
i = 1;
while (i < block_count) {
if (block[1][i - 1] == block[1][i]) {
/* bring together */
block[0][i - 1] = block[0][i - 1] + block[0][i];
j = i + 1;
/* decreace the list */
while (j < block_count) {
block[0][j - 1] = block[0][j];
block[1][j - 1] = block[1][j];
j++;
}
block_count--;
i--;
}
i++;
}
}
for (i = 0; i < block_count - 1; i++) {
if ((block[1][i] == NUMERIC) && (block[0][i] & 1)) {
/* Odd size numeric block */
block[0][i] = block[0][i] - 1;
block[0][i + 1] = block[0][i + 1] + 1;
}
}
j = 0;
for (i = 0; i < block_count; i++) {
for (k = 0; k < block[0][i]; k++) {
type[j] = block[1][i];
j++;
}
}
if ((block[1][block_count - 1] == NUMERIC) && (block[0][block_count - 1] & 1)) {
/* If the last block is numeric and an odd size, further
processing needs to be done outside this procedure */
return 1;
} else {
return 0;
}
}
/* Handles all data encodation from section 7.2.5 of ISO/IEC 24724 */ /* Handles all data encodation from section 7.2.5 of ISO/IEC 24724 */
int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_string[]) { int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_string[]) {
int encoding_method, i, j, read_posn, latch, debug = symbol->debug, last_mode = ISOIEC; int encoding_method, i, j, read_posn, last_digit, debug = symbol->debug, mode = NUMERIC;
int symbol_characters, characters_per_row; int symbol_characters, characters_per_row;
#ifndef _MSC_VER #ifndef _MSC_VER
char general_field[strlen(source) + 1], general_field_type[strlen(source) + 1]; char general_field[strlen(source) + 1];
#else #else
char* general_field = (char*) _alloca(strlen(source) + 1); char* general_field = (char*) _alloca(strlen(source) + 1);
char* general_field_type = (char*) _alloca(strlen(source) + 1);
#endif #endif
int remainder, d1, d2; int remainder, d1, d2;
char padstring[40]; char padstring[40];
@ -1507,231 +1390,11 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
general_field[j] = '\0'; general_field[j] = '\0';
if (debug) printf("General field data = %s\n", general_field); if (debug) printf("General field data = %s\n", general_field);
latch = 0; if (!general_field_encode(general_field, &mode, &last_digit, binary_string)) {
for (i = 0; i < strlen(general_field); i++) {
/* Table 13 - ISO/IEC 646 encodation */
if ((general_field[i] < ' ') || (general_field[i] > 'z')) {
general_field_type[i] = INVALID_CHAR;
latch = 1;
} else {
general_field_type[i] = ISOIEC;
}
if (general_field[i] == '#') {
general_field_type[i] = INVALID_CHAR;
latch = 1;
}
if (general_field[i] == '$') {
general_field_type[i] = INVALID_CHAR;
latch = 1;
}
if (general_field[i] == '@') {
general_field_type[i] = INVALID_CHAR;
latch = 1;
}
if (general_field[i] == 92) {
general_field_type[i] = INVALID_CHAR;
latch = 1;
}
if (general_field[i] == '^') {
general_field_type[i] = INVALID_CHAR;
latch = 1;
}
if (general_field[i] == 96) {
general_field_type[i] = INVALID_CHAR;
latch = 1;
}
/* Table 12 - Alphanumeric encodation */
if ((general_field[i] >= 'A') && (general_field[i] <= 'Z')) {
general_field_type[i] = ALPHA_OR_ISO;
}
if (general_field[i] == '*') {
general_field_type[i] = ALPHA_OR_ISO;
}
if (general_field[i] == ',') {
general_field_type[i] = ALPHA_OR_ISO;
}
if (general_field[i] == '-') {
general_field_type[i] = ALPHA_OR_ISO;
}
if (general_field[i] == '.') {
general_field_type[i] = ALPHA_OR_ISO;
}
if (general_field[i] == '/') {
general_field_type[i] = ALPHA_OR_ISO;
}
/* Numeric encodation */
if ((general_field[i] >= '0') && (general_field[i] <= '9')) {
general_field_type[i] = ANY_ENC;
}
if (general_field[i] == '[') {
/* FNC1 can be encoded in any system */
general_field_type[i] = ANY_ENC;
}
}
general_field_type[strlen(general_field)] = '\0';
if (debug) printf("General field type: %s\n", general_field_type);
if (latch == 1) {
/* Invalid characters in input data */ /* Invalid characters in input data */
strcpy(symbol->errtxt, "386: Invalid characters in input data"); strcpy(symbol->errtxt, "386: Invalid characters in input data");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
for (i = 0; i < strlen(general_field); i++) {
if ((general_field_type[i] == ISOIEC) && (general_field[i + 1] == '[')) {
general_field_type[i + 1] = ISOIEC;
}
}
for (i = 0; i < strlen(general_field); i++) {
if ((general_field_type[i] == ALPHA_OR_ISO) && (general_field[i + 1] == '[')) {
general_field_type[i + 1] = ALPHA_OR_ISO;
}
}
latch = general_rules(general_field_type);
if (debug) printf("General field type: %s\n", general_field_type);
last_mode = NUMERIC;
/* Set initial mode if not NUMERIC */
if (general_field_type[0] == ALPHA) {
bin_append(0, 4, binary_string); /* Alphanumeric latch */
last_mode = ALPHA;
}
if (general_field_type[0] == ISOIEC) {
bin_append(0, 4, binary_string); /* Alphanumeric latch */
bin_append(4, 5, binary_string); /* ISO/IEC 646 latch */
last_mode = ISOIEC;
}
i = 0;
do {
if (debug) printf("Processing character %d ", i);
switch (general_field_type[i]) {
case NUMERIC:
if (debug) printf("as NUMERIC:");
if (last_mode != NUMERIC) {
bin_append(0, 3, binary_string); /* Numeric latch */
if (debug) printf("<NUMERIC LATCH>\n");
}
if (debug) printf(" %c%c > ", general_field[i], general_field[i + 1]);
if (general_field[i] != '[') {
d1 = ctoi(general_field[i]);
} else {
d1 = 10;
}
if (general_field[i + 1] != '[') {
d2 = ctoi(general_field[i + 1]);
} else {
d2 = 10;
}
bin_append((11 * d1) + d2 + 8, 7, binary_string);
i += 2;
if (debug) printf("\n");
last_mode = NUMERIC;
break;
case ALPHA:
if (debug) printf("as ALPHA\n");
if (i != 0) {
if (last_mode == NUMERIC) {
bin_append(0, 4, binary_string); /* Alphanumeric latch */
}
if (last_mode == ISOIEC) {
bin_append(4, 5, binary_string); /* Alphanumeric latch */
}
}
if ((general_field[i] >= '0') && (general_field[i] <= '9')) {
bin_append(general_field[i] - 43, 5, binary_string);
}
if ((general_field[i] >= 'A') && (general_field[i] <= 'Z')) {
bin_append(general_field[i] - 33, 6, binary_string);
}
last_mode = ALPHA;
if (general_field[i] == '[') {
bin_append(15, 5, binary_string);
last_mode = NUMERIC;
} /* FNC1/Numeric latch */
if (general_field[i] == '*') bin_append(58, 6, binary_string); /* asterisk */
if (general_field[i] == ',') bin_append(59, 6, binary_string); /* comma */
if (general_field[i] == '-') bin_append(60, 6, binary_string); /* minus or hyphen */
if (general_field[i] == '.') bin_append(61, 6, binary_string); /* period or full stop */
if (general_field[i] == '/') bin_append(62, 6, binary_string); /* slash or solidus */
i++;
break;
case ISOIEC:
if (debug) printf("as ISOIEC\n");
if (i != 0) {
if (last_mode == NUMERIC) {
bin_append(0, 4, binary_string); /* Alphanumeric latch */
bin_append(4, 5, binary_string); /* ISO/IEC 646 latch */
}
if (last_mode == ALPHA) {
bin_append(4, 5, binary_string); /* ISO/IEC 646 latch */
}
}
if ((general_field[i] >= '0') && (general_field[i] <= '9')) {
bin_append(general_field[i] - 43, 5, binary_string);
}
if ((general_field[i] >= 'A') && (general_field[i] <= 'Z')) {
bin_append(general_field[i] - 1, 7, binary_string);
}
if ((general_field[i] >= 'a') && (general_field[i] <= 'z')) {
bin_append(general_field[i] - 7, 7, binary_string);
}
last_mode = ISOIEC;
if (general_field[i] == '[') {
bin_append(15, 5, binary_string);
last_mode = NUMERIC;
} /* FNC1/Numeric latch */
if (general_field[i] == '!') bin_append(232, 8, binary_string); /* exclamation mark */
if (general_field[i] == 34) bin_append(233, 8, binary_string); /* quotation mark */
if (general_field[i] == 37) bin_append(234, 8, binary_string); /* percent sign */
if (general_field[i] == '&') bin_append(235, 8, binary_string); /* ampersand */
if (general_field[i] == 39) bin_append(236, 8, binary_string); /* apostrophe */
if (general_field[i] == '(') bin_append(237, 8, binary_string); /* left parenthesis */
if (general_field[i] == ')') bin_append(238, 8, binary_string); /* right parenthesis */
if (general_field[i] == '*') bin_append(239, 8, binary_string); /* asterisk */
if (general_field[i] == '+') bin_append(240, 8, binary_string); /* plus sign */
if (general_field[i] == ',') bin_append(241, 8, binary_string); /* comma */
if (general_field[i] == '-') bin_append(242, 8, binary_string); /* minus or hyphen */
if (general_field[i] == '.') bin_append(243, 8, binary_string); /* period or full stop */
if (general_field[i] == '/') bin_append(244, 8, binary_string); /* slash or solidus */
if (general_field[i] == ':') bin_append(245, 8, binary_string); /* colon */
if (general_field[i] == ';') bin_append(246, 8, binary_string); /* semicolon */
if (general_field[i] == '<') bin_append(247, 8, binary_string); /* less-than sign */
if (general_field[i] == '=') bin_append(248, 8, binary_string); /* equals sign */
if (general_field[i] == '>') bin_append(249, 8, binary_string); /* greater-than sign */
if (general_field[i] == '?') bin_append(250, 8, binary_string); /* question mark */
if (general_field[i] == '_') bin_append(251, 8, binary_string); /* underline or low line */
if (general_field[i] == ' ') bin_append(252, 8, binary_string); /* space */
i++;
break;
}
} while (i + latch < strlen(general_field));
if (debug) printf("Resultant binary = %s\n", binary_string); if (debug) printf("Resultant binary = %s\n", binary_string);
if (debug) printf("\tLength: %d\n", (int) strlen(binary_string)); if (debug) printf("\tLength: %d\n", (int) strlen(binary_string));
@ -1751,33 +1414,29 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
if ((symbol_characters % characters_per_row) == 1) { if ((symbol_characters % characters_per_row) == 1) {
symbol_characters++; symbol_characters++;
} }
}
if (symbol_characters < 4) { if (symbol_characters < 4) {
symbol_characters = 4; symbol_characters = 4;
} }
}
if (symbol_characters < 3) {
symbol_characters = 3;
}
remainder = (12 * (symbol_characters - 1)) - strlen(binary_string); remainder = (12 * (symbol_characters - 1)) - strlen(binary_string);
if (latch == 1) { if (last_digit) {
/* There is still one more numeric digit to encode */ /* There is still one more numeric digit to encode */
if (debug) printf("Adding extra (odd) numeric digit\n"); if (debug) printf("Adding extra (odd) numeric digit\n");
if (last_mode == NUMERIC) { if (mode == NUMERIC) {
if ((remainder >= 4) && (remainder <= 6)) { if ((remainder >= 4) && (remainder <= 6)) {
bin_append(ctoi(general_field[i]) + 1, 4, binary_string); bin_append(ctoi(last_digit) + 1, 4, binary_string);
} else { } else {
d1 = ctoi(general_field[i]); d1 = ctoi(last_digit);
d2 = 10; d2 = 10;
bin_append((11 * d1) + d2 + 8, 7, binary_string); bin_append((11 * d1) + d2 + 8, 7, binary_string);
} }
} else { } else {
bin_append(general_field[i] - 43, 5, binary_string); bin_append(last_digit - 43, 5, binary_string);
} }
remainder = 12 - (strlen(binary_string) % 12); remainder = 12 - (strlen(binary_string) % 12);
@ -1796,15 +1455,11 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
if ((symbol_characters % characters_per_row) == 1) { if ((symbol_characters % characters_per_row) == 1) {
symbol_characters++; symbol_characters++;
} }
}
if (symbol_characters < 4) { if (symbol_characters < 4) {
symbol_characters = 4; symbol_characters = 4;
} }
}
if (symbol_characters < 3) {
symbol_characters = 3;
}
remainder = (12 * (symbol_characters - 1)) - strlen(binary_string); remainder = (12 * (symbol_characters - 1)) - strlen(binary_string);
@ -1819,7 +1474,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
/* Now add padding to binary string (7.2.5.5.4) */ /* Now add padding to binary string (7.2.5.5.4) */
i = remainder; i = remainder;
if ((strlen(general_field) != 0) && (last_mode == NUMERIC)) { if (mode == NUMERIC) {
strcpy(padstring, "0000"); strcpy(padstring, "0000");
i -= 4; i -= 4;
} else { } else {
@ -2204,7 +1859,7 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int src_len)
} }
symbol->row_height[symbol->rows - 2] = 1; symbol->row_height[symbol->rows - 2] = 1;
/* bottom separator pattern (above current row) */ /* bottom separator pattern (above current row) */
for (j = 4; j < (writer - 4); j++) { for (j = 4 + special_case_row; j < (writer - 4); j++) {
if (module_is_set(symbol, symbol->rows, j)) { if (module_is_set(symbol, symbol->rows, j)) {
unset_module(symbol, symbol->rows - 1, j); unset_module(symbol, symbol->rows - 1, j);
} else { } else {

View File

@ -29,13 +29,7 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */
#define NUMERIC 110
#define ALPHA 97
#define ISOIEC 105
#define INVALID_CHAR 100
#define ANY_ENC 120
#define ALPHA_OR_ISO 121
/* RSS-14 Tables */ /* RSS-14 Tables */
static const unsigned short int g_sum_table[9] = { static const unsigned short int g_sum_table[9] = {

View File

@ -117,7 +117,7 @@ static void test_helper_generate(const struct zint_symbol* symbol, int ret, int
} }
} }
// Replicate examples from GS1 Specification standard and ISO/IEC 24723:2010 // Replicate examples from GS1 General Specifications 19.1 and ISO/IEC 24723:2010
static void test_examples(void) static void test_examples(void)
{ {
testStart(""); testStart("");
@ -137,7 +137,7 @@ static void test_examples(void)
char* comment; char* comment;
unsigned char* expected; unsigned char* expected;
}; };
// Verified manually against GS1 Specification standard and ISO/IEC 24723:2010, with noted exceptions // Verified manually against GS1 General Specifications 19.1 and ISO/IEC 24723:2010, with noted exceptions
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_RSS14_OMNI_CC, "0401234567890", "[17]050101[10]ABC123", 1, 0, 0, 0, 11, 56, "Figure 5.1-5. GS1 DataBar Stacked Omnidirectional barcode with a Composite Component", /* 0*/ { BARCODE_RSS14_OMNI_CC, "0401234567890", "[17]050101[10]ABC123", 1, 0, 0, 0, 11, 56, "Figure 5.1-5. GS1 DataBar Stacked Omnidirectional barcode with a Composite Component",
"01101100110101110001001100001000000110100111011110101001" "01101100110101110001001100001000000110100111011110101001"

View File

@ -45,7 +45,7 @@ static void test_gs1_reduce(void)
int symbology; int symbology;
int input_mode; int input_mode;
unsigned char* data; unsigned char* data;
unsigned char* primary; unsigned char* composite;
int ret; int ret;
char* comment; char* comment;
@ -103,34 +103,34 @@ static void test_gs1_reduce(void)
}, },
/*13*/ { BARCODE_RSS_EXP, -1, "2012", "", ZINT_ERROR_INVALID_DATA, "GS1 data required", "" }, /*13*/ { BARCODE_RSS_EXP, -1, "2012", "", ZINT_ERROR_INVALID_DATA, "GS1 data required", "" },
/*14*/ { BARCODE_RSS_EXP, -1, "[20]12", "", 0, "Input mode ignored", /*14*/ { BARCODE_RSS_EXP, -1, "[20]12", "", 0, "Input mode ignored",
"0101010100000000011011111111000010101011000000010001011111001011100010111100000000101" "010010000010000101101111111100001010000010000110010101111100101110001011110000000010101111100001011101"
}, },
/*15*/ { BARCODE_RSS_EXP, GS1_MODE, "[20]12", "", 0, "Input mode ignored", /*15*/ { BARCODE_RSS_EXP, GS1_MODE, "[20]12", "", 0, "Input mode ignored",
"0101010100000000011011111111000010101011000000010001011111001011100010111100000000101" "010010000010000101101111111100001010000010000110010101111100101110001011110000000010101111100001011101"
}, },
/*16*/ { BARCODE_RSS_EXP, UNICODE_MODE, "[20]12", "", 0, "Input mode ignored", /*16*/ { BARCODE_RSS_EXP, UNICODE_MODE, "[20]12", "", 0, "Input mode ignored",
"0101010100000000011011111111000010101011000000010001011111001011100010111100000000101" "010010000010000101101111111100001010000010000110010101111100101110001011110000000010101111100001011101"
}, },
/*17*/ { BARCODE_RSS_EXP_CC, -1, "[20]12", "[21]1234", 0, "Input mode ignored", /*17*/ { BARCODE_RSS_EXP_CC, -1, "[20]12", "[21]1234", 0, "Input mode ignored",
"00110110111011010000100000110100110011101100001001110100110000101000110001001001101100000011011000101" "001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010"
"00110110110011111010001001100110101110010000001001100100100111100101111001110101100100000011001000101" "001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010"
"00110110100010111110011000010100111101000000101001100110101110111001111001001111011000011011101000101" "001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010"
"00001010111111111001000000001010010001100100011101101000001101000111010000111111100000000000000000000" "000001111111010110010000000010100100111001100001011010000011010001100100001010101001010000011110100000"
"01010101000000000110111111110000101110011011100010010111110010111000101111000000001010000000000000000" "010010000000101001101111111100001011000110011110100101111100101110001011110000000010101111100001011101"
}, },
/*18*/ { BARCODE_RSS_EXP_CC, GS1_MODE, "[20]12", "[21]1234", 0, "Input mode ignored", /*18*/ { BARCODE_RSS_EXP_CC, GS1_MODE, "[20]12", "[21]1234", 0, "Input mode ignored",
"00110110111011010000100000110100110011101100001001110100110000101000110001001001101100000011011000101" "001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010"
"00110110110011111010001001100110101110010000001001100100100111100101111001110101100100000011001000101" "001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010"
"00110110100010111110011000010100111101000000101001100110101110111001111001001111011000011011101000101" "001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010"
"00001010111111111001000000001010010001100100011101101000001101000111010000111111100000000000000000000" "000001111111010110010000000010100100111001100001011010000011010001100100001010101001010000011110100000"
"01010101000000000110111111110000101110011011100010010111110010111000101111000000001010000000000000000" "010010000000101001101111111100001011000110011110100101111100101110001011110000000010101111100001011101"
}, },
/*19*/ { BARCODE_RSS_EXP_CC, UNICODE_MODE, "[20]12", "[21]1234", 0, "Input mode ignored", /*19*/ { BARCODE_RSS_EXP_CC, UNICODE_MODE, "[20]12", "[21]1234", 0, "Input mode ignored",
"00110110111011010000100000110100110011101100001001110100110000101000110001001001101100000011011000101" "001101101110110100001000001101001100111011000010011101001100001010001100010010011011000000110110001010"
"00110110110011111010001001100110101110010000001001100100100111100101111001110101100100000011001000101" "001101101100111110100010011001101011100100000010011001001001111001011110011101011001000000110010001010"
"00110110100010111110011000010100111101000000101001100110101110111001111001001111011000011011101000101" "001101101000101111100110000101001111010000001010011001101011101110011110010011110110000110111010001010"
"00001010111111111001000000001010010001100100011101101000001101000111010000111111100000000000000000000" "000001111111010110010000000010100100111001100001011010000011010001100100001010101001010000011110100000"
"01010101000000000110111111110000101110011011100010010111110010111000101111000000001010000000000000000" "010010000000101001101111111100001011000110011110100101111100101110001011110000000010101111100001011101"
}, },
/*20*/ { BARCODE_RSS_EXPSTACK, -1, "12", "", ZINT_ERROR_INVALID_DATA, "GS1 data required", "" }, /*20*/ { BARCODE_RSS_EXPSTACK, -1, "12", "", ZINT_ERROR_INVALID_DATA, "GS1 data required", "" },
/*21*/ { BARCODE_RSS_EXPSTACK, -1, "[20]12", "", 0, "Input mode ignored", /*21*/ { BARCODE_RSS_EXPSTACK, -1, "[20]12", "", 0, "Input mode ignored",
@ -179,8 +179,8 @@ static void test_gs1_reduce(void)
symbol->input_mode = data[i].input_mode; symbol->input_mode = data[i].input_mode;
} }
if (strlen(data[i].primary)) { if (strlen(data[i].composite)) {
text = data[i].primary; text = data[i].composite;
strcpy(symbol->primary, data[i].data); strcpy(symbol->primary, data[i].data);
} else { } else {
text = data[i].data; text = data[i].data;
@ -192,12 +192,12 @@ static void test_gs1_reduce(void)
#ifdef TEST_GS1_REDUCE_GENERATE_EXPECTED #ifdef TEST_GS1_REDUCE_GENERATE_EXPECTED
if (data[i].ret == 0) { if (data[i].ret == 0) {
printf(" /*%2d*/ { %s, %s, \"%s\", \"%s\", %d, \"%s\",\n", 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); i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].data, data[i].composite, data[i].ret, data[i].comment);
testUtilModulesDump(symbol, " ", "\n"); testUtilModulesDump(symbol, " ", "\n");
printf(" },\n"); printf(" },\n");
} else { } else {
printf(" /*%2d*/ { %s, %s, \"%s\", \"%s\", %s, \"%s\", \"\" },\n", 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); i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].data, data[i].composite, testUtilErrorName(data[i].ret), data[i].comment);
} }
#else #else
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
@ -223,7 +223,7 @@ static void test_hrt(void)
struct item { struct item {
int symbology; int symbology;
unsigned char* data; unsigned char* data;
unsigned char* primary; unsigned char* composite;
unsigned char* expected; unsigned char* expected;
}; };
@ -245,8 +245,8 @@ static void test_hrt(void)
symbol->symbology = data[i].symbology; symbol->symbology = data[i].symbology;
if (strlen(data[i].primary)) { if (strlen(data[i].composite)) {
text = data[i].primary; text = data[i].composite;
strcpy(symbol->primary, data[i].data); strcpy(symbol->primary, data[i].data);
} else { } else {
text = data[i].data; text = data[i].data;

View File

@ -27,10 +27,13 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */
#include "testcommon.h" #include "testcommon.h"
//#define TEST_RSS_BINARY_DIV_MODULO_DIVISOR_GENERATE_EXPECTED 1 //#define TEST_RSS_BINARY_DIV_MODULO_DIVISOR_GENERATE_EXPECTED 1
//#define TEST_EXAMPLES_GENERATE_EXPECTED 1
//#define TEST_GENERAL_FIELD_GENERATE_EXPECTED 1
static void test_binary_div_modulo_divisor(void) static void test_binary_div_modulo_divisor(void)
{ {
@ -98,9 +101,443 @@ static void test_binary_div_modulo_divisor(void)
testFinish(); testFinish();
} }
// Replicate examples from GS1 General Specifications 19.1 and ISO/IEC 24724:2011
static void test_examples(void)
{
testStart("");
int ret;
struct item {
int symbology;
unsigned char* data;
int ret;
int expected_rows;
int expected_width;
char* comment;
unsigned char* expected;
};
// Verified manually against GS1 General Specifications 19.1 and ISO/IEC 24724:2011
struct item data[] = {
/* 0*/ { BARCODE_RSS14, "0950110153001", 0, 1, 96, "Figure 5.5.2.1.1-1. GS1 DataBar Omnidirectional",
"010000010100000101000111110000010111101101011100100011011101000101100000000111001110110111001101"
},
/* 1*/ { BARCODE_RSS_EXP, "[01]90614141000015[3202]000150", 0, 1, 151, "Figure 5.5.2.3.1-1. GS1 DataBar Expanded",
"0101100011001100001011111111000010100100010000111101110011100010100010111100000011100111010111111011010100000100000110001111110000101000000100011010010"
},
/* 2*/ { BARCODE_RSS_EXPSTACK, "[01]90614141000015[3202]000150", 0, 5, 102, "Figure 5.5.2.3.2-1. GS1 DataBar Expanded Stacked",
"010110001100110000101111111100001010010001000011110111001110001010001011110000001110011101011111101101"
"000001110011001111010000000010100101101110111100001000110001110101100100001010100001100010100000010000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000001011111011111001010000001010010111111011100100000000000000000000000000000000000000000000000000000"
"001010100000100000110001111110000101000000100011010010000000000000000000000000000000000000000000000000"
},
/* 3*/ { BARCODE_RSS14, "2001234567890", 0, 1, 96, "24724:2011 Figure 1 — GS1 DataBar Omnidirectional",
"010100011101000001001111111000010100110110111110110000010010100101100000000111000110110110001101"
},
/* 4*/ { BARCODE_RSS14, "0441234567890", 0, 1, 96, "24724:2011 Figure 2 — GS1 DataBar Omnidirectional",
"010010001000010001000111000000010101000001100110101100100100000101111110000011000010100011100101"
},
/* 5*/ { BARCODE_RSS14, "0001234567890", 0, 1, 96, "24724:2011 Figure 4 — GS1 DataBar Truncated",
"010101001000000001001111111000010111001011011110111001010110000101111111000111001100111101110101"
},
/* 6*/ { BARCODE_RSS14STACK, "0001234567890", 0, 3, 50, "24724:2011 Figure 5 — GS1 DataBar Stacked",
"01010100100000000100111111100001011100101101111010"
"00001010101011111010000000111010100011010010000000"
"10111001010110000101111111000111001100111101110101"
},
/* 7*/ { BARCODE_RSS14STACK_OMNI, "0003456789012", 0, 5, 50, "24724:2011 Figure 6 — GS1 DataBar Stacked Omnidirectional",
"01010100100000000100111110000001010011100110011010"
"00001011011111111010000001010100101100011001100000"
"00000101010101010101010101010101010101010101010000"
"00001000100010111010010101010000111101001101110000"
"10110111011101000101100000000111000010110010001101"
},
/* 8*/ { BARCODE_RSS_LTD, "1501234567890", 0, 1, 74, "24724:2011 Figure 7 — GS1 DataBar Limited",
"01000110011000110110101001110100101011010011010010010110001101110011001101"
},
/* 9*/ { BARCODE_RSS_LTD, "0031234567890", 0, 1, 74, "24724:2011 Figure 8 — (a) GS1 DataBar Limited",
"01010100000100100010000101110010101101101001010110000010100100101100000101"
},
/*10*/ { BARCODE_RSS_EXP, "[01]98898765432106[3202]012345[15]991231", 0, 1, 200, "24724:2011 Figure 10 — GS1 DataBar Expanded",
"01001000011000110110111111110000101110000110010100011010000001100010101111110000111010011100000010010100111110111001100011111100001011101100000100100100011110010110001011111111001110001101111010000101"
},
/*11*/ { BARCODE_RSS_EXP, "[01]90012345678908[3103]001750", 0, 1, 151, "24724:2011 Figure 11 — GS1 DataBar Expanded",
"0101110010000010011011111111000010111000010011000101011110111001100010111100000011100101110001110111011110101111000110001111110000101011000010011111010"
},
/*12*/ { BARCODE_RSS_EXPSTACK, "[01]98898765432106[3202]012345[15]991231", 0, 5, 102, "24724:2011 Figure 12 — GS1 DataBar Expanded Stacked symbol",
"010010000110001101101111111100001011100001100101000110100000011000101011111100001110100111000000100101"
"000001111001110010010000000010100100011110011010111001011111100111010100000010100001011000111111010000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000011101000010011100001000000001011100101100001110110110111110010001001010000001010011000100000110000"
"101000010111101100011100111111110100011010011110001001001000001101110100001111110001100111011111001010"
},
/*13*/ { BARCODE_RSS_EXPSTACK, "[01]95012345678903[3103]000123", 0, 5, 102, "24724:2011 Figure 13 — GS1 DataBar Expanded Stacked",
"010100010001111000101111111100001010111000001100010111000110001001101011110000001110010111000111011101"
"000011101110000111010000000010100101000111110011101000111001110110010100001010100001101000111000100000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000000001010000111001010000001010010111011011111100000000000000000000000000000000000000000000000000000"
"001011110101111000110001111110000101000100100000011010000000000000000000000000000000000000000000000000"
},
/*14*/ { BARCODE_RSS_LTD, "0009876543210", 0, 1, 74, "24724:2011 Figure F.2 — GS1 DataBar Limited",
"01010100100100110000110000010101101001011001010001000101000100000100100101"
},
/*15*/ { BARCODE_RSS_EXP, "[10]12A", 0, 1, 102, "24724:2011 Figure F.3 — GS1 DataBar Expanded",
"010100000110100000101111111100001010001000000010110101111100100111001011110000000010011101111111010101"
},
};
int data_size = sizeof(data) / sizeof(struct item);
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;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_EXAMPLES_GENERATE_EXPECTED
if (ret == 0) {
printf(" /*%2d*/ { %s, \"%s\", %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(symbol->symbology), data[i].data, ret, symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
} else {
printf(" /*%2d*/ { %s, \"%s\", %s, %d, %d, \"%s\", \"\" },\n",
i, testUtilBarcodeName(symbol->symbology), data[i].data, testUtilErrorName(ret), symbol->rows, symbol->width, data[i].comment);
}
#else
assert_equal(symbol->rows, data[i].expected_rows, "i:%d %s symbol->rows %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d %s symbol->width %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->width, data[i].expected_width, data[i].data);
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();
}
// Test general-purpose data compaction
static void test_general_field(void)
{
testStart("");
int ret;
struct item {
int symbology;
unsigned char* data;
int ret;
int expected_rows;
int expected_width;
char* comment;
unsigned char* expected;
};
// Verified manually against bwipp and tec-it.com (bottom separator differs from tec-it.com where noted)
struct item data[] = {
/* 0*/ { BARCODE_RSS_EXP, "[91]1", 0, 1, 102, "Single numeric",
"010100000001000101101111111100001011001000010000010110111110101100001011110000000010101111100001011101"
},
/* 1*/ { BARCODE_RSS_EXP, "[91]12", 0, 1, 102, "2 numerics",
"010010000010000101101111111100001011001000010000010101111100101110001011110000000010101111100001011101"
},
/* 2*/ { BARCODE_RSS_EXP, "[91]123", 0, 1, 102, "Odd-numbered numeric",
"010100000110000100101111111100001011001000010000010100011111010111001011110000000010000011000110100101"
},
/* 3*/ { BARCODE_RSS_EXP, "[91]1234", 0, 1, 102, "Even-numbered numeric",
"010110010000001000101111111100001011001000010000010100111110001011101011110000000010001101111001011101"
},
/* 4*/ { BARCODE_RSS_EXP, "[91]A1234567C", 0, 1, 183, "Alphanumeric followed by 7 digits and alphanumeric",
"010100000111001001101111111100001011000001000101110101111110111101001011111100001110100110111110111100001111010110011000111111000010110001000001101101110111101111010010111111110011101"
},
/* 5*/ { BARCODE_RSS_EXP, "[91]A123456C", 0, 1, 151, "Alphanumeric followed by 6 digits and alphanumeric",
"0101100111001000001011111111000010110010000100000101011111101111010010111100000011101001101111101111000011110101100110001111110000101000100011000111010"
},
/* 6*/ { BARCODE_RSS_EXP, "[91]A12345B", 0, 1, 151, "Alphanumeric followed by 5 digits and alphanumeric",
"0101111001000001001011111111000010110010000100000101011111101111010010111100000011100000010111001001010000111101000010001111110000101100000001001010010"
},
/* 7*/ { BARCODE_RSS_EXP, "[91]A1234567", 0, 1, 151, "Alphanumeric followed by 7 digits, terminating",
"0101100100011100001011111111000010110010000100000101011111101111010010111100000011101001101111101111000011110110100110001111110000101101011110111100010"
},
/* 8*/ { BARCODE_RSS_EXP, "[91]A123456", 0, 1, 134, "Alphanumeric followed by 6 digits, terminating",
"01000101001100000010111111110000101100000100010111010111111011110100101111000000111010011011111011110000111101011001100011111100001010"
},
/* 9*/ { BARCODE_RSS_EXP, "[91]A12345", 0, 1, 134, "Alphanumeric followed by 5 digits, terminating",
"01000110010100000010111111110000101100000100010111010111111011110100101111000000111010011011111011110000101100111110100011111100001010"
},
/*10*/ { BARCODE_RSS_EXP, "[91]A1234", 0, 1, 134, "Alphanumeric followed by 4 digits, terminating",
"01011101000010000110111111110000101100000100010111010111111011110100101111000000111010011011111011110001101111100100100011111100001010"
},
/*11*/ { BARCODE_RSS_EXP, "[91]A123", 0, 1, 134, "Alphanumeric followed by 3 digits, terminating",
"01000010110010000010111111110000101100000100010111010111111011110100101111000000111000000101110010010001000010000101100011111100001010"
},
/*12*/ { BARCODE_RSS_EXP, "[91]a1234ABCDEFGb", 0, 1, 249, "ISO-646 followed by 11 non-ISO-646 non-terminating, starting 4 digits",
"010000100011100110101111111100001011001000010000010101101111110011101011111000000110000110110100011100001110000101011000111111000010100111000010110001000000100110110010111111110011101000001110010001010011011111100110001111000000101110111010011000010"
},
/*13*/ { BARCODE_RSS_EXP, "[91]a1234ABCDEFb", 0, 1, 249, "ISO-646 followed by 10 non-ISO-646 non-terminating, starting 4 digits",
"010111010001110001101111111100001011001000010000010101101111110011101011111000000110000110110100011100001110000101011000111111000010100111000010110001000000100110110010111111110011101000001110010001001100011011100110001111000000101101000111001110010"
},
/*14*/ { BARCODE_RSS_EXP, "[91]a1234ABCDEF", 0, 1, 232, "ISO-646 followed by 10 non-ISO-646 terminating, starting 4 digits",
"0100001011010000111011111111000010110000010001011101011011111100111010111110000001100001101101000111000011100001010110001111110000101001110000101100010000001001101100101111111100111010000011100100010011100111000101100011110000001010"
},
/*15*/ { BARCODE_RSS_EXP, "[91]a1234ABCDEb", 0, 1, 232, "ISO-646 followed by 9 non-ISO-646 non-terminating, starting 4 digits",
"0100001011011000011011111111000010110000010001011101011011111100111010111110000001100100011100100111011110010111110010001111110000101111100011001010010110001000011110101111111100111011100101111000110111001000011110100011110000001010"
},
/*16*/ { BARCODE_RSS_EXP, "[91]a1234ABCDE", 0, 1, 200, "ISO-646 followed by 9 non-ISO-646 terminating, starting 4 digits",
"01001000011000111010111111110000101100100001000001010110111111001110101111110000111000011011010001110000111000010101100011111100001010011100001011000100000010011011001011111111001110010011100000100101"
},
/*17*/ { BARCODE_RSS_EXP, "[91]aABCDEF12345b", 0, 1, 249, "ISO-646 followed by 11 non-ISO-646 non-terminating, starting 6 letters",
"010000100010100111101111111100001011001000010000010101101111110011101011111000000110100001110001011100010000010100011000111111000010111101000100100001100111010000110010111111110011101000001110011011000100000110101110001111000000101011110010001110010"
},
/*18*/ { BARCODE_RSS_EXP, "[91]aABCDEF1234b", 0, 1, 249, "ISO-646 followed by 10 non-ISO-646 non-terminating, starting 6 letters",
"010110111100110000101111111100001011001000010000010101101111110011101011111000000110100001110001011100010000010100011000111111000010111101000100100001100111010000110010111111110011101000001110011011000100001001110110001111000000101111110110110001010"
},
/*19*/ { BARCODE_RSS_EXP, "[91]aABCDE12345b", 0, 1, 249, "ISO-646 followed by 10 non-ISO-646 non-terminating, starting 5 letters",
"010000100010011011101111111100001011001000010000010101101111110011101011111000000110100001110001011100010000010100011000111111000010111101000100100001100100001110011010111111110011100110110010000111000101111000101110001111000000101111011001101000010"
},
/*20*/ { BARCODE_RSS_EXP, "[91]aABCDE1234", 0, 1, 200, "ISO-646 followed by 10 non-ISO-646 terminating, starting 5 letters",
"01000101100011100010111111110000101100100001000001010110111111001110101111110000111010000111000101110001000001010001100011111100001011110100010010000110000100101111001011111111001110010010001110011101"
},
/*21*/ { BARCODE_RSS_EXP, "[91]aABCDE1234b", 0, 1, 232, "ISO-646 followed by 9 non-ISO-646 non-terminating, starting 5 letters",
"0100010000110011011011111111000010110000010001011101011011111100111010111110000001100001000110110111010000010110000010001111110000101000011101001100011001000011100110101111111100111011001100100001110111001000011110100011110000001010"
},
/*22*/ { BARCODE_RSS_EXP, "[91]aABCDE1234", 0, 1, 200, "ISO-646 followed by 9 non-ISO-646 terminating, starting 5 letters",
"01000101100011100010111111110000101100100001000001010110111111001110101111110000111010000111000101110001000001010001100011111100001011110100010010000110000100101111001011111111001110010010001110011101"
},
/*23*/ { BARCODE_RSS_EXPSTACK, "[91]1", 0, 1, 102, "Single numeric",
"010100000001000101101111111100001011001000010000010110111110101100001011110000000010101111100001011101"
},
/*24*/ { BARCODE_RSS_EXPSTACK, "[91]12", 0, 1, 102, "2 numerics",
"010010000010000101101111111100001011001000010000010101111100101110001011110000000010101111100001011101"
},
/*25*/ { BARCODE_RSS_EXPSTACK, "[91]123", 0, 1, 102, "Odd-numbered numeric",
"010100000110000100101111111100001011001000010000010100011111010111001011110000000010000011000110100101"
},
/*26*/ { BARCODE_RSS_EXPSTACK, "[91]1234", 0, 1, 102, "Even-numbered numeric",
"010110010000001000101111111100001011001000010000010100111110001011101011110000000010001101111001011101"
},
/*27*/ { BARCODE_RSS_EXPSTACK, "[91]A1234567C", 0, 5, 102, "Alphanumeric followed by 7 digits and alphanumeric",
"010100000111001001101111111100001011000001000101110101111110111101001011111100001110100110111110111101"
"000011111000110110010000000010100100111110111010001010000001000010100100000010100001011001000001000000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000000100000000101101000010000100010010011111011100100101000000011001100101000011000000000000000000000"
"101110011111111010010111101111011101101100000100011010000111111000110011010111100001000000000000000000"
},
/*28*/ { BARCODE_RSS_EXPSTACK, "[91]A123456C", 0, 5, 102, "Alphanumeric followed by 6 digits and alphanumeric",
"010110011100100000101111111100001011001000010000010101111110111101001011110000001110100110111110111101"
"000001100011011111010000000010100100110111101111101010000001000010100100001010100001011001000001000000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000001100001010011001010000001010010111011100111000000000000000000000000000000000000000000000000000000"
"001000011110101100110001111110000101000100011000111010000000000000000000000000000000000000000000000000"
},
/*29*/ { BARCODE_RSS_EXPSTACK, "[91]A12345B", 0, 5, 102, "Alphanumeric followed by 5 digits and alphanumeric",
"010111100100000100101111111100001011001000010000010101111110111101001011110000001110000001011100100101"
"000000011011111011010000000010100100110111101111101010000001000010100100001010100001111110100011010000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000001111000010111101010000001010010011111110110100000000000000000000000000000000000000000000000000000"
"001010000111101000010001111110000101100000001001010010000000000000000000000000000000000000000000000000"
},
/*30*/ { BARCODE_RSS_EXPSTACK, "[91]A1234567", 0, 5, 102, "Alphanumeric followed by 7 digits, terminating **NOTE** bottom separator differs from tec-it.com, same as bwipp",
"010110010001110000101111111100001011001000010000010101111110111101001011110000001110100110111110111101"
"000001101110001111010000000010100100110111101111101010000001000010100100001010100001011001000001000000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000001100001001011001010000001010010010100001000010000000000000000000000000000000000000000000000000000"
"001000011110110100110001111110000101101011110111100010000000000000000000000000000000000000000000000000"
},
/*31*/ { BARCODE_RSS_EXPSTACK, "[91]A123456", 0, 5, 102, "Alphanumeric followed by 6 digits, terminating **NOTE** ditto",
"010100001100111000101111111100001011001000010000010101111110111101001011110000001110100110111110111101"
"000011110011000111010000000010100100110111101111101010000001000010100100001010100001011001000001000000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000001100001010011001010000001010010011101011111110000000000000000000000000000000000000000000000000000"
"001000011110101100110001111110000101100010100000001010000000000000000000000000000000000000000000000000"
},
/*32*/ { BARCODE_RSS_EXPSTACK, "[91]A12345", 0, 5, 102, "Alphanumeric followed by 5 digits, terminating **NOTE** ditto",
"010100100011000011101111111100001011001000010000010101111110111101001011110000001110100110111110111101"
"000011011100111100010000000010100100110111101111101010000001000010100100001010100001011001000001000000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000001101001100000101010000001010010011101011111110000000000000000000000000000000000000000000000000000"
"001000010110011111010001111110000101100010100000001010000000000000000000000000000000000000000000000000"
},
/*33*/ { BARCODE_RSS_EXPSTACK, "[91]A1234", 0, 5, 102, "Alphanumeric followed by 4 digits, terminating **NOTE** ditto",
"010111000010010001101111111100001011001000010000010101111110111101001011110000001110100110111110111101"
"000000111101101110010000000010100100110111101111101010000001000010100100001010100001011001000001000000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000001001000001101101010000001010010000111011101110000000000000000000000000000000000000000000000000000"
"001000110111110010010001111110000101111000100010001010000000000000000000000000000000000000000000000000"
},
/*34*/ { BARCODE_RSS_EXPSTACK, "[91]A123", 0, 5, 102, "Alphanumeric followed by 3 digits, terminating **NOTE** ditto",
"010110000100111000101111111100001011001000010000010101111110111101001011110000001110000001011100100101"
"000001111011000111010000000010100100110111101111101010000001000010100100001010100001111110100011010000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000001011110111101001010000001010010101111100001010000000000000000000000000000000000000000000000000000"
"001000100001000010110001111110000101010000011110100010000000000000000000000000000000000000000000000000"
},
/*35*/ { BARCODE_RSS_EXPSTACK, "[91]a1234ABCDEFGb", 0, 9, 102, "ISO-646 followed by 11 non-ISO-646 non-terminating, starting 4 digits **NOTE** ditto",
"010000100011100110101111111100001011001000010000010101101111110011101011111000000110000110110100011101"
"000011011100011001010000000010100100110111101111101010010000001100010100000101010001111001001011100000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000011011000111110100001000000001011001001101111110111001011110001101001010000001010010101111000110000"
"101000100111000001011100111111110100110110010000001000110100001110010100001111110001101010000111000010"
"000011011000111110100001000000001011001001101111110111001011110001101001010000001010010101111000110000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000011001000000110010100001010100100010001011001100000000000000000000000000000000000000000000000000000"
"010100110111111001100011110000001011101110100110000100000000000000000000000000000000000000000000000000"
},
/*36*/ { BARCODE_RSS_EXPSTACK, "[91]a1234ABCDEFb", 0, 9, 102, "ISO-646 followed by 10 non-ISO-646 non-terminating, starting 4 digits",
"010111010001110001101111111100001011001000010000010101101111110011101011111000000110000110110100011101"
"000000101110001110010000000010100100110111101111101010010000001100010100000101010001111001001011100000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000011011000111110100001000000001011001001101111110111001011110001101001010000001010010101111000110000"
"101000100111000001011100111111110100110110010000001000110100001110010100001111110001101010000111000010"
"000011011000111110100001000000001011001001101111110111001011110001101001010000001010010101111000110000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000000111001000110010100001010100100101110001100000000000000000000000000000000000000000000000000000000"
"010011000110111001100011110000001011010001110011100100000000000000000000000000000000000000000000000000"
},
/*37*/ { BARCODE_RSS_EXPSTACK, "[91]a1234ABCDEF", 0, 9, 102, "ISO-646 followed by 10 non-ISO-646 terminating, starting 4 digits **NOTE** ditto",
"010110111001000011101111111100001011001000010000010101101111110011101011111000000110000110110100011101"
"000001000110111100010000000010100100110111101111101010010000001100010100000101010001111001001011100000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000011011000111110100001000000001011001001101111110111001011110001101001010000001010010101111000110000"
"101000100111000001011100111111110100110110010000001000110100001110010100001111110001101010000111000010"
"000011011000111110100001000000001011001001101111110111001011110001101001010000001010010101111000110000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000000011000111010010100001010100101011111000010100000000000000000000000000000000000000000000000000000"
"010011100111000101100011110000001010100000111101000100000000000000000000000000000000000000000000000000"
},
/*38*/ { BARCODE_RSS_EXPSTACK, "[91]a1234ABCDEb", 0, 9, 102, "ISO-646 followed by 9 non-ISO-646 non-terminating, starting 4 digits **NOTE** ditto",
"010110111001100001101111111100001011001000010000010101101111110011101011111000000110010001110010011101"
"000001000110011110010000000010100100110111101111101010010000001100010100000101010001101110001101100000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000011100001011000100001000000001010000111101110010110101100111000001001010000001010110000010110000000"
"101100011110100111011100111111110101111000010001101001010011000111110100001111110001001111101001111010"
"000011100001011000100001000000001010000111101110010110101100111000001001010000001010110000010110000000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000000110111100001010100001010100101011111000010100000000000000000000000000000000000000000000000000000"
"010111001000011110100011110000001010100000111101000100000000000000000000000000000000000000000000000000"
},
/*39*/ { BARCODE_RSS_EXPSTACK, "[91]a1234ABCDE", 0, 5, 102, "ISO-646 followed by 9 non-ISO-646 terminating, starting 4 digits",
"010010000110001110101111111100001011001000010000010101101111110011101011111100001110000110110100011101"
"000001111001110001010000000010100100110111101111101010010000001100010100000010100001111001001011100000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000010111110001101100001000000001011001001101111110111001011110001101001010000001010010101111000110000"
"101001000001110010011100111111110100110110010000001000110100001110010100001111110001101010000111000010"
},
/*40*/ { BARCODE_RSS_EXPSTACK, "[91]aABCDEF12345b", 0, 9, 102, "ISO-646 followed by 11 non-ISO-646 non-terminating, starting 6 letters",
"010000100010100111101111111100001011001000010000010101101111110011101011111000000110100001110001011101"
"000011011101011000010000000010100100110111101111101010010000001100010100000101010001011110001110100000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000010011000111110100001000000001011001111010001100111101101110100001001010000001010011101011111010000"
"101101100111000001011100111111110100110000101110011000010010001011110100001111110001100010100000100010"
"000010011000111110100001000000001011001111010001100111101101110100001001010000001010011101011111010000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000010111110010100010100001010100101000011011100000000000000000000000000000000000000000000000000000000"
"010001000001101011100011110000001010111100100011100100000000000000000000000000000000000000000000000000"
},
/*41*/ { BARCODE_RSS_EXPSTACK, "[91]aABCDEF1234b", 0, 9, 102, "ISO-646 followed by 10 non-ISO-646 non-terminating, starting 6 letters **NOTE** ditto",
"010110111100110000101111111100001011001000010000010101101111110011101011111000000110100001110001011101"
"000001000011001111010000000010100100110111101111101010010000001100010100000101010001011110001110100000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000010011000111110100001000000001011001111010001100111101101110100001001010000001010011101011111010000"
"101101100111000001011100111111110100110000101110011000010010001011110100001111110001100010100000100010"
"000010011000111110100001000000001011001111010001100111101101110100001001010000001010011101011111010000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000010111101100010010100001010100100000010010011100000000000000000000000000000000000000000000000000000"
"010001000010011101100011110000001011111101101100010100000000000000000000000000000000000000000000000000"
},
/*42*/ { BARCODE_RSS_EXPSTACK, "[91]aABCDE12345b", 0, 9, 102, "ISO-646 followed by 10 non-ISO-646 non-terminating, starting 5 letters **NOTE** ditto",
"010000100010011011101111111100001011001000010000010101101111110011101011111000000110100001110001011101"
"000011011101100100010000000010100100110111101111101010010000001100010100000101010001011110001110100000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000001111011001001100001000000001010011000111101100111101101110100001001010000001010011101011111010000"
"101110000100110110011100111111110101100111000010011000010010001011110100001111110001100010100000100010"
"000001111011001001100001000000001010011000111101100111101101110100001001010000001010011101011111010000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000010100001110100010100001010100100001001100101100000000000000000000000000000000000000000000000000000"
"010001011110001011100011110000001011110110011010000100000000000000000000000000000000000000000000000000"
},
/*43*/ { BARCODE_RSS_EXPSTACK, "[91]aABCDE1234", 0, 5, 102, "ISO-646 followed by 10 non-ISO-646 terminating, starting 5 letters",
"010001011000111000101111111100001011001000010000010101101111110011101011111100001110100001110001011101"
"000010100111000111010000000010100100110111101111101010010000001100010100000010100001011110001110100000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000001100011101101100001000000001011000010110111100111101101110100001001010000001010011101011111010000"
"101110011100010010011100111111110100111101001000011000010010001011110100001111110001100010100000100010"
},
/*44*/ { BARCODE_RSS_EXPSTACK, "[91]aABCDE1234b", 0, 9, 102, "ISO-646 followed by 9 non-ISO-646 non-terminating, starting 5 letters **NOTE** ditto",
"010000100001110110101111111100001011001000010000010101101111110011101011111000000110000100011011011101"
"000011011110001001010000000010100100110111101111101010010000001100010100000101010001111011100100100000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000001111011001100100001000000001010011000111101100111001101000111101001010000001010111110010111110000"
"101110000100110011011100111111110101100111000010011000110010111000010100001111110001000001101000001010"
"000001111011001100100001000000001010011000111101100111001101000111101001010000001010111110010111110000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000000110111100001010100001010100101011111000010100000000000000000000000000000000000000000000000000000"
"010111001000011110100011110000001010100000111101000100000000000000000000000000000000000000000000000000"
},
/*45*/ { BARCODE_RSS_EXPSTACK, "[91]aABCDE1234", 0, 5, 102, "ISO-646 followed by 9 non-ISO-646 terminating, starting 5 letters",
"010001011000111000101111111100001011001000010000010101101111110011101011111100001110100001110001011101"
"000010100111000111010000000010100100110111101111101010010000001100010100000010100001011110001110100000"
"000001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000"
"000001100011101101100001000000001011000010110111100111101101110100001001010000001010011101011111010000"
"101110011100010010011100111111110100111101001000011000010010001011110100001111110001100010100000100010"
},
};
int data_size = sizeof(data) / sizeof(struct item);
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;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_GENERAL_FIELD_GENERATE_EXPECTED
if (ret == 0) {
printf(" /*%2d*/ { %s, \"%s\", %d, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(symbol->symbology), data[i].data, ret, symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
} else {
printf(" /*%2d*/ { %s, \"%s\", %s, %d, %d, \"%s\", \"\" },\n",
i, testUtilBarcodeName(symbol->symbology), data[i].data, testUtilErrorName(ret), symbol->rows, symbol->width, data[i].comment);
}
#else
assert_equal(symbol->rows, data[i].expected_rows, "i:%d %s symbol->rows %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d %s symbol->width %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->width, data[i].expected_width, data[i].data);
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();
}
int main() int main()
{ {
test_binary_div_modulo_divisor(); test_binary_div_modulo_divisor();
test_examples();
test_general_field();
testReport(); testReport();