x_basename.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* lib/vfs - x_basename() function testing
  2. Copyright (C) 2011 Free Software Foundation, Inc.
  3. Written by:
  4. Slava Zanko <slavazanko@gmail.com>, 2011
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License
  7. as published by the Free Software Foundation; either version 2 of
  8. the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. */
  17. #define TEST_SUITE_NAME "/lib"
  18. #include <check.h>
  19. #include <stdio.h>
  20. #include "lib/global.h"
  21. #include "lib/strutil.h"
  22. #include "lib/util.h"
  23. static void
  24. setup (void)
  25. {
  26. }
  27. static void
  28. teardown (void)
  29. {
  30. }
  31. /* --------------------------------------------------------------------------------------------- */
  32. #define check_x_basename( input, etalon ) \
  33. { \
  34. result = x_basename ( input ); \
  35. fail_unless(strcmp(result, etalon) == 0, \
  36. "\ninput (%s)\nactial (%s) not equal to\netalon (%s)", input, result, etalon); \
  37. }
  38. START_TEST (test_x_basename)
  39. {
  40. const char *result;
  41. check_x_basename ("/test/path/test2/path2", "path2");
  42. check_x_basename ("/test/path/test2/path2#vfsprefix", "path2#vfsprefix");
  43. check_x_basename ("/test/path/test2/path2/vfsprefix://", "path2/vfsprefix://");
  44. check_x_basename ("/test/path/test2/path2/vfsprefix://subdir", "subdir");
  45. check_x_basename ("/test/path/test2/path2/vfsprefix://subdir/", "subdir/");
  46. check_x_basename ("/test/path/test2/path2/vfsprefix://subdir/subdir2", "subdir2");
  47. check_x_basename ("/test/path/test2/path2/vfsprefix:///", "/");
  48. }
  49. END_TEST
  50. /* --------------------------------------------------------------------------------------------- */
  51. int
  52. main (void)
  53. {
  54. int number_failed;
  55. Suite *s = suite_create (TEST_SUITE_NAME);
  56. TCase *tc_core = tcase_create ("Core");
  57. SRunner *sr;
  58. tcase_add_checked_fixture (tc_core, setup, teardown);
  59. /* Add new tests here: *************** */
  60. tcase_add_test (tc_core, test_x_basename);
  61. /* *********************************** */
  62. suite_add_tcase (s, tc_core);
  63. sr = srunner_create (s);
  64. srunner_set_log (sr, "x_basename.log");
  65. srunner_run_all (sr, CK_NORMAL);
  66. number_failed = srunner_ntests_failed (sr);
  67. srunner_free (sr);
  68. return (number_failed == 0) ? 0 : 1;
  69. }
  70. /* --------------------------------------------------------------------------------------------- */