diff options
Diffstat (limited to 'lib/tests/test_disk.c')
-rw-r--r-- | lib/tests/test_disk.c | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/lib/tests/test_disk.c b/lib/tests/test_disk.c index e48b30aa..ac9db005 100644 --- a/lib/tests/test_disk.c +++ b/lib/tests/test_disk.c | |||
@@ -21,6 +21,12 @@ | |||
21 | #include "common.h" | 21 | #include "common.h" |
22 | #include "utils_disk.h" | 22 | #include "utils_disk.h" |
23 | #include "tap.h" | 23 | #include "tap.h" |
24 | #include "regex.h" | ||
25 | |||
26 | void np_test_mount_entry_regex (struct mount_entry *dummy_mount_list, | ||
27 | char *regstr, int cflags, int expect, | ||
28 | char *desc); | ||
29 | |||
24 | 30 | ||
25 | int | 31 | int |
26 | main (int argc, char **argv) | 32 | main (int argc, char **argv) |
@@ -35,8 +41,9 @@ main (int argc, char **argv) | |||
35 | struct mount_entry *dummy_mount_list; | 41 | struct mount_entry *dummy_mount_list; |
36 | struct mount_entry *me; | 42 | struct mount_entry *me; |
37 | struct mount_entry **mtail = &dummy_mount_list; | 43 | struct mount_entry **mtail = &dummy_mount_list; |
44 | int cflags = REG_NOSUB | REG_EXTENDED; | ||
38 | 45 | ||
39 | plan_tests(18); | 46 | plan_tests(29); |
40 | 47 | ||
41 | ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list"); | 48 | ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list"); |
42 | np_add_name(&exclude_filesystem, "/var/log"); | 49 | np_add_name(&exclude_filesystem, "/var/log"); |
@@ -76,6 +83,37 @@ main (int argc, char **argv) | |||
76 | *mtail = me; | 83 | *mtail = me; |
77 | mtail = &me->me_next; | 84 | mtail = &me->me_next; |
78 | 85 | ||
86 | np_test_mount_entry_regex(dummy_mount_list, strdup("/"), | ||
87 | cflags, 3, strdup("a")); | ||
88 | np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"), | ||
89 | cflags, 3,strdup("regex on dev names:")); | ||
90 | np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"), | ||
91 | cflags, 0, | ||
92 | strdup("regex on non existant dev/path:")); | ||
93 | np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"), | ||
94 | cflags | REG_ICASE,0, | ||
95 | strdup("regi on non existant dev/path:")); | ||
96 | np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"), | ||
97 | cflags, 3, | ||
98 | strdup("partial devname regex match:")); | ||
99 | np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"), | ||
100 | cflags, 1, | ||
101 | strdup("partial devname regex match:")); | ||
102 | np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"), | ||
103 | cflags | REG_ICASE, 1, | ||
104 | strdup("partial devname regi match:")); | ||
105 | np_test_mount_entry_regex(dummy_mount_list, strdup("home"), | ||
106 | cflags, 1, | ||
107 | strdup("partial pathname regex match:")); | ||
108 | np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"), | ||
109 | cflags | REG_ICASE, 1, | ||
110 | strdup("partial pathname regi match:")); | ||
111 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), | ||
112 | cflags, 2, | ||
113 | strdup("grouped regex pathname match:")); | ||
114 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), | ||
115 | cflags | REG_ICASE, 2, | ||
116 | strdup("grouped regi pathname match:")); | ||
79 | 117 | ||
80 | np_add_parameter(&paths, "/home/groups"); | 118 | np_add_parameter(&paths, "/home/groups"); |
81 | np_add_parameter(&paths, "/var"); | 119 | np_add_parameter(&paths, "/var"); |
@@ -125,3 +163,22 @@ main (int argc, char **argv) | |||
125 | return exit_status(); | 163 | return exit_status(); |
126 | } | 164 | } |
127 | 165 | ||
166 | |||
167 | void | ||
168 | np_test_mount_entry_regex (struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc) | ||
169 | { | ||
170 | int matches = 0; | ||
171 | regex_t re; | ||
172 | struct mount_entry *me; | ||
173 | if (regcomp(&re,regstr, cflags) == 0) { | ||
174 | for (me = dummy_mount_list; me; me= me->me_next) { | ||
175 | if(np_regex_match_mount_entry(me,&re)) | ||
176 | matches++; | ||
177 | } | ||
178 | ok( matches == expect, | ||
179 | "%s '%s' matched %i/3 entries. ok: %i/3", | ||
180 | desc, regstr, expect, matches); | ||
181 | |||
182 | } else | ||
183 | ok ( false, "regex '%s' not compileable", regstr); | ||
184 | } | ||