diff options
Diffstat (limited to 'plugins/tests/test_check_disk.c')
| -rw-r--r-- | plugins/tests/test_check_disk.c | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/plugins/tests/test_check_disk.c b/plugins/tests/test_check_disk.c index 35c57bce..32b46c2d 100644 --- a/plugins/tests/test_check_disk.c +++ b/plugins/tests/test_check_disk.c | |||
| @@ -21,7 +21,8 @@ | |||
| 21 | #include "../../tap/tap.h" | 21 | #include "../../tap/tap.h" |
| 22 | #include "regex.h" | 22 | #include "regex.h" |
| 23 | 23 | ||
| 24 | void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc); | 24 | void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, |
| 25 | int expect, char *desc); | ||
| 25 | 26 | ||
| 26 | int main(int argc, char **argv) { | 27 | int main(int argc, char **argv) { |
| 27 | plan_tests(35); | 28 | plan_tests(35); |
| @@ -70,16 +71,26 @@ int main(int argc, char **argv) { | |||
| 70 | 71 | ||
| 71 | int cflags = REG_NOSUB | REG_EXTENDED; | 72 | int cflags = REG_NOSUB | REG_EXTENDED; |
| 72 | np_test_mount_entry_regex(dummy_mount_list, strdup("/"), cflags, 3, strdup("a")); | 73 | np_test_mount_entry_regex(dummy_mount_list, strdup("/"), cflags, 3, strdup("a")); |
| 73 | np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"), cflags, 3, strdup("regex on dev names:")); | 74 | np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"), cflags, 3, |
| 74 | np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"), cflags, 0, strdup("regex on non existent dev/path:")); | 75 | strdup("regex on dev names:")); |
| 75 | np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"), cflags | REG_ICASE, 0, strdup("regi on non existent dev/path:")); | 76 | np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"), cflags, 0, |
| 76 | np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"), cflags, 3, strdup("partial devname regex match:")); | 77 | strdup("regex on non existent dev/path:")); |
| 77 | np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"), cflags, 1, strdup("partial devname regex match:")); | 78 | np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"), cflags | REG_ICASE, 0, |
| 78 | np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"), cflags | REG_ICASE, 1, strdup("partial devname regi match:")); | 79 | strdup("regi on non existent dev/path:")); |
| 79 | np_test_mount_entry_regex(dummy_mount_list, strdup("home"), cflags, 1, strdup("partial pathname regex match:")); | 80 | np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"), cflags, 3, |
| 80 | np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"), cflags | REG_ICASE, 1, strdup("partial pathname regi match:")); | 81 | strdup("partial devname regex match:")); |
| 81 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), cflags, 2, strdup("grouped regex pathname match:")); | 82 | np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"), cflags, 1, |
| 82 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), cflags | REG_ICASE, 2, strdup("grouped regi pathname match:")); | 83 | strdup("partial devname regex match:")); |
| 84 | np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"), cflags | REG_ICASE, 1, | ||
| 85 | strdup("partial devname regi match:")); | ||
| 86 | np_test_mount_entry_regex(dummy_mount_list, strdup("home"), cflags, 1, | ||
| 87 | strdup("partial pathname regex match:")); | ||
| 88 | np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"), cflags | REG_ICASE, 1, | ||
| 89 | strdup("partial pathname regi match:")); | ||
| 90 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), cflags, 2, | ||
| 91 | strdup("grouped regex pathname match:")); | ||
| 92 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), cflags | REG_ICASE, 2, | ||
| 93 | strdup("grouped regi pathname match:")); | ||
| 83 | 94 | ||
| 84 | filesystem_list test_paths = filesystem_list_init(); | 95 | filesystem_list test_paths = filesystem_list_init(); |
| 85 | mp_int_fs_list_append(&test_paths, "/home/groups"); | 96 | mp_int_fs_list_append(&test_paths, "/home/groups"); |
| @@ -94,15 +105,18 @@ int main(int argc, char **argv) { | |||
| 94 | struct mount_entry *temp_me; | 105 | struct mount_entry *temp_me; |
| 95 | temp_me = p->best_match; | 106 | temp_me = p->best_match; |
| 96 | if (!strcmp(p->name, "/home/groups")) { | 107 | if (!strcmp(p->name, "/home/groups")) { |
| 97 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/groups got right best match: /home"); | 108 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), |
| 109 | "/home/groups got right best match: /home"); | ||
| 98 | } else if (!strcmp(p->name, "/var")) { | 110 | } else if (!strcmp(p->name, "/var")) { |
| 99 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var"); | 111 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var"); |
| 100 | } else if (!strcmp(p->name, "/tmp")) { | 112 | } else if (!strcmp(p->name, "/tmp")) { |
| 101 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /"); | 113 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /"); |
| 102 | } else if (!strcmp(p->name, "/home/tonvoon")) { | 114 | } else if (!strcmp(p->name, "/home/tonvoon")) { |
| 103 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/tonvoon got right best match: /home"); | 115 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), |
| 116 | "/home/tonvoon got right best match: /home"); | ||
| 104 | } else if (!strcmp(p->name, "/dev/c2t0d0s0")) { | 117 | } else if (!strcmp(p->name, "/dev/c2t0d0s0")) { |
| 105 | ok(temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0"); | 118 | ok(temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), |
| 119 | "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0"); | ||
| 106 | } | 120 | } |
| 107 | } | 121 | } |
| 108 | 122 | ||
| @@ -180,7 +194,8 @@ int main(int argc, char **argv) { | |||
| 180 | return exit_status(); | 194 | return exit_status(); |
| 181 | } | 195 | } |
| 182 | 196 | ||
| 183 | void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc) { | 197 | void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, |
| 198 | int expect, char *desc) { | ||
| 184 | regex_t regex; | 199 | regex_t regex; |
| 185 | if (regcomp(®ex, regstr, cflags) == 0) { | 200 | if (regcomp(®ex, regstr, cflags) == 0) { |
| 186 | int matches = 0; | 201 | int matches = 0; |
| @@ -189,7 +204,8 @@ void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regst | |||
| 189 | matches++; | 204 | matches++; |
| 190 | } | 205 | } |
| 191 | } | 206 | } |
| 192 | ok(matches == expect, "%s '%s' matched %i/3 entries. ok: %i/3", desc, regstr, expect, matches); | 207 | ok(matches == expect, "%s '%s' matched %i/3 entries. ok: %i/3", desc, regstr, expect, |
| 208 | matches); | ||
| 193 | 209 | ||
| 194 | } else { | 210 | } else { |
| 195 | ok(false, "regex '%s' not compilable", regstr); | 211 | ok(false, "regex '%s' not compilable", regstr); |
