From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter =?utf-8?q?M=C3=BCller?= <peter.mueller@ipfire.org> To: development@lists.ipfire.org Subject: [PATCH 2/2] network-functions.pl: add missing unit tests for changed, network membership procedure Date: Sat, 25 Jul 2020 19:08:37 +0000 Message-ID: <982fdab7-5283-0639-f96b-9ef37a955b3d@ipfire.org> In-Reply-To: <6bc37aaf-4096-9ec6-030b-3781a015fc11@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0478430329006167335==" List-Id: <development.lists.ipfire.org> --===============0478430329006167335== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Cc: Tim FitzGeorge <ipfr(a)tfitzgeorge.me.uk> Cc: Alexander Marx <alexander.marx(a)ipfire.org> Signed-off-by: Peter M=C3=BCller <peter.mueller(a)ipfire.org> --- config/cfgroot/network-functions.pl | 34 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-fun= ctions.pl index b6f994522..3d7f04743 100644 --- a/config/cfgroot/network-functions.pl +++ b/config/cfgroot/network-functions.pl @@ -191,7 +191,7 @@ sub check_ip_address_and_netmask($$) { my ($address, $netmask) =3D split(/\//, $network, 2); =20 # Check if the IP address is fine. - #=20 + # my $result =3D &check_ip_address($address); unless ($result) { return $result; @@ -449,14 +449,15 @@ sub get_mac_by_name($) { # Remove the next line to enable the testsuite __END__ =20 -sub assert($) { +sub assert($$) { + my $tst =3D shift; my $ret =3D shift; =20 if ($ret) { return; } =20 - print "ASSERTION ERROR"; + print "ASSERTION ERROR - $tst\n"; exit(1); } =20 @@ -464,10 +465,10 @@ sub testsuite() { my $result; =20 my $address1 =3D &ip2bin("8.8.8.8"); - assert($address1 =3D=3D 134744072); + assert('ip2bin("8.8.8.8")', $address1 =3D=3D 134744072); =20 my $address2 =3D &bin2ip($address1); - assert($address2 eq "8.8.8.8"); + assert("bin2ip($address1)", $address2 eq "8.8.8.8"); =20 # Check if valid IP addresses are correctly recognised. foreach my $address ("1.2.3.4", "192.168.180.1", "127.0.0.1") { @@ -486,34 +487,37 @@ sub testsuite() { } =20 $result =3D &check_ip_address_and_netmask("192.168.180.0/255.255.255.0"); - assert($result); + assert('check_ip_address_and_netmask("192.168.180.0/255.255.255.0")', $resu= lt); =20 $result =3D &convert_netmask2prefix("255.255.254.0"); - assert($result =3D=3D 23); + assert('convert_netmask2prefix("255.255.254.0")', $result =3D=3D 23); =20 $result =3D &convert_prefix2netmask(8); - assert($result eq "255.0.0.0"); + assert('convert_prefix2netmask(8)', $result eq "255.0.0.0"); =20 $result =3D &find_next_ip_address("1.2.3.4", 2); - assert($result eq "1.2.3.6"); + assert('find_next_ip_address("1.2.3.4", 2)', $result eq "1.2.3.6"); =20 $result =3D &network_equal("192.168.0.0/24", "192.168.0.0/255.255.255.0"); - assert($result); + assert('network_equal("192.168.0.0/24", "192.168.0.0/255.255.255.0")', $res= ult); =20 $result =3D &network_equal("192.168.0.0/24", "192.168.0.0/25"); - assert(!$result); + assert('network_equal("192.168.0.0/24", "192.168.0.0/25")', !$result); =20 $result =3D &network_equal("192.168.0.0/24", "192.168.0.128/25"); - assert(!$result); + assert('network_equal("192.168.0.0/24", "192.168.0.128/25")', !$result); =20 $result =3D &network_equal("192.168.0.1/24", "192.168.0.XXX/24"); - assert(!$result); + assert('network_equal("192.168.0.1/24", "192.168.0.XXX/24")', !$result); =20 $result =3D &ip_address_in_network("10.0.1.4", "10.0.0.0/8"); - assert($result); + assert('ip_address_in_network("10.0.1.4", "10.0.0.0/8"', $result); =20 $result =3D &ip_address_in_network("192.168.30.11", "192.168.30.0/255.255.2= 55.0"); - assert($result); + assert('ip_address_in_network("192.168.30.11", "192.168.30.0/255.255.255.0"= )', $result); + + $result =3D &ip_address_in_network("192.168.30.11", "0.0.0.0/8"); + assert('ip_address_in_network("192.168.30.11", "0.0.0.0/8")', !$result); =20 print "Testsuite completed successfully!\n"; =20 --=20 2.26.2 --===============0478430329006167335==--