general: change BARCODE_RAW_TEXT to write to new zint_symbol

fields `raw_segs` and `raw_seg_count` instead of `text`, and to
  do so for all symbologies, using new common funcs `rt_cpy()` etc.
MICROPDF417: return ECC percentage in top byte of `option_1`
DBAR_EXP_STK: return `option_2`/`option_3` feedback
CLI: change warning text "ignoring" -> "**IGNORED**"
GUI: show feedback for DBAR_EXP_STK, MICROPDF417, UPNQR
ctest: fix recent inability to run tests via "ctest" on Windows
  (MSVC) by using cmake 3.22 feature `ENVIRONMENT_MODIFICATION`
manual: document feedback and RAW_TEXT in new "Feedback" section;
  rephrase some symbology descriptions
test suite: new general-use arg "-a"; add `func_name` to context;
  new "test_bwipp" test for testing BWIPP against ZXing-C++
This commit is contained in:
gitlost 2025-03-28 10:02:19 +00:00
parent d1bf02e156
commit a6c225447e
120 changed files with 10511 additions and 5620 deletions

View file

@ -55,7 +55,7 @@ static void test_large(const testCtx *const p_ctx) {
char data_buf[4096];
testStartSymbol("test_large", &symbol);
testStartSymbol(p_ctx->func_name, &symbol);
for (i = 0; i < data_size; i++) {
@ -149,7 +149,7 @@ static void test_input(const testCtx *const p_ctx) {
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStartSymbol("test_input", &symbol);
testStartSymbol(p_ctx->func_name, &symbol);
for (i = 0; i < data_size; i++) {
@ -256,7 +256,7 @@ static void test_encode(const testCtx *const p_ctx) {
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStartSymbol("test_encode", &symbol);
testStartSymbol(p_ctx->func_name, &symbol);
for (i = 0; i < data_size; i++) {
@ -304,12 +304,91 @@ static void test_encode(const testCtx *const p_ctx) {
testFinish();
}
static void test_rt(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int input_mode;
int output_options;
const char *data;
int length;
int ret;
int expected_eci;
const char *expected;
int expected_length;
int expected_raw_eci;
};
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
static const struct item data[] = {
/* 0*/ { UNICODE_MODE, -1, "AB\000123", 6, 0, 0, "", -1, 0 },
/* 1*/ { UNICODE_MODE, BARCODE_RAW_TEXT, "AB\000123", 6, 0, 0, "AB\000123", 6, 3 },
/* 2*/ { DATA_MODE, -1, "AB\000123", 6, 0, 0, "", -1, 0 },
/* 3*/ { DATA_MODE, BARCODE_RAW_TEXT, "AB\000123", 6, 0, 0, "AB\000123", 6, 3 },
/* 4*/ { GS1_MODE, -1, "[01]04912345123459[15]970331[30]128[10]ABC123", -1, 0, 0, "", -1, 0 },
/* 5*/ { GS1_MODE, BARCODE_RAW_TEXT, "[01]04912345123459[15]970331[30]128[10]ABC123", -1, 0, 0, "01049123451234591597033130128\03510ABC123", -1, 3 },
};
const int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol *symbol = NULL;
int expected_length;
char escaped[4096];
char escaped2[4096];
testStartSymbol(p_ctx->func_name, &symbol);
for (i = 0; i < data_size; i++) {
if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, BARCODE_CODE49, data[i].input_mode, -1 /*eci*/,
-1 /*option_1*/, -1 /*option_2*/, -1 /*option_3*/, data[i].output_options,
data[i].data, data[i].length, debug);
expected_length = data[i].expected_length == -1 ? (int) strlen(data[i].expected) : data[i].expected_length;
ret = ZBarcode_Encode(symbol, TCU(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 (ret < ZINT_ERROR) {
assert_equal(symbol->eci, data[i].expected_eci, "i:%d eci %d != %d\n",
i, symbol->eci, data[i].expected_eci);
if (symbol->output_options & BARCODE_RAW_TEXT) {
assert_nonnull(symbol->raw_segs, "i:%d raw_segs NULL\n", i);
assert_nonnull(symbol->raw_segs[0].source, "i:%d raw_segs[0].source NULL\n", i);
assert_equal(symbol->raw_segs[0].length, expected_length,
"i:%d raw_segs[0].length %d != expected_length %d\n",
i, symbol->raw_segs[0].length, expected_length);
assert_zero(memcmp(symbol->raw_segs[0].source, data[i].expected, expected_length),
"i:%d raw_segs[0].source memcmp(%s, %s, %d) != 0\n", i,
testUtilEscape((const char *) symbol->raw_segs[0].source, symbol->raw_segs[0].length,
escaped, sizeof(escaped)),
testUtilEscape(data[i].expected, expected_length, escaped2, sizeof(escaped2)),
expected_length);
assert_equal(symbol->raw_segs[0].eci, data[i].expected_raw_eci,
"i:%d raw_segs[0].eci %d != expected_raw_eci %d\n",
i, symbol->raw_segs[0].eci, data[i].expected_raw_eci);
} else {
assert_null(symbol->raw_segs, "i:%d raw_segs not NULL\n", i);
}
}
ZBarcode_Delete(symbol);
}
testFinish();
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
{ "test_large", test_large },
{ "test_input", test_input },
{ "test_encode", test_encode },
{ "test_rt", test_rt },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));