current_dir.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. lib/vfs - manipulate with current directory
  3. Copyright (C) 2011
  4. The Free Software Foundation, Inc.
  5. Written by:
  6. Slava Zanko <slavazanko@gmail.com>, 2011
  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 <config.h>
  21. #include <check.h>
  22. #include "lib/global.h"
  23. #include "lib/strutil.h"
  24. #include "lib/vfs/xdirentry.h"
  25. #include "src/vfs/local/local.c"
  26. static void
  27. setup (void)
  28. {
  29. str_init_strings (NULL);
  30. vfs_init ();
  31. init_localfs ();
  32. vfs_setup_work_dir ();
  33. }
  34. static void
  35. teardown (void)
  36. {
  37. vfs_shut ();
  38. str_uninit_strings ();
  39. }
  40. static int
  41. test_chdir (const vfs_path_t * vpath)
  42. {
  43. #if 0
  44. char *path = vfs_path_to_str (vpath);
  45. printf ("test_chdir: %s\n", path);
  46. g_free (path);
  47. #else
  48. (void) vpath;
  49. #endif
  50. return 0;
  51. }
  52. /* --------------------------------------------------------------------------------------------- */
  53. #define cd_and_check( cd_dir, etalon ) \
  54. vpath = vfs_path_from_str (cd_dir); \
  55. mc_chdir(vpath); \
  56. vfs_path_free (vpath); \
  57. buffer = _vfs_get_cwd (); \
  58. fail_unless( \
  59. strcmp(etalon, buffer) == 0, \
  60. "\n expected(%s) doesn't equal \nto actual(%s)", etalon, buffer); \
  61. g_free (buffer);
  62. START_TEST (set_up_current_dir_url)
  63. {
  64. vfs_path_t *vpath;
  65. static struct vfs_s_subclass test_subclass;
  66. static struct vfs_class vfs_test_ops;
  67. char *buffer;
  68. vfs_s_init_class (&vfs_test_ops, &test_subclass);
  69. vfs_test_ops.name = "testfs";
  70. vfs_test_ops.flags = VFSF_NOLINKS;
  71. vfs_test_ops.prefix = "test";
  72. vfs_test_ops.chdir = test_chdir;
  73. vfs_register_class (&vfs_test_ops);
  74. cd_and_check ("/dev/some.file/test://", "/dev/some.file/test://");
  75. cd_and_check ("/dev/some.file/test://bla-bla", "/dev/some.file/test://bla-bla");
  76. cd_and_check ("..", "/dev/some.file/test://");
  77. cd_and_check ("..", "/dev");
  78. cd_and_check ("..", "/");
  79. cd_and_check ("..", "/");
  80. test_subclass.flags = VFS_S_REMOTE;
  81. cd_and_check ("/test://user:pass@host.net/path", "/test://user:pass@host.net/path");
  82. cd_and_check ("..", "/test://user:pass@host.net/");
  83. cd_and_check ("..", "/");
  84. }
  85. END_TEST
  86. /* --------------------------------------------------------------------------------------------- */
  87. int
  88. main (void)
  89. {
  90. int number_failed;
  91. Suite *s = suite_create (TEST_SUITE_NAME);
  92. TCase *tc_core = tcase_create ("Core");
  93. SRunner *sr;
  94. tcase_add_checked_fixture (tc_core, setup, teardown);
  95. /* Add new tests here: *************** */
  96. tcase_add_test (tc_core, set_up_current_dir_url);
  97. /* *********************************** */
  98. suite_add_tcase (s, tc_core);
  99. sr = srunner_create (s);
  100. srunner_set_log (sr, "current_dir.log");
  101. srunner_run_all (sr, CK_NORMAL);
  102. number_failed = srunner_ntests_failed (sr);
  103. srunner_free (sr);
  104. return (number_failed == 0) ? 0 : 1;
  105. }
  106. /* --------------------------------------------------------------------------------------------- */