From ee03f1415acc9f4f8901593d9045244fbb3bbbb0 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Wed, 12 Jul 2006 12:15:42 +0000 Subject: Moving check_disk functions into utils_disk.c and testing them git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1447 f882894a-f735-0410-b71e-b25c423dba1c --- plugins/tests/Makefile.am | 9 +++-- plugins/tests/test_disk.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++ plugins/tests/test_disk.t | 6 ++++ 3 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 plugins/tests/test_disk.c create mode 100755 plugins/tests/test_disk.t (limited to 'plugins/tests') diff --git a/plugins/tests/Makefile.am b/plugins/tests/Makefile.am index 8ed3fc1d..741499d5 100644 --- a/plugins/tests/Makefile.am +++ b/plugins/tests/Makefile.am @@ -7,9 +7,9 @@ check_PROGRAMS = @EXTRA_TEST@ INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/intl -EXTRA_PROGRAMS = test_utils +EXTRA_PROGRAMS = test_utils test_disk -EXTRA_DIST = test_utils.t +EXTRA_DIST = test_utils.t test_disk.t LIBS = @LIBINTL@ @@ -18,6 +18,11 @@ test_utils_CFLAGS = -g -I.. test_utils_LDFLAGS = -L/usr/local/lib -ltap test_utils_LDADD = ../utils.o +test_disk_SOURCES = test_disk.c +test_disk_CFLAGS = -g -I.. +test_disk_LDFLAGS = -L/usr/local/lib -ltap +test_disk_LDADD = ../utils_disk.o + test: ${noinst_PROGRAMS} perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS) diff --git a/plugins/tests/test_disk.c b/plugins/tests/test_disk.c new file mode 100644 index 00000000..19cc3acd --- /dev/null +++ b/plugins/tests/test_disk.c @@ -0,0 +1,85 @@ +/****************************************************************************** + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + $Id$ + +******************************************************************************/ + +#include "common.h" +#include "utils_disk.h" +#include "tap.h" + +int +main (int argc, char **argv) +{ + struct name_list *exclude_filesystem=NULL; + struct name_list *exclude_fstype=NULL; + + plan_tests(8); + + ok( np_find_name(exclude_filesystem, "/var") == FALSE, "/var not in list"); + np_add_name(&exclude_filesystem, "/var"); + ok( np_find_name(exclude_filesystem, "/var") == TRUE, "is in list now"); + ok( np_find_name(exclude_filesystem, "/home") == FALSE, "/home not in list"); + np_add_name(&exclude_filesystem, "/home"); + ok( np_find_name(exclude_filesystem, "/home") == TRUE, "is in list now"); + ok( np_find_name(exclude_filesystem, "/var") == TRUE, "/var still in list"); + + ok( np_find_name(exclude_fstype, "iso9660") == FALSE, "iso9660 not in list"); + np_add_name(&exclude_fstype, "iso9660"); + ok( np_find_name(exclude_fstype, "iso9660") == TRUE, "is in list now"); + + ok( np_find_name(exclude_filesystem, "iso9660") == FALSE, "Make sure no clashing in variables"); + + + + + /* + range = parse_range_string("6"); + ok( range != NULL, "'6' is valid range"); + ok( range->start == 0, "Start correct"); + ok( range->start_infinity == FALSE, "Not using negative infinity"); + ok( range->end == 6, "End correct"); + ok( range->end_infinity == FALSE, "Not using infinity"); + free(range); + + range = parse_range_string("-7:23"); + ok( range != NULL, "'-7:23' is valid range"); + ok( range->start == -7, "Start correct"); + ok( range->start_infinity == FALSE, "Not using negative infinity"); + ok( range->end == 23, "End correct"); + ok( range->end_infinity == FALSE, "Not using infinity"); + free(range); + + range = parse_range_string(":5.75"); + ok( range != NULL, "':5.75' is valid range"); + ok( range->start == 0, "Start correct"); + ok( range->start_infinity == FALSE, "Not using negative infinity"); + ok( range->end == 5.75, "End correct"); + ok( range->end_infinity == FALSE, "Not using infinity"); + free(range); + + range = parse_range_string("~:-95.99"); + ok( range != NULL, "~:-95.99' is valid range"); + ok( range->start_infinity == TRUE, "Using negative infinity"); + ok( range->end == -95.99, "End correct (with rounding errors)"); + ok( range->end_infinity == FALSE, "Not using infinity"); + free(range); + */ + + return exit_status(); +} + diff --git a/plugins/tests/test_disk.t b/plugins/tests/test_disk.t new file mode 100755 index 00000000..d32567a9 --- /dev/null +++ b/plugins/tests/test_disk.t @@ -0,0 +1,6 @@ +#!/usr/bin/perl +use Test::More; +if (! -e "./test_disk") { + plan skip_all => "./test_disk not compiled - please install tap library to test"; +} +exec "./test_disk"; -- cgit v1.2.3-74-g34f1