current_dir.c 3.5 KB

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