7 # Wireshark - Network traffic analyzer
8 # By Gerald Combs <gerald@wireshark.org>
9 # Copyright 2005 Ulf Lamping
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # as published by the Free Software Foundation; either version 2
14 # of the License, or (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 # http://www.gnu.org/software/bash/manual/bashref.html "Bash Reference Manual"
29 # http://www.tldp.org/LDP/abs/html/ "Advanced Bash-Scripting Guide"
30 # http://www.tldp.org/LDP/abs/html/colorizing.html "Colorizing" Scripts"
31 # http://www.junit.org/junit/javadoc/3.8.1/index.htm "JUnit javadoc"
33 # check undefined variables
34 # http://www.tldp.org/LDP/abs/html/options.html
39 color_reset="tput sgr0"
40 color_green='\E[32;40m'
42 color_blue='\E[36;40m'
46 TEST_OUTPUT="VERBOSE" # "OFF", "DOTTED", "VERBOSE"
49 TEST_NESTING_LEVEL=0 # nesting level of current test
50 TEST_STEPS[0]=0 # number of steps of a specific nesting level
53 TEST_OK=0 # global count of succeeded steps
54 TEST_FAILED=0 # global count of failed steps
59 # level number of this test item (suite or step)
63 for ((a=0; a <= LIMIT ; a++))
65 if [ ! $a -eq 0 ]; then
68 echo -n "${TEST_STEPS[a]}"
69 if [ $a -eq $TEST_NESTING_LEVEL ]; then
77 # $1 - "OUT", "DOTTED", "VERBOSE"
87 echo -n -e $color_blue
94 # run the actual test suite
98 if [ $TEST_RUN = "ON" ]; then
100 if [ $TEST_FAILED -eq 0 ]; then
101 echo -n -e $color_green
103 echo -n -e $color_red
105 echo "### Test suite results ###"
106 echo -n -e $color_green
108 echo -n -e $color_red
109 echo "Failed: $TEST_FAILED"
114 #if [ $TEST_FAILED -eq 0 ]; then
130 echo -n -e $color_blue
132 echo "### Test suite: $1 ###"
138 # show this test suite subitems
149 # increase step counter of this nesting level
150 let "TEST_STEPS[$TEST_NESTING_LEVEL] += 1"
152 if [ $TEST_RUN = "ON" ]; then
156 # title output if we'll list the subitems
157 if [[ $TEST_RUN = "ON" ]]; then
158 echo -n -e $color_blue
164 if [[ $TEST_NESTING_LEVEL -eq 0 ]]; then
165 pos=${TEST_STEPS[$TEST_NESTING_LEVEL]}
168 test_function[$pos]=$2
169 #echo ${test_title[1]}
173 # reset test step counter back to zero
176 # call the suites function
177 let "TEST_NESTING_LEVEL += 1"
178 TEST_STEPS[$TEST_NESTING_LEVEL]=0
180 let "TEST_NESTING_LEVEL -= 1"
182 # title output (with subitem counter) if we don't listed the subitems
183 if [[ ! $TEST_RUN = "ON" && $TEST_NESTING_LEVEL -eq 0 ]]; then
184 echo -n -e $color_blue
186 echo " Suite: $1 (${TEST_STEPS[TEST_NESTING_LEVEL+1]} subitems)"
198 let "TEST_STEPS[$TEST_NESTING_LEVEL] += 1"
200 if [[ ($TEST_RUN = "ON" && $TEST_OUTPUT = "DOTTED") && $TEST_NESTING_LEVEL -eq 0 ]]; then
204 if [[ ( $TEST_RUN = "ON" && $TEST_OUTPUT = "VERBOSE" ) || $TEST_NESTING_LEVEL -eq 0 ]]; then
205 echo -n -e $color_blue
211 if [ $TEST_RUN = "ON" ]; then
214 #echo "command: "$2" opt1: "$3" opt2: "$4" opt3: "$5" opt4: "$6" opt5: "$7
216 # actually run the command to test now
218 #"$3" "$4" "$5" "$6" "$7"
219 # post precessing step
222 if [[ $TEST_NESTING_LEVEL -eq 0 ]]; then
229 # set the preprocessing function
231 test_step_set_pre() {
235 # set the post processing function
237 test_step_set_post() {
245 # test is running or toplevel item? -> show remark
246 if [[ $TEST_RUN = "ON" || $TEST_NESTING_LEVEL -eq 0 ]]; then
247 # test is running and output is dotted -> newline first
248 if [[ $TEST_RUN = "ON" && $TEST_OUTPUT = "DOTTED" ]]; then
253 echo -n -e $color_blue
260 # the test step succeeded
266 echo -n -e $color_green
268 if [ $TEST_OUTPUT = "VERBOSE" ]; then
277 # the test step failed
280 let "TEST_FAILED += 1"
283 echo -n -e "$color_red"
286 echo "\"$TEST_STEP_NAME\" Failed!"
293 # XXX - add a mechanism to optionally stop here