vfs_prefix_to_class.c 4.6 KB

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