path_len.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* lib/vfs - tests for vfspath_len() function.
  2. Copyright (C) 2011-2019
  3. Free Software Foundation, Inc.
  4. Written by:
  5. Slava Zanko <slavazanko@gmail.com>, 2011, 2013
  6. This file is part of the Midnight Commander.
  7. The Midnight Commander is free software: you can redistribute it
  8. and/or modify it under the terms of the GNU General Public License as
  9. published by the Free Software Foundation, either version 3 of the License,
  10. or (at your option) any later version.
  11. The Midnight Commander is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #define TEST_SUITE_NAME "/lib/vfs"
  19. #include "tests/mctest.h"
  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. /* --------------------------------------------------------------------------------------------- */
  28. /* @Before */
  29. static void
  30. setup (void)
  31. {
  32. str_init_strings (NULL);
  33. vfs_init ();
  34. vfs_init_localfs ();
  35. vfs_setup_work_dir ();
  36. mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  37. #ifdef HAVE_CHARSET
  38. load_codepages_list ();
  39. #endif
  40. }
  41. /* --------------------------------------------------------------------------------------------- */
  42. /* @After */
  43. static void
  44. teardown (void)
  45. {
  46. #ifdef HAVE_CHARSET
  47. free_codepages_list ();
  48. #endif
  49. vfs_shut ();
  50. str_uninit_strings ();
  51. }
  52. /* --------------------------------------------------------------------------------------------- */
  53. /* @DataSource("test_path_length_ds") */
  54. /* *INDENT-OFF* */
  55. static const struct test_path_length_ds
  56. {
  57. const char *input_path;
  58. const size_t expected_length;
  59. } test_path_length_ds[] =
  60. {
  61. { /* 0. */
  62. NULL,
  63. 0
  64. },
  65. { /* 1. */
  66. "/",
  67. 1
  68. },
  69. { /* 2. */
  70. "/тестовый/путь",
  71. 26
  72. },
  73. #ifdef HAVE_CHARSET
  74. { /* 3. */
  75. "/#enc:KOI8-R/тестовый/путь",
  76. 38
  77. },
  78. #endif /* HAVE_CHARSET */
  79. };
  80. /* *INDENT-ON* */
  81. /* @Test(dataSource = "test_path_length_ds") */
  82. /* *INDENT-OFF* */
  83. START_PARAMETRIZED_TEST (test_path_length, test_path_length_ds)
  84. /* *INDENT-ON* */
  85. {
  86. /* given */
  87. vfs_path_t *vpath;
  88. size_t actual_length;
  89. vpath = vfs_path_from_str (data->input_path);
  90. /* when */
  91. actual_length = vfs_path_len (vpath);
  92. /* then */
  93. mctest_assert_int_eq (actual_length, data->expected_length);
  94. vfs_path_free (vpath);
  95. }
  96. /* *INDENT-OFF* */
  97. END_PARAMETRIZED_TEST
  98. /* *INDENT-ON* */
  99. /* --------------------------------------------------------------------------------------------- */
  100. int
  101. main (void)
  102. {
  103. int number_failed;
  104. Suite *s = suite_create (TEST_SUITE_NAME);
  105. TCase *tc_core = tcase_create ("Core");
  106. SRunner *sr;
  107. tcase_add_checked_fixture (tc_core, setup, teardown);
  108. /* Add new tests here: *************** */
  109. mctest_add_parameterized_test (tc_core, test_path_length, test_path_length_ds);
  110. /* *********************************** */
  111. suite_add_tcase (s, tc_core);
  112. sr = srunner_create (s);
  113. srunner_set_log (sr, "path_len.log");
  114. srunner_run_all (sr, CK_ENV);
  115. number_failed = srunner_ntests_failed (sr);
  116. srunner_free (sr);
  117. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  118. }
  119. /* --------------------------------------------------------------------------------------------- */