mc_build_filename.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. { "test/path" },
  79. { "/test/path" },
  80. { "/test/pa/th" },
  81. { "/test/#vfsprefix:/path " },
  82. { "/test/vfsprefix://path " },
  83. { "/test/prefix://p\\/ath" },
  84. { "/test/test/path" },
  85. { "path" },
  86. { "path" },
  87. { "path" },
  88. { "/path" },
  89. { "pa/th" },
  90. { "/pa/th" },
  91. };
  92. /* *INDENT-ON* */
  93. /* @Test(dataSource = "test_mc_build_filename_ds") */
  94. /* *INDENT-OFF* */
  95. START_PARAMETRIZED_TEST (test_mc_build_filename, test_mc_build_filename_ds)
  96. /* *INDENT-ON* */
  97. {
  98. /* given */
  99. char *actual_result;
  100. /* when */
  101. actual_result = run_mc_build_filename (_i);
  102. /* then */
  103. mctest_assert_str_eq (actual_result, data->expected_result);
  104. g_free (actual_result);
  105. }
  106. /* *INDENT-OFF* */
  107. END_PARAMETRIZED_TEST
  108. /* *INDENT-ON* */
  109. /* --------------------------------------------------------------------------------------------- */
  110. int
  111. main (void)
  112. {
  113. TCase *tc_core;
  114. tc_core = tcase_create ("Core");
  115. tcase_add_checked_fixture (tc_core, setup, teardown);
  116. /* Add new tests here: *************** */
  117. mctest_add_parameterized_test (tc_core, test_mc_build_filename, test_mc_build_filename_ds);
  118. /* *********************************** */
  119. return mctest_run_all (tc_core);
  120. }
  121. /* --------------------------------------------------------------------------------------------- */