]>
git.ipfire.org Git - ipfire-3.x.git/blob - initscripts/src/ipcalc-tests
3 # Run some simple ipcalc tests.
5 # Adapted from: Matej Susta <msusta@redhat.com>
7 # Copyright (c) 2009 Red Hat, Inc. All rights reserved.
9 # This copyrighted material is made available to anyone wishing
10 # to use, modify, copy, or redistribute it subject to the terms
11 # and conditions of the GNU General Public License version 2.
13 # This program is distributed in the hope that it will be
14 # useful, but WITHOUT ANY WARRANTY; without even the implied
15 # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 # PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public
19 # License along with this program; if not, write to the Free
20 # Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 # Boston, MA 02110-1301, USA.
32 exitcode
=$
((exitcode
+1))
33 echo -e "Output was:\n$output"
37 echo -n "Checking $@... "
38 output
=$
(sh
-c "$1" 2>&1)
40 [ $rc -eq 0 ] && ok || fail
$output
44 echo -n "Checking $@... "
45 output
=$
(sh
-c "$1" 2>&1)
47 [ $rc -eq 0 ] && fail
$output || ok
51 echo -n "Checking $1... "
52 output
=$
(sh
-c "$1" 2>&1)
54 [ "$output" = "$2" ] && ok || fail
$output
57 echo -n "Checking for ipcalc binary... "
58 [ -x $bin ] ||
{ fail
; exit $exitcode ; }
60 TestSuccess
"$bin --help"
62 TestSuccess
"$bin -c 127.0.0.1"
63 TestSuccess
"$bin -c -6 ::1"
64 TestSuccess
"$bin -c ::1"
66 TestSuccess
"$bin -c 192.168.1.1"
67 TestSuccess
"$bin -c -6 2a01:198:200:300::2"
68 TestSuccess
"$bin -c -6 2a01:198:200:300:0000:0000:0000:2"
69 TestSuccess
"$bin -c -6 2a01:0198:0200:0300:0000:0000:0000:0002"
70 TestSuccess
"$bin -c -6 ::1/128"
71 TestSuccess
"$bin -c -6 fec0::1:0:0:c0a8:8002/64"
73 TestFailure
"$bin -c -6 gggg::"
74 TestFailure
"$bin -b -6 ::1/128"
75 TestFailure
"$bin -c -4 -6 2a01:198:200:300:0000:0000:0000:2"
76 TestFailure
"$bin -c -4 -6 127.0.0.1"
77 TestFailure
"$bin -c -6 127.0.0.1"
78 TestFailure
"$bin -c ::1/999"
79 TestFailure
"$bin -m 192.168.1.1/-1"
80 TestFailure
"$bin -m 192.168.1.1/64"
81 TestFailure
"$bin -m 192.168.1.1/99999"
83 TestOutput
"$bin -b 192.168.1.1/24" "BROADCAST=192.168.1.255"
84 TestOutput
"$bin -b 192.168.1.1 255.255.255.0" "BROADCAST=192.168.1.255"
85 TestOutput
"$bin -m 192.168.1.1/24" "NETMASK=255.255.255.0"
86 TestOutput
"$bin -p 192.168.1.1 255.255.255.0" "PREFIX=24"
87 TestOutput
"$bin -p 192.168.1.1 255.255.255.255" "PREFIX=32"
88 TestOutput
"$bin -p 192.168.1.1 0.0.0.0" "PREFIX=0"
89 TestOutput
"$bin -p 172.16.59.222 255.255.252.0" "PREFIX=22"
90 TestOutput
"$bin -m 172.16.59.222/22" "NETMASK=255.255.252.0"
91 TestOutput
"$bin -m 192.168.1.1" "NETMASK=255.255.255.0"
92 TestOutput
"$bin -m 10.1.2.3" "NETMASK=255.0.0.0"
93 TestOutput
"$bin -m 129.22.4.3" "NETMASK=255.255.0.0"
94 TestOutput
"$bin -n 192.168.1.1/32" "NETWORK=192.168.1.1"
95 TestOutput
"$bin -n 192.168.1.1/0" "NETWORK=0.0.0.0"
97 echo "$exitcode test(s) failed."