mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
C25STANDARD/C25INTER/C25IATA/C25LOGIC/C25IND: add check digit option (#216)
This commit is contained in:
238
backend/2of5.c
238
backend/2of5.c
@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2008 - 2020 Robin Stuart <rstuart114@gmail.com>
|
||||
Copyright (C) 2008 - 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
|
||||
@ -34,162 +34,121 @@
|
||||
#include <stdio.h>
|
||||
#include "common.h"
|
||||
#ifdef _MSC_VER
|
||||
#include <malloc.h>
|
||||
#define inline _inline
|
||||
#endif
|
||||
|
||||
static const char *C25MatrixTable[10] = {
|
||||
"113311", "311131", "131131", "331111", "113131", "313111",
|
||||
"133111", "111331", "311311", "131311"
|
||||
"113311", "311131", "131131", "331111", "113131",
|
||||
"313111", "133111", "111331", "311311", "131311"
|
||||
};
|
||||
|
||||
static const char *C25MatrixStartStop[2] = { "411111", "41111" };
|
||||
|
||||
static const char *C25IndustTable[10] = {
|
||||
"1111313111", "3111111131", "1131111131", "3131111111", "1111311131",
|
||||
"3111311111", "1131311111", "1111113131", "3111113111", "1131113111"
|
||||
};
|
||||
|
||||
static const char *C25IndustStartStop[2] = { "313111", "31113" };
|
||||
|
||||
static const char *C25IataLogicStartStop[2] = { "1111", "311" };
|
||||
|
||||
static const char *C25InterTable[10] = {
|
||||
"11331", "31113", "13113", "33111", "11313", "31311", "13311", "11133",
|
||||
"31131", "13131"
|
||||
"11331", "31113", "13113", "33111", "11313",
|
||||
"31311", "13311", "11133", "31131", "13131"
|
||||
};
|
||||
|
||||
static inline char check_digit(unsigned int count) {
|
||||
static inline char check_digit(const unsigned int count) {
|
||||
return itoc((10 - (count % 10)) % 10);
|
||||
}
|
||||
|
||||
/* Calculate the check digit - the same method used for EAN-13 (GS1 General Specifications 7.9.1) */
|
||||
static unsigned int gs1_checksum(const unsigned char source[], const int length) {
|
||||
int i;
|
||||
unsigned int count = 0;
|
||||
int factor = length & 1 ? 3 : 1;
|
||||
for (i = 0; i < length; i++) {
|
||||
count += factor * ctoi(source[i]);
|
||||
factor = factor == 1 ? 3 : 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/* Common to Standard (Matrix), Industrial, IATA, and Data Logic */
|
||||
static int c25_common(struct zint_symbol *symbol, const unsigned char source[], int length, const int max,
|
||||
const char *table[10], const char *start_stop[2], const int error_base) {
|
||||
|
||||
int i, error_number;
|
||||
char dest[512]; /* Largest destination 6 + (80 + 1) * 6 + 5 + 1 = 498 */
|
||||
unsigned char temp[80 + 1 + 1]; /* Largest maximum 80 */
|
||||
int have_checkdigit = symbol->option_2 == 1 || symbol->option_2 == 2;
|
||||
|
||||
if (length > max) {
|
||||
sprintf(symbol->errtxt, "%d: Input too long (maximum %d)", error_base, max);
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
sprintf(symbol->errtxt, "%d: Invalid characters in data", error_base + 1);
|
||||
return error_number;
|
||||
}
|
||||
|
||||
ustrcpy(temp, source);
|
||||
|
||||
if (have_checkdigit) {
|
||||
/* Add standard GS1 check digit */
|
||||
temp[length] = check_digit(gs1_checksum(source, length));
|
||||
temp[++length] = '\0';
|
||||
}
|
||||
|
||||
/* start character */
|
||||
strcpy(dest, start_stop[0]);
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
lookup(NEON, table, temp[i], dest);
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
strcat(dest, start_stop[1]);
|
||||
|
||||
expand(symbol, dest);
|
||||
|
||||
ustrcpy(symbol->text, temp);
|
||||
if (symbol->option_2 == 2) {
|
||||
/* Remove check digit from HRT */
|
||||
symbol->text[length - 1] = '\0';
|
||||
}
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Code 2 of 5 Standard (Code 2 of 5 Matrix) */
|
||||
INTERNAL int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
|
||||
int i, error_number;
|
||||
char dest[512]; /* 6 + 80 * 6 + 5 + 1 = 492 */
|
||||
|
||||
if (length > 80) {
|
||||
strcpy(symbol->errtxt, "301: Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "302: Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* start character */
|
||||
strcpy(dest, "411111");
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
lookup(NEON, C25MatrixTable, source[i], dest);
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
strcat(dest, "41111");
|
||||
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, source);
|
||||
return error_number;
|
||||
return c25_common(symbol, source, length, 80, C25MatrixTable, C25MatrixStartStop, 301);
|
||||
}
|
||||
|
||||
/* Code 2 of 5 Industrial */
|
||||
INTERNAL int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
|
||||
int i, error_number;
|
||||
char dest[512]; /* 6 + 45 * 10 + 5 + 1 = 462 */
|
||||
|
||||
if (length > 45) {
|
||||
strcpy(symbol->errtxt, "303: Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "304: Invalid character in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* start character */
|
||||
strcpy(dest, "313111");
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
lookup(NEON, C25IndustTable, source[i], dest);
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
strcat(dest, "31113");
|
||||
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, source);
|
||||
return error_number;
|
||||
return c25_common(symbol, source, length, 45, C25IndustTable, C25IndustStartStop, 303);
|
||||
}
|
||||
|
||||
/* Code 2 of 5 IATA */
|
||||
INTERNAL int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
int i, error_number;
|
||||
char dest[512]; /* 4 + 45 * 10 + 3 + 1 = 458 */
|
||||
|
||||
if (length > 45) {
|
||||
strcpy(symbol->errtxt, "305: Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "306: Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* start */
|
||||
strcpy(dest, "1111");
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
lookup(NEON, C25IndustTable, source[i], dest);
|
||||
}
|
||||
|
||||
/* stop */
|
||||
strcat(dest, "311");
|
||||
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, source);
|
||||
return error_number;
|
||||
return c25_common(symbol, source, length, 45, C25IndustTable, C25IataLogicStartStop, 305);
|
||||
}
|
||||
|
||||
/* Code 2 of 5 Data Logic */
|
||||
INTERNAL int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
|
||||
int i, error_number;
|
||||
char dest[512]; /* 4 + 80 * 6 + 3 + 1 = 488 */
|
||||
|
||||
if (length > 80) {
|
||||
strcpy(symbol->errtxt, "307: Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "308: Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* start character */
|
||||
strcpy(dest, "1111");
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
lookup(NEON, C25MatrixTable, source[i], dest);
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
strcat(dest, "311");
|
||||
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, source);
|
||||
return error_number;
|
||||
return c25_common(symbol, source, length, 80, C25MatrixTable, C25IataLogicStartStop, 307);
|
||||
}
|
||||
|
||||
/* Code 2 of 5 Interleaved */
|
||||
INTERNAL int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
|
||||
int i, j, error_number;
|
||||
char bars[7], spaces[7], mixed[14], dest[512]; /* 4 + 90 * 5 + 3 + 1 = 458 */
|
||||
#ifndef _MSC_VER
|
||||
unsigned char temp[length + 2];
|
||||
#else
|
||||
unsigned char* temp = (unsigned char *) _alloca((length + 2) * sizeof (unsigned char));
|
||||
#endif
|
||||
char bars[7], spaces[7], mixed[14], dest[512]; /* 4 + (90 + 2) * 5 + 3 + 1 = 468 */
|
||||
unsigned char temp[90 + 2 + 1];
|
||||
int have_checkdigit = symbol->option_2 == 1 || symbol->option_2 == 2;
|
||||
|
||||
if (length > 90) {
|
||||
strcpy(symbol->errtxt, "309: Input too long");
|
||||
@ -203,13 +162,20 @@ INTERNAL int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char s
|
||||
|
||||
temp[0] = '\0';
|
||||
/* Input must be an even number of characters for Interlaced 2 of 5 to work:
|
||||
if an odd number of characters has been entered then add a leading zero */
|
||||
if (length & 1) {
|
||||
if an odd number of characters has been entered and no check digit or an even number and have check digit
|
||||
then add a leading zero */
|
||||
if (((length & 1) && !have_checkdigit) || (!(length & 1) && have_checkdigit)) {
|
||||
ustrcpy(temp, "0");
|
||||
length++;
|
||||
}
|
||||
ustrncat(temp, source, length);
|
||||
|
||||
if (have_checkdigit) {
|
||||
/* Add standard GS1 check digit */
|
||||
temp[length] = check_digit(gs1_checksum(temp, length));
|
||||
temp[++length] = '\0';
|
||||
}
|
||||
|
||||
/* start character */
|
||||
strcpy(dest, "1111");
|
||||
|
||||
@ -236,17 +202,20 @@ INTERNAL int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char s
|
||||
strcat(dest, "311");
|
||||
|
||||
expand(symbol, dest);
|
||||
|
||||
ustrcpy(symbol->text, temp);
|
||||
if (symbol->option_2 == 2) {
|
||||
/* Remove check digit from HRT */
|
||||
symbol->text[length - 1] = '\0';
|
||||
}
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Interleaved 2-of-5 (ITF) */
|
||||
INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
int i, error_number, zeroes;
|
||||
unsigned int count;
|
||||
char localstr[16];
|
||||
|
||||
count = 0;
|
||||
unsigned char localstr[16] = {0};
|
||||
|
||||
if (length > 13) {
|
||||
strcpy(symbol->errtxt, "311: Input too long");
|
||||
@ -267,14 +236,7 @@ INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
ustrcpy(localstr + zeroes, source);
|
||||
|
||||
/* Calculate the check digit - the same method used for EAN-13 */
|
||||
for (i = 12; i >= 0; i--) {
|
||||
count += ctoi(localstr[i]);
|
||||
|
||||
if (!(i & 1)) {
|
||||
count += 2 * ctoi(localstr[i]);
|
||||
}
|
||||
}
|
||||
localstr[13] = check_digit(count);
|
||||
localstr[13] = check_digit(gs1_checksum(localstr, 13));
|
||||
localstr[14] = '\0';
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *) localstr, 14);
|
||||
ustrcpy(symbol->text, localstr);
|
||||
@ -295,7 +257,7 @@ INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
int i, error_number;
|
||||
unsigned int count;
|
||||
char localstr[16];
|
||||
unsigned char localstr[16] = {0};
|
||||
int zeroes;
|
||||
|
||||
count = 0;
|
||||
@ -323,7 +285,7 @@ INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int leng
|
||||
}
|
||||
localstr[13] = check_digit(count);
|
||||
localstr[14] = '\0';
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *) localstr, 14);
|
||||
error_number = interleaved_two_of_five(symbol, localstr, 14);
|
||||
ustrcpy(symbol->text, localstr);
|
||||
return error_number;
|
||||
}
|
||||
@ -332,7 +294,7 @@ INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int leng
|
||||
INTERNAL int dpident(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
int i, error_number, zeroes;
|
||||
unsigned int count;
|
||||
char localstr[16];
|
||||
unsigned char localstr[16] = {0};
|
||||
|
||||
count = 0;
|
||||
if (length > 11) {
|
||||
@ -359,7 +321,7 @@ INTERNAL int dpident(struct zint_symbol *symbol, unsigned char source[], int len
|
||||
}
|
||||
localstr[11] = check_digit(count);
|
||||
localstr[12] = '\0';
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *) localstr, 12);
|
||||
error_number = interleaved_two_of_five(symbol, localstr, 12);
|
||||
ustrcpy(symbol->text, localstr);
|
||||
return error_number;
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ static void test_large(int index, int debug) {
|
||||
int ret;
|
||||
struct item {
|
||||
int symbology;
|
||||
int option_2;
|
||||
char *pattern;
|
||||
int length;
|
||||
int ret;
|
||||
@ -46,22 +47,32 @@ static void test_large(int index, int debug) {
|
||||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
|
||||
struct item data[] = {
|
||||
/* 0*/ { BARCODE_C25STANDARD, "1", 80, 0, 1, 817 },
|
||||
/* 1*/ { BARCODE_C25STANDARD, "1", 81, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 2*/ { BARCODE_C25INTER, "1", 90, 0, 1, 819 },
|
||||
/* 3*/ { BARCODE_C25INTER, "1", 91, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 4*/ { BARCODE_C25IATA, "1", 45, 0, 1, 639 },
|
||||
/* 5*/ { BARCODE_C25IATA, "1", 46, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 6*/ { BARCODE_C25LOGIC, "1", 80, 0, 1, 809 },
|
||||
/* 7*/ { BARCODE_C25LOGIC, "1", 81, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 8*/ { BARCODE_C25IND, "1", 45, 0, 1, 649 },
|
||||
/* 9*/ { BARCODE_C25IND, "1", 46, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 10*/ { BARCODE_DPLEIT, "1", 13, 0, 1, 135 },
|
||||
/* 11*/ { BARCODE_DPLEIT, "1", 14, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 12*/ { BARCODE_DPIDENT, "1", 11, 0, 1, 117 },
|
||||
/* 13*/ { BARCODE_DPIDENT, "1", 12, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 14*/ { BARCODE_ITF14, "1", 13, 0, 1, 135 },
|
||||
/* 15*/ { BARCODE_ITF14, "1", 14, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 0*/ { BARCODE_C25STANDARD, -1, "1", 80, 0, 1, 817 },
|
||||
/* 1*/ { BARCODE_C25STANDARD, -1, "1", 81, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 2*/ { BARCODE_C25STANDARD, 1, "1", 80, 0, 1, 827 },
|
||||
/* 3*/ { BARCODE_C25STANDARD, 1, "1", 81, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 4*/ { BARCODE_C25INTER, -1, "1", 90, 0, 1, 819 },
|
||||
/* 5*/ { BARCODE_C25INTER, -1, "1", 91, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 6*/ { BARCODE_C25INTER, 1, "1", 90, 0, 1, 837 },
|
||||
/* 7*/ { BARCODE_C25INTER, 1, "1", 91, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 8*/ { BARCODE_C25IATA, -1, "1", 45, 0, 1, 639 },
|
||||
/* 9*/ { BARCODE_C25IATA, -1, "1", 46, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 10*/ { BARCODE_C25IATA, 1, "1", 45, 0, 1, 653 },
|
||||
/* 11*/ { BARCODE_C25IATA, 1, "1", 46, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 12*/ { BARCODE_C25LOGIC, -1, "1", 80, 0, 1, 809 },
|
||||
/* 13*/ { BARCODE_C25LOGIC, -1, "1", 81, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 14*/ { BARCODE_C25LOGIC, 1, "1", 80, 0, 1, 819 },
|
||||
/* 15*/ { BARCODE_C25LOGIC, 1, "1", 81, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 16*/ { BARCODE_C25IND, -1, "1", 45, 0, 1, 649 },
|
||||
/* 17*/ { BARCODE_C25IND, -1, "1", 46, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 18*/ { BARCODE_C25IND, 1, "1", 45, 0, 1, 663 },
|
||||
/* 19*/ { BARCODE_C25IND, 1, "1", 46, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 20*/ { BARCODE_DPLEIT, -1, "1", 13, 0, 1, 135 },
|
||||
/* 21*/ { BARCODE_DPLEIT, -1, "1", 14, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 22*/ { BARCODE_DPIDENT, -1, "1", 11, 0, 1, 117 },
|
||||
/* 23*/ { BARCODE_DPIDENT, -1, "1", 12, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
/* 24*/ { BARCODE_ITF14, -1, "1", 13, 0, 1, 135 },
|
||||
/* 25*/ { BARCODE_ITF14, -1, "1", 14, ZINT_ERROR_TOO_LONG, -1, -1 },
|
||||
};
|
||||
int data_size = ARRAY_SIZE(data);
|
||||
|
||||
@ -77,7 +88,7 @@ static void test_large(int index, int debug) {
|
||||
testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length);
|
||||
assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf));
|
||||
|
||||
int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, -1 /*output_options*/, data_buf, data[i].length, debug);
|
||||
int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug);
|
||||
|
||||
ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length);
|
||||
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
|
||||
@ -100,22 +111,36 @@ static void test_hrt(int index, int debug) {
|
||||
int ret;
|
||||
struct item {
|
||||
int symbology;
|
||||
int option_2;
|
||||
char *data;
|
||||
char *expected;
|
||||
};
|
||||
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
|
||||
struct item data[] = {
|
||||
/* 0*/ { BARCODE_C25STANDARD, "123456789", "123456789" },
|
||||
/* 1*/ { BARCODE_C25INTER, "123456789", "0123456789" }, // Adds leading zero if odd
|
||||
/* 2*/ { BARCODE_C25IATA, "123456789", "123456789" },
|
||||
/* 3*/ { BARCODE_C25LOGIC, "123456789", "123456789" },
|
||||
/* 4*/ { BARCODE_C25IND, "123456789", "123456789" },
|
||||
/* 5*/ { BARCODE_DPLEIT, "123456789", "00001234567890" }, // Leading zeroes added to make 13 + appended checksum
|
||||
/* 6*/ { BARCODE_DPLEIT, "1234567890123", "12345678901236" },
|
||||
/* 7*/ { BARCODE_DPIDENT, "123456789", "001234567890" }, // Leading zeroes added to make 11 + appended checksum
|
||||
/* 8*/ { BARCODE_DPIDENT, "12345678901", "123456789016" },
|
||||
/* 9*/ { BARCODE_ITF14, "123456789", "00001234567895" }, // Leading zeroes added to make 13 + appended checksum
|
||||
/* 10*/ { BARCODE_ITF14, "1234567890123", "12345678901231" },
|
||||
/* 0*/ { BARCODE_C25STANDARD, -1, "123456789", "123456789" },
|
||||
/* 1*/ { BARCODE_C25STANDARD, 1, "123456789", "1234567895" },
|
||||
/* 2*/ { BARCODE_C25STANDARD, 2, "123456789", "123456789" }, // Suppresses printing of check digit
|
||||
/* 3*/ { BARCODE_C25INTER, -1, "123456789", "0123456789" }, // Adds leading zero if odd
|
||||
/* 4*/ { BARCODE_C25INTER, 1, "123456789", "1234567895" }, // Unless check digit added when it becomes even
|
||||
/* 5*/ { BARCODE_C25INTER, 2, "123456789", "123456789" },
|
||||
/* 6*/ { BARCODE_C25INTER, -1, "1234567890", "1234567890" }, // No leading zero if even
|
||||
/* 7*/ { BARCODE_C25INTER, 1, "1234567890", "012345678905" }, // Unless check digit added when it becomes odd
|
||||
/* 8*/ { BARCODE_C25INTER, 2, "1234567890", "01234567890" },
|
||||
/* 9*/ { BARCODE_C25IATA, -1, "123456789", "123456789" },
|
||||
/* 10*/ { BARCODE_C25IATA, 1, "123456789", "1234567895" },
|
||||
/* 11*/ { BARCODE_C25IATA, 2, "123456789", "123456789" },
|
||||
/* 12*/ { BARCODE_C25LOGIC, -1, "123456789", "123456789" },
|
||||
/* 13*/ { BARCODE_C25LOGIC, 1, "123456789", "1234567895" },
|
||||
/* 14*/ { BARCODE_C25LOGIC, 2, "123456789", "123456789" },
|
||||
/* 15*/ { BARCODE_C25IND, -1, "123456789", "123456789" },
|
||||
/* 16*/ { BARCODE_C25IND, 1, "123456789", "1234567895" },
|
||||
/* 17*/ { BARCODE_C25IND, 2, "123456789", "123456789" },
|
||||
/* 18*/ { BARCODE_DPLEIT, -1, "123456789", "00001234567890" }, // Leading zeroes added to make 13 + appended checksum
|
||||
/* 19*/ { BARCODE_DPLEIT, -1, "1234567890123", "12345678901236" },
|
||||
/* 20*/ { BARCODE_DPIDENT, -1, "123456789", "001234567890" }, // Leading zeroes added to make 11 + appended checksum
|
||||
/* 21*/ { BARCODE_DPIDENT, -1, "12345678901", "123456789016" },
|
||||
/* 22*/ { BARCODE_ITF14, -1, "123456789", "00001234567895" }, // Leading zeroes added to make 13 + appended checksum
|
||||
/* 23*/ { BARCODE_ITF14, -1, "1234567890123", "12345678901231" },
|
||||
};
|
||||
int data_size = ARRAY_SIZE(data);
|
||||
|
||||
@ -126,7 +151,7 @@ static void test_hrt(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*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
|
||||
int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
|
||||
|
||||
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
|
||||
assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt);
|
||||
@ -196,6 +221,7 @@ static void test_encode(int index, int generate, int debug) {
|
||||
int ret;
|
||||
struct item {
|
||||
int symbology;
|
||||
int option_2;
|
||||
char *data;
|
||||
int ret;
|
||||
|
||||
@ -206,46 +232,67 @@ static void test_encode(int index, int generate, int debug) {
|
||||
};
|
||||
// BARCODE_ITF14 examples verified manually against GS1 General Specifications 21.0.1
|
||||
struct item data[] = {
|
||||
/* 0*/ { BARCODE_C25STANDARD, "87654321", 0, 1, 97, "Standard Code 2 of 5; note zint uses 4X start/end wides while BWIPP uses 3X",
|
||||
/* 0*/ { BARCODE_C25STANDARD, -1, "87654321", 0, 1, 97, "Standard Code 2 of 5; note zint uses 4X start/end wides while BWIPP uses 3X",
|
||||
"1111010101110100010101000111010001110101110111010101110111011100010101000101110111010111011110101"
|
||||
},
|
||||
/* 1*/ { BARCODE_C25INTER, "87654321", 0, 1, 81, "Interleaved Code 2 of 5; verified manually against tec-it",
|
||||
/* 1*/ { BARCODE_C25STANDARD, 1, "87654321", 0, 1, 107, "With check digit",
|
||||
"11110101011101000101010001110100011101011101110101011101110111000101010001011101110101110100010111011110101"
|
||||
},
|
||||
/* 2*/ { BARCODE_C25INTER, -1, "87654321", 0, 1, 81, "Interleaved Code 2 of 5, even; verified manually against tec-it",
|
||||
"101011101010111000100010001110111000101010001000111010111010001110101011100011101"
|
||||
},
|
||||
/* 2*/ { BARCODE_C25INTER, "602003", 0, 1, 63, "DX cartridge barcode https://en.wikipedia.org/wiki/Interleaved_2_of_5 example",
|
||||
/* 3*/ { BARCODE_C25INTER, 1, "87654321", 0, 1, 99, "With check digit",
|
||||
"101010001011101110001010100010001110111011101011100010100011101110001010100011101000101011100011101"
|
||||
},
|
||||
/* 4*/ { BARCODE_C25INTER, -1, "7654321", 0, 1, 81, "Interleaved Code 2 of 5, odd",
|
||||
"101010101110111000100010001110111000101010001000111010111010001110101011100011101"
|
||||
},
|
||||
/* 5*/ { BARCODE_C25INTER, 1, "7654321", 0, 1, 81, "With check digit",
|
||||
"101010100010001110111011101011100010100011101110001010100011101010001000111011101"
|
||||
},
|
||||
/* 6*/ { BARCODE_C25INTER, -1, "602003", 0, 1, 63, "DX cartridge barcode https://en.wikipedia.org/wiki/Interleaved_2_of_5 example",
|
||||
"101010111011100010001010111010001000111010001000111011101011101"
|
||||
},
|
||||
/* 3*/ { BARCODE_C25IATA, "87654321", 0, 1, 121, "IATA Code 2 of 5; verified manually against tec-it",
|
||||
/* 7*/ { BARCODE_C25IATA, -1, "87654321", 0, 1, 121, "IATA Code 2 of 5; verified manually against tec-it",
|
||||
"1010111010101110101010101110111010111011101010111010111010101010111010111011101110101010101110101011101110101010111011101"
|
||||
},
|
||||
/* 4*/ { BARCODE_C25LOGIC, "87654321", 0, 1, 89, "Code 2 of 5 Data Logic; verified manually against tec-it",
|
||||
/* 8*/ { BARCODE_C25IATA, 1, "87654321", 0, 1, 135, "With check digit",
|
||||
"101011101010111010101010111011101011101110101011101011101010101011101011101110111010101010111010101110111010101011101011101010111011101"
|
||||
},
|
||||
/* 9*/ { BARCODE_C25LOGIC, -1, "87654321", 0, 1, 89, "Code 2 of 5 Data Logic; verified manually against tec-it",
|
||||
"10101110100010101000111010001110101110111010101110111011100010101000101110111010111011101"
|
||||
},
|
||||
/* 5*/ { BARCODE_C25IND, "87654321", 0, 1, 131, "Industrial Code 2 of 5; verified manually against tec-it",
|
||||
/* 10*/ { BARCODE_C25LOGIC, 1, "87654321", 0, 1, 99, "With check digit",
|
||||
"101011101000101010001110100011101011101110101011101110111000101010001011101110101110100010111011101"
|
||||
},
|
||||
/* 11*/ { BARCODE_C25IND, -1, "87654321", 0, 1, 131, "Industrial Code 2 of 5; verified manually against tec-it",
|
||||
"11101110101110101011101010101011101110101110111010101110101110101010101110101110111011101010101011101010111011101010101110111010111"
|
||||
},
|
||||
/* 6*/ { BARCODE_DPLEIT, "0000087654321", 0, 1, 135, "Deutsche Post Leitcode; verified manually against tec-it",
|
||||
/* 12*/ { BARCODE_C25IND, 1, "87654321", 0, 1, 145, "With check digit",
|
||||
"1110111010111010101110101010101110111010111011101010111010111010101010111010111011101110101010101110101011101110101010111010111010101110111010111"
|
||||
},
|
||||
/* 13*/ { BARCODE_DPLEIT, -1, "0000087654321", 0, 1, 135, "Deutsche Post Leitcode; verified manually against tec-it",
|
||||
"101010101110001110001010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000100010111011101"
|
||||
},
|
||||
/* 7*/ { BARCODE_DPLEIT, "5082300702800", 0, 1, 135, "Deutsche Post Leitcode https://de.wikipedia.org/wiki/Leitcode example",
|
||||
/* 14*/ { BARCODE_DPLEIT, -1, "5082300702800", 0, 1, 135, "Deutsche Post Leitcode https://de.wikipedia.org/wiki/Leitcode example",
|
||||
"101011101011100010001011101000101110100011101110100010001010101110111000100010100011101110100011101010001110001010001011100011101011101"
|
||||
},
|
||||
/* 8*/ { BARCODE_DPIDENT, "00087654321", 0, 1, 117, "Deutsche Post Identcode; verified manually against tec-it",
|
||||
/* 15*/ { BARCODE_DPIDENT, -1, "00087654321", 0, 1, 117, "Deutsche Post Identcode; verified manually against tec-it",
|
||||
"101010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000100010111011101"
|
||||
},
|
||||
/* 9*/ { BARCODE_DPIDENT, "39601313414", 0, 1, 117, "Deutsche Post Identcode https://de.wikipedia.org/wiki/Leitcode example",
|
||||
/* 16*/ { BARCODE_DPIDENT, -1, "39601313414", 0, 1, 117, "Deutsche Post Identcode https://de.wikipedia.org/wiki/Leitcode example",
|
||||
"101011101110001010001010111011100010001011100010001010111011100010001010111010001011101011100010101110001000111011101"
|
||||
},
|
||||
/* 10*/ { BARCODE_ITF14, "0000087654321", 0, 1, 135, "ITF-14; verified manually against tec-it",
|
||||
/* 17*/ { BARCODE_ITF14, -1, "0000087654321", 0, 1, 135, "ITF-14; verified manually against tec-it",
|
||||
"101010101110001110001010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000101011100011101"
|
||||
},
|
||||
/* 11*/ { BARCODE_ITF14, "0950110153000", 0, 1, 135, "GS1 General Specifications Figure 5.1-2",
|
||||
/* 18*/ { BARCODE_ITF14, -1, "0950110153000", 0, 1, 135, "GS1 General Specifications Figure 5.1-2",
|
||||
"101010100011101110001011101011100010001011100010101011100010001011101110100011100010001110101010101110001110001010001000111011101011101"
|
||||
},
|
||||
/* 12*/ { BARCODE_ITF14, "1540014128876", 0, 1, 135, "GS1 General Specifications Figure 5.3.2.4-1",
|
||||
/* 19*/ { BARCODE_ITF14, -1, "1540014128876", 0, 1, 135, "GS1 General Specifications Figure 5.3.2.4-1",
|
||||
"101011100010100010111010101110001000111010001011101110100010001011101011100010001110101000111011101010111000100010001110001110101011101"
|
||||
},
|
||||
/* 13*/ { BARCODE_ITF14, "0950110153001", 0, 1, 135, "GS1 General Specifications Figure 5.3.6-1",
|
||||
/* 20*/ { BARCODE_ITF14, -1, "0950110153001", 0, 1, 135, "GS1 General Specifications Figure 5.3.6-1",
|
||||
"101010100011101110001011101011100010001011100010101011100010001011101110100011100010001110101010101110001110001011101010001000111011101"
|
||||
},
|
||||
};
|
||||
@ -262,14 +309,14 @@ static void test_encode(int index, int generate, 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*/, -1 /*option_1*/, -1 /*option_2*/, -1, -1 /*output_options*/, data[i].data, -1, debug);
|
||||
int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -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\", %s, %d, %d, \"%s\",\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
|
||||
printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n",
|
||||
i, testUtilBarcodeName(data[i].symbology), data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
|
||||
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
|
||||
testUtilModulesPrint(symbol, " ", "\n");
|
||||
printf(" },\n");
|
||||
@ -282,8 +329,8 @@ static void test_encode(int index, int generate, int debug) {
|
||||
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
|
||||
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
|
||||
|
||||
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) {
|
||||
ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, bwipp_buf, sizeof(bwipp_buf));
|
||||
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) {
|
||||
ret = testUtilBwipp(i, symbol, -1, data[i].option_2, -1, data[i].data, length, NULL, bwipp_buf, sizeof(bwipp_buf));
|
||||
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
|
||||
|
||||
ret = testUtilBwippCmp(symbol, bwipp_msg, bwipp_buf, data[i].expected);
|
||||
|
@ -1758,12 +1758,12 @@ static const char *testUtilBwippName(int index, const struct zint_symbol *symbol
|
||||
static const struct item data[] = {
|
||||
{ "", -1, 0, 0, 0, 0, 0, 0, },
|
||||
{ "code11", BARCODE_CODE11, 1, 0, 1, 0, 0, 0, },
|
||||
{ "matrix2of5", BARCODE_C25STANDARD, 2, 0, 0, 0, 0, 0, },
|
||||
{ "interleaved2of5", BARCODE_C25INTER, 3, 0, 0, 0, 0, 0, },
|
||||
{ "iata2of5", BARCODE_C25IATA, 4, 0, 0, 0, 0, 0, },
|
||||
{ "matrix2of5", BARCODE_C25STANDARD, 2, 0, 1, 0, 0, 0, },
|
||||
{ "interleaved2of5", BARCODE_C25INTER, 3, 0, 1, 0, 0, 0, },
|
||||
{ "iata2of5", BARCODE_C25IATA, 4, 0, 1, 0, 0, 0, },
|
||||
{ "", -1, 5, 0, 0, 0, 0, 0, },
|
||||
{ "datalogic2of5", BARCODE_C25LOGIC, 6, 0, 0, 0, 0, 0, },
|
||||
{ "industrial2of5", BARCODE_C25IND, 7, 0, 0, 0, 0, 0, },
|
||||
{ "datalogic2of5", BARCODE_C25LOGIC, 6, 0, 1, 0, 0, 0, },
|
||||
{ "industrial2of5", BARCODE_C25IND, 7, 0, 1, 0, 0, 0, },
|
||||
{ "code39", BARCODE_CODE39, 8, 0, 1, 0, 0, 0, },
|
||||
{ "code39ext", BARCODE_EXCODE39, 9, 0, 1, 0, 0, 0, },
|
||||
{ "", -1, 10, 0, 0, 0, 0, 0, },
|
||||
@ -2239,7 +2239,13 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
|
||||
bwipp_opts = bwipp_opts_buf;
|
||||
}
|
||||
|
||||
if (symbology == BARCODE_CODE93) {
|
||||
if (symbology == BARCODE_C25STANDARD || symbology == BARCODE_C25INTER || symbology == BARCODE_C25IATA
|
||||
|| symbology == BARCODE_C25LOGIC || symbology == BARCODE_C25IND) {
|
||||
if (option_2 == 1 || option_2 == 2) { // Add check digit without or with HRT suppression
|
||||
sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sincludecheck", strlen(bwipp_opts_buf) ? " " : "");
|
||||
bwipp_opts = bwipp_opts_buf;
|
||||
}
|
||||
} else if (symbology == BARCODE_CODE93) {
|
||||
sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sincludecheck", strlen(bwipp_opts_buf) ? " " : "");
|
||||
if (parse) {
|
||||
bwipp_barcode = "code93ext";
|
||||
|
Reference in New Issue
Block a user