mc_build_filename.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. lib/vfs - mc_build_filename() function testing
  3. Copyright (C) 2011-2015
  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"
  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", NULL);
  44. case 1:
  45. return mc_build_filename ("/test", "path/", NULL);
  46. case 2:
  47. return mc_build_filename ("/test", "pa/th", NULL);
  48. case 3:
  49. return mc_build_filename ("/test", "#vfsprefix:", "path ", NULL);
  50. case 4:
  51. return mc_build_filename ("/test", "vfsprefix://", "path ", NULL);
  52. case 5:
  53. return mc_build_filename ("/test", "vfs/../prefix:///", "p\\///ath", NULL);
  54. case 6:
  55. return mc_build_filename ("/test", "path", "..", "/test", "path/", NULL);
  56. case 7:
  57. return mc_build_filename ("", "path", NULL);
  58. case 8:
  59. return mc_build_filename ("", "/path", NULL);
  60. case 9:
  61. return mc_build_filename ("path", "", NULL);
  62. case 10:
  63. return mc_build_filename ("/path", "", NULL);
  64. case 11:
  65. return mc_build_filename ("pa", "", "th", NULL);
  66. case 12:
  67. return mc_build_filename ("/pa", "", "/th", NULL);
  68. }
  69. return NULL;
  70. }
  71. /* @DataSource("test_mc_build_filename_ds") */
  72. /* *INDENT-OFF* */
  73. static const struct test_mc_build_filename_ds
  74. {
  75. const char *expected_result;
  76. } test_mc_build_filename_ds[] =
  77. {
  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. int number_failed;
  114. Suite *s = suite_create (TEST_SUITE_NAME);
  115. TCase *tc_core = tcase_create ("Core");
  116. SRunner *sr;
  117. tcase_add_checked_fixture (tc_core, setup, teardown);
  118. /* Add new tests here: *************** */
  119. mctest_add_parameterized_test (tc_core, test_mc_build_filename, test_mc_build_filename_ds);
  120. /* *********************************** */
  121. suite_add_tcase (s, tc_core);
  122. sr = srunner_create (s);
  123. srunner_set_log (sr, "mc_build_filename.log");
  124. srunner_run_all (sr, CK_NORMAL);
  125. number_failed = srunner_ntests_failed (sr);
  126. srunner_free (sr);
  127. return (number_failed == 0) ? 0 : 1;
  128. }
  129. /* --------------------------------------------------------------------------------------------- */