test_bmp/emf/print/ultra: update after pixel/colour changes, new test_ps

This commit is contained in:
gitlost 2020-08-12 22:16:11 +01:00
parent 09e6d09e6b
commit 4853b4d851
20 changed files with 868 additions and 274 deletions

View file

@ -30,6 +30,7 @@
/* vim: set ts=4 sw=4 et : */
#include "testcommon.h"
#include <sys/stat.h>
static void test_emf(int index, int debug) {
@ -64,13 +65,7 @@ static void test_emf(int index, int debug) {
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
if (data[i].option_1 != -1) {
symbol->option_1 = data[i].option_1;
}
if (data[i].option_2 != -1) {
symbol->option_2 = data[i].option_2;
}
int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
if (data[i].fgcolour != NULL) {
strcpy(symbol->fgcolour, data[i].fgcolour);
}
@ -80,9 +75,6 @@ static void test_emf(int index, int debug) {
if (data[i].scale != 0) {
symbol->scale = data[i].scale;
}
symbol->debug | debug;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_zero(ret, "i:%d %s ZBarcode_Encode ret %d != 0 %s\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt);
@ -103,10 +95,96 @@ static void test_emf(int index, int debug) {
testFinish();
}
static void test_print(int index, int generate, int debug) {
testStart("");
int have_inkscape = testUtilHaveInkscape();
int ret;
struct item {
int symbology;
int whitespace_width;
int option_1;
int option_2;
char *fgcolour;
char *bgcolour;
unsigned char* data;
char* expected_file;
};
struct item data[] = {
/* 0*/ { BARCODE_TELEPEN, -1, -1, -1, "147AD0", "FC9630", "123", "../data/emf/telenum_fg_bg.emf" },
/* 1*/ { BARCODE_ULTRA, 5, -1, -1, "147AD0", "FC9630", "123", "../data/emf/ultracode_fg_bg.emf" },
};
int data_size = ARRAY_SIZE(data);
char* data_dir = "../data/emf";
char* emf = "out.emf";
char escaped[1024];
int escaped_size = 1024;
if (generate) {
if (!testUtilExists(data_dir)) {
ret = mkdir(data_dir, 0755);
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
}
}
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
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*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
if (data[i].whitespace_width != -1) {
symbol->whitespace_width = data[i].whitespace_width;
}
if (data[i].fgcolour != NULL) {
strcpy(symbol->fgcolour, data[i].fgcolour);
}
if (data[i].bgcolour != NULL) {
strcpy(symbol->bgcolour, data[i].bgcolour);
}
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_zero(ret, "i:%d %s ZBarcode_Encode ret %d != 0 %s\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt);
strcpy(symbol->outfile, emf);
ret = ZBarcode_Print(symbol, 0);
assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret);
if (generate) {
printf(" /*%3d*/ { %s, %d, %d, %d, \"%s\", \"%s\", \"%s\", \"%s\"},\n",
i, testUtilBarcodeName(data[i].symbology), data[i].whitespace_width, data[i].option_1, data[i].option_2, data[i].fgcolour, data[i].bgcolour,
testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].expected_file);
ret = rename(symbol->outfile, data[i].expected_file);
assert_zero(ret, "i:%d rename(%s, %s) ret %d != 0\n", i, symbol->outfile, data[i].expected_file, ret);
if (have_inkscape) {
ret = testUtilVerifyInkscape(data[i].expected_file, debug);
assert_zero(ret, "i:%d %s inkscape %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), data[i].expected_file, ret);
}
} else {
assert_nonzero(testUtilExists(symbol->outfile), "i:%d testUtilExists(%s) == 0\n", i, symbol->outfile);
assert_nonzero(testUtilExists(data[i].expected_file), "i:%d testUtilExists(%s) == 0\n", i, data[i].expected_file);
ret = testUtilCmpBins(symbol->outfile, data[i].expected_file);
assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, data[i].expected_file, ret);
assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile);
}
ZBarcode_Delete(symbol);
}
testFinish();
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
{ "test_emf", test_emf, 1, 0, 1 },
{ "test_print", test_print, 1, 1, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));