test suite: convert to use test context p_ctx instead of individual

args; new -x exclude option and ranges; no longer use getopt();
  make C89 compat
This commit is contained in:
gitlost
2022-09-12 19:26:04 +01:00
parent 0d4aa6cce3
commit 90dfbdb5d9
58 changed files with 2822 additions and 2340 deletions

View File

@ -27,10 +27,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h"
static void test_large(int index, int debug) {
static void test_large(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int option_1;
@ -42,14 +44,14 @@ static void test_large(int index, int debug) {
int expected_rows;
int expected_width;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = {
/* 0*/ { -1, -1, { 0, 0, "" }, "1", 252, 0, 31, 66 }, // Default EC2
/* 0*/ { -1, -1, { 0, 0, "" }, "1", 252, 0, 31, 66 }, /* Default EC2 */
/* 1*/ { -1, -1, { 0, 0, "" }, "1", 253, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 2*/ { -1, -1, { 0, 0, "" }, "1", ZINT_MAX_DATA_LEN, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 3*/ { -1, -1, { 1, 2, "" }, "1", 251, 0, 31, 66 }, // Structured Append no File Number 1 codeword overhead
/* 3*/ { -1, -1, { 1, 2, "" }, "1", 251, 0, 31, 66 }, /* Structured Append no File Number 1 codeword overhead */
/* 4*/ { -1, -1, { 1, 2, "" }, "1", 252, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 5*/ { -1, -1, { 1, 2, "1" }, "1", 249, 0, 31, 66 }, // Structured Append with File Number 3 codewords overhead
/* 5*/ { -1, -1, { 1, 2, "1" }, "1", 249, 0, 31, 66 }, /* Structured Append with File Number 3 codewords overhead */
/* 6*/ { -1, -1, { 1, 2, "1" }, "1", 250, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 7*/ { -1, -1, { 0, 0, "" }, "A", 252, 0, 31, 66 },
/* 8*/ { -1, -1, { 0, 0, "" }, "A", 253, ZINT_ERROR_TOO_LONG, -1, -1 },
@ -92,7 +94,7 @@ static void test_large(int index, int debug) {
for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -119,7 +121,8 @@ static void test_large(int index, int debug) {
testFinish();
}
static void test_reader_init(int index, int generate, int debug) {
static void test_reader_init(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int input_mode;
@ -146,20 +149,19 @@ static void test_reader_init(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_ULTRA, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, data[i].option_3, data[i].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) {
if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options), testUtilOption3Name(data[i].option_3),
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
@ -178,7 +180,8 @@ static void test_reader_init(int index, int generate, int debug) {
testFinish();
}
static void test_input(int index, int generate, int debug) {
static void test_input(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int input_mode;
@ -271,13 +274,12 @@ static void test_input(int index, int generate, int debug) {
for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
symbol->debug = ZINT_DEBUG_TEST; /* Needed to get codeword dump in errtxt */
length = testUtilSetSymbol(symbol, BARCODE_ULTRA, data[i].input_mode, data[i].eci,
data[i].option_1, data[i].option_2, data[i].option_3,
@ -289,7 +291,7 @@ static void test_input(int index, int generate, int 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) {
if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, %d, %s, { %d, %d, \"%s\" }, \"%s\", %s, \"%s\", \"%s\" },\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3),
data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
@ -304,7 +306,8 @@ static void test_input(int index, int generate, int debug) {
testFinish();
}
static void test_encode(int index, int generate, int debug) {
static void test_encode(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int input_mode;
@ -322,8 +325,9 @@ static void test_encode(int index, int generate, int debug) {
char *comment;
char *expected;
};
// Based on AIMD/TSC15032-43 (v 0.99c), with values updated from BWIPP update 2021-07-14
// https://github.com/bwipp/postscriptbarcode/commit/4255810845fa8d45c6192dd30aee1fdad1aaf0cc
/* Based on AIMD/TSC15032-43 (v 0.99c), with values updated from BWIPP update 2021-07-14
https://github.com/bwipp/postscriptbarcode/commit/4255810845fa8d45c6192dd30aee1fdad1aaf0cc
*/
struct item data[] = {
/* 0*/ { UNICODE_MODE, 0, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, "ULTRACODE_123456789!", 0, 13, 22, 1, "AIMD/TSC15032-43 Figure G.1 **NOT SAME** different compression",
"7777777777777777777777"
@ -778,14 +782,13 @@ static void test_encode(int index, int generate, int debug) {
char bwipp_buf[32768];
char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_encode");
for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -798,7 +801,7 @@ static void test_encode(int index, int generate, int 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) {
if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, %d, %s, { %d, %d, \"%s\" }, \"%s\", %s, %d, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].option_3),
data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
@ -836,7 +839,8 @@ static void test_encode(int index, int generate, int debug) {
testFinish();
}
static void test_encode_segs(int index, int generate, int debug) {
static void test_encode_segs(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
int input_mode;
@ -853,8 +857,9 @@ static void test_encode_segs(int index, int generate, int debug) {
char *comment;
char *expected;
};
// Based on AIMD/TSC15032-43 (v 0.99c), with values updated from BWIPP update 2021-07-14
// https://github.com/bwipp/postscriptbarcode/commit/4255810845fa8d45c6192dd30aee1fdad1aaf0cc
/* Based on AIMD/TSC15032-43 (v 0.99c), with values updated from BWIPP update 2021-07-14
https://github.com/bwipp/postscriptbarcode/commit/4255810845fa8d45c6192dd30aee1fdad1aaf0cc
*/
struct item data[] = {
/* 0*/ { UNICODE_MODE, -1, -1, ULTRA_COMPRESSION, { 0, 0, "" }, { { TU(""), -1, 0 }, { TU("Ж"), -1, 7 }, { TU(""), 0, 0 } }, 0, 13, 15, 0, "Standard example; BWIPP no ECI support for Ultracode",
"777777777777777"
@ -1018,14 +1023,13 @@ static void test_encode_segs(int index, int generate, int debug) {
char bwipp_buf[32768];
char bwipp_msg[1024];
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); /* Only do BWIPP test if asked, too slow otherwise */
testStart("test_encode_segs");
for (i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
if (testContinue(p_ctx, i)) continue;
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -1040,7 +1044,7 @@ static void test_encode_segs(int index, int generate, int debug) {
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) {
if (p_ctx->generate) {
char escaped1[4096];
char escaped2[4096];
int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length;
@ -1087,12 +1091,12 @@ static void test_encode_segs(int index, int generate, int debug) {
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_large", test_large, 1, 0, 1 },
{ "test_reader_init", test_reader_init, 1, 1, 1 },
{ "test_input", test_input, 1, 1, 1 },
{ "test_encode", test_encode, 1, 1, 1 },
{ "test_encode_segs", test_encode_segs, 1, 1, 1 },
testFunction funcs[] = { /* name, func */
{ "test_large", test_large },
{ "test_reader_init", test_reader_init },
{ "test_input", test_input },
{ "test_encode", test_encode },
{ "test_encode_segs", test_encode_segs },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));