EAN128_CC ecc, cc_width, rows and alignment adjustments

This commit is contained in:
gitlost 2019-11-05 14:16:48 +00:00
parent fac9b94f1b
commit 3b87cd4ec6
10 changed files with 191 additions and 41 deletions

View file

@ -34,6 +34,7 @@
//#define TEST_EXAMPLES_GENERATE_EXPECTED 1
//#define TEST_ODD_NUMBERED_NUMERIC_GENERATE_EXPECTED 1
//#define TEST_EAN128_CC_SHIFT_GENERATE_EXPECTED 1
//#define TEST_EAN128_CC_WIDTH_GENERATE_EXPECTED 1
//#define TEST_ENCODATION_0_GENERATE_EXPECTED 1
//#define TEST_ENCODATION_10_GENERATE_EXPECTED 1
//#define TEST_ENCODATION_11_GENERATE_EXPECTED 1
@ -282,6 +283,15 @@ static void test_examples(void)
"000000111001111101010100001010100101011111000010100000000000000000000000000000000000000000000000000000"
"010111000110000010100011110000001010100000111101000100000000000000000000000000000000000000000000000000"
},
/*13*/ { BARCODE_EAN128_CC, "[00]030123456789012340", "[02]13012345678909[37]24[10]1234567ABCDEFG", 3, 0, 0, 0, 7, 174, "24723:2010 Figure 12 — A GS1-128 Composite symbol (with CC-C)",
"111111110101010001111010101111000011010111011110000111011111011101001000001000010001011110101100111110111010010001110001000100011000011011111010100111110111111101000101001000"
"111111110101010001111110101000111010000100111101000110011110101111101111010001010000011111000110010100111001011100011001001001111101100011111101010111000111111101000101001000"
"111111110101010001010100011110000011001111100001010110100010111110001110111101011100011000001101011110101111001000000101100001011111101011101010001111110111111101000101001000"
"111111110101010001010111100111100011110100001011110101011111011111001101010000110000011010011100011110101111001111010001100011101101000011101001011100000111111101000101001000"
"111111110101010001110101110000110011111010100011000100100001111000101110000001011001011110010110001100111100101101100001111011000110100011101011100110000111111101000101001000"
"000000000101100011000010100010010011001101101100111001100100110001001000101000100111011110100110010010000100110010011000100100010011101011101000010001000100001010011100010100"
"000000011010011100111101011101101100110010010011000110011011001110110111010111011000100001011001101101111011001101100111011011101100010100010111101110111011110101100011101011"
},
};
int data_size = sizeof(data) / sizeof(struct item);
@ -579,6 +589,69 @@ static void test_ean128_cc_shift(void)
testFinish();
}
static void test_ean128_cc_width(void)
{
testStart("");
int ret;
struct item {
unsigned char* data;
unsigned char* composite;
int ret;
int expected_rows;
int expected_width;
char* comment;
};
// Verified manually with bwipp (except very large tests)
struct item data[] = {
/* 0*/ { "[91]1", "[02]13012345678909", 0, 11, 103, "" },
/* 1*/ { "[91]12", "[02]13012345678909", 0, 20, 86, "" },
/* 2*/ { "[91]123", "[02]13012345678909", 0, 11, 108, "" },
/* 3*/ { "[91]123A", "[02]13012345678909", 0, 8, 120, "" },
/* 4*/ { "[91]123A1", "[02]13012345678909", 0, 7, 137, "" },
/* 5*/ { "[91]123A12", "[02]13012345678909", 0, 7, 141, "" },
/* 6*/ { "[91]123A123", "[02]13012345678909", 0, 6, 154, "" },
/* 7*/ { "[91]123A1234", "[02]13012345678909", 0, 6, 154, "" },
/* 8*/ { "[91]123A1234A", "[02]13012345678909", 0, 5, 174, "" },
/* 9*/ { "[91]123A1234A1", "[02]13012345678909", 0, 5, 188, "" },
/*10*/ { "[91]123A1234A12", "[02]13012345678909", 0, 5, 205, "" },
/*11*/ { "[00]123456789012345678", "[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[91]1234567890", 0, 32, 579, "With composite 2372 digits == max" },
/*12*/ { "[00]123456789012345678", "[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[00]123456789012345678[91]12345678901", ZINT_ERROR_TOO_LONG, 0, 0, "With composite 2373 digits > max" },
};
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 = BARCODE_EAN128_CC;
symbol->option_1 = 3;
int length = strlen(data[i].data);
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, data[i].composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d %s\n", i, ret, data[i].ret, symbol->errtxt);
#ifdef TEST_EAN128_CC_WIDTH_GENERATE_EXPECTED
printf(" /*%2d*/ { \"%s\", \"%s\", %s, %d, %d, \"%s\" },\n",
i, data[i].data, data[i].composite, testUtilErrorName(ret), symbol->rows, symbol->width, data[i].comment);
#else
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
#endif
ZBarcode_Delete(symbol);
}
testFinish();
}
// Test general-purpose data compaction
static void test_encodation_0(void)
{
@ -1539,13 +1612,14 @@ static void test_encodation_11(void)
int main()
{
test_eanx_leading_zeroes();
test_examples();
test_odd_numbered_numeric();
test_ean128_cc_shift();
test_ean128_cc_width();
test_encodation_0();
test_encodation_10();
test_encodation_11();
test_eanx_leading_zeroes();
testReport();

View file

@ -34,6 +34,7 @@
//#define TEST_RSS_BINARY_DIV_MODULO_DIVISOR_GENERATE_EXPECTED 1
//#define TEST_EXAMPLES_GENERATE_EXPECTED 1
//#define TEST_GENERAL_FIELD_GENERATE_EXPECTED 1
//#define TEST_BINARY_BUFFER_SIZE_GENERATE_EXPECTED 1
static void test_binary_div_modulo_divisor(void)
{
@ -533,11 +534,63 @@ static void test_general_field(void)
testFinish();
}
static void test_binary_buffer_size(void)
{
testStart("");
int ret;
struct item {
unsigned char* data;
int ret;
int expected_rows;
int expected_width;
char* comment;
};
struct item data[] = {
/* 0*/ { "[91]1", 0, 1, 102, "Minimum digit" },
/* 1*/ { "[91]+", 0, 1, 102, "Minimum ISO-646" },
/* 2*/ { "[00]123456789012345678[00]123456789012345678[00]123456789012345678[91]12345678", 0, 1, 543, "70 == any AIs max" },
/* 3*/ { "[00]123456789012345678[00]123456789012345678[00]123456789012345678[91]123456789", ZINT_ERROR_TOO_LONG, 0, 0, "71 > any AIs max" },
/* 4*/ { "[01]12345678901234[00]123456789012345678[00]123456789012345678[91]1234567890123456", 0, 1, 543, "74 == 01 + other AIs max" },
/* 5*/ { "[01]12345678901234[00]123456789012345678[00]123456789012345678[91]12345678901234567", ZINT_ERROR_TOO_LONG, 0, 0, "75 > 01 + other AIs max" },
/* 6*/ { "[01]92345678901234[3920]123456789012345[00]123456789012345678[91]1234567890123456789", 0, 1, 543, "77 (incl. FNC1 after 3920) == 01 + 392x + other AIs max" },
/* 7*/ { "[01]92345678901234[3920]123456789012345[00]123456789012345678[91]12345678901234567890", ZINT_ERROR_TOO_LONG, 0, 0, "78 > 01 + 392x + other AIs max" },
};
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 = BARCODE_RSS_EXP;
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_BINARY_BUFFER_SIZE_GENERATE_EXPECTED
printf(" /*%2d*/ { \"%s\", %s, %d, %d, \"%s\" },\n",
i, data[i].data, testUtilErrorName(ret), symbol->rows, symbol->width, data[i].comment);
#else
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
#endif
ZBarcode_Delete(symbol);
}
testFinish();
}
int main()
{
test_binary_div_modulo_divisor();
test_examples();
test_general_field();
test_binary_buffer_size();
testReport();