mc_build_filename.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* lib/vfs - mc_build_filename() 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_mc_build_filename( inargs, etalon ) \
  33. { \
  34. result = mc_build_filename inargs; \
  35. fail_unless( strcmp (result, etalon) == 0, \
  36. "\nactial (%s) not equal to\netalon (%s)", result, etalon); \
  37. g_free (result); \
  38. }
  39. START_TEST (test_mc_build_filename)
  40. {
  41. char *result;
  42. check_mc_build_filename(("test", "path", NULL), "/test/path");
  43. check_mc_build_filename(("/test", "path/", NULL), "/test/path");
  44. check_mc_build_filename(("/test", "pa/th", NULL), "/test/pa/th");
  45. check_mc_build_filename(("/test", "#vfsprefix:", "path ", NULL), "/test/#vfsprefix:/path ");
  46. check_mc_build_filename(("/test", "vfsprefix://", "path ", NULL), "/test/vfsprefix://path ");
  47. check_mc_build_filename(("/test", "vfs/../prefix:///", "p\\///ath", NULL), "/test/prefix://p\\/ath");
  48. check_mc_build_filename(("/test", "path", "..", "/test", "path/", NULL), "/test/test/path");
  49. }
  50. END_TEST
  51. /* --------------------------------------------------------------------------------------------- */
  52. int
  53. main (void)
  54. {
  55. int number_failed;
  56. Suite *s = suite_create (TEST_SUITE_NAME);
  57. TCase *tc_core = tcase_create ("Core");
  58. SRunner *sr;
  59. tcase_add_checked_fixture (tc_core, setup, teardown);
  60. /* Add new tests here: *************** */
  61. tcase_add_test (tc_core, test_mc_build_filename);
  62. /* *********************************** */
  63. suite_add_tcase (s, tc_core);
  64. sr = srunner_create (s);
  65. srunner_set_log (sr, "mc_build_filename.log");
  66. srunner_run_all (sr, CK_NORMAL);
  67. number_failed = srunner_ntests_failed (sr);
  68. srunner_free (sr);
  69. return (number_failed == 0) ? 0 : 1;
  70. }
  71. /* --------------------------------------------------------------------------------------------- */