2020-08-05 09:22:26 +12:00
/*
libzint - the open source barcode library
Copyright ( C ) 2020 Robin Stuart < rstuart114 @ gmail . com >
Redistribution and use in source and binary forms , with or without
modification , are permitted provided that the following conditions
are met :
1. Redistributions of source code must retain the above copyright
notice , this list of conditions and the following disclaimer .
2. Redistributions in binary form must reproduce the above copyright
notice , this list of conditions and the following disclaimer in the
documentation and / or other materials provided with the distribution .
3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission .
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS " AS IS " AND
ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL
DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION )
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT
LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE .
*/
/* vim: set ts=4 sw=4 et : */
# include <errno.h>
# include "testcommon.h"
static char * exec ( const char * cmd , char * buf , int buf_size , int debug , int index ) {
2020-08-05 09:44:20 +12:00
FILE * fp ;
int cnt ;
2020-08-05 09:22:26 +12:00
2020-08-05 09:44:20 +12:00
if ( debug & ZINT_DEBUG_TEST_PRINT ) printf ( " %d: %s \n " , index , cmd ) ;
2020-08-05 09:22:26 +12:00
2020-08-05 09:44:20 +12:00
* buf = ' \0 ' ;
2020-08-05 09:22:26 +12:00
2020-08-05 09:44:20 +12:00
fp = popen ( cmd , " r " ) ;
2020-08-05 09:22:26 +12:00
if ( ! fp ) {
fprintf ( stderr , " exec: failed to run '%s' \n " , cmd ) ;
return NULL ;
}
2020-08-05 09:44:20 +12:00
cnt = fread ( buf , 1 , buf_size , fp ) ;
2020-08-05 09:22:26 +12:00
if ( fgetc ( fp ) ! = EOF ) {
fprintf ( stderr , " exec: failed to read full stream (%s) \n " , cmd ) ;
pclose ( fp ) ;
return NULL ;
}
2020-08-05 09:44:20 +12:00
pclose ( fp ) ;
if ( cnt ) {
if ( buf [ cnt - 1 ] = = ' \r ' | | buf [ cnt - 1 ] = = ' \n ' ) {
buf [ cnt - 1 ] = ' \0 ' ;
if ( buf [ cnt - 2 ] = = ' \r ' | | buf [ cnt - 2 ] = = ' \n ' ) {
buf [ cnt - 2 ] = ' \0 ' ;
}
}
}
return buf ;
2020-08-05 09:22:26 +12:00
}
static void arg_int ( char * cmd , const char * opt , int val ) {
2020-08-05 09:44:20 +12:00
if ( val ! = - 1 ) {
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s%s%d " , strlen ( cmd ) ? " " : " " , opt , val ) ;
}
2020-08-05 09:22:26 +12:00
}
static void arg_bool ( char * cmd , const char * opt , int val ) {
2020-08-05 09:44:20 +12:00
if ( val = = 1 ) {
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s%s " , strlen ( cmd ) ? " " : " " , opt ) ;
}
2020-08-05 09:22:26 +12:00
}
static void arg_double ( char * cmd , const char * opt , double val ) {
2020-08-05 09:44:20 +12:00
if ( val ! = - 1 ) {
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s%s%g " , strlen ( cmd ) ? " " : " " , opt , val ) ;
}
2020-08-05 09:22:26 +12:00
}
static void arg_data ( char * cmd , const char * opt , const char * data ) {
2020-08-05 09:44:20 +12:00
if ( data ! = NULL ) {
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s%s'%s' " , strlen ( cmd ) ? " " : " " , opt , data ) ;
}
2020-08-05 09:22:26 +12:00
}
static int arg_input ( char * cmd , const char * filename , const char * input ) {
2020-08-05 09:44:20 +12:00
FILE * fp ;
int cnt ;
if ( input ! = NULL ) {
fp = fopen ( filename , " wb " ) ;
if ( ! fp ) {
fprintf ( stderr , " arg_input: failed to open '%s' for writing \n " , filename ) ;
return 0 ;
}
cnt = fwrite ( input , 1 , strlen ( input ) , fp ) ;
if ( cnt ! = ( int ) strlen ( input ) ) {
fprintf ( stderr , " arg_input: failed to write %d bytes, cnt %d written (%s) \n " , ( int ) strlen ( input ) , cnt , filename ) ;
fclose ( fp ) ;
return 0 ;
}
fclose ( fp ) ;
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s-i '%s' " , strlen ( cmd ) ? " " : " " , filename ) ;
return 1 ;
}
return 0 ;
2020-08-05 09:22:26 +12:00
}
static void arg_input_mode ( char * cmd , int input_mode ) {
2020-08-05 09:44:20 +12:00
if ( input_mode ! = - 1 ) {
if ( ( input_mode & 0x07 ) = = DATA_MODE ) {
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s--binary " , strlen ( cmd ) ? " " : " " ) ;
} else if ( ( input_mode & 0x07 ) = = GS1_MODE ) {
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s--gs1 " , strlen ( cmd ) ? " " : " " ) ;
}
if ( input_mode & ESCAPE_MODE ) {
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s--esc " , strlen ( cmd ) ? " " : " " ) ;
}
}
2020-08-05 09:22:26 +12:00
}
static void arg_output_options ( char * cmd , int output_options ) {
2020-08-05 09:44:20 +12:00
if ( output_options ! = - 1 ) {
if ( output_options & BARCODE_BIND ) {
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s--bind " , strlen ( cmd ) ? " " : " " ) ;
}
if ( output_options & BARCODE_BOX ) {
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s--box " , strlen ( cmd ) ? " " : " " ) ;
}
if ( output_options & BARCODE_STDOUT ) {
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s--direct " , strlen ( cmd ) ? " " : " " ) ;
}
if ( output_options & READER_INIT ) {
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s--init " , strlen ( cmd ) ? " " : " " ) ;
}
if ( output_options & SMALL_TEXT ) {
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s--small " , strlen ( cmd ) ? " " : " " ) ;
}
if ( output_options & BOLD_TEXT ) {
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s--bold " , strlen ( cmd ) ? " " : " " ) ;
}
if ( output_options & CMYK_COLOUR ) {
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s--cmyk " , strlen ( cmd ) ? " " : " " ) ;
}
if ( output_options & BARCODE_DOTTY_MODE ) {
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s--dotty " , strlen ( cmd ) ? " " : " " ) ;
}
if ( output_options & GS1_GS_SEPARATOR ) {
sprintf ( cmd + ( int ) strlen ( cmd ) , " %s--gssep " , strlen ( cmd ) ? " " : " " ) ;
}
}
2020-08-05 09:22:26 +12:00
}
// Tests args that can be detected with `--dump`
static void test_dump_args ( int index , int debug ) {
testStart ( " " ) ;
int ret ;
struct item {
int b ;
char * data ;
char * data2 ;
2020-08-05 09:44:20 +12:00
char * input ;
char * input2 ;
int input_mode ;
int output_options ;
int batch ;
int cols ;
int dmre ;
int eci ;
int fullmultibyte ;
int mode ;
char * primary ;
int rows ;
int secure ;
int square ;
int vers ;
char * expected ;
2020-08-05 09:22:26 +12:00
} ;
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data [ ] = {
2020-08-05 09:44:20 +12:00
/* 0*/ { - 1 , " 123 " , NULL , NULL , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " D2 13 9B 39 65 C8 C9 8E B " } ,
/* 1*/ { BARCODE_CODE128 , " 123 " , NULL , NULL , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " D2 13 9B 39 65 C8 C9 8E B " } ,
/* 2*/ { BARCODE_CODE128 , " 123 " , " 456 " , NULL , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " D2 13 9B 39 65 C8 C9 8E B \n D2 19 3B 72 67 4E 4D 8E B " } ,
/* 3*/ { BARCODE_CODE128 , " 123 " , NULL , NULL , NULL , - 1 , - 1 , 1 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " Warning 141: Can't use batch mode if data given, ignoring \n D2 13 9B 39 65 C8 C9 8E B " } ,
/* 4*/ { BARCODE_CODE128 , NULL , NULL , " 123 \n 45 \n " , NULL , - 1 , - 1 , 1 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " D2 13 9B 39 65 C8 C9 8E B \n D3 97 62 3B 63 AC " } ,
/* 5*/ { BARCODE_CODE128 , NULL , NULL , " 123 \n 45 \n " , " 7 \n " , - 1 , - 1 , 1 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " Warning 144: Processing first input file 'test_dump_args1.txt' only \n D2 13 9B 39 65 C8 C9 8E B \n D3 97 62 3B 63 AC " } ,
/* 6*/ { BARCODE_CODE128 , " \t " , NULL , NULL , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " D0 90 D2 1A 63 AC " } ,
/* 7*/ { BARCODE_CODE128 , " \\ t " , NULL , NULL , NULL , ESCAPE_MODE , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " D0 90 D2 1A 63 AC " } ,
/* 8*/ { BARCODE_CODE128 , " 123 " , NULL , NULL , NULL , - 1 , BARCODE_BIND | BARCODE_BOX | SMALL_TEXT | BOLD_TEXT | CMYK_COLOUR , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " D2 13 9B 39 65 C8 C9 8E B " } ,
/* 9*/ { BARCODE_CODE128 , " 123 " , NULL , NULL , NULL , - 1 , BARCODE_DOTTY_MODE , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " Error 224: Selected symbology cannot be rendered as dots " } ,
/* 10*/ { BARCODE_CODABLOCKF , " ABCDEF " , NULL , NULL , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " D0 97 BA 86 51 88 B1 11 AC 46 D8 C7 58 \n D0 97 BB 12 46 88 C5 1A 3C 55 CC C7 58 " } ,
/* 11*/ { BARCODE_CODABLOCKF , " ABCDEF " , NULL , NULL , NULL , - 1 , - 1 , 0 , 10 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " D0 97 BA 86 51 88 B1 11 AC 44 68 BC 98 EB \n D0 97 BB 12 46 2B BD 7B A3 47 8A 8D 18 EB " } ,
/* 12*/ { BARCODE_CODABLOCKF , " ABCDEF " , NULL , NULL , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , 3 , - 1 , 0 , - 1 , " D0 97 BA 58 51 88 B1 11 AC 46 36 C7 58 \n D0 97 BB 12 46 88 C5 77 AF 74 62 C7 58 \n D0 97 BA CE 5D EB DD 1A 3C 56 88 C7 58 " } ,
/* 13*/ { BARCODE_CODE11 , NULL , NULL , " 123 " , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " B2 D6 96 CA B5 6D 64 " } ,
/* 14*/ { BARCODE_CODE11 , NULL , NULL , " 123 " , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , 1 , " B2 D6 96 CA B5 64 " } ,
/* 15*/ { BARCODE_CODE11 , " 123 " , NULL , " 456 " , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , 2 , " B2 D6 96 CA B2 \n B2 B6 DA 9A B2 " } ,
/* 16*/ { BARCODE_CODE11 , " 123 " , " 456 " , " 789 " , " 012 " , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , 2 , " B2 D6 96 CA B2 \n B2 B6 DA 9A B2 \n B2 A6 D2 D5 64 \n B2 AD AD 2D 64 " } ,
/* 17*/ { BARCODE_PDF417 , " 123 " , NULL , NULL , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , 1 , 0 , 0 , - 1 , " FF 54 7A BC 3D 4F 1D 5C 0F E8 A4 \n FF 54 7A 90 2F D3 1F AB 8F E8 A4 \n FF 54 6A F8 3A BF 15 3C 0F E8 A4 \n FF 54 57 9E 24 E7 1A F7 CF E8 A4 \n FF 54 7A E7 3D 0D 9D 73 0F E8 A4 \n FF 54 7D 70 B9 CB DF 5E CF E8 A4 " } ,
/* 18*/ { BARCODE_DATAMATRIX , " ABC " , NULL , NULL , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " AA 8 \n B3 4 \n 8F 0 \n B2 C \n A6 0 \n BA C \n D6 0 \n EB 4 \n E2 8 \n FF C " } ,
/* 19*/ { BARCODE_DATAMATRIX , " ABC " , NULL , NULL , NULL , - 1 , READER_INIT , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " AA A \n AC 7 \n 8A 4 \n A0 3 \n C2 2 \n B5 1 \n 82 2 \n BA 7 \n 8C C \n A0 5 \n 86 A \n FF F " } ,
/* 20*/ { BARCODE_DATAMATRIX , " ABCDEFGHIJK " , NULL , NULL , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " AA AA AA AA \n A6 C7 FA F9 \n B2 AA C7 BA \n 98 BF F4 0F \n E8 DA 90 C8 \n C7 D5 B6 DF \n C5 50 B0 2C \n FF FF FF FF " } ,
/* 21*/ { BARCODE_DATAMATRIX , " ABCDEFGHIJK " , NULL , NULL , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 1 , - 1 , " AA AA \n A6 D3 \n B2 DA \n 99 19 \n A8 A6 \n 84 F7 \n C0 8C \n F9 87 \n FC 4C \n D8 A5 \n 83 E6 \n 99 75 \n F7 82 \n AE 65 \n 8D 6A \n FF FF " } ,
/* 22*/ { BARCODE_DATAMATRIX , " ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF " , NULL , NULL , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " AA AA A8 \n A6 94 BC \n B2 AD F0 \n 99 08 F4 \n A9 E1 B8 \n 86 81 CC \n C2 F5 88 \n F5 D5 3C \n F2 68 30 \n DA 7A BC \n B7 FE 70 \n A8 E7 34 \n 91 40 88 \n D6 33 DC \n D2 89 20 \n D1 6A 94 \n E2 71 A8 \n E4 3E EC \n F2 9D 70 \n E5 8D FC \n B9 56 50 \n FF FF FC " } ,
/* 23*/ { BARCODE_DATAMATRIX , " ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF " , NULL , NULL , NULL , - 1 , - 1 , 0 , - 1 , 1 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " AA AA AA AA AA AA AA AA \n A6 D9 C8 0B FC 57 F3 17 \n B2 BA A7 CA C9 18 87 BE \n 99 2F EF 2B F1 A1 B9 DF \n A8 84 99 CA CF 4A BF 14 \n 86 D5 D9 87 A4 EF F4 9F \n 85 44 BF 22 E7 58 C6 8A \n FF FF FF FF FF FF FF FF " } ,
/* 24*/ { BARCODE_DATAMATRIX , " ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF " , NULL , NULL , NULL , - 1 , - 1 , 0 , - 1 , 1 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 1 , - 1 , " AA AA A8 \n A6 94 BC \n B2 AD F0 \n 99 08 F4 \n A9 E1 B8 \n 86 81 CC \n C2 F5 88 \n F5 D5 3C \n F2 68 30 \n DA 7A BC \n B7 FE 70 \n A8 E7 34 \n 91 40 88 \n D6 33 DC \n D2 89 20 \n D1 6A 94 \n E2 71 A8 \n E4 3E EC \n F2 9D 70 \n E5 8D FC \n B9 56 50 \n FF FF FC " } ,
/* 25*/ { BARCODE_DATAMATRIX , " [91]12[92]34 " , NULL , NULL , NULL , GS1_MODE , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " AA A8 \n FA 9C \n BC 00 \n D7 84 \n ED E0 \n A4 E4 \n A7 40 \n 9D 3C \n BF 50 \n FA 24 \n B1 68 \n E5 04 \n 92 70 \n FF FC " } ,
/* 26*/ { BARCODE_DATAMATRIX , " [91]12[92]34 " , NULL , NULL , NULL , GS1_MODE , GS1_GS_SEPARATOR , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " AA A8 \n F9 DC \n BF 20 \n D6 C4 \n ED 10 \n A0 0C \n A7 C0 \n 96 5C \n BA 70 \n BB A4 \n E2 18 \n DD 14 \n 9C 40 \n FF FC " } ,
/* 27*/ { BARCODE_DATAMATRIX , " [9 \\ x31]12[92]34 " , NULL , NULL , NULL , GS1_MODE | ESCAPE_MODE , GS1_GS_SEPARATOR , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , - 1 , 0 , - 1 , " AA A8 \n F9 DC \n BF 20 \n D6 C4 \n ED 10 \n A0 0C \n A7 C0 \n 96 5C \n BA 70 \n BB A4 \n E2 18 \n DD 14 \n 9C 40 \n FF FC " } ,
/* 28*/ { BARCODE_EANX_CC , " [91]12 " , NULL , NULL , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , " 12345678+12 " , - 1 , - 1 , 0 , - 1 , " DB BC D3 9C 44 E9 D2 2C 19 E7 A2 D8 A0 00 00 00 \n DB 31 1C 9C C7 29 92 47 D9 E9 40 C8 A0 00 00 00 \n DA 3B EB 10 AF 09 9A 18 9D 7D 82 E8 A0 00 00 00 \n 10 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00 \n 20 00 00 00 00 00 00 00 00 00 00 00 20 00 00 00 \n 10 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00 \n 14 68 D1 A6 49 BD 55 C9 D4 22 48 B9 40 59 94 98 " } ,
/* 29*/ { BARCODE_EANX_CC , " [91]12 " , NULL , NULL , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , 2 , " 12345678+12 " , - 1 , - 1 , 0 , - 1 , " D3 A3 E9 DB F5 C9 DB 43 D9 CB 98 D2 20 00 00 00 \n D3 25 0F 11 E4 49 D3 51 F1 AC FC D6 20 00 00 00 \n D1 33 48 19 39 E9 93 18 49 D8 98 D7 20 00 00 00 \n D1 A6 FC DA 1C 49 9B C5 05 E2 84 D7 A0 00 00 00 \n 10 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00 \n 20 00 00 00 00 00 00 00 00 00 00 00 20 00 00 00 \n 10 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00 \n 14 68 D1 A6 49 BD 55 C9 D4 22 48 B9 40 59 94 98 " } ,
/* 30*/ { BARCODE_QRCODE , " 点 " , NULL , NULL , NULL , - 1 , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , 1 , 0 , - 1 , " FE 4B F8 \n 82 92 08 \n BA 42 E8 \n BA 92 E8 \n BA 3A E8 \n 82 EA 08 \n FE AB F8 \n 00 38 00 \n FB CD 50 \n A5 89 18 \n 0B 74 B8 \n FC 81 A0 \n 92 34 B8 \n 00 DE 48 \n FE AB 10 \n 82 5E 50 \n BA C9 20 \n BA C9 20 \n BA F4 E0 \n 82 81 A0 \n FE B4 E8 " } ,
/* 31*/ { BARCODE_QRCODE , " 点 " , NULL , NULL , NULL , - 1 , - 1 , 0 , - 1 , 0 , 26 , 0 , - 1 , NULL , - 1 , 1 , 0 , - 1 , " FE 5B F8 \n 82 72 08 \n BA DA E8 \n BA 52 E8 \n BA 2A E8 \n 82 0A 08 \n FE AB F8 \n 00 D8 00 \n EF F6 20 \n B5 C2 28 \n 36 28 88 \n FD 42 10 \n 62 2A C8 \n 00 95 70 \n FE B7 38 \n 82 FD D8 \n BA 97 00 \n BA 43 60 \n BA C8 C8 \n 82 C3 68 \n FE EA F8 " } ,
/* 32*/ { BARCODE_QRCODE , " \223 \137 " , NULL , NULL , NULL , DATA_MODE , - 1 , 0 , - 1 , 0 , - 1 , 0 , - 1 , NULL , - 1 , 1 , 0 , - 1 , " FE 2B F8 \n 82 0A 08 \n BA A2 E8 \n BA 0A E8 \n BA 5A E8 \n 82 72 08 \n FE AB F8 \n 00 A0 00 \n EF AE 20 \n 75 B5 20 \n 82 F7 58 \n F4 9D C8 \n 5E 17 28 \n 00 C2 20 \n FE 88 80 \n 82 82 38 \n BA EA A8 \n BA 55 50 \n BA D7 68 \n 82 BD D0 \n FE B7 78 " } ,
/* 33*/ { BARCODE_QRCODE , " \223 \137 " , NULL , NULL , NULL , DATA_MODE , - 1 , 0 , - 1 , 0 , - 1 , 1 , - 1 , NULL , - 1 , 1 , 0 , - 1 , " FE 4B F8 \n 82 92 08 \n BA 42 E8 \n BA 92 E8 \n BA 3A E8 \n 82 EA 08 \n FE AB F8 \n 00 38 00 \n FB CD 50 \n A5 89 18 \n 0B 74 B8 \n FC 81 A0 \n 92 34 B8 \n 00 DE 48 \n FE AB 10 \n 82 5E 50 \n BA C9 20 \n BA C9 20 \n BA F4 E0 \n 82 81 A0 \n FE B4 E8 " } ,
/* 34*/ { BARCODE_QRCODE , " \\ x93 \\ x5F " , NULL , NULL , NULL , DATA_MODE | ESCAPE_MODE , - 1 , 0 , - 1 , 0 , - 1 , 1 , - 1 , NULL , - 1 , 1 , 0 , - 1 , " FE 4B F8 \n 82 92 08 \n BA 42 E8 \n BA 92 E8 \n BA 3A E8 \n 82 EA 08 \n FE AB F8 \n 00 38 00 \n FB CD 50 \n A5 89 18 \n 0B 74 B8 \n FC 81 A0 \n 92 34 B8 \n 00 DE 48 \n FE AB 10 \n 82 5E 50 \n BA C9 20 \n BA C9 20 \n BA F4 E0 \n 82 81 A0 \n FE B4 E8 " } ,
2020-08-05 09:22:26 +12:00
} ;
int data_size = ARRAY_SIZE ( data ) ;
2020-08-05 09:44:20 +12:00
char cmd [ 4096 ] ;
char buf [ 4096 ] ;
2020-08-05 09:22:26 +12:00
2020-08-05 09:44:20 +12:00
char * input1_filename = " test_dump_args1.txt " ;
char * input2_filename = " test_dump_args2.txt " ;
int have_input1 ;
int have_input2 ;
2020-08-05 09:22:26 +12:00
for ( int i = 0 ; i < data_size ; i + + ) {
if ( index ! = - 1 & & i ! = index ) continue ;
2020-08-05 09:44:20 +12:00
strcpy ( cmd , " zint --dump " ) ;
if ( debug & ZINT_DEBUG_PRINT ) {
strcat ( cmd , " --verbose " ) ;
}
arg_int ( cmd , " -b " , data [ i ] . b ) ;
arg_data ( cmd , " -d " , data [ i ] . data ) ;
arg_data ( cmd , " -d " , data [ i ] . data2 ) ;
have_input1 = arg_input ( cmd , input1_filename , data [ i ] . input ) ;
have_input2 = arg_input ( cmd , input2_filename , data [ i ] . input2 ) ;
arg_input_mode ( cmd , data [ i ] . input_mode ) ;
arg_output_options ( cmd , data [ i ] . output_options ) ;
arg_bool ( cmd , " --batch " , data [ i ] . batch ) ;
arg_int ( cmd , " --cols= " , data [ i ] . cols ) ;
arg_bool ( cmd , " --dmre " , data [ i ] . dmre ) ;
arg_int ( cmd , " --eci= " , data [ i ] . eci ) ;
arg_bool ( cmd , " --fullmultibyte " , data [ i ] . fullmultibyte ) ;
arg_int ( cmd , " --mode= " , data [ i ] . mode ) ;
arg_data ( cmd , " --primary= " , data [ i ] . primary ) ;
arg_int ( cmd , " --rows= " , data [ i ] . rows ) ;
arg_int ( cmd , " --secure= " , data [ i ] . secure ) ;
arg_bool ( cmd , " --square " , data [ i ] . square ) ;
arg_int ( cmd , " --vers= " , data [ i ] . vers ) ;
strcat ( cmd , " 2>&1 " ) ;
2020-08-05 09:22:26 +12:00
assert_nonnull ( exec ( cmd , buf , sizeof ( buf ) - 1 , debug , i ) , " i:%d exec(%s) NULL \n " , i , cmd ) ;
2020-08-05 09:44:20 +12:00
assert_zero ( strcmp ( buf , data [ i ] . expected ) , " i:%d buf (%s) != expected (%s) \n " , i , buf , data [ i ] . expected ) ;
if ( have_input1 ) {
assert_zero ( remove ( input1_filename ) , " i:%d remove(%s) != 0 (%d) \n " , i , input1_filename , errno ) ;
}
if ( have_input2 ) {
assert_zero ( remove ( input2_filename ) , " i:%d remove(%s) != 0 \n " , i , input2_filename ) ;
}
2020-08-05 09:22:26 +12:00
}
testFinish ( ) ;
}
static void test_input ( int index , int debug ) {
testStart ( " " ) ;
int ret ;
struct item {
int b ;
2020-08-05 09:44:20 +12:00
int batch ;
int mirror ;
char * filetype ;
char * input ;
char * outfile ;
int num_expected ;
char * expected ;
2020-08-05 09:22:26 +12:00
} ;
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data [ ] = {
2020-08-05 09:44:20 +12:00
/* 0*/ { BARCODE_CODE128 , 1 , 0 , NULL , " 123 \n 456 \n " , " test_batch~.png " , 2 , " test_batch1.png \000 test_batch2.png " } ,
/* 1*/ { BARCODE_CODE128 , 1 , 1 , NULL , " 123 \n 456 \n 7890123456789 \n " , NULL , 3 , " 123.png \000 456.png \000 7890123456789.png " } ,
/* 2*/ { BARCODE_CODE128 , 1 , 1 , " svg " , " 123 \n 456 \n 7890123456789 \n " , NULL , 3 , " 123.svg \000 456.svg \000 7890123456789.svg " } ,
/* 3*/ { BARCODE_CODE128 , 1 , 0 , NULL , " \n " , " test_batch.png " , 0 , NULL } ,
/* 4*/ { BARCODE_CODE128 , 1 , 0 , NULL , " 123 \n 456 \n " , " test_67890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890~.png " , 2 , " test_678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901.png \000 test_678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678902.png " } ,
/* 5*/ { BARCODE_CODE128 , 0 , 0 , " svg " , " 123 " , " test_678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901.png " , 1 , " test_678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901.svg " } ,
/* 6*/ { BARCODE_CODE128 , 1 , 0 , " svg " , " 123 \n " , " test_678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901.png " , 1 , " test_678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901.svg " } ,
/* 7*/ { BARCODE_CODE128 , 1 , 0 , NULL , " 123 \n " , " test_batch.jpeg " , 1 , " test_batch.jpeg.png " } ,
/* 8*/ { BARCODE_CODE128 , 1 , 0 , NULL , " 123 \n " , " test_batch.jpg " , 1 , " test_batch.png " } ,
/* 9*/ { BARCODE_CODE128 , 1 , 0 , " emf " , " 123 \n " , " test_batch.jpeg " , 1 , " test_batch.jpeg.emf " } ,
/* 10*/ { BARCODE_CODE128 , 1 , 0 , " emf " , " 123 \n " , " test_batch.jpg " , 1 , " test_batch.emf " } ,
/* 11*/ { BARCODE_CODE128 , 1 , 0 , " eps " , " 123 \n " , " test_batch.ps " , 1 , " test_batch.eps " } ,
2020-08-05 09:22:26 +12:00
} ;
int data_size = ARRAY_SIZE ( data ) ;
2020-08-05 09:44:20 +12:00
char cmd [ 4096 ] ;
char buf [ 4096 ] ;
2020-08-05 09:22:26 +12:00
2020-08-05 09:44:20 +12:00
char * input_filename = " test_input.txt " ;
char * outfile ;
2020-08-05 09:22:26 +12:00
for ( int i = 0 ; i < data_size ; i + + ) {
if ( index ! = - 1 & & i ! = index ) continue ;
2020-08-05 09:44:20 +12:00
strcpy ( cmd , " zint " ) ;
if ( debug & ZINT_DEBUG_PRINT ) {
strcat ( cmd , " --verbose " ) ;
}
2020-08-05 09:22:26 +12:00
2020-08-05 09:44:20 +12:00
arg_int ( cmd , " -b " , data [ i ] . b ) ;
arg_bool ( cmd , " --batch " , data [ i ] . batch ) ;
arg_bool ( cmd , " --mirror " , data [ i ] . mirror ) ;
arg_data ( cmd , " --filetype= " , data [ i ] . filetype ) ;
arg_input ( cmd , input_filename , data [ i ] . input ) ;
arg_data ( cmd , " -o " , data [ i ] . outfile ) ;
2020-08-05 09:22:26 +12:00
assert_nonnull ( exec ( cmd , buf , sizeof ( buf ) - 1 , debug , i ) , " i:%d exec(%s) NULL \n " , i , cmd ) ;
2020-08-05 09:44:20 +12:00
outfile = data [ i ] . expected ;
for ( int j = 0 ; j < data [ i ] . num_expected ; j + + ) {
assert_nonzero ( testUtilExists ( outfile ) , " i:%d j:%d testUtilExists(%s) != 1 \n " , i , j , outfile ) ;
assert_zero ( remove ( outfile ) , " i:%d j:%d remove(%s) != 0 (%d) \n " , i , j , outfile , errno ) ;
outfile + = strlen ( outfile ) + 1 ;
}
2020-08-05 09:22:26 +12:00
2020-08-05 09:44:20 +12:00
assert_zero ( remove ( input_filename ) , " i:%d remove(%s) != 0 (%d) \n " , i , input_filename , errno ) ;
2020-08-05 09:22:26 +12:00
}
testFinish ( ) ;
}
// Note ordering of `--batch` before/after data/input args affects error messages
static void test_batch_input ( int index , int debug ) {
testStart ( " " ) ;
int ret ;
struct item {
int b ;
char * data ;
2020-08-05 09:44:20 +12:00
char * input ;
char * input2 ;
2020-08-05 09:22:26 +12:00
2020-08-05 09:44:20 +12:00
char * expected ;
2020-08-05 09:22:26 +12:00
} ;
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data [ ] = {
2020-08-05 09:44:20 +12:00
/* 0*/ { BARCODE_CODE128 , " 123 " , NULL , NULL , " Warning 122: Can't define data in batch mode, ignoring '123' \n Warning 124: No data received, no symbol generated " } ,
/* 1*/ { BARCODE_CODE128 , " 123 " , " 123 \n 456 \n " , NULL , " Warning 122: Can't define data in batch mode, ignoring '123' \n D2 13 9B 39 65 C8 C9 8E B \n D2 19 3B 72 67 4E 4D 8E B " } ,
/* 3*/ { BARCODE_CODE128 , NULL , " 123 \n 456 \n " , " 789 \n " , " Warning 143: Can only define one input file in batch mode, ignoring 'test_batch_input2.txt' \n D2 13 9B 39 65 C8 C9 8E B \n D2 19 3B 72 67 4E 4D 8E B " } ,
2020-08-05 09:22:26 +12:00
} ;
int data_size = ARRAY_SIZE ( data ) ;
2020-08-05 09:44:20 +12:00
char cmd [ 4096 ] ;
char buf [ 4096 ] ;
2020-08-05 09:22:26 +12:00
2020-08-05 09:44:20 +12:00
char * input1_filename = " test_batch_input1.txt " ;
char * input2_filename = " test_batch_input2.txt " ;
int have_input1 ;
int have_input2 ;
2020-08-05 09:22:26 +12:00
for ( int i = 0 ; i < data_size ; i + + ) {
if ( index ! = - 1 & & i ! = index ) continue ;
2020-08-05 09:44:20 +12:00
strcpy ( cmd , " zint --dump --batch " ) ;
if ( debug & ZINT_DEBUG_PRINT ) {
strcat ( cmd , " --verbose " ) ;
}
2020-08-05 09:22:26 +12:00
2020-08-05 09:44:20 +12:00
arg_int ( cmd , " -b " , data [ i ] . b ) ;
arg_data ( cmd , " -d " , data [ i ] . data ) ;
have_input1 = arg_input ( cmd , input1_filename , data [ i ] . input ) ;
have_input2 = arg_input ( cmd , input2_filename , data [ i ] . input2 ) ;
2020-08-05 09:22:26 +12:00
2020-08-05 09:44:20 +12:00
strcat ( cmd , " 2>&1 " ) ;
2020-08-05 09:22:26 +12:00
assert_nonnull ( exec ( cmd , buf , sizeof ( buf ) - 1 , debug , i ) , " i:%d exec(%s) NULL \n " , i , cmd ) ;
2020-08-05 09:44:20 +12:00
assert_zero ( strcmp ( buf , data [ i ] . expected ) , " i:%d buf (%s) != expected (%s) \n " , i , buf , data [ i ] . expected ) ;
if ( have_input1 ) {
assert_zero ( remove ( input1_filename ) , " i:%d remove(%s) != 0 (%d) \n " , i , input1_filename , errno ) ;
}
if ( have_input2 ) {
assert_zero ( remove ( input2_filename ) , " i:%d remove(%s) != 0 \n " , i , input2_filename ) ;
}
2020-08-05 09:22:26 +12:00
}
testFinish ( ) ;
}
static void test_batch_large ( int index , int debug ) {
testStart ( " " ) ;
int ret ;
struct item {
int b ;
int mirror ;
char * pattern ;
2020-08-05 09:44:20 +12:00
int length ;
2020-08-05 09:22:26 +12:00
2020-08-05 09:44:20 +12:00
char * expected ;
2020-08-05 09:22:26 +12:00
} ;
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data [ ] = {
2020-08-05 09:44:20 +12:00
/* 0*/ { BARCODE_HANXIN , 0 , " 1 " , 7827 , " out.png " } ,
/* 1*/ { BARCODE_HANXIN , 1 , " 1 " , 7827 , " 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111.png " } ,
/* 2*/ { BARCODE_HANXIN , 0 , " 1 " , 7828 , NULL } ,
2020-08-05 09:22:26 +12:00
} ;
int data_size = ARRAY_SIZE ( data ) ;
2020-08-05 09:44:20 +12:00
char cmd [ 16384 ] ;
char data_buf [ 8192 ] ;
char buf [ 16384 ] ;
2020-08-05 09:22:26 +12:00
2020-08-05 09:44:20 +12:00
char * input_filename = " test_batch_large.txt " ;
int have_input ;
2020-08-05 09:22:26 +12:00
for ( int i = 0 ; i < data_size ; i + + ) {
if ( index ! = - 1 & & i ! = index ) continue ;
2020-08-05 09:44:20 +12:00
strcpy ( cmd , " zint --batch " ) ;
if ( debug & ZINT_DEBUG_PRINT ) {
strcat ( cmd , " --verbose " ) ;
}
2020-08-05 09:22:26 +12:00
2020-08-05 09:44:20 +12:00
arg_int ( cmd , " -b " , data [ i ] . b ) ;
arg_bool ( cmd , " --mirror " , data [ i ] . mirror ) ;
2020-08-05 09:22:26 +12:00
testUtilStrCpyRepeat ( data_buf , data [ i ] . pattern , data [ i ] . length ) ;
2020-08-05 09:44:20 +12:00
strcat ( data_buf , " \n " ) ;
have_input = arg_input ( cmd , input_filename , data_buf ) ;
2020-08-05 09:22:26 +12:00
assert_nonnull ( exec ( cmd , buf , sizeof ( buf ) - 1 , debug , i ) , " i:%d exec(%s) NULL \n " , i , cmd ) ;
2020-08-05 09:44:20 +12:00
if ( data [ i ] . expected ) {
assert_zero ( remove ( data [ i ] . expected ) , " i:%d remove(%s) != 0 (%d) \n " , i , data [ i ] . expected , errno ) ;
} else {
assert_zero ( testUtilExists ( " out.png " ) , " i:%d testUtilExists(out.png) != 0 (%d) \n " , i , errno ) ;
}
if ( have_input ) {
assert_zero ( remove ( input_filename ) , " i:%d remove(%s) != 0 (%d) \n " , i , input_filename , errno ) ;
}
2020-08-05 09:22:26 +12:00
}
testFinish ( ) ;
}
static void test_checks ( int index , int debug ) {
testStart ( " " ) ;
int ret ;
struct item {
2020-08-05 09:44:20 +12:00
int addongap ;
int border ;
int cols ;
double dotsize ;
int eci ;
char * filetype ;
int height ;
int mode ;
int rotate ;
int rows ;
double scale ;
int secure ;
int separator ;
int vers ;
int w ;
char * expected ;
2020-08-05 09:22:26 +12:00
} ;
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data [ ] = {
2020-08-11 06:40:10 +12:00
/* 0*/ { - 2 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , " Error 139: Invalid add-on gap value " } ,
/* 1*/ { 6 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , " Warning 140: Invalid add-on gap value " } ,
/* 2*/ { - 1 , - 2 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , " Error 107: Invalid border width value " } ,
/* 3*/ { - 1 , 1001 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , " Warning 108: Border width out of range " } ,
/* 4*/ { - 1 , - 1 , - 1 , 0.009 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , " Warning 106: Invalid dot radius value " } ,
/* 5*/ { - 1 , - 1 , - 2 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , " Error 131: Invalid columns value " } ,
/* 6*/ { - 1 , - 1 , 68 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , " Warning 111: Number of columns out of range " } ,
/* 7*/ { - 1 , - 1 , - 1 , - 1 , - 2 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , " Error 138: Invalid ECI value " } ,
/* 8*/ { - 1 , - 1 , - 1 , - 1 , 1000000 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , " Warning 118: Invalid ECI code " } ,
/* 9*/ { - 1 , - 1 , - 1 , - 1 , - 1 , " jpg " , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , " Warning 142: File type 'jpg' not supported, ignoring " } ,
/* 10*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 2 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , " Error 109: Invalid symbol height value " } ,
/* 11*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , 0 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , " Warning 110: Symbol height out of range " } ,
/* 12*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 2 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , " Error 136: Invalid mode value " } ,
/* 13*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , 7 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , " Warning 116: Invalid mode " } ,
/* 14*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 2 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , " Error 117: Invalid rotation value " } ,
/* 15*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , 45 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , " Warning 137: Invalid rotation parameter " } ,
/* 16*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 2 , - 1 , - 1 , - 1 , - 1 , - 1 , " Error 132: Invalid rows value " } ,
/* 17*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , 45 , - 1 , - 1 , - 1 , - 1 , - 1 , " Warning 112: Number of rows out of range " } ,
/* 18*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , - 2 , - 1 , - 1 , - 1 , - 1 , " Warning 105: Invalid scale value " } ,
/* 19*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , 0.49 , - 1 , - 1 , - 1 , - 1 , " Warning 146: Scaling less than 0.5 will be set to 0.5 for 'png' output " } ,
/* 20*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , - 2 , - 1 , - 1 , - 1 , " Error 134: Invalid ECC value " } ,
/* 21*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , 9 , - 1 , - 1 , - 1 , " Warning 114: ECC level out of range " } ,
/* 22*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 2 , - 1 , - 1 , " Error 128: Invalid separator value " } ,
/* 23*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , 5 , - 1 , - 1 , " Warning 127: Invalid separator value " } ,
/* 24*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 2 , - 1 , " Error 133: Invalid version value " } ,
/* 25*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , 85 , - 1 , " Warning 113: Invalid version " } ,
/* 26*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 2 , " Error 120: Invalid whitespace value '-2' " } ,
/* 27*/ { - 1 , - 1 , - 1 , - 1 , - 1 , NULL , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , 1001 , " Warning 121: Whitespace value out of range " } ,
2020-08-05 09:22:26 +12:00
} ;
int data_size = ARRAY_SIZE ( data ) ;
2020-08-05 09:44:20 +12:00
char cmd [ 4096 ] ;
char buf [ 4096 ] ;
2020-08-11 06:40:10 +12:00
char * outfilename = " out.png " ;
2020-08-05 09:22:26 +12:00
for ( int i = 0 ; i < data_size ; i + + ) {
if ( index ! = - 1 & & i ! = index ) continue ;
2020-08-11 06:40:10 +12:00
strcpy ( cmd , " zint -d '1' " ) ;
2020-08-05 09:44:20 +12:00
if ( debug & ZINT_DEBUG_PRINT ) {
strcat ( cmd , " --verbose " ) ;
}
arg_int ( cmd , " --addongap= " , data [ i ] . addongap ) ;
arg_int ( cmd , " --border= " , data [ i ] . border ) ;
arg_int ( cmd , " --cols= " , data [ i ] . cols ) ;
arg_double ( cmd , " --dotsize= " , data [ i ] . dotsize ) ;
arg_int ( cmd , " --eci= " , data [ i ] . eci ) ;
arg_data ( cmd , " --filetype= " , data [ i ] . filetype ) ;
arg_int ( cmd , " --height= " , data [ i ] . height ) ;
arg_int ( cmd , " --mode= " , data [ i ] . mode ) ;
arg_int ( cmd , " --rotate= " , data [ i ] . rotate ) ;
arg_int ( cmd , " --rows= " , data [ i ] . rows ) ;
arg_double ( cmd , " --scale= " , data [ i ] . scale ) ;
arg_int ( cmd , " --secure= " , data [ i ] . secure ) ;
arg_int ( cmd , " --separator= " , data [ i ] . separator ) ;
arg_int ( cmd , " --vers= " , data [ i ] . vers ) ;
arg_int ( cmd , " -w " , data [ i ] . w ) ;
strcat ( cmd , " 2>&1 " ) ;
2020-08-05 09:22:26 +12:00
assert_nonnull ( exec ( cmd , buf , sizeof ( buf ) - 1 , debug , i ) , " i:%d exec(%s) NULL \n " , i , cmd ) ;
2020-08-05 09:44:20 +12:00
assert_zero ( strcmp ( buf , data [ i ] . expected ) , " i:%d buf (%s) != expected (%s) \n " , i , buf , data [ i ] . expected ) ;
2020-08-11 06:40:10 +12:00
if ( strncmp ( data [ i ] . expected , " Warning " , 7 ) = = 0 ) {
assert_zero ( remove ( outfilename ) , " i:%d remove(%s) != 0 (%d) \n " , i , outfilename , errno ) ;
}
2020-08-05 09:22:26 +12:00
}
testFinish ( ) ;
}
int main ( int argc , char * argv [ ] ) {
testFunction funcs [ ] = { /* name, func, has_index, has_generate, has_debug */
{ " test_dump_args " , test_dump_args , 1 , 0 , 1 } ,
{ " test_input " , test_input , 1 , 0 , 1 } ,
{ " test_batch_input " , test_batch_input , 1 , 0 , 1 } ,
{ " test_batch_large " , test_batch_large , 1 , 0 , 1 } ,
{ " test_checks " , test_checks , 1 , 0 , 1 } ,
} ;
testRun ( argc , argv , funcs , ARRAY_SIZE ( funcs ) ) ;
testReport ( ) ;
return 0 ;
}