mc_build_filename.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. lib - mc_build_filename() function testing
  3. Copyright (C) 2011-2024
  4. 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/util"
  20. #include "tests/mctest.h"
  21. #include <stdio.h>
  22. #include "lib/strutil.h"
  23. #include "lib/util.h"
  24. /* --------------------------------------------------------------------------------------------- */
  25. /* @Before */
  26. static void
  27. setup (void)
  28. {
  29. }
  30. /* --------------------------------------------------------------------------------------------- */
  31. /* @After */
  32. static void
  33. teardown (void)
  34. {
  35. }
  36. /* --------------------------------------------------------------------------------------------- */
  37. static char *
  38. run_mc_build_filename (int iteration)
  39. {
  40. switch (iteration)
  41. {
  42. case 0:
  43. return mc_build_filename ("test", "path", (char *) NULL);
  44. case 1:
  45. return mc_build_filename ("/test", "path/", (char *) NULL);
  46. case 2:
  47. return mc_build_filename ("/test", "pa/th", (char *) NULL);
  48. case 3:
  49. return mc_build_filename ("/test", "#vfsprefix:", "path ", (char *) NULL);
  50. case 4:
  51. return mc_build_filename ("/test", "vfsprefix://", "path ", (char *) NULL);
  52. case 5:
  53. return mc_build_filename ("/test", "vfs/../prefix:///", "p\\///ath", (char *) NULL);
  54. case 6:
  55. return mc_build_filename ("/test", "path", "..", "/test", "path/", (char *) NULL);
  56. case 7:
  57. return mc_build_filename ("", "path", (char *) NULL);
  58. case 8:
  59. return mc_build_filename ("", "/path", (char *) NULL);
  60. case 9:
  61. return mc_build_filename ("path", "", (char *) NULL);
  62. case 10:
  63. return mc_build_filename ("/path", "", (char *) NULL);
  64. case 11:
  65. return mc_build_filename ("pa", "", "th", (char *) NULL);
  66. case 12:
  67. return mc_build_filename ("/pa", "", "/th", (char *) NULL);
  68. default:
  69. return NULL;
  70. }
  71. }
  72. /* @DataSource("test_mc_build_filename_ds") */
  73. /* *INDENT-OFF* */
  74. static const struct test_mc_build_filename_ds
  75. {
  76. const char *expected_result;
  77. } test_mc_build_filename_ds[] =
  78. {
  79. {"test/path"},
  80. {"/test/path"},
  81. {"/test/pa/th"},
  82. {"/test/#vfsprefix:/path "},
  83. {"/test/vfsprefix://path "},
  84. {"/test/prefix://p\\/ath"},
  85. {"/test/test/path"},
  86. {"path"},
  87. {"path"},
  88. {"path"},
  89. {"/path"},
  90. {"pa/th"},
  91. {"/pa/th"},
  92. };
  93. /* *INDENT-ON* */
  94. /* @Test(dataSource = "test_mc_build_filename_ds") */
  95. /* *INDENT-OFF* */
  96. START_PARAMETRIZED_TEST (test_mc_build_filename, test_mc_build_filename_ds)
  97. /* *INDENT-ON* */
  98. {
  99. /* given */
  100. char *actual_result;
  101. /* when */
  102. actual_result = run_mc_build_filename (_i);
  103. /* then */
  104. mctest_assert_str_eq (actual_result, data->expected_result);
  105. g_free (actual_result);
  106. }
  107. /* *INDENT-OFF* */
  108. END_PARAMETRIZED_TEST
  109. /* *INDENT-ON* */
  110. /* --------------------------------------------------------------------------------------------- */
  111. int
  112. main (void)
  113. {
  114. TCase *tc_core;
  115. tc_core = tcase_create ("Core");
  116. tcase_add_checked_fixture (tc_core, setup, teardown);
  117. /* Add new tests here: *************** */
  118. mctest_add_parameterized_test (tc_core, test_mc_build_filename, test_mc_build_filename_ds);
  119. /* *********************************** */
  120. return mctest_run_all (tc_core);
  121. }
  122. /* --------------------------------------------------------------------------------------------- */