vfs_path_from_str_flags.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* lib/vfs - test vfs_path_from_str_flags() function
  2. Copyright (C) 2013
  3. The Free Software Foundation, Inc.
  4. Written by:
  5. Slava Zanko <slavazanko@gmail.com>, 2013
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Library General Public License
  8. as published by the Free Software Foundation; either version 2 of
  9. the License, or (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. */
  18. #define TEST_SUITE_NAME "/lib/vfs"
  19. #include "tests/mctest.h"
  20. #include "lib/strutil.h"
  21. #include "lib/vfs/xdirentry.h"
  22. #include "lib/vfs/path.h"
  23. #include "src/vfs/local/local.c"
  24. const char *mc_config_get_home_dir (void);
  25. /* --------------------------------------------------------------------------------------------- */
  26. /* @Mock */
  27. const char *
  28. mc_config_get_home_dir (void)
  29. {
  30. return "/mock/test";
  31. }
  32. /* --------------------------------------------------------------------------------------------- */
  33. /* @Before */
  34. static void
  35. setup (void)
  36. {
  37. str_init_strings (NULL);
  38. vfs_init ();
  39. init_localfs ();
  40. vfs_setup_work_dir ();
  41. }
  42. /* --------------------------------------------------------------------------------------------- */
  43. /* @After */
  44. static void
  45. teardown (void)
  46. {
  47. vfs_shut ();
  48. str_uninit_strings ();
  49. }
  50. /* --------------------------------------------------------------------------------------------- */
  51. /* @DataSource("test_from_to_string_ds") */
  52. /* *INDENT-OFF* */
  53. static const struct test_strip_home_ds
  54. {
  55. const char *input_string;
  56. const char *expected_result;
  57. } test_strip_home_ds[] =
  58. {
  59. { /* 0. */
  60. "/mock/test/some/path",
  61. "~/some/path"
  62. },
  63. { /* 1. */
  64. "/mock/testttt/some/path",
  65. "/mock/testttt/some/path"
  66. },
  67. };
  68. /* *INDENT-ON* */
  69. /* @Test */
  70. /* *INDENT-OFF* */
  71. START_PARAMETRIZED_TEST (test_strip_home, test_strip_home_ds)
  72. /* *INDENT-ON* */
  73. {
  74. /* given */
  75. vfs_path_t *actual_result;
  76. /* when */
  77. actual_result = vfs_path_from_str_flags (data->input_string, VPF_STRIP_HOME);
  78. /* then */
  79. mctest_assert_str_eq (actual_result->str, data->expected_result);
  80. vfs_path_free (actual_result);
  81. }
  82. /* *INDENT-OFF* */
  83. END_PARAMETRIZED_TEST
  84. /* *INDENT-ON* */
  85. /* --------------------------------------------------------------------------------------------- */
  86. int
  87. main (void)
  88. {
  89. int number_failed;
  90. Suite *s = suite_create (TEST_SUITE_NAME);
  91. TCase *tc_core = tcase_create ("Core");
  92. SRunner *sr;
  93. tcase_add_checked_fixture (tc_core, setup, teardown);
  94. /* Add new tests here: *************** */
  95. mctest_add_parameterized_test (tc_core, test_strip_home, test_strip_home_ds);
  96. /* *********************************** */
  97. suite_add_tcase (s, tc_core);
  98. sr = srunner_create (s);
  99. srunner_set_log (sr, "vfs_path_from_str_flags.log");
  100. srunner_run_all (sr, CK_NORMAL);
  101. number_failed = srunner_ntests_failed (sr);
  102. srunner_free (sr);
  103. return (number_failed == 0) ? 0 : 1;
  104. }
  105. /* --------------------------------------------------------------------------------------------- */