mc_build_filename.c 3.2 KB

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