vfs_split.c 6.3 KB

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