8#include "tpcclibConfig.h"
23 IFT *ift1,
IFT *ift2,
char *key,
int test_lt,
int test_gt,
24 double test_abs,
int verbose
27 IFT *ift1,
IFT *ift2,
char *key1,
char *key2,
int test_lt,
int test_gt,
28 double test_abs,
int verbose
33static char *info[] = {
34 "Verify that the contents in two IFT files is similar.",
35 "By default, all contents (keys and values) are tested, but by specifying",
36 "a key, only values of that that key are tested. If the second IFT file",
37 "has a different key name, then it can be specified as the second key name.",
39 "IFT files are text files with key and (optional) value at each line,",
42 " calibration_coefficient := 6.78901E-005",
44 "Key and value strings are case-insensitive. Lines may be in any order,",
45 "except that if more than one key instances are found, the order of the",
46 "values must be the same.",
48 "Program returns 0, if match is found, 1-9 in case of an error, or",
49 "10, if matching key or value is not found.",
51 "Usage: @P [options] filename1 filename2 [key [key2]]",
54 "-lt | -gt | -abs=<limit>",
55 " Values in file 1 and 2 are tested numerically (not as text), to be less",
56 " (-lt) or greater (-gt) in file 1 than in file 2, or the absolute",
57 " difference is not allowed to exceed the specified limit (-abs=<limit>)",
61 " @P data1.ift data2.ift",
63 " @P iea345header.txt validheader.txt calibrated",
65 " @P -abs=0.02 iea345hdr.txt validhdr.txt halflife",
67 " @P -abs=0.02 iea345hdr.txt validhdr.txt half-life halflife",
69 "See also: iftisval, iftlist, csv2ift",
71 "Keywords: IFT, tool, software testing",
90int main(
int argc,
char **argv)
92 int ai, help=0, version=0, verbose=1;
94 char *cptr, iftfile1[FILENAME_MAX], iftfile2[FILENAME_MAX];
98 int test_lt=0, test_gt=0;
103 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
105 iftfile1[0]=iftfile2[0]=(char)0; key=NULL; key2=NULL;
107 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
110 if(strncasecmp(cptr,
"ABS=", 4)==0) {
111 test_abs=
atofVerified(cptr+4);
if(!isnan(test_abs))
continue;
112 }
else if(strcasecmp(cptr,
"LT")==0) {
114 }
else if(strcasecmp(cptr,
"GT")==0) {
117 fprintf(stderr,
"Error: invalid option '%s'\n", argv[ai]);
118 free(key); free(key2);
123 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
132 for(; ai<argc; ai++) {
134 strcpy(iftfile1, argv[ai]);
continue;
135 }
else if(!iftfile2[0]) {
136 strcpy(iftfile2, argv[ai]);
continue;
137 }
else if(key==NULL) {
138 key=
strdup(argv[ai]);
continue;
139 }
else if(key2==NULL) {
140 key2=
strdup(argv[ai]);
continue;
142 fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
143 free(key); free(key2);
148 if(!iftfile2[0]) {
tpcPrintUsage(argv[0], info, stdout);
return(1);}
152 for(ai=0; ai<argc; ai++)
153 printf(
"%s ", argv[ai]);
155 printf(
"iftfile1 := %s\n", iftfile1);
156 printf(
"iftfile2 := %s\n", iftfile2);
157 if(key!=NULL) printf(
"key := %s\n", key);
158 if(key2!=NULL) printf(
"key2 := %s\n", key2);
159 if(test_abs>=0.0) printf(
"test_abs := %g\n", test_abs);
160 printf(
"test_lt := %d\n", test_lt);
161 printf(
"test_gt := %d\n", test_gt);
169 if(verbose>1) printf(
"reading %s\n", iftfile1);
170 fp=fopen(iftfile1,
"r");
if(fp==NULL) {
171 fprintf(stderr,
"Error: cannot open file %s\n", iftfile1);
172 free(key); free(key2);
return(2);
174 ret=
iftRead(&ift1, fp, 1, 1, &status); fclose(fp);
176 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
177 free(key); free(key2);
iftFree(&ift1);
return(2);
179 if(verbose>2) printf(
"list1 size: %d item(s)\n", ift1.
keyNr);
181 if(verbose>1) printf(
"reading %s\n", iftfile2);
182 fp=fopen(iftfile2,
"r");
if(fp==NULL) {
183 fprintf(stderr,
"Error: cannot open file %s\n", iftfile2);
184 free(key); free(key2);
iftFree(&ift1);
return(2);
186 ret=
iftRead(&ift2, fp, 1, 1, &status); fclose(fp);
188 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
191 if(verbose>2) printf(
"list2 size: %d item(s)\n", ift2.
keyNr);
196 if(verbose>1) printf(
"testing key '%s'\n", key);
200 if(verbose>1) printf(
"testing keys '%s' and '%s'\n", key, key2);
205 if(verbose>=0) fprintf(stdout,
"Match was found.\n");
207 if(verbose>=0) fprintf(stderr,
"No match: values are not the same.\n");
215 if(verbose>1) printf(
"full content testing\n");
219 if(verbose>=0) fprintf(stderr,
"No match: key number is not the same.\n");
226 for(i=0; i<ift1.
keyNr; i++) {
230 if(verbose>1) printf(
"testing key '%s'\n", ift1.
item[i].
key);
232 test_abs, verbose-1);
234 if(verbose>1) fprintf(stdout,
"Match was found.\n");
237 fprintf(stderr,
"No match: values are not the same for the key %s.\n",
247 if(verbose>=0) fprintf(stdout,
"Match was found.\n");
278 printf(
"iftCheckKeyValue(*ift1, *ift2, \"%s\", %d, %d, %g, ...)\n",
279 key, test_lt, test_gt, test_abs);
280 if(ift1==NULL || ift2==NULL)
return(1);
281 if(key==NULL || strlen(key)<1)
return(1);
288 printf(
"%d instance(s) of key in file1.\n", n1);
289 printf(
"%d instance(s) of key in file2.\n", n2);
292 if(verbose>0) fprintf(stderr,
"No match: key not found.\n");
297 if(verbose>0) fprintf(stderr,
"No match: different nr of keys.\n");
303 s1=(
char*)NULL; s2=(
char*)NULL;
304 for(i=0, li=lj=-1; i<n1; i++) {
305 li=
iftFindKey(ift1, key, li+1);
if(verbose>5) printf(
"li=%d\n", li);
306 lj=
iftFindKey(ift2, key, lj+1);
if(verbose>5) printf(
"lj=%d\n", lj);
307 if(li<0 || lj<0)
break;
310 if(verbose>2) printf(
"testing strings '%s' == '%s'\n", s1, s2);
312 if(s1==NULL && s2==NULL)
continue;
313 if(strlen(s1)==0 && strlen(s2)==0)
continue;
315 if(strcasecmp(s1, s2)==0)
continue;
321 if(verbose>2) printf(
"testing whether %g < %g\n", v1, v2);
324 if(verbose>2) printf(
"testing whether %g > %g\n", v1, v2);
326 }
else if(test_abs>=0) {
327 if(verbose>2) printf(
"testing whether |%g-%g| < %g\n", v1, v2, test_abs);
328 if(fabs(v1-v2)<test_abs)
continue;
330 if(verbose>2) printf(
"testing whether %g == %g\n", v1, v2);
336 if(verbose>0) fprintf(stderr,
"No match: values are not the same.\n");
337 if(verbose>1) printf(
"value1 := '%s'\nvalue2 := '%s'\n", s1, s2);
340 if(verbose>0) fprintf(stdout,
"Match was found: values are the same.\n");
373 printf(
"iftCheckKeyValues(*ift1, *ift2, \"%s\", \"%s\", %d, %d, %g, ...)\n",
374 key1, key2, test_lt, test_gt, test_abs);
375 if(ift1==NULL || ift2==NULL)
return(1);
376 if(key1==NULL || strlen(key1)<1)
return(1);
377 if(key2==NULL) key2=key1;
384 printf(
"%d instance(s) of key in file1.\n", n1);
385 printf(
"%d instance(s) of key in file2.\n", n2);
388 if(verbose>0) fprintf(stderr,
"No match: key not found.\n");
393 if(verbose>0) fprintf(stderr,
"No match: different nr of keys.\n");
399 s1=(
char*)NULL; s2=(
char*)NULL;
400 for(i=0, li=lj=-1; i<n1; i++) {
401 li=
iftFindKey(ift1, key1, li+1);
if(verbose>5) printf(
"li=%d\n", li);
402 lj=
iftFindKey(ift2, key2, lj+1);
if(verbose>5) printf(
"lj=%d\n", lj);
403 if(li<0 || lj<0)
break;
406 if(verbose>2) printf(
"testing strings '%s' == '%s'\n", s1, s2);
408 if(s1==NULL && s2==NULL)
continue;
409 if(strlen(s1)==0 && strlen(s2)==0)
continue;
411 if(strcasecmp(s1, s2)==0)
continue;
417 if(verbose>2) printf(
"testing whether %g < %g\n", v1, v2);
420 if(verbose>2) printf(
"testing whether %g > %g\n", v1, v2);
422 }
else if(test_abs>=0) {
423 if(verbose>2) printf(
"testing whether |%g-%g| < %g\n", v1, v2, test_abs);
424 if(fabs(v1-v2)<test_abs)
continue;
426 if(verbose>2) printf(
"testing whether %g == %g\n", v1, v2);
432 if(verbose>0) fprintf(stderr,
"No match: values are not the same.\n");
433 if(verbose>1) printf(
"value1 := '%s'\nvalue2 := '%s'\n", s1, s2);
436 if(verbose>0) fprintf(stdout,
"Match was found: values are the same.\n");
double atofVerified(const char *s)
int doubleGetWithUnit(const char *s, double *v, int *u)
int iftFindNrOfKeys(IFT *ift, const char *key)
int iftFindKey(IFT *ift, const char *key, int start_index)
int iftRead(IFT *ift, FILE *fp, int is_key_required, int is_comment_accepted, TPCSTATUS *status)
int iftCheckKeyValues(IFT *ift1, IFT *ift2, char *key1, char *key2, int test_lt, int test_gt, double test_abs, int verbose)
int iftCheckKeyValue(IFT *ift1, IFT *ift2, char *key, int test_lt, int test_gt, double test_abs, int verbose)
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
int tpcHtmlUsage(const char *program, char *text[], const char *path)
void tpcPrintBuild(const char *program, FILE *fp)
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
void statusInit(TPCSTATUS *s)
char * errorMsg(tpcerror e)
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
char * strdup(const char *s)
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
Header file for library libtpcextensions.
Header file for library libtpcift.