Skip to content

Commit ff88ce2

Browse files
committed
base64-test. Keep track of count of failures and count of execs of the program
1 parent 48433be commit ff88ce2

File tree

1 file changed

+73
-51
lines changed

1 file changed

+73
-51
lines changed

base64_conv_tst.sh

+73-51
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,35 @@
55
# -q for 'quiet' mode.
66

77
T=yes
8-
F=0
8+
FAILS=0
99
Q=N
10+
TOTAL=0
1011
if [ x$1 = "x-q" ] ; then Q=Y ; fi
1112

13+
function Base64_Conv_Func {
14+
local out_var=$1;
15+
shift
16+
local ret_str
17+
ret_str=`../run/base64conv 2>/dev/null $*`
18+
((TOTAL++))
19+
eval $out_var=\$ret_str;
20+
}
21+
1222
# simple test cycling through the types. $MEM and $V9 should be same in the end
1323
MEM=123456789aBCDefGHJ
14-
V1=`../run/base64conv 2>/dev/null -i raw -q -e -o hex $MEM`
15-
V2=`../run/base64conv 2>/dev/null -i hex -q -e -o mime $V1`
16-
V3=`../run/base64conv 2>/dev/null -i mime -q -e -o crypt $V2`
17-
V4=`../run/base64conv 2>/dev/null -i crypt -q -e -o cryptBS $V3`
18-
V5=`../run/base64conv 2>/dev/null -i cryptBS -q -e -o mime $V4`
19-
V6=`../run/base64conv 2>/dev/null -i mime -q -e -o cryptBS $V5`
20-
V7=`../run/base64conv 2>/dev/null -i cryptBS -q -e -o crypt $V6`
21-
V8=`../run/base64conv 2>/dev/null -i crypt -q -e -o hex $V7`
22-
V9=`../run/base64conv 2>/dev/null -i hex -q -e -o raw $V8`
24+
Base64_Conv_Func V1 -i raw -q -e -o hex $MEM
25+
Base64_Conv_Func V2 -i hex -q -e -o mime $V1
26+
Base64_Conv_Func V3 -i mime -q -e -o crypt $V2
27+
Base64_Conv_Func V4 -i crypt -q -e -o cryptBS $V3
28+
Base64_Conv_Func V5 -i cryptBS -q -e -o mime $V4
29+
Base64_Conv_Func V6 -i mime -q -e -o cryptBS $V5
30+
Base64_Conv_Func V7 -i cryptBS -q -e -o crypt $V6
31+
Base64_Conv_Func V8 -i crypt -q -e -o hex $V7
32+
Base64_Conv_Func V9 -i hex -q -e -o raw $V8
2333
if [ x$MEM != x$V9 ];
2434
then
25-
F=1
26-
echo "Simple test failed. '$MEM' not same as '$9'"
35+
((FAILS++))
36+
echo "Simple test failed. '$MEM' not same as '$V9'"
2737
echo "MEM='$MEM'"
2838
echo "V1 ='$V1'"
2939
echo "V2 ='$V2'"
@@ -47,66 +57,74 @@ function known {
4757
kC=$4
4858
kM=$3
4959
kB=$2
50-
B=`../run/base64conv 2>/dev/null -i raw -q -e -o cryptBS $1`
51-
C=`../run/base64conv 2>/dev/null -i raw -q -e -o crypt $1`
52-
M=`../run/base64conv 2>/dev/null -i raw -q -e -o mime $1`
60+
Base64_Conv_Func B -i raw -q -e -o cryptBS $1
61+
Base64_Conv_Func C -i raw -q -e -o crypt $1
62+
Base64_Conv_Func M -i raw -q -e -o mime $1
5363
T=yes
5464
if [ x$B != x$kB ];
5565
then
5666
echo "Known test failed (cryptBS). '$1' should be '$kB' not '$B'"
5767
T=no
68+
((FAILS++))
5869
fi
5970
if [ x$M != x$kM ];
6071
then
6172
echo "Known test failed (mime). '$1' should be '$kM' not '$M'"
6273
T=no
74+
((FAILS++))
6375
fi
6476
if [ x$C != x$kC ];
6577
then
6678
echo "Known test failed (crypt). '$1' should be '$kC' not '$C'"
6779
T=no
80+
((FAILS++))
6881
fi
69-
C2=`../run/base64conv 2>/dev/null -i cryptBS -q -e -o crypt $B`
70-
M2=`../run/base64conv 2>/dev/null -i cryptBS -q -e -o mime $B`
82+
Base64_Conv_Func C2 -i cryptBS -q -e -o crypt $B
83+
Base64_Conv_Func M2 -i cryptBS -q -e -o mime $B
7184
if [ x$M2 != x$kM ];
7285
then
7386
echo "Known test failed (cryptBS->mime). '$1' should be '$kM' not '$M2'"
7487
T=no
88+
((FAILS++))
7589
fi
7690
if [ x$C2 != x$kC ];
7791
then
7892
echo "Known test failed (cryptBS->crypt). '$1' should be '$kC' not '$C2'"
7993
T=no
94+
((FAILS++))
8095
fi
81-
B2=`../run/base64conv 2>/dev/null -i crypt -q -e -o cryptBS $C`
82-
M2=`../run/base64conv 2>/dev/null -i crypt -q -e -o mime $C`
96+
Base64_Conv_Func B2 -i crypt -q -e -o cryptBS $C
97+
Base64_Conv_Func M2 -i crypt -q -e -o mime $C
8398
if [ x$M2 != x$kM ];
8499
then
85100
echo "Known test failed (crypt->mime). '$1' should be '$kM' not '$M2'"
86101
T=no
102+
((FAILS++))
87103
fi
88104
if [ x$B2 != x$kB ];
89105
then
90106
echo "Known test failed (crypt->cryptBS). '$1' should be '$kB' not '$B2'"
91107
T=no
92-
fi
93-
B2=`../run/base64conv 2>/dev/null -i mime -q -e -o cryptBS $M`
94-
C2=`../run/base64conv 2>/dev/null -i mime -q -e -o crypt $M`
108+
((FAILS++))
109+
fi
110+
Base64_Conv_Func B2 -i mime -q -e -o cryptBS $M
111+
Base64_Conv_Func C2 -i mime -q -e -o crypt $M
95112
if [ x$C2 != x$kC ];
96113
then
97114
echo "Known test failed (mime->crypt). '$1' should be '$kC' not '$C2'"
98115
T=no
116+
((FAILS++))
99117
fi
100118
if [ x$B2 != x$kB ];
101119
then
102120
echo "Known test failed (mime->cryptBS). '$1' should be '$kB' not '$B2'"
103121
T=no
104-
fi
122+
((FAILS++))
123+
fi
105124
if [ x$T = "xyes" ];
106125
then
107126
if [ $Q = "N" ] ; then echo "Success known test param = $1" ; fi
108127
else
109-
F=1
110128
echo "Failure known test param = $1"
111129
fi
112130
}
@@ -131,33 +149,33 @@ if [ $Q = "N" ] ; then echo "performing NULL checks" ; fi
131149
T=yes
132150
B2=000000000000
133151
C2=........
134-
B=`../run/base64conv 2>/dev/null -q -i hex -o crypt $B2`
135-
C=`../run/base64conv 2>/dev/null -q -o hex -i crypt $C2`
152+
Base64_Conv_Func B -q -i hex -o crypt $B2
153+
Base64_Conv_Func C -q -o hex -i crypt $C2
136154
if [ x$B != "x$C2" -o x$C != "x$B2" ];
137155
then
138156
echo "failed! crypt";
139157
T=no
158+
((FAILS++))
140159
fi
141-
B=`../run/base64conv 2>/dev/null -q -i hex -o cryptBS $B2`
142-
C=`../run/base64conv 2>/dev/null -q -o hex -i cryptBS $C2`
160+
Base64_Conv_Func B -q -i hex -o cryptBS $B2
161+
Base64_Conv_Func C -q -o hex -i cryptBS $C2
143162
if [ x$B != "x$C2" -o x$C != "x$B2" ];
144163
then
145164
echo "failed! cryptBS";
146165
T=no
166+
((FAILS++))
147167
fi
148168
C2=AAAAAAAA
149-
B=`../run/base64conv 2>/dev/null -q -i hex -o mime $B2`
150-
C=`../run/base64conv 2>/dev/null -q -o hex -i mime $C2`
169+
Base64_Conv_Func B -q -i hex -o mime $B2
170+
Base64_Conv_Func C -q -o hex -i mime $C2
151171
if [ x$B != "x$C2" -o x$C != "x$B2" ];
152172
then
153173
echo "failed! mime";
154174
T=no
175+
((FAILS++))
155176
fi
156-
if [ x$T = "xyes" ];
157-
then
177+
if [ x$T = "xyes" ]; then
158178
if [ $Q = "N" ] ; then echo "ALL null tests were valid" ; fi
159-
else
160-
F=1
161179
fi
162180

163181
#########################################
@@ -171,44 +189,44 @@ function comp {
171189
then
172190
echo "$3: '$1' is not equal to '$2'"
173191
T=no
192+
((FAILS++))
174193
fi
175194
}
176195

177196
function tst {
178197
T=yes
179-
B=`../run/base64conv 2>/dev/null -i raw -q -e -o cryptBS $1`
180-
C=`../run/base64conv 2>/dev/null -i raw -q -e -o crypt $1`
181-
M=`../run/base64conv 2>/dev/null -i raw -q -e -o mime $1`
198+
Base64_Conv_Func B -i raw -q -e -o cryptBS $1
199+
Base64_Conv_Func C -i raw -q -e -o crypt $1
200+
Base64_Conv_Func M -i raw -q -e -o mime $1
182201

183-
R=`../run/base64conv 2>/dev/null -i crypt -q -e -o cryptBS $C`
184-
R=`../run/base64conv 2>/dev/null -i cryptBS -q -e -o raw $R`
202+
Base64_Conv_Func R -i crypt -q -e -o cryptBS $C
203+
Base64_Conv_Func R -i cryptBS -q -e -o raw $R
185204
comp x$1 x$R "crypt_cryptBS (1)"
186205

187-
R=`../run/base64conv 2>/dev/null -i mime -q -e -o cryptBS $M`
188-
R=`../run/base64conv 2>/dev/null -i cryptBS -q -e -o raw $R`
206+
Base64_Conv_Func R -i mime -q -e -o cryptBS $M
207+
Base64_Conv_Func R -i cryptBS -q -e -o raw $R
189208
comp x$1 x$R "mime_cryptBS (2)"
190209

191-
R=`../run/base64conv 2>/dev/null -i cryptBS -q -e -o crypt $B`
192-
R=`../run/base64conv 2>/dev/null -i crypt -q -e -o raw $R`
210+
Base64_Conv_Func R -i cryptBS -q -e -o crypt $B
211+
Base64_Conv_Func R -i crypt -q -e -o raw $R
193212
comp x$1 x$R "cryptBS_crypt (3)"
194213

195-
R=`../run/base64conv 2>/dev/null -i mime -q -e -o crypt $M`
196-
R=`../run/base64conv 2>/dev/null -i crypt -q -e -o raw $R`
214+
Base64_Conv_Func R -i mime -q -e -o crypt $M
215+
Base64_Conv_Func R -i crypt -q -e -o raw $R
197216
comp x$1 x$R "mime_crypt (4)"
198217

199-
R=`../run/base64conv 2>/dev/null -i cryptBS -q -e -o mime $B`
200-
R=`../run/base64conv 2>/dev/null -i mime -q -e -o raw $R`
218+
Base64_Conv_Func R -i cryptBS -q -e -o mime $B
219+
Base64_Conv_Func R -i mime -q -e -o raw $R
201220
comp a$1 a$R "cryptBS_mime (5)"
202221

203-
R=`../run/base64conv 2>/dev/null -i crypt -q -e -o mime $C`
204-
R=`../run/base64conv 2>/dev/null -i mime -q -e -o raw $R`
222+
Base64_Conv_Func R -i crypt -q -e -o mime $C
223+
Base64_Conv_Func R -i mime -q -e -o raw $R
205224
comp b$1 b$R "crypt_mime (6)"
206225

207226
if [ x$T = "xyes" ];
208227
then
209228
if [ $Q = "N" ] ; then echo "Success multi-convert test param = $1" ; fi
210229
else
211-
F=1
212230
echo "Failure multi-convert test param = $1"
213231
fi
214232
}
@@ -397,5 +415,9 @@ tst $P
397415

398416
# if there were no failures, then list so. This is so there
399417
# is SOME output in -q mode, if all tests passed.
400-
if [ x$F = "x0" ] ; then echo "All tests succeeded" ; fi
418+
if [ x$FAILS = "x0" ] ; then
419+
echo "All tests succeeded. $TOTAL calls to ../run/base64conv"
420+
else
421+
echo "There were $FAILS failures, from $TOTAL calls to ../run/base64conv"
422+
fi
401423

0 commit comments

Comments
 (0)