vfs_path_from_str_flags.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* lib/vfs - test vfs_path_from_str_flags() function
  2. Copyright (C) 2013-2025
  3. Free Software Foundation, Inc.
  4. Written by:
  5. Slava Zanko <slavazanko@gmail.com>, 2013
  6. This file is part of the Midnight Commander.
  7. The Midnight Commander is free software: you can redistribute it
  8. and/or modify it under the terms of the GNU General Public License as
  9. published by the Free Software Foundation, either version 3 of the License,
  10. or (at your option) any later version.
  11. The Midnight Commander is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program. If not, see <https://www.gnu.org/licenses/>.
  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. /* --------------------------------------------------------------------------------------------- */
  25. /* @Mock */
  26. const char *
  27. mc_config_get_home_dir (void)
  28. {
  29. return "/mock/test";
  30. }
  31. /* --------------------------------------------------------------------------------------------- */
  32. /* @Before */
  33. static void
  34. setup (void)
  35. {
  36. str_init_strings (NULL);
  37. vfs_init ();
  38. vfs_init_localfs ();
  39. vfs_setup_work_dir ();
  40. }
  41. /* --------------------------------------------------------------------------------------------- */
  42. /* @After */
  43. static void
  44. teardown (void)
  45. {
  46. vfs_shut ();
  47. str_uninit_strings ();
  48. }
  49. /* --------------------------------------------------------------------------------------------- */
  50. /* @DataSource("test_from_to_string_ds") */
  51. static const struct test_strip_home_ds
  52. {
  53. const char *input_string;
  54. const char *expected_result;
  55. } test_strip_home_ds[] = {
  56. {
  57. // 0.
  58. "/mock/test/some/path",
  59. "~/some/path",
  60. },
  61. {
  62. // 1.
  63. "/mock/testttt/some/path",
  64. "/mock/testttt/some/path",
  65. },
  66. };
  67. /* @Test */
  68. START_PARAMETRIZED_TEST (test_strip_home, test_strip_home_ds)
  69. {
  70. // given
  71. vfs_path_t *actual_result;
  72. // when
  73. actual_result = vfs_path_from_str_flags (data->input_string, VPF_STRIP_HOME);
  74. // then
  75. mctest_assert_str_eq (actual_result->str, data->expected_result);
  76. vfs_path_free (actual_result, TRUE);
  77. }
  78. END_PARAMETRIZED_TEST
  79. /* --------------------------------------------------------------------------------------------- */
  80. int
  81. main (void)
  82. {
  83. TCase *tc_core;
  84. tc_core = tcase_create ("Core");
  85. tcase_add_checked_fixture (tc_core, setup, teardown);
  86. // Add new tests here: ***************
  87. mctest_add_parameterized_test (tc_core, test_strip_home, test_strip_home_ds);
  88. // ***********************************
  89. return mctest_run_all (tc_core);
  90. }
  91. /* --------------------------------------------------------------------------------------------- */