Code

e48b30aaf8415c93f94875bd2593dc2d65e8e449
[nagiosplug.git] / lib / tests / test_disk.c
1 /******************************************************************************
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; either version 2 of the License, or
6  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  GNU General Public License for more details.
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  $Id$
18  
19 ******************************************************************************/
21 #include "common.h"
22 #include "utils_disk.h"
23 #include "tap.h"
25 int
26 main (int argc, char **argv)
27 {
28         struct name_list *exclude_filesystem=NULL;
29         struct name_list *exclude_fstype=NULL;
30         struct name_list *dummy_mountlist = NULL;
31         struct name_list *temp_name;
32         struct parameter_list *paths = NULL;
33         struct parameter_list *p;
35         struct mount_entry *dummy_mount_list;
36         struct mount_entry *me;
37         struct mount_entry **mtail = &dummy_mount_list;
39         plan_tests(18);
41         ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list");
42         np_add_name(&exclude_filesystem, "/var/log");
43         ok( np_find_name(exclude_filesystem, "/var/log") == TRUE, "is in list now");
44         ok( np_find_name(exclude_filesystem, "/home") == FALSE, "/home not in list");
45         np_add_name(&exclude_filesystem, "/home");
46         ok( np_find_name(exclude_filesystem, "/home") == TRUE, "is in list now");
47         ok( np_find_name(exclude_filesystem, "/var/log") == TRUE, "/var/log still in list");
49         ok( np_find_name(exclude_fstype, "iso9660") == FALSE, "iso9660 not in list");
50         np_add_name(&exclude_fstype, "iso9660");
51         ok( np_find_name(exclude_fstype, "iso9660") == TRUE, "is in list now");
53         ok( np_find_name(exclude_filesystem, "iso9660") == FALSE, "Make sure no clashing in variables");
55         /*
56         for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) {
57                 printf("Name: %s\n", temp_name->name);
58         }
59         */
61         me = (struct mount_entry *) malloc(sizeof *me);
62         me->me_devname = strdup("/dev/c0t0d0s0");
63         me->me_mountdir = strdup("/");
64         *mtail = me;
65         mtail = &me->me_next;
67         me = (struct mount_entry *) malloc(sizeof *me);
68         me->me_devname = strdup("/dev/c1t0d1s0");
69         me->me_mountdir = strdup("/var");
70         *mtail = me;
71         mtail = &me->me_next;
73         me = (struct mount_entry *) malloc(sizeof *me);
74         me->me_devname = strdup("/dev/c2t0d0s0");
75         me->me_mountdir = strdup("/home");
76         *mtail = me;
77         mtail = &me->me_next;
80         np_add_parameter(&paths, "/home/groups");
81         np_add_parameter(&paths, "/var");
82         np_add_parameter(&paths, "/tmp");
83         np_add_parameter(&paths, "/home/tonvoon");
84         np_add_parameter(&paths, "/dev/c2t0d0s0");
86         np_set_best_match(paths, dummy_mount_list, FALSE);
87         for (p = paths; p; p = p->name_next) {
88                 struct mount_entry *temp_me;
89                 temp_me = p->best_match;
90                 if (! strcmp(p->name, "/home/groups")) {
91                         ok( temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/groups got right best match: /home");
92                 } else if (! strcmp(p->name, "/var")) {
93                         ok( temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var");
94                 } else if (! strcmp(p->name, "/tmp")) {
95                         ok( temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /");
96                 } else if (! strcmp(p->name, "/home/tonvoon")) {
97                         ok( temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/tonvoon got right best match: /home");
98                 } else if (! strcmp(p->name, "/dev/c2t0d0s0")) {
99                         ok( temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0");
100                 }
101         }
103         paths = NULL;   /* Bad boy - should free, but this is a test suite */
104         np_add_parameter(&paths, "/home/groups");
105         np_add_parameter(&paths, "/var");
106         np_add_parameter(&paths, "/tmp");
107         np_add_parameter(&paths, "/home/tonvoon");
108         np_add_parameter(&paths, "/home");
110         np_set_best_match(paths, dummy_mount_list, TRUE);
111         for (p = paths; p; p = p->name_next) {
112                 if (! strcmp(p->name, "/home/groups")) {
113                         ok( ! p->best_match , "/home/groups correctly not found");
114                 } else if (! strcmp(p->name, "/var")) {
115                         ok( p->best_match, "/var found");
116                 } else if (! strcmp(p->name, "/tmp")) {
117                         ok(! p->best_match, "/tmp correctly not found");
118                 } else if (! strcmp(p->name, "/home/tonvoon")) {
119                         ok(! p->best_match, "/home/tonvoon not found");
120                 } else if (! strcmp(p->name, "/home")) {
121                         ok( p->best_match, "/home found");
122                 }
123         }
125         return exit_status();