vfs_s_get_path.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* lib/vfs - test vfs_s_get_path() function
  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/direntry.c" /* for testing static methods */
  22. #include "src/vfs/local/local.c"
  23. #define ARCH_NAME "/path/to/some/file.ext"
  24. #define ETALON_PATH "path/to/test1_file.ext"
  25. #define ETALON_VFS_NAME "#test2:user:pass@host.net"
  26. #define ETALON_VFS_URL_NAME "test2://user:pass@host.net"
  27. struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3;
  28. struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
  29. static int
  30. test1_mock_open_archive(struct vfs_s_super *super, const vfs_path_t *vpath, const vfs_path_element_t *vpath_element)
  31. {
  32. struct vfs_s_inode *root;
  33. char *spath = vfs_path_to_str (vpath);
  34. fail_unless(strcmp("/" ETALON_VFS_URL_NAME ARCH_NAME, spath) == 0,
  35. "etalon(%s) doesn't equal to actual(%s)", "/" ETALON_VFS_URL_NAME ARCH_NAME, spath);
  36. super->name = g_strdup (spath);
  37. super->data = g_new (char *, 1);
  38. root = vfs_s_new_inode (vpath_element->class, super, NULL);
  39. super->root = root;
  40. g_free(spath);
  41. return 0;
  42. }
  43. static int
  44. test1_mock_archive_same (const vfs_path_element_t *vpath_element, struct vfs_s_super *super,
  45. const vfs_path_t *vpath, void *cookie)
  46. {
  47. vfs_path_element_t *path_element = vfs_path_get_by_index(vpath, -1);
  48. (void) vpath_element;
  49. (void) super;
  50. (void) cookie;
  51. if (strcmp(ARCH_NAME, path_element->path) != 0)
  52. return 0;
  53. return 1;
  54. }
  55. static void
  56. setup (void)
  57. {
  58. str_init_strings (NULL);
  59. vfs_init ();
  60. init_localfs ();
  61. vfs_setup_work_dir ();
  62. test_subclass1.flags = VFS_S_REMOTE;
  63. vfs_s_init_class (&vfs_test_ops1, &test_subclass1);
  64. vfs_test_ops1.name = "testfs1";
  65. vfs_test_ops1.flags = VFSF_NOLINKS;
  66. vfs_test_ops1.prefix = "test1:";
  67. vfs_register_class (&vfs_test_ops1);
  68. test_subclass1.open_archive = test1_mock_open_archive;
  69. test_subclass1.archive_same = test1_mock_archive_same;
  70. test_subclass1.archive_check = NULL;
  71. vfs_s_init_class (&vfs_test_ops2, &test_subclass2);
  72. vfs_test_ops2.name = "testfs2";
  73. vfs_test_ops2.prefix = "test2:";
  74. vfs_register_class (&vfs_test_ops2);
  75. vfs_s_init_class (&vfs_test_ops3, &test_subclass3);
  76. vfs_test_ops3.name = "testfs3";
  77. vfs_test_ops3.prefix = "test3:";
  78. vfs_register_class (&vfs_test_ops3);
  79. }
  80. static void
  81. teardown (void)
  82. {
  83. vfs_shut ();
  84. str_uninit_strings ();
  85. }
  86. void
  87. vfs_die (const char *m)
  88. {
  89. printf("VFS_DIE: '%s'\n", m);
  90. }
  91. /* --------------------------------------------------------------------------------------------- */
  92. START_TEST (test_vfs_s_get_path)
  93. {
  94. struct vfs_s_super *archive;
  95. const char *result;
  96. vfs_path_t *vpath = vfs_path_from_str_flags ("/" ETALON_VFS_NAME ARCH_NAME "#test1:/" ETALON_PATH,
  97. VPF_USE_DEPRECATED_PARSER);
  98. result = vfs_s_get_path (vpath, &archive, 0);
  99. fail_unless(strcmp(ETALON_PATH, result) == 0,
  100. "expected(%s) doesn't equal to actual(%s)", ETALON_PATH, result);
  101. fail_unless(strcmp("/" ETALON_VFS_URL_NAME ARCH_NAME,archive->name) == 0,
  102. "expected(%s) doesn't equal to actual(%s)", "/" ETALON_VFS_URL_NAME ARCH_NAME, archive->name);
  103. g_free(vpath);
  104. }
  105. END_TEST
  106. /* --------------------------------------------------------------------------------------------- */
  107. int
  108. main (void)
  109. {
  110. int number_failed;
  111. Suite *s = suite_create (TEST_SUITE_NAME);
  112. TCase *tc_core = tcase_create ("Core");
  113. SRunner *sr;
  114. tcase_add_checked_fixture (tc_core, setup, teardown);
  115. /* Add new tests here: *************** */
  116. tcase_add_test (tc_core, test_vfs_s_get_path);
  117. /* *********************************** */
  118. suite_add_tcase (s, tc_core);
  119. sr = srunner_create (s);
  120. srunner_set_log (sr, "vfs_s_get_path.log");
  121. srunner_run_all (sr, CK_NORMAL);
  122. number_failed = srunner_ntests_failed (sr);
  123. srunner_free (sr);
  124. return (number_failed == 0) ? 0 : 1;
  125. }
  126. /* --------------------------------------------------------------------------------------------- */