Skip to content

Commit

Permalink
TJBench/TJUnitTest: Don't ignore mistyped args
Browse files Browse the repository at this point in the history
  • Loading branch information
dcommander committed Nov 13, 2017
1 parent 94e152b commit f3ad13e
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 76 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ testing BufferedImage encoding/decoding on big endian systems.
is selected along with the `-crop` option. That option does not currently work
with other output image formats.

4. TJBench (both C and Java versions) will now display usage information if any
command-line argument is unrecognized. This prevents the program from silently
ignoring typos.


1.5.2
=====
Expand Down
61 changes: 30 additions & 31 deletions java/TJBench.java
Original file line number Diff line number Diff line change
Expand Up @@ -721,37 +721,37 @@ public static void main(String[] argv) {
if (argv[i].equalsIgnoreCase("-tile")) {
doTile = true; xformOpt |= TJTransform.OPT_CROP;
}
if (argv[i].equalsIgnoreCase("-fastupsample")) {
else if (argv[i].equalsIgnoreCase("-fastupsample")) {
System.out.println("Using fast upsampling code\n");
flags |= TJ.FLAG_FASTUPSAMPLE;
}
if (argv[i].equalsIgnoreCase("-fastdct")) {
else if (argv[i].equalsIgnoreCase("-fastdct")) {
System.out.println("Using fastest DCT/IDCT algorithm\n");
flags |= TJ.FLAG_FASTDCT;
}
if (argv[i].equalsIgnoreCase("-accuratedct")) {
else if (argv[i].equalsIgnoreCase("-accuratedct")) {
System.out.println("Using most accurate DCT/IDCT algorithm\n");
flags |= TJ.FLAG_ACCURATEDCT;
}
if (argv[i].equalsIgnoreCase("-rgb"))
else if (argv[i].equalsIgnoreCase("-rgb"))
pf = TJ.PF_RGB;
if (argv[i].equalsIgnoreCase("-rgbx"))
else if (argv[i].equalsIgnoreCase("-rgbx"))
pf = TJ.PF_RGBX;
if (argv[i].equalsIgnoreCase("-bgr"))
else if (argv[i].equalsIgnoreCase("-bgr"))
pf = TJ.PF_BGR;
if (argv[i].equalsIgnoreCase("-bgrx"))
else if (argv[i].equalsIgnoreCase("-bgrx"))
pf = TJ.PF_BGRX;
if (argv[i].equalsIgnoreCase("-xbgr"))
else if (argv[i].equalsIgnoreCase("-xbgr"))
pf = TJ.PF_XBGR;
if (argv[i].equalsIgnoreCase("-xrgb"))
else if (argv[i].equalsIgnoreCase("-xrgb"))
pf = TJ.PF_XRGB;
if (argv[i].equalsIgnoreCase("-bottomup"))
else if (argv[i].equalsIgnoreCase("-bottomup"))
flags |= TJ.FLAG_BOTTOMUP;
if (argv[i].equalsIgnoreCase("-quiet"))
else if (argv[i].equalsIgnoreCase("-quiet"))
quiet = 1;
if (argv[i].equalsIgnoreCase("-qq"))
else if (argv[i].equalsIgnoreCase("-qq"))
quiet = 2;
if (argv[i].equalsIgnoreCase("-scale") && i < argv.length - 1) {
else if (argv[i].equalsIgnoreCase("-scale") && i < argv.length - 1) {
int temp1 = 0, temp2 = 0;
boolean match = false, scanned = true;
Scanner scanner = new Scanner(argv[++i]).useDelimiter("/");
Expand All @@ -774,25 +774,25 @@ public static void main(String[] argv) {
} else
usage();
}
if (argv[i].equalsIgnoreCase("-hflip"))
else if (argv[i].equalsIgnoreCase("-hflip"))
xformOp = TJTransform.OP_HFLIP;
if (argv[i].equalsIgnoreCase("-vflip"))
else if (argv[i].equalsIgnoreCase("-vflip"))
xformOp = TJTransform.OP_VFLIP;
if (argv[i].equalsIgnoreCase("-transpose"))
else if (argv[i].equalsIgnoreCase("-transpose"))
xformOp = TJTransform.OP_TRANSPOSE;
if (argv[i].equalsIgnoreCase("-transverse"))
else if (argv[i].equalsIgnoreCase("-transverse"))
xformOp = TJTransform.OP_TRANSVERSE;
if (argv[i].equalsIgnoreCase("-rot90"))
else if (argv[i].equalsIgnoreCase("-rot90"))
xformOp = TJTransform.OP_ROT90;
if (argv[i].equalsIgnoreCase("-rot180"))
else if (argv[i].equalsIgnoreCase("-rot180"))
xformOp = TJTransform.OP_ROT180;
if (argv[i].equalsIgnoreCase("-rot270"))
else if (argv[i].equalsIgnoreCase("-rot270"))
xformOp = TJTransform.OP_ROT270;
if (argv[i].equalsIgnoreCase("-grayscale"))
else if (argv[i].equalsIgnoreCase("-grayscale"))
xformOpt |= TJTransform.OPT_GRAY;
if (argv[i].equalsIgnoreCase("-nooutput"))
else if (argv[i].equalsIgnoreCase("-nooutput"))
xformOpt |= TJTransform.OPT_NOOUTPUT;
if (argv[i].equalsIgnoreCase("-benchtime") && i < argv.length - 1) {
else if (argv[i].equalsIgnoreCase("-benchtime") && i < argv.length - 1) {
double temp = -1;
try {
temp = Double.parseDouble(argv[++i]);
Expand All @@ -802,19 +802,19 @@ public static void main(String[] argv) {
else
usage();
}
if (argv[i].equalsIgnoreCase("-yuv")) {
else if (argv[i].equalsIgnoreCase("-yuv")) {
System.out.println("Testing YUV planar encoding/decoding\n");
doYUV = true;
}
if (argv[i].equalsIgnoreCase("-yuvpad") && i < argv.length - 1) {
else if (argv[i].equalsIgnoreCase("-yuvpad") && i < argv.length - 1) {
int temp = 0;
try {
temp = Integer.parseInt(argv[++i]);
} catch (NumberFormatException e) {}
if (temp >= 1)
yuvpad = temp;
}
if (argv[i].equalsIgnoreCase("-subsamp") && i < argv.length - 1) {
else if (argv[i].equalsIgnoreCase("-subsamp") && i < argv.length - 1) {
i++;
if (argv[i].toUpperCase().startsWith("G"))
subsamp = TJ.SAMP_GRAY;
Expand All @@ -829,11 +829,11 @@ else if (argv[i].equals("420"))
else if (argv[i].equals("411"))
subsamp = TJ.SAMP_411;
}
if (argv[i].equalsIgnoreCase("-componly"))
else if (argv[i].equalsIgnoreCase("-componly"))
compOnly = true;
if (argv[i].equalsIgnoreCase("-nowrite"))
else if (argv[i].equalsIgnoreCase("-nowrite"))
write = false;
if (argv[i].equalsIgnoreCase("-warmup") && i < argv.length - 1) {
else if (argv[i].equalsIgnoreCase("-warmup") && i < argv.length - 1) {
double temp = -1;
try {
temp = Double.parseDouble(argv[++i]);
Expand All @@ -844,8 +844,7 @@ else if (argv[i].equals("411"))
} else
usage();
}
if (argv[i].equalsIgnoreCase("-?"))
usage();
else usage();
}
}

Expand Down
10 changes: 4 additions & 6 deletions java/TJUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -902,15 +902,13 @@ public static void main(String[] argv) {
for (int i = 0; i < argv.length; i++) {
if (argv[i].equalsIgnoreCase("-yuv"))
doYUV = true;
if (argv[i].equalsIgnoreCase("-noyuvpad"))
else if (argv[i].equalsIgnoreCase("-noyuvpad"))
pad = 1;
if (argv[i].substring(0, 1).equalsIgnoreCase("-h") ||
argv[i].equalsIgnoreCase("-?"))
usage();
if (argv[i].equalsIgnoreCase("-bi")) {
else if (argv[i].equalsIgnoreCase("-bi")) {
bi = true;
testName = "javabitest";
}
} else
usage();
}
if (doYUV)
_4byteFormats[4] = -1;
Expand Down
68 changes: 34 additions & 34 deletions tjbench.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,32 +835,32 @@ int main(int argc, char *argv[])
{
dotile=1; xformopt|=TJXOPT_CROP;
}
if(!strcasecmp(argv[i], "-fastupsample"))
else if(!strcasecmp(argv[i], "-fastupsample"))
{
printf("Using fast upsampling code\n\n");
flags|=TJFLAG_FASTUPSAMPLE;
}
if(!strcasecmp(argv[i], "-fastdct"))
else if(!strcasecmp(argv[i], "-fastdct"))
{
printf("Using fastest DCT/IDCT algorithm\n\n");
flags|=TJFLAG_FASTDCT;
}
if(!strcasecmp(argv[i], "-accuratedct"))
else if(!strcasecmp(argv[i], "-accuratedct"))
{
printf("Using most accurate DCT/IDCT algorithm\n\n");
flags|=TJFLAG_ACCURATEDCT;
}
if(!strcasecmp(argv[i], "-rgb")) pf=TJPF_RGB;
if(!strcasecmp(argv[i], "-rgbx")) pf=TJPF_RGBX;
if(!strcasecmp(argv[i], "-bgr")) pf=TJPF_BGR;
if(!strcasecmp(argv[i], "-bgrx")) pf=TJPF_BGRX;
if(!strcasecmp(argv[i], "-xbgr")) pf=TJPF_XBGR;
if(!strcasecmp(argv[i], "-xrgb")) pf=TJPF_XRGB;
if(!strcasecmp(argv[i], "-cmyk")) pf=TJPF_CMYK;
if(!strcasecmp(argv[i], "-bottomup")) flags|=TJFLAG_BOTTOMUP;
if(!strcasecmp(argv[i], "-quiet")) quiet=1;
if(!strcasecmp(argv[i], "-qq")) quiet=2;
if(!strcasecmp(argv[i], "-scale") && i<argc-1)
else if(!strcasecmp(argv[i], "-rgb")) pf=TJPF_RGB;
else if(!strcasecmp(argv[i], "-rgbx")) pf=TJPF_RGBX;
else if(!strcasecmp(argv[i], "-bgr")) pf=TJPF_BGR;
else if(!strcasecmp(argv[i], "-bgrx")) pf=TJPF_BGRX;
else if(!strcasecmp(argv[i], "-xbgr")) pf=TJPF_XBGR;
else if(!strcasecmp(argv[i], "-xrgb")) pf=TJPF_XRGB;
else if(!strcasecmp(argv[i], "-cmyk")) pf=TJPF_CMYK;
else if(!strcasecmp(argv[i], "-bottomup")) flags|=TJFLAG_BOTTOMUP;
else if(!strcasecmp(argv[i], "-quiet")) quiet=1;
else if(!strcasecmp(argv[i], "-qq")) quiet=2;
else if(!strcasecmp(argv[i], "-scale") && i<argc-1)
{
int temp1=0, temp2=0, match=0;
if(sscanf(argv[++i], "%d/%d", &temp1, &temp2)==2)
Expand All @@ -878,43 +878,42 @@ int main(int argc, char *argv[])
}
else usage(argv[0]);
}
if(!strcasecmp(argv[i], "-hflip")) xformop=TJXOP_HFLIP;
if(!strcasecmp(argv[i], "-vflip")) xformop=TJXOP_VFLIP;
if(!strcasecmp(argv[i], "-transpose")) xformop=TJXOP_TRANSPOSE;
if(!strcasecmp(argv[i], "-transverse")) xformop=TJXOP_TRANSVERSE;
if(!strcasecmp(argv[i], "-rot90")) xformop=TJXOP_ROT90;
if(!strcasecmp(argv[i], "-rot180")) xformop=TJXOP_ROT180;
if(!strcasecmp(argv[i], "-rot270")) xformop=TJXOP_ROT270;
if(!strcasecmp(argv[i], "-grayscale")) xformopt|=TJXOPT_GRAY;
if(!strcasecmp(argv[i], "-custom")) customFilter=dummyDCTFilter;
if(!strcasecmp(argv[i], "-nooutput")) xformopt|=TJXOPT_NOOUTPUT;
if(!strcasecmp(argv[i], "-benchtime") && i<argc-1)
else if(!strcasecmp(argv[i], "-hflip")) xformop=TJXOP_HFLIP;
else if(!strcasecmp(argv[i], "-vflip")) xformop=TJXOP_VFLIP;
else if(!strcasecmp(argv[i], "-transpose")) xformop=TJXOP_TRANSPOSE;
else if(!strcasecmp(argv[i], "-transverse")) xformop=TJXOP_TRANSVERSE;
else if(!strcasecmp(argv[i], "-rot90")) xformop=TJXOP_ROT90;
else if(!strcasecmp(argv[i], "-rot180")) xformop=TJXOP_ROT180;
else if(!strcasecmp(argv[i], "-rot270")) xformop=TJXOP_ROT270;
else if(!strcasecmp(argv[i], "-grayscale")) xformopt|=TJXOPT_GRAY;
else if(!strcasecmp(argv[i], "-custom")) customFilter=dummyDCTFilter;
else if(!strcasecmp(argv[i], "-nooutput")) xformopt|=TJXOPT_NOOUTPUT;
else if(!strcasecmp(argv[i], "-benchtime") && i<argc-1)
{
double temp=atof(argv[++i]);
if(temp>0.0) benchtime=temp;
else usage(argv[0]);
}
if(!strcasecmp(argv[i], "-warmup") && i<argc-1)
else if(!strcasecmp(argv[i], "-warmup") && i<argc-1)
{
double temp=atof(argv[++i]);
if(temp>=0.0) warmup=temp;
else usage(argv[0]);
printf("Warmup time = %.1f seconds\n\n", warmup);
}
if(!strcmp(argv[i], "-?")) usage(argv[0]);
if(!strcasecmp(argv[i], "-alloc")) flags&=(~TJFLAG_NOREALLOC);
if(!strcasecmp(argv[i], "-bmp")) ext="bmp";
if(!strcasecmp(argv[i], "-yuv"))
else if(!strcasecmp(argv[i], "-alloc")) flags&=(~TJFLAG_NOREALLOC);
else if(!strcasecmp(argv[i], "-bmp")) ext="bmp";
else if(!strcasecmp(argv[i], "-yuv"))
{
printf("Testing YUV planar encoding/decoding\n\n");
doyuv=1;
}
if(!strcasecmp(argv[i], "-yuvpad") && i<argc-1)
else if(!strcasecmp(argv[i], "-yuvpad") && i<argc-1)
{
int temp=atoi(argv[++i]);
if(temp>=1) yuvpad=temp;
}
if(!strcasecmp(argv[i], "-subsamp") && i<argc-1)
else if(!strcasecmp(argv[i], "-subsamp") && i<argc-1)
{
i++;
if(toupper(argv[i][0])=='G') subsamp=TJSAMP_GRAY;
Expand All @@ -931,8 +930,9 @@ int main(int argc, char *argv[])
}
}
}
if(!strcasecmp(argv[i], "-componly")) componly=1;
if(!strcasecmp(argv[i], "-nowrite")) dowrite=0;
else if(!strcasecmp(argv[i], "-componly")) componly=1;
else if(!strcasecmp(argv[i], "-nowrite")) dowrite=0;
else usage(argv[0]);
}
}

Expand Down
9 changes: 4 additions & 5 deletions tjunittest.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C)2009-2014 D. R. Commander. All Rights Reserved.
* Copyright (C)2009-2014, 2017 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -697,10 +697,9 @@ int main(int argc, char *argv[])
for(i=1; i<argc; i++)
{
if(!strcasecmp(argv[i], "-yuv")) doyuv=1;
if(!strcasecmp(argv[i], "-noyuvpad")) pad=1;
if(!strcasecmp(argv[i], "-alloc")) alloc=1;
if(!strncasecmp(argv[i], "-h", 2) || !strcasecmp(argv[i], "-?"))
usage(argv[0]);
else if(!strcasecmp(argv[i], "-noyuvpad")) pad=1;
else if(!strcasecmp(argv[i], "-alloc")) alloc=1;
else usage(argv[0]);
}
}
if(alloc) printf("Testing automatic buffer allocation\n");
Expand Down

0 comments on commit f3ad13e

Please sign in to comment.