1 |
|
|
/* |
2 |
|
|
Teem: Tools to process and visualize scientific data and images . |
3 |
|
|
Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago |
4 |
|
|
Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann |
5 |
|
|
Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah |
6 |
|
|
|
7 |
|
|
This library is free software; you can redistribute it and/or |
8 |
|
|
modify it under the terms of the GNU Lesser General Public License |
9 |
|
|
(LGPL) as published by the Free Software Foundation; either |
10 |
|
|
version 2.1 of the License, or (at your option) any later version. |
11 |
|
|
The terms of redistributing and/or modifying this software also |
12 |
|
|
include exceptions to the LGPL that facilitate static linking. |
13 |
|
|
|
14 |
|
|
This library is distributed in the hope that it will be useful, |
15 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 |
|
|
Lesser General Public License for more details. |
18 |
|
|
|
19 |
|
|
You should have received a copy of the GNU Lesser General Public License |
20 |
|
|
along with this library; if not, write to Free Software Foundation, Inc., |
21 |
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#include "teem/gage.h" |
25 |
|
|
|
26 |
|
|
/* |
27 |
|
|
** Tests: |
28 |
|
|
** gageStackBlurParmParse |
29 |
|
|
** gageStackBlurParmSprint |
30 |
|
|
** gageHestStackBlurParm |
31 |
|
|
** gageStackBlurParmCompare |
32 |
|
|
*/ |
33 |
|
|
|
34 |
|
|
/* experimenting with globals for the sake of simplifying tests */ |
35 |
|
|
int extraFlag[256]; |
36 |
|
|
char *extraParm; |
37 |
|
|
gageStackBlurParm *sbp, *sbq; |
38 |
|
|
airArray *mop; |
39 |
|
|
char *err; |
40 |
|
|
char buff[AIR_STRLEN_LARGE]; |
41 |
|
|
|
42 |
|
|
void |
43 |
|
|
parseFailOrDie(const char *str) { |
44 |
|
|
static const char me[]="parseFailOrDie"; |
45 |
|
|
|
46 |
|
24 |
fprintf(stderr, "%s(\"%s\"): ", me, str); |
47 |
✗✓ |
12 |
if (!gageStackBlurParmParse(sbp, extraFlag, &extraParm, str)) { |
48 |
|
|
fprintf(stderr, "problem did NOT fail!\n"); |
49 |
|
|
airMopError(mop); exit(1); |
50 |
|
|
} |
51 |
|
|
/* else good, we got an error */ |
52 |
|
12 |
airMopAdd(mop, err = biffGetDone(GAGE), airFree, airMopAlways); |
53 |
|
12 |
fprintf(stderr, "did get error: %s", err); |
54 |
|
12 |
return; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
void |
58 |
|
|
parseOrDie(const char *str) { |
59 |
|
|
static const char me[]="parseOrDie"; |
60 |
|
10 |
int differ; |
61 |
|
5 |
char explain[AIR_STRLEN_LARGE]="!explain_not_set!"; |
62 |
|
|
|
63 |
✗✓ |
10 |
if (gageStackBlurParmParse(sbp, extraFlag, &extraParm, str) |
64 |
✓✗ |
10 |
|| gageStackBlurParmSprint(buff, sbp, extraFlag, extraParm)) { |
65 |
|
|
airMopAdd(mop, err = biffGetDone(GAGE), airFree, airMopAlways); |
66 |
|
|
fprintf(stderr, "%s: failed to parse \"%s\" or then sprint: %s\n", |
67 |
|
|
me, str, err); |
68 |
|
|
airMopError(mop); exit(1); |
69 |
|
|
} |
70 |
✗✓ |
5 |
if (gageStackBlurParmParse(sbq, extraFlag, &extraParm, str)) { |
71 |
|
|
airMopAdd(mop, err = biffGetDone(GAGE), airFree, airMopAlways); |
72 |
|
|
fprintf(stderr, "%s: failed to parse \"%s\": %s\n", me, str, err); |
73 |
|
|
airMopError(mop); exit(1); |
74 |
|
|
} |
75 |
|
|
/* can tweak sbq here to make sure compare is working */ |
76 |
|
|
/* |
77 |
|
|
sbp->kspec = nrrdKernelSpecNew(); |
78 |
|
|
nrrdKernelSpecParse(sbp->kspec, "cubic:1,1,0"); |
79 |
|
|
sbq->kspec = nrrdKernelSpecNew(); |
80 |
|
|
nrrdKernelSpecParse(sbq->kspec, "gauss:1,5"); |
81 |
|
|
*/ |
82 |
|
|
/* |
83 |
|
|
sbp->bspec = nrrdBoundarySpecNew(); |
84 |
|
|
sbq->bspec = nrrdBoundarySpecNew(); |
85 |
|
|
nrrdBoundarySpecParse(sbp->bspec, "pad:3"); |
86 |
|
|
nrrdBoundarySpecParse(sbq->bspec, "pad:2"); |
87 |
|
|
*/ |
88 |
✗✓✗✓
|
10 |
if (gageStackBlurParmCompare(sbp, "first", sbq, "second", |
89 |
|
5 |
&differ, explain)) { |
90 |
|
|
airMopAdd(mop, err = biffGetDone(GAGE), airFree, airMopAlways); |
91 |
|
|
fprintf(stderr, "%s: failed to compare: %s", me, err); |
92 |
|
|
airMopError(mop); exit(1); |
93 |
|
|
} |
94 |
✗✓ |
5 |
if (differ) { |
95 |
|
|
fprintf(stderr, "%s: two sbps from same string differ: %s\n", |
96 |
|
|
me, explain); |
97 |
|
|
airMopError(mop); exit(1); |
98 |
|
|
} |
99 |
|
5 |
printf("%s: \"%s\" -> \"%s\"\n", me, str, buff); |
100 |
|
5 |
gageStackBlurParmInit(sbp); |
101 |
|
5 |
gageStackBlurParmInit(sbq); |
102 |
|
|
return; |
103 |
|
5 |
} |
104 |
|
|
|
105 |
|
|
static const char *sbpInfo = |
106 |
|
|
"for testing handling of stack blur parms"; |
107 |
|
|
int |
108 |
|
|
main(int argc, const char **argv) { |
109 |
|
|
/* stock variables */ |
110 |
|
|
const char *me; |
111 |
|
2 |
hestOpt *hopt=NULL; |
112 |
|
|
hestParm *hparm; |
113 |
|
|
/* variables specific to this program */ |
114 |
|
1 |
gageStackBlurParm **sbpv; |
115 |
|
1 |
unsigned int sbpNum, sbpIdx; |
116 |
|
|
|
117 |
|
1 |
me = argv[0]; |
118 |
|
1 |
mop = airMopNew(); |
119 |
|
1 |
hparm = hestParmNew(); |
120 |
|
1 |
airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways); |
121 |
|
1 |
hestOptAdd(&hopt, "sbp", "sbp0", airTypeOther, 1, -1, &sbpv, NULL, |
122 |
|
1 |
"stack blur parms", &sbpNum, NULL, gageHestStackBlurParm); |
123 |
|
1 |
hestParseOrDie(hopt, argc-1, argv+1, hparm, me, sbpInfo, |
124 |
|
|
AIR_TRUE, AIR_TRUE, AIR_TRUE); |
125 |
|
1 |
airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); |
126 |
|
1 |
airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); |
127 |
|
|
|
128 |
|
1 |
printf("%s: command line options: ---------- \n", me); |
129 |
✓✓ |
4 |
for (sbpIdx=0; sbpIdx<sbpNum; sbpIdx++) { |
130 |
✗✓ |
1 |
if (gageStackBlurParmSprint(buff, sbpv[sbpIdx], NULL, NULL)) { |
131 |
|
|
airMopAdd(mop, err = biffGetDone(GAGE), airFree, airMopAlways); |
132 |
|
|
fprintf(stderr, "%s: problem with sbpv[%u]:%s", me, sbpIdx, err); |
133 |
|
|
airMopError(mop); return 1; |
134 |
|
|
} |
135 |
|
1 |
printf("%s: sbp[%u] = \"%s\"\n", me, sbpIdx, buff); |
136 |
|
|
} |
137 |
|
1 |
printf("\n"); |
138 |
|
|
|
139 |
|
1 |
sbp = gageStackBlurParmNew(); |
140 |
|
1 |
airMopAdd(mop, sbp, (airMopper)gageStackBlurParmNix, airMopAlways); |
141 |
|
1 |
sbq = gageStackBlurParmNew(); |
142 |
|
1 |
airMopAdd(mop, sbq, (airMopper)gageStackBlurParmNix, airMopAlways); |
143 |
|
|
|
144 |
|
1 |
printf("%s: testing various broken strings ---------- \n", me); |
145 |
|
1 |
parseFailOrDie("0-8"); |
146 |
|
1 |
parseFailOrDie("0-8-joe"); |
147 |
|
1 |
parseFailOrDie("0-n-8.3"); |
148 |
|
1 |
parseFailOrDie("0-n-8.3-r"); |
149 |
|
1 |
parseFailOrDie("0-4-8.3-uo"); |
150 |
|
1 |
parseFailOrDie("0-4-8.3-u+4"); |
151 |
|
1 |
parseFailOrDie("0-4-8.3-u/k=bingo"); |
152 |
|
1 |
parseFailOrDie("0-4-8.3-u/k=dg:1,5/b=bingo"); |
153 |
|
1 |
parseFailOrDie("0-4-8.3-u/k=dg:1,5/b=pad:joe"); |
154 |
|
1 |
parseFailOrDie("0-4-8.3-u/k=dg:1,5/b=pad:0/v=n"); |
155 |
|
1 |
parseFailOrDie("0-4-8.3-u/k=dg:1,5/b=pad:0/v=1/s=optiL2"); |
156 |
|
1 |
parseFailOrDie("0-4-8.3/k=dg:1,5/b=pad:0/v=1/s=optiL2/dggsm=bingo"); |
157 |
|
1 |
printf("\n"); |
158 |
|
|
|
159 |
|
1 |
printf("%s: testing various okay strings ---------- \n", me); |
160 |
|
1 |
parseOrDie("0-4-8.3"); |
161 |
|
1 |
parseOrDie("0-4-8-o"); |
162 |
|
1 |
parseOrDie("0-4-8.3-u"); |
163 |
|
1 |
parseOrDie("0-4-8.3-u1rpn/k=dg:1,5"); |
164 |
|
1 |
parseOrDie("0-4-8.3-u1rpn/k=dg:1,5/b=pad:42/v=1/dggsm=8"); |
165 |
|
1 |
printf("\n"); |
166 |
|
|
|
167 |
|
1 |
airMopOkay(mop); |
168 |
|
1 |
printf("%s: all okay!\n", me); |
169 |
|
1 |
return 0; |
170 |
|
1 |
} |