vfs_path_from_str_flags.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* lib/vfs - test vfs_path_from_str_flags() function
  2. Copyright (C) 2013-2024
  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 <http://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. /* *INDENT-OFF* */
  52. static const struct test_strip_home_ds
  53. {
  54. const char *input_string;
  55. const char *expected_result;
  56. } test_strip_home_ds[] =
  57. {
  58. { /* 0. */
  59. "/mock/test/some/path",
  60. "~/some/path"
  61. },
  62. { /* 1. */
  63. "/mock/testttt/some/path",
  64. "/mock/testttt/some/path"
  65. },
  66. };
  67. /* *INDENT-ON* */
  68. /* @Test */
  69. /* *INDENT-OFF* */
  70. START_PARAMETRIZED_TEST (test_strip_home, test_strip_home_ds)
  71. /* *INDENT-ON* */
  72. {
  73. /* given */
  74. vfs_path_t *actual_result;
  75. /* when */
  76. actual_result = vfs_path_from_str_flags (data->input_string, VPF_STRIP_HOME);
  77. /* then */
  78. mctest_assert_str_eq (actual_result->str, data->expected_result);
  79. vfs_path_free (actual_result, TRUE);
  80. }
  81. /* *INDENT-OFF* */
  82. END_PARAMETRIZED_TEST
  83. /* *INDENT-ON* */
  84. /* --------------------------------------------------------------------------------------------- */
  85. int
  86. main (void)
  87. {
  88. TCase *tc_core;
  89. tc_core = tcase_create ("Core");
  90. tcase_add_checked_fixture (tc_core, setup, teardown);
  91. /* Add new tests here: *************** */
  92. mctest_add_parameterized_test (tc_core, test_strip_home, test_strip_home_ds);
  93. /* *********************************** */
  94. return mctest_run_all (tc_core);
  95. }
  96. /* --------------------------------------------------------------------------------------------- */