x_basename.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. lib/vfs - x_basename() function testing
  3. Copyright (C) 2011, 2013
  4. The 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. /* @DataSource("test_x_basename_ds") */
  38. /* *INDENT-OFF* */
  39. static const struct test_x_basename_ds
  40. {
  41. const char *input_value;
  42. const char *expected_result;
  43. } test_x_basename_ds[] =
  44. {
  45. {
  46. "/test/path/test2/path2",
  47. "path2"
  48. },
  49. {
  50. "/test/path/test2/path2#vfsprefix",
  51. "path2#vfsprefix"
  52. },
  53. {
  54. "/test/path/test2/path2/vfsprefix://",
  55. "path2/vfsprefix://"
  56. },
  57. {
  58. "/test/path/test2/path2/vfsprefix://subdir",
  59. "subdir"
  60. },
  61. {
  62. "/test/path/test2/path2/vfsprefix://subdir/",
  63. "subdir/"
  64. },
  65. {
  66. "/test/path/test2/path2/vfsprefix://subdir/subdir2",
  67. "subdir2"
  68. },
  69. {
  70. "/test/path/test2/path2/vfsprefix:///",
  71. "/"
  72. },
  73. };
  74. /* *INDENT-ON* */
  75. /* @Test(dataSource = "test_x_basename_ds") */
  76. /* *INDENT-OFF* */
  77. START_PARAMETRIZED_TEST (test_x_basename, test_x_basename_ds)
  78. /* *INDENT-ON* */
  79. {
  80. /* given */
  81. const char *actual_result;
  82. /* when */
  83. actual_result = x_basename (data->input_value);
  84. /* then */
  85. mctest_assert_str_eq (actual_result, data->expected_result);
  86. }
  87. /* *INDENT-OFF* */
  88. END_PARAMETRIZED_TEST
  89. /* *INDENT-ON* */
  90. /* --------------------------------------------------------------------------------------------- */
  91. int
  92. main (void)
  93. {
  94. int number_failed;
  95. Suite *s = suite_create (TEST_SUITE_NAME);
  96. TCase *tc_core = tcase_create ("Core");
  97. SRunner *sr;
  98. tcase_add_checked_fixture (tc_core, setup, teardown);
  99. /* Add new tests here: *************** */
  100. mctest_add_parameterized_test (tc_core, test_x_basename, test_x_basename_ds);
  101. /* *********************************** */
  102. suite_add_tcase (s, tc_core);
  103. sr = srunner_create (s);
  104. srunner_set_log (sr, "x_basename.log");
  105. srunner_run_all (sr, CK_NORMAL);
  106. number_failed = srunner_ntests_failed (sr);
  107. srunner_free (sr);
  108. return (number_failed == 0) ? 0 : 1;
  109. }
  110. /* --------------------------------------------------------------------------------------------- */