mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
test_bmp/emf/print/ultra: update after pixel/colour changes, new test_ps
This commit is contained in:
@ -112,10 +112,96 @@ static void test_pixel_plot(int index, int debug) {
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_print(int index, int generate, int debug) {
|
||||
|
||||
testStart("");
|
||||
|
||||
int have_identify = testUtilHaveIdentify();
|
||||
|
||||
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_PDF417, 5, -1, -1, "147AD0", "FC9630", "123", "../data/bmp/pdf417_fg_bg.bmp" },
|
||||
/* 1*/ { BARCODE_ULTRA, 5, -1, -1, "147AD0", "FC9630", "123", "../data/bmp/ultracode_fg_bg.bmp" },
|
||||
};
|
||||
int data_size = ARRAY_SIZE(data);
|
||||
|
||||
char* data_dir = "../data/bmp";
|
||||
char* bmp = "out.bmp";
|
||||
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, bmp);
|
||||
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_identify) {
|
||||
ret = testUtilVerifyIdentify(data[i].expected_file, debug);
|
||||
assert_zero(ret, "i:%d %s identify %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_pixel_plot", test_pixel_plot, 1, 0, 1 },
|
||||
{ "test_print", test_print, 1, 1, 1 },
|
||||
};
|
||||
|
||||
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
|
||||
|
Reference in New Issue
Block a user