relative_cd.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. #ifndef HAVE_CHARSET
  21. #define HAVE_CHARSET 1
  22. #endif
  23. #include "lib/charsets.h"
  24. #include "lib/strutil.h"
  25. #include "lib/vfs/xdirentry.h"
  26. #include "lib/vfs/path.h"
  27. #include "src/vfs/local/local.c"
  28. struct vfs_s_subclass test_subclass1;
  29. struct vfs_class vfs_test_ops1;
  30. static int test_chdir (const vfs_path_t * vpath);
  31. static void
  32. setup (void)
  33. {
  34. str_init_strings (NULL);
  35. vfs_init ();
  36. init_localfs ();
  37. vfs_setup_work_dir ();
  38. test_subclass1.flags = VFS_S_REMOTE;
  39. vfs_s_init_class (&vfs_test_ops1, &test_subclass1);
  40. vfs_test_ops1.name = "testfs1";
  41. vfs_test_ops1.flags = VFSF_NOLINKS;
  42. vfs_test_ops1.prefix = "test1";
  43. vfs_test_ops1.chdir = test_chdir;
  44. vfs_register_class (&vfs_test_ops1);
  45. mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  46. load_codepages_list ();
  47. }
  48. static void
  49. teardown (void)
  50. {
  51. free_codepages_list ();
  52. vfs_shut ();
  53. str_uninit_strings ();
  54. }
  55. /* --------------------------------------------------------------------------------------------- */
  56. static int
  57. test_chdir (const vfs_path_t * vpath)
  58. {
  59. char *path = vfs_path_to_str (vpath);
  60. printf ("test_chdir: %s\n", path);
  61. g_free (path);
  62. return 0;
  63. }
  64. /* --------------------------------------------------------------------------------------------- */
  65. START_TEST (test_relative_cd)
  66. {
  67. vfs_path_t *vpath;
  68. vpath = vfs_path_from_str ("/test1://user:pass@some.host:12345/path/to/dir");
  69. fail_if (mc_chdir(vpath) == -1);
  70. vfs_path_free (vpath);
  71. vpath = vfs_path_from_str_flags ("some-non-exists-dir", VPF_NO_CANON);
  72. fail_if (mc_chdir(vpath) == -1);
  73. vfs_path_free (vpath);
  74. }
  75. END_TEST
  76. /* --------------------------------------------------------------------------------------------- */
  77. /* Relative to panel_correct_path_to_show() */
  78. START_TEST (test_vpath_to_str_filter)
  79. {
  80. vfs_path_t *vpath, *last_vpath;
  81. char *filtered_path;
  82. const vfs_path_element_t *path_element;
  83. vpath = vfs_path_from_str ("/test1://some.host/dir");
  84. path_element = vfs_path_element_clone (vfs_path_get_by_index (vpath, -1));
  85. vfs_path_free (vpath);
  86. last_vpath = vfs_path_new ();
  87. last_vpath->relative = TRUE;
  88. vfs_path_add_element (last_vpath, path_element);
  89. filtered_path = vfs_path_to_str_flags (last_vpath, 0,
  90. VPF_STRIP_HOME | VPF_STRIP_PASSWORD | VPF_HIDE_CHARSET);
  91. vfs_path_free (last_vpath);
  92. fail_unless (strcmp("test1://some.host/dir", filtered_path) == 0, "actual: %s", filtered_path);
  93. g_free (filtered_path);
  94. }
  95. END_TEST
  96. /* --------------------------------------------------------------------------------------------- */
  97. int
  98. main (void)
  99. {
  100. int number_failed;
  101. Suite *s = suite_create (TEST_SUITE_NAME);
  102. TCase *tc_core = tcase_create ("Core");
  103. SRunner *sr;
  104. tcase_add_checked_fixture (tc_core, setup, teardown);
  105. /* Add new tests here: *************** */
  106. tcase_add_test (tc_core, test_relative_cd);
  107. tcase_add_test (tc_core, test_vpath_to_str_filter);
  108. /* *********************************** */
  109. suite_add_tcase (s, tc_core);
  110. sr = srunner_create (s);
  111. srunner_set_log (sr, "relative_cd.log");
  112. srunner_run_all (sr, CK_NORMAL);
  113. number_failed = srunner_ntests_failed (sr);
  114. srunner_free (sr);
  115. return (number_failed == 0) ? 0 : 1;
  116. }
  117. /* --------------------------------------------------------------------------------------------- */