vfs_split.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. lib/vfs - test vfs_split() functionality
  3. Copyright (C) 2011-2019
  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/path.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. /* @Before */
  28. static void
  29. setup (void)
  30. {
  31. str_init_strings (NULL);
  32. vfs_init ();
  33. vfs_init_localfs ();
  34. vfs_setup_work_dir ();
  35. vfs_init_class (&vfs_test_ops1, "testfs1", VFS_NOLINKS | VFS_REMOTE, "test1");
  36. vfs_register_class (&vfs_test_ops1);
  37. vfs_init_class (&vfs_test_ops2, "testfs2", VFS_UNKNOWN, "test2");
  38. vfs_register_class (&vfs_test_ops2);
  39. vfs_init_class (&vfs_test_ops3, "testfs3", VFS_UNKNOWN, "test3");
  40. vfs_register_class (&vfs_test_ops3);
  41. }
  42. /* --------------------------------------------------------------------------------------------- */
  43. /* @After */
  44. static void
  45. teardown (void)
  46. {
  47. vfs_shut ();
  48. str_uninit_strings ();
  49. }
  50. /* --------------------------------------------------------------------------------------------- */
  51. /* @DataSource("test_vfs_split_ds") */
  52. /* *INDENT-OFF* */
  53. static const struct test_vfs_split_ds
  54. {
  55. const char *input_string;
  56. const char *expected_path;
  57. const char *expected_local;
  58. const char *expected_op;
  59. const struct vfs_class *expected_result;
  60. } test_vfs_split_ds[] =
  61. {
  62. { /* 0. */
  63. "#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/#test3:/qqq/www/eee.rr",
  64. "#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/",
  65. "qqq/www/eee.rr",
  66. "test3:",
  67. &vfs_test_ops3
  68. },
  69. { /* 1. */
  70. "#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/",
  71. "#test1:/bla-bla/some/path/",
  72. "bla-bla/some/path2/",
  73. "test2:",
  74. &vfs_test_ops2
  75. },
  76. { /* 2. */
  77. "#test1:/bla-bla/some/path/",
  78. "",
  79. "bla-bla/some/path/",
  80. "test1:",
  81. &vfs_test_ops1
  82. },
  83. { /* 3. */
  84. "",
  85. "",
  86. NULL,
  87. NULL,
  88. NULL
  89. },
  90. { /* 4. split with local */
  91. "/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2#test3:/qqq/www/eee.rr",
  92. "/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2",
  93. "qqq/www/eee.rr",
  94. "test3:",
  95. &vfs_test_ops3
  96. },
  97. { /* 5. split with local */
  98. "/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2",
  99. "/local/path/#test1:/bla-bla/some/path/",
  100. "bla-bla/some/path2",
  101. "test2:",
  102. &vfs_test_ops2
  103. },
  104. { /* 6. split with local */
  105. "/local/path/#test1:/bla-bla/some/path/",
  106. "/local/path/",
  107. "bla-bla/some/path/",
  108. "test1:",
  109. &vfs_test_ops1
  110. },
  111. { /* 7. split with local */
  112. "/local/path/",
  113. "/local/path/",
  114. NULL,
  115. NULL,
  116. NULL
  117. },
  118. { /* 8. split with URL */
  119. "#test2:username:passwd@somehost.net/bla-bla/some/path2",
  120. "",
  121. "bla-bla/some/path2",
  122. "test2:username:passwd@somehost.net",
  123. &vfs_test_ops2
  124. },
  125. { /* 9. split URL with semi */
  126. "/local/path/#test1:/bla-bla/some/path/#test2:username:p!a@s#s$w%d@somehost.net/bla-bla/some/path2",
  127. "/local/path/#test1:/bla-bla/some/path/",
  128. "bla-bla/some/path2",
  129. "test2:username:p!a@s#s$w%d@somehost.net",
  130. &vfs_test_ops2
  131. },
  132. { /* 10. split with semi in path */
  133. "#test2:/bl#a-bl#a/so#me/pa#th2",
  134. "",
  135. "bl#a-bl#a/so#me/pa#th2",
  136. "test2:",
  137. &vfs_test_ops2
  138. }
  139. };
  140. /* *INDENT-ON* */
  141. /* @Test(dataSource = "test_vfs_split_ds") */
  142. /* *INDENT-OFF* */
  143. START_PARAMETRIZED_TEST (test_vfs_split, test_vfs_split_ds)
  144. /* *INDENT-ON* */
  145. {
  146. /* given */
  147. const char *local = NULL, *op = NULL;
  148. struct vfs_class *actual_result;
  149. char *path;
  150. path = g_strdup (data->input_string);
  151. /* when */
  152. actual_result = _vfs_split_with_semi_skip_count (path, &local, &op, 0);
  153. /* then */
  154. mctest_assert_ptr_eq (actual_result, data->expected_result);
  155. mctest_assert_str_eq (path, data->expected_path);
  156. mctest_assert_str_eq (local, data->expected_local);
  157. mctest_assert_str_eq (op, data->expected_op);
  158. g_free (path);
  159. }
  160. /* *INDENT-OFF* */
  161. END_PARAMETRIZED_TEST
  162. /* *INDENT-ON* */
  163. /* --------------------------------------------------------------------------------------------- */
  164. int
  165. main (void)
  166. {
  167. int number_failed;
  168. Suite *s = suite_create (TEST_SUITE_NAME);
  169. TCase *tc_core = tcase_create ("Core");
  170. SRunner *sr;
  171. tcase_add_checked_fixture (tc_core, setup, teardown);
  172. /* Add new tests here: *************** */
  173. mctest_add_parameterized_test (tc_core, test_vfs_split, test_vfs_split_ds);
  174. /* *********************************** */
  175. suite_add_tcase (s, tc_core);
  176. sr = srunner_create (s);
  177. srunner_set_log (sr, "vfs_split.log");
  178. srunner_run_all (sr, CK_ENV);
  179. number_failed = srunner_ntests_failed (sr);
  180. srunner_free (sr);
  181. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  182. }
  183. /* --------------------------------------------------------------------------------------------- */