relative_cd.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* lib/vfs - test vfs_path_t manipulation functions
  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.c"
  20. #include "lib/strutil.h"
  21. #include "lib/vfs/xdirentry.h"
  22. #include "lib/vfs/path.h"
  23. #include "src/vfs/local/local.c"
  24. struct vfs_s_subclass test_subclass1;
  25. struct vfs_class vfs_test_ops1;
  26. static int test_chdir (const vfs_path_t * vpath);
  27. static void
  28. setup (void)
  29. {
  30. str_init_strings (NULL);
  31. vfs_init ();
  32. init_localfs ();
  33. vfs_setup_work_dir ();
  34. test_subclass1.flags = VFS_S_REMOTE;
  35. vfs_s_init_class (&vfs_test_ops1, &test_subclass1);
  36. vfs_test_ops1.name = "testfs1";
  37. vfs_test_ops1.flags = VFSF_NOLINKS;
  38. vfs_test_ops1.prefix = "test1";
  39. vfs_test_ops1.chdir = test_chdir;
  40. vfs_register_class (&vfs_test_ops1);
  41. mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  42. }
  43. static void
  44. teardown (void)
  45. {
  46. vfs_shut ();
  47. str_uninit_strings ();
  48. }
  49. /* --------------------------------------------------------------------------------------------- */
  50. static int
  51. test_chdir (const vfs_path_t * vpath)
  52. {
  53. char *path = vfs_path_to_str (vpath);
  54. printf ("test_chdir: %s\n", path);
  55. g_free (path);
  56. return 0;
  57. }
  58. /* --------------------------------------------------------------------------------------------- */
  59. START_TEST (test_relative_cd)
  60. {
  61. vfs_path_t *vpath;
  62. vpath = vfs_path_from_str ("/test1://user:pass@some.host:12345/path/to/dir");
  63. fail_if (mc_chdir(vpath) == -1);
  64. vfs_path_free (vpath);
  65. vpath = vfs_path_from_str_flags ("some-non-exists-dir", VPF_NO_CANON);
  66. fail_if (mc_chdir(vpath) == -1);
  67. vfs_path_free (vpath);
  68. }
  69. END_TEST
  70. /* --------------------------------------------------------------------------------------------- */
  71. /* Relative to panel_correct_path_to_show() */
  72. START_TEST (test_vpath_to_str_filter)
  73. {
  74. vfs_path_t *vpath, *last_vpath;
  75. char *filtered_path;
  76. const vfs_path_element_t *path_element;
  77. vpath = vfs_path_from_str ("/test1://some.host/dir");
  78. path_element = vfs_path_element_clone (vfs_path_get_by_index (vpath, -1));
  79. vfs_path_free (vpath);
  80. last_vpath = vfs_path_new ();
  81. last_vpath->relative = TRUE;
  82. vfs_path_add_element (last_vpath, path_element);
  83. filtered_path = vfs_path_to_str_flags (last_vpath, 0,
  84. VPF_STRIP_HOME | VPF_STRIP_PASSWORD | VPF_HIDE_CHARSET);
  85. vfs_path_free (last_vpath);
  86. fail_unless (strcmp("test1://some.host/dir", filtered_path) == 0, "actual: %s", filtered_path);
  87. g_free (filtered_path);
  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_relative_cd);
  101. tcase_add_test (tc_core, test_vpath_to_str_filter);
  102. /* *********************************** */
  103. suite_add_tcase (s, tc_core);
  104. sr = srunner_create (s);
  105. srunner_set_log (sr, "relative_cd.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. /* --------------------------------------------------------------------------------------------- */