vfs_prefix_to_class.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* lib/vfs - test vfs_prefix_to_class() functionality
  2. Copyright (C) 2011 Free Software Foundation, Inc.
  3. Written by:
  4. Slava Zanko <slavazanko@gmail.com>, 2011
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License
  7. as published by the Free Software Foundation; either version 2 of
  8. the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. */
  17. #define TEST_SUITE_NAME "/lib/vfs"
  18. #include <check.h>
  19. #include "lib/global.h"
  20. #include "lib/strutil.h"
  21. #include "lib/vfs/xdirentry.h"
  22. #include "lib/vfs/vfs.c" /* for testing static methods */
  23. #include "src/vfs/local/local.c"
  24. struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3;
  25. struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
  26. static int
  27. test_which (struct vfs_class *me, const char *path)
  28. {
  29. (void) me;
  30. if (
  31. (strcmp(path, "test_1:") == 0) ||
  32. (strcmp(path, "test_2:") == 0) ||
  33. (strcmp(path, "test_3:") == 0) ||
  34. (strcmp(path, "test_4:") == 0)
  35. )
  36. return 1;
  37. return -1;
  38. }
  39. static void
  40. setup (void)
  41. {
  42. str_init_strings (NULL);
  43. vfs_init ();
  44. init_localfs ();
  45. vfs_setup_work_dir ();
  46. test_subclass1.flags = VFS_S_REMOTE;
  47. vfs_s_init_class (&vfs_test_ops1, &test_subclass1);
  48. vfs_test_ops1.name = "testfs1";
  49. vfs_test_ops1.flags = VFSF_NOLINKS;
  50. vfs_test_ops1.prefix = "test1:";
  51. vfs_test_ops1.which = test_which;
  52. vfs_register_class (&vfs_test_ops1);
  53. vfs_s_init_class (&vfs_test_ops2, &test_subclass2);
  54. vfs_test_ops2.name = "testfs2";
  55. vfs_test_ops2.prefix = "test2:";
  56. vfs_register_class (&vfs_test_ops2);
  57. vfs_s_init_class (&vfs_test_ops3, &test_subclass3);
  58. vfs_test_ops3.name = "testfs3";
  59. vfs_test_ops3.prefix = "test3:";
  60. vfs_register_class (&vfs_test_ops3);
  61. }
  62. static void
  63. teardown (void)
  64. {
  65. vfs_shut ();
  66. str_uninit_strings ();
  67. }
  68. /* --------------------------------------------------------------------------------------------- */
  69. START_TEST (test_vfs_prefix_to_class_valid)
  70. {
  71. fail_unless(vfs_prefix_to_class((char *) "test_1:") == &vfs_test_ops1, "'test_1:' doesn't transform to vfs_test_ops1");
  72. fail_unless(vfs_prefix_to_class((char *) "test_2:") == &vfs_test_ops1, "'test_2:' doesn't transform to vfs_test_ops1");
  73. fail_unless(vfs_prefix_to_class((char *) "test_3:") == &vfs_test_ops1, "'test_3:' doesn't transform to vfs_test_ops1");
  74. fail_unless(vfs_prefix_to_class((char *) "test_4:") == &vfs_test_ops1, "'test_4:' doesn't transform to vfs_test_ops1");
  75. fail_unless(vfs_prefix_to_class((char *) "test2:") == &vfs_test_ops2, "'test2:' doesn't transform to vfs_test_ops2");
  76. fail_unless(vfs_prefix_to_class((char *) "test3:") == &vfs_test_ops3, "'test3:' doesn't transform to vfs_test_ops3");
  77. }
  78. END_TEST
  79. /* --------------------------------------------------------------------------------------------- */
  80. START_TEST (test_vfs_prefix_to_class_invalid)
  81. {
  82. fail_unless(vfs_prefix_to_class((char *) "test1:") == NULL, "'test1:' doesn't transform to NULL");
  83. fail_unless(vfs_prefix_to_class((char *) "test_5:") == NULL, "'test_5:' doesn't transform to NULL");
  84. fail_unless(vfs_prefix_to_class((char *) "test4:") == NULL, "'test4:' doesn't transform to NULL");
  85. }
  86. END_TEST
  87. /* --------------------------------------------------------------------------------------------- */
  88. int
  89. main (void)
  90. {
  91. int number_failed;
  92. Suite *s = suite_create (TEST_SUITE_NAME);
  93. TCase *tc_core = tcase_create ("Core");
  94. SRunner *sr;
  95. tcase_add_checked_fixture (tc_core, setup, teardown);
  96. /* Add new tests here: *************** */
  97. tcase_add_test (tc_core, test_vfs_prefix_to_class_valid);
  98. tcase_add_test (tc_core, test_vfs_prefix_to_class_invalid);
  99. /* *********************************** */
  100. suite_add_tcase (s, tc_core);
  101. sr = srunner_create (s);
  102. srunner_set_log (sr, "vfs_prefix_to_class.log");
  103. srunner_run_all (sr, CK_NORMAL);
  104. number_failed = srunner_ntests_failed (sr);
  105. srunner_free (sr);
  106. return (number_failed == 0) ? 0 : 1;
  107. }
  108. /* --------------------------------------------------------------------------------------------- */