3 # Test the command line options of the Ethereal tools
7 # Ethereal - Network traffic analyzer
8 # By Gerald Combs <gerald@ethereal.com>
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.
26 # common exit status values
32 # generic: check against a specific exit status with a single char option
33 # $1 command: tethereal
35 # $3 expected exit status: 0
36 test_single_char_options()
38 #echo "command: "$1" opt1: "$2" opt2: "$3" opt3: "$4" opt4: "$5" opt5: "$6
39 $1 -$2 > ./testout.txt 2>&1
41 if [ ! $RETURNVALUE -eq $3 ]; then
42 test_step_failed "exit status: $RETURNVALUE"
50 # check exit status when reading an existing file
51 clopts_step_existing_file() {
52 $TETHEREAL -r $CAPFILE > ./testout.txt 2>&1
54 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
55 test_step_failed "exit status: $RETURNVALUE"
63 # check exit status when reading a none existing file
64 clopts_step_nonexisting_file() {
65 $TETHEREAL -r ThisFileDontExist.pcap > ./testout.txt 2>&1
67 if [ ! $RETURNVALUE -eq $EXIT_ERROR ]; then
68 test_step_failed "exit status: $RETURNVALUE"
76 # check exit status of all single char option being invalid
77 clopts_suite_tethereal_invalid_chars() {
78 for index in A B C E F H I J K M N O P Q R T U W X Y Z a b c d e f g i j k m o r s t u w y z
80 test_step_add "Invalid Tethereal parameter -$index, exit status must be $EXIT_COMMAND_LINE" "test_single_char_options $TETHEREAL $index $EXIT_COMMAND_LINE"
85 # check exit status of all single char option being valid
86 clopts_suite_valid_chars() {
87 for index in D G L h v
89 test_step_add "Valid Tethereal parameter -$index, exit status must be $EXIT_OK" "test_single_char_options $TETHEREAL $index $EXIT_OK"
96 # check exit status and grep output string of an invalid capture filter
97 clopts_step_invalid_capfilter() {
98 $TETHEREAL -f 'jkghg' -w './testout.pcap' > ./testout.txt 2>&1
100 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
101 test_step_failed "exit status: $RETURNVALUE"
103 grep -i 'Invalid capture filter: "jkghg"' ./testout.txt > /dev/null
104 if [ $? -eq 0 ]; then
108 test_step_failed "Infos"
113 # check exit status and grep output string of an invalid interface
114 clopts_step_invalid_interface() {
115 $TETHEREAL -i invalid_interface -w './testout.pcap' > ./testout.txt 2>&1
117 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
118 test_step_failed "exit status: $RETURNVALUE"
120 grep -i 'The capture session could not be initiated!' ./testout.txt > /dev/null
121 if [ $? -eq 0 ]; then
125 test_step_failed "Infos"
130 # check exit status and grep output string of an invalid interface index
131 # (valid interface indexes start with 1)
132 clopts_step_invalid_interface_index() {
133 $TETHEREAL -i 0 -w './testout.pcap' > ./testout.txt 2>&1
135 if [ ! $RETURNVALUE -eq $EXIT_COMMAND_LINE ]; then
136 test_step_failed "exit status: $RETURNVALUE"
138 grep -i 'there is no interface with that adapter index' ./testout.txt > /dev/null
139 if [ $? -eq 0 ]; then
143 test_step_failed "Infos"
148 # check exit status and grep output string of an invalid capture filter
149 # XXX - how to efficiently test the *invalid* flags?
150 clopts_step_valid_name_resolving() {
151 $TETHEREAL -N mntC -a duration:1 > ./testout.txt 2>&1
153 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
154 test_step_failed "exit status: $RETURNVALUE"
160 # check exit status of some basic functions
161 clopts_suite_basic() {
162 test_step_add "Exit status for existing file: \""$CAPFILE"\" must be 0" clopts_step_existing_file
163 test_step_add "Exit status for none existing files must be 2" clopts_step_nonexisting_file
172 test_step_set_post clopts_post_step
173 test_suite_add "Basic tests" clopts_suite_basic
174 test_suite_add "Invalid Tethereal single char options" clopts_suite_tethereal_invalid_chars
175 test_suite_add "Valid Tethereal single char options" clopts_suite_valid_chars
176 test_step_add "Invalid capture filter -f" clopts_step_invalid_capfilter
177 test_step_add "Invalid capture interface -i" clopts_step_invalid_interface
178 test_step_add "Invalid capture interface index 0" clopts_step_invalid_interface_index
179 test_step_add "Valid name resolution options -N (1s)" clopts_step_valid_name_resolving
180 #test_remark_add "Undocumented command line option: G"
181 #test_remark_add "Options currently unchecked: S, V, l, n, p, q and x"