path_len.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* lib/vfs - vfs_path_t compare functions
  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/vfs"
  18. #include <check.h>
  19. #include "lib/global.c"
  20. #ifdef HAVE_CHARSET
  21. #include "lib/charsets.h"
  22. #endif
  23. #include "lib/strutil.h"
  24. #include "lib/vfs/xdirentry.h"
  25. #include "lib/vfs/path.h"
  26. #include "src/vfs/local/local.c"
  27. static void
  28. setup (void)
  29. {
  30. str_init_strings (NULL);
  31. vfs_init ();
  32. init_localfs ();
  33. vfs_setup_work_dir ();
  34. mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  35. #ifdef HAVE_CHARSET
  36. load_codepages_list ();
  37. #endif
  38. }
  39. static void
  40. teardown (void)
  41. {
  42. #ifdef HAVE_CHARSET
  43. free_codepages_list ();
  44. #endif
  45. vfs_shut ();
  46. str_uninit_strings ();
  47. }
  48. /* --------------------------------------------------------------------------------------------- */
  49. #define path_len_one_check(input,etalon) {\
  50. vpath = vfs_path_from_str (input);\
  51. result = vfs_path_len (vpath);\
  52. vfs_path_free (vpath); \
  53. fail_unless ( result == etalon, "\ninput: %s\nexpected: %d\nactual: %d\n",\
  54. input, etalon, result); \
  55. }
  56. START_TEST (test_path_length)
  57. {
  58. vfs_path_t *vpath;
  59. size_t result;
  60. path_len_one_check ("/тестовый/путь", 26);
  61. #ifdef HAVE_CHARSET
  62. path_len_one_check ("/#enc:KOI8-R/тестовый/путь", 38);
  63. #endif
  64. path_len_one_check (NULL, 0);
  65. }
  66. END_TEST
  67. /* --------------------------------------------------------------------------------------------- */
  68. int
  69. main (void)
  70. {
  71. int number_failed;
  72. Suite *s = suite_create (TEST_SUITE_NAME);
  73. TCase *tc_core = tcase_create ("Core");
  74. SRunner *sr;
  75. tcase_add_checked_fixture (tc_core, setup, teardown);
  76. /* Add new tests here: *************** */
  77. tcase_add_test (tc_core, test_path_length);
  78. /* *********************************** */
  79. suite_add_tcase (s, tc_core);
  80. sr = srunner_create (s);
  81. srunner_set_log (sr, "path_len.log");
  82. srunner_run_all (sr, CK_NORMAL);
  83. number_failed = srunner_ntests_failed (sr);
  84. srunner_free (sr);
  85. return (number_failed == 0) ? 0 : 1;
  86. }
  87. /* --------------------------------------------------------------------------------------------- */