vfs_path_string_convert.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* lib/vfs - get vfs_path_t from string
  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 "lib/vfs/path.c" /* for testing static methods */
  23. #include "src/vfs/local/local.c"
  24. struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3;
  25. struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
  26. static void
  27. setup (void)
  28. {
  29. str_init_strings (NULL);
  30. vfs_init ();
  31. init_localfs ();
  32. vfs_setup_work_dir ();
  33. test_subclass1.flags = VFS_S_REMOTE;
  34. vfs_s_init_class (&vfs_test_ops1, &test_subclass1);
  35. vfs_test_ops1.name = "testfs1";
  36. vfs_test_ops1.flags = VFSF_NOLINKS;
  37. vfs_test_ops1.prefix = "test1:";
  38. vfs_register_class (&vfs_test_ops1);
  39. vfs_s_init_class (&vfs_test_ops2, &test_subclass2);
  40. vfs_test_ops2.name = "testfs2";
  41. vfs_test_ops2.prefix = "test2:";
  42. vfs_register_class (&vfs_test_ops2);
  43. vfs_s_init_class (&vfs_test_ops3, &test_subclass3);
  44. vfs_test_ops3.name = "testfs3";
  45. vfs_test_ops3.prefix = "test3:";
  46. vfs_register_class (&vfs_test_ops3);
  47. }
  48. static void
  49. teardown (void)
  50. {
  51. vfs_shut ();
  52. }
  53. /* --------------------------------------------------------------------------------------------- */
  54. #define ETALON_PATH_STR "/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path#test3:/111/22/33"
  55. START_TEST (test_vfs_path_from_to_string)
  56. {
  57. vfs_path_t *vpath;
  58. size_t vpath_len;
  59. char *result;
  60. vpath = vfs_path_from_str (ETALON_PATH_STR);
  61. vpath_len = vfs_path_elements_count(vpath);
  62. fail_unless(vpath_len == 4, "vpath length should be 4 (actial: %d)",vpath_len);
  63. result = vfs_path_to_str(vpath);
  64. fail_unless(strcmp(ETALON_PATH_STR, result) == 0, "expected(%s) doesn't equal to actual(%s)", ETALON_PATH_STR, result);
  65. g_free(result);
  66. vfs_path_free(vpath);
  67. }
  68. END_TEST
  69. /* --------------------------------------------------------------------------------------------- */
  70. int
  71. main (void)
  72. {
  73. int number_failed;
  74. Suite *s = suite_create (TEST_SUITE_NAME);
  75. TCase *tc_core = tcase_create ("Core");
  76. SRunner *sr;
  77. tcase_add_checked_fixture (tc_core, setup, teardown);
  78. /* Add new tests here: *************** */
  79. tcase_add_test (tc_core, test_vfs_path_from_to_string);
  80. /* *********************************** */
  81. suite_add_tcase (s, tc_core);
  82. sr = srunner_create (s);
  83. srunner_set_log (sr, "get_vfs_class.log");
  84. srunner_run_all (sr, CK_NORMAL);
  85. number_failed = srunner_ntests_failed (sr);
  86. srunner_free (sr);
  87. return (number_failed == 0) ? 0 : 1;
  88. }
  89. /* --------------------------------------------------------------------------------------------- */