x_basename.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. lib/vfs - x_basename() function testing
  3. Copyright (C) 2011
  4. The Free Software Foundation, Inc.
  5. Written by:
  6. Slava Zanko <slavazanko@gmail.com>, 2011
  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 <config.h>
  21. #include <check.h>
  22. #include <stdio.h>
  23. #include "lib/global.h"
  24. #include "lib/strutil.h"
  25. #include "lib/util.h"
  26. static void
  27. setup (void)
  28. {
  29. }
  30. static void
  31. teardown (void)
  32. {
  33. }
  34. /* --------------------------------------------------------------------------------------------- */
  35. #define check_x_basename( input, etalon ) \
  36. { \
  37. result = x_basename ( input ); \
  38. fail_unless(strcmp(result, etalon) == 0, \
  39. "\ninput (%s)\nactial (%s) not equal to\netalon (%s)", input, result, etalon); \
  40. }
  41. START_TEST (test_x_basename)
  42. {
  43. const char *result;
  44. check_x_basename ("/test/path/test2/path2", "path2");
  45. check_x_basename ("/test/path/test2/path2#vfsprefix", "path2#vfsprefix");
  46. check_x_basename ("/test/path/test2/path2/vfsprefix://", "path2/vfsprefix://");
  47. check_x_basename ("/test/path/test2/path2/vfsprefix://subdir", "subdir");
  48. check_x_basename ("/test/path/test2/path2/vfsprefix://subdir/", "subdir/");
  49. check_x_basename ("/test/path/test2/path2/vfsprefix://subdir/subdir2", "subdir2");
  50. check_x_basename ("/test/path/test2/path2/vfsprefix:///", "/");
  51. }
  52. END_TEST
  53. /* --------------------------------------------------------------------------------------------- */
  54. int
  55. main (void)
  56. {
  57. int number_failed;
  58. Suite *s = suite_create (TEST_SUITE_NAME);
  59. TCase *tc_core = tcase_create ("Core");
  60. SRunner *sr;
  61. tcase_add_checked_fixture (tc_core, setup, teardown);
  62. /* Add new tests here: *************** */
  63. tcase_add_test (tc_core, test_x_basename);
  64. /* *********************************** */
  65. suite_add_tcase (s, tc_core);
  66. sr = srunner_create (s);
  67. srunner_set_log (sr, "x_basename.log");
  68. srunner_run_all (sr, CK_NORMAL);
  69. number_failed = srunner_ntests_failed (sr);
  70. srunner_free (sr);
  71. return (number_failed == 0) ? 0 : 1;
  72. }
  73. /* --------------------------------------------------------------------------------------------- */