From b862734c00dc8df767a079f769a1d9b59081e470 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 31 May 2017 23:11:40 +0100 Subject: [PATCH] test: Add module tests for ip_network_is_subset_of Signed-off-by: Michael Tremer --- Makefile.am | 1 + test/functions/ip/ip_network_is_subnet_of | 44 +++++++++++++++++++++ test/test-functions | 48 +++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100755 test/functions/ip/ip_network_is_subnet_of create mode 100644 test/test-functions diff --git a/Makefile.am b/Makefile.am index c9a71557..3856d7db 100644 --- a/Makefile.am +++ b/Makefile.am @@ -448,6 +448,7 @@ TESTS = \ test/functions/ip/ip_get_prefix \ test/functions/ip/ip_is_network \ test/functions/ip/ip_is_valid \ + test/functions/ip/ip_network_is_subnet_of \ test/functions/ip/ip_prefix_is_valid \ test/functions/ip/ip_protocol_is_supported \ test/functions/ip/ip_split_prefix diff --git a/test/functions/ip/ip_network_is_subnet_of b/test/functions/ip/ip_network_is_subnet_of new file mode 100755 index 00000000..d2854839 --- /dev/null +++ b/test/functions/ip/ip_network_is_subnet_of @@ -0,0 +1,44 @@ +#!/bin/bash + +. ${functions} + +# Load test functions +. ${testdir}/test-functions + +############################################################ +# Run a number of valid function calls # +############################################################ + +# IPv6 +test_expect_ok ip_network_is_subset_of 2001:db8:abcd::/32 2001:db8::/32 +test_expect_ok ip_network_is_subset_of 2001:db8:abcd::/33 2001:db8::/32 +test_expect_ok ip_network_is_subset_of 2001:db8:abcd::/36 2001:db8::/32 +test_expect_ok ip_network_is_subset_of 2001:db8:abcd::/48 2001:db8::/32 +test_expect_ok ip_network_is_subset_of 2001:db8:abcd::/52 2001:db8::/32 +test_expect_ok ip_network_is_subset_of 2001:db8:abcd::/64 2001:db8::/32 + +# IPv4 +test_expect_ok ip_network_is_subset_of 1.1.1.1 1.0.0.0/8 +test_expect_ok ip_network_is_subset_of 2.2.2.2 2.0.0.0/8 + +############################################################ +# Run a number of invalid function calls # +############################################################ + +# IPv6 +test_expect_error ip_network_is_subset_of 2001:db8::/31 2001:db8::/32 +test_expect_error ip_network_is_subset_of ::1/128 2001:db8::/32 + +# IPv4 +test_expect_error ip_network_is_subset_of 1.1.1.1 1.0.0.0/16 +test_expect_error ip_network_is_subset_of 1.1.1.1 1.0.0.0/24 + +# Protocols cannot be mixed +test_expect_error ip_network_is_subset_of ::1 127.0.0.0/8 +test_expect_error ip_network_is_subset_of 127.0.0.0/8 ::1 + +# Some garbage inputs +test_expect_error ip_network_is_subset_of 127.0.0.0/8 a.b.c.d/e +test_expect_error ip_network_is_subset_of a.b.c.d/e 127.0.0.0/8 + +exit ${TEST_FAILED} diff --git a/test/test-functions b/test/test-functions new file mode 100644 index 00000000..21ffecaa --- /dev/null +++ b/test/test-functions @@ -0,0 +1,48 @@ +#!/bin/bash +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2017 IPFire Network Development Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +TEST_FAILED=${EXIT_OK} + +test_expect_ok() { + local cmd=$@ + + if ${cmd}; then + echo "OK: ${cmd} exited successfully" + else + echo "ERROR: ${cmd} exited with failure" + TEST_FAILED=${EXIT_ERROR} + fi + + return ${TEST_FAILED} +} + +test_expect_error() { + local cmd=$@ + + if ! ${cmd}; then + echo "OK: ${cmd} exited with error" + else + echo "ERROR: ${cmd} exited successfully" + TEST_FAILED=${EXIT_ERROR} + fi + + return ${TEST_FAILED} +} -- 2.39.2