current_dir.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. mc_chdir(cd_dir); \
  55. fail_unless( \
  56. strcmp(etalon, mc_get_current_wd(buffer,MC_MAXPATHLEN)) == 0, \
  57. "\n expected(%s) doesn't equal \nto actual(%s)", etalon, buffer);
  58. START_TEST (set_up_current_dir_url)
  59. {
  60. static struct vfs_s_subclass test_subclass;
  61. static struct vfs_class vfs_test_ops;
  62. char buffer[MC_MAXPATHLEN];
  63. vfs_s_init_class (&vfs_test_ops, &test_subclass);
  64. vfs_test_ops.name = "testfs";
  65. vfs_test_ops.flags = VFSF_NOLINKS;
  66. vfs_test_ops.prefix = "test";
  67. vfs_test_ops.chdir = test_chdir;
  68. vfs_register_class (&vfs_test_ops);
  69. cd_and_check ("/dev/some.file/test://", "/dev/some.file/test://");
  70. cd_and_check ("/dev/some.file/test://bla-bla", "/dev/some.file/test://bla-bla");
  71. cd_and_check ("..", "/dev/some.file/test://");
  72. cd_and_check ("..", "/dev");
  73. cd_and_check ("..", "/");
  74. cd_and_check ("..", "/");
  75. test_subclass.flags = VFS_S_REMOTE;
  76. cd_and_check ("/test://user:pass@host.net/path", "/test://user:pass@host.net/path");
  77. cd_and_check ("..", "/test://user:pass@host.net");
  78. cd_and_check ("..", "/");
  79. }
  80. END_TEST
  81. /* --------------------------------------------------------------------------------------------- */
  82. int
  83. main (void)
  84. {
  85. int number_failed;
  86. Suite *s = suite_create (TEST_SUITE_NAME);
  87. TCase *tc_core = tcase_create ("Core");
  88. SRunner *sr;
  89. tcase_add_checked_fixture (tc_core, setup, teardown);
  90. /* Add new tests here: *************** */
  91. tcase_add_test (tc_core, set_up_current_dir_url);
  92. /* *********************************** */
  93. suite_add_tcase (s, tc_core);
  94. sr = srunner_create (s);
  95. srunner_set_log (sr, "current_dir.log");
  96. srunner_run_all (sr, CK_NORMAL);
  97. number_failed = srunner_ntests_failed (sr);
  98. srunner_free (sr);
  99. return (number_failed == 0) ? 0 : 1;
  100. }
  101. /* --------------------------------------------------------------------------------------------- */