[Nagiosplug-checkins] nagiosplug/lib/tests test_disk.c,1.2,1.3
Matthias Eble
psychotrahe at users.sourceforge.net
Fri Mar 30 11:00:08 CEST 2007
Update of /cvsroot/nagiosplug/nagiosplug/lib/tests
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv3086/lib/tests
Modified Files:
test_disk.c
Log Message:
Test Cases for check_disk's -r, -R, -C and -g
Index: test_disk.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/lib/tests/test_disk.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- test_disk.c 18 Oct 2006 12:05:10 -0000 1.2
+++ test_disk.c 30 Mar 2007 09:00:05 -0000 1.3
@@ -21,6 +21,12 @@
#include "common.h"
#include "utils_disk.h"
#include "tap.h"
+#include "regex.h"
+
+void np_test_mount_entry_regex (struct mount_entry *dummy_mount_list,
+ char *regstr, int cflags, int expect,
+ char *desc);
+
int
main (int argc, char **argv)
@@ -35,8 +41,9 @@
struct mount_entry *dummy_mount_list;
struct mount_entry *me;
struct mount_entry **mtail = &dummy_mount_list;
+ int cflags = REG_NOSUB | REG_EXTENDED;
- plan_tests(18);
+ plan_tests(29);
ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list");
np_add_name(&exclude_filesystem, "/var/log");
@@ -76,6 +83,37 @@
*mtail = me;
mtail = &me->me_next;
+ np_test_mount_entry_regex(dummy_mount_list, strdup("/"),
+ cflags, 3, strdup("a"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"),
+ cflags, 3,strdup("regex on dev names:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"),
+ cflags, 0,
+ strdup("regex on non existant dev/path:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"),
+ cflags | REG_ICASE,0,
+ strdup("regi on non existant dev/path:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"),
+ cflags, 3,
+ strdup("partial devname regex match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"),
+ cflags, 1,
+ strdup("partial devname regex match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"),
+ cflags | REG_ICASE, 1,
+ strdup("partial devname regi match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("home"),
+ cflags, 1,
+ strdup("partial pathname regex match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"),
+ cflags | REG_ICASE, 1,
+ strdup("partial pathname regi match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"),
+ cflags, 2,
+ strdup("grouped regex pathname match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"),
+ cflags | REG_ICASE, 2,
+ strdup("grouped regi pathname match:"));
np_add_parameter(&paths, "/home/groups");
np_add_parameter(&paths, "/var");
@@ -125,3 +163,22 @@
return exit_status();
}
+
+void
+np_test_mount_entry_regex (struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc)
+{
+ int matches = 0;
+ regex_t re;
+ struct mount_entry *me;
+ if (regcomp(&re,regstr, cflags) == 0) {
+ for (me = dummy_mount_list; me; me= me->me_next) {
+ if(np_regex_match_mount_entry(me,&re))
+ matches++;
+ }
+ ok( matches == expect,
+ "%s '%s' matched %i/3 entries. ok: %i/3",
+ desc, regstr, expect, matches);
+
+ } else
+ ok ( false, "regex '%s' not compileable", regstr);
+}
More information about the Commits
mailing list