path_recode.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. lib/vfs - vfs_path_t charset recode functions
  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/vfs"
  20. #include <config.h>
  21. #include <check.h>
  22. #include "lib/global.c"
  23. #ifndef HAVE_CHARSET
  24. #define HAVE_CHARSET 1
  25. #endif
  26. #include "lib/charsets.h"
  27. #include "lib/strutil.h"
  28. #include "lib/vfs/xdirentry.h"
  29. #include "lib/vfs/path.h"
  30. #include "src/vfs/local/local.c"
  31. struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3;
  32. struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
  33. static void
  34. setup (void)
  35. {
  36. }
  37. static void
  38. teardown (void)
  39. {
  40. }
  41. /* --------------------------------------------------------------------------------------------- */
  42. #define path_recode_one_check(input, etalon1, etalon2) {\
  43. vpath = vfs_path_from_str (input);\
  44. element = vfs_path_get_by_index(vpath, -1);\
  45. fail_unless ( strcmp (element->path, etalon1) == 0, "expected: %s\nactual: %s\n", etalon1, element->path);\
  46. result = vfs_path_to_str(vpath);\
  47. fail_unless ( strcmp (result, etalon2) == 0, "\nexpected: %s\nactual: %s\n", etalon2, result);\
  48. g_free(result);\
  49. vfs_path_free (vpath);\
  50. }
  51. START_TEST (test_path_recode_base_utf8)
  52. {
  53. vfs_path_t *vpath;
  54. char *result;
  55. vfs_path_element_t *element;
  56. str_init_strings ("UTF-8");
  57. vfs_init ();
  58. init_localfs ();
  59. vfs_setup_work_dir ();
  60. mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  61. mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  62. load_codepages_list ();
  63. path_recode_one_check("/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ", "/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ", "/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ");
  64. path_recode_one_check("/#enc:KOI8-R/теÑ�товый/путь", "/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ", "/#enc:KOI8-R/теÑ�товый/путь");
  65. free_codepages_list ();
  66. str_uninit_strings ();
  67. vfs_shut ();
  68. }
  69. END_TEST
  70. START_TEST (test_path_recode_base_koi8r)
  71. {
  72. vfs_path_t *vpath;
  73. char *result;
  74. vfs_path_element_t *element;
  75. str_init_strings ("KOI8-R");
  76. vfs_init ();
  77. init_localfs ();
  78. vfs_setup_work_dir ();
  79. mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  80. mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  81. load_codepages_list ();
  82. path_recode_one_check("/те�товый/путь", "/те�товый/путь", "/те�товый/путь");
  83. path_recode_one_check("/#enc:UTF-8/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ", "/теÑ�товый/путь", "/#enc:UTF-8/ÔÅÓÔÏ×ÙÊ/ÐÕÔØ");
  84. free_codepages_list ();
  85. str_uninit_strings ();
  86. vfs_shut ();
  87. }
  88. END_TEST
  89. /* --------------------------------------------------------------------------------------------- */
  90. int
  91. main (void)
  92. {
  93. int number_failed;
  94. Suite *s = suite_create (TEST_SUITE_NAME);
  95. TCase *tc_core = tcase_create ("Core");
  96. SRunner *sr;
  97. tcase_add_checked_fixture (tc_core, setup, teardown);
  98. /* Add new tests here: *************** */
  99. tcase_add_test (tc_core, test_path_recode_base_utf8);
  100. tcase_add_test (tc_core, test_path_recode_base_koi8r);
  101. /* *********************************** */
  102. suite_add_tcase (s, tc_core);
  103. sr = srunner_create (s);
  104. srunner_set_log (sr, "path_recode.log");
  105. srunner_run_all (sr, CK_NORMAL);
  106. number_failed = srunner_ntests_failed (sr);
  107. srunner_free (sr);
  108. return (number_failed == 0) ? 0 : 1;
  109. }
  110. /* --------------------------------------------------------------------------------------------- */