path_len.c 2.8 KB

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