vfs_prefix_to_class.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. lib/vfs - test vfs_prefix_to_class() functionality
  3. Copyright (C) 2011-2024
  4. Free Software Foundation, Inc.
  5. Written by:
  6. Slava Zanko <slavazanko@gmail.com>, 2011, 2013
  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 "tests/mctest.h"
  21. #include "lib/strutil.h"
  22. #include "lib/vfs/xdirentry.h"
  23. #include "lib/vfs/vfs.c" /* for testing static methods */
  24. #include "src/vfs/local/local.c"
  25. static struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
  26. /* --------------------------------------------------------------------------------------------- */
  27. static int
  28. test_which (struct vfs_class *me, const char *path)
  29. {
  30. (void) me;
  31. if ((strcmp (path, "test_1:") == 0) ||
  32. (strcmp (path, "test_2:") == 0) ||
  33. (strcmp (path, "test_3:") == 0) || (strcmp (path, "test_4:") == 0))
  34. return 1;
  35. return -1;
  36. }
  37. /* --------------------------------------------------------------------------------------------- */
  38. /* @Before */
  39. static void
  40. setup (void)
  41. {
  42. str_init_strings (NULL);
  43. vfs_init ();
  44. vfs_init_localfs ();
  45. vfs_setup_work_dir ();
  46. vfs_init_class (&vfs_test_ops1, "testfs1", VFSF_NOLINKS | VFSF_REMOTE, "test1");
  47. vfs_test_ops1.which = test_which;
  48. vfs_register_class (&vfs_test_ops1);
  49. vfs_init_class (&vfs_test_ops2, "testfs2", VFSF_UNKNOWN, "test2");
  50. vfs_register_class (&vfs_test_ops2);
  51. vfs_init_class (&vfs_test_ops3, "testfs3", VFSF_UNKNOWN, "test3");
  52. vfs_register_class (&vfs_test_ops3);
  53. }
  54. /* --------------------------------------------------------------------------------------------- */
  55. /* @After */
  56. static void
  57. teardown (void)
  58. {
  59. vfs_shut ();
  60. str_uninit_strings ();
  61. }
  62. /* --------------------------------------------------------------------------------------------- */
  63. /* @DataSource("test_vfs_prefix_to_class_ds") */
  64. /* *INDENT-OFF* */
  65. static const struct test_vfs_prefix_to_class_ds
  66. {
  67. const char *input_string;
  68. const struct vfs_class *expected_result;
  69. } test_vfs_prefix_to_class_ds[] =
  70. {
  71. { /* 0 */
  72. "test_1:",
  73. &vfs_test_ops1
  74. },
  75. { /* 1 */
  76. "test_2:",
  77. &vfs_test_ops1
  78. },
  79. { /* 2 */
  80. "test_3:",
  81. &vfs_test_ops1
  82. },
  83. { /* 3 */
  84. "test_4:",
  85. &vfs_test_ops1
  86. },
  87. { /* 4 */
  88. "test2:",
  89. &vfs_test_ops2
  90. },
  91. { /* 5 */
  92. "test3:",
  93. &vfs_test_ops3
  94. },
  95. {
  96. "test1:",
  97. NULL
  98. },
  99. { /* 6 */
  100. "test_5:",
  101. NULL
  102. },
  103. { /* 7 */
  104. "test4:",
  105. NULL
  106. },
  107. };
  108. /* *INDENT-ON* */
  109. /* @Test(dataSource = "test_vfs_prefix_to_class_ds") */
  110. /* *INDENT-OFF* */
  111. START_PARAMETRIZED_TEST (test_vfs_prefix_to_class, test_vfs_prefix_to_class_ds)
  112. /* *INDENT-ON* */
  113. {
  114. /* given */
  115. struct vfs_class *actual_result;
  116. /* when */
  117. actual_result = vfs_prefix_to_class ((char *) data->input_string);
  118. /* then */
  119. mctest_assert_ptr_eq (actual_result, data->expected_result);
  120. }
  121. /* *INDENT-OFF* */
  122. END_PARAMETRIZED_TEST
  123. /* *INDENT-ON* */
  124. /* --------------------------------------------------------------------------------------------- */
  125. int
  126. main (void)
  127. {
  128. TCase *tc_core;
  129. tc_core = tcase_create ("Core");
  130. tcase_add_checked_fixture (tc_core, setup, teardown);
  131. /* Add new tests here: *************** */
  132. mctest_add_parameterized_test (tc_core, test_vfs_prefix_to_class, test_vfs_prefix_to_class_ds);
  133. /* *********************************** */
  134. return mctest_run_all (tc_core);
  135. }
  136. /* --------------------------------------------------------------------------------------------- */