test_disk.c 4.4 KB

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