vfs_prefix_to_class.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. lib/vfs - test vfs_prefix_to_class() functionality
  3. Copyright (C) 2011, 2013
  4. The Free Software Foundation, Inc.
  5. Written by:
  6. Slava Zanko <slavazanko@gmail.com>, 2011, 2013
  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 "tests/mctest.h"
  21. #include "lib/strutil.h"
  22. #include "lib/vfs/xdirentry.h"
  23. #include "lib/vfs/vfs.c" /* for testing static methods */
  24. #include "src/vfs/local/local.c"
  25. struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3;
  26. struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
  27. /* --------------------------------------------------------------------------------------------- */
  28. static int
  29. test_which (struct vfs_class *me, const char *path)
  30. {
  31. (void) me;
  32. if ((strcmp (path, "test_1:") == 0) ||
  33. (strcmp (path, "test_2:") == 0) ||
  34. (strcmp (path, "test_3:") == 0) || (strcmp (path, "test_4:") == 0))
  35. return 1;
  36. return -1;
  37. }
  38. /* --------------------------------------------------------------------------------------------- */
  39. /* @Before */
  40. static void
  41. setup (void)
  42. {
  43. str_init_strings (NULL);
  44. vfs_init ();
  45. init_localfs ();
  46. vfs_setup_work_dir ();
  47. test_subclass1.flags = VFS_S_REMOTE;
  48. vfs_s_init_class (&vfs_test_ops1, &test_subclass1);
  49. vfs_test_ops1.name = "testfs1";
  50. vfs_test_ops1.flags = VFSF_NOLINKS;
  51. vfs_test_ops1.prefix = "test1:";
  52. vfs_test_ops1.which = test_which;
  53. vfs_register_class (&vfs_test_ops1);
  54. vfs_s_init_class (&vfs_test_ops2, &test_subclass2);
  55. vfs_test_ops2.name = "testfs2";
  56. vfs_test_ops2.prefix = "test2:";
  57. vfs_register_class (&vfs_test_ops2);
  58. vfs_s_init_class (&vfs_test_ops3, &test_subclass3);
  59. vfs_test_ops3.name = "testfs3";
  60. vfs_test_ops3.prefix = "test3:";
  61. vfs_register_class (&vfs_test_ops3);
  62. }
  63. /* --------------------------------------------------------------------------------------------- */
  64. /* @After */
  65. static void
  66. teardown (void)
  67. {
  68. vfs_shut ();
  69. str_uninit_strings ();
  70. }
  71. /* --------------------------------------------------------------------------------------------- */
  72. /* @DataSource("test_vfs_prefix_to_class_ds") */
  73. /* *INDENT-OFF* */
  74. static const struct test_vfs_prefix_to_class_ds
  75. {
  76. const char *input_string;
  77. const struct vfs_class *expected_result;
  78. } test_vfs_prefix_to_class_ds[] =
  79. {
  80. { /* 0 */
  81. "test_1:",
  82. &vfs_test_ops1
  83. },
  84. { /* 1 */
  85. "test_2:",
  86. &vfs_test_ops1
  87. },
  88. { /* 2 */
  89. "test_3:",
  90. &vfs_test_ops1
  91. },
  92. { /* 3 */
  93. "test_4:",
  94. &vfs_test_ops1
  95. },
  96. { /* 4 */
  97. "test2:",
  98. &vfs_test_ops2
  99. },
  100. { /* 5 */
  101. "test3:",
  102. &vfs_test_ops3
  103. },
  104. {
  105. "test1:",
  106. NULL
  107. },
  108. { /* 6 */
  109. "test_5:",
  110. NULL
  111. },
  112. { /* 7 */
  113. "test4:",
  114. NULL
  115. },
  116. };
  117. /* *INDENT-ON* */
  118. /* @Test(dataSource = "test_vfs_prefix_to_class_ds") */
  119. /* *INDENT-OFF* */
  120. START_PARAMETRIZED_TEST (test_vfs_prefix_to_class, test_vfs_prefix_to_class_ds)
  121. /* *INDENT-ON* */
  122. {
  123. /* given */
  124. struct vfs_class *actual_result;
  125. /* when */
  126. actual_result = vfs_prefix_to_class ((char *) data->input_string);
  127. /* then */
  128. mctest_assert_ptr_eq (actual_result, data->expected_result);
  129. }
  130. /* *INDENT-OFF* */
  131. END_PARAMETRIZED_TEST
  132. /* *INDENT-ON* */
  133. /* --------------------------------------------------------------------------------------------- */
  134. int
  135. main (void)
  136. {
  137. int number_failed;
  138. Suite *s = suite_create (TEST_SUITE_NAME);
  139. TCase *tc_core = tcase_create ("Core");
  140. SRunner *sr;
  141. tcase_add_checked_fixture (tc_core, setup, teardown);
  142. /* Add new tests here: *************** */
  143. mctest_add_parameterized_test (tc_core, test_vfs_prefix_to_class, test_vfs_prefix_to_class_ds);
  144. /* *********************************** */
  145. suite_add_tcase (s, tc_core);
  146. sr = srunner_create (s);
  147. srunner_set_log (sr, "vfs_prefix_to_class.log");
  148. srunner_run_all (sr, CK_NORMAL);
  149. number_failed = srunner_ntests_failed (sr);
  150. srunner_free (sr);
  151. return (number_failed == 0) ? 0 : 1;
  152. }
  153. /* --------------------------------------------------------------------------------------------- */