c31dba8662d0c0293e92be5b1da91010dfd9595c
[obnox/wireshark/wip.git] / test / test.sh
1 #!/bin/bash
2 #
3 # Test various command line testable aspects of the Wireshark tools
4 #
5 # $Id$
6 #
7 # Wireshark - Network traffic analyzer
8 # By Gerald Combs <gerald@wireshark.org>
9 # Copyright 2005 Ulf Lamping
10 #
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.
15 #
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.
20 #
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.
24
25
26 # an existing capture file
27 CAPFILE=./dhcp.pcap
28
29
30 source test-backend.sh
31
32 source config.sh
33 source suite-clopts.sh
34 source suite-io.sh
35 source suite-capture.sh
36
37
38 #check prerequisites
39 test_step_prerequisites() {
40
41         NOTFOUND=0
42         for i in "$WIRESHARK" "$TSHARK" "$CAPINFOS" "$DUMPCAP" ; do
43                 if [ ! -x $i ]; then
44                         echo "Couldn't find $i"
45                         NOTFOUND=1
46                 fi
47         done 
48         if [ $NOTFOUND -eq 1 ]; then
49                 test_step_failed "Tool not found"
50                 exit 1
51         else
52                 test_step_ok
53         fi
54 }
55
56
57 prerequisites_suite() {
58         test_step_add "Prerequisites settings" test_step_prerequisites
59 }
60
61 test_suite() {
62         test_suite_add "Prerequisites" prerequisites_suite
63         test_suite_add "Command line options" clopt_suite
64         test_suite_add "File I/O" io_suite
65         test_suite_add "Capture" capture_suite
66 }
67
68
69 #test_set_output OFF # doesn't work
70 #test_set_output DOTTED
71 test_set_output VERBOSE
72
73
74 #test_suite_run "TShark command line options" clopt_suite
75 #test_suite_run "TShark capture" capture_suite
76
77
78 # all
79 #test_suite_run "All" test_suite
80 #test_suite_show "All" test_suite
81
82 MENU_LEVEL=0
83
84 menu_title[0]="All"
85 menu_function[0]=test_suite
86
87 echo "----------------------------------------------------------------------"
88
89 for ((a=0; a <= 100000000000 ; a++)) 
90 do
91         TEST_STEPS[0]=0                 # number of steps of a specific nesting level
92         
93         #echo $current_title $current_function
94         test_suite_show "${menu_title[MENU_LEVEL]}" "${menu_function[MENU_LEVEL]}"
95         echo "1-$TEST_STEPS  : Select item"
96         echo "Enter: Test All"
97         if [[ ! $MENU_LEVEL -eq 0 ]]; then
98                 echo "U    : Up"
99         fi
100         echo "Q    : Quit"
101         echo ""
102         read -n1 key
103         newl=$'\x0d'
104         echo "$newl----------------------------------------------------------------------"
105
106         TEST_STEPS[0]=0                 # number of steps of a specific nesting level
107
108         #echo $key
109         case "$key" in
110                 "Q" | "q")
111                 exit 0
112         ;;
113                 "T" | "t" | "")
114 LIMIT_RUNS=1
115 for ((a_runs=1; a_runs <= LIMIT_RUNS ; a_runs++))  # Double parentheses, and "LIMIT" with no "$".
116 do
117                 test_suite_run "${menu_title[MENU_LEVEL]}" "${menu_function[MENU_LEVEL]}"
118 done
119                 echo "----------------------------------------------------------------------"
120         ;;
121                 "U" | "u")
122                 if [[ ! $MENU_LEVEL -eq 0 ]]; then
123                         let "MENU_LEVEL -= 1"
124                         #echo "----------------------------------------------------------------------"
125                 fi
126         ;;
127                 "1")
128                 let "MENU_LEVEL += 1"
129                 menu_title[MENU_LEVEL]=${test_title[1]}
130                 menu_function[MENU_LEVEL]=${test_function[1]}
131         ;;
132                 "2")
133                 let "MENU_LEVEL += 1"
134                 menu_title[MENU_LEVEL]=${test_title[2]}
135                 menu_function[MENU_LEVEL]=${test_function[2]}
136         ;;
137                 "3")
138                 let "MENU_LEVEL += 1"
139                 menu_title[MENU_LEVEL]=${test_title[3]}
140                 menu_function[MENU_LEVEL]=${test_function[3]}
141         ;;
142                 "4")
143                 let "MENU_LEVEL += 1"
144                 menu_title[MENU_LEVEL]=${test_title[4]}
145                 menu_function[MENU_LEVEL]=${test_function[4]}
146         ;;
147                 "5")
148                 let "MENU_LEVEL += 1"
149                 menu_title[MENU_LEVEL]=${test_title[5]}
150                 menu_function[MENU_LEVEL]=${test_function[5]}
151         ;;
152                 "6")
153                 let "MENU_LEVEL += 1"
154                 menu_title[MENU_LEVEL]=${test_title[6]}
155                 menu_function[MENU_LEVEL]=${test_function[6]}
156         ;;
157                 "7")
158                 let "MENU_LEVEL += 1"
159                 menu_title[MENU_LEVEL]=${test_title[7]}
160                 menu_function[MENU_LEVEL]=${test_function[7]}
161         ;;
162                 "8")
163                 let "MENU_LEVEL += 1"
164                 menu_title[MENU_LEVEL]=${test_title[8]}
165                 menu_function[MENU_LEVEL]=${test_function[8]}
166         ;;
167                 "9")
168                 let "MENU_LEVEL += 1"
169                 menu_title[MENU_LEVEL]=${test_title[9]}
170                 menu_function[MENU_LEVEL]=${test_function[9]}
171         ;;
172
173         esac
174 done